@theme-registry/refract 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/prompt.d.ts +61 -8
- package/dist/build.cjs.js +1 -1
- package/dist/build.cjs.js.map +1 -1
- package/dist/build.esm.js +1 -1
- package/dist/build.esm.js.map +1 -1
- package/dist/cli.js +303 -26
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/build.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("node:fs"),t=require("node:path"),r=require("node:url"),n=require("node:readline"),o=require("node:os"),s=require("node:readline/promises"),i=require("node:util");const a=[{id:"color-math",outfile:"color-math.js",source:"src/subsystems/colors/utils.ts",exports:["lighten","darken","alpha","setL","rotateHue","complement","adjust","rgbToOklch","oklchToRgb","toHexColor","toOklchColor","convertHexToRGB","convertRgbToHex"],description:"Pure OKLCH colour math — the exact lighten/darken/setL/rotateHue/complement/adjust (+ OKLCH and hex converters) refract synthesizes palette steps/variants with, so a value computed live in the consumer matches the emitted CSS variables."}],l=e=>a.find(t=>t.id===e),c=(r=__dirname)=>{let n=r;for(;;){if(e.existsSync(t.join(n,"package.json")))return n;const o=t.dirname(n);if(o===n)throw new Error(`No package.json found walking up from "${r}".`);n=o}},u=r=>{const n=t.join(c(),r);if(!e.existsSync(n))throw new Error(`Vendor helper source "${r}" not found at "${n}". Ensure it is listed in package.json "files" so it ships with the package.`);return e.readFileSync(n,"utf8")};async function d(){var e;try{const t=await import("typescript");return null!==(e=t.default)&&void 0!==e?e:t}catch{throw new Error('refract: the optional peer dependency "typescript" is required to transpile a `.ts` theme.config or vendor a shared helper module, but it could not be resolved. Install it (`npm i -D typescript`), or use a `.mjs`/`.js` config and avoid the `helpers` opt-in.')}}const f=async e=>{const t=await d();return t.transpileModule(e,{compilerOptions:{module:t.ModuleKind.ESNext,target:t.ScriptTarget.ES2020}}).outputText};let p=0;const m=e=>t.resolve(e).replace(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/,""),h=async r=>{const n=await d(),o={module:n.ModuleKind.ESNext,target:n.ScriptTarget.ES2020,moduleResolution:n.ModuleResolutionKind.Bundler,resolveJsonModule:!0,allowJs:!1,noLib:!0,skipLibCheck:!0,noEmitOnError:!1,declaration:!1,sourceMap:!1,types:[]},s=n.createCompilerHost(o),i=n.createProgram([r],o,s),a=new Map,l=e=>!e.isDeclarationFile&&!e.fileName.includes("/node_modules/")&&/\.(ts|tsx|mts|cts)$/.test(e.fileName);for(const e of i.getSourceFiles()){if(!l(e))continue;const r=t.resolve(e.fileName),n=t.basename(r).replace(/\.(ts|tsx|mts|cts)$/,"");a.set(m(r),t.join(t.dirname(r),`.${n}.${process.pid}-${p++}.mjs`))}const c=e=>r=>{const i=t.resolve(r.fileName),l=e.factory,c=e=>{const r=((e,t)=>{var r;if(!e.startsWith("."))return;const i=null===(r=n.resolveModuleName(e,t,o,s).resolvedModule)||void 0===r?void 0:r.resolvedFileName;return i?a.get(m(i)):void 0})(e,i);return r?l.createStringLiteral(`./${t.basename(r)}`):void 0},u=t=>{if(n.isImportDeclaration(t)&&n.isStringLiteral(t.moduleSpecifier)){const e=c(t.moduleSpecifier.text);if(e)return l.updateImportDeclaration(t,t.modifiers,t.importClause,e,t.attributes)}else if(n.isExportDeclaration(t)&&t.moduleSpecifier&&n.isStringLiteral(t.moduleSpecifier)){const e=c(t.moduleSpecifier.text);if(e)return l.updateExportDeclaration(t,t.modifiers,t.isTypeOnly,t.exportClause,e,t.attributes)}else if(n.isCallExpression(t)&&t.expression.kind===n.SyntaxKind.ImportKeyword&&t.arguments.length&&n.isStringLiteral(t.arguments[0])){const e=c(t.arguments[0].text);if(e)return l.updateCallExpression(t,t.expression,t.typeArguments,[e,...t.arguments.slice(1)])}return n.visitEachChild(t,u,e)};return n.visitNode(r,u)},u=[],f=(t,r)=>{const n=a.get(m(t));n&&(e.writeFileSync(n,r,"utf8"),u.push(n))},h=()=>{for(const t of u)e.rmSync(t,{force:!0})};try{i.emit(void 0,f,void 0,!1,{before:[c]})}catch(e){throw h(),e}const g=a.get(m(r));if(!g||!e.existsSync(g))throw h(),new Error(`refract: failed to compile the \`.ts\` config graph for "${r}".`);return{entry:g,cleanup:h}},g=e=>e.replace(/\|/g,"\\|");function b(e,t,r){var n;const o=[];if(o.push(`# Theme consumption guide (${e.format})`),o.push(""),o.push("This folder is a self-contained theme built with refract. You do NOT need refract to use it —","everything below refers to files in THIS folder (relative paths), so it works whether the theme","was installed as a package, unzipped from an artifact, or vendored into a repo."),o.push(""),t.files.length>0){o.push("## Files"),o.push("");for(const e of t.files)o.push(`- \`./${e}\``);o.push("")}o.push("## How to use"),o.push("");for(const t of e.summary)o.push(t);t.packageName&&(o.push(""),o.push(`If this theme is installed as the \`${t.packageName}\` package, you may import the same`,`files by specifier (e.g. \`${t.packageName}/${null!==(n=t.files[0])&&void 0!==n?n:"theme.css"}\`) instead of by relative path.`)),o.push("");const{recipes:s}=e;if(s.length>0){o.push("## Recipes — real names"),o.push(""),o.push("Use these exact identities; do not invent names."),o.push(""),o.push("| Recipe | Identity |"),o.push("| --- | --- |");const e=s.slice(0,60);for(const t of e)o.push(`| \`${g(`${t.subsystem}.${t.group}.${t.variant}`)}\` | \`${g(t.name)}\` |`);if(s.length>e.length){const t=s.length-e.length;o.push(""),o.push(`_(+${t} more recipe(s) — the complete list is in ${r?`\`./${r}\``:"the manifest"}.)_`)}o.push("")}return r&&(o.push("## Machine-readable index"),o.push(""),o.push(`See \`./${r}\` for the full recipe index and the theme's tokens (DTCG format).`),o.push("")),o.join("\n")}function v(e,t,r){var n;const o=null!==(n=r.llmsFile)&&void 0!==n?n:"llms.txt",s=void 0===r.manifestFile?"manifest.json":r.manifestFile,i={[o]:b(e,r,s)};if(s){const n={schema:1,format:e.format,files:r.files,packageName:r.packageName,recipes:e.recipes,tokens:t};i[s]=`${JSON.stringify(n,null,2)}\n`}return{files:i}}class y extends Error{constructor(e,t,r){super(t),this.name="RefractError",this.code=e,r&&(this.failures=r),Object.setPrototypeOf(this,y.prototype)}}const w=e=>"string"==typeof e||"number"==typeof e,$=e=>Array.isArray(e),k=e=>({value:e}),x=(e,t)=>{if(!t)return k(e);const r={ref:t.ref};return void 0!==t.fn&&(r.fn=t.fn),void 0!==t.arg&&(r.arg=t.arg),void 0!==t.modifiers&&(r.modifiers=t.modifiers),void 0!==e&&(r.value=e),r},j=new Set(["mode","target","base","derive"]),A=(e,t,r)=>{const n={},o=e.derive,s=e.base;if(o){if(void 0===o.ref)throw new y("REFRACT_E_REFERENCE",`Derived appearance mode "${t}.modes.${r}" was not baked — derived modes require a subsystem that resolves them (colors). Use a literal value instead.`);n.base=x(w(s)?s:void 0,o)}else w(s)?n.base=k(s):$(s)&&(n.base={struct:s});for(const[t,r]of Object.entries(e))j.has(t)||w(r)&&(n[t]=k(r));return n},S=(e,t)=>{const r={};for(const[n,o]of Object.entries(e))t.has(n)||w(o)&&(r[n]=k(o));return r},E=new Set(["base","derive"]),R=new Set(["base","responsive","variants","modes","external"]),C=new Set(["breakpoint","query","state","orientation","ref","modifiers","mode","variant","target","derive","ratio","step","steps"]),O=(e,t="property")=>{var r;const n={base:void 0!==e.external?{value:`var(${e.external})`,external:e.external}:(o=e.base,$(o)?{struct:o}:k(o))};var o;const s=S(e,R);if(Object.keys(s).length&&(n.extras=s),e.variants&&Object.keys(e.variants).length){const t={};for(const[r,n]of Object.entries(e.variants)){let e;const o=n.derive;if(w(n.base)?e=x(n.base,o):$(n.base)?e={struct:n.base}:void 0!==(null==o?void 0:o.ref)&&(e=x(void 0,o)),!e)continue;const s=S(n,E);t[r]=Object.keys(s).length?{base:e,extras:s}:{base:e}}Object.keys(t).length&&(n.variants=t)}const i=e.modes;if(i&&i.length){const e=[];for(const r of i){const n=r.mode,o=A(r,t,n);if(!Object.keys(o).length)continue;const s={mode:n,overrides:o};"string"==typeof r.target&&(s.target=r.target),e.push(s)}e.length&&(n.modes=e)}if(null===(r=e.responsive)||void 0===r?void 0:r.length){const t=e.responsive.map(e=>{const t=e,r={breakpoint:t.breakpoint};"string"==typeof t.query&&(r.query=t.query),"string"==typeof t.orientation&&(r.orientation=t.orientation),"string"==typeof t.ref&&(r.ref=t.ref),"string"==typeof t.mode&&(r.mode=t.mode),"string"==typeof t.target&&(r.target=t.target);const n=((e,t)=>{const r={};for(const[n,o]of Object.entries(e))t.has(n)||(w(o)?r[n]=k(o):$(o)&&(r[n]={struct:o}));return r})(t,C),o=t.derive;return o&&n.base&&void 0!==n.base.value&&(n.base=x(n.base.value,o)),Object.keys(n).length&&(r.overrides=n),r});n.responsive=t}return n},T=e=>({kind:"recipe",declarations:{...e.base},overrides:e.responsive.map(e=>{const t={};return void 0!==e.state&&(t.state=e.state),void 0!==e.breakpoint&&(t.breakpoint=e.breakpoint),void 0!==e.query&&(t.query=e.query),void 0!==e.orientation&&(t.orientation=e.orientation),void 0!==e.container&&(t.container=e.container),void 0!==e.size&&(t.size=e.size),void 0!==e.variant&&(t.variant=e.variant),void 0!==e.target&&(t.target=e.target),Object.keys(e.declarations).length&&(t.declarations={...e.declarations}),t})}),F=(e,t)=>{const r=T(e);return r.kind="recipe",t.length&&(r.references=t),r},_=new Set(["colors","typography","layout","effects","borders"]),N=e=>!!e&&Object.keys(e).length>0,P=e=>{var t;if(!e)return;const r={};return e.properties&&Object.keys(e.properties).length&&(r.properties=(e=>{const t={};for(const[r,n]of Object.entries(e))t[r]=O(n,r);return t})(e.properties)),e.extraProperties&&Object.keys(e.extraProperties).length&&(r.properties={...null!==(t=r.properties)&&void 0!==t?t:{},...e.extraProperties}),N(e.ruleSetGroups)&&(r.ruleSets=e.ruleSetGroups),N(e.keyframes)&&(r.keyframes=e.keyframes),Object.keys(r).length?r:void 0},z=e=>{var t,r,n,o;const s={};for(const[i,a]of Object.entries(e.subsystems))for(const[e,l]of Object.entries(null!==(t=a.properties)&&void 0!==t?t:{})){const t=`${i}.${e}`;s[t]=l.base;for(const[e,o]of Object.entries(null!==(r=l.variants)&&void 0!==r?r:{})){s[`${t}.${e}`]=o.base;for(const[r,i]of Object.entries(null!==(n=o.extras)&&void 0!==n?n:{}))s[`${t}.${e}.${r}`]=i}for(const[e,r]of Object.entries(null!==(o=l.extras)&&void 0!==o?o:{}))s[`${t}.${e}`]=r}return s},q=new Set(["px","cm","mm","q","in","pc","pt","rem","em","ex","cap","ch","ic","lh","rlh","%","vw","vh","vi","vb","vmin","vmax","svw","svh","lvw","lvh","dvw","dvh","cqw","cqh","cqi","cqb","cqmin","cqmax"]),M=/^-?(?:\d+\.?\d*|\.\d+)(?:e-?\d+)?$/i,I=/^(-?(?:\d+\.?\d*|\.\d+)(?:e-?\d+)?)([a-z%]+)$/i,L=e=>{if("number"==typeof e)return{value:e};const t=e.trim();if(M.test(t))return{value:Number(t)};const r=I.exec(t);if(r){const t=r[2].toLowerCase();if(q.has(t))return{value:Number(r[1]),unit:t};throw new y("REFRACT_E_UNITS",`Unknown length unit "${r[2]}" in "${e}". Use a CSS unit, or wrap functions/keywords (calc(), clamp(), var(), a keyword) — those pass through as raw strings.`)}return{raw:e}},B={"typography.lineHeight":"none","typography.letterSpacing":"em"},U=(e,t)=>{var r,n,o,s;const i=e.slice(0,e.indexOf("."));return null!==(s=null!==(o=null!==(n=null!==(r=null==t?void 0:t[e])&&void 0!==r?r:B[e])&&void 0!==n?n:null==t?void 0:t[i])&&void 0!==o?o:null==t?void 0:t.default)&&void 0!==s?s:"px"},D=(e,t)=>Number((e/t).toFixed(4)),V=(e,t,r)=>"none"===t?{value:e}:"rem"===t?{value:D(e,r),unit:"rem"}:{value:e,unit:t},W=(e,t,r)=>{if("number"==typeof e){const{value:n,unit:o}=V(e,t,r);return void 0===o?e:{value:n,unit:o}}return e},H={typography:{fontSize:"length",letterSpacing:"length",lineHeight:"length"},layout:{spacing:"length",gutters:"length",sizes:"length"},borders:{width:"length",offset:"length",radius:"length"},effects:{blur:"length",shadow:"shadow"}},G=(e,t)=>{let r=!1;const n={};for(const[o,s]of Object.entries(e)){const e=t(s);e!==s&&(r=!0),n[o]=e}return r?n:e},Y=(e,t,r)=>{const n=t(e.base),o=e.variants?((e,t)=>{let r=!1;const n={};for(const[o,s]of Object.entries(e)){const e=t(s.base),i=s.extras?G(s.extras,t):void 0;e===s.base&&i===s.extras||(r=!0),n[o]=i?{base:e,extras:i}:{base:e}}return r?n:e})(e.variants,t):void 0,s=r&&e.extras?G(e.extras,t):e.extras,i=e.modes?((e,t)=>{let r=!1;const n=e.map(e=>{if(!e.overrides)return e;const n=G(e.overrides,t);return n===e.overrides?e:(r=!0,{...e,overrides:n})});return r?n:e})(e.modes,t):void 0,a=((e,t)=>{if(!e.responsive)return;let r=!1;const n=e.responsive.map(e=>{if(!e.overrides)return e;const n=G(e.overrides,t);return n===e.overrides?e:(r=!0,{...e,overrides:n})});return r?n:e.responsive})(e,t);if(n===e.base&&o===e.variants&&s===e.extras&&i===e.modes&&a===e.responsive)return e;const l={...e,base:n};return void 0!==o&&(l.variants=o),void 0!==s&&(l.extras=s),void 0!==i&&(l.modes=i),void 0!==a&&(l.responsive=a),l},J=(e,t,r,n)=>{const o="shadow"===t?e=>{if(!e.struct)return e;const t=e.struct;let o=!1;const s=t.map(e=>{const t=((e,t,r)=>{const n={...e};let o=!1;for(const s of["offsetX","offsetY","blur","spread"]){const i=e[s];if(void 0===i)continue;const a=W(i,t,r);a!==i&&(n[s]=a,o=!0)}return o?n:e})(e,r,n);return t!==e&&(o=!0),t});return o?{...e,struct:s}:e}:e=>((e,t,r)=>{if(void 0!==e.unit)return e;if(void 0!==e.ref&&void 0===e.value)return e;const n=e.value;if("number"==typeof n){const{value:o,unit:s}=V(n,t,r);return void 0===s?e:{...e,value:o,unit:s}}if("string"==typeof n){const o=L(n);if("raw"in o)return e;if(void 0!==o.unit)return{...e,value:o.value,unit:o.unit};const{value:s,unit:i}=V(o.value,t,r);return void 0===i?{...e,value:s}:{...e,value:s,unit:i}}return e})(e,r,n);return Y(e,o,!1)},K=(e,t={})=>{var r;const n=null!==(r=t.baseFontSize)&&void 0!==r?r:16;let o=!1;const s={};for(const[r,i]of Object.entries(e.subsystems)){const e=H[r];if(!e||!i.properties){s[r]=i;continue}let a=!1;const l={};for(const[o,s]of Object.entries(i.properties)){const i=e[o];if(!i){l[o]=s;continue}const c=U(`${r}.${o}`,t.units),u=J(s,i,c,n);u!==s&&(a=!0),l[o]=u}a?(s[r]={...i,properties:l},o=!0):s[r]=i}return o?{...e,subsystems:s}:e},X=e=>(null==e?void 0:e.propertyPath)?` for "${e.propertyPath}"`:"",Z=(e,t)=>!t||(Array.isArray(t)?t.includes(e):t.has(e));function Q(e,t){const r=e.variants?Object.keys(e.variants):[];if(!r.length)return;const n=new Set(r),o=(null==t?void 0:t.propertyPath)?` for "${t.propertyPath}"`:"";for(const t of e.responsive){if(t.ref&&!n.has(t.ref))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${o} references unknown variant "${t.ref}" (ref).`);if(t.target&&!n.has(t.target))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${o} references unknown target "${t.target}".`)}}const ee=e=>"object"==typeof e&&null!==e&&Array.isArray(e.modifiers),te=(e,t)=>{if(!Array.isArray(e)||0===e.length)throw new y("REFRACT_E_VARIANT",`Derivation "${t}" needs a non-empty "modifiers" array.`);return e.map((e,r)=>{if("object"!=typeof e||null===e||Array.isArray(e))throw new y("REFRACT_E_VARIANT",`Modifier ${r} of "${t}" must be a single-key object like { darken: 10 }.`);const n=Object.keys(e);if(1!==n.length)throw new y("REFRACT_E_VARIANT",`Modifier ${r} of "${t}" must have exactly one fn key; got [${n.join(", ")}].`);return{fn:n[0],arg:e[n[0]]}})},re=new Set(["breakpoint","query","ref","modifiers","mode","target","orientation"]),ne=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),oe=(e,t,r)=>{var n;const o=null!==(n=null!=e?e:t)&&void 0!==n?n:r.fallbackBase;if(void 0===o)throw new y("REFRACT_E_PROPERTY",`Unable to resolve base value${s=r.propertyPath,s?` for "${s}"`:""}.`);var s;return r.coerceValue?r.coerceValue(o):o},se=(e,t)=>{const r=new Set(t),n={},o={};let s=!1;for(const[t,i]of Object.entries(e))r.has(t)?(n[t]=i,s=!0):o[t]=i;return{base:s?n:void 0,extra:o}},ie=(e,t,r,n)=>{var o;if(void 0===e&&(null===(o=n.leafFields)||void 0===o?void 0:o.length)){const e=se(t,n.leafFields);if(void 0!==e.base){const t=e.base;return{base:n.coerceValue?n.coerceValue(t):t,extra:e.extra}}}return{base:oe(e,r,n),extra:t}},ae=(e,t,r,n)=>{const o=r.propertyPath?`${r.propertyPath}.variants.${e}`:`variants.${e}`,s=ne(t)?t:{base:t},{base:i,...a}=s,{base:l,extra:c}=ie(i,a,n,{...r,propertyPath:o});return{...c,base:l}},le=(e,t={})=>{var r;const n=ne(e)?e:{base:e},{base:o,responsive:s,variants:i,modes:a,...l}=n,{base:c,extra:u}=ie(o,l,t.fallbackBase,t),d=i?Object.fromEntries(Object.entries(i).map(([e,r])=>[e,ae(e,r,t,c)])):void 0,f=a?a.map(e=>((e,t)=>{const{mode:r,target:n,...o}=e,s=t.propertyPath?`${t.propertyPath}.modes.${r}`:`modes.${r}`;return{mode:r,...void 0!==n?{target:n}:{},...(()=>{var e;if((null===(e=t.leafFields)||void 0===e?void 0:e.length)&&!("base"in o)&&!ee(o)){const{base:e,extra:r}=se(o,t.leafFields);if(void 0!==e){const n={...r};return n.base=t.coerceValue?t.coerceValue(e):e,n}}if(ee(o)){const{ref:e,modifiers:t,...r}=o,n={...r};return n.derive={...void 0!==e?{ref:e}:{},modifiers:te(t,s)},n}const{base:r,...n}=o,i={...n};if(void 0!==r&&(i.base=Array.isArray(r)||!t.coerceValue?r:t.coerceValue(r)),void 0===i.base&&!i.derive&&!Object.keys(n).length)throw new y("REFRACT_E_MODE",`Appearance mode "${s}" overrides nothing.`);return i})()}})(e,t)):void 0,p={propertyPath:t.propertyPath,allowedBreakpoints:t.allowedBreakpoints},m=(g=p,(null==(h=s)?void 0:h.length)?h.map(e=>{if(!e.breakpoint)throw new y("REFRACT_E_BREAKPOINT",`Responsive entry${X(g)} is missing a "breakpoint" value.`);if((null==g?void 0:g.allowedBreakpoints)&&!Z(e.breakpoint,g.allowedBreakpoints))throw new y("REFRACT_E_BREAKPOINT",`Responsive entry${X(g)} references unknown breakpoint "${e.breakpoint}".`);if(e.ref&&!Z(e.ref,null==g?void 0:g.allowedVariants))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${X(g)} references unknown variant "${e.ref}" (ref).`);if(e.target&&!Z(e.target,null==g?void 0:g.allowedTargets))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${X(g)} references unknown target "${e.target}".`);const{query:t,...r}=e;return{...r,query:null!=t?t:"exact"}}):[]);var h,g;const b=(null===(r=t.leafFields)||void 0===r?void 0:r.length)?m.map(e=>((e,t)=>{const r={},n={};let o;for(const[t,s]of Object.entries(e))re.has(t)?r[t]=s:"base"===t?o=s:n[t]=s;const s=t.leafFields.some(e=>e in n);if(void 0===o&&!s)return e;const{base:i,extra:a}=ie(o,n,void 0,t);return{...r,...a,base:i}})(e,t)):m;return{...u,base:c,responsive:b,variants:d,modes:f}},ce=["orientation","height","aspectRatio"],ue=(e,t)=>!t||(Array.isArray(t)?t.includes(e):t.has(e)),de=e=>e?` for "${e}"`:"",fe="responsive",pe="states",me="css",he="variants",ge=e=>Array.isArray(e)?e:e&&"object"==typeof e?Object.entries(e).map(([e,t])=>({state:e,...t})):[],be=e=>{var t;return`${e.state}\0${null!==(t=e.target)&&void 0!==t?t:""}`},ve=(e,t)=>{const r=ge(e).map(e=>({...e})),n=new Map(r.map((e,t)=>[be(e),t]));for(const e of ge(t)){const t=be(e),o=n.get(t);void 0!==o?r[o]={...r[o],...e}:(n.set(t,r.length),r.push({...e}))}return r},ye=(e,t)=>{var r,n;const o={...e};for(const[s,i]of Object.entries(t))null!==i?s===fe?o[fe]=[...null!==(r=e[fe])&&void 0!==r?r:[],...i]:s===pe?o[pe]=ve(e[pe],i):s===me?o[me]={...null!==(n=e[me])&&void 0!==n?n:{},...i}:o[s]=i:delete o[s];return o},we=(e,t={})=>{const r=((e,t)=>{if(!Object.values(e).some(e=>null!=e&&"object"==typeof e&&null!=e[he]))return e;const r={},n=(e,n)=>{if(e in r)throw new y("REFRACT_E_VARIANT",`Recipe variant expansion${de(t)} produced a duplicate recipe name "${e}" — a desugared "<recipe>-<variant>" collides with an existing sibling recipe.`);r[e]=n};for(const[t,r]of Object.entries(e)){const{[he]:e,...o}=r;if(n(t,o),null!=e){const r=null!=o[pe]?{...o,[pe]:ge(o[pe]).filter(e=>!e.target)}:o;for(const[o,s]of Object.entries(e))n(`${t}-${o}`,ye(r,s))}}return r})(e,t.propertyPath),n=Object.keys(r),o=n.length?new Set(n):void 0,s={};return n.forEach(e=>{var n;const i=r[e];s[e]=$e(`${null!==(n=t.propertyPath)&&void 0!==n?n:"recipes"}.${e}`,i,{allowedBreakpoints:t.allowedBreakpoints,allowedStates:t.allowedStates,allowedTargets:o,allowedVariants:o,allowedContainers:t.allowedContainers,recipeName:e})}),s},$e=(e,t,r)=>{const{responsive:n,states:o,...s}=t;return{base:s,responsive:[...ke(o,e,r),...xe(n,e,r)]}},ke=(e,t,r)=>ge(e).map(e=>{const{state:n,...o}=e;if(r.allowedStates&&!ue(n,r.allowedStates))throw new y("REFRACT_E_STATE",`Recipe state entry${de(t)} references unknown state "${n}".`);if(o.target&&r.allowedTargets){const e=r.recipeName?`${r.recipeName}-${o.target}`:o.target;if(!ue(e,r.allowedTargets))throw new y("REFRACT_E_RESPONSIVE",`Recipe state entry${de(t)} references unknown target "${o.target}".`)}return{...o,state:n}}),xe=(e,t,r)=>(null==e?void 0:e.length)?e.map(e=>{var n;if(void 0!==e.variant&&void 0!==e.target)throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${de(t)} cannot set both "variant" and "target".`);if(void 0!==e.container)return je(e,t,r);if(!e.breakpoint)throw new y("REFRACT_E_BREAKPOINT",`Responsive recipe entry${de(t)} is missing a "breakpoint" value.`);if(r.allowedBreakpoints&&!ue(e.breakpoint,r.allowedBreakpoints))throw new y("REFRACT_E_BREAKPOINT",`Responsive recipe entry${de(t)} references unknown breakpoint "${e.breakpoint}".`);if(e.state&&r.allowedStates&&!ue(e.state,r.allowedStates))throw new y("REFRACT_E_STATE",`Responsive recipe entry${de(t)} references unknown state "${e.state}".`);if(e.variant&&!ue(e.variant,r.allowedVariants))throw new y("REFRACT_E_RESPONSIVE",`Responsive recipe entry${de(t)} references unknown variant "${e.variant}".`);if(e.target&&!ue(e.target,r.allowedTargets))throw new y("REFRACT_E_RESPONSIVE",`Responsive recipe entry${de(t)} references unknown target "${e.target}".`);return{...e,query:null!==(n=e.query)&&void 0!==n?n:"exact"}}):[],je=(e,t,r)=>{var n,o;const s=e.container;for(const r of ce)if(void 0!==e[r])throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} cannot use "${r}" — container queries respond to a container's inline size, not orientation/height/aspect-ratio.`);const i=null===(n=r.allowedContainers)||void 0===n?void 0:n.get(s);if(r.allowedContainers&&!i)throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} references unknown container "${s}".`);if(void 0===e.size)throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} for container "${s}" is missing a "size" value.`);if(i&&!i.has(e.size))throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} references unknown size "${e.size}" on container "${s}".`);return{...e,query:null!==(o=e.query)&&void 0!==o?o:"min"}},Ae=(e,t,r={})=>{var n;const o=new Map,s=[],i=null!==(n=r.groupPath)&&void 0!==n?n:"recipes",a=r=>{if(o.has(r))return o.get(r);if(s.includes(r)){const e=[...s,r].join(" -> ");throw new y("REFRACT_E_CYCLE",`Cyclic recipe reference in "${i}": ${e}`)}const n=e[r];if(!n)throw new y("REFRACT_E_REFERENCE",`Recipe variant "${r}" is not defined in "${i}".`);s.push(r);try{const e=t(r,n,a);return o.set(r,e),e}finally{s.pop()}};return{resolve:a,resolveAll:()=>{const t={};for(const r of Object.keys(e))t[r]=a(r);return t}}},Se=(e,t,r,n=new Map,o=new Set)=>{const s=n.get(r);if(void 0!==s)return s;const i=e[r];if(!i)throw new y("REFRACT_E_TOKEN_PATH",`Unknown token path "${r}".`);if(void 0!==i.external){const e=`var(${i.external})`;return n.set(r,e),e}if(void 0===i.ref){if(void 0===i.value)throw new y("REFRACT_E_TOKEN_PATH",`Token "${r}" has neither "ref" nor "value".`);return n.set(r,i.value),i.value}if(o.has(r))throw new y("REFRACT_E_CYCLE",`Cyclic token reference: ${[...o,r].join(" -> ")}`);o.add(r);const a=Se(e,t,i.ref,n,o);let l;if(void 0!==i.modifiers)l=i.modifiers.reduce((e,n)=>{const o=t[n.fn];if(!o)throw new y("REFRACT_E_TOKEN_PATH",`Unknown derivation fn "${n.fn}" for token "${r}".`);return o(e,n.arg)},a);else if(void 0!==i.fn){const e=t[i.fn];if(!e)throw new y("REFRACT_E_TOKEN_PATH",`Unknown derivation fn "${i.fn}" for token "${r}".`);l=e(a,i.arg)}else l=a;return o.delete(r),n.set(r,l),l},Ee=(e,t)=>!!(null==e?void 0:e.ref)&&((void 0!==e.modifiers||void 0!==e.fn)&&(e=>{const[t,r]=e.split(".");return`${t}.${r}`})(e.ref)!==t),Re=(e,t,r,n,o)=>{let s;try{s=Se(t,r,e.ref,n)}catch{throw new y("REFRACT_E_VALIDATION",`${o}: cross-property derivation references unknown token '${e.ref}'.`)}const i=(e,t)=>{const n=r[e];if(!n)throw new y("REFRACT_E_VALIDATION",`${o}: unknown derivation fn '${e}'.`);return n(s,t)};if(void 0!==e.modifiers)for(const t of e.modifiers)s=i(t.fn,t.arg);else void 0!==e.fn&&(s=i(e.fn,e.arg));return{...e,value:s}},Ce=(e,t,r,n,o,s)=>{let i;for(const[a,l]of Object.entries(e))Ee(l,t)&&(i=null!=i?i:{...e},i[a]=Re(l,r,n,o,`${s}.${a}`));return i},Oe=(e,t,r,n,o)=>{const s=e.variants?((e,t,r,n,o)=>{let s;for(const[i,a]of Object.entries(e)){const l=`${t}.variants.${i}`,c=Ee(a.base,t)?Re(a.base,r,n,o,l):a.base,u=a.extras?Ce(a.extras,t,r,n,o,`${l} extra`):void 0;(c!==a.base||u)&&(s=null!=s?s:{...e},s[i]=u?{base:c,extras:u}:{...a,base:c})}return s})(e.variants,t,r,n,o):void 0;let i;if(e.modes)for(let s=0;s<e.modes.length;s++){const a=e.modes[s];if(!a.overrides)continue;const l=Ce(a.overrides,t,r,n,o,`${t}.modes.${a.mode}`);l&&(i=null!=i?i:[...e.modes],i[s]={...a,overrides:l})}if(!s&&!i)return;const a={...e};return s&&(a.variants=s),i&&(a.modes=i),a},Te=(e,t)=>{var r;const n=z(e),o=new Map;let s=!1;const i={};for(const[a,l]of Object.entries(e.subsystems)){let e,c=!1;for(const[s,i]of Object.entries(null!==(r=l.properties)&&void 0!==r?r:{})){const r=Oe(i,`${a}.${s}`,n,t,o);r&&(e=null!=e?e:{...l.properties},e[s]=r,c=!0)}c?(i[a]={...l,properties:e},s=!0):i[a]=l}return s?{...e,subsystems:i}:e},Fe=["min","max","exact","between"],_e=e=>void 0===e?void 0:e-.02,Ne=(e,t)=>{const r=(e=>Object.keys(e).sort((t,r)=>e[t]-e[r]))(e);(e=>{const t=e.filter(e=>Fe.includes(e));if(t.length)throw new y("REFRACT_E_BREAKPOINT",`Breakpoint names conflict with reserved keys: ${t.map(e=>`"${e}"`).join(", ")}. Reserved: ${Fe.map(e=>`"${e}"`).join(", ")}.`)})(r);const n=e=>r[r.indexOf(e)+1],o=r.reduce((r,o)=>{const s=e[o],i=n(o),a=void 0!==i?e[i]:void 0;return r[o]=Pe({own:s,next:a},t),r},{}),s=e=>{const t=o[e];if(!t)throw new y("REFRACT_E_BREAKPOINT",`Breakpoint "${e}" is not defined.`);return t};return{...o,min:(r,n)=>{const o=s(r);return n?t({min:e[r],...n}):o.min},max:(r,o)=>{const i=s(r);if(!o)return i.max;const a=n(r),l=void 0!==a?e[a]:void 0;return t({max:_e(l),...o})},exact:(r,o)=>{const i=s(r);if(!o)return i.exact;const a=n(r),l=void 0!==a?e[a]:void 0;return t({min:e[r],max:_e(l),...o})},between:(r,n,o)=>{const s=e[r],i=e[n];if(void 0===s||void 0===i)throw new y("REFRACT_E_BREAKPOINT",`Cannot build media query between "${r}" and "${n}" breakpoints.`);return t({min:s,max:i-.02,...o})}}},Pe=({own:e,next:t},r)=>{const n=_e(t);return{min:r({min:e}),max:void 0===n?"":r({max:n}),exact:r({min:e,max:n})}},ze="px",qe=16,Me=e=>{var t;return{unit:null!==(t=null==e?void 0:e.unit)&&void 0!==t?t:ze,baseFontSize:(null==e?void 0:e.baseFontSize)&&e.baseFontSize>0?e.baseFontSize:qe}},Ie=(e,t)=>{if("px"===t.unit)return`${e}px`;const r=e/t.baseFontSize;return`${Number(r.toFixed(4))}${t.unit}`},Le=({min:e,max:t,orientation:r},n)=>{const o=[];if(void 0!==e&&void 0!==t&&e>t)throw new y("REFRACT_E_MEDIA","Invalid media query: `min` cannot be greater than `max`.");return void 0!==e&&o.push(`(min-width: ${Ie(e,n)})`),void 0!==t&&o.push(`(max-width: ${Ie(t,n)})`),r&&o.push(`(orientation: ${r})`),o.length?`@media ${o.join(" and ")}`:""},Be=(e,{min:t,max:r},n)=>{const o=[];if(void 0!==t&&void 0!==r&&t>r)throw new y("REFRACT_E_MEDIA","Invalid container query: `min` cannot be greater than `max`.");return void 0!==t&&o.push(`(min-width: ${Ie(t,n)})`),void 0!==r&&o.push(`(max-width: ${Ie(r,n)})`),o.length?`@container ${e} ${o.join(" and ")}`:""},Ue={xs:0,sm:576,md:768,lg:992,xl:1280},De=(e,t)=>{const r=Me(t),n={};for(const[t,o]of Object.entries(null!=e?e:{}))n[t]=Ne(o.sizes,e=>Be(t,{min:e.min,max:e.max},r));return n},Ve=new Set([3,6]),We=(e,t,r)=>Math.min(r,Math.max(t,e)),He=e=>We(e,0,255),Ge=e=>Math.round(1e3*We(e,0,1))/1e3,Ye=e=>{const t=e.replace(/^\s*#|\s*$/g,"");if(!Ve.has(t.length))throw new Error(`Unsupported hex length: "${t}". Use 3 or 6 digits.`);const r=3===t.length?t.replace(/(.)/g,"$1$1"):t;return[parseInt(r.substring(0,2),16),parseInt(r.substring(2,4),16),parseInt(r.substring(4,6),16)]},Je=e=>{if(3!==e.length)throw new Error(`Expected RGB tuple of length 3, received ${e.length}`);return`#${e.map(e=>{const t=He(Math.round(e)).toString(16);return 1===t.length?`0${t}`:t}).join("")}`},Ke=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i,Xe=e=>{const t=e.trim(),r=Ke.exec(t);return r?{rgb:[Number(r[1]),Number(r[2]),Number(r[3])],a:void 0===r[4]?1:Ge(Number(r[4]))}:{rgb:Ye(t),a:1}},Ze=(e,t=1)=>{const r=Ge(t),[n,o,s]=e,i=He(Math.round(n)),a=He(Math.round(o)),l=He(Math.round(s));return r>=1?`rgb(${i}, ${a}, ${l})`:`rgba(${i}, ${a}, ${l}, ${r})`},Qe=180/Math.PI,et=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),tt=e=>e>=.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,rt=e=>{const[t,r,n]=e,o=((e,t,r)=>{const n=.4122214708*e+.5363325363*t+.0514459929*r,o=.2119034982*e+.6806995451*t+.1073969566*r,s=.0883024619*e+.2817188376*t+.6299787005*r,i=Math.cbrt(n),a=Math.cbrt(o),l=Math.cbrt(s);return{L:.2104542553*i+.793617785*a-.0040720468*l,a:1.9779984951*i-2.428592205*a+.4505937099*l,b:.0259040371*i+.7827717662*a-.808675766*l}})(et(t/255),et(r/255),et(n/255)),s=Math.sqrt(o.a*o.a+o.b*o.b);let i=Math.atan2(o.b,o.a)*Qe;return i<0&&(i+=360),{L:100*o.L,C:s,h:i}},nt=e=>{const t=We(e.L,0,100)/100,r=e.h/Qe,n=Math.cos(r),o=Math.sin(r),s=e=>((e,t,r)=>{const n=e+.3963377774*t+.2158037573*r,o=e-.1055613458*t-.0638541728*r,s=e-.0894841775*t-1.291485548*r,i=n*n*n,a=o*o*o,l=s*s*s;return[4.0767416621*i-3.3077115913*a+.2309699292*l,-1.2684380046*i+2.6097574011*a-.3413193965*l,-.0041960863*i-.7034186147*a+1.707614701*l]})(t,e*n,e*o),i=e=>e.every(e=>e>=-1e-6&&e<=1.000001);let a=s(e.C);if(!i(a)){let t=0,r=e.C;for(let e=0;e<24;e++){const e=(t+r)/2;i(s(e))?t=e:r=e}a=s(t)}return[255*tt(We(a[0],0,1)),255*tt(We(a[1],0,1)),255*tt(We(a[2],0,1))]},ot=(e,t)=>{const{rgb:r,a:n}=Xe(e);return Ze(nt(t(rt(r))),n)},st=(e,t)=>ot(e,e=>({...e,L:We(e.L+t,0,100)})),it=(e,t)=>ot(e,e=>({...e,L:We(e.L-t,0,100)})),at=(e,t)=>ot(e,e=>({...e,L:We(t,0,100)})),lt=(e,t)=>ot(e,e=>({...e,h:((e.h+t)%360+360)%360})),ct=(e,t)=>ot(e,e=>({L:void 0===t.l?e.L:We(t.l,0,100),C:void 0===t.c?e.C:Math.max(0,e.C*t.c),h:void 0===t.h?e.h:((e.h+t.h)%360+360)%360})),ut=e=>{const{rgb:t,a:r}=Xe(e),n=Je(t);if(r>=1)return n;return`${n}${He(Math.round(255*r)).toString(16).padStart(2,"0")}`},dt=(e,t)=>{const{rgb:r}=Xe(e);return Ze(r,(e=>We(e,0,100))(t)/100)},ft={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},pt=e=>Math.round(1e3*Math.min(1,Math.max(0,e)))/1e3,mt=(e,t,r)=>{const n=(e%360+360)%360/60,o=(1-Math.abs(2*Math.min(1,Math.max(0,r))-1))*Math.min(1,Math.max(0,t)),s=o*(1-Math.abs(n%2-1)),i=Math.min(1,Math.max(0,r))-o/2,[a,l,c]=n<1?[o,s,0]:n<2?[s,o,0]:n<3?[0,o,s]:n<4?[0,s,o]:n<5?[s,0,o]:[o,0,s];return[255*(a+i),255*(l+i),255*(c+i)]},ht=/^oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*(?:\/\s*([\d.]+)(%?)\s*)?\)$/i,gt=/^hsla?\(\s*([\d.]+)(?:deg)?\s*[, ]\s*([\d.]+)%\s*[, ]\s*([\d.]+)%\s*(?:[,/]\s*([\d.]+)(%?)\s*)?\)$/i,bt=e=>{if("string"==typeof e){const t=(e=>{const t=e.trim(),r=ht.exec(t);if(r){const e="%"===r[2]?Number(r[1]):100*Number(r[1]),t=void 0===r[5]?1:pt("%"===r[6]?Number(r[5])/100:Number(r[5]));return{rgb:nt({L:e,C:Number(r[3]),h:Number(r[4])}),a:t}}const n=gt.exec(t);if(n){const e=void 0===n[4]?1:pt("%"===n[5]?Number(n[4])/100:Number(n[4]));return{rgb:mt(Number(n[1]),Number(n[2])/100,Number(n[3])/100),a:e}}const o=ft[t.toLowerCase()];if(o)return{rgb:Ye(o),a:1};try{return Xe(t)}catch{return null}})(e);if(!t)throw new y("REFRACT_E_COLOR_INPUT",`Invalid colour "${e}". Author a colour as a hex string ("#4dabf7"), an [r, g, b] tuple, or a CSS colour — oklch(), hsl()/hsla(), rgb()/rgba(), or a named keyword (e.g. "rebeccapurple"). A var(--…) can't be tonally derived at build time.`);return Ze(t.rgb,t.a)}if(!Array.isArray(e)||3!==e.length||e.some(e=>"number"!=typeof e))throw new y("REFRACT_E_COLOR_TUPLE",`Invalid colour tuple ${JSON.stringify(e)}. Use an [r, g, b] tuple with 0–255 channels (alpha comes from an \`alpha\` variant, not the base).`);const[t,r,n]=e;return Ze([t,r,n])},vt={lighten:(e,t)=>st(e,Number(t)),darken:(e,t)=>it(e,Number(t)),alpha:(e,t)=>dt(e,Number(t)),setL:(e,t)=>at(e,Number(t)),rotateHue:(e,t)=>lt(e,Number(t)),adjust:(e,t)=>ct(e,t)},yt=["light","lighter"],wt=["dark","darker"],$t=(e,t)=>{if(!e||!e.includes("."))return!1;const[r,n]=e.split(".");return`${r}.${n}`!=`colors.${t}`},kt=(e,t)=>{try{return bt(e)}catch(e){throw new y("REFRACT_E_COLOR_INPUT",`colors.${t}.text — ${e.message}`)}},xt=(e,t,r={})=>{var n;const o=((e,t)=>{let r=t;if(void 0!==t.text&&(r={...r,text:kt(t.text,e)}),t.variants){let n=!1;const o={};for(const[r,s]of Object.entries(t.variants))void 0!==s.text?(o[r]={...s,text:kt(s.text,`${e}.variants.${r}`)},n=!0):o[r]=s;n&&(r={...r,variants:o})}if(t.modes){let n=!1;const o=t.modes.map(t=>void 0!==t.text?(n=!0,{...t,text:kt(t.text,`${e}.modes.${t.mode}`)}):t);n&&(r={...r,modes:o})}return r})(e,t),s=(e=>{try{return Xe(e),!0}catch{return!1}})(o.base),i=!(!o.steps||!o.steps.length),a=Object.keys(r).length>0,l=void 0!==o.harmony;if((i||a||l)&&!s)throw new y("REFRACT_E_STEPS",`colors.${e} declares derived steps/variants but its base "${o.base}" is not a hex or [r,g,b] colour.`);const c=s?St(o,e):{},u=s?Rt(o,e):{},d=null!==(n=o.variants)&&void 0!==n?n:{},f={...c,...u,...d},p=Nt(e,o.base,f,r),m={...c,...u,...d,...p},h=At(o,e,m),g=jt(o,e,m);return Object.keys(m).length||h||g?{...o,...Object.keys(m).length?{variants:m}:{},...h?{modes:h}:{},...g?{responsive:g}:{}}:o},jt=(e,t,r)=>{const n=e.responsive;if(!n||!n.length)return;let o=!1;const s=n.map((e,n)=>{const s=e.ref,i=e.modifiers;if(!s||!Array.isArray(i)||!i.length){let t;for(const r of["base","text"]){const n=e[r];if("string"==typeof n||Array.isArray(n)){const o=bt(n);o!==n&&(t=null!=t?t:{...e},t[r]=o)}}return t&&(o=!0),null!=t?t:e}const a=r[s];if(!a)throw new y("REFRACT_E_VARIANT_REF",`colors.${t}.responsive[${n}] references unknown variant "${s}".`);if(void 0===a.base)throw new y("REFRACT_E_VARIANT_REF",`colors.${t}.responsive[${n}] references "${s}", a cross-property derivation — not supported.`);const l=_t({modifiers:i},t,`responsive[${n}]`);let c=a.base;for(const e of l)c=vt[e.fn](c,e.arg);o=!0;const{ref:u,modifiers:d,...f}=e;return{...f,base:c,derive:{ref:`colors.${t}.${s}`,modifiers:l}}});return o?s:n},At=(e,t,r)=>{const n=e.modes;if(!n||!n.length)return;return n.map(n=>{var o;const s=n.mode,i=n.derive;if(!i)return n;const a=null!==(o=i.modifiers)&&void 0!==o?o:i.fn?[{fn:i.fn,arg:i.arg}]:[];if($t(i.ref,t)){const{base:e,derive:t,...r}=n;return{...r,derive:{ref:i.ref,modifiers:a}}}const l=((n,o)=>{if(!n||n===`colors.${t}`)return{value:e.base,path:`colors.${t}`};const s=n.includes(".")?n.slice(`colors.${t}.`.length):n,i=r[s];if(!i||void 0===i.base)throw new y("REFRACT_E_VARIANT_REF",`colors.${t}.modes.${o} references unknown variant "${n}".`);return{value:i.base,path:`colors.${t}.${s}`}})(i.ref,s);let c=l.value;for(const e of a){const r=vt[e.fn];if(!r)throw new y("REFRACT_E_VARIANT_REF",`Unknown derivation fn "${e.fn}" for appearance mode "colors.${t}.modes.${s}".`);c=r(c,e.arg)}return{...n,base:c,derive:{ref:l.path,modifiers:a}}})},St=(e,t)=>e.steps&&e.steps.length?Ft(e,t):Ot(e,t),Et={complement:[{name:"complement",deg:180}],analogous:[{name:"analogous1",deg:-30},{name:"analogous2",deg:30}],"split-complement":[{name:"split1",deg:150},{name:"split2",deg:210}],triadic:[{name:"triadic1",deg:120},{name:"triadic2",deg:240}],tetradic:[{name:"tetradic1",deg:90},{name:"complement",deg:180},{name:"tetradic2",deg:270}]},Rt=(e,t)=>{const r=e.harmony;if(void 0===r)return{};let n,o;if("string"==typeof r)n=r;else{if("object"!=typeof r||null===r||Array.isArray(r))throw new y("REFRACT_E_HARMONY",`colors.${t}.harmony must be a scheme name or a { scheme: [names] } object.`);{const e=Object.keys(r);if(1!==e.length)throw new y("REFRACT_E_HARMONY",`colors.${t}.harmony object form must name exactly one scheme; got [${e.join(", ")}].`);n=e[0],o=r[n]}}const s=Et[n];if(!s)throw new y("REFRACT_E_HARMONY",`colors.${t}.harmony: unknown scheme "${n}". Use one of ${Object.keys(Et).join(", ")}.`);const i={};return s.forEach((r,n)=>{var s;const a=null!==(s=null==o?void 0:o[n])&&void 0!==s?s:r.name;i[a]={base:lt(e.base,r.deg),derive:{ref:`colors.${t}`,fn:"rotateHue",arg:r.deg}}}),i},Ct=(e,t,r,n,o,s,i,a)=>{var l;const c=e=>e?`colors.${r}.${e}`:`colors.${r}`;let u,d=t.base;for(const t of o){if(void 0!==(null===(l=n[t])||void 0===l?void 0:l.base)){d=n[t].base,u=t;continue}const r=s(d,a);e[t]={base:r,derive:{ref:c(u),fn:i,arg:a}},d=r,u=t}},Ot=(e,t)=>{var r,n,o;const s=null!==(r=e.variants)&&void 0!==r?r:{},i={},a=null!==(n=e.lightenBy)&&void 0!==n?n:10,l=null!==(o=e.darkenBy)&&void 0!==o?o:10;return Ct(i,e,t,s,yt,st,"lighten",a),Ct(i,e,t,s,wt,it,"darken",l),i},Tt=e=>e<=0?100:e>=1e3?0:Math.min(98,Math.max(5,(1e3-e)/10)),Ft=(e,t)=>{var r,n;const o=null!==(r=e.steps)&&void 0!==r?r:[],s=o.find(e=>"number"!=typeof e||isNaN(e)||e<0||e>1e3);if(void 0!==s)throw new y("REFRACT_E_STEPS",`colors.${t}.steps must be numbers in 0–1000 (e.g. [50, …, 950]); got ${JSON.stringify(s)}.`);const i=null!==(n=e.variants)&&void 0!==n?n:{},a={};for(const r of o){const n=r.toString();if(i[n])continue;const o=Tt(r);a[n]={base:at(e.base,o),derive:{ref:`colors.${t}`,fn:"setL",arg:o}}}return a},_t=(e,t,r)=>{const n=`colors.${t}.variants.${r}`,o=e.modifiers;if(!Array.isArray(o)||0===o.length)throw new y("REFRACT_E_VARIANT",`${n} needs a non-empty "modifiers" array (e.g. [{ darken: 10 }]).`);return o.map((e,o)=>{if("object"!=typeof e||null===e||Array.isArray(e))throw new y("REFRACT_E_VARIANT",`${n}.modifiers[${o}] must be a single-key object like { darken: 10 }.`);const s=Object.keys(e);if(1!==s.length)throw new y("REFRACT_E_VARIANT",`${n}.modifiers[${o}] must have exactly one fn key; got [${s.join(", ")}].`);const i=s[0];if(!vt[i])throw new y("REFRACT_E_VARIANT",`${n}.modifiers[${o}] unknown fn "${i}"; use ${Object.keys(vt).join(" / ")}.`);const a=e[i],l="adjust"===i?((e,t,r)=>{const n=`colors.${t}.variants.${r}.adjust`;if("object"!=typeof e||null===e||Array.isArray(e))throw new y("REFRACT_E_ADJUST",`${n} must be an object with numeric l / c / h dials.`);const{l:o,c:s,h:i}=e,a={};if(void 0!==o){if("number"!=typeof o||isNaN(o)||o<0||o>100)throw new y("REFRACT_E_ADJUST",`${n}.l must be an absolute OKLCH lightness in 0–100; got ${JSON.stringify(o)}.`);a.l=o}if(void 0!==s){if("number"!=typeof s||isNaN(s)||s<0)throw new y("REFRACT_E_ADJUST",`${n}.c must be a non-negative chroma multiplier (1 keeps, 0 greys); got ${JSON.stringify(s)}.`);a.c=s}if(void 0!==i){if("number"!=typeof i||isNaN(i))throw new y("REFRACT_E_ADJUST",`${n}.h must be a numeric hue rotation in degrees; got ${JSON.stringify(i)}.`);a.h=i}return a})(a,t,r):Number(a);return{fn:i,arg:l}})},Nt=(e,t,r,n)=>{const o={},s=new Set,i=(t,r)=>{if(void 0===t.base)throw new y("REFRACT_E_VARIANT_REF",`colors.${e} variant chains off "${r}", which is a cross-property derivation — not supported.`);return t.base};function a(l,c){if(o[l])return;if(s.has(l))throw new y("REFRACT_E_CYCLE",`Cyclic colour variant derivation at colors.${e}.${l}.`);s.add(l);const u=_t(c,e,l);if($t(c.ref,e))return o[l]={derive:{ref:c.ref,modifiers:u}},void s.delete(l);const d=(s=>{if(!s)return{value:t,path:`colors.${e}`};if(o[s])return{value:i(o[s],s),path:`colors.${e}.${s}`};if(r[s])return{value:i(r[s],s),path:`colors.${e}.${s}`};if(n[s])return a(s,n[s]),{value:i(o[s],s),path:`colors.${e}.${s}`};throw new y("REFRACT_E_VARIANT_REF",`colors.${e} variant references unknown source "${s}".`)})(c.ref);let f=d.value;for(const e of u)f=vt[e.fn](f,e.arg);o[l]={base:f,derive:{ref:d.path,modifiers:u}},s.delete(l)}for(const[e,t]of Object.entries(n))a(e,t);return o},Pt=new Set("display position top right bottom left inset inset-block inset-block-start inset-block-end inset-inline inset-inline-start inset-inline-end float clear z-index visibility overflow overflow-x overflow-y overflow-block overflow-inline overflow-clip-margin overflow-anchor box-sizing width height min-width min-height max-width max-height block-size inline-size min-block-size min-inline-size max-block-size max-inline-size aspect-ratio margin margin-top margin-right margin-bottom margin-left margin-block margin-block-start margin-block-end margin-inline margin-inline-start margin-inline-end margin-trim padding padding-top padding-right padding-bottom padding-left padding-block padding-block-start padding-block-end padding-inline padding-inline-start padding-inline-end flex flex-grow flex-shrink flex-basis flex-direction flex-flow flex-wrap order justify-content justify-items justify-self align-content align-items align-self place-content place-items place-self gap row-gap column-gap grid grid-area grid-template grid-template-areas grid-template-columns grid-template-rows grid-auto-columns grid-auto-rows grid-auto-flow grid-column grid-column-start grid-column-end grid-row grid-row-start grid-row-end columns column-count column-width column-gap column-rule column-rule-color column-rule-style column-rule-width column-span column-fill color opacity accent-color caret-color color-scheme forced-color-adjust print-color-adjust background background-color background-image background-position background-position-x background-position-y background-size background-repeat background-origin background-clip background-attachment background-blend-mode mix-blend-mode isolation border border-width border-style border-color border-top border-top-width border-top-style border-top-color border-right border-right-width border-right-style border-right-color border-bottom border-bottom-width border-bottom-style border-bottom-color border-left border-left-width border-left-style border-left-color border-block border-block-width border-block-style border-block-color border-block-start border-block-start-width border-block-start-style border-block-start-color border-block-end border-block-end-width border-block-end-style border-block-end-color border-inline border-inline-width border-inline-style border-inline-color border-inline-start border-inline-start-width border-inline-start-style border-inline-start-color border-inline-end border-inline-end-width border-inline-end-style border-inline-end-color border-radius border-top-left-radius border-top-right-radius border-bottom-right-radius border-bottom-left-radius border-start-start-radius border-start-end-radius border-end-start-radius border-end-end-radius border-image border-image-source border-image-slice border-image-width border-image-outset border-image-repeat border-collapse border-spacing outline outline-width outline-style outline-color outline-offset box-shadow filter backdrop-filter clip-path mask mask-image mask-mode mask-repeat mask-position mask-clip mask-origin mask-size mask-composite mask-type opacity transform transform-origin transform-box transform-style perspective perspective-origin backface-visibility rotate scale translate transition transition-property transition-duration transition-timing-function transition-delay transition-behavior animation animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-fill-mode animation-play-state animation-composition animation-timeline will-change font font-family font-size font-size-adjust font-weight font-style font-variant font-variant-caps font-variant-numeric font-variant-ligatures font-variant-east-asian font-variant-alternates font-variant-position font-feature-settings font-variation-settings font-kerning font-stretch font-optical-sizing font-synthesis font-display line-height letter-spacing word-spacing text-align text-align-last text-decoration text-decoration-line text-decoration-color text-decoration-style text-decoration-thickness text-decoration-skip-ink text-underline-offset text-underline-position text-transform text-indent text-overflow text-shadow text-rendering text-wrap text-wrap-mode text-wrap-style text-emphasis text-emphasis-color text-emphasis-style text-emphasis-position text-orientation text-combine-upright text-justify white-space white-space-collapse word-break word-wrap overflow-wrap hyphens hyphenate-character line-break tab-size vertical-align writing-mode direction unicode-bidi quotes content list-style list-style-type list-style-position list-style-image counter-reset counter-increment counter-set cursor pointer-events user-select touch-action resize appearance caret scroll-behavior scroll-margin scroll-margin-top scroll-margin-right scroll-margin-bottom scroll-margin-left scroll-padding scroll-padding-top scroll-padding-right scroll-padding-bottom scroll-padding-left scroll-snap-type scroll-snap-align scroll-snap-stop overscroll-behavior overscroll-behavior-x overscroll-behavior-y scrollbar-width scrollbar-color scrollbar-gutter table-layout caption-side empty-cells vertical-align object-fit object-position image-rendering fill fill-opacity fill-rule stroke stroke-width stroke-opacity stroke-linecap stroke-linejoin stroke-dasharray stroke-dashoffset stroke-miterlimit paint-order shape-rendering stop-color flood-color lighting-color container container-type container-name contain content-visibility break-before break-after break-inside page-break-before page-break-after page-break-inside orphans widows all cx cy r rx ry d".split(" ")),zt=/^-(webkit|moz|ms|o)-/,qt=e=>{if(e.startsWith("--"))return!0;const t=e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();return!!zt.test(t)||Pt.has(t)},Mt=new Set(["breakpoint","query","state","variant","target","orientation"]),It=(e,t,r)=>{const n={};if(!e)return n;for(const[o,s]of Object.entries(e)){if(void 0===s||Mt.has(o))continue;if(!qt(o))throw new y("REFRACT_E_RECIPE_PROPERTY",`Unknown recipe property "${o}" in ${r} — expected a CSS property or a reserved key (variant, target, state, breakpoint, query, orientation, container, size).`);const e=Lt(s,t,r,o);void 0!==e&&(n[Bt(o)]=e)}return n},Lt=(e,t,r,n)=>{var o;if("number"==typeof e)return{value:e};const s=e.trim();if(!s)return;const i=s.split("."),a=i[0],l=t.properties[a];if(!l)return{value:s};const c=i.length>1?i.slice(1).join("."):void 0;if(!c)return{ref:`colors.${a}`};if("text"===c)return{ref:`colors.${a}.text`};if(!(null===(o=l.variants)||void 0===o?void 0:o[c]))throw new y("REFRACT_E_VARIANT_REF",`Unknown palette variant reference "${a}.${c}" in ${r}.${n}.`);return{ref:`colors.${a}.${c}`}},Bt=e=>e.startsWith("--")?e:e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ut=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),Dt=([e,t,r])=>.2126*Ut(e/255)+.7152*Ut(t/255)+.0722*Ut(r/255),Vt={fail:0,"AA-large":1,AA:2,AAA:3},Wt=2.4,Ht=.2126729,Gt=.7151522,Yt=.072175,Jt=.56,Kt=.57,Xt=.62,Zt=.65,Qt=.022,er=1.414,tr=1.14,rr=.027,nr=1.14,or=.027,sr=5e-4,ir=.1,ar=([e,t,r])=>Ht*Math.pow(e/255,Wt)+Gt*Math.pow(t/255,Wt)+Yt*Math.pow(r/255,Wt),lr=(e,t)=>{const r=e=>e>Qt?e:e+Math.pow(Qt-e,er),n=r(ar(e)),o=r(ar(t));if(Math.abs(o-n)<sr)return 0;let s;if(o>n){const e=(Math.pow(o,Jt)-Math.pow(n,Kt))*tr;s=e<ir?0:e-rr}else{const e=(Math.pow(o,Zt)-Math.pow(n,Xt))*nr;s=e>-ir?0:e+or}return 100*s},cr=(e,t)=>{const r=10**t;return Math.round(e*r)/r},ur=(e,t)=>{if(void 0!==t.ref)try{return String(e.resolveToken(t.ref))}catch{return}if("string"==typeof t.value)return t.value},dr="color",fr=["background-color","background"],pr=e=>{if(e)for(const t of fr)if(e[t])return e[t]},mr=(e,t,r,n,o)=>{let s,i;try{void 0!==r&&(s=Xe(r).rgb)}catch{}try{void 0!==n&&(i=Xe(n).rgb)}catch{}if(!s||!i)return{kind:e,label:t,fg:r,bg:n,skipped:s||i?s?"bg not a colour":"fg not a colour":"no derivable fg/bg"};const a=((e,t)=>{const r=Dt(e),n=Dt(t);return(Math.max(r,n)+.05)/(Math.min(r,n)+.05)})(s,i),l=((e,t)=>t?e>=4.5?"AAA":e>=3?"AA":"fail":e>=7?"AAA":e>=4.5?"AA":e>=3?"AA-large":"fail")(a,o.largeText),c=Vt[l]>=Vt[o.minWcag];return{kind:e,label:t,fg:r,bg:n,wcagRatio:cr(a,2),wcagLevel:l,apcaLc:cr(lr(s,i),1),pass:c}},hr=(e,t={})=>{var r,n,o,s,i,a,l,c,u,d,f;const p={largeText:null!==(r=t.largeText)&&void 0!==r&&r,minWcag:null!==(n=t.minWcag)&&void 0!==n?n:"AA"},m=null===(o=t.includeRecipes)||void 0===o||o,h=[];if(null===(s=t.includePalettes)||void 0===s||s)for(const t of Object.keys(e.tokens)){const r=/^colors\.([^.]+)\.text$/.exec(t);if(!r)continue;const n=`colors.${r[1]}`;let o,s;try{o=String(e.resolveToken(t))}catch{}try{s=String(e.resolveToken(n))}catch{}h.push(mr("palette",n,o,s,p))}if(m)for(const[t,r]of Object.entries(e.model.subsystems))if(r.ruleSets)for(const[n,o]of Object.entries(r.ruleSets))for(const[r,s]of Object.entries(o)){const o=s.declarations[dr],m=pr(s.declarations),g=`${t}.${n}.${r}`;o&&m&&h.push(mr("recipe",g,ur(e,o),ur(e,m),p));for(const t of null!==(i=s.overrides)&&void 0!==i?i:[]){const r=null!==(l=null===(a=t.declarations)||void 0===a?void 0:a[dr])&&void 0!==l?l:o,n=null!==(c=pr(t.declarations))&&void 0!==c?c:m;if(!t.declarations||!t.declarations[dr]&&!pr(t.declarations))continue;if(!r||!n)continue;const s=null!==(f=null!==(d=null!==(u=t.state)&&void 0!==u?u:t.breakpoint)&&void 0!==d?d:t.query)&&void 0!==f?f:"override";h.push(mr("recipe",`${g} (${s})`,ur(e,r),ur(e,n),p))}}const g=h.filter(e=>!e.skipped),b=g.filter(e=>!1===e.pass),v=g.reduce((e,t)=>{var r,n;return void 0===e||(null!==(r=t.wcagRatio)&&void 0!==r?r:1/0)<(null!==(n=e.wcagRatio)&&void 0!==n?n:1/0)?t:e},void 0),w={pairings:h,summary:{total:g.length,passed:g.length-b.length,failed:b.length,skipped:h.length-g.length,worst:v},ok:0===b.length};if(t.strict&&b.length>0){const e=b.map(e=>`${e.label} (${e.wcagRatio}:1, ${e.wcagLevel})`).join(", ");throw new y("REFRACT_E_AUDIT",`refract audit: ${b.length} pairing(s) fail WCAG ${p.minWcag} — ${e}. Adjust the colour(s), lower --min-wcag, or drop --strict to report without failing.`,b.map(e=>`${e.label} (${e.wcagRatio}:1, ${e.wcagLevel})`))}return w},gr=new Set(["recipes"]),br=e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&!("base"in e)&&Array.isArray(e.modifiers),vr=e=>{if("object"!=typeof e||null===e||Array.isArray(e)||!e.variants)return{value:e,specs:{}};const t=e.variants,r={},n={};for(const[e,o]of Object.entries(t))br(o)?r[e]=o:n[e]=o;if(!Object.keys(r).length)return{value:e,specs:r};const o=Object.keys(n).length?n:void 0;return{value:{...e,variants:o},specs:r}},yr={key:"colors",derivations:{lighten:(e,t)=>st(String(e),Number(t)),darken:(e,t)=>it(String(e),Number(t)),alpha:(e,t)=>dt(String(e),Number(t)),setL:(e,t)=>at(String(e),Number(t)),rotateHue:(e,t)=>lt(String(e),Number(t)),adjust:(e,t)=>ct(String(e),t)},normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(gr.has(n))continue;const{value:e,specs:s}=vr(o),i=le(e,{propertyPath:`colors.${n}`,allowedBreakpoints:t.allowedBreakpoints,coerceValue:bt}),a=xt(n,i,s);Q(a,{propertyPath:`colors.${n}`}),r[n]=a}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>{const n=`${r.groupPath}.${e}`;return{base:It(t.base,r,n),responsive:t.responsive.map(e=>{const{breakpoint:t,query:o,state:s,variant:i,target:a,orientation:l,container:c,size:u,...d}=e,f={declarations:{...i?{...r.resolveRecipeVariant(i).base}:{},...It(d,r,`${n}.responsive`)}};return t&&(f.breakpoint=t,f.query=null!=o?o:"exact"),c&&(f.container=c,u&&(f.size=u),f.query=null!=o?o:"min"),s&&(f.state=s),l&&(f.orientation=l),a&&(f.target=a),f})}})(e,t,r)},wr={"minor-second":1.067,"major-second":1.125,"minor-third":1.2,"major-third":1.25,"perfect-fourth":1.333,"augmented-fourth":1.414,"perfect-fifth":1.5,golden:1.618},$r={xs:-2,sm:-1,md:0,lg:1,xl:2,"2xl":3,"3xl":4,"4xl":5},kr=(e,t)=>"fontSize"!==e?t:xr(t),xr=e=>{var t,r,n,o;const s=e.ratio;if(!s)return e;const i=wr[s];if(!i)return e;const a=null!==(t=e.baseFontSize)&&void 0!==t?t:e.base,l=null!==(r=e.precision)&&void 0!==r?r:4,c=e.algorithm,u=null!==(n=e.variants)&&void 0!==n?n:{},d={};let f=null;for(const[e,t]of Object.entries($r)){if(u[e]){f=null!==(o=u[e].base)&&void 0!==o?o:null;continue}let r;r=c?c(a,e,t,f):a*Math.pow(i,t);const n=Number(r.toFixed(l));f=n,d[e]={base:n}}return{...e,variants:{...d,...u}}},jr=new Set(["breakpoint","query","state","variant","target","orientation"]),Ar={fontFamily:"font-family",fontSize:"font-size",fontWeight:"font-weight",lineHeight:"line-height",letterSpacing:"letter-spacing",fontStyle:"font-style",textTransform:"text-transform",textDecoration:"text-decoration",textAlign:"text-align"},Sr=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e)){if(!n||jr.has(r))continue;const e=Ar[r];e&&(t[e]={ref:Er(r,n)})}return t},Er=(e,t)=>"base"===t?`typography.${e}`:`typography.${e}.${t}`,Rr=new Set(["recipes"]),Cr={key:"typography",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(Rr.has(n))continue;const e=le(o,{propertyPath:`typography.${n}`,allowedBreakpoints:t.allowedBreakpoints}),s=kr(n,e);Q(s,{propertyPath:`typography.${n}`}),r[n]=s}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>({base:Sr(t.base),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:o,variant:s,target:i,orientation:a,container:l,size:c,...u}=e,d={declarations:{...s?{...r.resolveRecipeVariant(s).base}:{},...Sr(u)}};return t&&(d.breakpoint=t,d.query=null!=n?n:"exact"),l&&(d.container=l,c&&(d.size=c),d.query=null!=n?n:"min"),o&&(d.state=o),i&&(d.target=i),a&&(d.orientation=a),d})}))(0,t,r)},Or=["spacing","gutters","aspectRatio","sizes"],Tr=new Set(["spacing","gutters","sizes"]),Fr=new Set(["spacing","gutters"]),_r=["xs","sm","md","lg","xl","2xl","3xl","4xl"],Nr=e=>Number(e.toFixed(4)),Pr=(e,t)=>{var r;if(!Tr.has(e))return t;const n=((e,t)=>{const r=t,n=void 0!==r.ratio,o=void 0!==r.step;if(!n&&!o)return;if(n&&o)throw new y("REFRACT_E_LAYOUT",`layout.${e}: declare only one of "ratio" (geometric) or "step" (linear) scale, not both.`);const s=r.steps;if(n){let t;if(void 0===s)t=_r;else{if(!Array.isArray(s))throw new y("REFRACT_E_LAYOUT",`layout.${e}: a geometric scale ("ratio") needs "steps" as an ordered name array, e.g. ["sm","md","lg"].`);t=s.map(String)}const n=t.map((e,t)=>({name:e,exp:t}));return{curve:"geometric",ratio:Number(r.ratio),specs:n}}let i;if(void 0===s)i=_r.map((e,t)=>({name:e,exp:t,mult:t+1}));else{if(Array.isArray(s)||"object"!=typeof s||null===s)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a linear scale ("step") needs "steps" as a name→multiplier map, e.g. { sm:1, md:2, lg:3 }.`);i=Object.entries(s).map(([e,t],r)=>({name:e,exp:r,mult:Number(t)}))}return{curve:"linear",step:Number(r.step),specs:i}})(e,t);if(!n)return Fr.has(e)?zr(t):t;const o=((e,t,r)=>{const n=`layout.${e}`,o={};for(const e of r.specs)if("geometric"===r.curve){const s=Nr(Number(t)*Math.pow(r.ratio,e.exp));o[e.name]={base:s,derive:{ref:n,fn:"scaleStep",arg:{curve:"geometric",ratio:r.ratio,exp:e.exp}}}}else{const t=Nr(r.step*e.mult);o[e.name]={base:t,derive:{ref:n,fn:"scaleStep",arg:{curve:"linear",step:r.step,mult:e.mult}}}}return o})(e,t.base,n);let s={...o,...null!==(r=t.variants)&&void 0!==r?r:{}};Fr.has(e)&&(s={...s,none:{base:0}});const i=((e,t,r,n)=>{if(!(null==r?void 0:r.length))return r;const o=`layout.${e}`,s=[];let i=!1;for(const a of r){const r=a;if(void 0===r.ratio&&void 0===r.step){s.push(r);continue}if(i=!0,void 0!==r.ratio&&void 0!==r.step)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a responsive ramp entry may set only "ratio" or "step", not both.`);if(!n)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a responsive ramp entry needs a base scale — declare a top-level "ratio"/"step" (+ "steps") first.`);const{breakpoint:l,query:c,orientation:u}=r,d=void 0!==r.ratio;for(const i of n.specs){let n,a;if(d){const e=Number(r.ratio),o=void 0!==r.base,s=Number(o?r.base:t);n=Nr(s*Math.pow(e,i.exp)),a={curve:"geometric",ratio:e,exp:i.exp,...o?{base:s}:{}}}else{if(void 0===i.mult)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a linear responsive ramp ("step") requires a linear base scale (a name→multiplier "steps").`);const t=Number(r.step);n=Nr(t*i.mult),a={curve:"linear",step:t,mult:i.mult}}const f={breakpoint:l,query:c,target:i.name,base:n,derive:{ref:o,fn:"scaleStep",arg:a}};void 0!==u&&(f.orientation=u),s.push(f)}}return i?s:r})(e,t.base,t.responsive,n);return(e=>{const{ratio:t,step:r,steps:n,...o}=e;return o})({...t,variants:s,responsive:i})},zr=e=>{var t;const r=null!==(t=e.variants)&&void 0!==t?t:{};return{...e,variants:{...r,none:{base:0}}}},qr=new Set(["breakpoint","query","state","variant","target","orientation"]),Mr={paddingY:["padding-top","padding-bottom"],paddingX:["padding-left","padding-right"],marginY:["margin-top","margin-bottom"],marginX:["margin-left","margin-right"],gap:["gap"],background:["background"],width:["width"],minWidth:["min-width"],maxWidth:["max-width"],height:["height"],minHeight:["min-height"],maxHeight:["max-height"]},Ir={paddingY:"spacing",paddingX:"spacing",marginY:"spacing",marginX:"spacing",gap:"spacing",width:"sizes",minWidth:"sizes",maxWidth:"sizes",height:"sizes",minHeight:"sizes",maxHeight:"sizes",background:"literal"},Lr=(e,t)=>"base"===t?`layout.${e}`:`layout.${e}.${t}`,Br=(e,t)=>{const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(qr.has(n))continue;if(!o)continue;const e=Mr[n];if(!e)throw new y("REFRACT_E_LAYOUT",`Unknown layout recipe property "${n}" in ${t}. Known verbs: ${Object.keys(Mr).join(", ")}. For arbitrary CSS use a component \`css\` delta.`);const s=Ir[n];for(const t of e)r[t]="literal"===s?{value:o}:{ref:Lr(s,o)}}return r},Ur=e=>({ref:"base"===e?"layout.spacing":`layout.spacing.${e}`}),Dr=e=>({ref:"base"===e?"layout.gutters":`layout.gutters.${e}`}),Vr=e=>({ref:`layout.${e}`}),Wr=e=>({value:e}),Hr=e=>Object.keys(e).sort((t,r)=>e[t]-e[r]),Gr=[["templateColumns","grid-template-columns"],["templateRows","grid-template-rows"],["autoRows","grid-auto-rows"],["autoColumns","grid-auto-columns"],["justifyItems","justify-items"],["alignItems","align-items"],["justifyContent","justify-content"],["alignContent","align-content"]],Yr=(e,t)=>{const r={};t&&(r.display=Wr("grid"));for(const[t,n]of Gr){const o=e[t];o&&(r[n]=Wr(o))}return e.gap&&(r.gap=Ur(e.gap)),r},Jr=e=>{var t,r;if(!e||"string"==typeof e)return{mode:null!==(t=e)&&void 0!==t?t:"fixed"};const n=e;return{mode:null!==(r=n.base)&&void 0!==r?r:"fixed",inset:n.inset,gutter:n.gutter,direction:n.direction,align:n.align,justify:n.justify,maxWidth:n.maxWidth}},Kr=(e,t,r=new Set,n)=>{var o,s,i,a;const l=Me(n),c=e=>Ie(e,l),u={},d={},f=Hr(t),p=e&&"object"==typeof e?e:void 0,m=p?{mode:null!==(o=p.base)&&void 0!==o?o:"fixed",inset:p.inset,gutter:p.gutter,direction:p.direction,align:p.align,justify:p.justify,maxWidth:p.maxWidth}:Jr(null!=e?e:"fixed"),h=null!==(s=null==p?void 0:p.variants)&&void 0!==s?s:{},g=null!==(i=null==p?void 0:p.responsive)&&void 0!==i?i:[],b=e=>e?`container-${e}`:"container",v=(e,n)=>{var o,s,i,a,l,p,h,g,v;const y=e?`--${e}`:"",w=`container${y}--inset`,$=`container${y}--gutter`,k=null!==(s=null!==(o=n.inset)&&void 0!==o?o:m.inset)&&void 0!==s?s:"base",x=null!==(i=n.gutter)&&void 0!==i?i:m.gutter,j=null!==(l=null!==(a=n.mode)&&void 0!==a?a:m.mode)&&void 0!==l?l:"fixed",A=null!==(p=n.direction)&&void 0!==p?p:m.direction,S=null!==(h=n.align)&&void 0!==h?h:m.align,E=null!==(g=n.justify)&&void 0!==g?g:m.justify,R=null!==(v=n.maxWidth)&&void 0!==v?v:e?m.maxWidth:void 0;u[w]={base:Ur(k)},x&&(u[$]={base:Dr(x)});const C={"box-sizing":Wr("border-box"),width:Wr("100%"),"margin-left":Wr("auto"),"margin-right":Wr("auto"),"padding-left":Vr(w),"padding-right":Vr(w)};x&&(C.gap=Vr($)),A&&(C.display=Wr("flex"),C["flex-direction"]=Wr(A)),S&&(C["align-items"]=Wr(S)),E&&(C["justify-content"]=Wr(E));const O=[];if("fixed"===j){const e="string"==typeof R&&void 0!==t[R]?R:void 0,r=e?f.indexOf(e):-1;for(let n=0;n<f.length;n++){const o=f[n],s=t[r>=0&&n>r?e:o];0!==s?0===n?C["max-width"]=Wr(c(s)):O.push({breakpoint:o,query:"min",declarations:{"max-width":Wr(c(s))}}):0===n&&(C["max-width"]=Wr("none"))}}else"fluid"===j?void 0!==R&&(C["max-width"]=((e,t,r)=>{return"number"==typeof e?Wr(`${e}px`):t.has(e)?{ref:"base"===(n=e)?"layout.sizes":`layout.sizes.${n}`}:void 0!==r[e]?Wr(`${r[e]}px`):Wr(e);var n})(R,r,t)):C["max-width"]=Wr("number"==typeof j?`${j}px`:j);d[b(e)]={kind:"recipe",declarations:C,overrides:O}};v(null,m);for(const[e,t]of Object.entries(h))v(e,Jr(t));for(const e of g){const t=e.target,r=b(null!=t?t:null),n=d[r];if(!n)continue;const o={};if(e.direction&&(o["flex-direction"]=Wr(e.direction)),e.align&&(o["align-items"]=Wr(e.align)),e.justify&&(o["justify-content"]=Wr(e.justify)),e.inset){const e=t?`container--${t}--inset`:"container--inset";o["padding-left"]=Vr(e),o["padding-right"]=Vr(e)}if(e.gutter){const e=t?`container--${t}--gutter`:"container--gutter";o.gap=Vr(e)}Object.keys(o).length&&n.overrides.push({breakpoint:e.breakpoint,query:null!==(a=e.query)&&void 0!==a?a:"exact",declarations:o})}return{ruleSetGroups:{container:d},configProperties:u}},Xr=(e,t,r)=>{const n={},o={},s=e=>{e&&(Object.assign(n,e.ruleSetGroups),Object.assign(o,e.configProperties))};return s(((e,t)=>{var r,n;if(!e)return;const o="number"==typeof e?{size:e}:e,s=o.size,i=null!==(r=o.gutter)&&void 0!==r?r:"base",a=null!==(n=o.inset)&&void 0!==n?n:"none",l={"columns--size":{base:Wr(String(s))},"columns--gutter":{base:Dr(i)},"columns--inset":{base:Ur(a)}},c={},u=Array.from({length:s},(e,t)=>t+1);for(const e of Hr(t))for(const r of u){const n=`col-${e}-${r}`,o=`offset-${e}-${r}`,s={"grid-column-end":Wr(`span ${r}`)},i={"grid-column-start":Wr(String(r+1))};0===t[e]?(c[n]={kind:"utility",declarations:s,overrides:[]},c[o]={kind:"utility",declarations:i,overrides:[]}):(c[n]={kind:"utility",declarations:{},overrides:[{breakpoint:e,query:"min",declarations:s}]},c[o]={kind:"utility",declarations:{},overrides:[{breakpoint:e,query:"min",declarations:i}]})}return{ruleSetGroups:{columns:c},configProperties:l}})(e.columns,t)),s((e=>{var t,r;if(!e||!Object.keys(e).length)return;const n={};for(const[o,s]of Object.entries(e)){const e=Yr(s,!0),i=[];for(const e of null!==(t=s.responsive)&&void 0!==t?t:[]){const t=Yr(e,!1);Object.keys(t).length&&i.push({breakpoint:e.breakpoint,query:null!==(r=e.query)&&void 0!==r?r:"exact",declarations:t})}n[`grid-${o}`]={kind:"recipe",declarations:e,overrides:i}}return{ruleSetGroups:{grids:n},configProperties:{}}})(e.grids)),s((e=>{var t,r,n;if(!e||!Object.keys(e).length)return;const o={};for(const[s,i]of Object.entries(e)){const e={display:Wr(i.inline?"inline-flex":"flex"),"flex-direction":Wr(null!==(t=i.direction)&&void 0!==t?t:"column")};i.align&&(e["align-items"]=Wr(i.align)),i.justify&&(e["justify-content"]=Wr(i.justify)),i.wrap&&(e["flex-wrap"]=Wr(i.wrap)),i.gap&&(e.gap=Ur(i.gap));const a=[];for(const e of null!==(r=i.responsive)&&void 0!==r?r:[]){const t={};void 0!==e.inline&&(t.display=Wr(e.inline?"inline-flex":"flex")),e.direction&&(t["flex-direction"]=Wr(e.direction)),e.align&&(t["align-items"]=Wr(e.align)),e.justify&&(t["justify-content"]=Wr(e.justify)),e.wrap&&(t["flex-wrap"]=Wr(e.wrap)),Object.keys(t).length&&a.push({breakpoint:e.breakpoint,query:null!==(n=e.query)&&void 0!==n?n:"exact",declarations:t})}o[`stack-${s}`]={kind:"recipe",declarations:e,overrides:a}}return{ruleSetGroups:{stacks:o},configProperties:{}}})(e.stacks)),s(Kr(e.container,t,(e=>{const t=new Set;if(e&&"object"==typeof e&&!Array.isArray(e)){const r=e;"base"in r&&t.add("base");const n=r.variants;if(n&&"object"==typeof n)for(const e of Object.keys(n))t.add(e)}return t})(e.sizes),r)),{ruleSetGroups:n,configProperties:o}},Zr=new Set(Or),Qr={key:"layout",derivations:{scaleStep:(e,t)=>((e,t)=>{const r=null!=t?t:{};if("linear"===r.curve)return Nr(Number(r.step)*Number(r.mult));const n=void 0!==r.base?Number(r.base):Number(e);return Nr(n*Math.pow(Number(r.ratio),Number(r.exp)))})(e,t)},normalizeProperties(e,t){const r={};if(!e)return r;for(const n of Or){const o=e[n];if(void 0===o||!Zr.has(n))continue;const s=le(o,{propertyPath:`layout.${n}`,allowedBreakpoints:t.allowedBreakpoints}),i=Pr(n,s);Q(i,{propertyPath:`layout.${n}`}),r[n]=i}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>{var n;const o=`${null!==(n=r.groupPath)&&void 0!==n?n:"layout.recipes"}.${e}`;return{base:Br(t.base,o),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:s,variant:i,target:a,orientation:l,container:c,size:u,...d}=e,f={declarations:{...i?{...r.resolveRecipeVariant(i).base}:{},...Br(d,o)}};return t&&(f.breakpoint=t,f.query=null!=n?n:"exact"),c&&(f.container=c,u&&(f.size=u),f.query=null!=n?n:"min"),s&&(f.state=s),a&&(f.target=a),l&&(f.orientation=l),f})}})(e,t,r),buildStructural:(e,t)=>Xr(e,t.breakpoints,t.mediaConfig)},en=new Set(["breakpoint","query","state","variant","target","orientation"]),tn={boxShadow:"box-shadow",opacity:"opacity",blur:"filter",transition:"transition",zIndex:"z-index"},rn={boxShadow:"shadow",opacity:"opacity",blur:"blur",transition:"transitions",zIndex:"zIndex"},nn=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e)){if(!n||en.has(r))continue;const e=tn[r],o=rn[r];if(!e||!o)continue;const s={ref:on(o,n)};"blur"===r&&(s.wrap="blur"),t[e]=s}return t},on=(e,t)=>"base"===t?`effects.${e}`:`effects.${e}.${t}`,sn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),an=(e,t)=>{if(void 0!==e){if("number"!=typeof e||Number.isNaN(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a number, received ${JSON.stringify(e)}.`);return e}},ln=(e,t)=>{if(void 0!==e){if("number"==typeof e){if(Number.isNaN(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a number or length string, received ${JSON.stringify(e)}.`);return e}if("string"==typeof e){const r=L(e);if("raw"in r)throw new y("REFRACT_E_EFFECTS",`${t} must be a number or a <number><unit> length (received ${JSON.stringify(e)}).`);return void 0===r.unit?r.value:{value:r.value,unit:r.unit}}throw new y("REFRACT_E_EFFECTS",`${t} must be a number or length string, received ${JSON.stringify(e)}.`)}},cn=new Set(["offsetX","offsetY","blur","spread","color","inset"]),un=(e,t)=>{if(!sn(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a shadow-layer object, received ${JSON.stringify(e)}.`);for(const r of Object.keys(e))if(!cn.has(r))throw new y("REFRACT_E_EFFECTS",`${t} has unknown shadow field "${r}" (allowed: ${[...cn].join(", ")}).`);const r={},n=ln(e.offsetX,`${t}.offsetX`),o=ln(e.offsetY,`${t}.offsetY`),s=ln(e.blur,`${t}.blur`),i=ln(e.spread,`${t}.spread`);if(void 0!==n&&(r.offsetX=n),void 0!==o&&(r.offsetY=o),void 0!==s&&(r.blur=s),void 0!==i&&(r.spread=i),void 0!==e.color){if("string"!=typeof e.color||!e.color)throw new y("REFRACT_E_EFFECTS",`${t}.color must be a "colors.*" token-path string.`);r.color=e.color}if(void 0!==e.inset){if("boolean"!=typeof e.inset)throw new y("REFRACT_E_EFFECTS",`${t}.inset must be a boolean.`);e.inset&&(r.inset=!0)}return r},dn=new Set(["property","duration","timingFunction","delay"]),fn=(e,t)=>{if(!sn(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a transition-part object, received ${JSON.stringify(e)}.`);for(const r of Object.keys(e))if(!dn.has(r))throw new y("REFRACT_E_EFFECTS",`${t} has unknown transition field "${r}" (allowed: ${[...dn].join(", ")}).`);if("string"!=typeof e.property||!e.property)throw new y("REFRACT_E_EFFECTS",`${t}.property is required (the CSS property to transition).`);const r={property:e.property},n=an(e.duration,`${t}.duration`),o=an(e.delay,`${t}.delay`);if(void 0!==n&&(r.duration=n),void 0!==e.timingFunction){if("string"!=typeof e.timingFunction||!e.timingFunction)throw new y("REFRACT_E_EFFECTS",`${t}.timingFunction must be a keyword or cubic-bezier(...) string.`);r.timingFunction=e.timingFunction}return void 0!==o&&(r.delay=o),r},pn=new Set(["recipes"]),mn={shadow:["offsetX","offsetY","blur","spread","color","inset"],transitions:["property","duration","timingFunction","delay"]},hn=e=>"shadow"===e?t=>((e,t="effects.shadow")=>{if("string"==typeof e){if("none"===e)return"none";throw new y("REFRACT_E_EFFECTS",`${t} must be structured shadow layer(s) or "none" — raw CSS strings are not accepted (received ${JSON.stringify(e)}).`)}if(Array.isArray(e)){if(!e.length)throw new y("REFRACT_E_EFFECTS",`${t} is an empty shadow-layer array.`);return e.map((e,r)=>un(e,`${t}[${r}]`))}return[un(e,t)]})(t,`effects.${e}`):"transitions"===e?t=>((e,t="effects.transitions")=>{if("string"==typeof e){if("none"===e)return"none";throw new y("REFRACT_E_EFFECTS",`${t} must be structured transition part(s) or "none" — raw CSS strings are not accepted (received ${JSON.stringify(e)}).`)}if(Array.isArray(e)){if(!e.length)throw new y("REFRACT_E_EFFECTS",`${t} is an empty transition-part array.`);return e.map((e,r)=>fn(e,`${t}[${r}]`))}return[fn(e,t)]})(t,`effects.${e}`):void 0,gn={key:"effects",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(pn.has(n))continue;const e=mn[n],s=hn(n),i=le(o,{propertyPath:`effects.${n}`,allowedBreakpoints:t.allowedBreakpoints,...e?{leafFields:e}:{},...s?{coerceValue:s}:{},...e?{fallbackBase:"none"}:{}});Q(i,{propertyPath:`effects.${n}`}),r[n]=i}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>({base:nn(t.base),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:o,variant:s,target:i,orientation:a,container:l,size:c,...u}=e,d={declarations:{...s?{...r.resolveRecipeVariant(s).base}:{},...nn(u)}};return t&&(d.breakpoint=t,d.query=null!=n?n:"exact"),l&&(d.container=l,c&&(d.size=c),d.query=null!=n?n:"min"),o&&(d.state=o),i&&(d.target=i),a&&(d.orientation=a),d})}))(0,t,r)},bn=new Set(["breakpoint","query","state","variant","target","orientation","container","size"]),vn=new Set(["as","side"]),yn=new Set(["width","style","offset","radius","color"]),wn=(e,t,r)=>"radius"===r?"border-radius":"offset"===r?"outline-offset":"outline"===e?`outline-${r}`:t?`border-${t}-${r}`:`border-${r}`,$n=(e,t)=>"color"===e?{ref:t}:{ref:"base"===t?`borders.${e}`:`borders.${e}.${t}`},kn=(e,t,r)=>{const n={};if(!e)return n;for(const[o,s]of Object.entries(e))s&&!bn.has(o)&&!vn.has(o)&&yn.has(o)&&(n[wn(t,r,o)]=$n(o,s));return n},xn=new Set(["recipes"]),jn={key:"borders",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(xn.has(n))continue;const e=le(o,{propertyPath:`borders.${n}`,allowedBreakpoints:t.allowedBreakpoints});Q(e,{propertyPath:`borders.${n}`}),r[n]=e}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>{var n;const o=null!==(n=t.base.as)&&void 0!==n?n:"border",s=t.base.side,i=kn(t.base,o,s),a=t.responsive.map(e=>{var t,n;const{breakpoint:i,query:a,state:l,variant:c,target:u,orientation:d,container:f,size:p,as:m,side:h,...g}=e,b=null!==(t=m)&&void 0!==t?t:o,v=null!==(n=h)&&void 0!==n?n:s,y={declarations:{...c?{...r.resolveRecipeVariant(c).base}:{},...kn(g,b,v)}};return i&&(y.breakpoint=i,y.query=null!=a?a:"exact"),f&&(y.container=f,p&&(y.size=p),y.query=null!=a?a:"min"),l&&(y.state=l),d&&(y.orientation=d),u&&(y.target=u),y});return{base:i,responsive:a}})(0,t,r)},An=new Set(["breakpoint","query","state","variant","target","orientation"]),Sn={keyframes:"animation-name",duration:"animation-duration",easing:"animation-timing-function",delay:"animation-delay",iterationCount:"animation-iteration-count",direction:"animation-direction",fillMode:"animation-fill-mode",playState:"animation-play-state"},En={duration:"duration",easing:"easing",delay:"delay"},Rn=(e,t)=>"base"===t?`animation.${e}`:`animation.${e}.${t}`,Cn=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e)){if(void 0===n||""===n||An.has(r))continue;const e=Sn[r];e&&(t[e]="keyframes"===r?{ref:`animation.keyframes.${n}`}:En[r]?{ref:Rn(En[r],String(n))}:{value:n})}return t},On=new Set(["keyframes","recipes"]),Tn=e=>e&&"object"==typeof e&&"ref"in e?{ref:String(e.ref)}:"string"==typeof e||"number"==typeof e?{value:e}:void 0,Fn=e=>{const t={};for(const[r,n]of Object.entries(e)){const e=Tn(n);e&&(t[r]=e)}return t},_n=e=>{const t=[];for(const[r,n]of Object.entries(e))t.push({stop:r,declarations:Fn(n)});return{steps:t}},Nn=e=>{if(!e||"object"!=typeof e)return{};const t={};for(const[r,n]of Object.entries(e))n&&"object"==typeof n&&(t[r]=_n(n));return t},Pn={key:"animation",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(On.has(n))continue;const e=le(o,{propertyPath:`animation.${n}`,allowedBreakpoints:t.allowedBreakpoints});Q(e,{propertyPath:`animation.${n}`}),r[n]=e}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>({base:Cn(t.base),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:o,variant:s,target:i,orientation:a,container:l,size:c,...u}=e,d={declarations:{...s?{...r.resolveRecipeVariant(s).base}:{},...Cn(u)}};return t&&(d.breakpoint=t,d.query=null!=n?n:"exact"),l&&(d.container=l,c&&(d.size=c),d.query=null!=n?n:"min"),o&&(d.state=o),i&&(d.target=i),a&&(d.orientation=a),d})}))(0,t,r),buildStructural:e=>({ruleSetGroups:{},configProperties:{},keyframes:Nn(e.keyframes)})},zn=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e))t[Mn(r)]=qn(n);return t},qn=e=>"object"==typeof e?{ref:e.ref}:{value:e},Mn=e=>e.startsWith("--")?e:e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),In={key:"components",normalizeProperties:()=>({}),interpretRecipe:(e,t,r)=>((e,t)=>({base:zn(t.base.css),responsive:t.responsive.map(e=>{var t,r;const n=e,o={declarations:zn(n.css)};return n.breakpoint&&(o.breakpoint=n.breakpoint,o.query=null!==(t=n.query)&&void 0!==t?t:"exact"),n.container&&(o.container=n.container,n.size&&(o.size=n.size),o.query=null!==(r=n.query)&&void 0!==r?r:"min"),n.state&&(o.state=n.state),n.orientation&&(o.orientation=n.orientation),n.target&&(o.target=n.target),o})}))(0,t),extractReferences:e=>(e=>{const t=[];for(const[r,n]of Object.entries(e))_.has(r)&&"string"==typeof n&&n.includes(".")&&t.push(`${r}:${n}`);return t})(e)},Ln=e=>({value:e}),Bn=e=>({ref:e}),Un=(e,t)=>({kind:"reset",selector:e,declarations:t,overrides:[]}),Dn=e=>{const t={};for(const[r,n,o]of e){const e={};for(const[t,r]of Object.entries(o))e[t]=Ln(r);t[r]=Un(n,e)}return t},Vn=[["h1","4xl"],["h2","3xl"],["h3","2xl"],["h4","xl"],["h5","lg"],["h6","md"]],Wn={preflight:{static:[["box","*,::before,::after",{"box-sizing":"border-box","border-width":"0","border-style":"solid"}],["body","body",{margin:"0","line-height":"inherit"}],["headings","h1,h2,h3,h4,h5,h6",{"font-size":"inherit","font-weight":"inherit",margin:"0"}],["blocks","p,figure,blockquote,dl,dd",{margin:"0"}],["lists","ul,ol",{"list-style":"none",margin:"0",padding:"0"}],["media","img,picture,video,canvas,svg",{display:"block","max-width":"100%"}],["forms","button,input,select,textarea",{font:"inherit",color:"inherit"}],["anchors","a",{color:"inherit","text-decoration":"inherit"}]],headings:!0},normalize:{static:[["box","*,::before,::after",{"box-sizing":"border-box"}],["body","body",{margin:"0"}],["media","img,picture,video,canvas,svg",{"max-width":"100%"}]],headings:!1},reset:{static:[["box","*,::before,::after",{"box-sizing":"border-box"}],["all","*",{margin:"0",padding:"0",border:"0",font:"inherit","vertical-align":"baseline"}],["headings","h1,h2,h3,h4,h5,h6",{"font-size":"inherit","font-weight":"inherit"}],["lists","ul,ol",{"list-style":"none"}],["media","img,picture,video,canvas,svg",{display:"block","max-width":"100%"}]],headings:!0}},Hn=Object.keys(Wn),Gn=e=>{if(!1===e)return{};const t=Wn[e];if(!t)throw new y("REFRACT_E_PRESET",`globals: unknown preset "${e}" — expected one of ${Hn.join(", ")} or false`);const r={static:Dn(t.static)};return t.headings&&(r.defaults=(()=>{const e={};for(const[t,r]of Vn)e[t]=Un(t,{"font-size":Bn(`typography.fontSize.${r}`)});return e})()),r},Yn=new Set(["state","breakpoint","query","orientation","container","size","variant","target"]),Jn=e=>null!==e&&"object"==typeof e?{ref:e.ref}:{value:e},Kn=e=>e.startsWith("--")?e:e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Xn=e=>{const t={};for(const[r,n]of Object.entries(e))null==n||Yn.has(r)||(t[Kn(r)]=Jn(n));return t},Zn=e=>{const t={declarations:Xn(e)},r=e;for(const e of Yn)void 0!==r[e]&&(t[e]=r[e]);return t},Qn=(e,t,r)=>(e=>({declarations:Xn(e.base),overrides:e.responsive.map(Zn)}))(we({[e]:t},r)[e]),eo=(e,t)=>{const r=null!=e?e:{},n={};if(void 0!==r.preset){const e=Gn(r.preset);e.static&&(n.static=e.static),e.defaults&&(n.defaults=e.defaults)}const o=((e,t)=>{if(!e||!Object.keys(e).length)return;const r=Object.keys(t.breakpoints),n={};for(const[o,s]of Object.entries(e)){if(!s||"object"!=typeof s)continue;const e={propertyPath:`globals.elements.${o}`,allowedBreakpoints:r,allowedStates:t.allowedStates,allowedContainers:t.allowedContainers},{variants:i,...a}=s,l=Qn(o,a,e),c={kind:"globals",selector:o,declarations:l.declarations,overrides:l.overrides};if(i&&"object"==typeof i&&Object.keys(i).length){const t={};for(const[r,n]of Object.entries(i))n&&"object"==typeof n&&(t[r]=Qn(r,n,{...e,propertyPath:`${e.propertyPath}.variants.${r}`}));Object.keys(t).length&&(c.variants=t)}n[o]=c}return Object.keys(n).length?n:void 0})(r.elements,t);return o&&(n.elements=o),n},to=[yr,Cr,Qr,gn,jn,Pn,In,{key:"globals",normalizeProperties:()=>({}),buildStructural:(e,t)=>({ruleSetGroups:eo(e,t),configProperties:{}})}];const ro=(e,t)=>Ne(e,e=>Le(e,Me(t))),no=e=>{var t;if(!e||"object"!=typeof e)return;const r={};for(const[n,o]of Object.entries(e))o&&"object"==typeof o&&o.sizes&&Object.keys(o.sizes).length&&(r[n]={type:null!==(t=o.type)&&void 0!==t?t:"inline-size",sizes:{...o.sizes}});return Object.keys(r).length?r:void 0},oo=e=>{if(!e)return;const t=new Map;for(const[r,n]of Object.entries(e))t.set(r,new Set(Object.keys(n.sizes)));return t},so=(e,t)=>{if(e.startsWith("--"))return e;const r=e.split(".").join("-").toLowerCase();return t?`--${t}-${r}`:`--${r}`};function io(e,t,r){const{clean:n,externals:o}=((e,t)=>{if(!e)return{clean:e,externals:{}};const r={},n={};for(const[o,s]of Object.entries(e))if(null===s||"object"!=typeof s||Array.isArray(s)||"string"!=typeof s.external)r[o]=s;else{const e=so(s.external,t);n[o]={base:`var(${e})`,external:e,responsive:[]}}return{clean:r,externals:n}})(t,r.extendsPrefix),s=e.normalizeProperties(n,{allowedBreakpoints:r.allowedBreakpoints});Object.assign(s,o);const i=r.inheritedProperties?{...r.inheritedProperties,...s}:s,a=function(e,t,r){var n,o;if(!e.interpretRecipe||!t||!Object.keys(t).length)return{};const s={};for(const[i,a]of Object.entries(t)){const t=`${e.key}.recipes.${i}`,l=we(a,{propertyPath:t,allowedBreakpoints:r.allowedBreakpoints,allowedStates:r.allowedStates,allowedContainers:r.allowedContainers}),c=Ae(l,(n,o,s)=>e.interpretRecipe(n,o,{breakpoints:r.breakpoints,media:r.media,properties:r.properties,resolveRecipeVariant:s,groupPath:t}),{groupPath:t}).resolveAll(),u={};for(const[t,r]of Object.entries(c))if(e.extractReferences){const s=e.extractReferences(null!==(o=null===(n=l[t])||void 0===n?void 0:n.base)&&void 0!==o?o:{});u[t]=F(r,s)}else u[t]=T(r);s[i]=u}return s}(e,null==t?void 0:t.recipes,{breakpoints:r.breakpoints,media:r.media,properties:i,allowedBreakpoints:r.allowedBreakpoints,allowedStates:r.allowedStates,allowedContainers:r.allowedContainers});let l,c,u=a;if(e.buildStructural&&t){const n=e.buildStructural(t,{breakpoints:r.breakpoints,media:r.media,mediaConfig:r.mediaConfig,allowedStates:r.allowedStates,allowedContainers:r.allowedContainers});u={...n.ruleSetGroups,...a},Object.keys(n.configProperties).length&&(l=n.configProperties),n.keyframes&&Object.keys(n.keyframes).length&&(c=n.keyframes)}const d={};return Object.keys(s).length&&(d.properties=s),Object.keys(u).length&&(d.ruleSetGroups=u),l&&(d.extraProperties=l),c&&(d.keyframes=c),d}function ao(e){const t={};if(!(null==e?void 0:e.properties))return t;for(const[r,n]of Object.entries(e.properties)){const e={base:n.base.value};if(n.variants&&Object.keys(n.variants).length){const t={};for(const[e,r]of Object.entries(n.variants)){const n={base:r.base.value};if(r.extras)for(const[e,t]of Object.entries(r.extras))n[e]=t.value;t[e]=n}e.variants=t}if(n.extras)for(const[t,r]of Object.entries(n.extras))e[t]=r.value;t[r]=e}return t}function lo(e,t){var r,n,o,s,i;if(!e)return t;const a={...e};if(t.properties&&(a.properties={...null!==(r=e.properties)&&void 0!==r?r:{},...t.properties}),t.ruleSets){const r={...null!==(n=e.ruleSets)&&void 0!==n?n:{}};for(const[n,i]of Object.entries(t.ruleSets))r[n]={...null!==(s=null===(o=e.ruleSets)||void 0===o?void 0:o[n])&&void 0!==s?s:{},...i};a.ruleSets=r}return t.keyframes&&(a.keyframes={...null!==(i=e.keyframes)&&void 0!==i?i:{},...t.keyframes}),a}function co(e,t){var r,n,o,s;const{adapter:i}=t,a=e,l=null!==(r=a.breakpoints)&&void 0!==r?r:Ue,c=Object.keys(l),u=null!==(o=null===(n=a.extends)||void 0===n?void 0:n.prefix)&&void 0!==o?o:"dt",d=i.allowedStates,f=new Set(null!==(s=a.modes)&&void 0!==s?s:["dark","light"]),p=t.media,m=ro(l,p),h=no(a.containers),g=oo(h),b={};for(const e of to){const t=io(e,a[e.key],{breakpoints:l,extendsPrefix:u,media:m,mediaConfig:p,allowedBreakpoints:c,allowedStates:d,allowedContainers:g});Object.keys(t).length&&(b[e.key]=t)}const v=(e=>{var t;const r={},n=P(e.colors);n&&(r.colors=n);const o=P(e.typography);o&&(r.typography=o);const s=P(e.layout);s&&(r.layout=s);const i=P(e.effects);i&&(r.effects=i);const a=P(e.borders);a&&(r.borders=a);const l=P(e.animation);l&&(r.animation=l),N(null===(t=e.components)||void 0===t?void 0:t.ruleSetGroups)&&(r.components={ruleSets:e.components.ruleSetGroups});const c=P(e.globals);c&&(r.globals=c);const u={breakpoints:e.breakpoints,subsystems:r};return e.containers&&Object.keys(e.containers).length&&(u.containers=e.containers),u})({breakpoints:l,containers:h,...b}),w={units:t.units,baseFontSize:t.baseFontSize},$=function(e,t){var r;const{propertiesOverlay:n,ruleSetsOverlay:o,keyframesOverlay:s,containersOverlay:i}=t;if(!(n||o||s||i))return e;const a={...e.subsystems},l=new Set([...Object.keys(null!=n?n:{}),...Object.keys(null!=o?o:{}),...Object.keys(null!=s?s:{})]);for(const e of l)a[e]=lo(a[e],{properties:null==n?void 0:n[e],ruleSets:null==o?void 0:o[e],keyframes:null==s?void 0:s[e]});const c={...e,subsystems:a};return i&&(c.containers={...null!==(r=e.containers)&&void 0!==r?r:{},...i}),c}(K(v,w),t),k=(e=>{const t={};for(const r of e)for(const[e,n]of Object.entries(r)){if(e in t)throw new y("REFRACT_E_TOKEN_PATH",`Duplicate derivation fn "${e}" registered by two subsystems.`);t[e]=n}return t})(to.flatMap(e=>e.derivations?[e.derivations]:[])),x=Te($,k),j=[...fo(x),...po(x),...mo(x),...uo(x,f)];if(j.length>0){const e=j.map(e=>` - ${e}`).join("\n");throw new y("REFRACT_E_VALIDATION",`refract: ${j.length} validation error(s):\n${e}`,j)}return ho(x,{adapter:i,derivationRegistry:k,allowedStates:d,mediaConfig:p,unitConfig:w})}function uo(e,t){var r,n,o;const s=[],i=(e,r,n,o)=>{t.has(n)||s.push(`${e}.${r}${o}: unknown appearance mode '${n}' — declare it in the top-level 'modes' registry (known: ${[...t].join(", ")})`)};for(const[t,s]of Object.entries(e.subsystems))for(const[e,a]of Object.entries(null!==(r=s.properties)&&void 0!==r?r:{})){for(const r of null!==(n=a.modes)&&void 0!==n?n:[])r.mode&&i(t,e,r.mode,"");for(const r of null!==(o=a.responsive)&&void 0!==o?o:[])r.mode&&i(t,e,r.mode," (responsive)")}return s}function fo(e){var t,r,n,o,s;const i=null===(t=e.subsystems.components)||void 0===t?void 0:t.ruleSets;if(!i)return[];const a=[];for(const[t,l]of Object.entries(i))for(const[i,c]of Object.entries(l))for(const l of null!==(r=c.references)&&void 0!==r?r:[]){const[r,c=""]=l.split(":"),u=c.indexOf("."),d=u>=0?c.slice(0,u):c,f=u>=0?c.slice(u+1):"";(null===(s=null===(o=null===(n=e.subsystems[r])||void 0===n?void 0:n.ruleSets)||void 0===o?void 0:o[d])||void 0===s?void 0:s[f])||a.push(`components.${t}.${i}: Recipe variant "${f}" is not defined in "${r}:${d}". Check the subsystem:group.variant reference against what the subsystem declares.`)}return a}function po(e){var t,r;const n=null===(t=e.subsystems.components)||void 0===t?void 0:t.ruleSets;if(!n)return[];const o=z(e),s=[],i=(e,t,r,n)=>{for(const[i,a]of Object.entries(null!=e?e:{}))void 0===a.ref||a.ref in o||s.push(`components.${t}.${r}: css '${i}'${n} references unknown token '${a.ref}' — check the token path, or use a bare string / number for a raw CSS value`)};for(const[e,t]of Object.entries(n))for(const[n,o]of Object.entries(t)){i(o.declarations,e,n,"");for(const t of null!==(r=o.overrides)&&void 0!==r?r:[])i(t.declarations,e,n," (override)")}return s}function mo(e){var t,r,n,o,s;const i=null===(t=e.subsystems.globals)||void 0===t?void 0:t.ruleSets;if(!i)return[];const a=z(e),l=[],c=(e,t,r)=>{for(const[n,o]of Object.entries(null!=e?e:{}))void 0===o.ref||o.ref in a||l.push(`globals element '${t}'${r}: '${n}' references unknown token '${o.ref}' — check the token path, or use a bare string / number for a raw CSS value`)};for(const e of Object.values(i))for(const t of Object.values(e)){if("globals"!==t.kind)continue;const e=null!==(r=t.selector)&&void 0!==r?r:"";c(t.declarations,e,"");for(const r of null!==(n=t.overrides)&&void 0!==n?n:[])c(r.declarations,e," (override)");for(const[r,n]of Object.entries(null!==(o=t.variants)&&void 0!==o?o:{})){const t=` (variant '${r}')`;c(n.declarations,e,t);for(const r of null!==(s=n.overrides)&&void 0!==s?s:[])c(r.declarations,e,`${t} (override)`)}}return l}function ho(e,t){var r;const n=ro(e.breakpoints,t.mediaConfig),o=De(e.containers,t.mediaConfig),s=new WeakMap,i=()=>{let t=s.get(e);return t||(t=z(e),s.set(e,t)),t},a=e=>Se(i(),t.derivationRegistry,e),l={media:n,containers:o,resolve:a},c=t.adapter.bind(e,l),u={model:e,get tokens(){return i()},resolveToken:a,override:r=>function(e,t,r){var n,o,s;const i=t.breakpoints,a=i?{...e.breakpoints,...i}:e.breakpoints,l=Object.keys(a),c=ro(a,r.mediaConfig),u=no(t.containers),d=u?{...null!==(n=e.containers)&&void 0!==n?n:{},...u}:e.containers,f=oo(d),p={...e.subsystems};for(const n of to){const i=t[n.key];if(void 0===i)continue;const u=ao(e.subsystems[n.key]),d=io(n,i,{breakpoints:a,extendsPrefix:null!==(s=null===(o=t.extends)||void 0===o?void 0:o.prefix)&&void 0!==s?s:"dt",media:c,mediaConfig:r.mediaConfig,allowedBreakpoints:l,allowedStates:r.allowedStates,allowedContainers:f,inheritedProperties:u}),m=P(d);m&&(p[n.key]=lo(e.subsystems[n.key],m))}const m={breakpoints:a,subsystems:p};d&&Object.keys(d).length&&(m.containers=d);const h=K(m,r.unitConfig),g=Te(h,r.derivationRegistry);return ho(g,r)}(e,r,t)},d=null===(r=c.extend)||void 0===r?void 0:r.call(c,u);return d&&Object.defineProperties(u,Object.getOwnPropertyDescriptors(d)),u}const go="theme.css",bo="styles.css",vo="variables.css",yo=(e,t)=>"variables"===t?`${e}.variables.css`:`${e}.css`,wo=e=>`${e.group}-${e.variant}.css`,$o="variables.css";function ko(e){var t,r,n,o,s,i,a,l;if(void 0===e)return{type:"single",file:go};if("string"==typeof e)switch(e){case"single":return{type:"single",file:go};case"split":return{type:"split",file:bo,variables:vo};case"subsystem":return{type:"subsystem",filename:yo};case"components":return{type:"components",inline:!0,filename:wo,variables:$o}}switch(null!==(t=e.type)&&void 0!==t?t:"variables"in e?"split":"single"){case"single":return{type:"single",file:null!==(r=e.file)&&void 0!==r?r:go};case"split":{const t=e;return{type:"split",file:null!==(n=t.file)&&void 0!==n?n:bo,variables:null!==(o=t.variables)&&void 0!==o?o:vo}}case"subsystem":return{type:"subsystem",filename:null!==(s=e.filename)&&void 0!==s?s:yo};case"components":{const t=e;return{type:"components",inline:null===(i=t.inline)||void 0===i||i,filename:null!==(a=t.filename)&&void 0!==a?a:wo,variables:null!==(l=t.variables)&&void 0!==l?l:$o}}}throw new Error("resolveEmitPlan: unrecognized emit directive.")}const xo="com.theme-registry.refract",jo=e=>"object"==typeof e&&null!==e&&"$value"in e,Ao=/^\{([^}]+)\}$/,So=(e,t,r=new Set)=>{if("string"==typeof e){const n=e.match(Ao);if(n){const o=n[1];if(r.has(o))throw new y("REFRACT_E_CYCLE",`Circular token reference: ${o}`);const s=t.get(o);return s?(r.add(o),So(s.value,t,r)):e}return e}if(Array.isArray(e))return e.map(e=>So(e,t,new Set(r)));if("object"==typeof e&&null!==e){const n={};for(const[o,s]of Object.entries(e))n[o]=So(s,t,new Set(r));return n}return e};function Eo(e){var t;const r=[];for(const[n,o]of Object.entries(e.subsystems))for(const[e,s]of Object.entries(null!==(t=o.ruleSets)&&void 0!==t?t:{}))for(const t of Object.keys(s))r.push({subsystem:n,group:e,variant:t});return r}function Ro(){return{name:(e={name:"noop",version:1,bind:()=>({recipeName:()=>"",renderRecipe:()=>"",renderVariables:()=>"",join:e=>e.join(""),emit:()=>({files:{}})})}).name,version:e.version,allowedStates:e.allowedStates,bind(t,r){var n,o,s,i;const a=e.bind(t,r),l=null!==(n=a.renderAllRecipes)&&void 0!==n?n:()=>a.join(Eo(t).map(({subsystem:e,group:t,variant:r})=>a.renderRecipe(e,t,r))),c=null!==(o=a.renderAllVariables)&&void 0!==o?o:()=>a.join(Object.keys(t.subsystems).map(e=>a.renderVariables(e))),u=null!==(s=a.renderAll)&&void 0!==s?s:()=>a.join([c(),l()]),d=null!==(i=a.describeUsage)&&void 0!==i?i:()=>({format:e.name,summary:[`This theme was built with the "${e.name}" refract adapter.`],recipes:Eo(t).map(({subsystem:e,group:t,variant:r})=>({subsystem:e,group:t,variant:r,name:a.recipeName(e,t,r)}))});return{...a,renderAllRecipes:l,renderAllVariables:c,renderAll:u,describeUsage:d}}};var e}const Co=(e,t)=>{var r,n,o;const s=(e=>{const t=[],r=new Map,n=(e,o,s)=>{var i,a,l;const c=null!==(i=e.$type)&&void 0!==i?i:s;for(const[s,i]of Object.entries(e)){if(s.startsWith("$"))continue;if("object"!=typeof i||null===i)continue;const e=[...o,s];if(jo(i)){const n=i,o={path:e,type:null!==(l=null!==(a=n.$type)&&void 0!==a?a:c)&&void 0!==l?l:"color",value:n.$value,description:n.$description,extensions:n.$extensions};t.push(o),r.set(e.join("."),o)}else n(i,e,c)}};n(e,[]);for(const e of t)e.value=So(e.value,r);return t})(e),i=null!==(r=null==t?void 0:t.groupMapping)&&void 0!==r?r:{},a={},l={},c={},u={},d={};let f=null!==(n=null==t?void 0:t.breakpoints)&&void 0!==n?n:{};const p=new Map;for(const e of s){const t=e.path[0];p.has(t)||p.set(t,[]),p.get(t).push(e)}const m=null==t?void 0:t.breakpointGroup;if(m&&p.has(m)){f={};for(const e of p.get(m)){f[e.path[e.path.length-1]]=Wo(e.value)}p.delete(m)}for(const[e,t]of p){const r=null!==(o=i[e])&&void 0!==o?o:Oo(e,t);if("ignore"!==r)switch(r){case"colors":_o(t,e,a);break;case"typography":Po(t,e,l);break;case"effects":Mo(t,e,c);break;case"borders":Lo(t,e,u);break;case"layout":Uo(t,e,d)}}const h={};return Object.keys(f).length&&(h.breakpoints=f),Object.keys(a).length&&(h.colors=a),Object.keys(l).length&&(h.typography=l),Object.keys(c).length&&(h.effects=c),Object.keys(u).length&&(h.borders=u),Object.keys(d).length&&(h.layout=d),h},Oo=(e,t)=>{var r;const n=null===(r=t[0])||void 0===r?void 0:r.type;if("color"===n)return"colors";if("typography"===n)return"typography";if("shadow"===n)return"effects";if("border"===n)return"borders";if("strokeStyle"===n)return"borders";if("transition"===n)return"effects";const o=e.toLowerCase();if(o.includes("color")||o.includes("palette"))return"colors";if(o.includes("font")||o.includes("typo")||o.includes("text"))return"typography";if(o.includes("spacing")||o.includes("space")||o.includes("gutter"))return"layout";if(o.includes("radius")||o.includes("border")||o.includes("outline"))return"borders";if(o.includes("shadow")||o.includes("blur")||o.includes("opacity")||o.includes("z-index")||o.includes("zindex")||o.includes("transition")||o.includes("effect"))return"effects";if("dimension"===n){if(o.includes("spacing")||o.includes("gap"))return"layout";if(o.includes("radius")||o.includes("border"))return"borders";if(o.includes("font")||o.includes("size"))return"typography"}return"ignore"},To=/^\{([^}]+)\}$/,Fo=e=>{if("string"!=typeof e)return;const t=e.match(To);if(!t)return;const r=t[1],n=r.indexOf("."),o=n<0?r:r.slice(0,n),s=n<0?"":r.slice(n+1),i="color"===o?"colors":o;return s?`${i}.${s}`:i},_o=(e,t,r)=>{var n;const o=new Map,s=[];for(const t of e)if(t.path.length<=2)s.push(t);else{const e=t.path[1];o.has(e)||o.set(e,[]),o.get(e).push(t)}for(const e of s){const t=e.path[e.path.length-1];if(!r[t]){const n=Fo(e.value);r[t]=n?{external:n}:{base:String(e.value)}}}for(const[e,t]of o)if(1===t.length){const n=t[0],o=n.path[n.path.length-1];o===e?r[e]={base:String(n.value)}:(r[e]||(r[e]={base:String(t[0].value)}),r[e].variants={[o]:String(n.value)})}else{const o=null!==(n=t.find(e=>{const t=e.path[e.path.length-1];return"base"===t||"default"===t||"500"===t}))&&void 0!==n?n:t[0],s={};for(const e of t){if(e===o)continue;s[e.path.slice(2).join("-")]=String(e.value)}r[e]={base:String(o.value),...Object.keys(s).length?{variants:s}:{}}}},No={fontfamily:"fontFamily",fontsize:"fontSize",fontweight:"fontWeight",lineheight:"lineHeight",letterspacing:"letterSpacing",fontstyle:"fontStyle",texttransform:"textTransform",textdecoration:"textDecoration",textalign:"textAlign"},Po=(e,t,r)=>{for(const n of e)if("typography"===n.type){const e=n.value,t=n.path.slice(1).join("-")||n.path[n.path.length-1];e.fontFamily&&zo(r,"fontFamily",Array.isArray(e.fontFamily)?e.fontFamily.join(", "):e.fontFamily,t),e.fontSize&&zo(r,"fontSize",Ho(e.fontSize),t),void 0!==e.fontWeight&&zo(r,"fontWeight",e.fontWeight,t),void 0!==e.lineHeight&&zo(r,"lineHeight",e.lineHeight,t),e.letterSpacing&&zo(r,"letterSpacing",e.letterSpacing,t)}else{const e=qo(n,t);if(!e)continue;const o=n.path[n.path.length-1],s="fontFamily"===n.type&&Array.isArray(n.value)?n.value.join(", "):"dimension"===n.type?Ho(n.value):n.value;zo(r,e,s,o)}},zo=(e,t,r,n)=>{if(!e[t])return void(e[t]={base:r,variants:{}});const o=e[t];"base"===n||"default"===n||"md"===n?o.base=r:o.variants[n]=r},qo=(e,t)=>{if("fontFamily"===e.type)return"fontFamily";if("fontWeight"===e.type)return"fontWeight";const r=e.path.join(".").toLowerCase();for(const[e,t]of Object.entries(No))if(r.includes(e))return t;const n=t.toLowerCase();for(const[e,t]of Object.entries(No))if(n.includes(e))return t;return null},Mo=(e,t,r)=>{for(const t of e){const e=t.path[t.path.length-1];switch(t.type){case"shadow":{const n=Do(t.value);Io(r,"shadow",n,e);break}case"transition":{const n=t.value,o=n.timingFunction?`cubic-bezier(${n.timingFunction.join(", ")})`:"ease",s=`all ${n.duration} ${o}`;Io(r,"transitions",s,e);break}case"dimension":t.path.join(".").toLowerCase().includes("blur")&&Io(r,"blur",Ho(t.value),e);break;case"number":{const n=t.path.join(".").toLowerCase();n.includes("opacity")?Io(r,"opacity",t.value,e):(n.includes("z-index")||n.includes("zindex"))&&Io(r,"zIndex",t.value,e);break}}}},Io=(e,t,r,n)=>{if(!e[t])return void(e[t]={base:r,variants:{}});const o=e[t];"base"===n||"default"===n||"md"===n?o.base=r:o.variants[n]=r},Lo=(e,t,r)=>{for(const t of e){const e=t.path[t.path.length-1];switch(t.type){case"border":{const n=t.value;Bo(r,"width",Ho(n.width),e),n.style&&Bo(r,"style",n.style,e);break}case"strokeStyle":Bo(r,"style",String(t.value),e);break;case"dimension":{const n=t.path.join(".").toLowerCase();n.includes("radius")?Bo(r,"radius",Ho(t.value),e):n.includes("offset")?Bo(r,"offset",Ho(t.value),e):n.includes("width")&&Bo(r,"width",Ho(t.value),e);break}}}},Bo=(e,t,r,n)=>{if(!e[t])return void(e[t]={base:r,variants:{}});const o=e[t];"base"===n||"default"===n||"md"===n?o.base=r:o.variants[n]=r},Uo=(e,t,r)=>{for(const t of e){if("dimension"!==t.type)continue;const e=t.path[t.path.length-1],n=Wo(t.value);r.spacing||(r.spacing={base:n,variants:{}});const o=r.spacing;"base"===e||"default"===e||"4"===e?o.base=n:o.variants[e]=n}},Do=e=>Array.isArray(e)?e.map(e=>Vo(e)).join(", "):Vo(e),Vo=e=>{const t=[];return e.inset&&t.push("inset"),t.push(e.offsetX,e.offsetY,e.blur,e.spread,e.color),t.join(" ")},Wo=e=>{if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?0:e.endsWith("rem")?Math.round(16*t):t},Ho=e=>{if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?e:e.endsWith("px")?t:e},Go=(e,t)=>{var r;const n={};(null==t?void 0:t.name)&&(n.$name=t.name);const o=e.model.breakpoints;if(!1!==(null==t?void 0:t.includeBreakpoints)&&o&&Object.keys(o).length){const e={$type:"dimension"};for(const[t,r]of Object.entries(o))e[t]={$value:`${r}px`};n.breakpoint=e}const s=Jo(e),i=t=>{try{return String(e.resolveToken(t))}catch{return t}},a=s.get("colors");if(a){const e={$type:"color"};for(const[t,r]of a){const n={};void 0!==r.base&&(n.base={$value:ut(String(r.base))});for(const[e,t]of Object.entries(r.members))n[e]={$value:ut(String(t))};e[t]=n}n.color=e}const l=s.get("typography");if(l){const e={};for(const[t,r]of l){const n={$type:Ko(t)};void 0!==r.base&&(n.base={$value:Xo(r.base,r.baseUnit)});for(const[e,t]of Object.entries(r.members))n[e]={$value:Xo(t,r.memberUnits[e])};e[t]=n}n.typography=e}const c=s.get("effects");if(c)for(const[e,t]of c){const{groupName:r,type:o}=Zo(e);n[r]||(n[r]={$type:o});const s=n[r];void 0!==t.base&&(s.base={$value:Qo(e,t.base,i,t.baseUnit)});for(const[r,n]of Object.entries(t.members))s[r]={$value:Qo(e,n,i,t.memberUnits[r])}}const u=s.get("borders");if(u)for(const[e,t]of u){const{groupName:r,type:o}=es(e);n[r]||(n[r]={$type:o});const s=n[r];void 0!==t.base&&(s.base={$value:ts(t.base,t.baseUnit)});for(const[e,r]of Object.entries(t.members))s[e]={$value:ts(r,t.memberUnits[e])}}const d=s.get("layout");if(d)for(const[e,t]of d){if(e.includes("--"))continue;const r=e;n[r]||(n[r]={$type:"dimension"});const o=n[r];void 0!==t.base&&(o.base={$value:rs(t.base,t.baseUnit)});for(const[e,r]of Object.entries(t.members))o[e]={$value:rs(r,t.memberUnits[e])}}if(null==t?void 0:t.includeRecipes){const t=(e=>{const t={},r={},n={};for(const[o,s]of Object.entries(e.subsystems))s.properties&&Object.keys(s.properties).length&&(t[o]=s.properties),s.ruleSets&&Object.keys(s.ruleSets).length&&(r[o]=s.ruleSets),s.keyframes&&Object.keys(s.keyframes).length&&(n[o]=s.keyframes);const o=Object.keys(t).length>0,s=Object.keys(r).length>0,i=Object.keys(n).length>0,a=!!e.containers&&Object.keys(e.containers).length>0;if(o||s||i||a)return{version:1,...o?{properties:t}:{},...s?{ruleSets:r}:{},...i?{keyframes:n}:{},...a?{containers:e.containers}:{}}})(e.model);t&&(n.$extensions={...null!==(r=n.$extensions)&&void 0!==r?r:{},[xo]:t})}return n},Yo=(e,t)=>void 0!==t?`${e}${t}`:e,Jo=e=>{const t=new Map;for(const r of Object.keys(e.tokens)){const n=r.indexOf(".");if(n<0)continue;const o=r.slice(0,n),s=r.slice(n+1),i=s.indexOf("."),a=i<0?s:s.slice(0,i),l=i<0?void 0:s.slice(i+1),c=e.tokens[r];if(void 0!==(null==c?void 0:c.external))continue;let u;if(void 0!==(null==c?void 0:c.struct))u=c.struct;else try{u=e.resolveToken(r)}catch{continue}const d=null==c?void 0:c.unit;let f=t.get(o);f||(f=new Map,t.set(o,f));let p=f.get(a);p||(p={members:{},memberUnits:{}},f.set(a,p)),void 0===l?(p.base=u,void 0!==d&&(p.baseUnit=d)):(p.members[l]=u,void 0!==d&&(p.memberUnits[l]=d))}return t},Ko=e=>{switch(e){case"fontFamily":return"fontFamily";case"fontWeight":return"fontWeight";case"fontSize":case"letterSpacing":return"dimension";default:return"number"}},Xo=(e,t)=>Yo(e,t),Zo=e=>{switch(e){case"shadow":return{groupName:"shadow",type:"shadow"};case"transitions":return{groupName:"transition",type:"transition"};case"blur":default:return{groupName:e,type:"dimension"};case"opacity":case"zIndex":return{groupName:e,type:"number"}}},Qo=(e,t,r,n)=>Array.isArray(t)?"transitions"===e?t.map(e=>{var t;const r=[e.property];return null==e.duration&&null==e.delay||r.push(`${null!==(t=e.duration)&&void 0!==t?t:0}ms`),e.timingFunction&&r.push(e.timingFunction),null!=e.delay&&r.push(`${e.delay}ms`),r.join(" ")}).join(", "):((e,t)=>e.map(e=>{const r=`0${(e=>{for(const t of[e.offsetX,e.offsetY,e.blur,e.spread])if(void 0!==t&&"number"!=typeof t)return t.unit;return"px"})(e)}`,n=e=>void 0===e?r:(e=>"number"==typeof e?`${e}px`:`${e.value}${e.unit}`)(e),o=[];return e.inset&&o.push("inset"),o.push(n(e.offsetX),n(e.offsetY)),null!=e.spread?o.push(n(e.blur),n(e.spread)):null!=e.blur&&o.push(n(e.blur)),e.color&&o.push(t(e.color)),o.join(" ")}).join(", "))(t,r):Yo(t,n),es=e=>{switch(e){case"radius":return{groupName:"radius",type:"dimension"};case"width":return{groupName:"borderWidth",type:"dimension"};case"offset":return{groupName:"outlineOffset",type:"dimension"};case"style":return{groupName:"borderStyle",type:"strokeStyle"};default:return{groupName:e,type:"dimension"}}},ts=(e,t)=>Yo(e,t),rs=(e,t)=>Yo(e,t);async function ns(r){var n;const{raw:o,adapter:s,outDir:i,helpers:c=[],emit:d,media:p,units:m,baseFontSize:h,guide:g}=r,b=co(o,{adapter:s,media:p,units:m,baseFontSize:h}),y=Ne(b.model.breakpoints,e=>Le(e,Me(p))),w=De(b.model.containers,p),$=s.bind(b.model,{media:y,containers:w,resolve:b.resolveToken});if(!$.emit)throw new Error(`Adapter "${s.name}" does not implement emit(); it cannot build to disk.`);const k=$.emit(ko(d)),x=[];e.mkdirSync(i,{recursive:!0});const j=(r,n)=>{const o=t.join(i,r);e.mkdirSync(t.dirname(o),{recursive:!0}),e.writeFileSync(o,n,"utf8"),x.push(o)};for(const[e,t]of Object.entries(k.files))j(e,t);for(const[e,t]of Object.entries(null!==(n=k.vendorHelpers)&&void 0!==n?n:{}))j(e,t);for(const e of c){const t=l(e);if(!t)throw new Error(`Unknown vendor helper "${e}". Known: ${a.map(e=>e.id).join(", ")}.`);j(t.outfile,await f(u(t.source)))}if(g){const e=!0===g?{}:g,t=v($.describeUsage(),Go(b),{files:Object.keys(k.files),packageName:e.packageName,llmsFile:e.llmsFile,manifestFile:e.manifestFile});for(const[e,r]of Object.entries(t.files))j(e,r)}return{outDir:i,files:x}}const os="theme.config",ss=[".ts",".mjs",".js"],is=(r=process.cwd())=>{for(const n of ss){const o=t.join(r,`${os}${n}`);if(e.existsSync(o))return o}};let as=0;async function ls(n={}){var o,s,i;const a=null!==(o=n.cwd)&&void 0!==o?o:process.cwd(),l=n.configPath?t.resolve(a,n.configPath):is(a);if(!l||!e.existsSync(l)){const e=n.configPath?`"${n.configPath}"`:`${os}.(ts|mjs|js) in "${a}"`;throw new Error(`No theme config found at ${e}.`)}const c=await async function(e){if(".ts"!==t.extname(e)){const t=`${r.pathToFileURL(e).href}?v=${++as}`;return await import(t)}const{entry:n,cleanup:o}=await h(e);try{return await import(r.pathToFileURL(n).href)}finally{o()}}(l),u=null!==(i=null!==(s=c.default)&&void 0!==s?s:c.config)&&void 0!==i?i:c;if(!u||"object"!=typeof u||!Array.isArray(u.targets))throw new Error(`"${l}" must export (default) a defineConfig({ raw, targets }) object.`);return{config:u,path:l}}const cs="@theme-registry/refract-css";function us(){var r;const n=t.join(c(),"package.json");return null!==(r=JSON.parse(e.readFileSync(n,"utf8")).name)&&void 0!==r?r:"@theme-registry/refract"}const ds="theme.raw",fs=[".ts",".mts",".mjs",".js",".json"],ps=(r=process.cwd())=>{for(const n of fs){const o=t.join(r,`${ds}${n}`);if(e.existsSync(o))return{path:o,filename:`${ds}${n}`,ext:n}}};function ms(e){if(".json"===e.ext)return{head:`import { readFileSync } from "node:fs";\n\n// The theme is JSON, so it's read rather than imported — no module-attribute support needed.\nconst raw = JSON.parse(readFileSync(new URL("./${e.filename}", import.meta.url), "utf8"));\n`,expression:"raw"};return{head:`import { raw } from "${".ts"===e.ext||".mts"===e.ext?`./${ds}`:`./${e.filename}`}";\n`,expression:"raw"}}function hs(e,t){const{head:r,expression:n}=ms(t);return`import { defineConfig } from "${e}/build";\nimport { createCssAdapter } from "${cs}";\n${r}\n// refract build config. \`refract build\` reads this file, builds the theme once, and writes each\n// target's emitted files into that target's \`outDir\`. The config is your code: it \`import\`s the\n// adapters it wants and passes their options at construction (not via CLI flags).\n//\n// Your tokens live in \`${t.filename}\` — edit them there, not here.\nexport default defineConfig({\n raw: ${n},\n targets: [\n // The CSS adapter (from @theme-registry/refract-css). Pass its options here, at construction.\n { adapter: createCssAdapter(/* { colors: { prefix: "app" } } */), outDir: "dist/theme" },\n\n // Add another adapter target once its package is installed, e.g.:\n // import { createStyledComponentsAdapter } from "@theme-registry/refract-styled-components";\n // { adapter: createStyledComponentsAdapter(), outDir: "dist/theme-sc" },\n ],\n});\n`}function gs(e){return`import { defineConfig } from "${e}/build";\nimport { createCssAdapter } from "${cs}";\n\n// refract build config. \`refract build\` reads this file, builds the theme once, and writes\n// each target's emitted files into that target's \`outDir\`. The config is your code: it \`import\`s\n// the adapters it wants and passes their options at construction (not via CLI flags).\nexport default defineConfig({\n // The raw theme — authored in refract's nested slices. Extend with typography/effects/layout.\n raw: {\n breakpoints: { sm: 576, md: 768, lg: 1024, xl: 1280 },\n colors: {\n // Starter palette passes its own contrast audit (WCAG AA): white text clears 4.5:1 on both\n // bases. Keep that when you retune — the auditor is a shipped feature; the default should model it.\n primary: { base: "#1864ab", text: "#fff", variants: { dark: "#0b4a86", light: "#a5d8ff" } },\n neutral: { base: "#495057", text: "#fff", variants: { light: "#f1f3f5", dark: "#212529" } },\n recipes: {\n solid: {\n primary: { background: "primary", color: "primary.text" },\n neutral: { background: "neutral.light", color: "neutral.dark" },\n },\n },\n },\n },\n targets: [\n // The CSS adapter (from @theme-registry/refract-css). Pass its options here, at construction.\n { adapter: createCssAdapter(/* { colors: { prefix: "app" } } */), outDir: "dist/theme" },\n\n // Add another adapter target once its package is installed, e.g.:\n // import { createStyledComponentsAdapter } from "@theme-registry/refract-styled-components";\n // { adapter: createStyledComponentsAdapter(), outDir: "dist/theme-sc" },\n ],\n});\n`}function bs(r={}){var n,o,s,i;const a=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),l=null!==(o=r.variant)&&void 0!==o?o:"ts",c=null!==(s=r.packageName)&&void 0!==s?s:us(),u=t.join(a,`theme.config.${l}`);if(e.existsSync(u)&&!r.force)throw new Error(`theme.config.${l} already exists at "${u}". Pass --force to overwrite it.`);const d=null===r.rawTheme?void 0:null!==(i=r.rawTheme)&&void 0!==i?i:ps(a),f=d?hs(c,d):gs(c);return e.writeFileSync(u,f,"utf8"),{path:u,variant:l,packageName:c,rawTheme:d}}const vs=[["xs",-2],["sm",-1],["md",0],["lg",1],["xl",2],["2xl",3],["3xl",4],["4xl",5]],ys={"minor-second":1.067,"major-second":1.125,"minor-third":1.2,"major-third":1.25,"perfect-fourth":1.333,"augmented-fourth":1.414,"perfect-fifth":1.5,golden:1.618},ws={complement:[180],analogous:[-30,30],"split-complement":[150,210],triadic:[120,240],tetradic:[90,180,270],pentadic:[72,144,216,288]},$s=["primary","secondary","tertiary","quaternary","quinary"],ks=[["success","#2f9e44","#ffffff"],["info","#1c7ed6","#ffffff"],["warning","#e89012","#1f2733"],["danger","#e03131","#ffffff"]],xs=[50,100,200,300,400,500,600,700,800,900],js=[8,14,22],As="system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",Ss="ui-monospace, 'SF Mono', Menlo, Consolas, monospace",Es={neutral:{label:"Neutral",blurb:"system type, comfortable spacing, soft corners",fontFamily:{base:As,mono:Ss},spacing:{xs:1,sm:2,md:4,lg:6,xl:8,"2xl":12},radius:{base:8,variants:{none:0,sm:4,lg:14,pill:"9999px"}},ratio:"major-third"},compact:{label:"Compact",blurb:"dense UI, tight scale, small radius",fontFamily:{base:As,mono:Ss},spacing:{xs:1,sm:2,md:3,lg:4,xl:6,"2xl":8},radius:{base:4,variants:{none:0,sm:2,lg:8,pill:"9999px"}},ratio:"major-second"},editorial:{label:"Editorial",blurb:"serif display, spacious, generous leading",fontFamily:{base:"'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif",mono:Ss},spacing:{xs:2,sm:4,md:6,lg:8,xl:12,"2xl":16},radius:{base:2,variants:{none:0,sm:1,lg:4,pill:"9999px"}},ratio:"perfect-fourth"},technical:{label:"Technical",blurb:"mono accents, compact, sharp corners",fontFamily:{base:Ss,mono:Ss},spacing:{xs:1,sm:2,md:3,lg:4,xl:6,"2xl":8},radius:{base:0,variants:{none:0,sm:0,lg:2,pill:"9999px"}},ratio:"minor-third"}},Rs=(e,t)=>Number(e.toFixed(t)),Cs=e=>Je(Xe(e).rgb),Os=e=>Rs(Math.min(1.7,Math.max(1.1,1.5*Math.pow(16/e,.22))),2),Ts=e=>`${Rs(.36/e-.0225,3)}em`,Fs=e=>{const t=1e3-10*e;let r=xs[0];for(const e of xs)Math.abs(e-t)<Math.abs(r-t)&&(r=e);return r},_s=e=>{if(!(e<=1))return 2===e?"complement":3===e?"triadic":4===e?"tetradic":"pentadic"},Ns=e=>Object.keys(ws).filter(t=>ws[t].length===e-1);function Ps(e){var t,r,n,o,s,i,a,l,c;const u=null!==(t=e.mode)&&void 0!==t?t:"auto",d=Es[null!==(r=e.feel)&&void 0!==r?r:"neutral"],f=Math.min(5,Math.max(1,null!==(n=e.brandCount)&&void 0!==n?n:2)),p=null!==(o=e.baseFontSize)&&void 0!==o?o:16,m=null!==(s=e.ratio)&&void 0!==s?s:d.ratio,h=ys[m];if(!h)throw new Error(`Unknown type ratio "${m}". Use one of: ${Object.keys(ys).join(", ")}.`);const g=Cs(e.seed),b=[{name:$s[0],hex:g,rotation:0}];if("manual"===u)(null!==(i=e.extraColors)&&void 0!==i?i:[]).slice(0,$s.length-1).forEach((e,t)=>{b.push({name:$s[t+1],hex:Cs(e),rotation:0})});else if(f>1){const t=null!==(a=e.scheme)&&void 0!==a?a:_s(f),r=ws[t];if(!r)throw new Error(`Unknown harmony scheme "${t}".`);r.slice(0,f-1).forEach((e,t)=>{b.push({name:$s[t+1],hex:Cs(lt(g,e)),rotation:e})})}const v=null!==(l=e.contrast)&&void 0!==l?l:"AA",y=[...b.map(e=>({name:e.name,base:e.hex,text:"#ffffff"})),...!1===e.semantics?[]:ks.map(([e,t,r])=>({name:e,base:t,text:r})),...!1===e.neutral?[]:[{name:"neutral",base:"#6b7280",text:"#ffffff"}]],{palettes:w,adjustments:$}="none"===v?{palettes:y,adjustments:[]}:function(e,t){var r;const n=e.map(e=>({...e})),o=new Map(n.map(e=>[e.name,0])),s=new Map,i=()=>{var e,r;const o={};for(const e of n)o[e.name]={base:e.base,text:e.text};const s=co({colors:o},{adapter:Ro()}),i=hr(s,{minWcag:t,includeRecipes:!1}),a=new Map;for(const t of i.pairings){if(t.skipped||void 0===t.wcagRatio)continue;const n=t.label.replace(/^colors\./,"");a.set(n,{ratio:t.wcagRatio,level:null!==(e=t.wcagLevel)&&void 0!==e?e:"fail",pass:null!==(r=t.pass)&&void 0!==r&&r})}return a};let a=i();for(const[e,t]of a)s.has(e)||s.set(e,t.ratio);for(let e=0;e<40;e++){const e=n.filter(e=>a.get(e.name)&&!a.get(e.name).pass);if(!e.length)break;for(const t of e)t.base=Cs(it(t.base,1)),o.set(t.name,(null!==(r=o.get(t.name))&&void 0!==r?r:0)+1);a=i()}const l=n.map((t,r)=>{var n,i,l,c;const u=a.get(t.name);return{name:t.name,seed:e[r].base,final:t.base,nudge:null!==(n=o.get(t.name))&&void 0!==n?n:0,ratioBefore:Rs(null!==(i=s.get(t.name))&&void 0!==i?i:0,2),ratioAfter:Rs(null!==(l=null==u?void 0:u.ratio)&&void 0!==l?l:0,2),levelAfter:null!==(c=null==u?void 0:u.level)&&void 0!==c?c:"fail",unresolved:!!u&&!u.pass}});return{palettes:n,adjustments:l}}(y,v),k={};for(const e of w)k[e.name]={base:e.base,text:e.text,steps:[...xs]};if(!1!==e.shadows){const e={};for(const t of js)e[`a${String(t).padStart(2,"0")}`]={modifiers:[{alpha:t}]};k.shadow={base:"#18274b",variants:e}}const x=vs.map(([e,t])=>({step:e,px:Rs(p*Math.pow(h,t),2)})),j={},A={};for(const{step:e,px:t}of x)"md"!==e&&(j[e]=Os(t),A[e]=Ts(t));A.caps="0.06em";const S={fontFamily:{base:d.fontFamily.base,variants:{mono:d.fontFamily.mono}},fontWeight:{base:400,variants:{medium:500,semibold:600,bold:700}},fontSize:{base:p,ratio:m},lineHeight:{base:Os(p),variants:j},letterSpacing:{base:"0em",variants:A}},E={spacing:{base:4,step:4,steps:{...d.spacing}}},R={width:{base:1,variants:{thick:2}},style:{base:"solid"},radius:{base:d.radius.base,variants:{...d.radius.variants}}},C=!1===e.shadows?void 0:{shadow:{offsetY:1,blur:3,color:"colors.shadow.a08",variants:{md:{offsetY:6,blur:16,color:"colors.shadow.a14"},lg:{offsetY:14,blur:34,color:"colors.shadow.a22"},none:"none"}}},O={colors:k,typography:S,layout:E,borders:R,...C?{effects:C}:{},animation:{duration:{base:200,variants:{fast:120,slow:400}},easing:{base:"cubic-bezier(.2,.7,.3,1)",variants:{out:"cubic-bezier(.16,.84,.44,1)"}}},..."none"===e.reset?{}:{globals:{preset:null!==(c=e.reset)&&void 0!==c?c:"preflight"}}},T=Rs(rt(Xe(g).rgb).L,1);return{raw:O,report:{seedLightness:T,nearestStep:Fs(T),brand:b.map(e=>{var t;const r=$.find(t=>t.name===e.name);return{name:e.name,hex:null!==(t=null==r?void 0:r.final)&&void 0!==t?t:e.hex,rotation:e.rotation}}),contrast:$,type:x.map(({step:e,px:t})=>({step:e,px:t,leading:Os(t),tracking:Ts(t)})),spacing:Object.entries(d.spacing).map(([e,t])=>({step:e,px:4*t}))}}}const zs="theme.raw",qs=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Ms=e=>JSON.stringify(e);function Is(e,t=0){const r=" ".repeat(t),n=" ".repeat(t+1);if(null===e)return"null";if("string"==typeof e)return Ms(e);if("number"==typeof e||"boolean"==typeof e)return String(e);if(Array.isArray(e)){if(!e.length)return"[]";if(e.every(e=>null===e||"object"!=typeof e)){const t=`[${e.map(e=>Is(e)).join(", ")}]`;if(r.length+t.length<=76)return t}return`[\n${e.map(e=>`${n}${Is(e,t+1)}`).join(",\n")}\n${r}]`}const o=Object.entries(e);if(!o.length)return"{}";return`{\n${o.map(([e,r])=>{const o=qs.test(e)?e:Ms(e);return`${n}${o}: ${Is(r,t+1)}`}).join(",\n")}\n${r}}`}const Ls=(e,t)=>`// Generated by \`refract create\` — seed ${e} · ${t}.\n// This is YOUR theme now: every value is a literal you can read, edit and delete. The generator\n// does not run again. Tonal ladders, the type scale and the spacing ramp are synthesized by the\n// engine from the declarations below — re-tune a scale by editing one word, not eight numbers.\n`;function Bs(e,t){if("json"===t.format)return`${JSON.stringify(e,null,2)}\n`;const r=Is(e);return"js"===t.format?`${Ls(t.seed,t.detail)}\n/** @type {import("${t.packageName}/build").RawTheme} */\nexport const raw = ${r};\n`:`${Ls(t.seed,t.detail)}import type { RawTheme } from "${t.packageName}/build";\n\nexport const raw = ${r} satisfies RawTheme;\n`}function Us(e){var t,r,n,o,s,i;const a=[],l="manual"===e.mode?(null!==(r=null===(t=e.extraColors)||void 0===t?void 0:t.length)&&void 0!==r?r:0)+1:null!==(n=e.brandCount)&&void 0!==n?n:2;return a.push(`${l} brand colour${1===l?"":"s"}`),"manual"!==e.mode&&l>1&&a.push(null!==(o=e.scheme)&&void 0!==o?o:"auto"),a.push(null!==(s=e.feel)&&void 0!==s?s:"neutral"),"none"!==e.contrast&&a.push(`WCAG ${null!==(i=e.contrast)&&void 0!==i?i:"AA"}`),a.join(" · ")}function Ds(r){var n,o,s,i;const a=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),l=null!==(o=r.format)&&void 0!==o?o:"ts",c=null!==(s=r.out)&&void 0!==s?s:`${zs}.${l}`,u=t.join(a,c);if(e.existsSync(u)&&!r.force)throw new Error(`"${c}" already exists. Re-run with --force to overwrite it.`);const{raw:d,report:f}=Ps(r),p=Bs(d,{format:l,packageName:null!==(i=r.packageName)&&void 0!==i?i:us(),seed:r.seed,detail:Us(r)});return e.writeFileSync(u,p,"utf8"),{path:u,format:l,raw:d,report:f,sections:Object.keys(d)}}const Vs=(e,t)=>Boolean(process.stdout.isTTY)&&!process.env.NO_COLOR?`[${e}m${t}[0m`:t,Ws=e=>Vs("1",e),Hs=e=>Vs("2",e),Gs=e=>Vs("36",e),Ys=e=>Vs("32",e),Js=e=>Vs("33",e);class Ks{constructor(e=Boolean(process.stdin.isTTY)&&Boolean(process.stdout.isTTY)){this.interactive=e}get io(){return this.rl||(this.rl=n.createInterface({input:process.stdin,output:process.stdout})),this.rl}close(){var e;null===(e=this.rl)||void 0===e||e.close(),this.rl=void 0}question(e){return new Promise(t=>this.io.question(e,e=>t(e)))}write(e=""){process.stdout.write(`${e}\n`)}async text(e,t,r){if(!this.interactive)return t;for(;;){const n=(await this.question(`${Gs("?")} ${Ws(e)} ${Hs(`(${t})`)} `)).trim()||t,o=null==r?void 0:r(n);if(!o)return n;this.write(` ${Js("!")} ${o}`)}}async number(e,t,r){const n=await this.text(e,String(t),e=>{const t=Number(e);return Number.isFinite(t)?null==r?void 0:r(t):`"${e}" is not a number.`});return Number(n)}async select(e,t,r=0){var n,o;if(!this.interactive||1===t.length)return null!==(o=null===(n=t[r])||void 0===n?void 0:n.value)&&void 0!==o?o:t[0].value;for(this.write(`${Gs("?")} ${Ws(e)}`),t.forEach((e,t)=>{const n=t===r?Ys("❯"):" ",o=e.hint?` ${Hs(`— ${e.hint}`)}`:"";this.write(` ${n} ${Hs(`${t+1}.`)} ${t===r?Ws(e.label):e.label}${o}`)});;){const e=(await this.question(` ${Hs(`1–${t.length}`)} `)).trim();if(!e)return t[r].value;const n=Number(e)-1;if(Number.isInteger(n)&&n>=0&&n<t.length)return t[n].value;this.write(` ${Js("!")} Enter a number between 1 and ${t.length}.`)}}async multiselect(e,t,r){if(!this.interactive)return r.map(e=>t[e].value);for(this.write(`${Gs("?")} ${Ws(e)} ${Hs('(comma-separated, blank = keep, "none" = clear)')}`),t.forEach((e,t)=>{const n=r.includes(t),o=e.hint?` ${Hs(`— ${e.hint}`)}`:"";this.write(` ${n?Ys("◉"):Hs("◯")} ${Hs(`${t+1}.`)} ${e.label}${o}`)});;){const e=(await this.question(` ${Hs(`1–${t.length}`)} `)).trim().toLowerCase();if(!e)return r.map(e=>t[e].value);if("none"===e)return[];const n=e.split(",").map(e=>Number(e.trim())-1);if(n.every(e=>Number.isInteger(e)&&e>=0&&e<t.length))return n.map(e=>t[e].value);this.write(` ${Js("!")} Enter numbers between 1 and ${t.length}, separated by commas.`)}}}const Xs={complement:"one companion, 180° opposite — maximum separation",analogous:"two neighbours, ±30° — quiet and cohesive","split-complement":"the complement's neighbours — contrast with less tension",triadic:"even thirds, ±120° — three colours of equal weight",tetradic:"two complementary pairs — the most range",pentadic:"five evenly spaced hues — needs a dominant colour picked by hand"},Zs=[["major-second","1.125 · 16 · 18 · 20 · 23 · 26 · 29"],["minor-third","1.2 · 16 · 19 · 23 · 28 · 33 · 40"],["major-third","1.25 · 16 · 20 · 25 · 31 · 39 · 49"],["perfect-fourth","1.333 · 16 · 21 · 28 · 38 · 51 · 67"],["perfect-fifth","1.5 · 16 · 24 · 36 · 54 · 81 · 122"],["golden","1.618 · 16 · 26 · 42 · 68 · 110 · 178"]],Qs=e=>{try{return void Xe(e)}catch{return`"${e}" isn't a colour refract can parse. Try a hex like #4c6ef5.`}};async function ei(e,t={}){var r,n,o,s,i,a,l,c;const u=null!==(r=t.seed)&&void 0!==r?r:await e.text("Primary colour","#4c6ef5",Qs),d=Math.round(10*rt(Xe(u).rgb).L)/10;e.write(` ${Hs(`parsed · lightness ${d}% — lands at ≈${Fs(d)} on the ladder`)}`),e.write();const f=Boolean(t.manual);let p,m=2,h=[];if(f){if(h=(null!==(n=t.colors)&&void 0!==n?n:"").split(",").map(e=>e.trim()).filter(Boolean),!h.length&&e.interactive){const t=await e.number("How many brand colours in total?",2,e=>Number.isInteger(e)&&e>=1&&e<=5?void 0:"Pick a whole number from 1 to 5.");for(let r=1;r<t;r++)h.push(await e.text(`Brand colour ${r+1}`,"#e64980",Qs))}m=h.length+1}else{m=t.colors?Number(t.colors):await e.number("How many brand colours? (including the primary)",2,e=>Number.isInteger(e)&&e>=1&&e<=5?void 0:"Pick a whole number from 1 to 5.");const r=Ns(m);p=null!==(o=t.scheme)&&void 0!==o?o:_s(m),!t.scheme&&r.length>1&&(p=await e.select("Harmony scheme",r.map(e=>({value:e,label:e,hint:Xs[e]})),Math.max(0,r.indexOf(p)))),p&&m>1&&(e.write(` ${Hs(`→ ${p} · each member becomes its own palette with a full ladder`)}`),e.write())}const g=t.noSemantics||t.noNeutral||t.noShadows||!e.interactive?{semantics:!t.noSemantics,neutral:!t.noNeutral,shadows:!t.noShadows}:await(async()=>{const t=await e.multiselect("Also add",[{value:"semantics",label:"Semantic colours",hint:"success · info · warning · danger"},{value:"neutral",label:"Neutral ramp",hint:"50 … 900"},{value:"shadows",label:"Shadow tints",hint:"3 alpha levels + the effects ramp"}],[0,1,2]);return{semantics:t.includes("semantics"),neutral:t.includes("neutral"),shadows:t.includes("shadows")}})(),b=null!==(s=t.contrast)&&void 0!==s?s:await e.select("Contrast target",[{value:"AA",label:"WCAG AA",hint:"4.5:1 body text"},{value:"AAA",label:"WCAG AAA",hint:"7:1 — expect heavier nudges"},{value:"none",label:"Skip",hint:"write the colours exactly as given"}]),v=void 0!==t.baseSize?Number(t.baseSize):await e.number("Base font size (px)",16,e=>e>0?void 0:"Must be greater than zero."),y=null!==(i=t.feel)&&void 0!==i?i:await e.select("Overall feel",Object.keys(Es).map(e=>({value:e,label:Es[e].label,hint:Es[e].blurb}))),w=null!==(a=t.ratio)&&void 0!==a?a:await e.select("Type scale",Zs.map(([e,t])=>({value:e,label:e,hint:t})),Math.max(0,Zs.findIndex(([e])=>e===Es[y].ratio))),$=null!==(l=t.reset)&&void 0!==l?l:await e.select("CSS reset",[{value:"preflight",label:"preflight",hint:"full normalization + an h1–h6 size map"},{value:"normalize",label:"normalize",hint:"the classic, no heading map"},{value:"none",label:"none",hint:"you already ship one"}]),k=null!==(c=t.format)&&void 0!==c?c:await e.select("Format",[{value:"ts",label:"theme.raw.ts",hint:"typed, `satisfies RawTheme`"},{value:"js",label:"theme.raw.js",hint:"plain ESM, no build step"},{value:"json",label:"theme.raw.json",hint:"portable, no code at all"}]);return{seed:u,mode:f?"manual":"auto",brandCount:m,scheme:p,extraColors:h,...g,contrast:b,baseFontSize:v,ratio:w,feel:y,reset:$,format:k}}function ti(e,t){const r=[],{contrast:n}=e.report;if(n.length){r.push(` ${Hs(`Contrast · ${n.length} pairings checked`)}`);for(const e of n){const t=e.nudge>0?`${Js(`−${e.nudge}`)} ${Ys(`${e.ratioAfter} ${e.levelAfter}`)}`:Hs("unchanged"),n=e.unresolved?` ${Js("! still short of the bar")}`:"";r.push(` ${e.name.padEnd(10)} ${String(e.ratioBefore).padStart(5)} ${t}${n}`)}r.push("")}const o=n.filter(e=>e.nudge>0).length;return r.push(` ${Hs(`${e.sections.length} subsystems · ${t} variables · 0 recipes`)}`),o&&r.push(` ${Hs(`${o} colour${1===o?"":"s"} darkened to clear the contrast bar`)}`),r}const ri="theme.config.ts";function ni(e){const t={};for(const r of e.split(",")){const[e,n]=r.split(":"),o=null==e?void 0:e.trim(),s=Number.parseFloat((null!=n?n:"").trim());o&&Number.isFinite(s)&&(t[o]=s)}return t}function oi(e,t,r){return`// Generated by \`refract import\` from ${r}.\n// DTCG carries property tokens ONLY — recipes, components, composition, and states are not imported.\n// The mapping is heuristic (subsystem inferred from \`$type\`/name; \`border\` composite colors dropped;\n// rem rounded to px). Review the seeded tokens, then hand-author the rest of your theme below.\nimport type { RawTheme } from "${e}/build";\n\nexport const raw: RawTheme = ${JSON.stringify(t,null,2)};\n`}function si(e,t){return`import { defineConfig } from "${e}/build";\nimport { createCssAdapter } from "${cs}";\nimport { raw } from "${t}";\n\n// Generated by \`refract import\`. This is your build config — edit it freely. Add adapter options at\n// construction (\`createCssAdapter({ … })\`) and extra targets (SC/JSON/…) as their packages install.\nexport default defineConfig({\n raw,\n targets: [\n { adapter: createCssAdapter(), outDir: "dist/theme" },\n ],\n});\n`}function ii(e){const t={};for(const[r,n]of Object.entries(e))"breakpoints"!==r&&(t[r]=n&&"object"==typeof n?Object.keys(n).length:0);return t}function ai(r){var n,o;const s=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),i=null!==(o=r.packageName)&&void 0!==o?o:us(),a=t.isAbsolute(r.input)?r.input:t.resolve(s,r.input);if(!e.existsSync(a))throw new Error(`No DTCG document found at "${r.input}" (resolved to "${a}").`);let l;try{l=JSON.parse(e.readFileSync(a,"utf8"))}catch(e){throw new Error(`"${a}" is not valid JSON: ${e.message}`)}const c={};r.breakpointGroup&&(c.breakpointGroup=r.breakpointGroup),r.breakpoints&&Object.keys(r.breakpoints).length&&(c.breakpoints=r.breakpoints);const u=Co(l,c),d=r.out?t.isAbsolute(r.out)?r.out:t.resolve(s,r.out):t.resolve(s,"theme.raw.ts");if(e.existsSync(d)&&!r.force)throw new Error(`${t.basename(d)} already exists at "${d}". Pass --force to overwrite it.`);let f;if(e.mkdirSync(t.dirname(d),{recursive:!0}),e.writeFileSync(d,oi(i,u,JSON.stringify(t.basename(a))),"utf8"),!r.rawOnly){if(f=t.resolve(t.dirname(d),ri),e.existsSync(f)&&!r.force)throw new Error(`${ri} already exists at "${f}". Pass --force to overwrite it, or --raw-only to skip writing a config.`);const n=`./${t.basename(d).replace(/\.(ts|mts|cts|tsx)$/,"")}`;e.writeFileSync(f,si(i,n),"utf8")}return{inputFile:a,rawFile:d,configFile:f,sections:Object.keys(u),counts:ii(u)}}async function li(e={}){var r;const n=null!==(r=e.cwd)&&void 0!==r?r:process.cwd(),{config:o,path:s}=await ls({cwd:n,configPath:e.configPath});if(!o.targets.length)throw new Error(`"${s}" has no targets to build.`);const i=function(e,t){if(void 0===t)return[...e];const r=e.filter(e=>e.name===t);if(r.length)return r;if(/^\d+$/.test(t)){const r=Number(t);if(r>=0&&r<e.length)return[e[r]]}const n=e.filter(e=>e.outDir===t);if(n.length)return n;throw new Error(`No target matched "${t}". Config has ${e.length} target(s): `+e.map((e,t)=>{var r;return null!==(r=e.name)&&void 0!==r?r:`#${t} (${e.outDir})`}).join(", ")+".")}(o.targets,e.target);if(void 0!==e.out&&i.length>1)throw new Error(`--out is ambiguous across ${i.length} targets; pass --target to pick one first.`);const a=t.dirname(s),l=[];for(const r of i){const s=void 0!==e.out?t.isAbsolute(e.out)?e.out:t.resolve(n,e.out):t.isAbsolute(r.outDir)?r.outDir:t.resolve(a,r.outDir),i=await ns({raw:o.raw,adapter:r.adapter,outDir:s,helpers:r.helpers,emit:r.emit,media:o.media,units:o.units,baseFontSize:o.baseFontSize,guide:r.guide});l.push({name:r.name,adapter:r.adapter.name,outDir:i.outDir,files:i.files})}return{configPath:s,targets:l}}async function ci(r={}){var n;const o=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),{config:s,path:i}=await ls({cwd:o,configPath:r.configPath}),a=co(s.raw,{adapter:Ro()}),l=Go(a),c=r.out?t.isAbsolute(r.out)?r.out:t.resolve(o,r.out):t.resolve(o,"tokens.json");e.mkdirSync(t.dirname(c),{recursive:!0}),e.writeFileSync(c,`${JSON.stringify(l,null,2)}\n`,"utf8");return{configPath:i,outFile:c,groupCount:Object.keys(l).filter(e=>!e.startsWith("$")).length}}async function ui(e={}){var t;const r=null!==(t=e.cwd)&&void 0!==t?t:process.cwd(),{config:n,path:o}=await ls({cwd:r,configPath:e.configPath}),s=co(n.raw,{adapter:Ro()});return{configPath:o,result:hr(s,{strict:e.strict,minWcag:e.minWcag,largeText:e.largeText})}}const di=(e,t)=>{try{return String(e.resolveToken(t))}catch{return null}},fi=e=>{var t;const r=[];for(const[n,o]of Object.entries(e.model.subsystems))for(const[e,s]of Object.entries(null!==(t=o.ruleSets)&&void 0!==t?t:{}))for(const t of Object.keys(s))r.push({subsystem:n,group:e,variant:t});return r},pi=(e,t,r,n)=>{var o,s,i;return Boolean(null===(i=null===(s=null===(o=e.model.subsystems[t])||void 0===o?void 0:o.ruleSets)||void 0===s?void 0:s[r])||void 0===i?void 0:i[n])};function mi(e,t){const r=((e,t)=>{const r=new Set([...Object.keys(e.tokens),...Object.keys(t.tokens)]),n=[];for(const o of r){const r=o in e.tokens,s=o in t.tokens,i=r?di(e,o):null,a=s?di(t,o):null;r&&!s?n.push({path:o,before:i,after:null,kind:"removed"}):!r&&s?n.push({path:o,before:null,after:a,kind:"added"}):i!==a&&n.push({path:o,before:i,after:a,kind:"changed"})}return n.sort((e,t)=>e.path.localeCompare(t.path))})(e,t),n=((e,t)=>{var r,n,o,s,i,a,l,c;const u=e,d=t;if(!u.renderRecipe&&!d.renderRecipe)return[];const f=new Set,p=[...fi(e),...fi(t)].filter(e=>{const t=`${e.subsystem}.${e.group}.${e.variant}`;return!f.has(t)&&(f.add(t),!0)}),m=[];for(const{subsystem:f,group:h,variant:g}of p){const p=pi(e,f,h,g),b=pi(t,f,h,g),v=null!==(s=null!==(n=null===(r=d.getClass)||void 0===r?void 0:r.call(d,f,h,g))&&void 0!==n?n:null===(o=u.getClass)||void 0===o?void 0:o.call(u,f,h,g))&&void 0!==s?s:`${f}.${h}.${g}`;p&&!b?m.push({name:v,kind:"removed"}):!p&&b?m.push({name:v,kind:"added"}):(null!==(a=null===(i=u.renderRecipe)||void 0===i?void 0:i.call(u,f,h,g))&&void 0!==a?a:"")!==(null!==(c=null===(l=d.renderRecipe)||void 0===l?void 0:l.call(d,f,h,g))&&void 0!==c?c:"")&&m.push({name:v,kind:"changed"})}return m.sort((e,t)=>e.name.localeCompare(t.name))})(e,t),o=((e,t)=>{var r,n,o,s;const i=e=>e?{ratio:e.wcagRatio,level:e.wcagLevel,pass:e.pass}:null,a=e=>new Map(e.map(e=>[e.label,e])),l=a(hr(e).pairings),c=a(hr(t).pairings),u=new Set([...l.keys(),...c.keys()]),d=[];for(const e of u){const t=l.get(e),a=c.get(e),u=i(t),f=i(a);if((null==u?void 0:u.ratio)===(null==f?void 0:f.ratio)&&(null==u?void 0:u.level)===(null==f?void 0:f.level)&&Boolean(t)===Boolean(a))continue;const p=(null!==(r=null==t?void 0:t.pass)&&void 0!==r?r:null)!==(null!==(n=null==a?void 0:a.pass)&&void 0!==n?n:null)||(null!==(o=null==t?void 0:t.wcagLevel)&&void 0!==o?o:null)!==(null!==(s=null==a?void 0:a.wcagLevel)&&void 0!==s?s:null);d.push({label:e,before:u,after:f,crossed:p})}return d.sort((e,t)=>e.label.localeCompare(t.label))})(e,t);return{tokens:r,classes:n,contrast:o,summary:{tokensChanged:r.length,classesChanged:n.length,pairingsCrossed:o.filter(e=>e.crossed).length}}}const hi={fail:0,"AA-large":1,AA:2,AAA:3};let gi=0;async function bi(n){var o,s,i,a;if(!e.existsSync(n))throw new Error(`candidate theme not found at "${n}".`);let l;if(".json"===t.extname(n))l=JSON.parse(e.readFileSync(n,"utf8"));else if(".ts"===t.extname(n)){const{entry:e,cleanup:t}=await h(n);try{const t=await import(r.pathToFileURL(e).href);l=null!==(s=null!==(o=t.default)&&void 0!==o?o:t.raw)&&void 0!==s?s:t}finally{t()}}else{const e=await import(`${r.pathToFileURL(n).href}?v=${++gi}`);l=null!==(a=null!==(i=e.default)&&void 0!==i?i:e.raw)&&void 0!==a?a:e}return function(e,t){const r=t?` (${t})`:"";if(null===e||"object"!=typeof e||Array.isArray(e)){const t=Array.isArray(e)?"an array":null===e?"null":typeof e;throw new y("REFRACT_E_RAW_SHAPE",`Expected a RawTheme object${r}, got ${t}. Pass the raw theme (a module's default export, or a .json raw theme).`)}if(Array.isArray(e.targets))throw new y("REFRACT_E_RAW_SHAPE",`Expected a RawTheme object${r}, but got what looks like a defineConfig({ raw, targets }). Pass its \`raw\` (or a module that default-exports the raw theme), not the whole config.`)}(l,n),l}async function vi(e){var r,n,o,s,i,a,l,c;const u=null!==(r=e.cwd)&&void 0!==r?r:process.cwd(),{config:d,path:f}=await ls({cwd:u,configPath:e.configPath}),p=t.resolve(u,e.candidatePath),m=await bi(p),h={units:d.units,baseFontSize:d.baseFontSize,media:d.media},g=d.targets.map((e,t)=>{var r,n;return{name:null!==(n=null!==(r=e.name)&&void 0!==r?r:e.outDir)&&void 0!==n?n:`target-${t}`,adapter:e.adapter}}),b=g.map(({name:e,adapter:t})=>{var r;try{return co(m,{adapter:t,...h}),{name:e,ok:!0,errors:[]}}catch(t){const n=t;return{name:e,ok:!1,errors:n.failures?[...n.failures]:[null!==(r=n.message)&&void 0!==r?r:String(t)]}}}),v=null!==(o=null!==(n=g.find(({adapter:e})=>"function"==typeof co(d.raw,{adapter:e,...h}).renderRecipe))&&void 0!==n?n:g[0])&&void 0!==o?o:{name:"noop",adapter:Ro()},y=co(d.raw,{adapter:v.adapter,...h});let w={tokens:[],classes:[],contrast:[],summary:{tokensChanged:0,classesChanged:0,pairingsCrossed:0}};try{w=mi(y,co(m,{adapter:v.adapter,...h}))}catch{}const $=[];if(void 0!==e.maxClassChanges&&w.summary.classesChanged>e.maxClassChanges&&$.push(`${w.summary.classesChanged} classes changed (max ${e.maxClassChanges})`),void 0!==e.maxTokenChanges&&w.summary.tokensChanged>e.maxTokenChanges&&$.push(`${w.summary.tokensChanged} tokens changed (max ${e.maxTokenChanges})`),e.failBelow){const t=null!==(s=hi[e.failBelow])&&void 0!==s?s:0;for(const r of w.contrast){const n=(null===(i=r.after)||void 0===i?void 0:i.level)&&null!==(a=hi[r.after.level])&&void 0!==a?a:0,o=(null===(l=r.before)||void 0===l?void 0:l.level)&&null!==(c=hi[r.before.level])&&void 0!==c?c:0;r.after&&n<t&&n<o&&$.push(`${r.label} drops to ${r.after.level} (below ${e.failBelow})`)}}const k=b.filter(e=>!e.ok).map(e=>e.name);return k.length&&$.push(`candidate no longer builds for: ${k.join(", ")}`),{configPath:f,candidatePath:p,diff:w,targets:b,ok:0===$.length,violations:$}}const yi=["claude","codex","opencode","github-copilot","cursor","generic"],wi={claude:{kind:"claude",routerFile:".claude/skills"},codex:{kind:"agents-md",routerFile:"AGENTS.md"},opencode:{kind:"agents-md",routerFile:"AGENTS.md"},"github-copilot":{kind:"agents-md",routerFile:".github/copilot-instructions.md"},cursor:{kind:"agents-md",routerFile:".cursor/rules/refract-skills.mdc"},generic:{kind:"agents-md",routerFile:"AGENTS.md"}},$i="\x3c!-- refract-skills:start --\x3e",ki="\x3c!-- refract-skills:end --\x3e",xi=t.join(".refract","skills.lock"),ji=t.join(".refract","skills");function Ai(e){return null!=e?e:t.join(c(),"skills")}function Si(r){const n=Ai(r);if(!e.existsSync(n))throw new Error(`Skills catalog not found at "${n}". Reinstall @theme-registry/refract.`);return e.readdirSync(n,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>t.join(n,e.name,"SKILL.md")).filter(e.existsSync).map(r=>function(e,r){var n,o,s;const i=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(e),a=i?i[1]:"",l=i?e.slice(i[0].length).replace(/^\s+/,""):e,c=e=>{const t=new RegExp(`^${e}:\\s*(.*)$`,"m").exec(a);return t?t[1].trim():void 0},u=null!==(o=null!==(n=c("name"))&&void 0!==n?n:t.dirname(r).split(/[\\/]/).pop())&&void 0!==o?o:"unnamed",d="optional"===c("tier")?"optional":"core";return{name:u,description:null!==(s=c("description"))&&void 0!==s?s:"",tier:d,raw:e,body:l,sourcePath:r}}(e.readFileSync(r,"utf8"),r)).sort((e,t)=>e.name.localeCompare(t.name))}function Ei(e){const t=e.map(e=>`| [${e.name}](${ji}/${e.name}.md) | ${function(e){const t=e.description.split(/\s*Triggers:/)[0].trim();return(t.split(/\.\s/)[0].trim()||t).replace(/\|/g,"\\|")}(e)} |`).join("\n");return[$i,"","## refract theme skills","","These skills document the [refract](https://github.com/theme-registry/refract) theme toolkit.","When a task matches a row below, read the linked file before working.","","| Skill | Use it for |","| --- | --- |",t,"",ki].join("\n")}function Ri(e,t){const r=e.indexOf($i),n=e.indexOf(ki);if(-1!==r&&-1!==n&&n>r)return e.slice(0,r)+t+e.slice(n+ki.length);const o=e.replace(/\s+$/,"");return o?`${o}\n\n${t}\n`:`${t}\n`}function Ci(r,n){e.mkdirSync(t.dirname(r),{recursive:!0}),e.writeFileSync(r,n,"utf8")}function Oi(r){var n,s,i;const a=null!==(n=r.scope)&&void 0!==n?n:"local",l="global"===a?null!==(s=r.home)&&void 0!==s?s:o.homedir():null!==(i=r.cwd)&&void 0!==i?i:process.cwd(),u=function(e,t){if(t.skills&&t.skills.length>0){const r=new Map(e.map(e=>[e.name,e])),n=[];for(const o of t.skills){const t=r.get(o);if(!t)throw new Error(`Unknown skill "${o}". Available: ${e.map(e=>e.name).join(", ")}.`);n.push(t)}return n}return e.filter(e=>"core"===e.tier||t.includeOptional)}(Si(r.catalogDir),r);if(0===r.agents.length)throw new Error("Pick at least one agent target.");const d=new Set;if(r.agents.some(e=>"agents-md"===wi[e].kind))for(const e of u){const r=t.join(l,ji,`${e.name}.md`);Ci(r,e.body),d.add(r)}for(const n of r.agents){const r=wi[n];if("claude"===r.kind)for(const e of u){const n=t.join(l,r.routerFile,e.name,"SKILL.md");Ci(n,e.raw),d.add(n)}else{const n=t.join(l,r.routerFile);Ci(n,Ri(e.existsSync(n)?e.readFileSync(n,"utf8"):"",Ei(u))),d.add(n)}}const{name:f,version:p}=function(){var r,n;const o=JSON.parse(e.readFileSync(t.join(c(),"package.json"),"utf8"));return{name:null!==(r=o.name)&&void 0!==r?r:"@theme-registry/refract",version:null!==(n=o.version)&&void 0!==n?n:"0.0.0"}}(),m={schema:1,packageName:f,refractVersion:p,scope:a,agents:[...r.agents],skills:u.map(e=>e.name)},h=t.join(l,xi);return Ci(h,`${JSON.stringify(m,null,2)}\n`),{scope:a,agents:[...r.agents],skills:u.map(e=>e.name),files:[...d].sort(),manifestPath:h}}function Ti(r={}){var n,s,i;const a=null!==(n=r.scope)&&void 0!==n?n:"local",l="global"===a?null!==(s=r.home)&&void 0!==s?s:o.homedir():null!==(i=r.cwd)&&void 0!==i?i:process.cwd(),c=t.join(l,xi);if(!e.existsSync(c))throw new Error(`No skills manifest at "${c}". Run \`refract skills install\` first.`);const u=JSON.parse(e.readFileSync(c,"utf8"));return Oi({agents:u.agents,scope:a,skills:u.skills,cwd:r.cwd,home:r.home,catalogDir:r.catalogDir})}const Fi="refract — build a refract theme to disk.\n\nUsage:\n refract create [--seed <color>] [--colors <n|list>] [--scheme <name>] [--manual]\n [--feel <neutral|compact|editorial|technical>] [--ratio <name>]\n [--base-size <px>] [--contrast <AA|AAA|none>] [--reset <name>]\n [--format <ts|js|json>] [--out <file>] [--no-semantics]\n [--no-neutral] [--no-shadows] [--yes] [--force]\n refract init [--js | --mjs] [--force]\n refract import <tokens.json> [--out <file>] [--raw-only] [--force]\n [--breakpoint-group <name>] [--breakpoints <n:px,…>]\n refract build [--config <path>] [--target <name|index>] [--out <dir>]\n refract tokens [--config <path>] [--out <file>]\n refract diff <candidate> [--config <path>] [--max-class-changes <n>]\n [--max-token-changes <n>] [--fail-below <AA|AAA|AA-large>]\n refract audit [--config <path>] [--strict] [--min-wcag <AA|AAA|AA-large>] [--large]\n refract skills <install|list|update> [--agent <a,b|all>] [--global|--local]\n [--only <names>] [--optional]\n refract help\n\nCommands:\n create Design a theme.raw.(ts|js|json) from one seed colour and a short interview.\n init Scaffold a runnable theme.config.(ts|js|mjs) in the current directory.\n import Seed a theme.raw.ts (+ theme.config.ts) from a DTCG tokens.json (one-shot).\n build Load the config and emit every target's files to its outDir.\n tokens Export the theme's tokens as a DTCG tokens.json (adapter-free).\n diff Show a candidate theme's blast radius vs the config (tokens/classes/contrast); thresholds gate CI.\n audit Score colour pairings for WCAG-2 contrast (+ advisory APCA). Reports; --strict fails.\n skills Install the bundled AI skills into your agent CLI(s) (claude/codex/…).\n";function _i(e,t){var r;const n=t,o="string"==typeof n.code&&n.code.startsWith("REFRACT_E_")?`[${n.code}] `:"";if(process.stderr.write(`refract ${e}: ${o}${null!==(r=n.message)&&void 0!==r?r:String(t)}\n`),n.failures)for(const e of n.failures)process.stderr.write(` - ${e}\n`);return 1}async function Ni(e){var t;const{values:r}=i.parseArgs({args:e,options:{seed:{type:"string"},colors:{type:"string"},scheme:{type:"string"},manual:{type:"boolean",default:!1},feel:{type:"string"},ratio:{type:"string"},"base-size":{type:"string"},contrast:{type:"string"},reset:{type:"string"},format:{type:"string"},out:{type:"string"},"no-semantics":{type:"boolean",default:!1},"no-neutral":{type:"boolean",default:!1},"no-shadows":{type:"boolean",default:!1},yes:{type:"boolean",default:!1},force:{type:"boolean",default:!1}},allowPositionals:!1}),n=new Ks(!r.yes&&void 0);try{n.write(),n.write(` ${Ws("refract")} ${Hs("· raw-theme scaffold")}`),n.write();const e=Ds({...await ei(n,{seed:r.seed,colors:r.colors,scheme:r.scheme,manual:r.manual,feel:r.feel,ratio:r.ratio,baseSize:r["base-size"],contrast:r.contrast,reset:r.reset,format:r.format,noSemantics:r["no-semantics"],noNeutral:r["no-neutral"],noShadows:r["no-shadows"]}),out:r.out,force:Boolean(r.force)});n.write();for(const t of ti(e,function(e){try{const t=co(e,{adapter:Ro()});return Object.keys(t.tokens).length}catch{return 0}}(e.raw)))n.write(t);return n.write(),n.write(` ${Ws(null!==(t=e.path.split(/[\\/]/).pop())&&void 0!==t?t:"")} written`),n.write(),n.write(` ${Hs("Next — wire up a build:")} ${Ws("refract init")}`),n.write(),0}catch(e){return _i("create",e)}finally{n.close()}}const Pi=new Set(["AAA","AA","AA-large"]);async function zi(e){const[t,...r]=e;if("list"===t)try{for(const e of Si())process.stdout.write(` ${e.name.padEnd(26)} [${e.tier}] ${e.description.split(/\s*Triggers:/)[0].trim().slice(0,80)}\n`);return 0}catch(e){return _i("skills list",e)}const{values:n}=i.parseArgs({args:r,options:{agent:{type:"string"},global:{type:"boolean",default:!1},local:{type:"boolean",default:!1},only:{type:"string"},optional:{type:"boolean",default:!1}},allowPositionals:!1});if(n.global&&n.local)return process.stderr.write("refract skills: pass at most one of --global / --local.\n"),1;const o=n.global?"global":"local";try{if("update"===t){const e=Ti({scope:o});return process.stdout.write(`Updated ${e.skills.length} skill(s) for ${e.agents.join(", ")} (${e.scope}).\n`),0}if("install"===t||void 0===t){let e,t=Boolean(n.optional),r=o;if(n.agent)e=function(e){if("all"===e.trim())return[...yi];const t=e.split(",").map(e=>e.trim()).filter(Boolean),r=t.filter(e=>!yi.includes(e));if(r.length>0)throw new Error(`unknown agent(s) ${r.map(e=>`"${e}"`).join(", ")}. Known: ${yi.join(", ")}.`);return t}(n.agent);else{if(!process.stdin.isTTY)return process.stderr.write("refract skills install: pass --agent <a,b|all> (no TTY for prompts).\n"),1;{const o=await async function(){const e=s.createInterface({input:process.stdin,output:process.stdout});try{process.stdout.write("Install refract skills for which agent(s)?\n"),yi.forEach((e,t)=>process.stdout.write(` ${t+1}) ${e}\n`));const t=await e.question("Enter numbers (comma-separated), or 'all': "),r="all"===t.trim()||""===t.trim()?[...yi]:t.split(",").map(e=>yi[Number(e.trim())-1]).filter(e=>Boolean(e));if(0===r.length)throw new Error("no agents selected.");return{agents:r,scope:(await e.question("Scope — [l]ocal (project) or [g]lobal (home)? [l]: ")).trim().toLowerCase().startsWith("g")?"global":"local",includeOptional:(await e.question("Include optional skills (adapter-scaffold, troubleshooting)? [y/N]: ")).trim().toLowerCase().startsWith("y")}}finally{e.close()}}();e=o.agents,t=o.includeOptional,n.global||n.local||(r=o.scope)}}const i=Oi({agents:e,scope:r,skills:n.only?n.only.split(",").map(e=>e.trim()).filter(Boolean):void 0,includeOptional:t});process.stdout.write(`Installed ${i.skills.length} skill(s) for ${i.agents.join(", ")} (${i.scope}):\n`);for(const e of i.files)process.stdout.write(` ${e}\n`);return process.stdout.write(` manifest → ${i.manifestPath}\n`),0}return process.stderr.write(`refract skills: unknown subcommand "${t}". Use install | list | update.\n`),1}catch(e){return _i("skills",e)}}async function qi(e){const[t,...r]=e;switch(t){case"create":return Ni(r);case"init":return async function(e){const{values:t}=i.parseArgs({args:e,options:{js:{type:"boolean",default:!1},mjs:{type:"boolean",default:!1},force:{type:"boolean",default:!1}},allowPositionals:!1});if(t.js&&t.mjs)return process.stderr.write("refract init: pass at most one of --js / --mjs.\n"),1;const r=t.mjs?"mjs":t.js?"js":"ts";try{const e=bs({variant:r,force:Boolean(t.force)});return e.rawTheme&&process.stdout.write(`Found ${e.rawTheme.filename} — wired it up.\n`),process.stdout.write(`Created ${e.path}\n`),process.stdout.write(e.rawTheme?"Next: run `refract build`.\n":"Next: edit the starter theme in the config (or run `refract create` to design one), then `refract build`.\n"),0}catch(e){return _i("init",e)}}(r);case"import":return async function(e){const{values:t,positionals:r}=i.parseArgs({args:e,options:{out:{type:"string"},"raw-only":{type:"boolean",default:!1},force:{type:"boolean",default:!1},"breakpoint-group":{type:"string"},breakpoints:{type:"string"}},allowPositionals:!0}),n=r[0];if(!n)return process.stderr.write("refract import: pass the DTCG document to import, e.g. `refract import tokens.json`.\n"),1;if(r.length>1)return process.stderr.write(`refract import: unexpected extra argument "${r[1]}".\n`),1;try{const e=ai({input:n,out:t.out,rawOnly:Boolean(t["raw-only"]),force:Boolean(t.force),breakpointGroup:t["breakpoint-group"],breakpoints:t.breakpoints?ni(t.breakpoints):void 0});process.stdout.write(`Imported ${e.inputFile}\n`),process.stdout.write(` raw → ${e.rawFile}\n`),e.configFile&&process.stdout.write(` config → ${e.configFile}\n`);const r=Object.entries(e.counts).map(([e,t])=>`${e} (${t})`).join(", ");return r&&process.stdout.write(` seeded: ${r}\n`),process.stdout.write("Next: review the inferred tokens, then add recipes/components and run `refract build`.\n"),0}catch(e){return _i("import",e)}}(r);case"build":return async function(e){const{values:t}=i.parseArgs({args:e,options:{config:{type:"string"},target:{type:"string"},out:{type:"string"}},allowPositionals:!1});try{const e=await li({configPath:t.config,target:t.target,out:t.out});process.stdout.write(`Built from ${e.configPath}\n`);for(const t of e.targets){const e=t.name?`${t.name} [${t.adapter}]`:t.adapter;process.stdout.write(` ${e} → ${t.outDir} (${t.files.length} file(s))\n`);for(const e of t.files)process.stdout.write(` ${e}\n`)}return 0}catch(e){return _i("build",e)}}(r);case"tokens":return async function(e){const{values:t}=i.parseArgs({args:e,options:{config:{type:"string"},out:{type:"string"}},allowPositionals:!1});try{const e=await ci({configPath:t.config,out:t.out});return process.stdout.write(`Exported tokens from ${e.configPath}\n`),process.stdout.write(` ${e.groupCount} group(s) → ${e.outFile}\n`),0}catch(e){return _i("tokens",e)}}(r);case"diff":return async function(e){var t,r,n,o;const{values:s,positionals:a}=i.parseArgs({args:e,options:{config:{type:"string"},"max-class-changes":{type:"string"},"max-token-changes":{type:"string"},"fail-below":{type:"string"}},allowPositionals:!0}),l=a[0];if(!l)return process.stderr.write("refract diff: pass the candidate theme, e.g. `refract diff candidate.ts`.\n"),1;const c=s["fail-below"];if(void 0!==c&&!Pi.has(c))return process.stderr.write(`refract diff: --fail-below must be one of AAA | AA | AA-large (got "${c}").\n`),1;try{const e=await vi({configPath:s.config,candidatePath:l,maxClassChanges:void 0!==s["max-class-changes"]?Number(s["max-class-changes"]):void 0,maxTokenChanges:void 0!==s["max-token-changes"]?Number(s["max-token-changes"]):void 0,failBelow:c}),{diff:i}=e;process.stdout.write(`Diffed ${e.candidatePath}\n vs ${e.configPath}\n`),process.stdout.write(` ${i.summary.tokensChanged} token(s), ${i.summary.classesChanged} class(es), ${i.summary.pairingsCrossed} pairing(s) crossed a threshold\n`);for(const e of i.tokens.slice(0,20)){const t="changed"===e.kind?`${e.before} → ${e.after}`:"added"===e.kind?`+ ${e.after}`:`- ${e.before}`;process.stdout.write(` token ${e.path}: ${t}\n`)}i.tokens.length>20&&process.stdout.write(` … +${i.tokens.length-20} more token(s)\n`);for(const e of i.classes)process.stdout.write(` class ${e.kind.padEnd(7)} ${e.name}\n`);for(const e of i.contrast.filter(e=>e.crossed))process.stdout.write(` contrast ${e.label}: ${null!==(r=null===(t=e.before)||void 0===t?void 0:t.level)&&void 0!==r?r:"—"} → ${null!==(o=null===(n=e.after)||void 0===n?void 0:n.level)&&void 0!==o?o:"—"}\n`);if(e.violations.length){process.stderr.write("✗ diff gate failed:\n");for(const t of e.violations)process.stderr.write(` ${t}\n`);return 1}return 0}catch(e){return _i("diff",e)}}(r);case"audit":return async function(e){const{values:t}=i.parseArgs({args:e,options:{config:{type:"string"},strict:{type:"boolean",default:!1},"min-wcag":{type:"string"},large:{type:"boolean",default:!1}},allowPositionals:!1}),r=t["min-wcag"];if(void 0!==r&&!Pi.has(r))return process.stderr.write(`refract audit: --min-wcag must be one of AAA | AA | AA-large (got "${r}").\n`),1;try{const{configPath:e,result:n}=await ui({configPath:t.config,strict:t.strict,minWcag:r,largeText:t.large});process.stdout.write(`Audited ${e}\n`);for(const e of n.pairings)if(e.skipped)process.stdout.write(` ~ ${e.label} — skipped (${e.skipped})\n`);else{const t=e.pass?"✓":"✗";process.stdout.write(` ${t} ${e.label} — ${e.wcagRatio}:1 ${e.wcagLevel} · APCA Lc ${e.apcaLc}\n`)}const o=n.summary;return process.stdout.write(`${o.passed}/${o.total} pass, ${o.failed} fail, ${o.skipped} skipped\n`),0}catch(e){return _i("audit",e)}}(r);case"skills":return zi(r);case void 0:case"help":case"--help":case"-h":return process.stdout.write(Fi),0;default:return process.stderr.write(`refract: unknown command "${t}".\n\n${Fi}`),1}}"undefined"!=typeof require&&"undefined"!=typeof module&&require.main===module&&qi(process.argv.slice(2)).then(e=>process.exit(e),e=>{var t;process.stderr.write(`refract: ${null!==(t=e.stack)&&void 0!==t?t:e}\n`),process.exit(1)}),exports.AGENT_TARGETS=yi,exports.CSS_ADAPTER_PACKAGE=cs,exports.DEFAULT_RAW_BASENAME=zs,exports.FEEL_PRESETS=Es,exports.Prompter=Ks,exports.SCHEME_HINTS=Xs,exports.TYPE_SCALE_CHOICES=Zs,exports.VENDOR_HELPERS=a,exports.bold=Ws,exports.buildGuide=v,exports.compileTsConfigGraph=h,exports.createReportLines=ti,exports.cyan=Gs,exports.defaultSchemeFor=_s,exports.defineConfig=e=>e,exports.deriveLeading=Os,exports.deriveTracking=Ts,exports.diffThemes=mi,exports.dim=Hs,exports.emitTheme=ns,exports.findConfigFile=is,exports.findPackageRoot=c,exports.findRawTheme=ps,exports.findVendorHelper=l,exports.green=Ys,exports.listSkills=Si,exports.loadConfig=ls,exports.main=qi,exports.nearestLadderStep=Fs,exports.parseBreakpointsFlag=ni,exports.promptCreateAnswers=ei,exports.rawThemeImport=ms,exports.readOwnPackageName=us,exports.readVendorSource=u,exports.renderRawTheme=Bs,exports.resolveEmitPlan=ko,exports.runAudit=ui,exports.runBuild=li,exports.runCreate=Ds,exports.runDiff=vi,exports.runImport=ai,exports.runInit=bs,exports.runSkillsInstall=Oi,exports.runSkillsUpdate=Ti,exports.runTokens=ci,exports.scaffoldConfig=gs,exports.scaffoldConfigForRaw=hs,exports.scaffoldImportConfig=si,exports.scaffoldRaw=oi,exports.scaffoldTheme=Ps,exports.schemesFor=Ns,exports.skillsCatalogDir=Ai,exports.transpileToEsm=f,exports.yellow=Js;
|
|
1
|
+
"use strict";var e=require("node:fs"),t=require("node:path"),r=require("node:url"),n=require("node:readline"),o=require("node:os"),s=require("node:readline/promises"),i=require("node:util");const a=[{id:"color-math",outfile:"color-math.js",source:"src/subsystems/colors/utils.ts",exports:["lighten","darken","alpha","setL","rotateHue","complement","adjust","rgbToOklch","oklchToRgb","toHexColor","toOklchColor","convertHexToRGB","convertRgbToHex"],description:"Pure OKLCH colour math — the exact lighten/darken/setL/rotateHue/complement/adjust (+ OKLCH and hex converters) refract synthesizes palette steps/variants with, so a value computed live in the consumer matches the emitted CSS variables."}],l=e=>a.find(t=>t.id===e),c=(r=__dirname)=>{let n=r;for(;;){if(e.existsSync(t.join(n,"package.json")))return n;const o=t.dirname(n);if(o===n)throw new Error(`No package.json found walking up from "${r}".`);n=o}},u=r=>{const n=t.join(c(),r);if(!e.existsSync(n))throw new Error(`Vendor helper source "${r}" not found at "${n}". Ensure it is listed in package.json "files" so it ships with the package.`);return e.readFileSync(n,"utf8")};async function d(){var e;try{const t=await import("typescript");return null!==(e=t.default)&&void 0!==e?e:t}catch{throw new Error('refract: the optional peer dependency "typescript" is required to transpile a `.ts` theme.config or vendor a shared helper module, but it could not be resolved. Install it (`npm i -D typescript`), or use a `.mjs`/`.js` config and avoid the `helpers` opt-in.')}}const f=async e=>{const t=await d();return t.transpileModule(e,{compilerOptions:{module:t.ModuleKind.ESNext,target:t.ScriptTarget.ES2020}}).outputText};let p=0;const m=e=>t.resolve(e).replace(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/,""),h=async r=>{const n=await d(),o={module:n.ModuleKind.ESNext,target:n.ScriptTarget.ES2020,moduleResolution:n.ModuleResolutionKind.Bundler,resolveJsonModule:!0,allowJs:!1,noLib:!0,skipLibCheck:!0,noEmitOnError:!1,declaration:!1,sourceMap:!1,types:[]},s=n.createCompilerHost(o),i=n.createProgram([r],o,s),a=new Map,l=e=>!e.isDeclarationFile&&!e.fileName.includes("/node_modules/")&&/\.(ts|tsx|mts|cts)$/.test(e.fileName);for(const e of i.getSourceFiles()){if(!l(e))continue;const r=t.resolve(e.fileName),n=t.basename(r).replace(/\.(ts|tsx|mts|cts)$/,"");a.set(m(r),t.join(t.dirname(r),`.${n}.${process.pid}-${p++}.mjs`))}const c=e=>r=>{const i=t.resolve(r.fileName),l=e.factory,c=e=>{const r=((e,t)=>{var r;if(!e.startsWith("."))return;const i=null===(r=n.resolveModuleName(e,t,o,s).resolvedModule)||void 0===r?void 0:r.resolvedFileName;return i?a.get(m(i)):void 0})(e,i);return r?l.createStringLiteral(`./${t.basename(r)}`):void 0},u=t=>{if(n.isImportDeclaration(t)&&n.isStringLiteral(t.moduleSpecifier)){const e=c(t.moduleSpecifier.text);if(e)return l.updateImportDeclaration(t,t.modifiers,t.importClause,e,t.attributes)}else if(n.isExportDeclaration(t)&&t.moduleSpecifier&&n.isStringLiteral(t.moduleSpecifier)){const e=c(t.moduleSpecifier.text);if(e)return l.updateExportDeclaration(t,t.modifiers,t.isTypeOnly,t.exportClause,e,t.attributes)}else if(n.isCallExpression(t)&&t.expression.kind===n.SyntaxKind.ImportKeyword&&t.arguments.length&&n.isStringLiteral(t.arguments[0])){const e=c(t.arguments[0].text);if(e)return l.updateCallExpression(t,t.expression,t.typeArguments,[e,...t.arguments.slice(1)])}return n.visitEachChild(t,u,e)};return n.visitNode(r,u)},u=[],f=(t,r)=>{const n=a.get(m(t));n&&(e.writeFileSync(n,r,"utf8"),u.push(n))},h=()=>{for(const t of u)e.rmSync(t,{force:!0})};try{i.emit(void 0,f,void 0,!1,{before:[c]})}catch(e){throw h(),e}const g=a.get(m(r));if(!g||!e.existsSync(g))throw h(),new Error(`refract: failed to compile the \`.ts\` config graph for "${r}".`);return{entry:g,cleanup:h}},g=e=>e.replace(/\|/g,"\\|");function b(e,t,r){var n;const o=[];if(o.push(`# Theme consumption guide (${e.format})`),o.push(""),o.push("This folder is a self-contained theme built with refract. You do NOT need refract to use it —","everything below refers to files in THIS folder (relative paths), so it works whether the theme","was installed as a package, unzipped from an artifact, or vendored into a repo."),o.push(""),t.files.length>0){o.push("## Files"),o.push("");for(const e of t.files)o.push(`- \`./${e}\``);o.push("")}o.push("## How to use"),o.push("");for(const t of e.summary)o.push(t);t.packageName&&(o.push(""),o.push(`If this theme is installed as the \`${t.packageName}\` package, you may import the same`,`files by specifier (e.g. \`${t.packageName}/${null!==(n=t.files[0])&&void 0!==n?n:"theme.css"}\`) instead of by relative path.`)),o.push("");const{recipes:s}=e;if(s.length>0){o.push("## Recipes — real names"),o.push(""),o.push("Use these exact identities; do not invent names."),o.push(""),o.push("| Recipe | Identity |"),o.push("| --- | --- |");const e=s.slice(0,60);for(const t of e)o.push(`| \`${g(`${t.subsystem}.${t.group}.${t.variant}`)}\` | \`${g(t.name)}\` |`);if(s.length>e.length){const t=s.length-e.length;o.push(""),o.push(`_(+${t} more recipe(s) — the complete list is in ${r?`\`./${r}\``:"the manifest"}.)_`)}o.push("")}return r&&(o.push("## Machine-readable index"),o.push(""),o.push(`See \`./${r}\` for the full recipe index and the theme's tokens (DTCG format).`),o.push("")),o.join("\n")}function v(e,t,r){var n;const o=null!==(n=r.llmsFile)&&void 0!==n?n:"llms.txt",s=void 0===r.manifestFile?"manifest.json":r.manifestFile,i={[o]:b(e,r,s)};if(s){const n={schema:1,format:e.format,files:r.files,packageName:r.packageName,recipes:e.recipes,tokens:t};i[s]=`${JSON.stringify(n,null,2)}\n`}return{files:i}}class y extends Error{constructor(e,t,r){super(t),this.name="RefractError",this.code=e,r&&(this.failures=r),Object.setPrototypeOf(this,y.prototype)}}const w=e=>"string"==typeof e||"number"==typeof e,$=e=>Array.isArray(e),k=e=>({value:e}),x=(e,t)=>{if(!t)return k(e);const r={ref:t.ref};return void 0!==t.fn&&(r.fn=t.fn),void 0!==t.arg&&(r.arg=t.arg),void 0!==t.modifiers&&(r.modifiers=t.modifiers),void 0!==e&&(r.value=e),r},j=new Set(["mode","target","base","derive"]),A=(e,t,r)=>{const n={},o=e.derive,s=e.base;if(o){if(void 0===o.ref)throw new y("REFRACT_E_REFERENCE",`Derived appearance mode "${t}.modes.${r}" was not baked — derived modes require a subsystem that resolves them (colors). Use a literal value instead.`);n.base=x(w(s)?s:void 0,o)}else w(s)?n.base=k(s):$(s)&&(n.base={struct:s});for(const[t,r]of Object.entries(e))j.has(t)||w(r)&&(n[t]=k(r));return n},S=(e,t)=>{const r={};for(const[n,o]of Object.entries(e))t.has(n)||w(o)&&(r[n]=k(o));return r},E=new Set(["base","derive"]),R=new Set(["base","responsive","variants","modes","external"]),C=new Set(["breakpoint","query","state","orientation","ref","modifiers","mode","variant","target","derive","ratio","step","steps"]),O=(e,t="property")=>{var r;const n={base:void 0!==e.external?{value:`var(${e.external})`,external:e.external}:(o=e.base,$(o)?{struct:o}:k(o))};var o;const s=S(e,R);if(Object.keys(s).length&&(n.extras=s),e.variants&&Object.keys(e.variants).length){const t={};for(const[r,n]of Object.entries(e.variants)){let e;const o=n.derive;if(w(n.base)?e=x(n.base,o):$(n.base)?e={struct:n.base}:void 0!==(null==o?void 0:o.ref)&&(e=x(void 0,o)),!e)continue;const s=S(n,E);t[r]=Object.keys(s).length?{base:e,extras:s}:{base:e}}Object.keys(t).length&&(n.variants=t)}const i=e.modes;if(i&&i.length){const e=[];for(const r of i){const n=r.mode,o=A(r,t,n);if(!Object.keys(o).length)continue;const s={mode:n,overrides:o};"string"==typeof r.target&&(s.target=r.target),e.push(s)}e.length&&(n.modes=e)}if(null===(r=e.responsive)||void 0===r?void 0:r.length){const t=e.responsive.map(e=>{const t=e,r={breakpoint:t.breakpoint};"string"==typeof t.query&&(r.query=t.query),"string"==typeof t.orientation&&(r.orientation=t.orientation),"string"==typeof t.ref&&(r.ref=t.ref),"string"==typeof t.mode&&(r.mode=t.mode),"string"==typeof t.target&&(r.target=t.target);const n=((e,t)=>{const r={};for(const[n,o]of Object.entries(e))t.has(n)||(w(o)?r[n]=k(o):$(o)&&(r[n]={struct:o}));return r})(t,C),o=t.derive;return o&&n.base&&void 0!==n.base.value&&(n.base=x(n.base.value,o)),Object.keys(n).length&&(r.overrides=n),r});n.responsive=t}return n},T=e=>({kind:"recipe",declarations:{...e.base},overrides:e.responsive.map(e=>{const t={};return void 0!==e.state&&(t.state=e.state),void 0!==e.breakpoint&&(t.breakpoint=e.breakpoint),void 0!==e.query&&(t.query=e.query),void 0!==e.orientation&&(t.orientation=e.orientation),void 0!==e.container&&(t.container=e.container),void 0!==e.size&&(t.size=e.size),void 0!==e.variant&&(t.variant=e.variant),void 0!==e.target&&(t.target=e.target),Object.keys(e.declarations).length&&(t.declarations={...e.declarations}),t})}),F=(e,t)=>{const r=T(e);return r.kind="recipe",t.length&&(r.references=t),r},N=new Set(["colors","typography","layout","effects","borders"]),_=e=>!!e&&Object.keys(e).length>0,P=e=>{var t;if(!e)return;const r={};return e.properties&&Object.keys(e.properties).length&&(r.properties=(e=>{const t={};for(const[r,n]of Object.entries(e))t[r]=O(n,r);return t})(e.properties)),e.extraProperties&&Object.keys(e.extraProperties).length&&(r.properties={...null!==(t=r.properties)&&void 0!==t?t:{},...e.extraProperties}),_(e.ruleSetGroups)&&(r.ruleSets=e.ruleSetGroups),_(e.keyframes)&&(r.keyframes=e.keyframes),Object.keys(r).length?r:void 0},z=e=>{var t,r,n,o;const s={};for(const[i,a]of Object.entries(e.subsystems))for(const[e,l]of Object.entries(null!==(t=a.properties)&&void 0!==t?t:{})){const t=`${i}.${e}`;s[t]=l.base;for(const[e,o]of Object.entries(null!==(r=l.variants)&&void 0!==r?r:{})){s[`${t}.${e}`]=o.base;for(const[r,i]of Object.entries(null!==(n=o.extras)&&void 0!==n?n:{}))s[`${t}.${e}.${r}`]=i}for(const[e,r]of Object.entries(null!==(o=l.extras)&&void 0!==o?o:{}))s[`${t}.${e}`]=r}return s},M=new Set(["px","cm","mm","q","in","pc","pt","rem","em","ex","cap","ch","ic","lh","rlh","%","vw","vh","vi","vb","vmin","vmax","svw","svh","lvw","lvh","dvw","dvh","cqw","cqh","cqi","cqb","cqmin","cqmax"]),q=/^-?(?:\d+\.?\d*|\.\d+)(?:e-?\d+)?$/i,L=/^(-?(?:\d+\.?\d*|\.\d+)(?:e-?\d+)?)([a-z%]+)$/i,I=e=>{if("number"==typeof e)return{value:e};const t=e.trim();if(q.test(t))return{value:Number(t)};const r=L.exec(t);if(r){const t=r[2].toLowerCase();if(M.has(t))return{value:Number(r[1]),unit:t};throw new y("REFRACT_E_UNITS",`Unknown length unit "${r[2]}" in "${e}". Use a CSS unit, or wrap functions/keywords (calc(), clamp(), var(), a keyword) — those pass through as raw strings.`)}return{raw:e}},B={"typography.lineHeight":"none","typography.letterSpacing":"em"},U=(e,t)=>{var r,n,o,s;const i=e.slice(0,e.indexOf("."));return null!==(s=null!==(o=null!==(n=null!==(r=null==t?void 0:t[e])&&void 0!==r?r:B[e])&&void 0!==n?n:null==t?void 0:t[i])&&void 0!==o?o:null==t?void 0:t.default)&&void 0!==s?s:"px"},D=(e,t)=>Number((e/t).toFixed(4)),V=(e,t,r)=>"none"===t?{value:e}:"rem"===t?{value:D(e,r),unit:"rem"}:{value:e,unit:t},W=(e,t,r)=>{if("number"==typeof e){const{value:n,unit:o}=V(e,t,r);return void 0===o?e:{value:n,unit:o}}return e},H={typography:{fontSize:"length",letterSpacing:"length",lineHeight:"length"},layout:{spacing:"length",gutters:"length",sizes:"length"},borders:{width:"length",offset:"length",radius:"length"},effects:{blur:"length",shadow:"shadow"}},G=(e,t)=>{let r=!1;const n={};for(const[o,s]of Object.entries(e)){const e=t(s);e!==s&&(r=!0),n[o]=e}return r?n:e},Y=(e,t,r)=>{const n=t(e.base),o=e.variants?((e,t)=>{let r=!1;const n={};for(const[o,s]of Object.entries(e)){const e=t(s.base),i=s.extras?G(s.extras,t):void 0;e===s.base&&i===s.extras||(r=!0),n[o]=i?{base:e,extras:i}:{base:e}}return r?n:e})(e.variants,t):void 0,s=r&&e.extras?G(e.extras,t):e.extras,i=e.modes?((e,t)=>{let r=!1;const n=e.map(e=>{if(!e.overrides)return e;const n=G(e.overrides,t);return n===e.overrides?e:(r=!0,{...e,overrides:n})});return r?n:e})(e.modes,t):void 0,a=((e,t)=>{if(!e.responsive)return;let r=!1;const n=e.responsive.map(e=>{if(!e.overrides)return e;const n=G(e.overrides,t);return n===e.overrides?e:(r=!0,{...e,overrides:n})});return r?n:e.responsive})(e,t);if(n===e.base&&o===e.variants&&s===e.extras&&i===e.modes&&a===e.responsive)return e;const l={...e,base:n};return void 0!==o&&(l.variants=o),void 0!==s&&(l.extras=s),void 0!==i&&(l.modes=i),void 0!==a&&(l.responsive=a),l},J=(e,t,r,n)=>{const o="shadow"===t?e=>{if(!e.struct)return e;const t=e.struct;let o=!1;const s=t.map(e=>{const t=((e,t,r)=>{const n={...e};let o=!1;for(const s of["offsetX","offsetY","blur","spread"]){const i=e[s];if(void 0===i)continue;const a=W(i,t,r);a!==i&&(n[s]=a,o=!0)}return o?n:e})(e,r,n);return t!==e&&(o=!0),t});return o?{...e,struct:s}:e}:e=>((e,t,r)=>{if(void 0!==e.unit)return e;if(void 0!==e.ref&&void 0===e.value)return e;const n=e.value;if("number"==typeof n){const{value:o,unit:s}=V(n,t,r);return void 0===s?e:{...e,value:o,unit:s}}if("string"==typeof n){const o=I(n);if("raw"in o)return e;if(void 0!==o.unit)return{...e,value:o.value,unit:o.unit};const{value:s,unit:i}=V(o.value,t,r);return void 0===i?{...e,value:s}:{...e,value:s,unit:i}}return e})(e,r,n);return Y(e,o,!1)},K=(e,t={})=>{var r;const n=null!==(r=t.baseFontSize)&&void 0!==r?r:16;let o=!1;const s={};for(const[r,i]of Object.entries(e.subsystems)){const e=H[r];if(!e||!i.properties){s[r]=i;continue}let a=!1;const l={};for(const[o,s]of Object.entries(i.properties)){const i=e[o];if(!i){l[o]=s;continue}const c=U(`${r}.${o}`,t.units),u=J(s,i,c,n);u!==s&&(a=!0),l[o]=u}a?(s[r]={...i,properties:l},o=!0):s[r]=i}return o?{...e,subsystems:s}:e},X=e=>(null==e?void 0:e.propertyPath)?` for "${e.propertyPath}"`:"",Z=(e,t)=>!t||(Array.isArray(t)?t.includes(e):t.has(e));function Q(e,t){const r=e.variants?Object.keys(e.variants):[];if(!r.length)return;const n=new Set(r),o=(null==t?void 0:t.propertyPath)?` for "${t.propertyPath}"`:"";for(const t of e.responsive){if(t.ref&&!n.has(t.ref))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${o} references unknown variant "${t.ref}" (ref).`);if(t.target&&!n.has(t.target))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${o} references unknown target "${t.target}".`)}}const ee=e=>"object"==typeof e&&null!==e&&Array.isArray(e.modifiers),te=(e,t)=>{if(!Array.isArray(e)||0===e.length)throw new y("REFRACT_E_VARIANT",`Derivation "${t}" needs a non-empty "modifiers" array.`);return e.map((e,r)=>{if("object"!=typeof e||null===e||Array.isArray(e))throw new y("REFRACT_E_VARIANT",`Modifier ${r} of "${t}" must be a single-key object like { darken: 10 }.`);const n=Object.keys(e);if(1!==n.length)throw new y("REFRACT_E_VARIANT",`Modifier ${r} of "${t}" must have exactly one fn key; got [${n.join(", ")}].`);return{fn:n[0],arg:e[n[0]]}})},re=new Set(["breakpoint","query","ref","modifiers","mode","target","orientation"]),ne=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),oe=(e,t,r)=>{var n;const o=null!==(n=null!=e?e:t)&&void 0!==n?n:r.fallbackBase;if(void 0===o)throw new y("REFRACT_E_PROPERTY",`Unable to resolve base value${s=r.propertyPath,s?` for "${s}"`:""}.`);var s;return r.coerceValue?r.coerceValue(o):o},se=(e,t)=>{const r=new Set(t),n={},o={};let s=!1;for(const[t,i]of Object.entries(e))r.has(t)?(n[t]=i,s=!0):o[t]=i;return{base:s?n:void 0,extra:o}},ie=(e,t,r,n)=>{var o;if(void 0===e&&(null===(o=n.leafFields)||void 0===o?void 0:o.length)){const e=se(t,n.leafFields);if(void 0!==e.base){const t=e.base;return{base:n.coerceValue?n.coerceValue(t):t,extra:e.extra}}}return{base:oe(e,r,n),extra:t}},ae=(e,t,r,n)=>{const o=r.propertyPath?`${r.propertyPath}.variants.${e}`:`variants.${e}`,s=ne(t)?t:{base:t},{base:i,...a}=s,{base:l,extra:c}=ie(i,a,n,{...r,propertyPath:o});return{...c,base:l}},le=(e,t={})=>{var r;const n=ne(e)?e:{base:e},{base:o,responsive:s,variants:i,modes:a,...l}=n,{base:c,extra:u}=ie(o,l,t.fallbackBase,t),d=i?Object.fromEntries(Object.entries(i).map(([e,r])=>[e,ae(e,r,t,c)])):void 0,f=a?a.map(e=>((e,t)=>{const{mode:r,target:n,...o}=e,s=t.propertyPath?`${t.propertyPath}.modes.${r}`:`modes.${r}`;return{mode:r,...void 0!==n?{target:n}:{},...(()=>{var e;if((null===(e=t.leafFields)||void 0===e?void 0:e.length)&&!("base"in o)&&!ee(o)){const{base:e,extra:r}=se(o,t.leafFields);if(void 0!==e){const n={...r};return n.base=t.coerceValue?t.coerceValue(e):e,n}}if(ee(o)){const{ref:e,modifiers:t,...r}=o,n={...r};return n.derive={...void 0!==e?{ref:e}:{},modifiers:te(t,s)},n}const{base:r,...n}=o,i={...n};if(void 0!==r&&(i.base=Array.isArray(r)||!t.coerceValue?r:t.coerceValue(r)),void 0===i.base&&!i.derive&&!Object.keys(n).length)throw new y("REFRACT_E_MODE",`Appearance mode "${s}" overrides nothing.`);return i})()}})(e,t)):void 0,p={propertyPath:t.propertyPath,allowedBreakpoints:t.allowedBreakpoints},m=(g=p,(null==(h=s)?void 0:h.length)?h.map(e=>{if(!e.breakpoint)throw new y("REFRACT_E_BREAKPOINT",`Responsive entry${X(g)} is missing a "breakpoint" value.`);if((null==g?void 0:g.allowedBreakpoints)&&!Z(e.breakpoint,g.allowedBreakpoints))throw new y("REFRACT_E_BREAKPOINT",`Responsive entry${X(g)} references unknown breakpoint "${e.breakpoint}".`);if(e.ref&&!Z(e.ref,null==g?void 0:g.allowedVariants))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${X(g)} references unknown variant "${e.ref}" (ref).`);if(e.target&&!Z(e.target,null==g?void 0:g.allowedTargets))throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${X(g)} references unknown target "${e.target}".`);const{query:t,...r}=e;return{...r,query:null!=t?t:"exact"}}):[]);var h,g;const b=(null===(r=t.leafFields)||void 0===r?void 0:r.length)?m.map(e=>((e,t)=>{const r={},n={};let o;for(const[t,s]of Object.entries(e))re.has(t)?r[t]=s:"base"===t?o=s:n[t]=s;const s=t.leafFields.some(e=>e in n);if(void 0===o&&!s)return e;const{base:i,extra:a}=ie(o,n,void 0,t);return{...r,...a,base:i}})(e,t)):m;return{...u,base:c,responsive:b,variants:d,modes:f}},ce=["orientation","height","aspectRatio"],ue=(e,t)=>!t||(Array.isArray(t)?t.includes(e):t.has(e)),de=e=>e?` for "${e}"`:"",fe="responsive",pe="states",me="css",he="variants",ge=e=>Array.isArray(e)?e:e&&"object"==typeof e?Object.entries(e).map(([e,t])=>({state:e,...t})):[],be=e=>{var t;return`${e.state}\0${null!==(t=e.target)&&void 0!==t?t:""}`},ve=(e,t)=>{const r=ge(e).map(e=>({...e})),n=new Map(r.map((e,t)=>[be(e),t]));for(const e of ge(t)){const t=be(e),o=n.get(t);void 0!==o?r[o]={...r[o],...e}:(n.set(t,r.length),r.push({...e}))}return r},ye=(e,t)=>{var r,n;const o={...e};for(const[s,i]of Object.entries(t))null!==i?s===fe?o[fe]=[...null!==(r=e[fe])&&void 0!==r?r:[],...i]:s===pe?o[pe]=ve(e[pe],i):s===me?o[me]={...null!==(n=e[me])&&void 0!==n?n:{},...i}:o[s]=i:delete o[s];return o},we=(e,t={})=>{const r=((e,t)=>{if(!Object.values(e).some(e=>null!=e&&"object"==typeof e&&null!=e[he]))return e;const r={},n=(e,n)=>{if(e in r)throw new y("REFRACT_E_VARIANT",`Recipe variant expansion${de(t)} produced a duplicate recipe name "${e}" — a desugared "<recipe>-<variant>" collides with an existing sibling recipe.`);r[e]=n};for(const[t,r]of Object.entries(e)){const{[he]:e,...o}=r;if(n(t,o),null!=e){const r=null!=o[pe]?{...o,[pe]:ge(o[pe]).filter(e=>!e.target)}:o;for(const[o,s]of Object.entries(e))n(`${t}-${o}`,ye(r,s))}}return r})(e,t.propertyPath),n=Object.keys(r),o=n.length?new Set(n):void 0,s={};return n.forEach(e=>{var n;const i=r[e];s[e]=$e(`${null!==(n=t.propertyPath)&&void 0!==n?n:"recipes"}.${e}`,i,{allowedBreakpoints:t.allowedBreakpoints,allowedStates:t.allowedStates,allowedTargets:o,allowedVariants:o,allowedContainers:t.allowedContainers,recipeName:e})}),s},$e=(e,t,r)=>{const{responsive:n,states:o,...s}=t;return{base:s,responsive:[...ke(o,e,r),...xe(n,e,r)]}},ke=(e,t,r)=>ge(e).map(e=>{const{state:n,...o}=e;if(r.allowedStates&&!ue(n,r.allowedStates))throw new y("REFRACT_E_STATE",`Recipe state entry${de(t)} references unknown state "${n}".`);if(o.target&&r.allowedTargets){const e=r.recipeName?`${r.recipeName}-${o.target}`:o.target;if(!ue(e,r.allowedTargets))throw new y("REFRACT_E_RESPONSIVE",`Recipe state entry${de(t)} references unknown target "${o.target}".`)}return{...o,state:n}}),xe=(e,t,r)=>(null==e?void 0:e.length)?e.map(e=>{var n;if(void 0!==e.variant&&void 0!==e.target)throw new y("REFRACT_E_RESPONSIVE",`Responsive entry${de(t)} cannot set both "variant" and "target".`);if(void 0!==e.container)return je(e,t,r);if(!e.breakpoint)throw new y("REFRACT_E_BREAKPOINT",`Responsive recipe entry${de(t)} is missing a "breakpoint" value.`);if(r.allowedBreakpoints&&!ue(e.breakpoint,r.allowedBreakpoints))throw new y("REFRACT_E_BREAKPOINT",`Responsive recipe entry${de(t)} references unknown breakpoint "${e.breakpoint}".`);if(e.state&&r.allowedStates&&!ue(e.state,r.allowedStates))throw new y("REFRACT_E_STATE",`Responsive recipe entry${de(t)} references unknown state "${e.state}".`);if(e.variant&&!ue(e.variant,r.allowedVariants))throw new y("REFRACT_E_RESPONSIVE",`Responsive recipe entry${de(t)} references unknown variant "${e.variant}".`);if(e.target&&!ue(e.target,r.allowedTargets))throw new y("REFRACT_E_RESPONSIVE",`Responsive recipe entry${de(t)} references unknown target "${e.target}".`);return{...e,query:null!==(n=e.query)&&void 0!==n?n:"exact"}}):[],je=(e,t,r)=>{var n,o;const s=e.container;for(const r of ce)if(void 0!==e[r])throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} cannot use "${r}" — container queries respond to a container's inline size, not orientation/height/aspect-ratio.`);const i=null===(n=r.allowedContainers)||void 0===n?void 0:n.get(s);if(r.allowedContainers&&!i)throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} references unknown container "${s}".`);if(void 0===e.size)throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} for container "${s}" is missing a "size" value.`);if(i&&!i.has(e.size))throw new y("REFRACT_E_CONTAINER",`Container recipe entry${de(t)} references unknown size "${e.size}" on container "${s}".`);return{...e,query:null!==(o=e.query)&&void 0!==o?o:"min"}},Ae=(e,t,r={})=>{var n;const o=new Map,s=[],i=null!==(n=r.groupPath)&&void 0!==n?n:"recipes",a=r=>{if(o.has(r))return o.get(r);if(s.includes(r)){const e=[...s,r].join(" -> ");throw new y("REFRACT_E_CYCLE",`Cyclic recipe reference in "${i}": ${e}`)}const n=e[r];if(!n)throw new y("REFRACT_E_REFERENCE",`Recipe variant "${r}" is not defined in "${i}".`);s.push(r);try{const e=t(r,n,a);return o.set(r,e),e}finally{s.pop()}};return{resolve:a,resolveAll:()=>{const t={};for(const r of Object.keys(e))t[r]=a(r);return t}}},Se=(e,t,r,n=new Map,o=new Set)=>{const s=n.get(r);if(void 0!==s)return s;const i=e[r];if(!i)throw new y("REFRACT_E_TOKEN_PATH",`Unknown token path "${r}".`);if(void 0!==i.external){const e=`var(${i.external})`;return n.set(r,e),e}if(void 0===i.ref){if(void 0===i.value)throw new y("REFRACT_E_TOKEN_PATH",`Token "${r}" has neither "ref" nor "value".`);return n.set(r,i.value),i.value}if(o.has(r))throw new y("REFRACT_E_CYCLE",`Cyclic token reference: ${[...o,r].join(" -> ")}`);o.add(r);const a=Se(e,t,i.ref,n,o);let l;if(void 0!==i.modifiers)l=i.modifiers.reduce((e,n)=>{const o=t[n.fn];if(!o)throw new y("REFRACT_E_TOKEN_PATH",`Unknown derivation fn "${n.fn}" for token "${r}".`);return o(e,n.arg)},a);else if(void 0!==i.fn){const e=t[i.fn];if(!e)throw new y("REFRACT_E_TOKEN_PATH",`Unknown derivation fn "${i.fn}" for token "${r}".`);l=e(a,i.arg)}else l=a;return o.delete(r),n.set(r,l),l},Ee=(e,t)=>!!(null==e?void 0:e.ref)&&((void 0!==e.modifiers||void 0!==e.fn)&&(e=>{const[t,r]=e.split(".");return`${t}.${r}`})(e.ref)!==t),Re=(e,t,r,n,o)=>{let s;try{s=Se(t,r,e.ref,n)}catch{throw new y("REFRACT_E_VALIDATION",`${o}: cross-property derivation references unknown token '${e.ref}'.`)}const i=(e,t)=>{const n=r[e];if(!n)throw new y("REFRACT_E_VALIDATION",`${o}: unknown derivation fn '${e}'.`);return n(s,t)};if(void 0!==e.modifiers)for(const t of e.modifiers)s=i(t.fn,t.arg);else void 0!==e.fn&&(s=i(e.fn,e.arg));return{...e,value:s}},Ce=(e,t,r,n,o,s)=>{let i;for(const[a,l]of Object.entries(e))Ee(l,t)&&(i=null!=i?i:{...e},i[a]=Re(l,r,n,o,`${s}.${a}`));return i},Oe=(e,t,r,n,o)=>{const s=e.variants?((e,t,r,n,o)=>{let s;for(const[i,a]of Object.entries(e)){const l=`${t}.variants.${i}`,c=Ee(a.base,t)?Re(a.base,r,n,o,l):a.base,u=a.extras?Ce(a.extras,t,r,n,o,`${l} extra`):void 0;(c!==a.base||u)&&(s=null!=s?s:{...e},s[i]=u?{base:c,extras:u}:{...a,base:c})}return s})(e.variants,t,r,n,o):void 0;let i;if(e.modes)for(let s=0;s<e.modes.length;s++){const a=e.modes[s];if(!a.overrides)continue;const l=Ce(a.overrides,t,r,n,o,`${t}.modes.${a.mode}`);l&&(i=null!=i?i:[...e.modes],i[s]={...a,overrides:l})}if(!s&&!i)return;const a={...e};return s&&(a.variants=s),i&&(a.modes=i),a},Te=(e,t)=>{var r;const n=z(e),o=new Map;let s=!1;const i={};for(const[a,l]of Object.entries(e.subsystems)){let e,c=!1;for(const[s,i]of Object.entries(null!==(r=l.properties)&&void 0!==r?r:{})){const r=Oe(i,`${a}.${s}`,n,t,o);r&&(e=null!=e?e:{...l.properties},e[s]=r,c=!0)}c?(i[a]={...l,properties:e},s=!0):i[a]=l}return s?{...e,subsystems:i}:e},Fe=["min","max","exact","between"],Ne=e=>void 0===e?void 0:e-.02,_e=(e,t)=>{const r=(e=>Object.keys(e).sort((t,r)=>e[t]-e[r]))(e);(e=>{const t=e.filter(e=>Fe.includes(e));if(t.length)throw new y("REFRACT_E_BREAKPOINT",`Breakpoint names conflict with reserved keys: ${t.map(e=>`"${e}"`).join(", ")}. Reserved: ${Fe.map(e=>`"${e}"`).join(", ")}.`)})(r);const n=e=>r[r.indexOf(e)+1],o=r.reduce((r,o)=>{const s=e[o],i=n(o),a=void 0!==i?e[i]:void 0;return r[o]=Pe({own:s,next:a},t),r},{}),s=e=>{const t=o[e];if(!t)throw new y("REFRACT_E_BREAKPOINT",`Breakpoint "${e}" is not defined.`);return t};return{...o,min:(r,n)=>{const o=s(r);return n?t({min:e[r],...n}):o.min},max:(r,o)=>{const i=s(r);if(!o)return i.max;const a=n(r),l=void 0!==a?e[a]:void 0;return t({max:Ne(l),...o})},exact:(r,o)=>{const i=s(r);if(!o)return i.exact;const a=n(r),l=void 0!==a?e[a]:void 0;return t({min:e[r],max:Ne(l),...o})},between:(r,n,o)=>{const s=e[r],i=e[n];if(void 0===s||void 0===i)throw new y("REFRACT_E_BREAKPOINT",`Cannot build media query between "${r}" and "${n}" breakpoints.`);return t({min:s,max:i-.02,...o})}}},Pe=({own:e,next:t},r)=>{const n=Ne(t);return{min:r({min:e}),max:void 0===n?"":r({max:n}),exact:r({min:e,max:n})}},ze="px",Me=16,qe=e=>{var t;return{unit:null!==(t=null==e?void 0:e.unit)&&void 0!==t?t:ze,baseFontSize:(null==e?void 0:e.baseFontSize)&&e.baseFontSize>0?e.baseFontSize:Me}},Le=(e,t)=>{if("px"===t.unit)return`${e}px`;const r=e/t.baseFontSize;return`${Number(r.toFixed(4))}${t.unit}`},Ie=({min:e,max:t,orientation:r},n)=>{const o=[];if(void 0!==e&&void 0!==t&&e>t)throw new y("REFRACT_E_MEDIA","Invalid media query: `min` cannot be greater than `max`.");return void 0!==e&&o.push(`(min-width: ${Le(e,n)})`),void 0!==t&&o.push(`(max-width: ${Le(t,n)})`),r&&o.push(`(orientation: ${r})`),o.length?`@media ${o.join(" and ")}`:""},Be=(e,{min:t,max:r},n)=>{const o=[];if(void 0!==t&&void 0!==r&&t>r)throw new y("REFRACT_E_MEDIA","Invalid container query: `min` cannot be greater than `max`.");return void 0!==t&&o.push(`(min-width: ${Le(t,n)})`),void 0!==r&&o.push(`(max-width: ${Le(r,n)})`),o.length?`@container ${e} ${o.join(" and ")}`:""},Ue={xs:0,sm:576,md:768,lg:992,xl:1280},De=(e,t)=>{const r=qe(t),n={};for(const[t,o]of Object.entries(null!=e?e:{}))n[t]=_e(o.sizes,e=>Be(t,{min:e.min,max:e.max},r));return n},Ve=new Set([3,6]),We=(e,t,r)=>Math.min(r,Math.max(t,e)),He=e=>We(e,0,255),Ge=e=>Math.round(1e3*We(e,0,1))/1e3,Ye=e=>{const t=e.replace(/^\s*#|\s*$/g,"");if(!Ve.has(t.length))throw new Error(`Unsupported hex length: "${t}". Use 3 or 6 digits.`);const r=3===t.length?t.replace(/(.)/g,"$1$1"):t;return[parseInt(r.substring(0,2),16),parseInt(r.substring(2,4),16),parseInt(r.substring(4,6),16)]},Je=e=>{if(3!==e.length)throw new Error(`Expected RGB tuple of length 3, received ${e.length}`);return`#${e.map(e=>{const t=He(Math.round(e)).toString(16);return 1===t.length?`0${t}`:t}).join("")}`},Ke=/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/i,Xe=e=>{const t=e.trim(),r=Ke.exec(t);return r?{rgb:[Number(r[1]),Number(r[2]),Number(r[3])],a:void 0===r[4]?1:Ge(Number(r[4]))}:{rgb:Ye(t),a:1}},Ze=(e,t=1)=>{const r=Ge(t),[n,o,s]=e,i=He(Math.round(n)),a=He(Math.round(o)),l=He(Math.round(s));return r>=1?`rgb(${i}, ${a}, ${l})`:`rgba(${i}, ${a}, ${l}, ${r})`},Qe=180/Math.PI,et=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),tt=e=>e>=.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,rt=e=>{const[t,r,n]=e,o=((e,t,r)=>{const n=.4122214708*e+.5363325363*t+.0514459929*r,o=.2119034982*e+.6806995451*t+.1073969566*r,s=.0883024619*e+.2817188376*t+.6299787005*r,i=Math.cbrt(n),a=Math.cbrt(o),l=Math.cbrt(s);return{L:.2104542553*i+.793617785*a-.0040720468*l,a:1.9779984951*i-2.428592205*a+.4505937099*l,b:.0259040371*i+.7827717662*a-.808675766*l}})(et(t/255),et(r/255),et(n/255)),s=Math.sqrt(o.a*o.a+o.b*o.b);let i=Math.atan2(o.b,o.a)*Qe;return i<0&&(i+=360),{L:100*o.L,C:s,h:i}},nt=e=>{const t=We(e.L,0,100)/100,r=e.h/Qe,n=Math.cos(r),o=Math.sin(r),s=e=>((e,t,r)=>{const n=e+.3963377774*t+.2158037573*r,o=e-.1055613458*t-.0638541728*r,s=e-.0894841775*t-1.291485548*r,i=n*n*n,a=o*o*o,l=s*s*s;return[4.0767416621*i-3.3077115913*a+.2309699292*l,-1.2684380046*i+2.6097574011*a-.3413193965*l,-.0041960863*i-.7034186147*a+1.707614701*l]})(t,e*n,e*o),i=e=>e.every(e=>e>=-1e-6&&e<=1.000001);let a=s(e.C);if(!i(a)){let t=0,r=e.C;for(let e=0;e<24;e++){const e=(t+r)/2;i(s(e))?t=e:r=e}a=s(t)}return[255*tt(We(a[0],0,1)),255*tt(We(a[1],0,1)),255*tt(We(a[2],0,1))]},ot=(e,t)=>{const{rgb:r,a:n}=Xe(e);return Ze(nt(t(rt(r))),n)},st=(e,t)=>ot(e,e=>({...e,L:We(e.L+t,0,100)})),it=(e,t)=>ot(e,e=>({...e,L:We(e.L-t,0,100)})),at=(e,t)=>ot(e,e=>({...e,L:We(t,0,100)})),lt=(e,t)=>ot(e,e=>({...e,h:((e.h+t)%360+360)%360})),ct=(e,t)=>ot(e,e=>({L:void 0===t.l?e.L:We(t.l,0,100),C:void 0===t.c?e.C:Math.max(0,e.C*t.c),h:void 0===t.h?e.h:((e.h+t.h)%360+360)%360})),ut=e=>{const{rgb:t,a:r}=Xe(e),n=Je(t);if(r>=1)return n;return`${n}${He(Math.round(255*r)).toString(16).padStart(2,"0")}`},dt=(e,t)=>{const{rgb:r}=Xe(e);return Ze(r,(e=>We(e,0,100))(t)/100)},ft={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},pt=e=>Math.round(1e3*Math.min(1,Math.max(0,e)))/1e3,mt=(e,t,r)=>{const n=(e%360+360)%360/60,o=(1-Math.abs(2*Math.min(1,Math.max(0,r))-1))*Math.min(1,Math.max(0,t)),s=o*(1-Math.abs(n%2-1)),i=Math.min(1,Math.max(0,r))-o/2,[a,l,c]=n<1?[o,s,0]:n<2?[s,o,0]:n<3?[0,o,s]:n<4?[0,s,o]:n<5?[s,0,o]:[o,0,s];return[255*(a+i),255*(l+i),255*(c+i)]},ht=/^oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*(?:\/\s*([\d.]+)(%?)\s*)?\)$/i,gt=/^hsla?\(\s*([\d.]+)(?:deg)?\s*[, ]\s*([\d.]+)%\s*[, ]\s*([\d.]+)%\s*(?:[,/]\s*([\d.]+)(%?)\s*)?\)$/i,bt=e=>{if("string"==typeof e){const t=(e=>{const t=e.trim(),r=ht.exec(t);if(r){const e="%"===r[2]?Number(r[1]):100*Number(r[1]),t=void 0===r[5]?1:pt("%"===r[6]?Number(r[5])/100:Number(r[5]));return{rgb:nt({L:e,C:Number(r[3]),h:Number(r[4])}),a:t}}const n=gt.exec(t);if(n){const e=void 0===n[4]?1:pt("%"===n[5]?Number(n[4])/100:Number(n[4]));return{rgb:mt(Number(n[1]),Number(n[2])/100,Number(n[3])/100),a:e}}const o=ft[t.toLowerCase()];if(o)return{rgb:Ye(o),a:1};try{return Xe(t)}catch{return null}})(e);if(!t)throw new y("REFRACT_E_COLOR_INPUT",`Invalid colour "${e}". Author a colour as a hex string ("#4dabf7"), an [r, g, b] tuple, or a CSS colour — oklch(), hsl()/hsla(), rgb()/rgba(), or a named keyword (e.g. "rebeccapurple"). A var(--…) can't be tonally derived at build time.`);return Ze(t.rgb,t.a)}if(!Array.isArray(e)||3!==e.length||e.some(e=>"number"!=typeof e))throw new y("REFRACT_E_COLOR_TUPLE",`Invalid colour tuple ${JSON.stringify(e)}. Use an [r, g, b] tuple with 0–255 channels (alpha comes from an \`alpha\` variant, not the base).`);const[t,r,n]=e;return Ze([t,r,n])},vt={lighten:(e,t)=>st(e,Number(t)),darken:(e,t)=>it(e,Number(t)),alpha:(e,t)=>dt(e,Number(t)),setL:(e,t)=>at(e,Number(t)),rotateHue:(e,t)=>lt(e,Number(t)),adjust:(e,t)=>ct(e,t)},yt=["light","lighter"],wt=["dark","darker"],$t=(e,t)=>{if(!e||!e.includes("."))return!1;const[r,n]=e.split(".");return`${r}.${n}`!=`colors.${t}`},kt=(e,t)=>{try{return bt(e)}catch(e){throw new y("REFRACT_E_COLOR_INPUT",`colors.${t}.text — ${e.message}`)}},xt=(e,t,r={})=>{var n;const o=((e,t)=>{let r=t;if(void 0!==t.text&&(r={...r,text:kt(t.text,e)}),t.variants){let n=!1;const o={};for(const[r,s]of Object.entries(t.variants))void 0!==s.text?(o[r]={...s,text:kt(s.text,`${e}.variants.${r}`)},n=!0):o[r]=s;n&&(r={...r,variants:o})}if(t.modes){let n=!1;const o=t.modes.map(t=>void 0!==t.text?(n=!0,{...t,text:kt(t.text,`${e}.modes.${t.mode}`)}):t);n&&(r={...r,modes:o})}return r})(e,t),s=(e=>{try{return Xe(e),!0}catch{return!1}})(o.base),i=!(!o.steps||!o.steps.length),a=Object.keys(r).length>0,l=void 0!==o.harmony;if((i||a||l)&&!s)throw new y("REFRACT_E_STEPS",`colors.${e} declares derived steps/variants but its base "${o.base}" is not a hex or [r,g,b] colour.`);const c=s?St(o,e):{},u=s?Rt(o,e):{},d=null!==(n=o.variants)&&void 0!==n?n:{},f={...c,...u,...d},p=_t(e,o.base,f,r),m={...c,...u,...d,...p},h=At(o,e,m),g=jt(o,e,m);return Object.keys(m).length||h||g?{...o,...Object.keys(m).length?{variants:m}:{},...h?{modes:h}:{},...g?{responsive:g}:{}}:o},jt=(e,t,r)=>{const n=e.responsive;if(!n||!n.length)return;let o=!1;const s=n.map((e,n)=>{const s=e.ref,i=e.modifiers;if(!s||!Array.isArray(i)||!i.length){let t;for(const r of["base","text"]){const n=e[r];if("string"==typeof n||Array.isArray(n)){const o=bt(n);o!==n&&(t=null!=t?t:{...e},t[r]=o)}}return t&&(o=!0),null!=t?t:e}const a=r[s];if(!a)throw new y("REFRACT_E_VARIANT_REF",`colors.${t}.responsive[${n}] references unknown variant "${s}".`);if(void 0===a.base)throw new y("REFRACT_E_VARIANT_REF",`colors.${t}.responsive[${n}] references "${s}", a cross-property derivation — not supported.`);const l=Nt({modifiers:i},t,`responsive[${n}]`);let c=a.base;for(const e of l)c=vt[e.fn](c,e.arg);o=!0;const{ref:u,modifiers:d,...f}=e;return{...f,base:c,derive:{ref:`colors.${t}.${s}`,modifiers:l}}});return o?s:n},At=(e,t,r)=>{const n=e.modes;if(!n||!n.length)return;return n.map(n=>{var o;const s=n.mode,i=n.derive;if(!i)return n;const a=null!==(o=i.modifiers)&&void 0!==o?o:i.fn?[{fn:i.fn,arg:i.arg}]:[];if($t(i.ref,t)){const{base:e,derive:t,...r}=n;return{...r,derive:{ref:i.ref,modifiers:a}}}const l=((n,o)=>{if(!n||n===`colors.${t}`)return{value:e.base,path:`colors.${t}`};const s=n.includes(".")?n.slice(`colors.${t}.`.length):n,i=r[s];if(!i||void 0===i.base)throw new y("REFRACT_E_VARIANT_REF",`colors.${t}.modes.${o} references unknown variant "${n}".`);return{value:i.base,path:`colors.${t}.${s}`}})(i.ref,s);let c=l.value;for(const e of a){const r=vt[e.fn];if(!r)throw new y("REFRACT_E_VARIANT_REF",`Unknown derivation fn "${e.fn}" for appearance mode "colors.${t}.modes.${s}".`);c=r(c,e.arg)}return{...n,base:c,derive:{ref:l.path,modifiers:a}}})},St=(e,t)=>e.steps&&e.steps.length?Ft(e,t):Ot(e,t),Et={complement:[{name:"complement",deg:180}],analogous:[{name:"analogous1",deg:-30},{name:"analogous2",deg:30}],"split-complement":[{name:"split1",deg:150},{name:"split2",deg:210}],triadic:[{name:"triadic1",deg:120},{name:"triadic2",deg:240}],tetradic:[{name:"tetradic1",deg:90},{name:"complement",deg:180},{name:"tetradic2",deg:270}]},Rt=(e,t)=>{const r=e.harmony;if(void 0===r)return{};let n,o;if("string"==typeof r)n=r;else{if("object"!=typeof r||null===r||Array.isArray(r))throw new y("REFRACT_E_HARMONY",`colors.${t}.harmony must be a scheme name or a { scheme: [names] } object.`);{const e=Object.keys(r);if(1!==e.length)throw new y("REFRACT_E_HARMONY",`colors.${t}.harmony object form must name exactly one scheme; got [${e.join(", ")}].`);n=e[0],o=r[n]}}const s=Et[n];if(!s)throw new y("REFRACT_E_HARMONY",`colors.${t}.harmony: unknown scheme "${n}". Use one of ${Object.keys(Et).join(", ")}.`);const i={};return s.forEach((r,n)=>{var s;const a=null!==(s=null==o?void 0:o[n])&&void 0!==s?s:r.name;i[a]={base:lt(e.base,r.deg),derive:{ref:`colors.${t}`,fn:"rotateHue",arg:r.deg}}}),i},Ct=(e,t,r,n,o,s,i,a)=>{var l;const c=e=>e?`colors.${r}.${e}`:`colors.${r}`;let u,d=t.base;for(const t of o){if(void 0!==(null===(l=n[t])||void 0===l?void 0:l.base)){d=n[t].base,u=t;continue}const r=s(d,a);e[t]={base:r,derive:{ref:c(u),fn:i,arg:a}},d=r,u=t}},Ot=(e,t)=>{var r,n,o;const s=null!==(r=e.variants)&&void 0!==r?r:{},i={},a=null!==(n=e.lightenBy)&&void 0!==n?n:10,l=null!==(o=e.darkenBy)&&void 0!==o?o:10;return Ct(i,e,t,s,yt,st,"lighten",a),Ct(i,e,t,s,wt,it,"darken",l),i},Tt=e=>e<=0?100:e>=1e3?0:Math.min(98,Math.max(5,(1e3-e)/10)),Ft=(e,t)=>{var r,n;const o=null!==(r=e.steps)&&void 0!==r?r:[],s=o.find(e=>"number"!=typeof e||isNaN(e)||e<0||e>1e3);if(void 0!==s)throw new y("REFRACT_E_STEPS",`colors.${t}.steps must be numbers in 0–1000 (e.g. [50, …, 950]); got ${JSON.stringify(s)}.`);const i=null!==(n=e.variants)&&void 0!==n?n:{},a={};for(const r of o){const n=r.toString();if(i[n])continue;const o=Tt(r);a[n]={base:at(e.base,o),derive:{ref:`colors.${t}`,fn:"setL",arg:o}}}return a},Nt=(e,t,r)=>{const n=`colors.${t}.variants.${r}`,o=e.modifiers;if(!Array.isArray(o)||0===o.length)throw new y("REFRACT_E_VARIANT",`${n} needs a non-empty "modifiers" array (e.g. [{ darken: 10 }]).`);return o.map((e,o)=>{if("object"!=typeof e||null===e||Array.isArray(e))throw new y("REFRACT_E_VARIANT",`${n}.modifiers[${o}] must be a single-key object like { darken: 10 }.`);const s=Object.keys(e);if(1!==s.length)throw new y("REFRACT_E_VARIANT",`${n}.modifiers[${o}] must have exactly one fn key; got [${s.join(", ")}].`);const i=s[0];if(!vt[i])throw new y("REFRACT_E_VARIANT",`${n}.modifiers[${o}] unknown fn "${i}"; use ${Object.keys(vt).join(" / ")}.`);const a=e[i],l="adjust"===i?((e,t,r)=>{const n=`colors.${t}.variants.${r}.adjust`;if("object"!=typeof e||null===e||Array.isArray(e))throw new y("REFRACT_E_ADJUST",`${n} must be an object with numeric l / c / h dials.`);const{l:o,c:s,h:i}=e,a={};if(void 0!==o){if("number"!=typeof o||isNaN(o)||o<0||o>100)throw new y("REFRACT_E_ADJUST",`${n}.l must be an absolute OKLCH lightness in 0–100; got ${JSON.stringify(o)}.`);a.l=o}if(void 0!==s){if("number"!=typeof s||isNaN(s)||s<0)throw new y("REFRACT_E_ADJUST",`${n}.c must be a non-negative chroma multiplier (1 keeps, 0 greys); got ${JSON.stringify(s)}.`);a.c=s}if(void 0!==i){if("number"!=typeof i||isNaN(i))throw new y("REFRACT_E_ADJUST",`${n}.h must be a numeric hue rotation in degrees; got ${JSON.stringify(i)}.`);a.h=i}return a})(a,t,r):Number(a);return{fn:i,arg:l}})},_t=(e,t,r,n)=>{const o={},s=new Set,i=(t,r)=>{if(void 0===t.base)throw new y("REFRACT_E_VARIANT_REF",`colors.${e} variant chains off "${r}", which is a cross-property derivation — not supported.`);return t.base};function a(l,c){if(o[l])return;if(s.has(l))throw new y("REFRACT_E_CYCLE",`Cyclic colour variant derivation at colors.${e}.${l}.`);s.add(l);const u=Nt(c,e,l);if($t(c.ref,e))return o[l]={derive:{ref:c.ref,modifiers:u}},void s.delete(l);const d=(s=>{if(!s)return{value:t,path:`colors.${e}`};if(o[s])return{value:i(o[s],s),path:`colors.${e}.${s}`};if(r[s])return{value:i(r[s],s),path:`colors.${e}.${s}`};if(n[s])return a(s,n[s]),{value:i(o[s],s),path:`colors.${e}.${s}`};throw new y("REFRACT_E_VARIANT_REF",`colors.${e} variant references unknown source "${s}".`)})(c.ref);let f=d.value;for(const e of u)f=vt[e.fn](f,e.arg);o[l]={base:f,derive:{ref:d.path,modifiers:u}},s.delete(l)}for(const[e,t]of Object.entries(n))a(e,t);return o},Pt=new Set("display position top right bottom left inset inset-block inset-block-start inset-block-end inset-inline inset-inline-start inset-inline-end float clear z-index visibility overflow overflow-x overflow-y overflow-block overflow-inline overflow-clip-margin overflow-anchor box-sizing width height min-width min-height max-width max-height block-size inline-size min-block-size min-inline-size max-block-size max-inline-size aspect-ratio margin margin-top margin-right margin-bottom margin-left margin-block margin-block-start margin-block-end margin-inline margin-inline-start margin-inline-end margin-trim padding padding-top padding-right padding-bottom padding-left padding-block padding-block-start padding-block-end padding-inline padding-inline-start padding-inline-end flex flex-grow flex-shrink flex-basis flex-direction flex-flow flex-wrap order justify-content justify-items justify-self align-content align-items align-self place-content place-items place-self gap row-gap column-gap grid grid-area grid-template grid-template-areas grid-template-columns grid-template-rows grid-auto-columns grid-auto-rows grid-auto-flow grid-column grid-column-start grid-column-end grid-row grid-row-start grid-row-end columns column-count column-width column-gap column-rule column-rule-color column-rule-style column-rule-width column-span column-fill color opacity accent-color caret-color color-scheme forced-color-adjust print-color-adjust background background-color background-image background-position background-position-x background-position-y background-size background-repeat background-origin background-clip background-attachment background-blend-mode mix-blend-mode isolation border border-width border-style border-color border-top border-top-width border-top-style border-top-color border-right border-right-width border-right-style border-right-color border-bottom border-bottom-width border-bottom-style border-bottom-color border-left border-left-width border-left-style border-left-color border-block border-block-width border-block-style border-block-color border-block-start border-block-start-width border-block-start-style border-block-start-color border-block-end border-block-end-width border-block-end-style border-block-end-color border-inline border-inline-width border-inline-style border-inline-color border-inline-start border-inline-start-width border-inline-start-style border-inline-start-color border-inline-end border-inline-end-width border-inline-end-style border-inline-end-color border-radius border-top-left-radius border-top-right-radius border-bottom-right-radius border-bottom-left-radius border-start-start-radius border-start-end-radius border-end-start-radius border-end-end-radius border-image border-image-source border-image-slice border-image-width border-image-outset border-image-repeat border-collapse border-spacing outline outline-width outline-style outline-color outline-offset box-shadow filter backdrop-filter clip-path mask mask-image mask-mode mask-repeat mask-position mask-clip mask-origin mask-size mask-composite mask-type opacity transform transform-origin transform-box transform-style perspective perspective-origin backface-visibility rotate scale translate transition transition-property transition-duration transition-timing-function transition-delay transition-behavior animation animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-fill-mode animation-play-state animation-composition animation-timeline will-change font font-family font-size font-size-adjust font-weight font-style font-variant font-variant-caps font-variant-numeric font-variant-ligatures font-variant-east-asian font-variant-alternates font-variant-position font-feature-settings font-variation-settings font-kerning font-stretch font-optical-sizing font-synthesis font-display line-height letter-spacing word-spacing text-align text-align-last text-decoration text-decoration-line text-decoration-color text-decoration-style text-decoration-thickness text-decoration-skip-ink text-underline-offset text-underline-position text-transform text-indent text-overflow text-shadow text-rendering text-wrap text-wrap-mode text-wrap-style text-emphasis text-emphasis-color text-emphasis-style text-emphasis-position text-orientation text-combine-upright text-justify white-space white-space-collapse word-break word-wrap overflow-wrap hyphens hyphenate-character line-break tab-size vertical-align writing-mode direction unicode-bidi quotes content list-style list-style-type list-style-position list-style-image counter-reset counter-increment counter-set cursor pointer-events user-select touch-action resize appearance caret scroll-behavior scroll-margin scroll-margin-top scroll-margin-right scroll-margin-bottom scroll-margin-left scroll-padding scroll-padding-top scroll-padding-right scroll-padding-bottom scroll-padding-left scroll-snap-type scroll-snap-align scroll-snap-stop overscroll-behavior overscroll-behavior-x overscroll-behavior-y scrollbar-width scrollbar-color scrollbar-gutter table-layout caption-side empty-cells vertical-align object-fit object-position image-rendering fill fill-opacity fill-rule stroke stroke-width stroke-opacity stroke-linecap stroke-linejoin stroke-dasharray stroke-dashoffset stroke-miterlimit paint-order shape-rendering stop-color flood-color lighting-color container container-type container-name contain content-visibility break-before break-after break-inside page-break-before page-break-after page-break-inside orphans widows all cx cy r rx ry d".split(" ")),zt=/^-(webkit|moz|ms|o)-/,Mt=e=>{if(e.startsWith("--"))return!0;const t=e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();return!!zt.test(t)||Pt.has(t)},qt=new Set(["breakpoint","query","state","variant","target","orientation"]),Lt=(e,t,r)=>{const n={};if(!e)return n;for(const[o,s]of Object.entries(e)){if(void 0===s||qt.has(o))continue;if(!Mt(o))throw new y("REFRACT_E_RECIPE_PROPERTY",`Unknown recipe property "${o}" in ${r} — expected a CSS property or a reserved key (variant, target, state, breakpoint, query, orientation, container, size).`);const e=It(s,t,r,o);void 0!==e&&(n[Bt(o)]=e)}return n},It=(e,t,r,n)=>{var o;if("number"==typeof e)return{value:e};const s=e.trim();if(!s)return;const i=s.split("."),a=i[0],l=t.properties[a];if(!l)return{value:s};const c=i.length>1?i.slice(1).join("."):void 0;if(!c)return{ref:`colors.${a}`};if("text"===c)return{ref:`colors.${a}.text`};if(!(null===(o=l.variants)||void 0===o?void 0:o[c]))throw new y("REFRACT_E_VARIANT_REF",`Unknown palette variant reference "${a}.${c}" in ${r}.${n}.`);return{ref:`colors.${a}.${c}`}},Bt=e=>e.startsWith("--")?e:e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ut=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),Dt=([e,t,r])=>.2126*Ut(e/255)+.7152*Ut(t/255)+.0722*Ut(r/255),Vt={fail:0,"AA-large":1,AA:2,AAA:3},Wt=2.4,Ht=.2126729,Gt=.7151522,Yt=.072175,Jt=.56,Kt=.57,Xt=.62,Zt=.65,Qt=.022,er=1.414,tr=1.14,rr=.027,nr=1.14,or=.027,sr=5e-4,ir=.1,ar=([e,t,r])=>Ht*Math.pow(e/255,Wt)+Gt*Math.pow(t/255,Wt)+Yt*Math.pow(r/255,Wt),lr=(e,t)=>{const r=e=>e>Qt?e:e+Math.pow(Qt-e,er),n=r(ar(e)),o=r(ar(t));if(Math.abs(o-n)<sr)return 0;let s;if(o>n){const e=(Math.pow(o,Jt)-Math.pow(n,Kt))*tr;s=e<ir?0:e-rr}else{const e=(Math.pow(o,Zt)-Math.pow(n,Xt))*nr;s=e>-ir?0:e+or}return 100*s},cr=(e,t)=>{const r=10**t;return Math.round(e*r)/r},ur=(e,t)=>{if(void 0!==t.ref)try{return String(e.resolveToken(t.ref))}catch{return}if("string"==typeof t.value)return t.value},dr="color",fr=["background-color","background"],pr=e=>{if(e)for(const t of fr)if(e[t])return e[t]},mr=(e,t,r,n,o)=>{let s,i;try{void 0!==r&&(s=Xe(r).rgb)}catch{}try{void 0!==n&&(i=Xe(n).rgb)}catch{}if(!s||!i)return{kind:e,label:t,fg:r,bg:n,skipped:s||i?s?"bg not a colour":"fg not a colour":"no derivable fg/bg"};const a=((e,t)=>{const r=Dt(e),n=Dt(t);return(Math.max(r,n)+.05)/(Math.min(r,n)+.05)})(s,i),l=((e,t)=>t?e>=4.5?"AAA":e>=3?"AA":"fail":e>=7?"AAA":e>=4.5?"AA":e>=3?"AA-large":"fail")(a,o.largeText),c=Vt[l]>=Vt[o.minWcag];return{kind:e,label:t,fg:r,bg:n,wcagRatio:cr(a,2),wcagLevel:l,apcaLc:cr(lr(s,i),1),pass:c}},hr=(e,t={})=>{var r,n,o,s,i,a,l,c,u,d,f;const p={largeText:null!==(r=t.largeText)&&void 0!==r&&r,minWcag:null!==(n=t.minWcag)&&void 0!==n?n:"AA"},m=null===(o=t.includeRecipes)||void 0===o||o,h=[];if(null===(s=t.includePalettes)||void 0===s||s)for(const t of Object.keys(e.tokens)){const r=/^colors\.([^.]+)\.text$/.exec(t);if(!r)continue;const n=`colors.${r[1]}`;let o,s;try{o=String(e.resolveToken(t))}catch{}try{s=String(e.resolveToken(n))}catch{}h.push(mr("palette",n,o,s,p))}if(m)for(const[t,r]of Object.entries(e.model.subsystems))if(r.ruleSets)for(const[n,o]of Object.entries(r.ruleSets))for(const[r,s]of Object.entries(o)){const o=s.declarations[dr],m=pr(s.declarations),g=`${t}.${n}.${r}`;o&&m&&h.push(mr("recipe",g,ur(e,o),ur(e,m),p));for(const t of null!==(i=s.overrides)&&void 0!==i?i:[]){const r=null!==(l=null===(a=t.declarations)||void 0===a?void 0:a[dr])&&void 0!==l?l:o,n=null!==(c=pr(t.declarations))&&void 0!==c?c:m;if(!t.declarations||!t.declarations[dr]&&!pr(t.declarations))continue;if(!r||!n)continue;const s=null!==(f=null!==(d=null!==(u=t.state)&&void 0!==u?u:t.breakpoint)&&void 0!==d?d:t.query)&&void 0!==f?f:"override";h.push(mr("recipe",`${g} (${s})`,ur(e,r),ur(e,n),p))}}const g=h.filter(e=>!e.skipped),b=g.filter(e=>!1===e.pass),v=g.reduce((e,t)=>{var r,n;return void 0===e||(null!==(r=t.wcagRatio)&&void 0!==r?r:1/0)<(null!==(n=e.wcagRatio)&&void 0!==n?n:1/0)?t:e},void 0),w={pairings:h,summary:{total:g.length,passed:g.length-b.length,failed:b.length,skipped:h.length-g.length,worst:v},ok:0===b.length};if(t.strict&&b.length>0){const e=b.map(e=>`${e.label} (${e.wcagRatio}:1, ${e.wcagLevel})`).join(", ");throw new y("REFRACT_E_AUDIT",`refract audit: ${b.length} pairing(s) fail WCAG ${p.minWcag} — ${e}. Adjust the colour(s), lower --min-wcag, or drop --strict to report without failing.`,b.map(e=>`${e.label} (${e.wcagRatio}:1, ${e.wcagLevel})`))}return w},gr=new Set(["recipes"]),br=e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&!("base"in e)&&Array.isArray(e.modifiers),vr=e=>{if("object"!=typeof e||null===e||Array.isArray(e)||!e.variants)return{value:e,specs:{}};const t=e.variants,r={},n={};for(const[e,o]of Object.entries(t))br(o)?r[e]=o:n[e]=o;if(!Object.keys(r).length)return{value:e,specs:r};const o=Object.keys(n).length?n:void 0;return{value:{...e,variants:o},specs:r}},yr={key:"colors",derivations:{lighten:(e,t)=>st(String(e),Number(t)),darken:(e,t)=>it(String(e),Number(t)),alpha:(e,t)=>dt(String(e),Number(t)),setL:(e,t)=>at(String(e),Number(t)),rotateHue:(e,t)=>lt(String(e),Number(t)),adjust:(e,t)=>ct(String(e),t)},normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(gr.has(n))continue;const{value:e,specs:s}=vr(o),i=le(e,{propertyPath:`colors.${n}`,allowedBreakpoints:t.allowedBreakpoints,coerceValue:bt}),a=xt(n,i,s);Q(a,{propertyPath:`colors.${n}`}),r[n]=a}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>{const n=`${r.groupPath}.${e}`;return{base:Lt(t.base,r,n),responsive:t.responsive.map(e=>{const{breakpoint:t,query:o,state:s,variant:i,target:a,orientation:l,container:c,size:u,...d}=e,f={declarations:{...i?{...r.resolveRecipeVariant(i).base}:{},...Lt(d,r,`${n}.responsive`)}};return t&&(f.breakpoint=t,f.query=null!=o?o:"exact"),c&&(f.container=c,u&&(f.size=u),f.query=null!=o?o:"min"),s&&(f.state=s),l&&(f.orientation=l),a&&(f.target=a),f})}})(e,t,r)},wr={"minor-second":1.067,"major-second":1.125,"minor-third":1.2,"major-third":1.25,"perfect-fourth":1.333,"augmented-fourth":1.414,"perfect-fifth":1.5,golden:1.618},$r={xs:-2,sm:-1,md:0,lg:1,xl:2,"2xl":3,"3xl":4,"4xl":5},kr=(e,t)=>"fontSize"!==e?t:xr(t),xr=e=>{var t,r,n,o;const s=e.ratio;if(!s)return e;const i=wr[s];if(!i)return e;const a=null!==(t=e.baseFontSize)&&void 0!==t?t:e.base,l=null!==(r=e.precision)&&void 0!==r?r:4,c=e.algorithm,u=null!==(n=e.variants)&&void 0!==n?n:{},d={};let f=null;for(const[e,t]of Object.entries($r)){if(u[e]){f=null!==(o=u[e].base)&&void 0!==o?o:null;continue}let r;r=c?c(a,e,t,f):a*Math.pow(i,t);const n=Number(r.toFixed(l));f=n,d[e]={base:n}}return{...e,variants:{...d,...u}}},jr=new Set(["breakpoint","query","state","variant","target","orientation"]),Ar={fontFamily:"font-family",fontSize:"font-size",fontWeight:"font-weight",lineHeight:"line-height",letterSpacing:"letter-spacing",fontStyle:"font-style",textTransform:"text-transform",textDecoration:"text-decoration",textAlign:"text-align"},Sr=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e)){if(!n||jr.has(r))continue;const e=Ar[r];e&&(t[e]={ref:Er(r,n)})}return t},Er=(e,t)=>"base"===t?`typography.${e}`:`typography.${e}.${t}`,Rr=new Set(["recipes"]),Cr={key:"typography",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(Rr.has(n))continue;const e=le(o,{propertyPath:`typography.${n}`,allowedBreakpoints:t.allowedBreakpoints}),s=kr(n,e);Q(s,{propertyPath:`typography.${n}`}),r[n]=s}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>({base:Sr(t.base),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:o,variant:s,target:i,orientation:a,container:l,size:c,...u}=e,d={declarations:{...s?{...r.resolveRecipeVariant(s).base}:{},...Sr(u)}};return t&&(d.breakpoint=t,d.query=null!=n?n:"exact"),l&&(d.container=l,c&&(d.size=c),d.query=null!=n?n:"min"),o&&(d.state=o),i&&(d.target=i),a&&(d.orientation=a),d})}))(0,t,r)},Or=["spacing","gutters","aspectRatio","sizes"],Tr=new Set(["spacing","gutters","sizes"]),Fr=new Set(["spacing","gutters"]),Nr=["xs","sm","md","lg","xl","2xl","3xl","4xl"],_r=e=>Number(e.toFixed(4)),Pr=(e,t)=>{var r;if(!Tr.has(e))return t;const n=((e,t)=>{const r=t,n=void 0!==r.ratio,o=void 0!==r.step;if(!n&&!o)return;if(n&&o)throw new y("REFRACT_E_LAYOUT",`layout.${e}: declare only one of "ratio" (geometric) or "step" (linear) scale, not both.`);const s=r.steps;if(n){let t;if(void 0===s)t=Nr;else{if(!Array.isArray(s))throw new y("REFRACT_E_LAYOUT",`layout.${e}: a geometric scale ("ratio") needs "steps" as an ordered name array, e.g. ["sm","md","lg"].`);t=s.map(String)}const n=t.map((e,t)=>({name:e,exp:t}));return{curve:"geometric",ratio:Number(r.ratio),specs:n}}let i;if(void 0===s)i=Nr.map((e,t)=>({name:e,exp:t,mult:t+1}));else{if(Array.isArray(s)||"object"!=typeof s||null===s)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a linear scale ("step") needs "steps" as a name→multiplier map, e.g. { sm:1, md:2, lg:3 }.`);i=Object.entries(s).map(([e,t],r)=>({name:e,exp:r,mult:Number(t)}))}return{curve:"linear",step:Number(r.step),specs:i}})(e,t);if(!n)return Fr.has(e)?zr(t):t;const o=((e,t,r)=>{const n=`layout.${e}`,o={};for(const e of r.specs)if("geometric"===r.curve){const s=_r(Number(t)*Math.pow(r.ratio,e.exp));o[e.name]={base:s,derive:{ref:n,fn:"scaleStep",arg:{curve:"geometric",ratio:r.ratio,exp:e.exp}}}}else{const t=_r(r.step*e.mult);o[e.name]={base:t,derive:{ref:n,fn:"scaleStep",arg:{curve:"linear",step:r.step,mult:e.mult}}}}return o})(e,t.base,n);let s={...o,...null!==(r=t.variants)&&void 0!==r?r:{}};Fr.has(e)&&(s={...s,none:{base:0}});const i=((e,t,r,n)=>{if(!(null==r?void 0:r.length))return r;const o=`layout.${e}`,s=[];let i=!1;for(const a of r){const r=a;if(void 0===r.ratio&&void 0===r.step){s.push(r);continue}if(i=!0,void 0!==r.ratio&&void 0!==r.step)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a responsive ramp entry may set only "ratio" or "step", not both.`);if(!n)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a responsive ramp entry needs a base scale — declare a top-level "ratio"/"step" (+ "steps") first.`);const{breakpoint:l,query:c,orientation:u}=r,d=void 0!==r.ratio;for(const i of n.specs){let n,a;if(d){const e=Number(r.ratio),o=void 0!==r.base,s=Number(o?r.base:t);n=_r(s*Math.pow(e,i.exp)),a={curve:"geometric",ratio:e,exp:i.exp,...o?{base:s}:{}}}else{if(void 0===i.mult)throw new y("REFRACT_E_LAYOUT",`layout.${e}: a linear responsive ramp ("step") requires a linear base scale (a name→multiplier "steps").`);const t=Number(r.step);n=_r(t*i.mult),a={curve:"linear",step:t,mult:i.mult}}const f={breakpoint:l,query:c,target:i.name,base:n,derive:{ref:o,fn:"scaleStep",arg:a}};void 0!==u&&(f.orientation=u),s.push(f)}}return i?s:r})(e,t.base,t.responsive,n);return(e=>{const{ratio:t,step:r,steps:n,...o}=e;return o})({...t,variants:s,responsive:i})},zr=e=>{var t;const r=null!==(t=e.variants)&&void 0!==t?t:{};return{...e,variants:{...r,none:{base:0}}}},Mr=new Set(["breakpoint","query","state","variant","target","orientation"]),qr={paddingY:["padding-top","padding-bottom"],paddingX:["padding-left","padding-right"],marginY:["margin-top","margin-bottom"],marginX:["margin-left","margin-right"],gap:["gap"],background:["background"],width:["width"],minWidth:["min-width"],maxWidth:["max-width"],height:["height"],minHeight:["min-height"],maxHeight:["max-height"]},Lr={paddingY:"spacing",paddingX:"spacing",marginY:"spacing",marginX:"spacing",gap:"spacing",width:"sizes",minWidth:"sizes",maxWidth:"sizes",height:"sizes",minHeight:"sizes",maxHeight:"sizes",background:"literal"},Ir=(e,t)=>"base"===t?`layout.${e}`:`layout.${e}.${t}`,Br=(e,t)=>{const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(Mr.has(n))continue;if(!o)continue;const e=qr[n];if(!e)throw new y("REFRACT_E_LAYOUT",`Unknown layout recipe property "${n}" in ${t}. Known verbs: ${Object.keys(qr).join(", ")}. For arbitrary CSS use a component \`css\` delta.`);const s=Lr[n];for(const t of e)r[t]="literal"===s?{value:o}:{ref:Ir(s,o)}}return r},Ur=e=>({ref:"base"===e?"layout.spacing":`layout.spacing.${e}`}),Dr=e=>({ref:"base"===e?"layout.gutters":`layout.gutters.${e}`}),Vr=e=>({ref:`layout.${e}`}),Wr=e=>({value:e}),Hr=e=>Object.keys(e).sort((t,r)=>e[t]-e[r]),Gr=[["templateColumns","grid-template-columns"],["templateRows","grid-template-rows"],["autoRows","grid-auto-rows"],["autoColumns","grid-auto-columns"],["justifyItems","justify-items"],["alignItems","align-items"],["justifyContent","justify-content"],["alignContent","align-content"]],Yr=(e,t)=>{const r={};t&&(r.display=Wr("grid"));for(const[t,n]of Gr){const o=e[t];o&&(r[n]=Wr(o))}return e.gap&&(r.gap=Ur(e.gap)),r},Jr=e=>{var t,r;if(!e||"string"==typeof e)return{mode:null!==(t=e)&&void 0!==t?t:"fixed"};const n=e;return{mode:null!==(r=n.base)&&void 0!==r?r:"fixed",inset:n.inset,gutter:n.gutter,direction:n.direction,align:n.align,justify:n.justify,maxWidth:n.maxWidth}},Kr=(e,t,r=new Set,n)=>{var o,s,i,a;const l=qe(n),c=e=>Le(e,l),u={},d={},f=Hr(t),p=e&&"object"==typeof e?e:void 0,m=p?{mode:null!==(o=p.base)&&void 0!==o?o:"fixed",inset:p.inset,gutter:p.gutter,direction:p.direction,align:p.align,justify:p.justify,maxWidth:p.maxWidth}:Jr(null!=e?e:"fixed"),h=null!==(s=null==p?void 0:p.variants)&&void 0!==s?s:{},g=null!==(i=null==p?void 0:p.responsive)&&void 0!==i?i:[],b=e=>e?`container-${e}`:"container",v=(e,n)=>{var o,s,i,a,l,p,h,g,v;const y=e?`--${e}`:"",w=`container${y}--inset`,$=`container${y}--gutter`,k=null!==(s=null!==(o=n.inset)&&void 0!==o?o:m.inset)&&void 0!==s?s:"base",x=null!==(i=n.gutter)&&void 0!==i?i:m.gutter,j=null!==(l=null!==(a=n.mode)&&void 0!==a?a:m.mode)&&void 0!==l?l:"fixed",A=null!==(p=n.direction)&&void 0!==p?p:m.direction,S=null!==(h=n.align)&&void 0!==h?h:m.align,E=null!==(g=n.justify)&&void 0!==g?g:m.justify,R=null!==(v=n.maxWidth)&&void 0!==v?v:e?m.maxWidth:void 0;u[w]={base:Ur(k)},x&&(u[$]={base:Dr(x)});const C={"box-sizing":Wr("border-box"),width:Wr("100%"),"margin-left":Wr("auto"),"margin-right":Wr("auto"),"padding-left":Vr(w),"padding-right":Vr(w)};x&&(C.gap=Vr($)),A&&(C.display=Wr("flex"),C["flex-direction"]=Wr(A)),S&&(C["align-items"]=Wr(S)),E&&(C["justify-content"]=Wr(E));const O=[];if("fixed"===j){const e="string"==typeof R&&void 0!==t[R]?R:void 0,r=e?f.indexOf(e):-1;for(let n=0;n<f.length;n++){const o=f[n],s=t[r>=0&&n>r?e:o];0!==s?0===n?C["max-width"]=Wr(c(s)):O.push({breakpoint:o,query:"min",declarations:{"max-width":Wr(c(s))}}):0===n&&(C["max-width"]=Wr("none"))}}else"fluid"===j?void 0!==R&&(C["max-width"]=((e,t,r)=>{return"number"==typeof e?Wr(`${e}px`):t.has(e)?{ref:"base"===(n=e)?"layout.sizes":`layout.sizes.${n}`}:void 0!==r[e]?Wr(`${r[e]}px`):Wr(e);var n})(R,r,t)):C["max-width"]=Wr("number"==typeof j?`${j}px`:j);d[b(e)]={kind:"recipe",declarations:C,overrides:O}};v(null,m);for(const[e,t]of Object.entries(h))v(e,Jr(t));for(const e of g){const t=e.target,r=b(null!=t?t:null),n=d[r];if(!n)continue;const o={};if(e.direction&&(o["flex-direction"]=Wr(e.direction)),e.align&&(o["align-items"]=Wr(e.align)),e.justify&&(o["justify-content"]=Wr(e.justify)),e.inset){const e=t?`container--${t}--inset`:"container--inset";o["padding-left"]=Vr(e),o["padding-right"]=Vr(e)}if(e.gutter){const e=t?`container--${t}--gutter`:"container--gutter";o.gap=Vr(e)}Object.keys(o).length&&n.overrides.push({breakpoint:e.breakpoint,query:null!==(a=e.query)&&void 0!==a?a:"exact",declarations:o})}return{ruleSetGroups:{container:d},configProperties:u}},Xr=(e,t,r)=>{const n={},o={},s=e=>{e&&(Object.assign(n,e.ruleSetGroups),Object.assign(o,e.configProperties))};return s(((e,t)=>{var r,n;if(!e)return;const o="number"==typeof e?{size:e}:e,s=o.size,i=null!==(r=o.gutter)&&void 0!==r?r:"base",a=null!==(n=o.inset)&&void 0!==n?n:"none",l={"columns--size":{base:Wr(String(s))},"columns--gutter":{base:Dr(i)},"columns--inset":{base:Ur(a)}},c={},u=Array.from({length:s},(e,t)=>t+1);for(const e of Hr(t))for(const r of u){const n=`col-${e}-${r}`,o=`offset-${e}-${r}`,s={"grid-column-end":Wr(`span ${r}`)},i={"grid-column-start":Wr(String(r+1))};0===t[e]?(c[n]={kind:"utility",declarations:s,overrides:[]},c[o]={kind:"utility",declarations:i,overrides:[]}):(c[n]={kind:"utility",declarations:{},overrides:[{breakpoint:e,query:"min",declarations:s}]},c[o]={kind:"utility",declarations:{},overrides:[{breakpoint:e,query:"min",declarations:i}]})}return{ruleSetGroups:{columns:c},configProperties:l}})(e.columns,t)),s((e=>{var t,r;if(!e||!Object.keys(e).length)return;const n={};for(const[o,s]of Object.entries(e)){const e=Yr(s,!0),i=[];for(const e of null!==(t=s.responsive)&&void 0!==t?t:[]){const t=Yr(e,!1);Object.keys(t).length&&i.push({breakpoint:e.breakpoint,query:null!==(r=e.query)&&void 0!==r?r:"exact",declarations:t})}n[`grid-${o}`]={kind:"recipe",declarations:e,overrides:i}}return{ruleSetGroups:{grids:n},configProperties:{}}})(e.grids)),s((e=>{var t,r,n;if(!e||!Object.keys(e).length)return;const o={};for(const[s,i]of Object.entries(e)){const e={display:Wr(i.inline?"inline-flex":"flex"),"flex-direction":Wr(null!==(t=i.direction)&&void 0!==t?t:"column")};i.align&&(e["align-items"]=Wr(i.align)),i.justify&&(e["justify-content"]=Wr(i.justify)),i.wrap&&(e["flex-wrap"]=Wr(i.wrap)),i.gap&&(e.gap=Ur(i.gap));const a=[];for(const e of null!==(r=i.responsive)&&void 0!==r?r:[]){const t={};void 0!==e.inline&&(t.display=Wr(e.inline?"inline-flex":"flex")),e.direction&&(t["flex-direction"]=Wr(e.direction)),e.align&&(t["align-items"]=Wr(e.align)),e.justify&&(t["justify-content"]=Wr(e.justify)),e.wrap&&(t["flex-wrap"]=Wr(e.wrap)),Object.keys(t).length&&a.push({breakpoint:e.breakpoint,query:null!==(n=e.query)&&void 0!==n?n:"exact",declarations:t})}o[`stack-${s}`]={kind:"recipe",declarations:e,overrides:a}}return{ruleSetGroups:{stacks:o},configProperties:{}}})(e.stacks)),s(Kr(e.container,t,(e=>{const t=new Set;if(e&&"object"==typeof e&&!Array.isArray(e)){const r=e;"base"in r&&t.add("base");const n=r.variants;if(n&&"object"==typeof n)for(const e of Object.keys(n))t.add(e)}return t})(e.sizes),r)),{ruleSetGroups:n,configProperties:o}},Zr=new Set(Or),Qr={key:"layout",derivations:{scaleStep:(e,t)=>((e,t)=>{const r=null!=t?t:{};if("linear"===r.curve)return _r(Number(r.step)*Number(r.mult));const n=void 0!==r.base?Number(r.base):Number(e);return _r(n*Math.pow(Number(r.ratio),Number(r.exp)))})(e,t)},normalizeProperties(e,t){const r={};if(!e)return r;for(const n of Or){const o=e[n];if(void 0===o||!Zr.has(n))continue;const s=le(o,{propertyPath:`layout.${n}`,allowedBreakpoints:t.allowedBreakpoints}),i=Pr(n,s);Q(i,{propertyPath:`layout.${n}`}),r[n]=i}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>{var n;const o=`${null!==(n=r.groupPath)&&void 0!==n?n:"layout.recipes"}.${e}`;return{base:Br(t.base,o),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:s,variant:i,target:a,orientation:l,container:c,size:u,...d}=e,f={declarations:{...i?{...r.resolveRecipeVariant(i).base}:{},...Br(d,o)}};return t&&(f.breakpoint=t,f.query=null!=n?n:"exact"),c&&(f.container=c,u&&(f.size=u),f.query=null!=n?n:"min"),s&&(f.state=s),a&&(f.target=a),l&&(f.orientation=l),f})}})(e,t,r),buildStructural:(e,t)=>Xr(e,t.breakpoints,t.mediaConfig)},en=new Set(["breakpoint","query","state","variant","target","orientation"]),tn={boxShadow:"box-shadow",opacity:"opacity",blur:"filter",transition:"transition",zIndex:"z-index"},rn={boxShadow:"shadow",opacity:"opacity",blur:"blur",transition:"transitions",zIndex:"zIndex"},nn=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e)){if(!n||en.has(r))continue;const e=tn[r],o=rn[r];if(!e||!o)continue;const s={ref:on(o,n)};"blur"===r&&(s.wrap="blur"),t[e]=s}return t},on=(e,t)=>"base"===t?`effects.${e}`:`effects.${e}.${t}`,sn=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),an=(e,t)=>{if(void 0!==e){if("number"!=typeof e||Number.isNaN(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a number, received ${JSON.stringify(e)}.`);return e}},ln=(e,t)=>{if(void 0!==e){if("number"==typeof e){if(Number.isNaN(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a number or length string, received ${JSON.stringify(e)}.`);return e}if("string"==typeof e){const r=I(e);if("raw"in r)throw new y("REFRACT_E_EFFECTS",`${t} must be a number or a <number><unit> length (received ${JSON.stringify(e)}).`);return void 0===r.unit?r.value:{value:r.value,unit:r.unit}}throw new y("REFRACT_E_EFFECTS",`${t} must be a number or length string, received ${JSON.stringify(e)}.`)}},cn=new Set(["offsetX","offsetY","blur","spread","color","inset"]),un=(e,t)=>{if(!sn(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a shadow-layer object, received ${JSON.stringify(e)}.`);for(const r of Object.keys(e))if(!cn.has(r))throw new y("REFRACT_E_EFFECTS",`${t} has unknown shadow field "${r}" (allowed: ${[...cn].join(", ")}).`);const r={},n=ln(e.offsetX,`${t}.offsetX`),o=ln(e.offsetY,`${t}.offsetY`),s=ln(e.blur,`${t}.blur`),i=ln(e.spread,`${t}.spread`);if(void 0!==n&&(r.offsetX=n),void 0!==o&&(r.offsetY=o),void 0!==s&&(r.blur=s),void 0!==i&&(r.spread=i),void 0!==e.color){if("string"!=typeof e.color||!e.color)throw new y("REFRACT_E_EFFECTS",`${t}.color must be a "colors.*" token-path string.`);r.color=e.color}if(void 0!==e.inset){if("boolean"!=typeof e.inset)throw new y("REFRACT_E_EFFECTS",`${t}.inset must be a boolean.`);e.inset&&(r.inset=!0)}return r},dn=new Set(["property","duration","timingFunction","delay"]),fn=(e,t)=>{if(!sn(e))throw new y("REFRACT_E_EFFECTS",`${t} must be a transition-part object, received ${JSON.stringify(e)}.`);for(const r of Object.keys(e))if(!dn.has(r))throw new y("REFRACT_E_EFFECTS",`${t} has unknown transition field "${r}" (allowed: ${[...dn].join(", ")}).`);if("string"!=typeof e.property||!e.property)throw new y("REFRACT_E_EFFECTS",`${t}.property is required (the CSS property to transition).`);const r={property:e.property},n=an(e.duration,`${t}.duration`),o=an(e.delay,`${t}.delay`);if(void 0!==n&&(r.duration=n),void 0!==e.timingFunction){if("string"!=typeof e.timingFunction||!e.timingFunction)throw new y("REFRACT_E_EFFECTS",`${t}.timingFunction must be a keyword or cubic-bezier(...) string.`);r.timingFunction=e.timingFunction}return void 0!==o&&(r.delay=o),r},pn=new Set(["recipes"]),mn={shadow:["offsetX","offsetY","blur","spread","color","inset"],transitions:["property","duration","timingFunction","delay"]},hn=e=>"shadow"===e?t=>((e,t="effects.shadow")=>{if("string"==typeof e){if("none"===e)return"none";throw new y("REFRACT_E_EFFECTS",`${t} must be structured shadow layer(s) or "none" — raw CSS strings are not accepted (received ${JSON.stringify(e)}).`)}if(Array.isArray(e)){if(!e.length)throw new y("REFRACT_E_EFFECTS",`${t} is an empty shadow-layer array.`);return e.map((e,r)=>un(e,`${t}[${r}]`))}return[un(e,t)]})(t,`effects.${e}`):"transitions"===e?t=>((e,t="effects.transitions")=>{if("string"==typeof e){if("none"===e)return"none";throw new y("REFRACT_E_EFFECTS",`${t} must be structured transition part(s) or "none" — raw CSS strings are not accepted (received ${JSON.stringify(e)}).`)}if(Array.isArray(e)){if(!e.length)throw new y("REFRACT_E_EFFECTS",`${t} is an empty transition-part array.`);return e.map((e,r)=>fn(e,`${t}[${r}]`))}return[fn(e,t)]})(t,`effects.${e}`):void 0,gn={key:"effects",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(pn.has(n))continue;const e=mn[n],s=hn(n),i=le(o,{propertyPath:`effects.${n}`,allowedBreakpoints:t.allowedBreakpoints,...e?{leafFields:e}:{},...s?{coerceValue:s}:{},...e?{fallbackBase:"none"}:{}});Q(i,{propertyPath:`effects.${n}`}),r[n]=i}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>({base:nn(t.base),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:o,variant:s,target:i,orientation:a,container:l,size:c,...u}=e,d={declarations:{...s?{...r.resolveRecipeVariant(s).base}:{},...nn(u)}};return t&&(d.breakpoint=t,d.query=null!=n?n:"exact"),l&&(d.container=l,c&&(d.size=c),d.query=null!=n?n:"min"),o&&(d.state=o),i&&(d.target=i),a&&(d.orientation=a),d})}))(0,t,r)},bn=new Set(["breakpoint","query","state","variant","target","orientation","container","size"]),vn=new Set(["as","side"]),yn=new Set(["width","style","offset","radius","color"]),wn=(e,t,r)=>"radius"===r?"border-radius":"offset"===r?"outline-offset":"outline"===e?`outline-${r}`:t?`border-${t}-${r}`:`border-${r}`,$n=(e,t)=>"color"===e?{ref:t}:{ref:"base"===t?`borders.${e}`:`borders.${e}.${t}`},kn=(e,t,r)=>{const n={};if(!e)return n;for(const[o,s]of Object.entries(e))s&&!bn.has(o)&&!vn.has(o)&&yn.has(o)&&(n[wn(t,r,o)]=$n(o,s));return n},xn=new Set(["recipes"]),jn={key:"borders",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(xn.has(n))continue;const e=le(o,{propertyPath:`borders.${n}`,allowedBreakpoints:t.allowedBreakpoints});Q(e,{propertyPath:`borders.${n}`}),r[n]=e}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>{var n;const o=null!==(n=t.base.as)&&void 0!==n?n:"border",s=t.base.side,i=kn(t.base,o,s),a=t.responsive.map(e=>{var t,n;const{breakpoint:i,query:a,state:l,variant:c,target:u,orientation:d,container:f,size:p,as:m,side:h,...g}=e,b=null!==(t=m)&&void 0!==t?t:o,v=null!==(n=h)&&void 0!==n?n:s,y={declarations:{...c?{...r.resolveRecipeVariant(c).base}:{},...kn(g,b,v)}};return i&&(y.breakpoint=i,y.query=null!=a?a:"exact"),f&&(y.container=f,p&&(y.size=p),y.query=null!=a?a:"min"),l&&(y.state=l),d&&(y.orientation=d),u&&(y.target=u),y});return{base:i,responsive:a}})(0,t,r)},An=new Set(["breakpoint","query","state","variant","target","orientation"]),Sn={keyframes:"animation-name",duration:"animation-duration",easing:"animation-timing-function",delay:"animation-delay",iterationCount:"animation-iteration-count",direction:"animation-direction",fillMode:"animation-fill-mode",playState:"animation-play-state"},En={duration:"duration",easing:"easing",delay:"delay"},Rn=(e,t)=>"base"===t?`animation.${e}`:`animation.${e}.${t}`,Cn=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e)){if(void 0===n||""===n||An.has(r))continue;const e=Sn[r];e&&(t[e]="keyframes"===r?{ref:`animation.keyframes.${n}`}:En[r]?{ref:Rn(En[r],String(n))}:{value:n})}return t},On=new Set(["keyframes","recipes"]),Tn=e=>e&&"object"==typeof e&&"ref"in e?{ref:String(e.ref)}:"string"==typeof e||"number"==typeof e?{value:e}:void 0,Fn=e=>{const t={};for(const[r,n]of Object.entries(e)){const e=Tn(n);e&&(t[r]=e)}return t},Nn=e=>{const t=[];for(const[r,n]of Object.entries(e))t.push({stop:r,declarations:Fn(n)});return{steps:t}},_n=e=>{if(!e||"object"!=typeof e)return{};const t={};for(const[r,n]of Object.entries(e))n&&"object"==typeof n&&(t[r]=Nn(n));return t},Pn={key:"animation",normalizeProperties(e,t){const r={};if(!e)return r;for(const[n,o]of Object.entries(e)){if(On.has(n))continue;const e=le(o,{propertyPath:`animation.${n}`,allowedBreakpoints:t.allowedBreakpoints});Q(e,{propertyPath:`animation.${n}`}),r[n]=e}return r},interpretRecipe:(e,t,r)=>((e,t,r)=>({base:Cn(t.base),responsive:t.responsive.map(e=>{const{breakpoint:t,query:n,state:o,variant:s,target:i,orientation:a,container:l,size:c,...u}=e,d={declarations:{...s?{...r.resolveRecipeVariant(s).base}:{},...Cn(u)}};return t&&(d.breakpoint=t,d.query=null!=n?n:"exact"),l&&(d.container=l,c&&(d.size=c),d.query=null!=n?n:"min"),o&&(d.state=o),i&&(d.target=i),a&&(d.orientation=a),d})}))(0,t,r),buildStructural:e=>({ruleSetGroups:{},configProperties:{},keyframes:_n(e.keyframes)})},zn=e=>{const t={};if(!e)return t;for(const[r,n]of Object.entries(e))t[qn(r)]=Mn(n);return t},Mn=e=>"object"==typeof e?{ref:e.ref}:{value:e},qn=e=>e.startsWith("--")?e:e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ln={key:"components",normalizeProperties:()=>({}),interpretRecipe:(e,t,r)=>((e,t)=>({base:zn(t.base.css),responsive:t.responsive.map(e=>{var t,r;const n=e,o={declarations:zn(n.css)};return n.breakpoint&&(o.breakpoint=n.breakpoint,o.query=null!==(t=n.query)&&void 0!==t?t:"exact"),n.container&&(o.container=n.container,n.size&&(o.size=n.size),o.query=null!==(r=n.query)&&void 0!==r?r:"min"),n.state&&(o.state=n.state),n.orientation&&(o.orientation=n.orientation),n.target&&(o.target=n.target),o})}))(0,t),extractReferences:e=>(e=>{const t=[];for(const[r,n]of Object.entries(e))N.has(r)&&"string"==typeof n&&n.includes(".")&&t.push(`${r}:${n}`);return t})(e)},In=e=>({value:e}),Bn=e=>({ref:e}),Un=(e,t)=>({kind:"reset",selector:e,declarations:t,overrides:[]}),Dn=e=>{const t={};for(const[r,n,o]of e){const e={};for(const[t,r]of Object.entries(o))e[t]=In(r);t[r]=Un(n,e)}return t},Vn=[["h1","4xl"],["h2","3xl"],["h3","2xl"],["h4","xl"],["h5","lg"],["h6","md"]],Wn={preflight:{static:[["box","*,::before,::after",{"box-sizing":"border-box","border-width":"0","border-style":"solid"}],["body","body",{margin:"0","line-height":"inherit"}],["headings","h1,h2,h3,h4,h5,h6",{"font-size":"inherit","font-weight":"inherit",margin:"0"}],["blocks","p,figure,blockquote,dl,dd",{margin:"0"}],["lists","ul,ol",{"list-style":"none",margin:"0",padding:"0"}],["media","img,picture,video,canvas,svg",{display:"block","max-width":"100%"}],["forms","button,input,select,textarea",{font:"inherit",color:"inherit"}],["anchors","a",{color:"inherit","text-decoration":"inherit"}]],headings:!0},normalize:{static:[["box","*,::before,::after",{"box-sizing":"border-box"}],["body","body",{margin:"0"}],["media","img,picture,video,canvas,svg",{"max-width":"100%"}]],headings:!1},reset:{static:[["box","*,::before,::after",{"box-sizing":"border-box"}],["all","*",{margin:"0",padding:"0",border:"0",font:"inherit","vertical-align":"baseline"}],["headings","h1,h2,h3,h4,h5,h6",{"font-size":"inherit","font-weight":"inherit"}],["lists","ul,ol",{"list-style":"none"}],["media","img,picture,video,canvas,svg",{display:"block","max-width":"100%"}]],headings:!0}},Hn=Object.keys(Wn),Gn=e=>{if(!1===e)return{};const t=Wn[e];if(!t)throw new y("REFRACT_E_PRESET",`globals: unknown preset "${e}" — expected one of ${Hn.join(", ")} or false`);const r={static:Dn(t.static)};return t.headings&&(r.defaults=(()=>{const e={};for(const[t,r]of Vn)e[t]=Un(t,{"font-size":Bn(`typography.fontSize.${r}`)});return e})()),r},Yn=new Set(["state","breakpoint","query","orientation","container","size","variant","target"]),Jn=e=>null!==e&&"object"==typeof e?{ref:e.ref}:{value:e},Kn=e=>e.startsWith("--")?e:e.replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Xn=e=>{const t={};for(const[r,n]of Object.entries(e))null==n||Yn.has(r)||(t[Kn(r)]=Jn(n));return t},Zn=e=>{const t={declarations:Xn(e)},r=e;for(const e of Yn)void 0!==r[e]&&(t[e]=r[e]);return t},Qn=(e,t,r)=>(e=>({declarations:Xn(e.base),overrides:e.responsive.map(Zn)}))(we({[e]:t},r)[e]),eo=(e,t)=>{const r=null!=e?e:{},n={};if(void 0!==r.preset){const e=Gn(r.preset);e.static&&(n.static=e.static),e.defaults&&(n.defaults=e.defaults)}const o=((e,t)=>{if(!e||!Object.keys(e).length)return;const r=Object.keys(t.breakpoints),n={};for(const[o,s]of Object.entries(e)){if(!s||"object"!=typeof s)continue;const e={propertyPath:`globals.elements.${o}`,allowedBreakpoints:r,allowedStates:t.allowedStates,allowedContainers:t.allowedContainers},{variants:i,...a}=s,l=Qn(o,a,e),c={kind:"globals",selector:o,declarations:l.declarations,overrides:l.overrides};if(i&&"object"==typeof i&&Object.keys(i).length){const t={};for(const[r,n]of Object.entries(i))n&&"object"==typeof n&&(t[r]=Qn(r,n,{...e,propertyPath:`${e.propertyPath}.variants.${r}`}));Object.keys(t).length&&(c.variants=t)}n[o]=c}return Object.keys(n).length?n:void 0})(r.elements,t);return o&&(n.elements=o),n},to=[yr,Cr,Qr,gn,jn,Pn,Ln,{key:"globals",normalizeProperties:()=>({}),buildStructural:(e,t)=>({ruleSetGroups:eo(e,t),configProperties:{}})}];const ro=(e,t)=>_e(e,e=>Ie(e,qe(t))),no=e=>{var t;if(!e||"object"!=typeof e)return;const r={};for(const[n,o]of Object.entries(e))o&&"object"==typeof o&&o.sizes&&Object.keys(o.sizes).length&&(r[n]={type:null!==(t=o.type)&&void 0!==t?t:"inline-size",sizes:{...o.sizes}});return Object.keys(r).length?r:void 0},oo=e=>{if(!e)return;const t=new Map;for(const[r,n]of Object.entries(e))t.set(r,new Set(Object.keys(n.sizes)));return t},so=(e,t)=>{if(e.startsWith("--"))return e;const r=e.split(".").join("-").toLowerCase();return t?`--${t}-${r}`:`--${r}`};function io(e,t,r){const{clean:n,externals:o}=((e,t)=>{if(!e)return{clean:e,externals:{}};const r={},n={};for(const[o,s]of Object.entries(e))if(null===s||"object"!=typeof s||Array.isArray(s)||"string"!=typeof s.external)r[o]=s;else{const e=so(s.external,t);n[o]={base:`var(${e})`,external:e,responsive:[]}}return{clean:r,externals:n}})(t,r.extendsPrefix),s=e.normalizeProperties(n,{allowedBreakpoints:r.allowedBreakpoints});Object.assign(s,o);const i=r.inheritedProperties?{...r.inheritedProperties,...s}:s,a=function(e,t,r){var n,o;if(!e.interpretRecipe||!t||!Object.keys(t).length)return{};const s={};for(const[i,a]of Object.entries(t)){const t=`${e.key}.recipes.${i}`,l=we(a,{propertyPath:t,allowedBreakpoints:r.allowedBreakpoints,allowedStates:r.allowedStates,allowedContainers:r.allowedContainers}),c=Ae(l,(n,o,s)=>e.interpretRecipe(n,o,{breakpoints:r.breakpoints,media:r.media,properties:r.properties,resolveRecipeVariant:s,groupPath:t}),{groupPath:t}).resolveAll(),u={};for(const[t,r]of Object.entries(c))if(e.extractReferences){const s=e.extractReferences(null!==(o=null===(n=l[t])||void 0===n?void 0:n.base)&&void 0!==o?o:{});u[t]=F(r,s)}else u[t]=T(r);s[i]=u}return s}(e,null==t?void 0:t.recipes,{breakpoints:r.breakpoints,media:r.media,properties:i,allowedBreakpoints:r.allowedBreakpoints,allowedStates:r.allowedStates,allowedContainers:r.allowedContainers});let l,c,u=a;if(e.buildStructural&&t){const n=e.buildStructural(t,{breakpoints:r.breakpoints,media:r.media,mediaConfig:r.mediaConfig,allowedStates:r.allowedStates,allowedContainers:r.allowedContainers});u={...n.ruleSetGroups,...a},Object.keys(n.configProperties).length&&(l=n.configProperties),n.keyframes&&Object.keys(n.keyframes).length&&(c=n.keyframes)}const d={};return Object.keys(s).length&&(d.properties=s),Object.keys(u).length&&(d.ruleSetGroups=u),l&&(d.extraProperties=l),c&&(d.keyframes=c),d}function ao(e){const t={};if(!(null==e?void 0:e.properties))return t;for(const[r,n]of Object.entries(e.properties)){const e={base:n.base.value};if(n.variants&&Object.keys(n.variants).length){const t={};for(const[e,r]of Object.entries(n.variants)){const n={base:r.base.value};if(r.extras)for(const[e,t]of Object.entries(r.extras))n[e]=t.value;t[e]=n}e.variants=t}if(n.extras)for(const[t,r]of Object.entries(n.extras))e[t]=r.value;t[r]=e}return t}function lo(e,t){var r,n,o,s,i;if(!e)return t;const a={...e};if(t.properties&&(a.properties={...null!==(r=e.properties)&&void 0!==r?r:{},...t.properties}),t.ruleSets){const r={...null!==(n=e.ruleSets)&&void 0!==n?n:{}};for(const[n,i]of Object.entries(t.ruleSets))r[n]={...null!==(s=null===(o=e.ruleSets)||void 0===o?void 0:o[n])&&void 0!==s?s:{},...i};a.ruleSets=r}return t.keyframes&&(a.keyframes={...null!==(i=e.keyframes)&&void 0!==i?i:{},...t.keyframes}),a}function co(e,t){var r,n,o,s;const{adapter:i}=t,a=e,l=null!==(r=a.breakpoints)&&void 0!==r?r:Ue,c=Object.keys(l),u=null!==(o=null===(n=a.extends)||void 0===n?void 0:n.prefix)&&void 0!==o?o:"dt",d=i.allowedStates,f=new Set(null!==(s=a.modes)&&void 0!==s?s:["dark","light"]),p=t.media,m=ro(l,p),h=no(a.containers),g=oo(h),b={};for(const e of to){const t=io(e,a[e.key],{breakpoints:l,extendsPrefix:u,media:m,mediaConfig:p,allowedBreakpoints:c,allowedStates:d,allowedContainers:g});Object.keys(t).length&&(b[e.key]=t)}const v=(e=>{var t;const r={},n=P(e.colors);n&&(r.colors=n);const o=P(e.typography);o&&(r.typography=o);const s=P(e.layout);s&&(r.layout=s);const i=P(e.effects);i&&(r.effects=i);const a=P(e.borders);a&&(r.borders=a);const l=P(e.animation);l&&(r.animation=l),_(null===(t=e.components)||void 0===t?void 0:t.ruleSetGroups)&&(r.components={ruleSets:e.components.ruleSetGroups});const c=P(e.globals);c&&(r.globals=c);const u={breakpoints:e.breakpoints,subsystems:r};return e.containers&&Object.keys(e.containers).length&&(u.containers=e.containers),u})({breakpoints:l,containers:h,...b}),w={units:t.units,baseFontSize:t.baseFontSize},$=function(e,t){var r;const{propertiesOverlay:n,ruleSetsOverlay:o,keyframesOverlay:s,containersOverlay:i}=t;if(!(n||o||s||i))return e;const a={...e.subsystems},l=new Set([...Object.keys(null!=n?n:{}),...Object.keys(null!=o?o:{}),...Object.keys(null!=s?s:{})]);for(const e of l)a[e]=lo(a[e],{properties:null==n?void 0:n[e],ruleSets:null==o?void 0:o[e],keyframes:null==s?void 0:s[e]});const c={...e,subsystems:a};return i&&(c.containers={...null!==(r=e.containers)&&void 0!==r?r:{},...i}),c}(K(v,w),t),k=(e=>{const t={};for(const r of e)for(const[e,n]of Object.entries(r)){if(e in t)throw new y("REFRACT_E_TOKEN_PATH",`Duplicate derivation fn "${e}" registered by two subsystems.`);t[e]=n}return t})(to.flatMap(e=>e.derivations?[e.derivations]:[])),x=Te($,k),j=[...fo(x),...po(x),...mo(x),...uo(x,f)];if(j.length>0){const e=j.map(e=>` - ${e}`).join("\n");throw new y("REFRACT_E_VALIDATION",`refract: ${j.length} validation error(s):\n${e}`,j)}return ho(x,{adapter:i,derivationRegistry:k,allowedStates:d,mediaConfig:p,unitConfig:w})}function uo(e,t){var r,n,o;const s=[],i=(e,r,n,o)=>{t.has(n)||s.push(`${e}.${r}${o}: unknown appearance mode '${n}' — declare it in the top-level 'modes' registry (known: ${[...t].join(", ")})`)};for(const[t,s]of Object.entries(e.subsystems))for(const[e,a]of Object.entries(null!==(r=s.properties)&&void 0!==r?r:{})){for(const r of null!==(n=a.modes)&&void 0!==n?n:[])r.mode&&i(t,e,r.mode,"");for(const r of null!==(o=a.responsive)&&void 0!==o?o:[])r.mode&&i(t,e,r.mode," (responsive)")}return s}function fo(e){var t,r,n,o,s;const i=null===(t=e.subsystems.components)||void 0===t?void 0:t.ruleSets;if(!i)return[];const a=[];for(const[t,l]of Object.entries(i))for(const[i,c]of Object.entries(l))for(const l of null!==(r=c.references)&&void 0!==r?r:[]){const[r,c=""]=l.split(":"),u=c.indexOf("."),d=u>=0?c.slice(0,u):c,f=u>=0?c.slice(u+1):"";(null===(s=null===(o=null===(n=e.subsystems[r])||void 0===n?void 0:n.ruleSets)||void 0===o?void 0:o[d])||void 0===s?void 0:s[f])||a.push(`components.${t}.${i}: Recipe variant "${f}" is not defined in "${r}:${d}". Check the subsystem:group.variant reference against what the subsystem declares.`)}return a}function po(e){var t,r;const n=null===(t=e.subsystems.components)||void 0===t?void 0:t.ruleSets;if(!n)return[];const o=z(e),s=[],i=(e,t,r,n)=>{for(const[i,a]of Object.entries(null!=e?e:{}))void 0===a.ref||a.ref in o||s.push(`components.${t}.${r}: css '${i}'${n} references unknown token '${a.ref}' — check the token path, or use a bare string / number for a raw CSS value`)};for(const[e,t]of Object.entries(n))for(const[n,o]of Object.entries(t)){i(o.declarations,e,n,"");for(const t of null!==(r=o.overrides)&&void 0!==r?r:[])i(t.declarations,e,n," (override)")}return s}function mo(e){var t,r,n,o,s;const i=null===(t=e.subsystems.globals)||void 0===t?void 0:t.ruleSets;if(!i)return[];const a=z(e),l=[],c=(e,t,r)=>{for(const[n,o]of Object.entries(null!=e?e:{}))void 0===o.ref||o.ref in a||l.push(`globals element '${t}'${r}: '${n}' references unknown token '${o.ref}' — check the token path, or use a bare string / number for a raw CSS value`)};for(const e of Object.values(i))for(const t of Object.values(e)){if("globals"!==t.kind)continue;const e=null!==(r=t.selector)&&void 0!==r?r:"";c(t.declarations,e,"");for(const r of null!==(n=t.overrides)&&void 0!==n?n:[])c(r.declarations,e," (override)");for(const[r,n]of Object.entries(null!==(o=t.variants)&&void 0!==o?o:{})){const t=` (variant '${r}')`;c(n.declarations,e,t);for(const r of null!==(s=n.overrides)&&void 0!==s?s:[])c(r.declarations,e,`${t} (override)`)}}return l}function ho(e,t){var r;const n=ro(e.breakpoints,t.mediaConfig),o=De(e.containers,t.mediaConfig),s=new WeakMap,i=()=>{let t=s.get(e);return t||(t=z(e),s.set(e,t)),t},a=e=>Se(i(),t.derivationRegistry,e),l={media:n,containers:o,resolve:a},c=t.adapter.bind(e,l),u={model:e,get tokens(){return i()},resolveToken:a,override:r=>function(e,t,r){var n,o,s;const i=t.breakpoints,a=i?{...e.breakpoints,...i}:e.breakpoints,l=Object.keys(a),c=ro(a,r.mediaConfig),u=no(t.containers),d=u?{...null!==(n=e.containers)&&void 0!==n?n:{},...u}:e.containers,f=oo(d),p={...e.subsystems};for(const n of to){const i=t[n.key];if(void 0===i)continue;const u=ao(e.subsystems[n.key]),d=io(n,i,{breakpoints:a,extendsPrefix:null!==(s=null===(o=t.extends)||void 0===o?void 0:o.prefix)&&void 0!==s?s:"dt",media:c,mediaConfig:r.mediaConfig,allowedBreakpoints:l,allowedStates:r.allowedStates,allowedContainers:f,inheritedProperties:u}),m=P(d);m&&(p[n.key]=lo(e.subsystems[n.key],m))}const m={breakpoints:a,subsystems:p};d&&Object.keys(d).length&&(m.containers=d);const h=K(m,r.unitConfig),g=Te(h,r.derivationRegistry);return ho(g,r)}(e,r,t)},d=null===(r=c.extend)||void 0===r?void 0:r.call(c,u);return d&&Object.defineProperties(u,Object.getOwnPropertyDescriptors(d)),u}const go="theme.css",bo="styles.css",vo="variables.css",yo=(e,t)=>"variables"===t?`${e}.variables.css`:`${e}.css`,wo=e=>`${e.group}-${e.variant}.css`,$o="variables.css";function ko(e){var t,r,n,o,s,i,a,l;if(void 0===e)return{type:"single",file:go};if("string"==typeof e)switch(e){case"single":return{type:"single",file:go};case"split":return{type:"split",file:bo,variables:vo};case"subsystem":return{type:"subsystem",filename:yo};case"components":return{type:"components",inline:!0,filename:wo,variables:$o}}switch(null!==(t=e.type)&&void 0!==t?t:"variables"in e?"split":"single"){case"single":return{type:"single",file:null!==(r=e.file)&&void 0!==r?r:go};case"split":{const t=e;return{type:"split",file:null!==(n=t.file)&&void 0!==n?n:bo,variables:null!==(o=t.variables)&&void 0!==o?o:vo}}case"subsystem":return{type:"subsystem",filename:null!==(s=e.filename)&&void 0!==s?s:yo};case"components":{const t=e;return{type:"components",inline:null===(i=t.inline)||void 0===i||i,filename:null!==(a=t.filename)&&void 0!==a?a:wo,variables:null!==(l=t.variables)&&void 0!==l?l:$o}}}throw new Error("resolveEmitPlan: unrecognized emit directive.")}const xo="com.theme-registry.refract",jo=e=>"object"==typeof e&&null!==e&&"$value"in e,Ao=/^\{([^}]+)\}$/,So=(e,t,r=new Set)=>{if("string"==typeof e){const n=e.match(Ao);if(n){const o=n[1];if(r.has(o))throw new y("REFRACT_E_CYCLE",`Circular token reference: ${o}`);const s=t.get(o);return s?(r.add(o),So(s.value,t,r)):e}return e}if(Array.isArray(e))return e.map(e=>So(e,t,new Set(r)));if("object"==typeof e&&null!==e){const n={};for(const[o,s]of Object.entries(e))n[o]=So(s,t,new Set(r));return n}return e};function Eo(e){var t;const r=[];for(const[n,o]of Object.entries(e.subsystems))for(const[e,s]of Object.entries(null!==(t=o.ruleSets)&&void 0!==t?t:{}))for(const t of Object.keys(s))r.push({subsystem:n,group:e,variant:t});return r}function Ro(){return{name:(e={name:"noop",version:1,bind:()=>({recipeName:()=>"",renderRecipe:()=>"",renderVariables:()=>"",join:e=>e.join(""),emit:()=>({files:{}})})}).name,version:e.version,allowedStates:e.allowedStates,bind(t,r){var n,o,s,i;const a=e.bind(t,r),l=null!==(n=a.renderAllRecipes)&&void 0!==n?n:()=>a.join(Eo(t).map(({subsystem:e,group:t,variant:r})=>a.renderRecipe(e,t,r))),c=null!==(o=a.renderAllVariables)&&void 0!==o?o:()=>a.join(Object.keys(t.subsystems).map(e=>a.renderVariables(e))),u=null!==(s=a.renderAll)&&void 0!==s?s:()=>a.join([c(),l()]),d=null!==(i=a.describeUsage)&&void 0!==i?i:()=>({format:e.name,summary:[`This theme was built with the "${e.name}" refract adapter.`],recipes:Eo(t).map(({subsystem:e,group:t,variant:r})=>({subsystem:e,group:t,variant:r,name:a.recipeName(e,t,r)}))});return{...a,renderAllRecipes:l,renderAllVariables:c,renderAll:u,describeUsage:d}}};var e}const Co=(e,t)=>{var r,n,o;const s=(e=>{const t=[],r=new Map,n=(e,o,s)=>{var i,a,l;const c=null!==(i=e.$type)&&void 0!==i?i:s;for(const[s,i]of Object.entries(e)){if(s.startsWith("$"))continue;if("object"!=typeof i||null===i)continue;const e=[...o,s];if(jo(i)){const n=i,o={path:e,type:null!==(l=null!==(a=n.$type)&&void 0!==a?a:c)&&void 0!==l?l:"color",value:n.$value,description:n.$description,extensions:n.$extensions};t.push(o),r.set(e.join("."),o)}else n(i,e,c)}};n(e,[]);for(const e of t)e.value=So(e.value,r);return t})(e),i=null!==(r=null==t?void 0:t.groupMapping)&&void 0!==r?r:{},a={},l={},c={},u={},d={};let f=null!==(n=null==t?void 0:t.breakpoints)&&void 0!==n?n:{};const p=new Map;for(const e of s){const t=e.path[0];p.has(t)||p.set(t,[]),p.get(t).push(e)}const m=null==t?void 0:t.breakpointGroup;if(m&&p.has(m)){f={};for(const e of p.get(m)){f[e.path[e.path.length-1]]=Wo(e.value)}p.delete(m)}for(const[e,t]of p){const r=null!==(o=i[e])&&void 0!==o?o:Oo(e,t);if("ignore"!==r)switch(r){case"colors":No(t,e,a);break;case"typography":Po(t,e,l);break;case"effects":qo(t,e,c);break;case"borders":Io(t,e,u);break;case"layout":Uo(t,e,d)}}const h={};return Object.keys(f).length&&(h.breakpoints=f),Object.keys(a).length&&(h.colors=a),Object.keys(l).length&&(h.typography=l),Object.keys(c).length&&(h.effects=c),Object.keys(u).length&&(h.borders=u),Object.keys(d).length&&(h.layout=d),h},Oo=(e,t)=>{var r;const n=null===(r=t[0])||void 0===r?void 0:r.type;if("color"===n)return"colors";if("typography"===n)return"typography";if("shadow"===n)return"effects";if("border"===n)return"borders";if("strokeStyle"===n)return"borders";if("transition"===n)return"effects";const o=e.toLowerCase();if(o.includes("color")||o.includes("palette"))return"colors";if(o.includes("font")||o.includes("typo")||o.includes("text"))return"typography";if(o.includes("spacing")||o.includes("space")||o.includes("gutter"))return"layout";if(o.includes("radius")||o.includes("border")||o.includes("outline"))return"borders";if(o.includes("shadow")||o.includes("blur")||o.includes("opacity")||o.includes("z-index")||o.includes("zindex")||o.includes("transition")||o.includes("effect"))return"effects";if("dimension"===n){if(o.includes("spacing")||o.includes("gap"))return"layout";if(o.includes("radius")||o.includes("border"))return"borders";if(o.includes("font")||o.includes("size"))return"typography"}return"ignore"},To=/^\{([^}]+)\}$/,Fo=e=>{if("string"!=typeof e)return;const t=e.match(To);if(!t)return;const r=t[1],n=r.indexOf("."),o=n<0?r:r.slice(0,n),s=n<0?"":r.slice(n+1),i="color"===o?"colors":o;return s?`${i}.${s}`:i},No=(e,t,r)=>{var n;const o=new Map,s=[];for(const t of e)if(t.path.length<=2)s.push(t);else{const e=t.path[1];o.has(e)||o.set(e,[]),o.get(e).push(t)}for(const e of s){const t=e.path[e.path.length-1];if(!r[t]){const n=Fo(e.value);r[t]=n?{external:n}:{base:String(e.value)}}}for(const[e,t]of o)if(1===t.length){const n=t[0],o=n.path[n.path.length-1];o===e?r[e]={base:String(n.value)}:(r[e]||(r[e]={base:String(t[0].value)}),r[e].variants={[o]:String(n.value)})}else{const o=null!==(n=t.find(e=>{const t=e.path[e.path.length-1];return"base"===t||"default"===t||"500"===t}))&&void 0!==n?n:t[0],s={};for(const e of t){if(e===o)continue;s[e.path.slice(2).join("-")]=String(e.value)}r[e]={base:String(o.value),...Object.keys(s).length?{variants:s}:{}}}},_o={fontfamily:"fontFamily",fontsize:"fontSize",fontweight:"fontWeight",lineheight:"lineHeight",letterspacing:"letterSpacing",fontstyle:"fontStyle",texttransform:"textTransform",textdecoration:"textDecoration",textalign:"textAlign"},Po=(e,t,r)=>{for(const n of e)if("typography"===n.type){const e=n.value,t=n.path.slice(1).join("-")||n.path[n.path.length-1];e.fontFamily&&zo(r,"fontFamily",Array.isArray(e.fontFamily)?e.fontFamily.join(", "):e.fontFamily,t),e.fontSize&&zo(r,"fontSize",Ho(e.fontSize),t),void 0!==e.fontWeight&&zo(r,"fontWeight",e.fontWeight,t),void 0!==e.lineHeight&&zo(r,"lineHeight",e.lineHeight,t),e.letterSpacing&&zo(r,"letterSpacing",e.letterSpacing,t)}else{const e=Mo(n,t);if(!e)continue;const o=n.path[n.path.length-1],s="fontFamily"===n.type&&Array.isArray(n.value)?n.value.join(", "):"dimension"===n.type?Ho(n.value):n.value;zo(r,e,s,o)}},zo=(e,t,r,n)=>{if(!e[t])return void(e[t]={base:r,variants:{}});const o=e[t];"base"===n||"default"===n||"md"===n?o.base=r:o.variants[n]=r},Mo=(e,t)=>{if("fontFamily"===e.type)return"fontFamily";if("fontWeight"===e.type)return"fontWeight";const r=e.path.join(".").toLowerCase();for(const[e,t]of Object.entries(_o))if(r.includes(e))return t;const n=t.toLowerCase();for(const[e,t]of Object.entries(_o))if(n.includes(e))return t;return null},qo=(e,t,r)=>{for(const t of e){const e=t.path[t.path.length-1];switch(t.type){case"shadow":{const n=Do(t.value);Lo(r,"shadow",n,e);break}case"transition":{const n=t.value,o=n.timingFunction?`cubic-bezier(${n.timingFunction.join(", ")})`:"ease",s=`all ${n.duration} ${o}`;Lo(r,"transitions",s,e);break}case"dimension":t.path.join(".").toLowerCase().includes("blur")&&Lo(r,"blur",Ho(t.value),e);break;case"number":{const n=t.path.join(".").toLowerCase();n.includes("opacity")?Lo(r,"opacity",t.value,e):(n.includes("z-index")||n.includes("zindex"))&&Lo(r,"zIndex",t.value,e);break}}}},Lo=(e,t,r,n)=>{if(!e[t])return void(e[t]={base:r,variants:{}});const o=e[t];"base"===n||"default"===n||"md"===n?o.base=r:o.variants[n]=r},Io=(e,t,r)=>{for(const t of e){const e=t.path[t.path.length-1];switch(t.type){case"border":{const n=t.value;Bo(r,"width",Ho(n.width),e),n.style&&Bo(r,"style",n.style,e);break}case"strokeStyle":Bo(r,"style",String(t.value),e);break;case"dimension":{const n=t.path.join(".").toLowerCase();n.includes("radius")?Bo(r,"radius",Ho(t.value),e):n.includes("offset")?Bo(r,"offset",Ho(t.value),e):n.includes("width")&&Bo(r,"width",Ho(t.value),e);break}}}},Bo=(e,t,r,n)=>{if(!e[t])return void(e[t]={base:r,variants:{}});const o=e[t];"base"===n||"default"===n||"md"===n?o.base=r:o.variants[n]=r},Uo=(e,t,r)=>{for(const t of e){if("dimension"!==t.type)continue;const e=t.path[t.path.length-1],n=Wo(t.value);r.spacing||(r.spacing={base:n,variants:{}});const o=r.spacing;"base"===e||"default"===e||"4"===e?o.base=n:o.variants[e]=n}},Do=e=>Array.isArray(e)?e.map(e=>Vo(e)).join(", "):Vo(e),Vo=e=>{const t=[];return e.inset&&t.push("inset"),t.push(e.offsetX,e.offsetY,e.blur,e.spread,e.color),t.join(" ")},Wo=e=>{if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?0:e.endsWith("rem")?Math.round(16*t):t},Ho=e=>{if("number"==typeof e)return e;const t=parseFloat(e);return isNaN(t)?e:e.endsWith("px")?t:e},Go=(e,t)=>{var r;const n={};(null==t?void 0:t.name)&&(n.$name=t.name);const o=e.model.breakpoints;if(!1!==(null==t?void 0:t.includeBreakpoints)&&o&&Object.keys(o).length){const e={$type:"dimension"};for(const[t,r]of Object.entries(o))e[t]={$value:`${r}px`};n.breakpoint=e}const s=Jo(e),i=t=>{try{return String(e.resolveToken(t))}catch{return t}},a=s.get("colors");if(a){const e={$type:"color"};for(const[t,r]of a){const n={};void 0!==r.base&&(n.base={$value:ut(String(r.base))});for(const[e,t]of Object.entries(r.members))n[e]={$value:ut(String(t))};e[t]=n}n.color=e}const l=s.get("typography");if(l){const e={};for(const[t,r]of l){const n={$type:Ko(t)};void 0!==r.base&&(n.base={$value:Xo(r.base,r.baseUnit)});for(const[e,t]of Object.entries(r.members))n[e]={$value:Xo(t,r.memberUnits[e])};e[t]=n}n.typography=e}const c=s.get("effects");if(c)for(const[e,t]of c){const{groupName:r,type:o}=Zo(e);n[r]||(n[r]={$type:o});const s=n[r];void 0!==t.base&&(s.base={$value:Qo(e,t.base,i,t.baseUnit)});for(const[r,n]of Object.entries(t.members))s[r]={$value:Qo(e,n,i,t.memberUnits[r])}}const u=s.get("borders");if(u)for(const[e,t]of u){const{groupName:r,type:o}=es(e);n[r]||(n[r]={$type:o});const s=n[r];void 0!==t.base&&(s.base={$value:ts(t.base,t.baseUnit)});for(const[e,r]of Object.entries(t.members))s[e]={$value:ts(r,t.memberUnits[e])}}const d=s.get("layout");if(d)for(const[e,t]of d){if(e.includes("--"))continue;const r=e;n[r]||(n[r]={$type:"dimension"});const o=n[r];void 0!==t.base&&(o.base={$value:rs(t.base,t.baseUnit)});for(const[e,r]of Object.entries(t.members))o[e]={$value:rs(r,t.memberUnits[e])}}if(null==t?void 0:t.includeRecipes){const t=(e=>{const t={},r={},n={};for(const[o,s]of Object.entries(e.subsystems))s.properties&&Object.keys(s.properties).length&&(t[o]=s.properties),s.ruleSets&&Object.keys(s.ruleSets).length&&(r[o]=s.ruleSets),s.keyframes&&Object.keys(s.keyframes).length&&(n[o]=s.keyframes);const o=Object.keys(t).length>0,s=Object.keys(r).length>0,i=Object.keys(n).length>0,a=!!e.containers&&Object.keys(e.containers).length>0;if(o||s||i||a)return{version:1,...o?{properties:t}:{},...s?{ruleSets:r}:{},...i?{keyframes:n}:{},...a?{containers:e.containers}:{}}})(e.model);t&&(n.$extensions={...null!==(r=n.$extensions)&&void 0!==r?r:{},[xo]:t})}return n},Yo=(e,t)=>void 0!==t?`${e}${t}`:e,Jo=e=>{const t=new Map;for(const r of Object.keys(e.tokens)){const n=r.indexOf(".");if(n<0)continue;const o=r.slice(0,n),s=r.slice(n+1),i=s.indexOf("."),a=i<0?s:s.slice(0,i),l=i<0?void 0:s.slice(i+1),c=e.tokens[r];if(void 0!==(null==c?void 0:c.external))continue;let u;if(void 0!==(null==c?void 0:c.struct))u=c.struct;else try{u=e.resolveToken(r)}catch{continue}const d=null==c?void 0:c.unit;let f=t.get(o);f||(f=new Map,t.set(o,f));let p=f.get(a);p||(p={members:{},memberUnits:{}},f.set(a,p)),void 0===l?(p.base=u,void 0!==d&&(p.baseUnit=d)):(p.members[l]=u,void 0!==d&&(p.memberUnits[l]=d))}return t},Ko=e=>{switch(e){case"fontFamily":return"fontFamily";case"fontWeight":return"fontWeight";case"fontSize":case"letterSpacing":return"dimension";default:return"number"}},Xo=(e,t)=>Yo(e,t),Zo=e=>{switch(e){case"shadow":return{groupName:"shadow",type:"shadow"};case"transitions":return{groupName:"transition",type:"transition"};case"blur":default:return{groupName:e,type:"dimension"};case"opacity":case"zIndex":return{groupName:e,type:"number"}}},Qo=(e,t,r,n)=>Array.isArray(t)?"transitions"===e?t.map(e=>{var t;const r=[e.property];return null==e.duration&&null==e.delay||r.push(`${null!==(t=e.duration)&&void 0!==t?t:0}ms`),e.timingFunction&&r.push(e.timingFunction),null!=e.delay&&r.push(`${e.delay}ms`),r.join(" ")}).join(", "):((e,t)=>e.map(e=>{const r=`0${(e=>{for(const t of[e.offsetX,e.offsetY,e.blur,e.spread])if(void 0!==t&&"number"!=typeof t)return t.unit;return"px"})(e)}`,n=e=>void 0===e?r:(e=>"number"==typeof e?`${e}px`:`${e.value}${e.unit}`)(e),o=[];return e.inset&&o.push("inset"),o.push(n(e.offsetX),n(e.offsetY)),null!=e.spread?o.push(n(e.blur),n(e.spread)):null!=e.blur&&o.push(n(e.blur)),e.color&&o.push(t(e.color)),o.join(" ")}).join(", "))(t,r):Yo(t,n),es=e=>{switch(e){case"radius":return{groupName:"radius",type:"dimension"};case"width":return{groupName:"borderWidth",type:"dimension"};case"offset":return{groupName:"outlineOffset",type:"dimension"};case"style":return{groupName:"borderStyle",type:"strokeStyle"};default:return{groupName:e,type:"dimension"}}},ts=(e,t)=>Yo(e,t),rs=(e,t)=>Yo(e,t);async function ns(r){var n;const{raw:o,adapter:s,outDir:i,helpers:c=[],emit:d,media:p,units:m,baseFontSize:h,guide:g}=r,b=co(o,{adapter:s,media:p,units:m,baseFontSize:h}),y=_e(b.model.breakpoints,e=>Ie(e,qe(p))),w=De(b.model.containers,p),$=s.bind(b.model,{media:y,containers:w,resolve:b.resolveToken});if(!$.emit)throw new Error(`Adapter "${s.name}" does not implement emit(); it cannot build to disk.`);const k=$.emit(ko(d)),x=[];e.mkdirSync(i,{recursive:!0});const j=(r,n)=>{const o=t.join(i,r);e.mkdirSync(t.dirname(o),{recursive:!0}),e.writeFileSync(o,n,"utf8"),x.push(o)};for(const[e,t]of Object.entries(k.files))j(e,t);for(const[e,t]of Object.entries(null!==(n=k.vendorHelpers)&&void 0!==n?n:{}))j(e,t);for(const e of c){const t=l(e);if(!t)throw new Error(`Unknown vendor helper "${e}". Known: ${a.map(e=>e.id).join(", ")}.`);j(t.outfile,await f(u(t.source)))}if(g){const e=!0===g?{}:g,t=v($.describeUsage(),Go(b),{files:Object.keys(k.files),packageName:e.packageName,llmsFile:e.llmsFile,manifestFile:e.manifestFile});for(const[e,r]of Object.entries(t.files))j(e,r)}return{outDir:i,files:x}}const os="theme.config",ss=[".ts",".mjs",".js"],is=(r=process.cwd())=>{for(const n of ss){const o=t.join(r,`${os}${n}`);if(e.existsSync(o))return o}};let as=0;async function ls(n={}){var o,s,i;const a=null!==(o=n.cwd)&&void 0!==o?o:process.cwd(),l=n.configPath?t.resolve(a,n.configPath):is(a);if(!l||!e.existsSync(l)){const e=n.configPath?`"${n.configPath}"`:`${os}.(ts|mjs|js) in "${a}"`;throw new Error(`No theme config found at ${e}.`)}const c=await async function(e){if(".ts"!==t.extname(e)){const t=`${r.pathToFileURL(e).href}?v=${++as}`;return await import(t)}const{entry:n,cleanup:o}=await h(e);try{return await import(r.pathToFileURL(n).href)}finally{o()}}(l),u=null!==(i=null!==(s=c.default)&&void 0!==s?s:c.config)&&void 0!==i?i:c;if(!u||"object"!=typeof u||!Array.isArray(u.targets))throw new Error(`"${l}" must export (default) a defineConfig({ raw, targets }) object.`);return{config:u,path:l}}const cs="@theme-registry/refract-css";function us(){var r;const n=t.join(c(),"package.json");return null!==(r=JSON.parse(e.readFileSync(n,"utf8")).name)&&void 0!==r?r:"@theme-registry/refract"}const ds="theme.raw",fs=[".ts",".mts",".mjs",".js",".json"],ps=(r=process.cwd())=>{for(const n of fs){const o=t.join(r,`${ds}${n}`);if(e.existsSync(o))return{path:o,filename:`${ds}${n}`,ext:n}}};function ms(e){if(".json"===e.ext)return{head:`import { readFileSync } from "node:fs";\n\n// The theme is JSON, so it's read rather than imported — no module-attribute support needed.\nconst raw = JSON.parse(readFileSync(new URL("./${e.filename}", import.meta.url), "utf8"));\n`,expression:"raw"};return{head:`import { raw } from "${".ts"===e.ext||".mts"===e.ext?`./${ds}`:`./${e.filename}`}";\n`,expression:"raw"}}function hs(e,t){const{head:r,expression:n}=ms(t);return`import { defineConfig } from "${e}/build";\nimport { createCssAdapter } from "${cs}";\n${r}\n// refract build config. \`refract build\` reads this file, builds the theme once, and writes each\n// target's emitted files into that target's \`outDir\`. The config is your code: it \`import\`s the\n// adapters it wants and passes their options at construction (not via CLI flags).\n//\n// Your tokens live in \`${t.filename}\` — edit them there, not here.\nexport default defineConfig({\n raw: ${n},\n targets: [\n // The CSS adapter (from @theme-registry/refract-css). Pass its options here, at construction.\n { adapter: createCssAdapter(/* { colors: { prefix: "app" } } */), outDir: "dist/theme" },\n\n // Add another adapter target once its package is installed, e.g.:\n // import { createStyledComponentsAdapter } from "@theme-registry/refract-styled-components";\n // { adapter: createStyledComponentsAdapter(), outDir: "dist/theme-sc" },\n ],\n});\n`}function gs(e){return`import { defineConfig } from "${e}/build";\nimport { createCssAdapter } from "${cs}";\n\n// refract build config. \`refract build\` reads this file, builds the theme once, and writes\n// each target's emitted files into that target's \`outDir\`. The config is your code: it \`import\`s\n// the adapters it wants and passes their options at construction (not via CLI flags).\nexport default defineConfig({\n // The raw theme — authored in refract's nested slices. Extend with typography/effects/layout.\n raw: {\n breakpoints: { sm: 576, md: 768, lg: 1024, xl: 1280 },\n colors: {\n // Starter palette passes its own contrast audit (WCAG AA): white text clears 4.5:1 on both\n // bases. Keep that when you retune — the auditor is a shipped feature; the default should model it.\n primary: { base: "#1864ab", text: "#fff", variants: { dark: "#0b4a86", light: "#a5d8ff" } },\n neutral: { base: "#495057", text: "#fff", variants: { light: "#f1f3f5", dark: "#212529" } },\n recipes: {\n solid: {\n primary: { background: "primary", color: "primary.text" },\n neutral: { background: "neutral.light", color: "neutral.dark" },\n },\n },\n },\n },\n targets: [\n // The CSS adapter (from @theme-registry/refract-css). Pass its options here, at construction.\n { adapter: createCssAdapter(/* { colors: { prefix: "app" } } */), outDir: "dist/theme" },\n\n // Add another adapter target once its package is installed, e.g.:\n // import { createStyledComponentsAdapter } from "@theme-registry/refract-styled-components";\n // { adapter: createStyledComponentsAdapter(), outDir: "dist/theme-sc" },\n ],\n});\n`}function bs(r={}){var n,o,s,i;const a=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),l=null!==(o=r.variant)&&void 0!==o?o:"ts",c=null!==(s=r.packageName)&&void 0!==s?s:us(),u=t.join(a,`theme.config.${l}`);if(e.existsSync(u)&&!r.force)throw new Error(`theme.config.${l} already exists at "${u}". Pass --force to overwrite it.`);const d=null===r.rawTheme?void 0:null!==(i=r.rawTheme)&&void 0!==i?i:ps(a),f=d?hs(c,d):gs(c);return e.writeFileSync(u,f,"utf8"),{path:u,variant:l,packageName:c,rawTheme:d}}const vs=[["xs",-2],["sm",-1],["md",0],["lg",1],["xl",2],["2xl",3],["3xl",4],["4xl",5]],ys={"minor-second":1.067,"major-second":1.125,"minor-third":1.2,"major-third":1.25,"perfect-fourth":1.333,"augmented-fourth":1.414,"perfect-fifth":1.5,golden:1.618},ws={complement:[180],analogous:[-30,30],"split-complement":[150,210],triadic:[120,240],tetradic:[90,180,270],pentadic:[72,144,216,288]},$s=["primary","secondary","tertiary","quaternary","quinary"],ks=[["success","#2f9e44","#ffffff"],["info","#1c7ed6","#ffffff"],["warning","#e89012","#1f2733"],["danger","#e03131","#ffffff"]],xs=[50,100,200,300,400,500,600,700,800,900],js=[8,14,22],As="system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",Ss="ui-monospace, 'SF Mono', Menlo, Consolas, monospace",Es={neutral:{label:"Neutral",blurb:"system type, comfortable spacing, soft corners",fontFamily:{base:As,mono:Ss},spacing:{xs:1,sm:2,md:4,lg:6,xl:8,"2xl":12},radius:{base:8,variants:{none:0,sm:4,lg:14,pill:"9999px"}},ratio:"major-third"},compact:{label:"Compact",blurb:"dense UI, tight scale, small radius",fontFamily:{base:As,mono:Ss},spacing:{xs:1,sm:2,md:3,lg:4,xl:6,"2xl":8},radius:{base:4,variants:{none:0,sm:2,lg:8,pill:"9999px"}},ratio:"major-second"},editorial:{label:"Editorial",blurb:"serif display, spacious, generous leading",fontFamily:{base:"'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif",mono:Ss},spacing:{xs:2,sm:4,md:6,lg:8,xl:12,"2xl":16},radius:{base:2,variants:{none:0,sm:1,lg:4,pill:"9999px"}},ratio:"perfect-fourth"},technical:{label:"Technical",blurb:"mono accents, compact, sharp corners",fontFamily:{base:Ss,mono:Ss},spacing:{xs:1,sm:2,md:3,lg:4,xl:6,"2xl":8},radius:{base:0,variants:{none:0,sm:0,lg:2,pill:"9999px"}},ratio:"minor-third"}},Rs=(e,t)=>Number(e.toFixed(t)),Cs=e=>Je(Xe(e).rgb),Os=e=>Rs(Math.min(1.7,Math.max(1.1,1.5*Math.pow(16/e,.22))),2),Ts=e=>`${Rs(.36/e-.0225,3)}em`,Fs=e=>{const t=1e3-10*e;let r=xs[0];for(const e of xs)Math.abs(e-t)<Math.abs(r-t)&&(r=e);return r},Ns=e=>{if(!(e<=1))return 2===e?"complement":3===e?"triadic":4===e?"tetradic":"pentadic"},_s=e=>Object.keys(ws).filter(t=>ws[t].length===e-1);function Ps(e){var t,r,n,o,s,i,a,l,c;const u=null!==(t=e.mode)&&void 0!==t?t:"auto",d=Es[null!==(r=e.feel)&&void 0!==r?r:"neutral"],f=Math.min(5,Math.max(1,null!==(n=e.brandCount)&&void 0!==n?n:2)),p=null!==(o=e.baseFontSize)&&void 0!==o?o:16,m=null!==(s=e.ratio)&&void 0!==s?s:d.ratio,h=ys[m];if(!h)throw new Error(`Unknown type ratio "${m}". Use one of: ${Object.keys(ys).join(", ")}.`);const g=Cs(e.seed),b=[{name:$s[0],hex:g,rotation:0}];if("manual"===u)(null!==(i=e.extraColors)&&void 0!==i?i:[]).slice(0,$s.length-1).forEach((e,t)=>{b.push({name:$s[t+1],hex:Cs(e),rotation:0})});else if(f>1){const t=null!==(a=e.scheme)&&void 0!==a?a:Ns(f),r=ws[t];if(!r)throw new Error(`Unknown harmony scheme "${t}".`);r.slice(0,f-1).forEach((e,t)=>{b.push({name:$s[t+1],hex:Cs(lt(g,e)),rotation:e})})}const v=null!==(l=e.contrast)&&void 0!==l?l:"AA",y=[...b.map(e=>({name:e.name,base:e.hex,text:"#ffffff"})),...!1===e.semantics?[]:ks.map(([e,t,r])=>({name:e,base:t,text:r})),...!1===e.neutral?[]:[{name:"neutral",base:"#6b7280",text:"#ffffff"}]],{palettes:w,adjustments:$}="none"===v?{palettes:y,adjustments:[]}:function(e,t){var r;const n=e.map(e=>({...e})),o=new Map(n.map(e=>[e.name,0])),s=new Map,i=()=>{var e,r;const o={};for(const e of n)o[e.name]={base:e.base,text:e.text};const s=co({colors:o},{adapter:Ro()}),i=hr(s,{minWcag:t,includeRecipes:!1}),a=new Map;for(const t of i.pairings){if(t.skipped||void 0===t.wcagRatio)continue;const n=t.label.replace(/^colors\./,"");a.set(n,{ratio:t.wcagRatio,level:null!==(e=t.wcagLevel)&&void 0!==e?e:"fail",pass:null!==(r=t.pass)&&void 0!==r&&r})}return a};let a=i();for(const[e,t]of a)s.has(e)||s.set(e,t.ratio);for(let e=0;e<40;e++){const e=n.filter(e=>a.get(e.name)&&!a.get(e.name).pass);if(!e.length)break;for(const t of e)t.base=Cs(it(t.base,1)),o.set(t.name,(null!==(r=o.get(t.name))&&void 0!==r?r:0)+1);a=i()}const l=n.map((t,r)=>{var n,i,l,c;const u=a.get(t.name);return{name:t.name,seed:e[r].base,final:t.base,nudge:null!==(n=o.get(t.name))&&void 0!==n?n:0,ratioBefore:Rs(null!==(i=s.get(t.name))&&void 0!==i?i:0,2),ratioAfter:Rs(null!==(l=null==u?void 0:u.ratio)&&void 0!==l?l:0,2),levelAfter:null!==(c=null==u?void 0:u.level)&&void 0!==c?c:"fail",unresolved:!!u&&!u.pass}});return{palettes:n,adjustments:l}}(y,v),k={};for(const e of w)k[e.name]={base:e.base,text:e.text,steps:[...xs]};if(!1!==e.shadows){const e={};for(const t of js)e[`a${String(t).padStart(2,"0")}`]={modifiers:[{alpha:t}]};k.shadow={base:"#18274b",variants:e}}const x=vs.map(([e,t])=>({step:e,px:Rs(p*Math.pow(h,t),2)})),j={},A={};for(const{step:e,px:t}of x)"md"!==e&&(j[e]=Os(t),A[e]=Ts(t));A.caps="0.06em";const S={fontFamily:{base:d.fontFamily.base,variants:{mono:d.fontFamily.mono}},fontWeight:{base:400,variants:{medium:500,semibold:600,bold:700}},fontSize:{base:p,ratio:m},lineHeight:{base:Os(p),variants:j},letterSpacing:{base:"0em",variants:A}},E={spacing:{base:4,step:4,steps:{...d.spacing}}},R={width:{base:1,variants:{thick:2}},style:{base:"solid"},radius:{base:d.radius.base,variants:{...d.radius.variants}}},C=!1===e.shadows?void 0:{shadow:{offsetY:1,blur:3,color:"colors.shadow.a08",variants:{md:{offsetY:6,blur:16,color:"colors.shadow.a14"},lg:{offsetY:14,blur:34,color:"colors.shadow.a22"},none:"none"}}},O={colors:k,typography:S,layout:E,borders:R,...C?{effects:C}:{},animation:{duration:{base:200,variants:{fast:120,slow:400}},easing:{base:"cubic-bezier(.2,.7,.3,1)",variants:{out:"cubic-bezier(.16,.84,.44,1)"}}},..."none"===e.reset?{}:{globals:{preset:null!==(c=e.reset)&&void 0!==c?c:"preflight"}}},T=Rs(rt(Xe(g).rgb).L,1);return{raw:O,report:{seedLightness:T,nearestStep:Fs(T),brand:b.map(e=>{var t;const r=$.find(t=>t.name===e.name);return{name:e.name,hex:null!==(t=null==r?void 0:r.final)&&void 0!==t?t:e.hex,rotation:e.rotation}}),contrast:$,type:x.map(({step:e,px:t})=>({step:e,px:t,leading:Os(t),tracking:Ts(t)})),spacing:Object.entries(d.spacing).map(([e,t])=>({step:e,px:4*t}))}}}const zs="theme.raw",Ms=/^[A-Za-z_$][A-Za-z0-9_$]*$/,qs=e=>JSON.stringify(e);function Ls(e,t=0){const r=" ".repeat(t),n=" ".repeat(t+1);if(null===e)return"null";if("string"==typeof e)return qs(e);if("number"==typeof e||"boolean"==typeof e)return String(e);if(Array.isArray(e)){if(!e.length)return"[]";if(e.every(e=>null===e||"object"!=typeof e)){const t=`[${e.map(e=>Ls(e)).join(", ")}]`;if(r.length+t.length<=76)return t}return`[\n${e.map(e=>`${n}${Ls(e,t+1)}`).join(",\n")}\n${r}]`}const o=Object.entries(e);if(!o.length)return"{}";return`{\n${o.map(([e,r])=>{const o=Ms.test(e)?e:qs(e);return`${n}${o}: ${Ls(r,t+1)}`}).join(",\n")}\n${r}}`}const Is=(e,t)=>`// Generated by \`refract create\` — seed ${e} · ${t}.\n// This is YOUR theme now: every value is a literal you can read, edit and delete. The generator\n// does not run again. Tonal ladders, the type scale and the spacing ramp are synthesized by the\n// engine from the declarations below — re-tune a scale by editing one word, not eight numbers.\n`;function Bs(e,t){if("json"===t.format)return`${JSON.stringify(e,null,2)}\n`;const r=Ls(e);return"js"===t.format?`${Is(t.seed,t.detail)}\n/** @type {import("${t.packageName}/build").RawTheme} */\nexport const raw = ${r};\n`:`${Is(t.seed,t.detail)}import type { RawTheme } from "${t.packageName}/build";\n\nexport const raw = ${r} satisfies RawTheme;\n`}function Us(e){var t,r,n,o,s,i;const a=[],l="manual"===e.mode?(null!==(r=null===(t=e.extraColors)||void 0===t?void 0:t.length)&&void 0!==r?r:0)+1:null!==(n=e.brandCount)&&void 0!==n?n:2;return a.push(`${l} brand colour${1===l?"":"s"}`),"manual"!==e.mode&&l>1&&a.push(null!==(o=e.scheme)&&void 0!==o?o:"auto"),a.push(null!==(s=e.feel)&&void 0!==s?s:"neutral"),"none"!==e.contrast&&a.push(`WCAG ${null!==(i=e.contrast)&&void 0!==i?i:"AA"}`),a.join(" · ")}function Ds(r){var n,o,s,i;const a=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),l=null!==(o=r.format)&&void 0!==o?o:"ts",c=null!==(s=r.out)&&void 0!==s?s:`${zs}.${l}`,u=t.join(a,c);if(e.existsSync(u)&&!r.force)throw new Error(`"${c}" already exists. Re-run with --force to overwrite it.`);const{raw:d,report:f}=Ps(r),p=Bs(d,{format:l,packageName:null!==(i=r.packageName)&&void 0!==i?i:us(),seed:r.seed,detail:Us(r)});return e.writeFileSync(u,p,"utf8"),{path:u,format:l,raw:d,report:f,sections:Object.keys(d)}}const Vs=()=>Boolean(process.stdout.isTTY)&&!process.env.NO_COLOR,Ws=(e,t)=>Vs()?`[${e}m${t}[0m`:t,Hs=e=>Ws("1",e),Gs=e=>Ws("2",e),Ys=e=>Ws("36",e),Js=e=>Ws("32",e),Ks=e=>Ws("33",e),Xs=e=>e>0?`[${e}A`:"",Zs="[0J";function Qs(e,t=2){if(!Vs())return"";const r=/^#?([0-9a-f]{6})$/i.exec(e.trim());if(!r)return"";const n=parseInt(r[1],16),[o,s,i]=[n>>16&255,n>>8&255,255&n],a=/truecolor|24bit/i.test(null!==(l=process.env.COLORTERM)&&void 0!==l?l:"")?`48;2;${o};${s};${i}`:`48;5;${((e,t,r)=>{const n=e=>e<48?0:e<114?1:Math.min(5,Math.round((e-35)/40));return 16+36*n(e)+6*n(t)+n(r)})(o,s,i)}`;var l;return`[${a}m${" ".repeat(t)}[0m`}function ei(e){switch(e){case"[A":case"k":return"up";case"[B":case"j":return"down";case" ":return"space";case"\r":case"\n":return"submit";case"a":return"all";case"":case"":return"cancel";default:return"none"}}function ti(e){const t=[];for(let r=0;r<e.length;)""===e[r]&&"["===e[r+1]&&r+2<e.length?(t.push(ei(e.slice(r,r+3))),r+=3):(t.push(ei(e[r])),r+=1);return t}function ri(e,t,r,n){if(e.done||e.cancelled||0===r)return e;switch(t){case"up":return{...e,cursor:(e.cursor-1+r)%r};case"down":return{...e,cursor:(e.cursor+1)%r};case"space":{if(!n)return e;const t=new Set(e.selected);return t.has(e.cursor)?t.delete(e.cursor):t.add(e.cursor),{...e,selected:t}}case"all":{if(!n)return e;const t=e.selected.size===r;return{...e,selected:t?new Set:new Set(Array.from({length:r},(e,t)=>t))}}case"submit":return{...e,done:!0};case"cancel":return{...e,cancelled:!0};default:return e}}const ni=()=>Boolean(process.stdin.isTTY)&&"function"==typeof process.stdin.setRawMode;class oi{constructor(e=Boolean(process.stdin.isTTY)&&Boolean(process.stdout.isTTY)){this.interactive=e}get io(){return this.rl||(this.rl=n.createInterface({input:process.stdin,output:process.stdout})),this.rl}close(){var e;null===(e=this.rl)||void 0===e||e.close(),this.rl=void 0}question(e){return new Promise(t=>this.io.question(e,e=>t(e)))}out(e){process.stdout.write(e)}write(e=""){process.stdout.write(`${e}\n`)}async text(e,t,r){if(!this.interactive)return t;for(;;){const n=(await this.question(`${Ys("?")} ${Hs(e)} ${Gs(`(${t})`)} `)).trim()||t,o=null==r?void 0:r(n);if(!o)return n;this.write(` ${Ks("!")} ${o}`)}}async number(e,t,r){const n=await this.text(e,String(t),e=>{const t=Number(e);return Number.isFinite(t)?null==r?void 0:r(t):`"${e}" is not a number.`});return Number(n)}async select(e,t,r=0){var n,o,s;if(!this.interactive||1===t.length)return null!==(o=null===(n=t[r])||void 0===n?void 0:n.value)&&void 0!==o?o:t[0].value;if(ni()){return t[null!==(s=(await this.runList(e,t,{multi:!1,cursor:r,selected:new Set}))[0])&&void 0!==s?s:r].value}return this.selectByNumber(e,t,r)}async multiselect(e,t,r){var n;if(!this.interactive)return r.map(e=>t[e].value);if(ni()){return(await this.runList(e,t,{multi:!0,cursor:null!==(n=r[0])&&void 0!==n?n:0,selected:new Set(r)})).map(e=>t[e].value)}return this.multiselectByNumber(e,t,r)}runList(e,t,r){this.close();const n=process.stdin,{multi:o}=r;let s={cursor:Math.max(0,Math.min(r.cursor,t.length-1)),selected:r.selected,done:!1,cancelled:!1},i=0;const a=o?"↑↓ move · space toggle · a all · enter confirm":"↑↓ move · enter select",l=t.reduce((e,t)=>Math.max(e,t.label.length),0),c=()=>{i&&this.out(Xs(i)+Zs);const r=(()=>{const r=t.map((e,t)=>{var r;const n=t===s.cursor,i=n?Js("❯"):" ",a=o?s.selected.has(t)?Js("[✓]"):Gs("[ ]"):"",c=n?Hs(e.label):e.label,u=" ".repeat(Math.max(0,l-e.label.length)),d=(null!==(r=e.swatches)&&void 0!==r?r:[]).map(e=>Qs(e)).filter(Boolean).join(" ");return` ${i} ${a?`${a} `:""}${c}${u}${d?` ${d}`:""}${e.hint?` ${Gs(e.hint)}`:""}`});return[`${Ys("?")} ${Hs(e)} ${Gs(a)}`,...r].join("\n")})();this.out(`${r}\n`),i=r.split("\n").length};return new Promise((r,a)=>{const l=()=>{n.removeListener("data",d),n.removeListener("end",u),n.isTTY&&n.setRawMode(!1),n.pause(),this.out("[?25h")},u=()=>{const e=o?[...s.selected].sort((e,t)=>e-t):[s.cursor];this.out(Xs(i)+Zs),l(),r(e)},d=n=>{for(const e of ti(n))if(s=ri(s,e,t.length,o),s.done||s.cancelled)break;if(s.cancelled)return this.out(Xs(i)+Zs),l(),void a(new Error("Cancelled."));if(s.done){const n=o?[...s.selected].sort((e,t)=>e-t):[s.cursor];this.out(Xs(i)+Zs);const a=n.length?n.map(e=>t[e].label).join(", "):"none";return this.write(`${Ys("?")} ${Hs(e)} ${Gs("›")} ${Js(a)}`),l(),void r(n)}c()};n.setRawMode(!0),n.resume(),n.setEncoding("utf8"),this.out("[?25l"),n.on("data",d),n.on("end",u),c()})}async selectByNumber(e,t,r){for(this.write(`${Ys("?")} ${Hs(e)}`),t.forEach((e,t)=>{const n=t===r?Js("❯"):" ",o=e.hint?` ${Gs(`— ${e.hint}`)}`:"";this.write(` ${n} ${Gs(`${t+1}.`)} ${t===r?Hs(e.label):e.label}${o}`)});;){const e=(await this.question(` ${Gs(`1–${t.length}`)} `)).trim();if(!e)return t[r].value;const n=Number(e)-1;if(Number.isInteger(n)&&n>=0&&n<t.length)return t[n].value;this.write(` ${Ks("!")} Enter a number between 1 and ${t.length}.`)}}async multiselectByNumber(e,t,r){for(this.write(`${Ys("?")} ${Hs(e)} ${Gs('(comma-separated, blank = keep, "none" = clear)')}`),t.forEach((e,t)=>{const n=r.includes(t),o=e.hint?` ${Gs(`— ${e.hint}`)}`:"";this.write(` ${n?Js("◉"):Gs("◯")} ${Gs(`${t+1}.`)} ${e.label}${o}`)});;){const e=(await this.question(` ${Gs(`1–${t.length}`)} `)).trim().toLowerCase();if(!e)return r.map(e=>t[e].value);if("none"===e)return[];const n=e.split(",").map(e=>Number(e.trim())-1);if(n.every(e=>Number.isInteger(e)&&e>=0&&e<t.length))return n.map(e=>t[e].value);this.write(` ${Ks("!")} Enter numbers between 1 and ${t.length}, separated by commas.`)}}}const si={complement:[180],analogous:[-30,30],"split-complement":[150,210],triadic:[120,240],tetradic:[90,180,270],pentadic:[72,144,216,288]},ii=(e,t)=>{var r;return(null!==(r=si[t])&&void 0!==r?r:[]).map(t=>Je(Xe(lt(e,t)).rgb))},ai={complement:"one companion, 180° opposite — maximum separation",analogous:"two neighbours, ±30° — quiet and cohesive","split-complement":"the complement's neighbours — contrast with less tension",triadic:"even thirds, ±120° — three colours of equal weight",tetradic:"two complementary pairs — the most range",pentadic:"five evenly spaced hues — needs a dominant colour picked by hand"},li=[["major-second","1.125 · 16 · 18 · 20 · 23 · 26 · 29"],["minor-third","1.2 · 16 · 19 · 23 · 28 · 33 · 40"],["major-third","1.25 · 16 · 20 · 25 · 31 · 39 · 49"],["perfect-fourth","1.333 · 16 · 21 · 28 · 38 · 51 · 67"],["perfect-fifth","1.5 · 16 · 24 · 36 · 54 · 81 · 122"],["golden","1.618 · 16 · 26 · 42 · 68 · 110 · 178"]],ci=e=>{try{return void Xe(e)}catch{return`"${e}" isn't a colour refract can parse. Try a hex like #4c6ef5.`}};async function ui(e,t={}){var r,n,o,s,i,a,l,c;const u=null!==(r=t.seed)&&void 0!==r?r:await e.text("Primary colour","#4c6ef5",ci),d=Math.round(10*rt(Xe(u).rgb).L)/10,f=Je(Xe(u).rgb),p=Qs(f,3);e.write(` ${p?`${p} `:""}${Gs(`${f} · lightness ${d}% — lands at ≈${Fs(d)} on the ladder`)}`),e.write();const m=Boolean(t.manual);let h,g=2,b=[];if(m){if(b=(null!==(n=t.colors)&&void 0!==n?n:"").split(",").map(e=>e.trim()).filter(Boolean),!b.length&&e.interactive){const t=await e.number("How many brand colours in total?",2,e=>Number.isInteger(e)&&e>=1&&e<=5?void 0:"Pick a whole number from 1 to 5.");for(let r=1;r<t;r++)b.push(await e.text(`Brand colour ${r+1}`,"#e64980",ci))}g=b.length+1}else{g=t.colors?Number(t.colors):await e.number("How many brand colours? (including the primary)",2,e=>Number.isInteger(e)&&e>=1&&e<=5?void 0:"Pick a whole number from 1 to 5.");const r=_s(g);h=null!==(o=t.scheme)&&void 0!==o?o:Ns(g),!t.scheme&&r.length>1&&(h=await e.select("Harmony scheme",r.map(e=>({value:e,label:e,hint:ai[e],swatches:[f,...ii(f,e)]})),Math.max(0,r.indexOf(h)))),h&&g>1&&(e.write(` ${Gs(`→ ${h} · each member becomes its own palette with a full ladder`)}`),e.write())}const v=t.noSemantics||t.noNeutral||t.noShadows||!e.interactive?{semantics:!t.noSemantics,neutral:!t.noNeutral,shadows:!t.noShadows}:await(async()=>{const t=await e.multiselect("Also add",[{value:"semantics",label:"Semantic colours",hint:"success · info · warning · danger"},{value:"neutral",label:"Neutral ramp",hint:"50 … 900"},{value:"shadows",label:"Shadow tints",hint:"3 alpha levels + the effects ramp"}],[0,1,2]);return{semantics:t.includes("semantics"),neutral:t.includes("neutral"),shadows:t.includes("shadows")}})(),y=null!==(s=t.contrast)&&void 0!==s?s:await e.select("Contrast target",[{value:"AA",label:"WCAG AA",hint:"4.5:1 body text"},{value:"AAA",label:"WCAG AAA",hint:"7:1 — expect heavier nudges"},{value:"none",label:"Skip",hint:"write the colours exactly as given"}]),w=void 0!==t.baseSize?Number(t.baseSize):await e.number("Base font size (px)",16,e=>e>0?void 0:"Must be greater than zero."),$=null!==(i=t.feel)&&void 0!==i?i:await e.select("Overall feel",Object.keys(Es).map(e=>({value:e,label:Es[e].label,hint:Es[e].blurb}))),k=null!==(a=t.ratio)&&void 0!==a?a:await e.select("Type scale",li.map(([e,t])=>({value:e,label:e,hint:t})),Math.max(0,li.findIndex(([e])=>e===Es[$].ratio))),x=null!==(l=t.reset)&&void 0!==l?l:await e.select("CSS reset",[{value:"preflight",label:"preflight",hint:"full normalization + an h1–h6 size map"},{value:"normalize",label:"normalize",hint:"the classic, no heading map"},{value:"none",label:"none",hint:"you already ship one"}]),j=null!==(c=t.format)&&void 0!==c?c:await e.select("Format",[{value:"ts",label:"theme.raw.ts",hint:"typed, `satisfies RawTheme`"},{value:"js",label:"theme.raw.js",hint:"plain ESM, no build step"},{value:"json",label:"theme.raw.json",hint:"portable, no code at all"}]);return{seed:u,mode:m?"manual":"auto",brandCount:g,scheme:h,extraColors:b,...v,contrast:y,baseFontSize:w,ratio:k,feel:$,reset:x,format:j}}function di(e,t){const r=[],{contrast:n}=e.report;if(n.length){r.push(` ${Gs(`Contrast · ${n.length} pairings checked`)}`);for(const e of n){const t=e.nudge>0?`${Ks(`−${e.nudge}`)} ${Js(`${e.ratioAfter} ${e.levelAfter}`)}`:Gs("unchanged"),n=e.unresolved?` ${Ks("! still short of the bar")}`:"";r.push(` ${e.name.padEnd(10)} ${String(e.ratioBefore).padStart(5)} ${t}${n}`)}r.push("")}const o=n.filter(e=>e.nudge>0).length;return r.push(` ${Gs(`${e.sections.length} subsystems · ${t} variables · 0 recipes`)}`),o&&r.push(` ${Gs(`${o} colour${1===o?"":"s"} darkened to clear the contrast bar`)}`),r}const fi="theme.config.ts";function pi(e){const t={};for(const r of e.split(",")){const[e,n]=r.split(":"),o=null==e?void 0:e.trim(),s=Number.parseFloat((null!=n?n:"").trim());o&&Number.isFinite(s)&&(t[o]=s)}return t}function mi(e,t,r){return`// Generated by \`refract import\` from ${r}.\n// DTCG carries property tokens ONLY — recipes, components, composition, and states are not imported.\n// The mapping is heuristic (subsystem inferred from \`$type\`/name; \`border\` composite colors dropped;\n// rem rounded to px). Review the seeded tokens, then hand-author the rest of your theme below.\nimport type { RawTheme } from "${e}/build";\n\nexport const raw: RawTheme = ${JSON.stringify(t,null,2)};\n`}function hi(e,t){return`import { defineConfig } from "${e}/build";\nimport { createCssAdapter } from "${cs}";\nimport { raw } from "${t}";\n\n// Generated by \`refract import\`. This is your build config — edit it freely. Add adapter options at\n// construction (\`createCssAdapter({ … })\`) and extra targets (SC/JSON/…) as their packages install.\nexport default defineConfig({\n raw,\n targets: [\n { adapter: createCssAdapter(), outDir: "dist/theme" },\n ],\n});\n`}function gi(e){const t={};for(const[r,n]of Object.entries(e))"breakpoints"!==r&&(t[r]=n&&"object"==typeof n?Object.keys(n).length:0);return t}function bi(r){var n,o;const s=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),i=null!==(o=r.packageName)&&void 0!==o?o:us(),a=t.isAbsolute(r.input)?r.input:t.resolve(s,r.input);if(!e.existsSync(a))throw new Error(`No DTCG document found at "${r.input}" (resolved to "${a}").`);let l;try{l=JSON.parse(e.readFileSync(a,"utf8"))}catch(e){throw new Error(`"${a}" is not valid JSON: ${e.message}`)}const c={};r.breakpointGroup&&(c.breakpointGroup=r.breakpointGroup),r.breakpoints&&Object.keys(r.breakpoints).length&&(c.breakpoints=r.breakpoints);const u=Co(l,c),d=r.out?t.isAbsolute(r.out)?r.out:t.resolve(s,r.out):t.resolve(s,"theme.raw.ts");if(e.existsSync(d)&&!r.force)throw new Error(`${t.basename(d)} already exists at "${d}". Pass --force to overwrite it.`);let f;if(e.mkdirSync(t.dirname(d),{recursive:!0}),e.writeFileSync(d,mi(i,u,JSON.stringify(t.basename(a))),"utf8"),!r.rawOnly){if(f=t.resolve(t.dirname(d),fi),e.existsSync(f)&&!r.force)throw new Error(`${fi} already exists at "${f}". Pass --force to overwrite it, or --raw-only to skip writing a config.`);const n=`./${t.basename(d).replace(/\.(ts|mts|cts|tsx)$/,"")}`;e.writeFileSync(f,hi(i,n),"utf8")}return{inputFile:a,rawFile:d,configFile:f,sections:Object.keys(u),counts:gi(u)}}async function vi(e={}){var r;const n=null!==(r=e.cwd)&&void 0!==r?r:process.cwd(),{config:o,path:s}=await ls({cwd:n,configPath:e.configPath});if(!o.targets.length)throw new Error(`"${s}" has no targets to build.`);const i=function(e,t){if(void 0===t)return[...e];const r=e.filter(e=>e.name===t);if(r.length)return r;if(/^\d+$/.test(t)){const r=Number(t);if(r>=0&&r<e.length)return[e[r]]}const n=e.filter(e=>e.outDir===t);if(n.length)return n;throw new Error(`No target matched "${t}". Config has ${e.length} target(s): `+e.map((e,t)=>{var r;return null!==(r=e.name)&&void 0!==r?r:`#${t} (${e.outDir})`}).join(", ")+".")}(o.targets,e.target);if(void 0!==e.out&&i.length>1)throw new Error(`--out is ambiguous across ${i.length} targets; pass --target to pick one first.`);const a=t.dirname(s),l=[];for(const r of i){const s=void 0!==e.out?t.isAbsolute(e.out)?e.out:t.resolve(n,e.out):t.isAbsolute(r.outDir)?r.outDir:t.resolve(a,r.outDir),i=await ns({raw:o.raw,adapter:r.adapter,outDir:s,helpers:r.helpers,emit:r.emit,media:o.media,units:o.units,baseFontSize:o.baseFontSize,guide:r.guide});l.push({name:r.name,adapter:r.adapter.name,outDir:i.outDir,files:i.files})}return{configPath:s,targets:l}}async function yi(r={}){var n;const o=null!==(n=r.cwd)&&void 0!==n?n:process.cwd(),{config:s,path:i}=await ls({cwd:o,configPath:r.configPath}),a=co(s.raw,{adapter:Ro()}),l=Go(a),c=r.out?t.isAbsolute(r.out)?r.out:t.resolve(o,r.out):t.resolve(o,"tokens.json");e.mkdirSync(t.dirname(c),{recursive:!0}),e.writeFileSync(c,`${JSON.stringify(l,null,2)}\n`,"utf8");return{configPath:i,outFile:c,groupCount:Object.keys(l).filter(e=>!e.startsWith("$")).length}}async function wi(e={}){var t;const r=null!==(t=e.cwd)&&void 0!==t?t:process.cwd(),{config:n,path:o}=await ls({cwd:r,configPath:e.configPath}),s=co(n.raw,{adapter:Ro()});return{configPath:o,result:hr(s,{strict:e.strict,minWcag:e.minWcag,largeText:e.largeText})}}const $i=(e,t)=>{try{return String(e.resolveToken(t))}catch{return null}},ki=e=>{var t;const r=[];for(const[n,o]of Object.entries(e.model.subsystems))for(const[e,s]of Object.entries(null!==(t=o.ruleSets)&&void 0!==t?t:{}))for(const t of Object.keys(s))r.push({subsystem:n,group:e,variant:t});return r},xi=(e,t,r,n)=>{var o,s,i;return Boolean(null===(i=null===(s=null===(o=e.model.subsystems[t])||void 0===o?void 0:o.ruleSets)||void 0===s?void 0:s[r])||void 0===i?void 0:i[n])};function ji(e,t){const r=((e,t)=>{const r=new Set([...Object.keys(e.tokens),...Object.keys(t.tokens)]),n=[];for(const o of r){const r=o in e.tokens,s=o in t.tokens,i=r?$i(e,o):null,a=s?$i(t,o):null;r&&!s?n.push({path:o,before:i,after:null,kind:"removed"}):!r&&s?n.push({path:o,before:null,after:a,kind:"added"}):i!==a&&n.push({path:o,before:i,after:a,kind:"changed"})}return n.sort((e,t)=>e.path.localeCompare(t.path))})(e,t),n=((e,t)=>{var r,n,o,s,i,a,l,c;const u=e,d=t;if(!u.renderRecipe&&!d.renderRecipe)return[];const f=new Set,p=[...ki(e),...ki(t)].filter(e=>{const t=`${e.subsystem}.${e.group}.${e.variant}`;return!f.has(t)&&(f.add(t),!0)}),m=[];for(const{subsystem:f,group:h,variant:g}of p){const p=xi(e,f,h,g),b=xi(t,f,h,g),v=null!==(s=null!==(n=null===(r=d.getClass)||void 0===r?void 0:r.call(d,f,h,g))&&void 0!==n?n:null===(o=u.getClass)||void 0===o?void 0:o.call(u,f,h,g))&&void 0!==s?s:`${f}.${h}.${g}`;p&&!b?m.push({name:v,kind:"removed"}):!p&&b?m.push({name:v,kind:"added"}):(null!==(a=null===(i=u.renderRecipe)||void 0===i?void 0:i.call(u,f,h,g))&&void 0!==a?a:"")!==(null!==(c=null===(l=d.renderRecipe)||void 0===l?void 0:l.call(d,f,h,g))&&void 0!==c?c:"")&&m.push({name:v,kind:"changed"})}return m.sort((e,t)=>e.name.localeCompare(t.name))})(e,t),o=((e,t)=>{var r,n,o,s;const i=e=>e?{ratio:e.wcagRatio,level:e.wcagLevel,pass:e.pass}:null,a=e=>new Map(e.map(e=>[e.label,e])),l=a(hr(e).pairings),c=a(hr(t).pairings),u=new Set([...l.keys(),...c.keys()]),d=[];for(const e of u){const t=l.get(e),a=c.get(e),u=i(t),f=i(a);if((null==u?void 0:u.ratio)===(null==f?void 0:f.ratio)&&(null==u?void 0:u.level)===(null==f?void 0:f.level)&&Boolean(t)===Boolean(a))continue;const p=(null!==(r=null==t?void 0:t.pass)&&void 0!==r?r:null)!==(null!==(n=null==a?void 0:a.pass)&&void 0!==n?n:null)||(null!==(o=null==t?void 0:t.wcagLevel)&&void 0!==o?o:null)!==(null!==(s=null==a?void 0:a.wcagLevel)&&void 0!==s?s:null);d.push({label:e,before:u,after:f,crossed:p})}return d.sort((e,t)=>e.label.localeCompare(t.label))})(e,t);return{tokens:r,classes:n,contrast:o,summary:{tokensChanged:r.length,classesChanged:n.length,pairingsCrossed:o.filter(e=>e.crossed).length}}}const Ai={fail:0,"AA-large":1,AA:2,AAA:3};let Si=0;async function Ei(n){var o,s,i,a;if(!e.existsSync(n))throw new Error(`candidate theme not found at "${n}".`);let l;if(".json"===t.extname(n))l=JSON.parse(e.readFileSync(n,"utf8"));else if(".ts"===t.extname(n)){const{entry:e,cleanup:t}=await h(n);try{const t=await import(r.pathToFileURL(e).href);l=null!==(s=null!==(o=t.default)&&void 0!==o?o:t.raw)&&void 0!==s?s:t}finally{t()}}else{const e=await import(`${r.pathToFileURL(n).href}?v=${++Si}`);l=null!==(a=null!==(i=e.default)&&void 0!==i?i:e.raw)&&void 0!==a?a:e}return function(e,t){const r=t?` (${t})`:"";if(null===e||"object"!=typeof e||Array.isArray(e)){const t=Array.isArray(e)?"an array":null===e?"null":typeof e;throw new y("REFRACT_E_RAW_SHAPE",`Expected a RawTheme object${r}, got ${t}. Pass the raw theme (a module's default export, or a .json raw theme).`)}if(Array.isArray(e.targets))throw new y("REFRACT_E_RAW_SHAPE",`Expected a RawTheme object${r}, but got what looks like a defineConfig({ raw, targets }). Pass its \`raw\` (or a module that default-exports the raw theme), not the whole config.`)}(l,n),l}async function Ri(e){var r,n,o,s,i,a,l,c;const u=null!==(r=e.cwd)&&void 0!==r?r:process.cwd(),{config:d,path:f}=await ls({cwd:u,configPath:e.configPath}),p=t.resolve(u,e.candidatePath),m=await Ei(p),h={units:d.units,baseFontSize:d.baseFontSize,media:d.media},g=d.targets.map((e,t)=>{var r,n;return{name:null!==(n=null!==(r=e.name)&&void 0!==r?r:e.outDir)&&void 0!==n?n:`target-${t}`,adapter:e.adapter}}),b=g.map(({name:e,adapter:t})=>{var r;try{return co(m,{adapter:t,...h}),{name:e,ok:!0,errors:[]}}catch(t){const n=t;return{name:e,ok:!1,errors:n.failures?[...n.failures]:[null!==(r=n.message)&&void 0!==r?r:String(t)]}}}),v=null!==(o=null!==(n=g.find(({adapter:e})=>"function"==typeof co(d.raw,{adapter:e,...h}).renderRecipe))&&void 0!==n?n:g[0])&&void 0!==o?o:{name:"noop",adapter:Ro()},y=co(d.raw,{adapter:v.adapter,...h});let w={tokens:[],classes:[],contrast:[],summary:{tokensChanged:0,classesChanged:0,pairingsCrossed:0}};try{w=ji(y,co(m,{adapter:v.adapter,...h}))}catch{}const $=[];if(void 0!==e.maxClassChanges&&w.summary.classesChanged>e.maxClassChanges&&$.push(`${w.summary.classesChanged} classes changed (max ${e.maxClassChanges})`),void 0!==e.maxTokenChanges&&w.summary.tokensChanged>e.maxTokenChanges&&$.push(`${w.summary.tokensChanged} tokens changed (max ${e.maxTokenChanges})`),e.failBelow){const t=null!==(s=Ai[e.failBelow])&&void 0!==s?s:0;for(const r of w.contrast){const n=(null===(i=r.after)||void 0===i?void 0:i.level)&&null!==(a=Ai[r.after.level])&&void 0!==a?a:0,o=(null===(l=r.before)||void 0===l?void 0:l.level)&&null!==(c=Ai[r.before.level])&&void 0!==c?c:0;r.after&&n<t&&n<o&&$.push(`${r.label} drops to ${r.after.level} (below ${e.failBelow})`)}}const k=b.filter(e=>!e.ok).map(e=>e.name);return k.length&&$.push(`candidate no longer builds for: ${k.join(", ")}`),{configPath:f,candidatePath:p,diff:w,targets:b,ok:0===$.length,violations:$}}const Ci=["claude","codex","opencode","github-copilot","cursor","generic"],Oi={claude:{kind:"claude",routerFile:".claude/skills"},codex:{kind:"agents-md",routerFile:"AGENTS.md"},opencode:{kind:"agents-md",routerFile:"AGENTS.md"},"github-copilot":{kind:"agents-md",routerFile:".github/copilot-instructions.md"},cursor:{kind:"agents-md",routerFile:".cursor/rules/refract-skills.mdc"},generic:{kind:"agents-md",routerFile:"AGENTS.md"}},Ti="\x3c!-- refract-skills:start --\x3e",Fi="\x3c!-- refract-skills:end --\x3e",Ni=t.join(".refract","skills.lock"),_i=t.join(".refract","skills");function Pi(e){return null!=e?e:t.join(c(),"skills")}function zi(r){const n=Pi(r);if(!e.existsSync(n))throw new Error(`Skills catalog not found at "${n}". Reinstall @theme-registry/refract.`);return e.readdirSync(n,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>t.join(n,e.name,"SKILL.md")).filter(e.existsSync).map(r=>function(e,r){var n,o,s;const i=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(e),a=i?i[1]:"",l=i?e.slice(i[0].length).replace(/^\s+/,""):e,c=e=>{const t=new RegExp(`^${e}:\\s*(.*)$`,"m").exec(a);return t?t[1].trim():void 0},u=null!==(o=null!==(n=c("name"))&&void 0!==n?n:t.dirname(r).split(/[\\/]/).pop())&&void 0!==o?o:"unnamed",d="optional"===c("tier")?"optional":"core";return{name:u,description:null!==(s=c("description"))&&void 0!==s?s:"",tier:d,raw:e,body:l,sourcePath:r}}(e.readFileSync(r,"utf8"),r)).sort((e,t)=>e.name.localeCompare(t.name))}function Mi(e){const t=e.map(e=>`| [${e.name}](${_i}/${e.name}.md) | ${function(e){const t=e.description.split(/\s*Triggers:/)[0].trim();return(t.split(/\.\s/)[0].trim()||t).replace(/\|/g,"\\|")}(e)} |`).join("\n");return[Ti,"","## refract theme skills","","These skills document the [refract](https://github.com/theme-registry/refract) theme toolkit.","When a task matches a row below, read the linked file before working.","","| Skill | Use it for |","| --- | --- |",t,"",Fi].join("\n")}function qi(e,t){const r=e.indexOf(Ti),n=e.indexOf(Fi);if(-1!==r&&-1!==n&&n>r)return e.slice(0,r)+t+e.slice(n+Fi.length);const o=e.replace(/\s+$/,"");return o?`${o}\n\n${t}\n`:`${t}\n`}function Li(r,n){e.mkdirSync(t.dirname(r),{recursive:!0}),e.writeFileSync(r,n,"utf8")}function Ii(r){var n,s,i;const a=null!==(n=r.scope)&&void 0!==n?n:"local",l="global"===a?null!==(s=r.home)&&void 0!==s?s:o.homedir():null!==(i=r.cwd)&&void 0!==i?i:process.cwd(),u=function(e,t){if(t.skills&&t.skills.length>0){const r=new Map(e.map(e=>[e.name,e])),n=[];for(const o of t.skills){const t=r.get(o);if(!t)throw new Error(`Unknown skill "${o}". Available: ${e.map(e=>e.name).join(", ")}.`);n.push(t)}return n}return e.filter(e=>"core"===e.tier||t.includeOptional)}(zi(r.catalogDir),r);if(0===r.agents.length)throw new Error("Pick at least one agent target.");const d=new Set;if(r.agents.some(e=>"agents-md"===Oi[e].kind))for(const e of u){const r=t.join(l,_i,`${e.name}.md`);Li(r,e.body),d.add(r)}for(const n of r.agents){const r=Oi[n];if("claude"===r.kind)for(const e of u){const n=t.join(l,r.routerFile,e.name,"SKILL.md");Li(n,e.raw),d.add(n)}else{const n=t.join(l,r.routerFile);Li(n,qi(e.existsSync(n)?e.readFileSync(n,"utf8"):"",Mi(u))),d.add(n)}}const{name:f,version:p}=function(){var r,n;const o=JSON.parse(e.readFileSync(t.join(c(),"package.json"),"utf8"));return{name:null!==(r=o.name)&&void 0!==r?r:"@theme-registry/refract",version:null!==(n=o.version)&&void 0!==n?n:"0.0.0"}}(),m={schema:1,packageName:f,refractVersion:p,scope:a,agents:[...r.agents],skills:u.map(e=>e.name)},h=t.join(l,Ni);return Li(h,`${JSON.stringify(m,null,2)}\n`),{scope:a,agents:[...r.agents],skills:u.map(e=>e.name),files:[...d].sort(),manifestPath:h}}function Bi(r={}){var n,s,i;const a=null!==(n=r.scope)&&void 0!==n?n:"local",l="global"===a?null!==(s=r.home)&&void 0!==s?s:o.homedir():null!==(i=r.cwd)&&void 0!==i?i:process.cwd(),c=t.join(l,Ni);if(!e.existsSync(c))throw new Error(`No skills manifest at "${c}". Run \`refract skills install\` first.`);const u=JSON.parse(e.readFileSync(c,"utf8"));return Ii({agents:u.agents,scope:a,skills:u.skills,cwd:r.cwd,home:r.home,catalogDir:r.catalogDir})}const Ui="refract — build a refract theme to disk.\n\nUsage:\n refract create [--seed <color>] [--colors <n|list>] [--scheme <name>] [--manual]\n [--feel <neutral|compact|editorial|technical>] [--ratio <name>]\n [--base-size <px>] [--contrast <AA|AAA|none>] [--reset <name>]\n [--format <ts|js|json>] [--out <file>] [--no-semantics]\n [--no-neutral] [--no-shadows] [--yes] [--force]\n refract init [--js | --mjs] [--force]\n refract import <tokens.json> [--out <file>] [--raw-only] [--force]\n [--breakpoint-group <name>] [--breakpoints <n:px,…>]\n refract build [--config <path>] [--target <name|index>] [--out <dir>]\n refract tokens [--config <path>] [--out <file>]\n refract diff <candidate> [--config <path>] [--max-class-changes <n>]\n [--max-token-changes <n>] [--fail-below <AA|AAA|AA-large>]\n refract audit [--config <path>] [--strict] [--min-wcag <AA|AAA|AA-large>] [--large]\n refract skills <install|list|update> [--agent <a,b|all>] [--global|--local]\n [--only <names>] [--optional]\n refract help\n\nCommands:\n create Design a theme.raw.(ts|js|json) from one seed colour and a short interview.\n init Scaffold a runnable theme.config.(ts|js|mjs) in the current directory.\n import Seed a theme.raw.ts (+ theme.config.ts) from a DTCG tokens.json (one-shot).\n build Load the config and emit every target's files to its outDir.\n tokens Export the theme's tokens as a DTCG tokens.json (adapter-free).\n diff Show a candidate theme's blast radius vs the config (tokens/classes/contrast); thresholds gate CI.\n audit Score colour pairings for WCAG-2 contrast (+ advisory APCA). Reports; --strict fails.\n skills Install the bundled AI skills into your agent CLI(s) (claude/codex/…).\n";function Di(e,t){var r;const n=t,o="string"==typeof n.code&&n.code.startsWith("REFRACT_E_")?`[${n.code}] `:"";if(process.stderr.write(`refract ${e}: ${o}${null!==(r=n.message)&&void 0!==r?r:String(t)}\n`),n.failures)for(const e of n.failures)process.stderr.write(` - ${e}\n`);return 1}async function Vi(e){var t;const{values:r}=i.parseArgs({args:e,options:{seed:{type:"string"},colors:{type:"string"},scheme:{type:"string"},manual:{type:"boolean",default:!1},feel:{type:"string"},ratio:{type:"string"},"base-size":{type:"string"},contrast:{type:"string"},reset:{type:"string"},format:{type:"string"},out:{type:"string"},"no-semantics":{type:"boolean",default:!1},"no-neutral":{type:"boolean",default:!1},"no-shadows":{type:"boolean",default:!1},yes:{type:"boolean",default:!1},force:{type:"boolean",default:!1}},allowPositionals:!1}),n=new oi(!r.yes&&void 0);try{n.write(),n.write(` ${Hs("refract")} ${Gs("· raw-theme scaffold")}`),n.write();const e=Ds({...await ui(n,{seed:r.seed,colors:r.colors,scheme:r.scheme,manual:r.manual,feel:r.feel,ratio:r.ratio,baseSize:r["base-size"],contrast:r.contrast,reset:r.reset,format:r.format,noSemantics:r["no-semantics"],noNeutral:r["no-neutral"],noShadows:r["no-shadows"]}),out:r.out,force:Boolean(r.force)});n.write();for(const t of di(e,function(e){try{const t=co(e,{adapter:Ro()});return Object.keys(t.tokens).length}catch{return 0}}(e.raw)))n.write(t);return n.write(),n.write(` ${Hs(null!==(t=e.path.split(/[\\/]/).pop())&&void 0!==t?t:"")} written`),n.write(),n.write(` ${Gs("Next — wire up a build:")} ${Hs("refract init")}`),n.write(),0}catch(e){return Di("create",e)}finally{n.close()}}const Wi=new Set(["AAA","AA","AA-large"]);async function Hi(e){const[t,...r]=e;if("list"===t)try{for(const e of zi())process.stdout.write(` ${e.name.padEnd(26)} [${e.tier}] ${e.description.split(/\s*Triggers:/)[0].trim().slice(0,80)}\n`);return 0}catch(e){return Di("skills list",e)}const{values:n}=i.parseArgs({args:r,options:{agent:{type:"string"},global:{type:"boolean",default:!1},local:{type:"boolean",default:!1},only:{type:"string"},optional:{type:"boolean",default:!1}},allowPositionals:!1});if(n.global&&n.local)return process.stderr.write("refract skills: pass at most one of --global / --local.\n"),1;const o=n.global?"global":"local";try{if("update"===t){const e=Bi({scope:o});return process.stdout.write(`Updated ${e.skills.length} skill(s) for ${e.agents.join(", ")} (${e.scope}).\n`),0}if("install"===t||void 0===t){let e,t=Boolean(n.optional),r=o;if(n.agent)e=function(e){if("all"===e.trim())return[...Ci];const t=e.split(",").map(e=>e.trim()).filter(Boolean),r=t.filter(e=>!Ci.includes(e));if(r.length>0)throw new Error(`unknown agent(s) ${r.map(e=>`"${e}"`).join(", ")}. Known: ${Ci.join(", ")}.`);return t}(n.agent);else{if(!process.stdin.isTTY)return process.stderr.write("refract skills install: pass --agent <a,b|all> (no TTY for prompts).\n"),1;{const o=await async function(){const e=s.createInterface({input:process.stdin,output:process.stdout});try{process.stdout.write("Install refract skills for which agent(s)?\n"),Ci.forEach((e,t)=>process.stdout.write(` ${t+1}) ${e}\n`));const t=await e.question("Enter numbers (comma-separated), or 'all': "),r="all"===t.trim()||""===t.trim()?[...Ci]:t.split(",").map(e=>Ci[Number(e.trim())-1]).filter(e=>Boolean(e));if(0===r.length)throw new Error("no agents selected.");return{agents:r,scope:(await e.question("Scope — [l]ocal (project) or [g]lobal (home)? [l]: ")).trim().toLowerCase().startsWith("g")?"global":"local",includeOptional:(await e.question("Include optional skills (adapter-scaffold, troubleshooting)? [y/N]: ")).trim().toLowerCase().startsWith("y")}}finally{e.close()}}();e=o.agents,t=o.includeOptional,n.global||n.local||(r=o.scope)}}const i=Ii({agents:e,scope:r,skills:n.only?n.only.split(",").map(e=>e.trim()).filter(Boolean):void 0,includeOptional:t});process.stdout.write(`Installed ${i.skills.length} skill(s) for ${i.agents.join(", ")} (${i.scope}):\n`);for(const e of i.files)process.stdout.write(` ${e}\n`);return process.stdout.write(` manifest → ${i.manifestPath}\n`),0}return process.stderr.write(`refract skills: unknown subcommand "${t}". Use install | list | update.\n`),1}catch(e){return Di("skills",e)}}async function Gi(e){const[t,...r]=e;switch(t){case"create":return Vi(r);case"init":return async function(e){const{values:t}=i.parseArgs({args:e,options:{js:{type:"boolean",default:!1},mjs:{type:"boolean",default:!1},force:{type:"boolean",default:!1}},allowPositionals:!1});if(t.js&&t.mjs)return process.stderr.write("refract init: pass at most one of --js / --mjs.\n"),1;const r=t.mjs?"mjs":t.js?"js":"ts";try{const e=bs({variant:r,force:Boolean(t.force)});return e.rawTheme&&process.stdout.write(`Found ${e.rawTheme.filename} — wired it up.\n`),process.stdout.write(`Created ${e.path}\n`),process.stdout.write(e.rawTheme?"Next: run `refract build`.\n":"Next: edit the starter theme in the config (or run `refract create` to design one), then `refract build`.\n"),0}catch(e){return Di("init",e)}}(r);case"import":return async function(e){const{values:t,positionals:r}=i.parseArgs({args:e,options:{out:{type:"string"},"raw-only":{type:"boolean",default:!1},force:{type:"boolean",default:!1},"breakpoint-group":{type:"string"},breakpoints:{type:"string"}},allowPositionals:!0}),n=r[0];if(!n)return process.stderr.write("refract import: pass the DTCG document to import, e.g. `refract import tokens.json`.\n"),1;if(r.length>1)return process.stderr.write(`refract import: unexpected extra argument "${r[1]}".\n`),1;try{const e=bi({input:n,out:t.out,rawOnly:Boolean(t["raw-only"]),force:Boolean(t.force),breakpointGroup:t["breakpoint-group"],breakpoints:t.breakpoints?pi(t.breakpoints):void 0});process.stdout.write(`Imported ${e.inputFile}\n`),process.stdout.write(` raw → ${e.rawFile}\n`),e.configFile&&process.stdout.write(` config → ${e.configFile}\n`);const r=Object.entries(e.counts).map(([e,t])=>`${e} (${t})`).join(", ");return r&&process.stdout.write(` seeded: ${r}\n`),process.stdout.write("Next: review the inferred tokens, then add recipes/components and run `refract build`.\n"),0}catch(e){return Di("import",e)}}(r);case"build":return async function(e){const{values:t}=i.parseArgs({args:e,options:{config:{type:"string"},target:{type:"string"},out:{type:"string"}},allowPositionals:!1});try{const e=await vi({configPath:t.config,target:t.target,out:t.out});process.stdout.write(`Built from ${e.configPath}\n`);for(const t of e.targets){const e=t.name?`${t.name} [${t.adapter}]`:t.adapter;process.stdout.write(` ${e} → ${t.outDir} (${t.files.length} file(s))\n`);for(const e of t.files)process.stdout.write(` ${e}\n`)}return 0}catch(e){return Di("build",e)}}(r);case"tokens":return async function(e){const{values:t}=i.parseArgs({args:e,options:{config:{type:"string"},out:{type:"string"}},allowPositionals:!1});try{const e=await yi({configPath:t.config,out:t.out});return process.stdout.write(`Exported tokens from ${e.configPath}\n`),process.stdout.write(` ${e.groupCount} group(s) → ${e.outFile}\n`),0}catch(e){return Di("tokens",e)}}(r);case"diff":return async function(e){var t,r,n,o;const{values:s,positionals:a}=i.parseArgs({args:e,options:{config:{type:"string"},"max-class-changes":{type:"string"},"max-token-changes":{type:"string"},"fail-below":{type:"string"}},allowPositionals:!0}),l=a[0];if(!l)return process.stderr.write("refract diff: pass the candidate theme, e.g. `refract diff candidate.ts`.\n"),1;const c=s["fail-below"];if(void 0!==c&&!Wi.has(c))return process.stderr.write(`refract diff: --fail-below must be one of AAA | AA | AA-large (got "${c}").\n`),1;try{const e=await Ri({configPath:s.config,candidatePath:l,maxClassChanges:void 0!==s["max-class-changes"]?Number(s["max-class-changes"]):void 0,maxTokenChanges:void 0!==s["max-token-changes"]?Number(s["max-token-changes"]):void 0,failBelow:c}),{diff:i}=e;process.stdout.write(`Diffed ${e.candidatePath}\n vs ${e.configPath}\n`),process.stdout.write(` ${i.summary.tokensChanged} token(s), ${i.summary.classesChanged} class(es), ${i.summary.pairingsCrossed} pairing(s) crossed a threshold\n`);for(const e of i.tokens.slice(0,20)){const t="changed"===e.kind?`${e.before} → ${e.after}`:"added"===e.kind?`+ ${e.after}`:`- ${e.before}`;process.stdout.write(` token ${e.path}: ${t}\n`)}i.tokens.length>20&&process.stdout.write(` … +${i.tokens.length-20} more token(s)\n`);for(const e of i.classes)process.stdout.write(` class ${e.kind.padEnd(7)} ${e.name}\n`);for(const e of i.contrast.filter(e=>e.crossed))process.stdout.write(` contrast ${e.label}: ${null!==(r=null===(t=e.before)||void 0===t?void 0:t.level)&&void 0!==r?r:"—"} → ${null!==(o=null===(n=e.after)||void 0===n?void 0:n.level)&&void 0!==o?o:"—"}\n`);if(e.violations.length){process.stderr.write("✗ diff gate failed:\n");for(const t of e.violations)process.stderr.write(` ${t}\n`);return 1}return 0}catch(e){return Di("diff",e)}}(r);case"audit":return async function(e){const{values:t}=i.parseArgs({args:e,options:{config:{type:"string"},strict:{type:"boolean",default:!1},"min-wcag":{type:"string"},large:{type:"boolean",default:!1}},allowPositionals:!1}),r=t["min-wcag"];if(void 0!==r&&!Wi.has(r))return process.stderr.write(`refract audit: --min-wcag must be one of AAA | AA | AA-large (got "${r}").\n`),1;try{const{configPath:e,result:n}=await wi({configPath:t.config,strict:t.strict,minWcag:r,largeText:t.large});process.stdout.write(`Audited ${e}\n`);for(const e of n.pairings)if(e.skipped)process.stdout.write(` ~ ${e.label} — skipped (${e.skipped})\n`);else{const t=e.pass?"✓":"✗";process.stdout.write(` ${t} ${e.label} — ${e.wcagRatio}:1 ${e.wcagLevel} · APCA Lc ${e.apcaLc}\n`)}const o=n.summary;return process.stdout.write(`${o.passed}/${o.total} pass, ${o.failed} fail, ${o.skipped} skipped\n`),0}catch(e){return Di("audit",e)}}(r);case"skills":return Hi(r);case void 0:case"help":case"--help":case"-h":return process.stdout.write(Ui),0;default:return process.stderr.write(`refract: unknown command "${t}".\n\n${Ui}`),1}}"undefined"!=typeof require&&"undefined"!=typeof module&&require.main===module&&Gi(process.argv.slice(2)).then(e=>process.exit(e),e=>{var t;process.stderr.write(`refract: ${null!==(t=e.stack)&&void 0!==t?t:e}\n`),process.exit(1)}),exports.AGENT_TARGETS=Ci,exports.CSS_ADAPTER_PACKAGE=cs,exports.DEFAULT_RAW_BASENAME=zs,exports.FEEL_PRESETS=Es,exports.Prompter=oi,exports.SCHEME_HINTS=ai,exports.TYPE_SCALE_CHOICES=li,exports.VENDOR_HELPERS=a,exports.applyKey=ri,exports.bold=Hs,exports.buildGuide=v,exports.compileTsConfigGraph=h,exports.createReportLines=di,exports.cyan=Ys,exports.decodeKey=ei,exports.decodeKeys=ti,exports.defaultSchemeFor=Ns,exports.defineConfig=e=>e,exports.deriveLeading=Os,exports.deriveTracking=Ts,exports.diffThemes=ji,exports.dim=Gs,exports.emitTheme=ns,exports.findConfigFile=is,exports.findPackageRoot=c,exports.findRawTheme=ps,exports.findVendorHelper=l,exports.green=Js,exports.listSkills=zi,exports.loadConfig=ls,exports.main=Gi,exports.nearestLadderStep=Fs,exports.parseBreakpointsFlag=pi,exports.promptCreateAnswers=ui,exports.rawThemeImport=ms,exports.readOwnPackageName=us,exports.readVendorSource=u,exports.renderRawTheme=Bs,exports.resolveEmitPlan=ko,exports.runAudit=wi,exports.runBuild=vi,exports.runCreate=Ds,exports.runDiff=Ri,exports.runImport=bi,exports.runInit=bs,exports.runSkillsInstall=Ii,exports.runSkillsUpdate=Bi,exports.runTokens=yi,exports.scaffoldConfig=gs,exports.scaffoldConfigForRaw=hs,exports.scaffoldImportConfig=hi,exports.scaffoldRaw=mi,exports.scaffoldTheme=Ps,exports.schemesFor=_s,exports.skillsCatalogDir=Pi,exports.swatch=Qs,exports.transpileToEsm=f,exports.yellow=Ks;
|
|
2
2
|
//# sourceMappingURL=build.cjs.js.map
|