@apollion-dsi/tokens 5.6.0 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/lib/build.cjs +10 -9
- package/lib/build.esm.js +10 -9
- package/lib/builders/colors.d.ts +27 -0
- package/lib/cli.mjs +13 -12
- package/lib/config-loader.cjs +1 -1
- package/lib/config-loader.esm.js +2 -2
- package/lib/config-schema.cjs +1 -1
- package/lib/runtime/v1.cjs +1 -1
- package/lib/runtime/v1.esm.js +1 -1
- package/package.json +1 -1
- package/src/build.ts +28 -1
- package/src/builders/colors.ts +34 -3
- package/src/builders/ladder.ts +116 -0
- package/src/config-schema-runtime.ts +1 -0
- package/src/config-schema.ts +5 -0
- package/src/ir.ts +23 -0
- package/src/renderers/css.ts +48 -0
- package/src/renderers/tailwind.ts +2 -2
- package/src/theme-factory.ts +5 -1
- package/src/token-meta.ts +9 -0
package/lib/cli.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var Tn=Object.defineProperty;var s=(e,n)=>Tn(e,"name",{value:n,configurable:!0}),Dn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,o)=>(typeof require<"u"?require:n)[o]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{readFile as Mo}from"node:fs/promises";import{resolve as ye}from"node:path";import{mkdir as Rn,mkdtemp as wo,readFile as yn,rename as vo,rm as bn,writeFile as kn}from"node:fs/promises";import{tmpdir as To}from"node:os";import{dirname as In,join as F}from"node:path";import{converter as zn,parse as qn}from"culori";import{defaultInputBorder as H}from"@apollion-dsi/core/themes/border";import{createReadableTextLayer as Cn}from"@apollion-dsi/core/themes/colors";import{createDeth as Vn,levelValues as On}from"@apollion-dsi/core/themes/depth";import{createFont as En,defaultInputFont as V}from"@apollion-dsi/core/themes/font";import{defaultInputSpacing as be}from"@apollion-dsi/core/themes/spacing";import{converter as An,formatHex as jn,parse as Gn}from"culori";import{DIMENSION_MULTIPLIERS as $n}from"@apollion-dsi/core/themes/dimension";function _({multiplier:e=.25,alias:n},o){let t=o!==void 0?$n[o]:e;return(...r)=>r.map(i=>{let a=typeof i=="string"?n[i]:i;return`${t*a}rem`}).join(" ")}s(_,"createSpacing");var te={"bg.primary":{description:"Primary action surface \u2014 the brand\u2019s dominant call-to-action background."},"bg.secondary":{description:"Secondary action surface \u2014 supporting actions paired with the primary."},"bg.danger":{description:"Destructive / error surface \u2014 irreversible or failing actions."},"bg.success":{description:"Positive confirmation surface \u2014 completed or healthy states."},"bg.info":{description:"Informational surface \u2014 neutral, non-blocking notices.",deprecated:"Use bg.information once the foundation role is renamed (tracked for S6)."},"text.on-primary":{description:"Text/icon colour with guaranteed contrast over bg.primary."},"text.on-danger":{description:"Text/icon colour with guaranteed contrast over bg.danger."},"space.medium":{description:"Base spacing step (1rem at normal density) \u2014 the layout rhythm unit."},"space.large":{description:"Comfortable spacing step \u2014 section padding and card gutters."},"spacing.md":{description:"Medium foundation spacing alias \u2014 references the space.medium primitive."},"spacing.lg":{description:"Large foundation spacing alias \u2014 references the space.large primitive."},"border.radius.md":{description:"Default card corner radius."},"border.width.thin":{description:"Hairline border \u2014 dividers and default input outlines."},"border.width.regular":{description:"Standard emphasis border \u2014 focused/active controls."}};function re(e){let n=Object.keys(te).filter(o=>!e.has(o));if(n.length>0)throw new Error(`token-meta: ${n.length} stale TOKEN_META key(s) resolve to no IR node: ${n.join(", ")}. Update src/token-meta.ts to match the current IR paths.`)}s(re,"assertTokenMetaResolves");var Mn=An("oklch");function h(e){return typeof e.type=="string"&&"value"in e}s(h,"isToken");function I(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(I,"kebab");function Re(e){return e.split(".").map(I).join(".")}s(Re,"kebabPath");function E(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(E,"rawValue");function B(e,n){return Number(e.toFixed(n))||0}s(B,"round");function se(e){let n=Mn(Gn(e));if(!n)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let o=[B(n.l,4),B(n.c,4),B(n.h??0,2)],t=jn(n)??"#000000";return n.alpha!==void 0&&n.alpha!==1?{kind:"color",raw:e,components:o,alpha:B(n.alpha,4),hex:t}:{kind:"color",raw:e,components:o,hex:t}}s(se,"toColorValue");var ke=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function O(e){let n=ke.exec(e.trim());if(n)return{kind:"dimension",raw:e,value:Number(n[1]),unit:n[2]};let o=Number.parseFloat(e);return{kind:"dimension",raw:e,value:Number.isFinite(o)?o:0,unit:"rem"}}s(O,"toDimensionValue");function k(e){return{type:"color",value:se(e)}}s(k,"colorToken");function ie(e){let n={};for(let[o,t]of Object.entries(e))n[o]=k(t);return n}s(ie,"recordColorGroup");function Ie(e){let n=Cn(e),o={};for(let[t,r]of Object.entries(n.palettes))o[t]=k(r);return o.neutral=ie(n.neutral),o}s(Ie,"buildReadableTextGroup");var Pn=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function xe(e){let n={};for(let o of Pn){let t=e[o];n[o]={base:k(t.base),dark:k(t.dark),action:k(t.action),active:k(t.active),light:k(t.light),onLight:k(t.onLight)}}return n.grayscale=ie(e.grayscale),n.neutral=ie(e.neutral),n.baseDark=k(e.baseDark??"#000000"),n.baseLight=k(e.baseLight??"#ffffff"),n.deepDark=k(e.deepDark??"#000000"),n.deepLight=k(e.deepLight??"#ffffff"),n}s(xe,"buildColorPrimitives");function Se(e){let n=_(be,e),o={};for(let t of Object.keys(be.alias))o[t]={type:"dimension",value:O(n(t))};return o}s(Se,"buildSpacePrimitives");function we(){let e={};for(let[n,o]of Object.entries(H.borderWidth))e[n]={type:"dimension",value:O(o)};return e}s(we,"buildBorderWidthPrimitives");function Nn(e,n){return{color:xe(e),space:Se(n),borderWidth:we()}}s(Nn,"buildPrimitives");var ve={primary:"color.primary.base",secondary:"color.secondary.base",tertiary:"color.tertiary.base",success:"color.success.base",danger:"color.danger.base",warning:"color.warning.base",info:"color.information.base"},Te={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function Fn(e,n){let o=e;for(let t of n.split(".").slice(1))if(o&&typeof o=="object"&&t in o)o=o[t];else return;return typeof o=="string"?o:void 0}s(Fn,"lookupPrimitive");function W(e,n,o){let t={};for(let[r,i]of Object.entries(e)){let a=o[r],c=a?Fn(n,a):void 0;t[r]=a&&c===i?{type:"color",value:{kind:"ref",path:a,resolved:se(i)}}:k(i)}return t}s(W,"colorRefGroup");var De={xs:"space.xs",sm:"space.small",md:"space.medium",lg:"space.large",xl:"space.xl",xxl:"space.xxl"},Ln={none:"border-width.none",thin:"border-width.thin",regular:"border-width.regular",great:"border-width.great",bold:"border-width.bold"};function _n(e,n){let o=n.split("."),t=o[0]==="border-width"?"borderWidth":o[0],r=e[t];for(let i of o.slice(1))if(r&&!h(r)&&i in r)r=r[i];else return;return r&&h(r)&&r.value.kind==="dimension"?r.value.raw:void 0}s(_n,"lookupDimensionPrimitive");function ae(e,n,o){let t={};for(let[r,i]of Object.entries(e)){let a=o[r],c=a?_n(n,a):void 0;t[r]=a&&c===i?{type:"dimension",value:{kind:"ref",path:a,resolved:O(i)}}:{type:"dimension",value:O(i)}}return t}s(ae,"dimensionRefGroup");function $e(e){let n={},o={};for(let[i,a]of Object.entries(H.borderRadius))ke.test(a)?n[i]={type:"dimension",value:O(a)}:o[i]=a;let t=ae(H.borderWidth,e,Ln),r={};for(let[i,a]of Object.entries(H.borderStyle))r[i]={type:"strokeStyle",value:{kind:"strokeStyle",raw:a,style:a}};return{group:{radius:n,width:t,style:r},extensions:o}}s($e,"buildBorder");function Ce(e){let n=En(V,e),o={};for(let[c,l]of Object.entries(V.fontFamily)){let p=l.replace(/;\s*$/,"").trim();o[c]={type:"fontFamily",value:{kind:"fontFamily",raw:p,family:p}}}let t={};for(let[c,l]of Object.entries(n.fontSize))t[c]={type:"dimension",value:O(l)};let r={};for(let[c,l]of Object.entries(V.fontWeight))r[c]={type:"fontWeight",value:{kind:"fontWeight",raw:`${l}`,weight:l}};let i={};for(let[c,l]of Object.entries(V.lineHeight))i[c]={type:"number",value:{kind:"number",raw:`${l}`,number:l}};let a={letterSpacing:V.letterSpacing,textTransform:V.textTransform,fontStyle:V.fontStyle};return{group:{family:o,size:t,weight:r,lineHeight:i},extensions:a}}s(Ce,"buildFont");var Bn=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function Hn(e){let n=e.trim(),o=n.startsWith("inset");o&&(n=n.slice(5).trim());let t=n.match(Bn),r=t?t[0]:"#000000",a=(t?n.slice(0,t.index).trim():n).split(/\s+/).filter(Boolean),c=s(l=>O(a[l]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:se(r),offsetX:c(0),offsetY:c(1),blur:c(2),spread:c(3),inset:o}}}s(Hn,"parseShadow");function Ve(e){let n=Vn(e),o={};for(let t of Object.keys(On))o[t]={type:"shadow",value:Hn(n(t))};return o}s(Ve,"buildShadow");function J(e,n,o){let t={};for(let[r,i]of Object.entries(e)){let a=n?`${n}.${I(r)}`:I(r);if(h(i)){o.add(a);let c=te[a];t[r]=c&&(c.description!==void 0||c.deprecated!==void 0)?{...i,...c.description!==void 0?{description:c.description}:{},...c.deprecated!==void 0?{deprecated:c.deprecated}:{}}:i}else t[r]=J(i,a,o)}return t}s(J,"decorateGroup");function Wn(e){let n=new Set,o=J(e.primitives,"",n),t=J(e.groups,"",n);return re(n),{...e,primitives:o,groups:t}}s(Wn,"decorateMeta");function z(e,n){return J(e,"",n)}s(z,"decorateSlice");function Oe(e,n,o){for(let[t,r]of Object.entries(e)){let i=n?`${n}.${I(t)}`:I(t);h(r)?o.add(i):Oe(r,i,o)}}s(Oe,"collectPaths");function Ee(e){let n=new Set;for(let o of e)Oe(o.groups,"",n);re(n)}s(Ee,"assertSlicesMetaComplete");function Ae(){let e=we(),o=$e({borderWidth:e}),t={};Object.keys(o.extensions).length>0&&(t["com.apollion.border"]={radius:o.extensions});let r=new Set;return{groups:z({"border-width":e,border:o.group},r),extensions:t}}s(Ae,"buildBaseIR");function je(e){let n=Ce(e),o=new Set;return{groups:z({font:n.group},o),extensions:{"com.apollion.font":n.extensions}}}s(je,"buildFontIR");function Ge(e,n){let o=xe(n),t=new Set;return{groups:z({color:o,bg:W(e.bg,n,ve),text:W(e.text,n,Te),tx:Ie(n),shadow:Ve(n)},t),extensions:{}}}s(Ge,"buildColorIR");function Me(e,n){let o=Se(n),t={space:o},r=new Set;return{groups:z({space:o,spacing:ae(e.spacing,t,De)},r),extensions:{}}}s(Me,"buildSpacingIR");function Jn(e,n,o){let t={brand:o.brand,mode:o.mode,surface:o.surface,dimension:o.dimension},r=Nn(n,o.dimension),i=$e(r),a=Ce(o.dimension),c={"com.apollion.variant":t,"com.apollion.font":a.extensions};Object.keys(i.extensions).length>0&&(c["com.apollion.border"]={radius:i.extensions});let l={description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${t.brand}/${t.mode}/${t.surface}/${t.dimension}.`,meta:t,primitives:r,groups:{bg:W(e.bg,n,ve),text:W(e.text,n,Te),tx:Ie(n),spacing:ae(e.spacing,r,De),border:i.group,font:a.group,shadow:Ve(n)},extensions:c};return Wn(l)}s(Jn,"buildIR");var q=Jn;var Un=zn("rgb"),Pe="// Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs.";function ce(e){if(e.value.kind==="color")return e.value;if(e.value.kind==="ref"&&e.value.resolved.kind==="color")return e.value.resolved}s(ce,"colorPayload");function le(e){return e.alpha===void 0}s(le,"isOpaqueColor");function Ne(e){let n=Un(qn(e.hex));if(!n)return"0 0 0";let o=s(t=>Math.min(255,Math.max(0,Math.round(t*255))),"channel");return`${o(n.r)} ${o(n.g)} ${o(n.b)}`}s(Ne,"rgbTriplet");function U(e,n=[]){let o=new Map;for(let[t,r]of Object.entries(e)){let i=[...n,I(t)];if(h(r))o.set(i.join("-"),r);else for(let[a,c]of U(r,i))o.set(a,c)}return o}s(U,"flatTokens");function y(e,...n){let o=e[n[0]];for(let t of n.slice(1)){if(!o||h(o))return{};o=o[t]}return o&&!h(o)?o:{}}s(y,"groupAt");function Fe(e){let n=[];for(let o of["bg","text","tx"])for(let[t,r]of U(y(e.groups,o),[o])){let i=ce(r);i&&n.push({key:t,cssVar:`--apollion-${t}`,opaque:le(i)})}return n}s(Fe,"colorEntries");function D(e,n){return[...U(e)].map(([o])=>[o,`var(--apollion-${[...n,o].join("-")})`])}s(D,"varEntries");function $(e,n,o){if(o.length!==0){e.push(` ${n}: {`);for(let[t,r]of o)e.push(` ${JSON.stringify(t)}: ${JSON.stringify(r)},`);e.push(" },")}}s($,"pushScale");function Le(e){let n=[Pe,"// Tailwind preset over the Apollion foundation tokens \u2014 requires dist/css/ vars in scope.","","const preset = {"," theme: {"," extend: {"],o=Fe(e);n.push(" colors: {");for(let{key:t,cssVar:r,opaque:i}of o)i?n.push(` ${JSON.stringify(t)}: ${JSON.stringify(`rgb(var(${r}-rgb) / <alpha-value>)`)},`):(n.push(` // ${t} carries its own alpha \u2014 excluded from the <alpha-value> modifier form.`),n.push(` ${JSON.stringify(t)}: ${JSON.stringify(`var(${r})`)},`));return n.push(" },"),$(n,"spacing",D(y(e.groups,"spacing"),["spacing"])),$(n,"borderRadius",D(y(e.groups,"border","radius"),["border","radius"])),$(n,"borderWidth",D(y(e.groups,"border","width"),["border","width"])),$(n,"fontFamily",D(y(e.groups,"font","family"),["font","family"])),$(n,"fontSize",D(y(e.groups,"font","size"),["font","size"])),$(n,"fontWeight",D(y(e.groups,"font","weight"),["font","weight"])),$(n,"lineHeight",D(y(e.groups,"font","lineHeight"),["font","line-height"])),$(n,"boxShadow",D(y(e.groups,"shadow"),["shadow"])),n.push(" },"," },","};","","export default preset;",""),n.join(`
|
|
3
|
-
`)}s(
|
|
4
|
-
`)}s(
|
|
5
|
-
`)}s(
|
|
2
|
+
var Wn=Object.defineProperty;var s=(e,n)=>Wn(e,"name",{value:n,configurable:!0}),Jn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,o)=>(typeof require<"u"?require:n)[o]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{readFile as sr}from"node:fs/promises";import{resolve as Le}from"node:path";import{mkdir as jn,mkdtemp as Uo,readFile as En,rename as Ko,rm as Gn,writeFile as Pn}from"node:fs/promises";import{tmpdir as Xo}from"node:os";import{dirname as Nn,join as z}from"node:path";import{converter as uo,parse as po}from"culori";import{defaultInputBorder as X}from"@apollion-dsi/core/themes/border";import{createReadableTextLayer as qn}from"@apollion-dsi/core/themes/colors";import{createDeth as Un,levelValues as Kn}from"@apollion-dsi/core/themes/depth";import{createFont as Xn,defaultInputFont as M}from"@apollion-dsi/core/themes/font";import{defaultInputSpacing as Me}from"@apollion-dsi/core/themes/spacing";import{converter as Yn,formatHex as Zn,parse as Qn}from"culori";import{DIMENSION_MULTIPLIERS as zn}from"@apollion-dsi/core/themes/dimension";function U({multiplier:e=.25,alias:n},o){let r=o!==void 0?zn[o]:e;return(...t)=>t.map(i=>{let a=typeof i=="string"?n[i]:i;return`${r*a}rem`}).join(" ")}s(U,"createSpacing");var fe={"bg.primary":{description:"Primary action surface \u2014 the brand\u2019s dominant call-to-action background."},"bg.secondary":{description:"Secondary action surface \u2014 supporting actions paired with the primary."},"bg.danger":{description:"Destructive / error surface \u2014 irreversible or failing actions."},"bg.success":{description:"Positive confirmation surface \u2014 completed or healthy states."},"bg.info":{description:"Informational surface \u2014 neutral, non-blocking notices.",deprecated:"Use bg.information once the foundation role is renamed (tracked for S6)."},"bg.canvas":{description:"Page ground \u2014 the theme canvas (never pure black in dark)."},"bg.paper":{description:"Component ground (cards, inputs, tables) \u2014 lighter than the canvas in both modes."},"bg.overlay":{description:"Top of the elevation ladder \u2014 modal / dialog panels."},"text.primary":{description:"Primary neutral ink \u2014 AA + APCA Lc \u2265 75 over bg.paper and bg.canvas."},"text.muted":{description:"Muted neutral ink \u2014 AA + APCA Lc \u2265 45 over bg.paper."},"edge.border":{description:"Default control outline \u2014 primary ink at 20 % alpha, legible on any ground."},"edge.hairline":{description:"Dividers and card outlines \u2014 primary ink at 10 % alpha."},"text.on-primary":{description:"Text/icon colour with guaranteed contrast over bg.primary."},"text.on-danger":{description:"Text/icon colour with guaranteed contrast over bg.danger."},"space.medium":{description:"Base spacing step (1rem at normal density) \u2014 the layout rhythm unit."},"space.large":{description:"Comfortable spacing step \u2014 section padding and card gutters."},"spacing.md":{description:"Medium foundation spacing alias \u2014 references the space.medium primitive."},"spacing.lg":{description:"Large foundation spacing alias \u2014 references the space.large primitive."},"border.radius.md":{description:"Default card corner radius."},"border.width.thin":{description:"Hairline border \u2014 dividers and default input outlines."},"border.width.regular":{description:"Standard emphasis border \u2014 focused/active controls."}};function ge(e){let n=Object.keys(fe).filter(o=>!e.has(o));if(n.length>0)throw new Error(`token-meta: ${n.length} stale TOKEN_META key(s) resolve to no IR node: ${n.join(", ")}. Update src/token-meta.ts to match the current IR paths.`)}s(ge,"assertTokenMetaResolves");var eo=Yn("oklch");function y(e){return typeof e.type=="string"&&"value"in e}s(y,"isToken");function x(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(x,"kebab");function Oe(e){return e.split(".").map(x).join(".")}s(Oe,"kebabPath");function G(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(G,"rawValue");function K(e,n){return Number(e.toFixed(n))||0}s(K,"round");function me(e){let n=eo(Qn(e));if(!n)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let o=[K(n.l,4),K(n.c,4),K(n.h??0,2)],r=Zn(n)??"#000000";return n.alpha!==void 0&&n.alpha!==1?{kind:"color",raw:e,components:o,alpha:K(n.alpha,4),hex:r}:{kind:"color",raw:e,components:o,hex:r}}s(me,"toColorValue");var Ee=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function E(e){let n=Ee.exec(e.trim());if(n)return{kind:"dimension",raw:e,value:Number(n[1]),unit:n[2]};let o=Number.parseFloat(e);return{kind:"dimension",raw:e,value:Number.isFinite(o)?o:0,unit:"rem"}}s(E,"toDimensionValue");function I(e){return{type:"color",value:me(e)}}s(I,"colorToken");function O(e){let n={};for(let[o,r]of Object.entries(e))n[o]=I(r);return n}s(O,"recordColorGroup");function Ge(e){let n=qn(e),o={};for(let[r,t]of Object.entries(n.palettes))o[r]=I(t);return o.neutral=O(n.neutral),o}s(Ge,"buildReadableTextGroup");var no=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function je(e){let n={};for(let o of no){let r=e[o];n[o]={base:I(r.base),dark:I(r.dark),action:I(r.action),active:I(r.active),light:I(r.light),onLight:I(r.onLight)}}return n.grayscale=O(e.grayscale),n.neutral=O(e.neutral),n.surface=O(e.surface),n.ink=O(e.ink),n.edge=O(e.edge),n.wash=O(e.wash),n.baseDark=I(e.baseDark??"#000000"),n.baseLight=I(e.baseLight??"#ffffff"),n.deepDark=I(e.deepDark??"#000000"),n.deepLight=I(e.deepLight??"#ffffff"),n}s(je,"buildColorPrimitives");function Pe(e){let n=U(Me,e),o={};for(let r of Object.keys(Me.alias))o[r]={type:"dimension",value:E(n(r))};return o}s(Pe,"buildSpacePrimitives");function Ne(){let e={};for(let[n,o]of Object.entries(X.borderWidth))e[n]={type:"dimension",value:E(o)};return e}s(Ne,"buildBorderWidthPrimitives");function oo(e,n){return{color:je(e),space:Pe(n),borderWidth:Ne()}}s(oo,"buildPrimitives");var Fe={primary:"color.primary.base",secondary:"color.secondary.base",tertiary:"color.tertiary.base",success:"color.success.base",danger:"color.danger.base",warning:"color.warning.base",info:"color.information.base",canvas:"color.surface.canvas",sunken:"color.surface.sunken",paper:"color.surface.paper",raised:"color.surface.raised",overlay:"color.surface.overlay"},_e={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight",primary:"color.ink.primary",secondary:"color.ink.secondary",muted:"color.ink.muted",disabled:"color.ink.disabled"},Be={hairline:"color.edge.hairline",border:"color.edge.border",strong:"color.edge.strong"};function ro(e,n){let o=e;for(let r of n.split(".").slice(1))if(o&&typeof o=="object"&&r in o)o=o[r];else return;return typeof o=="string"?o:void 0}s(ro,"lookupPrimitive");function F(e,n,o){let r={};for(let[t,i]of Object.entries(e)){let a=o[t],c=a?ro(n,a):void 0;r[t]=a&&c===i?{type:"color",value:{kind:"ref",path:a,resolved:me(i)}}:I(i)}return r}s(F,"colorRefGroup");var He={xs:"space.xs",sm:"space.small",md:"space.medium",lg:"space.large",xl:"space.xl",xxl:"space.xxl"},to={none:"border-width.none",thin:"border-width.thin",regular:"border-width.regular",great:"border-width.great",bold:"border-width.bold"};function io(e,n){let o=n.split("."),r=o[0]==="border-width"?"borderWidth":o[0],t=e[r];for(let i of o.slice(1))if(t&&!y(t)&&i in t)t=t[i];else return;return t&&y(t)&&t.value.kind==="dimension"?t.value.raw:void 0}s(io,"lookupDimensionPrimitive");function he(e,n,o){let r={};for(let[t,i]of Object.entries(e)){let a=o[t],c=a?io(n,a):void 0;r[t]=a&&c===i?{type:"dimension",value:{kind:"ref",path:a,resolved:E(i)}}:{type:"dimension",value:E(i)}}return r}s(he,"dimensionRefGroup");function We(e){let n={},o={};for(let[i,a]of Object.entries(X.borderRadius))Ee.test(a)?n[i]={type:"dimension",value:E(a)}:o[i]=a;let r=he(X.borderWidth,e,to),t={};for(let[i,a]of Object.entries(X.borderStyle))t[i]={type:"strokeStyle",value:{kind:"strokeStyle",raw:a,style:a}};return{group:{radius:n,width:r,style:t},extensions:o}}s(We,"buildBorder");function Je(e){let n=Xn(M,e),o={};for(let[c,l]of Object.entries(M.fontFamily)){let f=l.replace(/;\s*$/,"").trim();o[c]={type:"fontFamily",value:{kind:"fontFamily",raw:f,family:f}}}let r={};for(let[c,l]of Object.entries(n.fontSize))r[c]={type:"dimension",value:E(l)};let t={};for(let[c,l]of Object.entries(M.fontWeight))t[c]={type:"fontWeight",value:{kind:"fontWeight",raw:`${l}`,weight:l}};let i={};for(let[c,l]of Object.entries(M.lineHeight))i[c]={type:"number",value:{kind:"number",raw:`${l}`,number:l}};let a={letterSpacing:M.letterSpacing,textTransform:M.textTransform,fontStyle:M.fontStyle};return{group:{family:o,size:r,weight:t,lineHeight:i},extensions:a}}s(Je,"buildFont");var so=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function ao(e){let n=e.trim(),o=n.startsWith("inset");o&&(n=n.slice(5).trim());let r=n.match(so),t=r?r[0]:"#000000",a=(r?n.slice(0,r.index).trim():n).split(/\s+/).filter(Boolean),c=s(l=>E(a[l]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:me(t),offsetX:c(0),offsetY:c(1),blur:c(2),spread:c(3),inset:o}}}s(ao,"parseShadow");function ze(e){let n=Un(e),o={};for(let r of Object.keys(Kn))o[r]={type:"shadow",value:ao(n(r))};return o}s(ze,"buildShadow");function Y(e,n,o){let r={};for(let[t,i]of Object.entries(e)){let a=n?`${n}.${x(t)}`:x(t);if(y(i)){o.add(a);let c=fe[a];r[t]=c&&(c.description!==void 0||c.deprecated!==void 0)?{...i,...c.description!==void 0?{description:c.description}:{},...c.deprecated!==void 0?{deprecated:c.deprecated}:{}}:i}else r[t]=Y(i,a,o)}return r}s(Y,"decorateGroup");function co(e){let n=new Set,o=Y(e.primitives,"",n),r=Y(e.groups,"",n);return ge(n),{...e,primitives:o,groups:r}}s(co,"decorateMeta");function Z(e,n){return Y(e,"",n)}s(Z,"decorateSlice");function qe(e,n,o){for(let[r,t]of Object.entries(e)){let i=n?`${n}.${x(r)}`:x(r);y(t)?o.add(i):qe(t,i,o)}}s(qe,"collectPaths");function Ue(e){let n=new Set;for(let o of e)qe(o.groups,"",n);ge(n)}s(Ue,"assertSlicesMetaComplete");function Ke(){let e=Ne(),o=We({borderWidth:e}),r={};Object.keys(o.extensions).length>0&&(r["com.apollion.border"]={radius:o.extensions});let t=new Set;return{groups:Z({"border-width":e,border:o.group},t),extensions:r}}s(Ke,"buildBaseIR");function Xe(e){let n=Je(e),o=new Set;return{groups:Z({font:n.group},o),extensions:{"com.apollion.font":n.extensions}}}s(Xe,"buildFontIR");function Ye(e,n){let o=je(n),r=new Set;return{groups:Z({color:o,bg:F(e.bg,n,Fe),text:F(e.text,n,_e),edge:F(e.edge,n,Be),tx:Ge(n),shadow:ze(n)},r),extensions:{}}}s(Ye,"buildColorIR");function Ze(e,n){let o=Pe(n),r={space:o},t=new Set;return{groups:Z({space:o,spacing:he(e.spacing,r,He)},t),extensions:{}}}s(Ze,"buildSpacingIR");function lo(e,n,o){let r={brand:o.brand,mode:o.mode,surface:o.surface,dimension:o.dimension},t=oo(n,o.dimension),i=We(t),a=Je(o.dimension),c={"com.apollion.variant":r,"com.apollion.font":a.extensions};Object.keys(i.extensions).length>0&&(c["com.apollion.border"]={radius:i.extensions});let l={description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${r.brand}/${r.mode}/${r.surface}/${r.dimension}.`,meta:r,primitives:t,groups:{bg:F(e.bg,n,Fe),text:F(e.text,n,_e),edge:F(e.edge,n,Be),tx:Ge(n),spacing:he(e.spacing,t,He),border:i.group,font:a.group,shadow:ze(n)},extensions:c};return co(l)}s(lo,"buildIR");var _=lo;var fo=uo("rgb"),Qe="// Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs.";function ye(e){if(e.value.kind==="color")return e.value;if(e.value.kind==="ref"&&e.value.resolved.kind==="color")return e.value.resolved}s(ye,"colorPayload");function be(e){return e.alpha===void 0}s(be,"isOpaqueColor");function en(e){let n=fo(po(e.hex));if(!n)return"0 0 0";let o=s(r=>Math.min(255,Math.max(0,Math.round(r*255))),"channel");return`${o(n.r)} ${o(n.g)} ${o(n.b)}`}s(en,"rgbTriplet");function Q(e,n=[]){let o=new Map;for(let[r,t]of Object.entries(e)){let i=[...n,x(r)];if(y(t))o.set(i.join("-"),t);else for(let[a,c]of Q(t,i))o.set(a,c)}return o}s(Q,"flatTokens");function k(e,...n){let o=e[n[0]];for(let r of n.slice(1)){if(!o||y(o))return{};o=o[r]}return o&&!y(o)?o:{}}s(k,"groupAt");function nn(e){let n=[];for(let o of["bg","text","edge","tx"])for(let[r,t]of Q(k(e.groups,o),[o])){let i=ye(t);i&&n.push({key:r,cssVar:`--apollion-${r}`,opaque:be(i)})}return n}s(nn,"colorEntries");function C(e,n){return[...Q(e)].map(([o])=>[o,`var(--apollion-${[...n,o].join("-")})`])}s(C,"varEntries");function A(e,n,o){if(o.length!==0){e.push(` ${n}: {`);for(let[r,t]of o)e.push(` ${JSON.stringify(r)}: ${JSON.stringify(t)},`);e.push(" },")}}s(A,"pushScale");function on(e){let n=[Qe,"// Tailwind preset over the Apollion foundation tokens \u2014 requires dist/css/ vars in scope.","","const preset = {"," theme: {"," extend: {"],o=nn(e);n.push(" colors: {");for(let{key:r,cssVar:t,opaque:i}of o)i?n.push(` ${JSON.stringify(r)}: ${JSON.stringify(`rgb(var(${t}-rgb) / <alpha-value>)`)},`):(n.push(` // ${r} carries its own alpha \u2014 excluded from the <alpha-value> modifier form.`),n.push(` ${JSON.stringify(r)}: ${JSON.stringify(`var(${t})`)},`));return n.push(" },"),A(n,"spacing",C(k(e.groups,"spacing"),["spacing"])),A(n,"borderRadius",C(k(e.groups,"border","radius"),["border","radius"])),A(n,"borderWidth",C(k(e.groups,"border","width"),["border","width"])),A(n,"fontFamily",C(k(e.groups,"font","family"),["font","family"])),A(n,"fontSize",C(k(e.groups,"font","size"),["font","size"])),A(n,"fontWeight",C(k(e.groups,"font","weight"),["font","weight"])),A(n,"lineHeight",C(k(e.groups,"font","lineHeight"),["font","line-height"])),A(n,"boxShadow",C(k(e.groups,"shadow"),["shadow"])),n.push(" },"," },","};","","export default preset;",""),n.join(`
|
|
3
|
+
`)}s(on,"renderTailwindPreset");function rn(e){let n=s(t=>[...Q(t).keys()],"keys"),o=s(t=>`[${t.map(i=>JSON.stringify(i)).join(", ")}]`,"list");return[Qe,"// tailwind-merge extension for the generated preset \u2014 pass to extendTailwindMerge().","","export const twMergeExtension = {"," extend: {"," theme: {",` colors: ${o(nn(e).map(t=>t.key))},`,` spacing: ${o(n(k(e.groups,"spacing")))},`,` borderRadius: ${o(n(k(e.groups,"border","radius")))},`,` borderWidth: ${o(n(k(e.groups,"border","width")))},`," },"," classGroups: {",` 'font-family': [{ font: ${o(n(k(e.groups,"font","family")))} }],`,` 'font-size': [{ text: ${o(n(k(e.groups,"font","size")))} }],`,` 'font-weight': [{ font: ${o(n(k(e.groups,"font","weight")))} }],`,` leading: [{ leading: ${o(n(k(e.groups,"font","lineHeight")))} }],`,` shadow: [{ shadow: ${o(n(k(e.groups,"shadow")))} }],`," },"," },","};",""].join(`
|
|
4
|
+
`)}s(rn,"renderTwMergeExtension");var tn="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function ee(e,n,o){for(let[r,t]of Object.entries(e)){let i=[...n,x(r)];y(t)?o.push(` --apollion-${i.join("-")}: ${G(t.value)};`):ee(t,i,o)}}s(ee,"emitVars");function ne(e,n,o){for(let[r,t]of Object.entries(e)){let i=[...n,x(r)];if(!y(t)){ne(t,i,o);continue}let a=ye(t);a&&be(a)&&o.push(` --apollion-${i.join("-")}-rgb: ${en(a)};`)}}s(ne,"emitRgbVars");function Re(e,n,o){for(let[r,t]of Object.entries(e)){let i=[...n,x(r)];y(t)?t.type==="color"&&o.push(` @property --apollion-${i.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${G(t.value)}; }`):Re(t,i,o)}}s(Re,"emitProperties");function sn(e,n={}){let{brand:o,mode:r,surface:t,dimension:i}=e.meta,a=[tn,""];return a.push(`/* Variant: brand=${o} mode=${r} surface=${t} dimension=${i} */`,"",":root {"),ee(e.groups,[],a),n.rgbCompanions&&(a.push(""," /* -rgb channel triplets \u2014 Tailwind <alpha-value> companions (opaque colour tokens only). */"),ne(e.groups,[],a)),a.push("}",""),a.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),Re(e.groups,[],a),a.push("}",""),a.join(`
|
|
5
|
+
`)}s(sn,"renderCss");function an(e,n,o={}){let{attribute:r="data-apollion-mode",rgbCompanions:t}=o,{brand:i,surface:a,dimension:c}=e.meta,l=[tn,""],f=s((w,d,u)=>{l.push(`${w} {`,` color-scheme: ${u};`),ee(d.groups,[],l),t&&ne(d.groups,[],l),l.push("}","")},"block");l.push(`/* Variant: brand=${i} surface=${a} dimension=${c} modes=light+dark (attribute ${r}) */`,""),f(`:root, html[${r}="light"]`,e,"light"),f(`html[${r}="dark"]`,n,"dark"),l.push("@media (prefers-color-scheme: dark) {"),l.push(` html:not([${r}]) {`," color-scheme: dark;");let b=[];ee(n.groups,[],b),t&&ne(n.groups,[],b);for(let w of b)l.push(` ${w}`);return l.push(" }","}",""),l.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),Re(e.groups,[],l),l.push("}",""),l.join(`
|
|
6
|
+
`)}s(an,"renderCssModes");var go="<!-- Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. -->";function ke(e,n,o){for(let[r,t]of Object.entries(e)){let i=n?`${n}.${r}`:r;y(t)?o.push([i,G(t.value)]):ke(t,i,o)}}s(ke,"flatten");function mo(e){return typeof e=="number"?String(e):`'${String(e).replace(/'/g,"''")}'`}s(mo,"yamlEscape");function ho(e){let{mode:n,surface:o,dimension:r}=e.meta;return`${n}.${o}.${r}`}s(ho,"variantKey");function cn(e,n){if(n.length===0)throw new Error(`renderDesignMd: no variants for brand "${e}"`);let o=["---",`brand: '${e}'`,"generator: apollion-tokens","variants:"];for(let t of n){let i=[];ke(t.groups,"",i),o.push(` ${ho(t)}:`);for(let[a,c]of i)o.push(` ${a}: ${mo(c)}`)}o.push("---");let r=["",go,"",`# Design.md \u2014 ${e}`,"","Resolved design-token values for this brand, one section per variant.","Consumption rules (which token to reach for, layer boundaries) live in the","package `llms.txt`; this file carries the values those rules reference.","Regenerate with `apollion-tokens build` \u2014 never edit.",""];for(let t of n){let{mode:i,surface:a,dimension:c}=t.meta;r.push(`## Variant \`${i} \xB7 ${a} \xB7 ${c}\``,"");let l=[];ke(t.groups,"",l);let f=new Map;for(let[b,w]of l){let d=b.split(".")[0]??b,u=f.get(d)??[];u.push([b,w]),f.set(d,u)}for(let[b,w]of f){r.push(`### ${b}`,"","| Token | Value |","| --- | --- |");for(let[d,u]of w)r.push(`| \`${d}\` | \`${u}\` |`);r.push("")}}return`${o.join(`
|
|
6
7
|
`)}
|
|
7
|
-
${
|
|
8
|
-
`)}`}s(
|
|
9
|
-
`}s(
|
|
10
|
-
`}s(
|
|
11
|
-
`)}s(
|
|
12
|
-
`}s(rn,"serializeManifest");var co="json/sets",sn="json/resolver.json";function Z(e){return`${co}/${e}.json`}s(Z,"setFile");function lo(e,n,o){return`${e}.color.${n}.${o}`}s(lo,"colorSetName");function uo(e){return`spacing.${e}`}s(uo,"spacingSetName");function po(e){return`font.${e}`}s(po,"fontSetName");function Q(e,n){e.includes(n)||e.push(n)}s(Q,"pushUnique");function an(e){let n=Y(e),o=[],t=[],r=[],i=[],a=new Set,c=[],l=new Set,p=[],R=new Set,T=[];for(let u of n){Q(o,u.brand),Q(t,u.mode),Q(r,u.surface),Q(i,u.dimension);let m=lo(u.brand,u.mode,u.surface);a.has(m)||(a.add(m),c.push({kind:"color",name:m,file:Z(m),brand:u.brand,mode:u.mode,surface:u.surface}));let x=uo(u.dimension);l.has(x)||(l.add(x),p.push({kind:"spacing",name:x,file:Z(x),dimension:u.dimension}));let f=po(u.dimension);R.has(f)||(R.add(f),T.push({kind:"font",name:f,file:Z(f),dimension:u.dimension}))}return{base:{kind:"base",name:"base",file:Z("base")},spacing:p,font:T,color:c,modifiers:{brand:o,mode:t,surface:r,dimension:i}}}s(an,"planSets");import{toDarkColors as Ro}from"@apollion-dsi/core/themes/colors";import{createFoundation as hn}from"@apollion-dsi/core/themes/foundation";import{createSemantic as ko}from"@apollion-dsi/core/themes/semantic";import{defaultInputSpacing as Io}from"@apollion-dsi/core/themes/spacing";import{invertForSurface as xo}from"@apollion-dsi/core/themes/surface";import{converter as fo,formatHex as N,interpolate as mo,parse as v,wcagContrast as fn}from"culori";var ge=fo("oklch");function d(e,n,o){let t=v(e),r=v(n);if(!t||!r)return e;let i=mo([t,r],"oklch");return N(i(o))??e}s(d,"mixOklch");function go(e){return e?typeof e=="string"?e:e.base:"#000"}s(go,"coerceToHex");var ee=1.3,ho=.05,cn=.04,C=s((e,n)=>{let o=v(e),t=v(n);return!o||!t?1:fn(o,t)},"contrastRatio"),me=s(e=>{let n=ge(v(e));return n?n.l??0:null},"oklchLightness"),yo=4.5;function ln(e,n,o=yo){let t=v(n),r=ge(v(e));if(!t||!r)return e;let i=C("#fff",n)>=C("#000",n)?.04:-.04;for(let a=0;a<25;a+=1){let c=N(r)??e,l=v(c);if(l&&fn(l,t)>=o)return c;let p=Math.min(1,Math.max(0,(r.l??0)+i));if(p===(r.l??0))break;r={...r,l:p}}return N(r)??e}s(ln,"readableColor");var un=s((e,n)=>{if(C(e,n)>=ee)return!0;let o=me(e),t=me(n);return o!==null&&t!==null&&Math.abs(o-t)>=ho},"isPerceptibleState"),bo=s(e=>e?C("#fff",e)>C("#000",e):!1,"isDarkSurface");function dn(e,n,o){let t=ge(v(e));if(!t)return null;let r={...t,l:o??t.l??0},i=n?cn:-cn;for(let a=0;a<25;a+=1){let c=Math.min(1,Math.max(0,(r.l??0)+i));if(c===(r.l??0))break;r={...r,l:c};let l=N(r);if(l&&C(e,l)>=ee)return l}return N(r)??null}s(dn,"derivePerceptibleState");function pn(e,n,o){let t=dn(e,n,o);if(t&&C(e,t)>=ee)return t;let r=dn(e,!n);return r&&C(e,r)>=ee?r:t??r}s(pn,"perceptibleStateFor");function w(e,n){let o=typeof e=="object"&&e!==null?e:void 0,t=go(e),r=n.deepDark,i=n.deepLight,a={base:t,dark:d(t,r,.6),action:d(t,r,.2),active:d(t,i,.6),light:d(t,i,.9),onLight:t};if(v(t)){let c=bo(n.baseLight),l=un(t,a.action);if(l||(a.action=pn(t,c)??a.action),!un(t,a.active)){let p=l?void 0:me(a.action)??void 0;a.active=pn(t,c,p)??a.active}}if(a.onLight=ln(a.action,a.light),o){let c=o.action??a.action,l=o.light??a.light;return{base:t,dark:o.dark??a.dark,action:c,active:o.active??a.active,light:l,onLight:o.onLight??ln(c,l)}}return a}s(w,"mountSingleColor");function mn(e){let n=e.deepLight,o=e.deepDark;return{0:n,5:d(n,o,.05),10:d(n,o,.1),20:d(n,o,.2),30:d(n,o,.3),40:d(n,o,.4),50:d(n,o,.5),60:d(n,o,.6),70:d(n,o,.7),80:d(n,o,.8),90:d(n,o,.9),100:d(n,o,1)}}s(mn,"mountGreyscaleColors");function gn(e){let n=e.deepLight,o=e.deepDark,t=typeof e.primary=="object"&&e.primary?e.primary.base:e.primary,r=s(a=>1/17*(a-1),"interpolation"),i=d(t,o,.5);return{0:d(i,n,r(18)),5:d(i,n,r(17.5)),10:d(i,n,r(17)),20:d(i,n,r(16)),30:d(i,n,r(15)),40:d(i,n,r(14)),50:d(i,n,r(13)),60:d(i,n,r(12)),70:d(i,n,r(11)),80:d(i,n,r(10)),90:d(i,n,r(9)),100:d(i,n,r(8)),110:d(i,n,r(7)),120:d(i,n,r(6)),130:d(i,n,r(5)),140:d(i,n,r(4)),150:d(i,n,r(3)),160:d(i,n,r(2)),170:i,180:d(i,o,.25)}}s(gn,"mountNeutralColors");function So(e){return{baseDark:e.baseDark,baseLight:e.baseLight,deepDark:e.deepDark,deepLight:e.deepLight,transparent:e.transparent??"transparent",neutral:gn(e),grayscale:mn(e),main:w(e.main,e),opposite:w(e.opposite,e),complementary:w(e.complementary,e),danger:w(e.danger,e),information:w(e.information,e),success:w(e.success,e),warning:w(e.warning,e),primary:w(e.primary,e),secondary:w(e.secondary,e),tertiary:w(e.tertiary,e)}}s(So,"composeColors");function G(e,n=Io){let o=e.mode==="dark"?Ro(e.colors):e.colors,t=So(o),r=_(n,e.dimension),i=ko({colors:t,spacing:r}),a=hn(i);return e.surface==="negative"&&(a=hn(xo({semantic:i,colors:t},"negative").semantic)),{foundation:a,colors:t}}s(G,"buildVariantThemes");async function xn(e){let{config:n,outDir:o,cwd:t=process.cwd(),verbose:r=!1}=e,i=Y(n),a=n.output??{};if(i.length===0)throw new Error("apollion-tokens build: no variants (config.brands is empty)");let c=await wo(F(To(),"apollion-tokens-"));try{let l=[],p=s(async(u,m)=>{await Do(c,u,m),l.push({path:u,sha256:K(m)}),r&&console.log(` \u2713 ${u}`)},"emit");if(a.json){let u=an(n),m=[],x=Ae();m.push(x),await p(u.base.file,Ue(x));for(let f of u.spacing){let b=i.find(L=>L.dimension===f.dimension),{foundation:M}=G(b),j=Me(M,f.dimension);m.push(j),await p(f.file,Ye(j,f.dimension))}for(let f of u.font){let b=je(f.dimension);m.push(b),await p(f.file,Ke(b,f.dimension))}for(let f of u.color){let b=i.find(oe=>oe.brand===f.brand&&oe.mode===f.mode&&oe.surface===f.surface),{foundation:M,colors:j}=G(b),L=Ge(M,j);m.push(L),await p(f.file,Xe(L,f.brand,f.mode,f.surface))}Ee(m),await p(sn,Ze(n,u))}if(a.css||a.ts)for(let u of i){let{foundation:m,colors:x}=G(u),f=q(m,x,u),b=nn(u);a.css&&await p(`css/${b}.css`,Je(f,{rgbCompanions:a.tailwind})),a.ts&&await p(`ts/${b}.d.ts`,en(f))}if(a.tailwind){let u=i[0],{foundation:m,colors:x}=G(u),f=q(m,x,u);await p("tailwind/preset.mjs",Le(f)),await p("tailwind/tw-merge.mjs",_e(f))}if(a.designMd){let u=[...new Set(i.map(m=>m.brand))];for(let m of u){let f=i.filter(b=>b.brand===m).map(b=>{let{foundation:M,colors:j}=G(b);return q(M,j,b)});await p(`design/${m}.design.md`,ze(m,f))}}let R={configHash:fe(n),files:l,gitCommit:on(t),buildEnv:tn()},T=rn(R);return await kn(F(c,"manifest.json"),T),await bn(o,{recursive:!0,force:!0}),await Rn(In(o),{recursive:!0}),await vo(c,o),r&&console.log(`\u2713 ${l.length} files \u2192 ${o}`),{manifest:R,outDir:o}}catch(l){throw await bn(c,{recursive:!0,force:!0}).catch(()=>{}),l}}s(xn,"build");async function Sn(e){let{config:n,outDir:o}=e,t;try{t=JSON.parse(await yn(F(o,"manifest.json"),"utf8"))}catch{return!1}if(t.configHash!==fe(n))return!1;for(let r of t.files){let i;try{i=await yn(F(o,r.path))}catch{return!1}if(K(i)!==r.sha256)return!1}return!0}s(Sn,"check");async function Do(e,n,o){let t=F(e,n);await Rn(In(t),{recursive:!0}),await kn(t,o)}s(Do,"writeAt");import{readFile as Co}from"node:fs/promises";import{resolve as Vo}from"node:path";import{createContext as Oo,Script as Eo}from"node:vm";import{z as g}from"zod";var S=g.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),$o=g.object({baseDark:g.string().optional(),baseLight:g.string().optional(),deepDark:S,deepLight:S,transparent:g.string().optional(),main:S.optional(),opposite:S.optional(),complementary:S.optional(),information:S.optional(),success:S.optional(),danger:S.optional(),warning:S.optional(),primary:S.optional(),secondary:S.optional(),tertiary:S.optional()}).passthrough(),wn=g.object({brands:g.record(g.string(),$o).refine(e=>Object.keys(e).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:g.array(g.enum(["light","dark"])).optional(),surfaces:g.array(g.enum(["positive","negative"])).optional(),dimensions:g.array(g.enum(["compact","normal","spacious"])).optional(),output:g.object({runtime:g.boolean().optional(),css:g.boolean().optional(),json:g.boolean().optional(),ts:g.boolean().optional(),designMd:g.boolean().optional(),tailwind:g.boolean().optional()}).passthrough().optional()}).passthrough();var Ao=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],jo=1e3;var he=class he extends Error{constructor(o,t){super(o);this.configPath=t;this.name="ConfigLoadError"}};s(he,"ConfigLoadError");var A=he;async function vn(e){let n=Vo(e.configPath),o=await Co(n,"utf8");for(let l of Ao)if(l.test(o))throw new A(`apollion.config: dynamic require/import not allowed (matched ${l}). Declarative config only \u2014 see ADR-006 \xA73.8 B3.`,n);let t=o.replace(/(^|\n)\s*export\s+default\s+/,(l,p)=>`${p}__apollion_config_export = `);if(t===o)throw new A("apollion.config: missing `export default <object>;` \u2014 config must export a default object literal.",n);let r={__apollion_config_export:void 0,console:Go(),Symbol,Number,String,Boolean,Array,Object,JSON,Math,defineConfig:s(l=>l,"defineConfig")},i=Oo(r);try{new Eo(t,{filename:n}).runInContext(i,{timeout:jo})}catch(l){throw new A(`apollion.config: evaluation failed \u2014 ${l instanceof Error?l.message:String(l)}`,n)}let a=r.__apollion_config_export;if(a===void 0)throw new A("apollion.config: `export default` produced undefined.",n);let c=wn.safeParse(a);if(!c.success){let l=c.error.issues.map(p=>` ${p.path.join(".")||"(root)"}: ${p.message}`).join(`
|
|
13
|
-
`);throw new
|
|
14
|
-
${l}`,n)}return c.data}s(
|
|
8
|
+
${r.join(`
|
|
9
|
+
`)}`}s(cn,"renderDesignMd");function ln(e){return e.alpha!==void 0?{colorSpace:"oklch",components:[...e.components],alpha:e.alpha,hex:e.hex}:{colorSpace:"oklch",components:[...e.components],hex:e.hex}}s(ln,"colorValue");function H(e){return{value:e.value,unit:e.unit}}s(H,"dimensionValue");function yo(e){let n=e.shadow,o={color:ln(n.color),offsetX:H(n.offsetX),offsetY:H(n.offsetY),blur:H(n.blur),spread:H(n.spread)};return n.inset&&(o.inset=!0),o}s(yo,"shadowValue");function bo(e){switch(e.kind){case"ref":return`{${Oe(e.path)}}`;case"color":return ln(e);case"dimension":return H(e);case"fontFamily":return e.family;case"fontWeight":return e.weight;case"number":return e.number;case"strokeStyle":return e.style;case"shadow":return yo(e)}}s(bo,"projectValue");function Ro(e){let n={$value:bo(e.value),$type:e.type};return e.description!==void 0&&(n.$description=e.description),e.deprecated!==void 0&&(n.$deprecated=e.deprecated),n}s(Ro,"projectToken");function Ie(e){let n={};for(let[o,r]of Object.entries(e))n[x(o)]=y(r)?Ro(r):Ie(r);return n}s(Ie,"projectGroup");function oe(e,n){let o={$description:n,...Ie(e.groups)};return Object.keys(e.extensions).length>0&&(o.$extensions=e.extensions),`${JSON.stringify(o,null,2)}
|
|
10
|
+
`}s(oe,"renderSet");function dn(e){return oe(e,"Apollion DS \u2014 base set (axis-invariant: border). DTCG 2025.10.")}s(dn,"renderBaseSet");function un(e,n,o,r){return oe(e,`Apollion DS \u2014 colour set. brand=${n} mode=${o} surface=${r}. DTCG 2025.10.`)}s(un,"renderColorSet");function pn(e,n){return oe(e,`Apollion DS \u2014 spacing set. dimension=${n}. DTCG 2025.10.`)}s(pn,"renderSpacingSet");function fn(e,n){return oe(e,`Apollion DS \u2014 font set. dimension=${n}. DTCG 2025.10.`)}s(fn,"renderFontSet");function gn(e,n){let{modifiers:o}=n,r=[{name:"brand",values:[...o.brand],default:o.brand[0]},{name:"mode",values:[...o.mode],default:o.mode[0]},{name:"surface",values:[...o.surface],default:o.surface[0]},{name:"dimension",values:[...o.dimension],default:o.dimension[0]}],i={name:"apollion-tokens",description:"Apollion DS token resolver \u2014 DTCG 2025.10. Compose the base set with the colour set for the chosen brand/mode/surface and the spacing + font sets for the chosen dimension. NOTE: mode is a topology placeholder in this release (dark resolves identically to light until S6).",sets:[{name:n.base.name,source:n.base.file},...n.spacing.map(a=>({name:a.name,source:a.file})),...n.font.map(a=>({name:a.name,source:a.file})),...n.color.map(a=>({name:a.name,source:a.file}))],modifiers:r,$extensions:{"com.apollion.resolver":{composition:{always:[n.base.name],byModifier:{color:"${brand}.color.${mode}.${surface}",spacing:"spacing.${dimension}",font:"font.${dimension}"}},modeIsPlaceholder:!0}}};return`${JSON.stringify(i,null,2)}
|
|
11
|
+
`}s(gn,"renderResolver");var ko="// Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs.";function Io(e,n,o){let r=[];if(e.description!==void 0&&r.push(e.description),e.deprecated===!0?r.push("@deprecated"):typeof e.deprecated=="string"&&r.push(`@deprecated ${e.deprecated}`),r.length!==0){o.push(`${n}/**`);for(let t of r)o.push(`${n} * ${t.replace(/\*\//g,"*\\/")}`);o.push(`${n} */`)}}s(Io,"emitDoc");function mn(e,n,o){let r=" ".repeat(n);for(let[t,i]of Object.entries(e))y(i)?(Io(i,r,o),o.push(`${r}${JSON.stringify(t)}: ${JSON.stringify(G(i.value))},`)):(o.push(`${r}${t}: {`),mn(i,n+1,o),o.push(`${r}},`))}s(mn,"emitGroup");function hn(e){let{brand:n,mode:o,surface:r,dimension:t}=e.meta,i=[ko,`// Variant: brand=${n} mode=${o} surface=${r} dimension=${t}`,"","export const tokens = {"];return mn(e.groups,1,i),i.push("} as const;","","export type Tokens = typeof tokens;",""),i.join(`
|
|
12
|
+
`)}s(hn,"renderTs");var xo=["light","dark"],So=["positive","negative"],wo=["compact","normal","spacious"];function re(e){let n=e.modes??xo,o=e.surfaces??So,r=e.dimensions??wo,t=Object.entries(e.brands).sort(([a],[c])=>a.localeCompare(c)),i=[];for(let[a,c]of t)for(let l of n)for(let f of o)for(let b of r)i.push({brand:a,colors:c,mode:l,surface:f,dimension:b});return i}s(re,"expandVariants");function yn(e){return`${e.brand}.${e.mode}.${e.surface}.${e.dimension}`}s(yn,"variantName");import{createHash as vo}from"node:crypto";function te(e){return vo("sha256").update(e).digest("hex")}s(te,"sha256");function Se(e){return te(xe(e))}s(Se,"hashConfig");function xe(e){return e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?`[${e.map(xe).join(",")}]`:`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${xe(e[r])}`).join(",")}}`}s(xe,"stableStringify");function bn(e){try{let{execSync:n}=Jn("node:child_process");return n("git rev-parse --short HEAD",{cwd:e,stdio:["ignore","pipe","ignore"],encoding:"utf8"}).trim()}catch{return""}}s(bn,"detectGitCommit");function Rn(){return{node:process.version,platform:`${process.platform}-${process.arch}`}}s(Rn,"buildEnv");function kn(e){let n=[...e.files].sort((r,t)=>r.path.localeCompare(t.path)),o={configHash:e.configHash,files:n,gitCommit:e.gitCommit,buildEnv:e.buildEnv};return`${JSON.stringify(o,null,2)}
|
|
13
|
+
`}s(kn,"serializeManifest");var Do="json/sets",In="json/resolver.json";function ie(e){return`${Do}/${e}.json`}s(ie,"setFile");function $o(e,n,o){return`${e}.color.${n}.${o}`}s($o,"colorSetName");function To(e){return`spacing.${e}`}s(To,"spacingSetName");function Co(e){return`font.${e}`}s(Co,"fontSetName");function se(e,n){e.includes(n)||e.push(n)}s(se,"pushUnique");function xn(e){let n=re(e),o=[],r=[],t=[],i=[],a=new Set,c=[],l=new Set,f=[],b=new Set,w=[];for(let d of n){se(o,d.brand),se(r,d.mode),se(t,d.surface),se(i,d.dimension);let u=$o(d.brand,d.mode,d.surface);a.has(u)||(a.add(u),c.push({kind:"color",name:u,file:ie(u),brand:d.brand,mode:d.mode,surface:d.surface}));let h=To(d.dimension);l.has(h)||(l.add(h),f.push({kind:"spacing",name:h,file:ie(h),dimension:d.dimension}));let g=Co(d.dimension);b.has(g)||(b.add(g),w.push({kind:"font",name:g,file:ie(g),dimension:d.dimension}))}return{base:{kind:"base",name:"base",file:ie("base")},spacing:f,font:w,color:c,modifiers:{brand:o,mode:r,surface:t,dimension:i}}}s(xn,"planSets");import{toDarkColors as Ho}from"@apollion-dsi/core/themes/colors";import{createFoundation as On}from"@apollion-dsi/core/themes/foundation";import{createSemantic as Wo}from"@apollion-dsi/core/themes/semantic";import{defaultInputSpacing as Jo}from"@apollion-dsi/core/themes/spacing";import{invertForSurface as zo}from"@apollion-dsi/core/themes/surface";import{converter as $n,formatHex as j,interpolate as Ao,parse as S,wcagContrast as Tn}from"culori";var J=$n("oklch"),Vo=$n("rgb");function p(e,n,o){let r=S(e),t=S(n);if(!r||!t)return e;let i=Ao([r,t],"oklch");return j(i(o))??e}s(p,"mixOklch");function Lo(e){return e?typeof e=="string"?e:e.base:"#000"}s(Lo,"coerceToHex");var ae=1.3,Mo=.05,Sn=.04,V=s((e,n)=>{let o=S(e),r=S(n);return!o||!r?1:Tn(o,r)},"contrastRatio"),we=s(e=>{let n=J(S(e));return n?n.l??0:null},"oklchLightness"),Oo=4.5;function W(e,n,o=Oo){let r=S(n),t=J(S(e));if(!r||!t)return e;let i=V("#fff",n)>=V("#000",n)?.04:-.04;for(let a=0;a<25;a+=1){let c=j(t)??e,l=S(c);if(l&&Tn(l,r)>=o)return c;let f=Math.min(1,Math.max(0,(t.l??0)+i));if(f===(t.l??0))break;t={...t,l:f}}return j(t)??e}s(W,"readableColor");var wn=s((e,n)=>{if(V(e,n)>=ae)return!0;let o=we(e),r=we(n);return o!==null&&r!==null&&Math.abs(o-r)>=Mo},"isPerceptibleState"),ve=s(e=>e?V("#fff",e)>V("#000",e):!1,"isDarkSurface");function vn(e,n,o){let r=J(S(e));if(!r)return null;let t={...r,l:o??r.l??0},i=n?Sn:-Sn;for(let a=0;a<25;a+=1){let c=Math.min(1,Math.max(0,(t.l??0)+i));if(c===(t.l??0))break;t={...t,l:c};let l=j(t);if(l&&V(e,l)>=ae)return l}return j(t)??null}s(vn,"derivePerceptibleState");function Dn(e,n,o){let r=vn(e,n,o);if(r&&V(e,r)>=ae)return r;let t=vn(e,!n);return t&&V(e,t)>=ae?t:r??t}s(Dn,"perceptibleStateFor");function D(e,n){let o=typeof e=="object"&&e!==null?e:void 0,r=Lo(e),t=n.deepDark,i=n.deepLight,a={base:r,dark:p(r,t,.6),action:p(r,t,.2),active:p(r,i,.6),light:p(r,i,.9),onLight:r};if(S(r)){let c=ve(n.baseLight),l=wn(r,a.action);if(l||(a.action=Dn(r,c)??a.action),!wn(r,a.active)){let f=l?void 0:we(a.action)??void 0;a.active=Dn(r,c,f)??a.active}}if(a.onLight=W(a.action,a.light),o){let c=o.action??a.action,l=o.light??a.light;return{base:r,dark:o.dark??a.dark,action:c,active:o.active??a.active,light:l,onLight:o.onLight??W(c,l)}}return a}s(D,"mountSingleColor");function Cn(e){let n=e.deepLight,o=e.deepDark;return{0:n,5:p(n,o,.05),10:p(n,o,.1),20:p(n,o,.2),30:p(n,o,.3),40:p(n,o,.4),50:p(n,o,.5),60:p(n,o,.6),70:p(n,o,.7),80:p(n,o,.8),90:p(n,o,.9),100:p(n,o,1)}}s(Cn,"mountGreyscaleColors");function An(e){let n=e.deepLight,o=e.deepDark,r=typeof e.primary=="object"&&e.primary?e.primary.base:e.primary,t=s(a=>1/17*(a-1),"interpolation"),i=p(r,o,.5);return{0:p(i,n,t(18)),5:p(i,n,t(17.5)),10:p(i,n,t(17)),20:p(i,n,t(16)),30:p(i,n,t(15)),40:p(i,n,t(14)),50:p(i,n,t(13)),60:p(i,n,t(12)),70:p(i,n,t(11)),80:p(i,n,t(10)),90:p(i,n,t(9)),100:p(i,n,t(8)),110:p(i,n,t(7)),120:p(i,n,t(6)),130:p(i,n,t(5)),140:p(i,n,t(4)),150:p(i,n,t(3)),160:p(i,n,t(2)),170:i,180:p(i,o,.25)}}s(An,"mountNeutralColors");function B(e,n){let o=J(S(e));if(!o)return e;let r=Math.min(1,Math.max(0,(o.l??0)+n));return j({...o,l:r})??e}s(B,"shiftLightness");function ce(e,n){let o=J(S(e));if(!o)return e;let r=o.l??0,t=n.min??0,i=n.max??1;return r>=t&&r<=i?e:j({...o,l:Math.min(i,Math.max(t,r))})??e}s(ce,"clampLightness");function P(e,n){let o=Vo(S(e));if(!o)return e;let r=Math.min(1,Math.max(0,n)),t=s(i=>Math.round((i??0)*255),"channel");return`rgba(${t(o.r)}, ${t(o.g)}, ${t(o.b)}, ${r})`}s(P,"toRgbaString");import{apcaContrast as le,EDGE_ALPHA as De,HALATION_FLOORS as Ce,INK_APCA_MIN as $e,INK_MIX as Te,LADDER_DELTAS as de,MIN_CONTRAST_AA as Vn,WASH_ALPHA as Eo}from"@apollion-dsi/core/themes/colors";var Go="#FFFFFF",Ae="#000000";function jo(e){return ve(e.baseLight)?"dark":"light"}s(jo,"resolvePolarity");function Ln(e,n,o){if(Math.abs(le(e,n))>=o)return e;let r=Math.abs(le("#ffffff",n))>=Math.abs(le("#000000",n)),t=e;for(let i=0;i<40;i+=1){let a=B(t,r?.02:-.02);if(a===t||(t=a,Math.abs(le(t,n))>=o))break}return t}s(Ln,"ensureApca");function Po(e,n){let o=e.baseLight??Go,r=n==="dark",t=r?ce(o,{min:Ce.CANVAS_MIN_L}):o,i=B(t,de.sunken);return{canvas:t,sunken:r?ce(i,{min:Ce.CANVAS_MIN_L}):i,paper:B(t,de.paper),raised:B(t,de.raised),overlay:B(t,de.overlay),scrim:r?e.deepLight??Ae:e.neutral?.["180"]??e.baseDark??Ae}}s(Po,"deriveSurface");function No(e,n){let o=e.baseDark??Ae,r=ce(Ln(W(o,n.paper,Vn),n.paper,$e.primary),{max:Ce.INK_MAX_L}),t=s((i,a)=>Ln(W(p(r,n.canvas,i),n.paper,Vn),n.paper,a),"tier");return{primary:r,secondary:t(Te.secondary,$e.secondary),muted:t(Te.muted,$e.muted),disabled:p(r,n.canvas,Te.disabled)}}s(No,"deriveInk");function Fo(e){return{hairline:P(e.primary,De.hairline),border:P(e.primary,De.border),strong:P(e.primary,De.strong)}}s(Fo,"deriveEdge");function _o(e,n){let o=Eo[n];return{hover:P(e.primary,o.hover),pressed:P(e.primary,o.pressed),selected:P(e.primary,o.selected)}}s(_o,"deriveWash");function Bo(e,n){return n?{surface:{...e.surface,...n.surface},ink:{...e.ink,...n.ink},edge:{...e.edge,...n.edge},wash:{...e.wash,...n.wash}}:e}s(Bo,"applyOverride");function Mn(e,n){let o=jo(e),r=Po(e,o),t=No(e,r),i={surface:r,ink:t,edge:Fo(t),wash:_o(t,o)};return Bo(i,n?.[o])}s(Mn,"resolveSurfaceLadder");function qo(e){let n=An(e);return{baseDark:e.baseDark,baseLight:e.baseLight,deepDark:e.deepDark,deepLight:e.deepLight,transparent:e.transparent??"transparent",neutral:n,grayscale:Cn(e),...Mn({...e,neutral:n},e.ladder),main:D(e.main,e),opposite:D(e.opposite,e),complementary:D(e.complementary,e),danger:D(e.danger,e),information:D(e.information,e),success:D(e.success,e),warning:D(e.warning,e),primary:D(e.primary,e),secondary:D(e.secondary,e),tertiary:D(e.tertiary,e)}}s(qo,"composeColors");function L(e,n=Jo){let o=e.mode==="dark"?Ho(e.colors):e.colors,r=qo(o),t=U(n,e.dimension),i=Wo({colors:r,spacing:t}),a=On(i);return e.surface==="negative"&&(a=On(zo({semantic:i,colors:r},"negative").semantic)),{foundation:a,colors:r}}s(L,"buildVariantThemes");async function Fn(e){let{config:n,outDir:o,cwd:r=process.cwd(),verbose:t=!1}=e,i=re(n),a=n.output??{};if(i.length===0)throw new Error("apollion-tokens build: no variants (config.brands is empty)");let c=await Uo(z(Xo(),"apollion-tokens-"));try{let l=[],f=s(async(d,u)=>{await Yo(c,d,u),l.push({path:d,sha256:te(u)}),t&&console.log(` \u2713 ${d}`)},"emit");if(a.json){let d=xn(n),u=[],h=Ke();u.push(h),await f(d.base.file,dn(h));for(let g of d.spacing){let R=i.find(q=>q.dimension===g.dimension),{foundation:$}=L(R),T=Ze($,g.dimension);u.push(T),await f(g.file,pn(T,g.dimension))}for(let g of d.font){let R=Xe(g.dimension);u.push(R),await f(g.file,fn(R,g.dimension))}for(let g of d.color){let R=i.find(pe=>pe.brand===g.brand&&pe.mode===g.mode&&pe.surface===g.surface),{foundation:$,colors:T}=L(R),q=Ye($,T);u.push(q),await f(g.file,un(q,g.brand,g.mode,g.surface))}Ue(u),await f(In,gn(n,d))}if(a.css||a.ts)for(let d of i){let{foundation:u,colors:h}=L(d),g=_(u,h,d),R=yn(d);a.css&&await f(`css/${R}.css`,sn(g,{rgbCompanions:a.tailwind})),a.ts&&await f(`ts/${R}.d.ts`,hn(g))}if(a.cssModes){let d=new Map;for(let u of i){let h=`${u.brand}.${u.surface}.${u.dimension}`,g=d.get(h)??{};g[u.mode]=u,d.set(h,g)}for(let[u,{light:h,dark:g}]of d){if(!h||!g)throw new Error(`apollion-tokens build: output.cssModes needs both modes for ${u} (config.modes)`);let R=L(h),$=L(g),T=an(_(R.foundation,R.colors,h),_($.foundation,$.colors,g),{rgbCompanions:a.tailwind});await f(`css/${u}.modes.css`,T)}}if(a.tailwind){let d=i[0],{foundation:u,colors:h}=L(d),g=_(u,h,d);await f("tailwind/preset.mjs",on(g)),await f("tailwind/tw-merge.mjs",rn(g))}if(a.designMd){let d=[...new Set(i.map(u=>u.brand))];for(let u of d){let g=i.filter(R=>R.brand===u).map(R=>{let{foundation:$,colors:T}=L(R);return _($,T,R)});await f(`design/${u}.design.md`,cn(u,g))}}let b={configHash:Se(n),files:l,gitCommit:bn(r),buildEnv:Rn()},w=kn(b);return await Pn(z(c,"manifest.json"),w),await Gn(o,{recursive:!0,force:!0}),await jn(Nn(o),{recursive:!0}),await Ko(c,o),t&&console.log(`\u2713 ${l.length} files \u2192 ${o}`),{manifest:b,outDir:o}}catch(l){throw await Gn(c,{recursive:!0,force:!0}).catch(()=>{}),l}}s(Fn,"build");async function _n(e){let{config:n,outDir:o}=e,r;try{r=JSON.parse(await En(z(o,"manifest.json"),"utf8"))}catch{return!1}if(r.configHash!==Se(n))return!1;for(let t of r.files){let i;try{i=await En(z(o,t.path))}catch{return!1}if(te(i)!==t.sha256)return!1}return!0}s(_n,"check");async function Yo(e,n,o){let r=z(e,n);await jn(Nn(r),{recursive:!0}),await Pn(r,o)}s(Yo,"writeAt");import{readFile as Qo}from"node:fs/promises";import{resolve as er}from"node:path";import{createContext as nr,Script as or}from"node:vm";import{z as m}from"zod";var v=m.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),Zo=m.object({baseDark:m.string().optional(),baseLight:m.string().optional(),deepDark:v,deepLight:v,transparent:m.string().optional(),main:v.optional(),opposite:v.optional(),complementary:v.optional(),information:v.optional(),success:v.optional(),danger:v.optional(),warning:v.optional(),primary:v.optional(),secondary:v.optional(),tertiary:v.optional()}).passthrough(),Bn=m.object({brands:m.record(m.string(),Zo).refine(e=>Object.keys(e).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:m.array(m.enum(["light","dark"])).optional(),surfaces:m.array(m.enum(["positive","negative"])).optional(),dimensions:m.array(m.enum(["compact","normal","spacious"])).optional(),output:m.object({runtime:m.boolean().optional(),css:m.boolean().optional(),json:m.boolean().optional(),ts:m.boolean().optional(),designMd:m.boolean().optional(),tailwind:m.boolean().optional(),cssModes:m.boolean().optional()}).passthrough().optional()}).passthrough();var rr=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],tr=1e3;var Ve=class Ve extends Error{constructor(o,r){super(o);this.configPath=r;this.name="ConfigLoadError"}};s(Ve,"ConfigLoadError");var N=Ve;async function Hn(e){let n=er(e.configPath),o=await Qo(n,"utf8");for(let l of rr)if(l.test(o))throw new N(`apollion.config: dynamic require/import not allowed (matched ${l}). Declarative config only \u2014 see ADR-006 \xA73.8 B3.`,n);let r=o.replace(/(^|\n)\s*export\s+default\s+/,(l,f)=>`${f}__apollion_config_export = `);if(r===o)throw new N("apollion.config: missing `export default <object>;` \u2014 config must export a default object literal.",n);let t={__apollion_config_export:void 0,console:ir(),Symbol,Number,String,Boolean,Array,Object,JSON,Math,defineConfig:s(l=>l,"defineConfig")},i=nr(t);try{new or(r,{filename:n}).runInContext(i,{timeout:tr})}catch(l){throw new N(`apollion.config: evaluation failed \u2014 ${l instanceof Error?l.message:String(l)}`,n)}let a=t.__apollion_config_export;if(a===void 0)throw new N("apollion.config: `export default` produced undefined.",n);let c=Bn.safeParse(a);if(!c.success){let l=c.error.issues.map(f=>` ${f.path.join(".")||"(root)"}: ${f.message}`).join(`
|
|
14
|
+
`);throw new N(`apollion.config: schema validation failed \u2014
|
|
15
|
+
${l}`,n)}return c.data}s(Hn,"loadConfig");function ir(){return{log:s((...e)=>console.log("[apollion.config]",...e),"log"),warn:s((...e)=>console.warn("[apollion.config]",...e),"warn"),error:s((...e)=>console.error("[apollion.config]",...e),"error")}}s(ir,"makeReadOnlyConsole");function ar(e){let n=e.slice(2),o=n[0];o!=="build"&&ue(`Unknown command "${o??""}". Usage: apollion-tokens build [--check] [--verbose] --config <path> [--out <dir>]`);let r="apollion.config.mjs",t="dist",i=!1,a=!1;for(let c=1;c<n.length;c++){let l=n[c];switch(l){case"--config":r=n[++c]??ue("--config needs a path");break;case"--out":t=n[++c]??ue("--out needs a path");break;case"--check":i=!0;break;case"--verbose":a=!0;break;default:ue(`Unknown flag "${l}"`)}}return{command:o,configPath:r,outDir:t,check:i,verbose:a}}s(ar,"parseArgs");function ue(e){console.error(`apollion-tokens: ${e}`),process.exit(2)}s(ue,"fail");async function cr(e){let n=Le(e);if(n.endsWith(".json")){let o=await sr(n,"utf8");return JSON.parse(o)}return Hn({configPath:n})}s(cr,"loadConfigFromPath");async function lr(){let e=ar(process.argv),n=await cr(e.configPath);if(e.check){await _n({config:n,outDir:Le(e.outDir)})||(console.error("apollion-tokens: dist/ is stale, missing, or has drifted from its manifest. Re-run `apollion-tokens build` without --check."),process.exit(1)),console.log("apollion-tokens: dist/ is up-to-date with config.");return}let{manifest:o}=await Fn({config:n,outDir:Le(e.outDir),verbose:e.verbose});console.log(`apollion-tokens: wrote ${o.files.length} file(s) \u2014 configHash=${o.configHash.slice(0,12)}\u2026`)}s(lr,"main");lr().catch(e=>{console.error(`apollion-tokens: ${e instanceof Error?e.message:String(e)}`),process.exit(1)});
|
package/lib/config-loader.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var a=(n,t)=>f(n,"name",{value:t,configurable:!0});var k=(n,t)=>{for(var r in t)f(n,r,{get:t[r],enumerable:!0})},j=(n,t,r,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of C(t))!_.call(n,s)&&s!==r&&f(n,s,{get:()=>t[s],enumerable:!(p=y(t,s))||p.enumerable});return n};var A=n=>j(f({},"__esModule",{value:!0}),n);var v={};k(v,{ConfigLoadError:()=>l,defineConfig:()=>P,loadConfig:()=>D});module.exports=A(v);var b=require("node:fs/promises"),w=require("node:path"),g=require("node:vm");var o=require("zod"),i=o.z.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),S=o.z.object({baseDark:o.z.string().optional(),baseLight:o.z.string().optional(),deepDark:i,deepLight:i,transparent:o.z.string().optional(),main:i.optional(),opposite:i.optional(),complementary:i.optional(),information:i.optional(),success:i.optional(),danger:i.optional(),warning:i.optional(),primary:i.optional(),secondary:i.optional(),tertiary:i.optional()}).passthrough(),h=o.z.object({brands:o.z.record(o.z.string(),S).refine(n=>Object.keys(n).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:o.z.array(o.z.enum(["light","dark"])).optional(),surfaces:o.z.array(o.z.enum(["positive","negative"])).optional(),dimensions:o.z.array(o.z.enum(["compact","normal","spacious"])).optional(),output:o.z.object({runtime:o.z.boolean().optional(),css:o.z.boolean().optional(),json:o.z.boolean().optional(),ts:o.z.boolean().optional(),designMd:o.z.boolean().optional(),tailwind:o.z.boolean().optional()}).passthrough().optional()}).passthrough();var $=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],O=1e3;function P(n){return n}a(P,"defineConfig");var u=class u extends Error{constructor(r,p){super(r);this.configPath=p;this.name="ConfigLoadError"}};a(u,"ConfigLoadError");var l=u;async function D(n){let t=(0,w.resolve)(n.configPath),r=await(0,b.readFile)(t,"utf8");for(let e of $)if(e.test(r))throw new l(`apollion.config: dynamic require/import not allowed (matched ${e}). Declarative config only \u2014 see ADR-006 \xA73.8 B3.`,t);let p=r.replace(/(^|\n)\s*export\s+default\s+/,(e,c)=>`${c}__apollion_config_export = `);if(p===r)throw new l("apollion.config: missing `export default <object>;` \u2014 config must export a default object literal.",t);let s={__apollion_config_export:void 0,console:T(),Symbol,Number,String,Boolean,Array,Object,JSON,Math,defineConfig:a(e=>e,"defineConfig")},x=(0,g.createContext)(s);try{new g.Script(p,{filename:t}).runInContext(x,{timeout:O})}catch(e){throw new l(`apollion.config: evaluation failed \u2014 ${e instanceof Error?e.message:String(e)}`,t)}let d=s.__apollion_config_export;if(d===void 0)throw new l("apollion.config: `export default` produced undefined.",t);let m=h.safeParse(d);if(!m.success){let e=m.error.issues.map(c=>` ${c.path.join(".")||"(root)"}: ${c.message}`).join(`
|
|
1
|
+
"use strict";var f=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var a=(n,t)=>f(n,"name",{value:t,configurable:!0});var k=(n,t)=>{for(var r in t)f(n,r,{get:t[r],enumerable:!0})},j=(n,t,r,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of C(t))!_.call(n,s)&&s!==r&&f(n,s,{get:()=>t[s],enumerable:!(p=y(t,s))||p.enumerable});return n};var A=n=>j(f({},"__esModule",{value:!0}),n);var v={};k(v,{ConfigLoadError:()=>l,defineConfig:()=>P,loadConfig:()=>D});module.exports=A(v);var b=require("node:fs/promises"),w=require("node:path"),g=require("node:vm");var o=require("zod"),i=o.z.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),S=o.z.object({baseDark:o.z.string().optional(),baseLight:o.z.string().optional(),deepDark:i,deepLight:i,transparent:o.z.string().optional(),main:i.optional(),opposite:i.optional(),complementary:i.optional(),information:i.optional(),success:i.optional(),danger:i.optional(),warning:i.optional(),primary:i.optional(),secondary:i.optional(),tertiary:i.optional()}).passthrough(),h=o.z.object({brands:o.z.record(o.z.string(),S).refine(n=>Object.keys(n).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:o.z.array(o.z.enum(["light","dark"])).optional(),surfaces:o.z.array(o.z.enum(["positive","negative"])).optional(),dimensions:o.z.array(o.z.enum(["compact","normal","spacious"])).optional(),output:o.z.object({runtime:o.z.boolean().optional(),css:o.z.boolean().optional(),json:o.z.boolean().optional(),ts:o.z.boolean().optional(),designMd:o.z.boolean().optional(),tailwind:o.z.boolean().optional(),cssModes:o.z.boolean().optional()}).passthrough().optional()}).passthrough();var $=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],O=1e3;function P(n){return n}a(P,"defineConfig");var u=class u extends Error{constructor(r,p){super(r);this.configPath=p;this.name="ConfigLoadError"}};a(u,"ConfigLoadError");var l=u;async function D(n){let t=(0,w.resolve)(n.configPath),r=await(0,b.readFile)(t,"utf8");for(let e of $)if(e.test(r))throw new l(`apollion.config: dynamic require/import not allowed (matched ${e}). Declarative config only \u2014 see ADR-006 \xA73.8 B3.`,t);let p=r.replace(/(^|\n)\s*export\s+default\s+/,(e,c)=>`${c}__apollion_config_export = `);if(p===r)throw new l("apollion.config: missing `export default <object>;` \u2014 config must export a default object literal.",t);let s={__apollion_config_export:void 0,console:T(),Symbol,Number,String,Boolean,Array,Object,JSON,Math,defineConfig:a(e=>e,"defineConfig")},x=(0,g.createContext)(s);try{new g.Script(p,{filename:t}).runInContext(x,{timeout:O})}catch(e){throw new l(`apollion.config: evaluation failed \u2014 ${e instanceof Error?e.message:String(e)}`,t)}let d=s.__apollion_config_export;if(d===void 0)throw new l("apollion.config: `export default` produced undefined.",t);let m=h.safeParse(d);if(!m.success){let e=m.error.issues.map(c=>` ${c.path.join(".")||"(root)"}: ${c.message}`).join(`
|
|
2
2
|
`);throw new l(`apollion.config: schema validation failed \u2014
|
|
3
3
|
${e}`,t)}return m.data}a(D,"loadConfig");function T(){return{log:a((...n)=>console.log("[apollion.config]",...n),"log"),warn:a((...n)=>console.warn("[apollion.config]",...n),"warn"),error:a((...n)=>console.error("[apollion.config]",...n),"error")}}a(T,"makeReadOnlyConsole");0&&(module.exports={ConfigLoadError,defineConfig,loadConfig});
|
package/lib/config-loader.esm.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var h=Object.defineProperty;var r=(n,i)=>h(n,"name",{value:i,configurable:!0});import{readFile as w}from"node:fs/promises";import{resolve as x}from"node:path";import{createContext as y,Script as C}from"node:vm";import{z as o}from"zod";var e=o.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),b=o.object({baseDark:o.string().optional(),baseLight:o.string().optional(),deepDark:e,deepLight:e,transparent:o.string().optional(),main:e.optional(),opposite:e.optional(),complementary:e.optional(),information:e.optional(),success:e.optional(),danger:e.optional(),warning:e.optional(),primary:e.optional(),secondary:e.optional(),tertiary:e.optional()}).passthrough(),u=o.object({brands:o.record(o.string(),b).refine(n=>Object.keys(n).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:o.array(o.enum(["light","dark"])).optional(),surfaces:o.array(o.enum(["positive","negative"])).optional(),dimensions:o.array(o.enum(["compact","normal","spacious"])).optional(),output:o.object({runtime:o.boolean().optional(),css:o.boolean().optional(),json:o.boolean().optional(),ts:o.boolean().optional(),designMd:o.boolean().optional(),tailwind:o.boolean().optional()}).passthrough().optional()}).passthrough();var _=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],k=1e3;function v(n){return n}r(v,"defineConfig");var f=class f extends Error{constructor(s,p){super(s);this.configPath=p;this.name="ConfigLoadError"}};r(f,"ConfigLoadError");var a=f;async function
|
|
1
|
+
var h=Object.defineProperty;var r=(n,i)=>h(n,"name",{value:i,configurable:!0});import{readFile as w}from"node:fs/promises";import{resolve as x}from"node:path";import{createContext as y,Script as C}from"node:vm";import{z as o}from"zod";var e=o.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),b=o.object({baseDark:o.string().optional(),baseLight:o.string().optional(),deepDark:e,deepLight:e,transparent:o.string().optional(),main:e.optional(),opposite:e.optional(),complementary:e.optional(),information:e.optional(),success:e.optional(),danger:e.optional(),warning:e.optional(),primary:e.optional(),secondary:e.optional(),tertiary:e.optional()}).passthrough(),u=o.object({brands:o.record(o.string(),b).refine(n=>Object.keys(n).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:o.array(o.enum(["light","dark"])).optional(),surfaces:o.array(o.enum(["positive","negative"])).optional(),dimensions:o.array(o.enum(["compact","normal","spacious"])).optional(),output:o.object({runtime:o.boolean().optional(),css:o.boolean().optional(),json:o.boolean().optional(),ts:o.boolean().optional(),designMd:o.boolean().optional(),tailwind:o.boolean().optional(),cssModes:o.boolean().optional()}).passthrough().optional()}).passthrough();var _=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],k=1e3;function v(n){return n}r(v,"defineConfig");var f=class f extends Error{constructor(s,p){super(s);this.configPath=p;this.name="ConfigLoadError"}};r(f,"ConfigLoadError");var a=f;async function M(n){let i=x(n.configPath),s=await w(i,"utf8");for(let t of _)if(t.test(s))throw new a(`apollion.config: dynamic require/import not allowed (matched ${t}). Declarative config only \u2014 see ADR-006 \xA73.8 B3.`,i);let p=s.replace(/(^|\n)\s*export\s+default\s+/,(t,l)=>`${l}__apollion_config_export = `);if(p===s)throw new a("apollion.config: missing `export default <object>;` \u2014 config must export a default object literal.",i);let g={__apollion_config_export:void 0,console:j(),Symbol,Number,String,Boolean,Array,Object,JSON,Math,defineConfig:r(t=>t,"defineConfig")},d=y(g);try{new C(p,{filename:i}).runInContext(d,{timeout:k})}catch(t){throw new a(`apollion.config: evaluation failed \u2014 ${t instanceof Error?t.message:String(t)}`,i)}let m=g.__apollion_config_export;if(m===void 0)throw new a("apollion.config: `export default` produced undefined.",i);let c=u.safeParse(m);if(!c.success){let t=c.error.issues.map(l=>` ${l.path.join(".")||"(root)"}: ${l.message}`).join(`
|
|
2
2
|
`);throw new a(`apollion.config: schema validation failed \u2014
|
|
3
|
-
${t}`,i)}return c.data}r(
|
|
3
|
+
${t}`,i)}return c.data}r(M,"loadConfig");function j(){return{log:r((...n)=>console.log("[apollion.config]",...n),"log"),warn:r((...n)=>console.warn("[apollion.config]",...n),"warn"),error:r((...n)=>console.error("[apollion.config]",...n),"error")}}r(j,"makeReadOnlyConsole");export{a as ConfigLoadError,v as defineConfig,M as loadConfig};
|
package/lib/config-schema.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var c=(o,n)=>t(o,"name",{value:n,configurable:!0});var g=(o,n)=>{for(var s in n)t(o,s,{get:n[s],enumerable:!0})},D=(o,n,s,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of f(n))!b.call(o,e)&&e!==s&&t(o,e,{get:()=>n[e],enumerable:!(r=u(n,e))||r.enumerable});return o};var S=o=>D(t({},"__esModule",{value:!0}),o);var
|
|
1
|
+
"use strict";var t=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var c=(o,n)=>t(o,"name",{value:n,configurable:!0});var g=(o,n)=>{for(var s in n)t(o,s,{get:n[s],enumerable:!0})},D=(o,n,s,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of f(n))!b.call(o,e)&&e!==s&&t(o,e,{get:()=>n[e],enumerable:!(r=u(n,e))||r.enumerable});return o};var S=o=>D(t({},"__esModule",{value:!0}),o);var E={};g(E,{expandVariants:()=>y,variantName:()=>C});module.exports=S(E);var x=["light","dark"],A=["positive","negative"],M=["compact","normal","spacious"];function y(o){let n=o.modes??x,s=o.surfaces??A,r=o.dimensions??M,e=Object.entries(o.brands).sort(([i],[a])=>i.localeCompare(a)),d=[];for(let[i,a]of e)for(let l of n)for(let p of s)for(let m of r)d.push({brand:i,colors:a,mode:l,surface:p,dimension:m});return d}c(y,"expandVariants");function C(o){return`${o.brand}.${o.mode}.${o.surface}.${o.dimension}`}c(C,"variantName");0&&(module.exports={expandVariants,variantName});
|
package/lib/runtime/v1.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var l=(e,t)=>g(e,"name",{value:t,configurable:!0});var D=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},F=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of E(t))!R.call(e,n)&&n!==r&&g(e,n,{get:()=>t[n],enumerable:!(o=P(t,n))||o.enumerable});return e};var $=e=>F(g({},"__esModule",{value:!0}),e);var U={};D(U,{TOKENS_RUNTIME_API_VERSION:()=>H,createFoundation:()=>b.createFoundation,createSpacing:()=>O,getOppositeColor:()=>M,invertForSurface:()=>y.invertForSurface,mountGreyscaleColors:()=>v,mountNeutralColors:()=>N,mountSingleColor:()=>A});module.exports=$(U);var c=require("culori");var d=(0,c.converter)("oklch"),w=(0,c.converter)("rgb");function i(e,t,r){let o=(0,c.parse)(e),n=(0,c.parse)(t);if(!o||!n)return e;let a=(0,c.interpolate)([o,n],"oklch");return(0,c.formatHex)(a(r))??e}l(i,"mixOklch");function L(e){return e?typeof e=="string"?e:e.base:"#000"}l(L,"coerceToHex");function M(e){let t=L(e),r=d((0,c.parse)(t));if(!r)return t;let o={...r,h:((r.h??0)+180)%360};return(0,c.formatHex)(o)??t}l(M,"getOppositeColor");var h=1.3,G=.05,C=.04,f=l((e,t)=>{let r=(0,c.parse)(e),o=(0,c.parse)(t);return!r||!o?1:(0,c.wcagContrast)(r,o)},"contrastRatio"),x=l(e=>{let t=d((0,c.parse)(e));return t?t.l??0:null},"oklchLightness"),j=4.5;function S(e,t,r=j){let o=(0,c.parse)(t),n=d((0,c.parse)(e));if(!o||!n)return e;let a=f("#fff",t)>=f("#000",t)?.04:-.04;for(let s=0;s<25;s+=1){let u=(0,c.formatHex)(n)??e,p=(0,c.parse)(u);if(p&&(0,c.wcagContrast)(p,o)>=r)return u;let m=Math.min(1,Math.max(0,(n.l??0)+a));if(m===(n.l??0))break;n={...n,l:m}}return(0,c.formatHex)(n)??e}l(S,"readableColor");var T=l((e,t)=>{if(f(e,t)>=h)return!0;let r=x(e),o=x(t);return r!==null&&o!==null&&Math.abs(r-o)>=G},"isPerceptibleState"),B=l(e=>e?f("#fff",e)>f("#000",e):!1,"isDarkSurface");function I(e,t,r){let o=d((0,c.parse)(e));if(!o)return null;let n={...o,l:r??o.l??0},a=t?C:-C;for(let s=0;s<25;s+=1){let u=Math.min(1,Math.max(0,(n.l??0)+a));if(u===(n.l??0))break;n={...n,l:u};let p=(0,c.formatHex)(n);if(p&&f(e,p)>=h)return p}return(0,c.formatHex)(n)??null}l(I,"derivePerceptibleState");function k(e,t,r){let o=I(e,t,r);if(o&&f(e,o)>=h)return o;let n=I(e,!t);return n&&f(e,n)>=h?n:o??n}l(k,"perceptibleStateFor");function A(e,t){let r=typeof e=="object"&&e!==null?e:void 0,o=L(e),n=t.deepDark,a=t.deepLight,s={base:o,dark:i(o,n,.6),action:i(o,n,.2),active:i(o,a,.6),light:i(o,a,.9),onLight:o};if((0,c.parse)(o)){let u=B(t.baseLight),p=T(o,s.action);if(p||(s.action=k(o,u)??s.action),!T(o,s.active)){let m=p?void 0:x(s.action)??void 0;s.active=k(o,u,m)??s.active}}if(s.onLight=S(s.action,s.light),r){let u=r.action??s.action,p=r.light??s.light;return{base:o,dark:r.dark??s.dark,action:u,active:r.active??s.active,light:p,onLight:r.onLight??S(u,p)}}return s}l(A,"mountSingleColor");function v(e){let t=e.deepLight,r=e.deepDark;return{0:t,5:i(t,r,.05),10:i(t,r,.1),20:i(t,r,.2),30:i(t,r,.3),40:i(t,r,.4),50:i(t,r,.5),60:i(t,r,.6),70:i(t,r,.7),80:i(t,r,.8),90:i(t,r,.9),100:i(t,r,1)}}l(v,"mountGreyscaleColors");function N(e){let t=e.deepLight,r=e.deepDark,o=typeof e.primary=="object"&&e.primary?e.primary.base:e.primary,n=l(s=>1/17*(s-1),"interpolation"),a=i(o,r,.5);return{0:i(a,t,n(18)),5:i(a,t,n(17.5)),10:i(a,t,n(17)),20:i(a,t,n(16)),30:i(a,t,n(15)),40:i(a,t,n(14)),50:i(a,t,n(13)),60:i(a,t,n(12)),70:i(a,t,n(11)),80:i(a,t,n(10)),90:i(a,t,n(9)),100:i(a,t,n(8)),110:i(a,t,n(7)),120:i(a,t,n(6)),130:i(a,t,n(5)),140:i(a,t,n(4)),150:i(a,t,n(3)),160:i(a,t,n(2)),170:a,180:i(a,r,.25)}}l(N,"mountNeutralColors");var _=require("@apollion-dsi/core/themes/dimension");function O({multiplier:e=.25,alias:t},r){let o=r!==void 0?_.DIMENSION_MULTIPLIERS[r]:e;return(...n)=>n.map(a=>{let s=typeof a=="string"?t[a]:a;return`${o*s}rem`}).join(" ")}l(O,"createSpacing");var b=require("@apollion-dsi/core/themes/foundation");var y=require("@apollion-dsi/core/themes/surface");var H="v1";0&&(module.exports={TOKENS_RUNTIME_API_VERSION,createFoundation,createSpacing,getOppositeColor,invertForSurface,mountGreyscaleColors,mountNeutralColors,mountSingleColor});
|
package/lib/runtime/v1.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var M=Object.defineProperty;var s=(e,t)=>M(e,"name",{value:t,configurable:!0});import{converter as I,formatHex as m,interpolate as A,parse as u,wcagContrast as k}from"culori";var d=I("oklch"),H=I("rgb");function i(e,t,r){let o=u(e),n=u(t);if(!o||!n)return e;let a=A([o,n],"oklch");return m(a(r))??e}s(i,"mixOklch");function L(e){return e?typeof e=="string"?e:e.base:"#000"}s(L,"coerceToHex");function v(e){let t=L(e),r=d(u(t));if(!r)return t;let o={...r,h:((r.h??0)+180)%360};return m(o)??t}s(v,"getOppositeColor");var h=1.3,N=.05,b=.04,f=s((e,t)=>{let r=u(e),o=u(t);return!r||!o?1:k(r,o)},"contrastRatio"),x=s(e=>{let t=d(u(e));return t?t.l??0:null},"oklchLightness"),_=4.5;function y(e,t,r=_){let o=u(t),n=d(u(e));if(!o||!n)return e;let a=f("#fff",t)>=f("#000",t)?.04:-.04;for(let c=0;c<25;c+=1){let p=m(n)??e,l=u(p);if(l&&k(l,o)>=r)return p;let g=Math.min(1,Math.max(0,(n.l??0)+a));if(g===(n.l??0))break;n={...n,l:g}}return m(n)??e}s(y,"readableColor");var C=s((e,t)=>{if(f(e,t)>=h)return!0;let r=x(e),o=x(t);return r!==null&&o!==null&&Math.abs(r-o)>=N},"isPerceptibleState"),O=s(e=>e?f("#fff",e)>f("#000",e):!1,"isDarkSurface");function S(e,t,r){let o=d(u(e));if(!o)return null;let n={...o,l:r??o.l??0},a=t?b:-b;for(let c=0;c<25;c+=1){let p=Math.min(1,Math.max(0,(n.l??0)+a));if(p===(n.l??0))break;n={...n,l:p};let l=m(n);if(l&&f(e,l)>=h)return l}return m(n)??null}s(S,"derivePerceptibleState");function T(e,t,r){let o=S(e,t,r);if(o&&f(e,o)>=h)return o;let n=S(e,!t);return n&&f(e,n)>=h?n:o??n}s(T,"perceptibleStateFor");function P(e,t){let r=typeof e=="object"&&e!==null?e:void 0,o=L(e),n=t.deepDark,a=t.deepLight,c={base:o,dark:i(o,n,.6),action:i(o,n,.2),active:i(o,a,.6),light:i(o,a,.9),onLight:o};if(u(o)){let p=O(t.baseLight),l=C(o,c.action);if(l||(c.action=T(o,p)??c.action),!C(o,c.active)){let g=l?void 0:x(c.action)??void 0;c.active=T(o,p,g)??c.active}}if(c.onLight=y(c.action,c.light),r){let p=r.action??c.action,l=r.light??c.light;return{base:o,dark:r.dark??c.dark,action:p,active:r.active??c.active,light:l,onLight:r.onLight??y(p,l)}}return c}s(P,"mountSingleColor");function E(e){let t=e.deepLight,r=e.deepDark;return{0:t,5:i(t,r,.05),10:i(t,r,.1),20:i(t,r,.2),30:i(t,r,.3),40:i(t,r,.4),50:i(t,r,.5),60:i(t,r,.6),70:i(t,r,.7),80:i(t,r,.8),90:i(t,r,.9),100:i(t,r,1)}}s(E,"mountGreyscaleColors");function R(e){let t=e.deepLight,r=e.deepDark,o=typeof e.primary=="object"&&e.primary?e.primary.base:e.primary,n=s(c=>1/17*(c-1),"interpolation"),a=i(o,r,.5);return{0:i(a,t,n(18)),5:i(a,t,n(17.5)),10:i(a,t,n(17)),20:i(a,t,n(16)),30:i(a,t,n(15)),40:i(a,t,n(14)),50:i(a,t,n(13)),60:i(a,t,n(12)),70:i(a,t,n(11)),80:i(a,t,n(10)),90:i(a,t,n(9)),100:i(a,t,n(8)),110:i(a,t,n(7)),120:i(a,t,n(6)),130:i(a,t,n(5)),140:i(a,t,n(4)),150:i(a,t,n(3)),160:i(a,t,n(2)),170:a,180:i(a,r,.25)}}s(R,"mountNeutralColors");import{DIMENSION_MULTIPLIERS as D}from"@apollion-dsi/core/themes/dimension";function F({multiplier:e=.25,alias:t},r){let o=r!==void 0?D[r]:e;return(...n)=>n.map(a=>{let c=typeof a=="string"?t[a]:a;return`${o*c}rem`}).join(" ")}s(F,"createSpacing");import{createFoundation as $}from"@apollion-dsi/core/themes/foundation";import{invertForSurface as G}from"@apollion-dsi/core/themes/surface";var X="v1";export{X as TOKENS_RUNTIME_API_VERSION,$ as createFoundation,F as createSpacing,v as getOppositeColor,G as invertForSurface,E as mountGreyscaleColors,R as mountNeutralColors,P as mountSingleColor};
|
package/package.json
CHANGED
package/src/build.ts
CHANGED
|
@@ -33,7 +33,7 @@ import { mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promise
|
|
|
33
33
|
import { tmpdir } from 'node:os';
|
|
34
34
|
import { dirname, join } from 'node:path';
|
|
35
35
|
|
|
36
|
-
import { renderCss } from './renderers/css';
|
|
36
|
+
import { renderCss, renderCssModes } from './renderers/css';
|
|
37
37
|
import { renderDesignMd } from './renderers/design-md';
|
|
38
38
|
import { renderBaseSet, renderColorSet, renderFontSet, renderResolver, renderSpacingSet } from './renderers/resolver';
|
|
39
39
|
import { renderTailwindPreset, renderTwMergeExtension } from './renderers/tailwind';
|
|
@@ -137,6 +137,33 @@ export async function build(opts: BuildOptions): Promise<BuildResult> {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
// ── Mode-scoped CSS (ADR-024): one file per (brand × surface × dimension)
|
|
141
|
+
// carrying both modes, scoped by the mode-engine attribute ─────────────────
|
|
142
|
+
if (output.cssModes) {
|
|
143
|
+
const pairs = new Map<string, { light?: Variant; dark?: Variant }>();
|
|
144
|
+
for (const variant of variants) {
|
|
145
|
+
const key = `${variant.brand}.${variant.surface}.${variant.dimension}`;
|
|
146
|
+
const entry = pairs.get(key) ?? {};
|
|
147
|
+
entry[variant.mode] = variant;
|
|
148
|
+
pairs.set(key, entry);
|
|
149
|
+
}
|
|
150
|
+
for (const [key, { light, dark }] of pairs) {
|
|
151
|
+
if (!light || !dark) {
|
|
152
|
+
throw new Error(`apollion-tokens build: output.cssModes needs both modes for ${key} (config.modes)`);
|
|
153
|
+
}
|
|
154
|
+
const l = buildVariantThemes(light);
|
|
155
|
+
const d = buildVariantThemes(dark);
|
|
156
|
+
const css = renderCssModes(
|
|
157
|
+
buildFullIR(l.foundation, l.colors, light),
|
|
158
|
+
buildFullIR(d.foundation, d.colors, dark),
|
|
159
|
+
{
|
|
160
|
+
rgbCompanions: output.tailwind,
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
await emit(`css/${key}.modes.css`, css);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
140
167
|
// ── Tailwind surface: preset + tw-merge extension (naming layer) ─────────
|
|
141
168
|
// Token *topology* is variant-invariant (same groups/keys across the axes),
|
|
142
169
|
// and every entry maps through `var(--apollion-*)` indirection — so one
|
package/src/builders/colors.ts
CHANGED
|
@@ -36,6 +36,7 @@ import type {
|
|
|
36
36
|
import { converter, formatHex, interpolate, parse, wcagContrast } from 'culori';
|
|
37
37
|
|
|
38
38
|
const toOklch = converter('oklch');
|
|
39
|
+
const toRgb = converter('rgb');
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* OKLch perceptual lerp wrapper. See core's S2 docs for rationale.
|
|
@@ -44,7 +45,7 @@ const toOklch = converter('oklch');
|
|
|
44
45
|
* §11.5) confirmou 0 unexpected regressions em 68 deltas; greyscale ramp
|
|
45
46
|
* 19× mais uniforme em OKLAB L space.
|
|
46
47
|
*/
|
|
47
|
-
function mixOklch(a: string, b: string, t: number): string {
|
|
48
|
+
export function mixOklch(a: string, b: string, t: number): string {
|
|
48
49
|
const colorA = parse(a);
|
|
49
50
|
const colorB = parse(b);
|
|
50
51
|
if (!colorA || !colorB) return a;
|
|
@@ -97,7 +98,7 @@ const MIN_CONTRAST_AA = 4.5;
|
|
|
97
98
|
* (`Colors.helpers.ts`; parity.test.ts). Used to derive the tonal ink
|
|
98
99
|
* `onLight` (APOLLION-CONTRAST-GUARANTEE).
|
|
99
100
|
*/
|
|
100
|
-
function readableColor(color: string, background: string, minRatio = MIN_CONTRAST_AA): string {
|
|
101
|
+
export function readableColor(color: string, background: string, minRatio = MIN_CONTRAST_AA): string {
|
|
101
102
|
const bgParsed = parse(background);
|
|
102
103
|
let oklch = toOklch(parse(color));
|
|
103
104
|
if (!bgParsed || !oklch) return color;
|
|
@@ -123,7 +124,7 @@ const isPerceptibleState = (base: string, candidate: string): boolean => {
|
|
|
123
124
|
return baseL !== null && candidateL !== null && Math.abs(baseL - candidateL) >= STATE_DELTA_L_JND;
|
|
124
125
|
};
|
|
125
126
|
|
|
126
|
-
const isDarkSurface = (baseLight?: string): boolean => {
|
|
127
|
+
export const isDarkSurface = (baseLight?: string): boolean => {
|
|
127
128
|
if (!baseLight) return false;
|
|
128
129
|
return contrastRatio('#fff', baseLight) > contrastRatio('#000', baseLight);
|
|
129
130
|
};
|
|
@@ -268,3 +269,33 @@ export function mountNeutralColors(colors: ColorsInput): Record<NeutralColorsTyp
|
|
|
268
269
|
'180': mixOklch(n170, darker, 0.25),
|
|
269
270
|
};
|
|
270
271
|
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Ladder primitives — Strangler Fig mirror of core's `shiftLightness` /
|
|
275
|
+
* `clampLightness` / `toRgbaString` (APOLLION-DARK-MODE-ENGINE S0). Byte parity
|
|
276
|
+
* enforced in `__tests__/parity.test.ts`.
|
|
277
|
+
*/
|
|
278
|
+
export function shiftLightness(color: string, delta: number): string {
|
|
279
|
+
const oklch = toOklch(parse(color));
|
|
280
|
+
if (!oklch) return color;
|
|
281
|
+
const l = Math.min(1, Math.max(0, (oklch.l ?? 0) + delta));
|
|
282
|
+
return formatHex({ ...oklch, l }) ?? color;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function clampLightness(color: string, range: { min?: number; max?: number }): string {
|
|
286
|
+
const oklch = toOklch(parse(color));
|
|
287
|
+
if (!oklch) return color;
|
|
288
|
+
const l = oklch.l ?? 0;
|
|
289
|
+
const min = range.min ?? 0;
|
|
290
|
+
const max = range.max ?? 1;
|
|
291
|
+
if (l >= min && l <= max) return color;
|
|
292
|
+
return formatHex({ ...oklch, l: Math.min(max, Math.max(min, l)) }) ?? color;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function toRgbaString(color: string, alpha: number): string {
|
|
296
|
+
const rgb = toRgb(parse(color));
|
|
297
|
+
if (!rgb) return color;
|
|
298
|
+
const a = Math.min(1, Math.max(0, alpha));
|
|
299
|
+
const channel = (value?: number): number => Math.round((value ?? 0) * 255);
|
|
300
|
+
return `rgba(${channel(rgb.r)}, ${channel(rgb.g)}, ${channel(rgb.b)}, ${a})`;
|
|
301
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface ladder builder — **Strangler Fig duplicate** of
|
|
3
|
+
* `@apollion-dsi/core/themes/colors` `Colors.ladder.ts` (ADR-023,
|
|
4
|
+
* APOLLION-DARK-MODE-ENGINE). Same contract as `./colors.ts`: the derivation
|
|
5
|
+
* logic is duplicated (pure culori), the constants and the APCA math are
|
|
6
|
+
* imported from the stable core subpath (data, not logic), and parity is
|
|
7
|
+
* enforced in `__tests__/parity.test.ts` — drift = build fail.
|
|
8
|
+
*
|
|
9
|
+
* @see ./colors.ts (Strangler Fig contract notes)
|
|
10
|
+
* @see ../../../core/src/themes/Colors/Colors.ladder.ts (source of truth)
|
|
11
|
+
*/
|
|
12
|
+
import type { LadderGroups, LadderInput, LadderOverride, Polarity } from '@apollion-dsi/core/themes/colors';
|
|
13
|
+
import {
|
|
14
|
+
apcaContrast,
|
|
15
|
+
EDGE_ALPHA,
|
|
16
|
+
HALATION_FLOORS,
|
|
17
|
+
INK_APCA_MIN,
|
|
18
|
+
INK_MIX,
|
|
19
|
+
LADDER_DELTAS,
|
|
20
|
+
MIN_CONTRAST_AA,
|
|
21
|
+
WASH_ALPHA,
|
|
22
|
+
} from '@apollion-dsi/core/themes/colors';
|
|
23
|
+
|
|
24
|
+
import { clampLightness, isDarkSurface, mixOklch, readableColor, shiftLightness, toRgbaString } from './colors';
|
|
25
|
+
|
|
26
|
+
const FALLBACK_LIGHT = '#FFFFFF';
|
|
27
|
+
const FALLBACK_DARK = '#000000';
|
|
28
|
+
|
|
29
|
+
export function resolvePolarity(colors: LadderInput): Polarity {
|
|
30
|
+
return isDarkSurface(colors.baseLight) ? 'dark' : 'light';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function ensureApca(ink: string, ground: string, minLc: number): string {
|
|
34
|
+
if (Math.abs(apcaContrast(ink, ground)) >= minLc) return ink;
|
|
35
|
+
const towardLight = Math.abs(apcaContrast('#ffffff', ground)) >= Math.abs(apcaContrast('#000000', ground));
|
|
36
|
+
let current = ink;
|
|
37
|
+
for (let i = 0; i < 40; i += 1) {
|
|
38
|
+
const next = shiftLightness(current, towardLight ? 0.02 : -0.02);
|
|
39
|
+
if (next === current) break;
|
|
40
|
+
current = next;
|
|
41
|
+
if (Math.abs(apcaContrast(current, ground)) >= minLc) break;
|
|
42
|
+
}
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function deriveSurface(colors: LadderInput, polarity: Polarity): LadderGroups['surface'] {
|
|
47
|
+
const baseLight = colors.baseLight ?? FALLBACK_LIGHT;
|
|
48
|
+
const isDark = polarity === 'dark';
|
|
49
|
+
const canvas = isDark ? clampLightness(baseLight, { min: HALATION_FLOORS.CANVAS_MIN_L }) : baseLight;
|
|
50
|
+
const sunkenRaw = shiftLightness(canvas, LADDER_DELTAS.sunken);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
canvas,
|
|
54
|
+
sunken: isDark ? clampLightness(sunkenRaw, { min: HALATION_FLOORS.CANVAS_MIN_L }) : sunkenRaw,
|
|
55
|
+
paper: shiftLightness(canvas, LADDER_DELTAS.paper),
|
|
56
|
+
raised: shiftLightness(canvas, LADDER_DELTAS.raised),
|
|
57
|
+
overlay: shiftLightness(canvas, LADDER_DELTAS.overlay),
|
|
58
|
+
scrim: isDark ? (colors.deepLight ?? FALLBACK_DARK) : (colors.neutral?.['180'] ?? colors.baseDark ?? FALLBACK_DARK),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function deriveInk(colors: LadderInput, surface: LadderGroups['surface']): LadderGroups['ink'] {
|
|
63
|
+
const baseDark = colors.baseDark ?? FALLBACK_DARK;
|
|
64
|
+
const primary = clampLightness(
|
|
65
|
+
ensureApca(readableColor(baseDark, surface.paper, MIN_CONTRAST_AA), surface.paper, INK_APCA_MIN.primary),
|
|
66
|
+
{ max: HALATION_FLOORS.INK_MAX_L },
|
|
67
|
+
);
|
|
68
|
+
const tier = (mix: number, minLc: number): string =>
|
|
69
|
+
ensureApca(
|
|
70
|
+
readableColor(mixOklch(primary, surface.canvas, mix), surface.paper, MIN_CONTRAST_AA),
|
|
71
|
+
surface.paper,
|
|
72
|
+
minLc,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
primary,
|
|
77
|
+
secondary: tier(INK_MIX.secondary, INK_APCA_MIN.secondary),
|
|
78
|
+
muted: tier(INK_MIX.muted, INK_APCA_MIN.muted),
|
|
79
|
+
disabled: mixOklch(primary, surface.canvas, INK_MIX.disabled),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function deriveEdge(ink: LadderGroups['ink']): LadderGroups['edge'] {
|
|
84
|
+
return {
|
|
85
|
+
hairline: toRgbaString(ink.primary, EDGE_ALPHA.hairline),
|
|
86
|
+
border: toRgbaString(ink.primary, EDGE_ALPHA.border),
|
|
87
|
+
strong: toRgbaString(ink.primary, EDGE_ALPHA.strong),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function deriveWash(ink: LadderGroups['ink'], polarity: Polarity): LadderGroups['wash'] {
|
|
92
|
+
const alpha = WASH_ALPHA[polarity];
|
|
93
|
+
return {
|
|
94
|
+
hover: toRgbaString(ink.primary, alpha.hover),
|
|
95
|
+
pressed: toRgbaString(ink.primary, alpha.pressed),
|
|
96
|
+
selected: toRgbaString(ink.primary, alpha.selected),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function applyOverride(groups: LadderGroups, override?: LadderOverride): LadderGroups {
|
|
101
|
+
if (!override) return groups;
|
|
102
|
+
return {
|
|
103
|
+
surface: { ...groups.surface, ...override.surface },
|
|
104
|
+
ink: { ...groups.ink, ...override.ink },
|
|
105
|
+
edge: { ...groups.edge, ...override.edge },
|
|
106
|
+
wash: { ...groups.wash, ...override.wash },
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function resolveSurfaceLadder(colors: LadderInput, override?: LadderInput['ladder']): LadderGroups {
|
|
111
|
+
const polarity = resolvePolarity(colors);
|
|
112
|
+
const surface = deriveSurface(colors, polarity);
|
|
113
|
+
const ink = deriveInk(colors, surface);
|
|
114
|
+
const derived: LadderGroups = { surface, ink, edge: deriveEdge(ink), wash: deriveWash(ink, polarity) };
|
|
115
|
+
return applyOverride(derived, override?.[polarity]);
|
|
116
|
+
}
|
package/src/config-schema.ts
CHANGED
|
@@ -45,6 +45,11 @@ export interface ApollionOutputFlags {
|
|
|
45
45
|
* channel-triplet companion vars to `dist/css/` so opaque colour tokens
|
|
46
46
|
* support Tailwind's alpha modifier. See `renderers/tailwind.ts`. */
|
|
47
47
|
tailwind?: boolean;
|
|
48
|
+
/** `dist/css/<brand>.<surface>.<dimension>.modes.css` — both modes in ONE file,
|
|
49
|
+
* scoped by `html[data-apollion-mode]` (+ `prefers-color-scheme` fallback) the
|
|
50
|
+
* way the core mode engine scopes them (ADR-024). Requires `modes` to include
|
|
51
|
+
* both `light` and `dark`. See `renderers/css.ts` (`renderCssModes`). */
|
|
52
|
+
cssModes?: boolean;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export interface ApollionConfig {
|