@apollion-dsi/tokens 4.1.0 → 4.2.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 +4 -4
- package/lib/build.cjs +6 -5
- package/lib/build.esm.js +6 -5
- package/lib/cli.mjs +8 -7
- package/package.json +4 -2
- package/src/build.ts +60 -26
- package/src/ir.ts +330 -20
- package/src/renderers/dtcg-project.ts +108 -0
- package/src/renderers/json.ts +17 -99
- package/src/renderers/resolver.ts +129 -0
- package/src/set-plan.ts +136 -0
- package/src/token-meta.ts +86 -0
package/README.md
CHANGED
|
@@ -19,14 +19,14 @@ import { TOKENS_RUNTIME_API_VERSION } from '@apollion-dsi/tokens/runtime/v1';
|
|
|
19
19
|
- **In:** OKLch palette derivation (S2/S4), Dimension axis (S3), Foundation/Surface builders (S4), build-time CSS/JSON/TS variant emission (S5), Config-First loader (S6).
|
|
20
20
|
- **Out:** Runtime React components (lives in `@apollion-dsi/core`), framework adapters (Vue/Flutter consumers consume `dist/json/*.json` directly).
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## JSON output (`dist/json/*.json`)
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Tokens em JSON estruturado — values are **structured objects**, not shorthand strings:
|
|
25
25
|
|
|
26
|
-
- `color` → `{ "colorSpace": "oklch", "components": [L, C, H], "hex": "#rrggbb" }` — OKLch working space
|
|
26
|
+
- `color` → `{ "colorSpace": "oklch", "components": [L, C, H], "hex": "#rrggbb" }` — OKLch working space + sRGB `hex` fallback. `alpha` emitted only when below 1.
|
|
27
27
|
- `dimension` → `{ "value": <number>, "unit": "rem" }`.
|
|
28
28
|
|
|
29
|
-
`dist/css/*.css` and `dist/ts/*.d.ts` stay string-based (hex / `rem`) — JSON is the
|
|
29
|
+
`dist/css/*.css` and `dist/ts/*.d.ts` stay string-based (hex / `rem`) — JSON is the interop surface; CSS/TS are the resolved consumer surfaces.
|
|
30
30
|
|
|
31
31
|
## Coupling to `@apollion-dsi/core`
|
|
32
32
|
|
package/lib/build.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var be=Object.prototype.hasOwnProperty;var s=(e,o)=>w(e,"name",{value:o,configurable:!0});var Re=(e,o)=>{for(var n in o)w(e,n,{get:o[n],enumerable:!0})},ke=(e,o,n,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of he(o))!be.call(e,i)&&i!==n&&w(e,i,{get:()=>o[i],enumerable:!(r=ye(o,i))||r.enumerable});return e};var Ie=e=>ke(w({},"__esModule",{value:!0}),e);var ze={};Re(ze,{build:()=>_e,check:()=>Je});module.exports=Ie(ze);var u=require("node:fs/promises"),de=require("node:os"),b=require("node:path");var C=require("@apollion-dsi/core/themes/border"),v=require("@apollion-dsi/core/themes/depth"),h=require("@apollion-dsi/core/themes/font"),k=require("culori");var xe=(0,k.converter)("oklch");function R(e){return typeof e.type=="string"&&"value"in e}s(R,"isToken");function I(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(I,"kebab");function W(e){return e.split(".").map(I).join(".")}s(W,"kebabPath");function x(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(x,"rawValue");function S(e,o){return Number(e.toFixed(o))||0}s(S,"round");function G(e){let o=xe((0,k.parse)(e));if(!o)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let n=[S(o.l,4),S(o.c,4),S(o.h??0,2)],r=(0,k.formatHex)(o)??"#000000";return o.alpha!==void 0&&o.alpha!==1?{kind:"color",raw:e,components:n,alpha:S(o.alpha,4),hex:r}:{kind:"color",raw:e,components:n,hex:r}}s(G,"toColorValue");var _=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function $(e){let o=_.exec(e.trim());if(o)return{kind:"dimension",raw:e,value:Number(o[1]),unit:o[2]};let n=Number.parseFloat(e);return{kind:"dimension",raw:e,value:Number.isFinite(n)?n:0,unit:"rem"}}s($,"toDimensionValue");function d(e){return{type:"color",value:G(e)}}s(d,"colorToken");function H(e){let o={};for(let[n,r]of Object.entries(e))o[n]=d(r);return o}s(H,"recordColorGroup");var De=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function Ve(e){let o={};for(let n of De){let r=e[n];o[n]={base:d(r.base),dark:d(r.dark),action:d(r.action),active:d(r.active),light:d(r.light)}}return o.grayscale=H(e.grayscale),o.neutral=H(e.neutral),o.baseDark=d(e.baseDark??"#000000"),o.baseLight=d(e.baseLight??"#ffffff"),o.deepDark=d(e.deepDark??"#000000"),o.deepLight=d(e.deepLight??"#ffffff"),o}s(Ve,"buildPrimitives");var Te={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"},we={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function Se(e,o){let n=e;for(let r of o.split(".").slice(1))if(n&&typeof n=="object"&&r in n)n=n[r];else return;return typeof n=="string"?n:void 0}s(Se,"lookupPrimitive");function P(e,o,n){let r={};for(let[i,t]of Object.entries(e)){let c=n[i],l=c?Se(o,c):void 0;r[i]=c&&l===t?{type:"color",value:{kind:"ref",path:c,resolved:G(t)}}:d(t)}return r}s(P,"colorRefGroup");function Ce(e){let o={};for(let[n,r]of Object.entries(e))o[n]={type:"dimension",value:$(r)};return o}s(Ce,"dimensionGroup");function $e(){let e={},o={};for(let[i,t]of Object.entries(C.defaultInputBorder.borderRadius))_.test(t)?e[i]={type:"dimension",value:$(t)}:o[i]=t;let n={};for(let[i,t]of Object.entries(C.defaultInputBorder.borderWidth))n[i]={type:"dimension",value:$(t)};let r={};for(let[i,t]of Object.entries(C.defaultInputBorder.borderStyle))r[i]={type:"strokeStyle",value:{kind:"strokeStyle",raw:t,style:t}};return{group:{radius:e,width:n,style:r},extensions:o}}s($e,"buildBorder");function ve(){let e={};for(let[t,c]of Object.entries(h.defaultInputFont.fontFamily)){let l=c.replace(/;\s*$/,"").trim();e[t]={type:"fontFamily",value:{kind:"fontFamily",raw:l,family:l}}}let o={};for(let[t,c]of Object.entries(h.defaultInputFont.fontSize))o[t]={type:"dimension",value:{kind:"dimension",raw:`${c}px`,value:c,unit:"px"}};let n={};for(let[t,c]of Object.entries(h.defaultInputFont.fontWeight))n[t]={type:"fontWeight",value:{kind:"fontWeight",raw:`${c}`,weight:c}};let r={};for(let[t,c]of Object.entries(h.defaultInputFont.lineHeight))r[t]={type:"number",value:{kind:"number",raw:`${c}`,number:c}};let i={letterSpacing:h.defaultInputFont.letterSpacing,textTransform:h.defaultInputFont.textTransform,fontStyle:h.defaultInputFont.fontStyle};return{group:{family:e,size:o,weight:n,lineHeight:r},extensions:i}}s(ve,"buildFont");var Oe=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function Fe(e){let o=e.trim(),n=o.startsWith("inset");n&&(o=o.slice(5).trim());let r=o.match(Oe),i=r?r[0]:"#000000",c=(r?o.slice(0,r.index).trim():o).split(/\s+/).filter(Boolean),l=s(p=>$(c[p]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:G(i),offsetX:l(0),offsetY:l(1),blur:l(2),spread:l(3),inset:n}}}s(Fe,"parseShadow");function je(e){let o=(0,v.createDeth)(e),n={};for(let r of Object.keys(v.levelValues))n[r]={type:"shadow",value:Fe(o(r))};return n}s(je,"buildShadow");function J(e,o,n){let r={brand:n.brand,mode:n.mode,surface:n.surface,dimension:n.dimension},i=$e(),t=ve(),c={"com.apollion.variant":r,"com.apollion.font":t.extensions};return Object.keys(i.extensions).length>0&&(c["com.apollion.border"]={radius:i.extensions}),{description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${r.brand}/${r.mode}/${r.surface}/${r.dimension}.`,meta:r,primitives:Ve(o),groups:{bg:P(e.bg,o,Te),text:P(e.text,o,we),spacing:Ce(e.spacing),border:i.group,font:t.group,shadow:je(o)},extensions:c}}s(J,"buildIR");var Ee="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function z(e,o,n){for(let[r,i]of Object.entries(e)){let t=[...o,I(r)];R(i)?n.push(` --apollion-${t.join("-")}: ${x(i.value)};`):z(i,t,n)}}s(z,"emitVars");function X(e,o,n){for(let[r,i]of Object.entries(e)){let t=[...o,I(r)];R(i)?i.type==="color"&&n.push(` @property --apollion-${t.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${x(i.value)}; }`):X(i,t,n)}}s(X,"emitProperties");function U(e){let{brand:o,mode:n,surface:r,dimension:i}=e.meta,t=[Ee,""];return t.push(`/* Variant: brand=${o} mode=${n} surface=${r} dimension=${i} */`,"",":root {"),z(e.groups,[],t),t.push("}",""),t.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),X(e.groups,[],t),t.push("}",""),t.join(`
|
|
2
|
-
`)}s(
|
|
3
|
-
`}s(
|
|
4
|
-
`
|
|
5
|
-
`}s(
|
|
1
|
+
"use strict";var j=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Xe=Object.prototype.hasOwnProperty;var s=(e,n)=>j(e,"name",{value:n,configurable:!0});var Ye=(e,n)=>{for(var o in n)j(e,o,{get:n[o],enumerable:!0})},qe=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ze(n))!Xe.call(e,i)&&i!==o&&j(e,i,{get:()=>n[i],enumerable:!(r=Ue(n,i))||r.enumerable});return e};var Ke=e=>qe(j({},"__esModule",{value:!0}),e);var wn={};Ye(wn,{build:()=>Sn,check:()=>xn});module.exports=Ke(wn);var f=require("node:fs/promises"),Je=require("node:os"),x=require("node:path");var C=require("@apollion-dsi/core/themes/border"),L=require("@apollion-dsi/core/themes/depth"),S=require("@apollion-dsi/core/themes/font"),z=require("@apollion-dsi/core/themes/spacing"),v=require("culori");var te=require("@apollion-dsi/core/themes/dimension");function M({multiplier:e=.25,alias:n},o){let r=o!==void 0?te.DIMENSION_MULTIPLIERS[o]:e;return(...i)=>i.map(t=>{let a=typeof t=="string"?n[t]:t;return`${r*a}rem`}).join(" ")}s(M,"createSpacing");var J={"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 U(e){let n=Object.keys(J).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(U,"assertTokenMetaResolves");var Ze=(0,v.converter)("oklch");function h(e){return typeof e.type=="string"&&"value"in e}s(h,"isToken");function R(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(R,"kebab");function se(e){return e.split(".").map(R).join(".")}s(se,"kebabPath");function V(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(V,"rawValue");function F(e,n){return Number(e.toFixed(n))||0}s(F,"round");function X(e){let n=Ze((0,v.parse)(e));if(!n)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let o=[F(n.l,4),F(n.c,4),F(n.h??0,2)],r=(0,v.formatHex)(n)??"#000000";return n.alpha!==void 0&&n.alpha!==1?{kind:"color",raw:e,components:o,alpha:F(n.alpha,4),hex:r}:{kind:"color",raw:e,components:o,hex:r}}s(X,"toColorValue");var ae=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function T(e){let n=ae.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(T,"toDimensionValue");function y(e){return{type:"color",value:X(e)}}s(y,"colorToken");function ie(e){let n={};for(let[o,r]of Object.entries(e))n[o]=y(r);return n}s(ie,"recordColorGroup");var Qe=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function ce(e){let n={};for(let o of Qe){let r=e[o];n[o]={base:y(r.base),dark:y(r.dark),action:y(r.action),active:y(r.active),light:y(r.light)}}return n.grayscale=ie(e.grayscale),n.neutral=ie(e.neutral),n.baseDark=y(e.baseDark??"#000000"),n.baseLight=y(e.baseLight??"#ffffff"),n.deepDark=y(e.deepDark??"#000000"),n.deepLight=y(e.deepLight??"#ffffff"),n}s(ce,"buildColorPrimitives");function le(e){let n=M(z.defaultInputSpacing,e),o={};for(let r of Object.keys(z.defaultInputSpacing.alias))o[r]={type:"dimension",value:T(n(r))};return o}s(le,"buildSpacePrimitives");function de(){let e={};for(let[n,o]of Object.entries(C.defaultInputBorder.borderWidth))e[n]={type:"dimension",value:T(o)};return e}s(de,"buildBorderWidthPrimitives");function en(e,n){return{color:ce(e),space:le(n),borderWidth:de()}}s(en,"buildPrimitives");var ue={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"},pe={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function nn(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(nn,"lookupPrimitive");function A(e,n,o){let r={};for(let[i,t]of Object.entries(e)){let a=o[i],l=a?nn(n,a):void 0;r[i]=a&&l===t?{type:"color",value:{kind:"ref",path:a,resolved:X(t)}}:y(t)}return r}s(A,"colorRefGroup");var fe={xs:"space.xs",sm:"space.small",md:"space.medium",lg:"space.large",xl:"space.xl",xxl:"space.xxl"},on={none:"border-width.none",thin:"border-width.thin",regular:"border-width.regular",great:"border-width.great",bold:"border-width.bold"};function rn(e,n){let o=n.split("."),r=o[0]==="border-width"?"borderWidth":o[0],i=e[r];for(let t of o.slice(1))if(i&&!h(i)&&t in i)i=i[t];else return;return i&&h(i)&&i.value.kind==="dimension"?i.value.raw:void 0}s(rn,"lookupDimensionPrimitive");function Y(e,n,o){let r={};for(let[i,t]of Object.entries(e)){let a=o[i],l=a?rn(n,a):void 0;r[i]=a&&l===t?{type:"dimension",value:{kind:"ref",path:a,resolved:T(t)}}:{type:"dimension",value:T(t)}}return r}s(Y,"dimensionRefGroup");function me(e){let n={},o={};for(let[t,a]of Object.entries(C.defaultInputBorder.borderRadius))ae.test(a)?n[t]={type:"dimension",value:T(a)}:o[t]=a;let r=Y(C.defaultInputBorder.borderWidth,e,on),i={};for(let[t,a]of Object.entries(C.defaultInputBorder.borderStyle))i[t]={type:"strokeStyle",value:{kind:"strokeStyle",raw:a,style:a}};return{group:{radius:n,width:r,style:i},extensions:o}}s(me,"buildBorder");function ge(){let e={};for(let[t,a]of Object.entries(S.defaultInputFont.fontFamily)){let l=a.replace(/;\s*$/,"").trim();e[t]={type:"fontFamily",value:{kind:"fontFamily",raw:l,family:l}}}let n={};for(let[t,a]of Object.entries(S.defaultInputFont.fontSize))n[t]={type:"dimension",value:{kind:"dimension",raw:`${a}px`,value:a,unit:"px"}};let o={};for(let[t,a]of Object.entries(S.defaultInputFont.fontWeight))o[t]={type:"fontWeight",value:{kind:"fontWeight",raw:`${a}`,weight:a}};let r={};for(let[t,a]of Object.entries(S.defaultInputFont.lineHeight))r[t]={type:"number",value:{kind:"number",raw:`${a}`,number:a}};let i={letterSpacing:S.defaultInputFont.letterSpacing,textTransform:S.defaultInputFont.textTransform,fontStyle:S.defaultInputFont.fontStyle};return{group:{family:e,size:n,weight:o,lineHeight:r},extensions:i}}s(ge,"buildFont");var tn=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function sn(e){let n=e.trim(),o=n.startsWith("inset");o&&(n=n.slice(5).trim());let r=n.match(tn),i=r?r[0]:"#000000",a=(r?n.slice(0,r.index).trim():n).split(/\s+/).filter(Boolean),l=s(m=>T(a[m]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:X(i),offsetX:l(0),offsetY:l(1),blur:l(2),spread:l(3),inset:o}}}s(sn,"parseShadow");function ye(e){let n=(0,L.createDeth)(e),o={};for(let r of Object.keys(L.levelValues))o[r]={type:"shadow",value:sn(n(r))};return o}s(ye,"buildShadow");function N(e,n,o){let r={};for(let[i,t]of Object.entries(e)){let a=n?`${n}.${R(i)}`:R(i);if(h(t)){o.add(a);let l=J[a];r[i]=l&&(l.description!==void 0||l.deprecated!==void 0)?{...t,...l.description!==void 0?{description:l.description}:{},...l.deprecated!==void 0?{deprecated:l.deprecated}:{}}:t}else r[i]=N(t,a,o)}return r}s(N,"decorateGroup");function an(e){let n=new Set,o=N(e.primitives,"",n),r=N(e.groups,"",n);return U(n),{...e,primitives:o,groups:r}}s(an,"decorateMeta");function q(e,n){return N(e,"",n)}s(q,"decorateSlice");function he(e,n,o){for(let[r,i]of Object.entries(e)){let t=n?`${n}.${R(r)}`:R(r);h(i)?o.add(t):he(i,t,o)}}s(he,"collectPaths");function be(e){let n=new Set;for(let o of e)he(o.groups,"",n);U(n)}s(be,"assertSlicesMetaComplete");function Re(){let e=de(),o=me({borderWidth:e}),r=ge(),i={"com.apollion.font":r.extensions};Object.keys(o.extensions).length>0&&(i["com.apollion.border"]={radius:o.extensions});let t=new Set;return{groups:q({"border-width":e,border:o.group,font:r.group},t),extensions:i}}s(Re,"buildBaseIR");function Ie(e,n){let o=ce(n),r=new Set;return{groups:q({color:o,bg:A(e.bg,n,ue),text:A(e.text,n,pe),shadow:ye(n)},r),extensions:{}}}s(Ie,"buildColorIR");function ke(e,n){let o=le(n),r={space:o},i=new Set;return{groups:q({space:o,spacing:Y(e.spacing,r,fe)},i),extensions:{}}}s(ke,"buildSpacingIR");function cn(e,n,o){let r={brand:o.brand,mode:o.mode,surface:o.surface,dimension:o.dimension},i=en(n,o.dimension),t=me(i),a=ge(),l={"com.apollion.variant":r,"com.apollion.font":a.extensions};Object.keys(t.extensions).length>0&&(l["com.apollion.border"]={radius:t.extensions});let m={description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${r.brand}/${r.mode}/${r.surface}/${r.dimension}.`,meta:r,primitives:i,groups:{bg:A(e.bg,n,ue),text:A(e.text,n,pe),spacing:Y(e.spacing,i,fe),border:t.group,font:a.group,shadow:ye(n)},extensions:l};return an(m)}s(cn,"buildIR");var Se=cn;var ln="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function xe(e,n,o){for(let[r,i]of Object.entries(e)){let t=[...n,R(r)];h(i)?o.push(` --apollion-${t.join("-")}: ${V(i.value)};`):xe(i,t,o)}}s(xe,"emitVars");function De(e,n,o){for(let[r,i]of Object.entries(e)){let t=[...n,R(r)];h(i)?i.type==="color"&&o.push(` @property --apollion-${t.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${V(i.value)}; }`):De(i,t,o)}}s(De,"emitProperties");function we(e){let{brand:n,mode:o,surface:r,dimension:i}=e.meta,t=[ln,""];return t.push(`/* Variant: brand=${n} mode=${o} surface=${r} dimension=${i} */`,"",":root {"),xe(e.groups,[],t),t.push("}",""),t.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),De(e.groups,[],t),t.push("}",""),t.join(`
|
|
2
|
+
`)}s(we,"renderCss");function Te(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(Te,"colorValue");function $(e){return{value:e.value,unit:e.unit}}s($,"dimensionValue");function dn(e){let n=e.shadow,o={color:Te(n.color),offsetX:$(n.offsetX),offsetY:$(n.offsetY),blur:$(n.blur),spread:$(n.spread)};return n.inset&&(o.inset=!0),o}s(dn,"shadowValue");function un(e){switch(e.kind){case"ref":return`{${se(e.path)}}`;case"color":return Te(e);case"dimension":return $(e);case"fontFamily":return e.family;case"fontWeight":return e.weight;case"number":return e.number;case"strokeStyle":return e.style;case"shadow":return dn(e)}}s(un,"projectValue");function pn(e){let n={$value:un(e.value),$type:e.type};return e.description!==void 0&&(n.$description=e.description),e.deprecated!==void 0&&(n.$deprecated=e.deprecated),n}s(pn,"projectToken");function K(e){let n={};for(let[o,r]of Object.entries(e))n[R(o)]=h(r)?pn(r):K(r);return n}s(K,"projectGroup");function Z(e,n){let o={$description:n,...K(e.groups)};return Object.keys(e.extensions).length>0&&(o.$extensions=e.extensions),`${JSON.stringify(o,null,2)}
|
|
3
|
+
`}s(Z,"renderSet");function ve(e){return Z(e,"Apollion DS \u2014 base set (axis-invariant: border + font). DTCG 2025.10.")}s(ve,"renderBaseSet");function Ce(e,n,o,r){return Z(e,`Apollion DS \u2014 colour set. brand=${n} mode=${o} surface=${r}. DTCG 2025.10.`)}s(Ce,"renderColorSet");function Ve(e,n){return Z(e,`Apollion DS \u2014 spacing set. dimension=${n}. DTCG 2025.10.`)}s(Ve,"renderSpacingSet");function $e(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]}],t={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 set 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.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}"}},modeIsPlaceholder:!0}}};return`${JSON.stringify(t,null,2)}
|
|
4
|
+
`}s($e,"renderResolver");var fn="// Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs.";function Ge(e,n,o){let r=" ".repeat(n);for(let[i,t]of Object.entries(e))h(t)?o.push(`${r}${JSON.stringify(i)}: ${JSON.stringify(V(t.value))},`):(o.push(`${r}${i}: {`),Ge(t,n+1,o),o.push(`${r}},`))}s(Ge,"emitGroup");function Oe(e){let{brand:n,mode:o,surface:r,dimension:i}=e.meta,t=[fn,`// Variant: brand=${n} mode=${o} surface=${r} dimension=${i}`,"","export const tokens = {"];return Ge(e.groups,1,t),t.push("} as const;","","export type Tokens = typeof tokens;",""),t.join(`
|
|
5
|
+
`)}s(Oe,"renderTs");var mn=["light","dark"],gn=["positive","negative"],yn=["compact","normal","spacious"];function P(e){let n=e.modes??mn,o=e.surfaces??gn,r=e.dimensions??yn,i=Object.entries(e.brands).sort(([a],[l])=>a.localeCompare(l)),t=[];for(let[a,l]of i)for(let m of n)for(let g of o)for(let d of r)t.push({brand:a,colors:l,mode:m,surface:g,dimension:d});return t}s(P,"expandVariants");function Ee(e){return`${e.brand}.${e.mode}.${e.surface}.${e.dimension}`}s(Ee,"variantName");var je=require("node:crypto");function ee(e){return(0,je.createHash)("sha256").update(e).digest("hex")}s(ee,"sha256");function ne(e){return ee(Q(e))}s(ne,"hashConfig");function Q(e){return e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?`[${e.map(Q).join(",")}]`:`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${Q(e[r])}`).join(",")}}`}s(Q,"stableStringify");function Me(e){try{let{execSync:n}=require("node:child_process");return n("git rev-parse --short HEAD",{cwd:e,stdio:["ignore","pipe","ignore"],encoding:"utf8"}).trim()}catch{return""}}s(Me,"detectGitCommit");function Fe(){return{node:process.version,platform:`${process.platform}-${process.arch}`}}s(Fe,"buildEnv");function Ae(e){let n=[...e.files].sort((r,i)=>r.path.localeCompare(i.path)),o={configHash:e.configHash,files:n,gitCommit:e.gitCommit,buildEnv:e.buildEnv};return`${JSON.stringify(o,null,2)}
|
|
6
|
+
`}s(Ae,"serializeManifest");var hn="json/sets",Ne="json/resolver.json";function oe(e){return`${hn}/${e}.json`}s(oe,"setFile");function bn(e,n,o){return`${e}.color.${n}.${o}`}s(bn,"colorSetName");function Rn(e){return`spacing.${e}`}s(Rn,"spacingSetName");function B(e,n){e.includes(n)||e.push(n)}s(B,"pushUnique");function Le(e){let n=P(e),o=[],r=[],i=[],t=[],a=new Set,l=[],m=new Set,g=[];for(let d of n){B(o,d.brand),B(r,d.mode),B(i,d.surface),B(t,d.dimension);let D=bn(d.brand,d.mode,d.surface);a.has(D)||(a.add(D),l.push({kind:"color",name:D,file:oe(D),brand:d.brand,mode:d.mode,surface:d.surface}));let u=Rn(d.dimension);m.has(u)||(m.add(u),g.push({kind:"spacing",name:u,file:oe(u),dimension:d.dimension}))}return{base:{kind:"base",name:"base",file:oe("base")},spacing:g,color:l,modifiers:{brand:o,mode:r,surface:i,dimension:t}}}s(Le,"planSets");var re=require("@apollion-dsi/core/themes/foundation"),_e=require("@apollion-dsi/core/themes/semantic"),He=require("@apollion-dsi/core/themes/spacing"),We=require("@apollion-dsi/core/themes/surface");var k=require("culori");var eo=(0,k.converter)("oklch");function c(e,n,o){let r=(0,k.parse)(e),i=(0,k.parse)(n);if(!r||!i)return e;let t=(0,k.interpolate)([r,i],"oklch");return(0,k.formatHex)(t(o))??e}s(c,"mixOklch");function In(e){return e?typeof e=="string"?e:e.base:"#000"}s(In,"coerceToHex");function b(e,n){let o=In(e),r=n.deepDark,i=n.deepLight;return{base:o,dark:c(o,r,.6),action:c(o,r,.2),active:c(o,i,.6),light:c(o,i,.9)}}s(b,"mountSingleColor");function Pe(e){let n=e.deepLight,o=e.deepDark;return{0:n,5:c(n,o,.05),10:c(n,o,.1),20:c(n,o,.2),30:c(n,o,.3),40:c(n,o,.4),50:c(n,o,.5),60:c(n,o,.6),70:c(n,o,.7),80:c(n,o,.8),90:c(n,o,.9),100:c(n,o,1)}}s(Pe,"mountGreyscaleColors");function Be(e){let n=e.deepLight,o=e.deepDark,r=e.primary,i=s(a=>1/17*(a-1),"interpolation"),t=c(r,o,.5);return{0:c(t,n,i(18)),5:c(t,n,i(17.5)),10:c(t,n,i(17)),20:c(t,n,i(16)),30:c(t,n,i(15)),40:c(t,n,i(14)),50:c(t,n,i(13)),60:c(t,n,i(12)),70:c(t,n,i(11)),80:c(t,n,i(10)),90:c(t,n,i(9)),100:c(t,n,i(8)),110:c(t,n,i(7)),120:c(t,n,i(6)),130:c(t,n,i(5)),140:c(t,n,i(4)),150:c(t,n,i(3)),160:c(t,n,i(2)),170:t,180:c(t,o,.25)}}s(Be,"mountNeutralColors");function kn(e){return{baseDark:e.baseDark,baseLight:e.baseLight,deepDark:e.deepDark,deepLight:e.deepLight,transparent:e.transparent??"transparent",neutral:Be(e),grayscale:Pe(e),main:b(e.main,e),opposite:b(e.opposite,e),complementary:b(e.complementary,e),danger:b(e.danger,e),information:b(e.information,e),success:b(e.success,e),warning:b(e.warning,e),primary:b(e.primary,e),secondary:b(e.secondary,e),tertiary:b(e.tertiary,e)}}s(kn,"composeColors");function _(e,n=He.defaultInputSpacing){let o=kn(e.colors),r=M(n,e.dimension),i=(0,_e.createSemantic)({colors:o,spacing:r}),t=(0,re.createFoundation)(i);return e.surface==="negative"&&(t=(0,re.createFoundation)((0,We.invertForSurface)({semantic:i,colors:o},"negative").semantic)),{foundation:t,colors:o}}s(_,"buildVariantThemes");async function Sn(e){let{config:n,outDir:o,cwd:r=process.cwd(),verbose:i=!1}=e,t=P(n),a=n.output??{};if(t.length===0)throw new Error("apollion-tokens build: no variants (config.brands is empty)");let l=await(0,f.mkdtemp)((0,x.join)((0,Je.tmpdir)(),"apollion-tokens-"));try{let m=[],g=s(async(u,I)=>{await Dn(l,u,I),m.push({path:u,sha256:ee(I)}),i&&console.log(` \u2713 ${u}`)},"emit");if(a.json){let u=Le(n),I=[],G=Re();I.push(G),await g(u.base.file,ve(G));for(let p of u.spacing){let w=t.find(E=>E.dimension===p.dimension),{foundation:H}=_(w),O=ke(H,p.dimension);I.push(O),await g(p.file,Ve(O,p.dimension))}for(let p of u.color){let w=t.find(W=>W.brand===p.brand&&W.mode===p.mode&&W.surface===p.surface),{foundation:H,colors:O}=_(w),E=Ie(H,O);I.push(E),await g(p.file,Ce(E,p.brand,p.mode,p.surface))}be(I),await g(Ne,$e(n,u))}if(a.css||a.ts)for(let u of t){let{foundation:I,colors:G}=_(u),p=Se(I,G,u),w=Ee(u);a.css&&await g(`css/${w}.css`,we(p)),a.ts&&await g(`ts/${w}.d.ts`,Oe(p))}let d={configHash:ne(n),files:m,gitCommit:Me(r),buildEnv:Fe()},D=Ae(d);return await(0,f.writeFile)((0,x.join)(l,"manifest.json"),D),await(0,f.rm)(o,{recursive:!0,force:!0}),await(0,f.mkdir)((0,x.dirname)(o),{recursive:!0}),await(0,f.rename)(l,o),i&&console.log(`\u2713 ${m.length} files \u2192 ${o}`),{manifest:d,outDir:o}}catch(m){throw await(0,f.rm)(l,{recursive:!0,force:!0}).catch(()=>{}),m}}s(Sn,"build");async function xn(e){let{config:n,outDir:o}=e,r;try{r=JSON.parse(await(0,f.readFile)((0,x.join)(o,"manifest.json"),"utf8"))}catch{return!1}return r.configHash===ne(n)}s(xn,"check");async function Dn(e,n,o){let r=(0,x.join)(e,n);await(0,f.mkdir)((0,x.dirname)(r),{recursive:!0}),await(0,f.writeFile)(r,o)}s(Dn,"writeAt");0&&(module.exports={build,check});
|
package/lib/build.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
var ue=Object.defineProperty;var s=(e,o)=>ue(e,"name",{value:o,configurable:!0}),pe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(o,n)=>(typeof require<"u"?require:o)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{mkdir as ie,mkdtemp as Xe,readFile as Ue,rename as Ye,rm as te,writeFile as se}from"node:fs/promises";import{tmpdir as qe}from"node:os";import{dirname as ae,join as V}from"node:path";import{defaultInputBorder as $}from"@apollion-dsi/core/themes/border";import{createDeth as fe,levelValues as de}from"@apollion-dsi/core/themes/depth";import{defaultInputFont as g}from"@apollion-dsi/core/themes/font";import{converter as me,formatHex as ge,parse as ye}from"culori";var he=me("oklch");function y(e){return typeof e.type=="string"&&"value"in e}s(y,"isToken");function h(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(h,"kebab");function A(e){return e.split(".").map(h).join(".")}s(A,"kebabPath");function b(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(b,"rawValue");function x(e,o){return Number(e.toFixed(o))||0}s(x,"round");function v(e){let o=he(ye(e));if(!o)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let n=[x(o.l,4),x(o.c,4),x(o.h??0,2)],r=ge(o)??"#000000";return o.alpha!==void 0&&o.alpha!==1?{kind:"color",raw:e,components:n,alpha:x(o.alpha,4),hex:r}:{kind:"color",raw:e,components:n,hex:r}}s(v,"toColorValue");var N=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function D(e){let o=N.exec(e.trim());if(o)return{kind:"dimension",raw:e,value:Number(o[1]),unit:o[2]};let n=Number.parseFloat(e);return{kind:"dimension",raw:e,value:Number.isFinite(n)?n:0,unit:"rem"}}s(D,"toDimensionValue");function f(e){return{type:"color",value:v(e)}}s(f,"colorToken");function G(e){let o={};for(let[n,r]of Object.entries(e))o[n]=f(r);return o}s(G,"recordColorGroup");var be=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function Re(e){let o={};for(let n of be){let r=e[n];o[n]={base:f(r.base),dark:f(r.dark),action:f(r.action),active:f(r.active),light:f(r.light)}}return o.grayscale=G(e.grayscale),o.neutral=G(e.neutral),o.baseDark=f(e.baseDark??"#000000"),o.baseLight=f(e.baseLight??"#ffffff"),o.deepDark=f(e.deepDark??"#000000"),o.deepLight=f(e.deepLight??"#ffffff"),o}s(Re,"buildPrimitives");var ke={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"},Ie={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function xe(e,o){let n=e;for(let r of o.split(".").slice(1))if(n&&typeof n=="object"&&r in n)n=n[r];else return;return typeof n=="string"?n:void 0}s(xe,"lookupPrimitive");function L(e,o,n){let r={};for(let[i,t]of Object.entries(e)){let c=n[i],l=c?xe(o,c):void 0;r[i]=c&&l===t?{type:"color",value:{kind:"ref",path:c,resolved:v(t)}}:f(t)}return r}s(L,"colorRefGroup");function De(e){let o={};for(let[n,r]of Object.entries(e))o[n]={type:"dimension",value:D(r)};return o}s(De,"dimensionGroup");function Ve(){let e={},o={};for(let[i,t]of Object.entries($.borderRadius))N.test(t)?e[i]={type:"dimension",value:D(t)}:o[i]=t;let n={};for(let[i,t]of Object.entries($.borderWidth))n[i]={type:"dimension",value:D(t)};let r={};for(let[i,t]of Object.entries($.borderStyle))r[i]={type:"strokeStyle",value:{kind:"strokeStyle",raw:t,style:t}};return{group:{radius:e,width:n,style:r},extensions:o}}s(Ve,"buildBorder");function Te(){let e={};for(let[t,c]of Object.entries(g.fontFamily)){let l=c.replace(/;\s*$/,"").trim();e[t]={type:"fontFamily",value:{kind:"fontFamily",raw:l,family:l}}}let o={};for(let[t,c]of Object.entries(g.fontSize))o[t]={type:"dimension",value:{kind:"dimension",raw:`${c}px`,value:c,unit:"px"}};let n={};for(let[t,c]of Object.entries(g.fontWeight))n[t]={type:"fontWeight",value:{kind:"fontWeight",raw:`${c}`,weight:c}};let r={};for(let[t,c]of Object.entries(g.lineHeight))r[t]={type:"number",value:{kind:"number",raw:`${c}`,number:c}};let i={letterSpacing:g.letterSpacing,textTransform:g.textTransform,fontStyle:g.fontStyle};return{group:{family:e,size:o,weight:n,lineHeight:r},extensions:i}}s(Te,"buildFont");var we=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function Se(e){let o=e.trim(),n=o.startsWith("inset");n&&(o=o.slice(5).trim());let r=o.match(we),i=r?r[0]:"#000000",c=(r?o.slice(0,r.index).trim():o).split(/\s+/).filter(Boolean),l=s(u=>D(c[u]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:v(i),offsetX:l(0),offsetY:l(1),blur:l(2),spread:l(3),inset:n}}}s(Se,"parseShadow");function Ce(e){let o=fe(e),n={};for(let r of Object.keys(de))n[r]={type:"shadow",value:Se(o(r))};return n}s(Ce,"buildShadow");function M(e,o,n){let r={brand:n.brand,mode:n.mode,surface:n.surface,dimension:n.dimension},i=Ve(),t=Te(),c={"com.apollion.variant":r,"com.apollion.font":t.extensions};return Object.keys(i.extensions).length>0&&(c["com.apollion.border"]={radius:i.extensions}),{description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${r.brand}/${r.mode}/${r.surface}/${r.dimension}.`,meta:r,primitives:Re(o),groups:{bg:L(e.bg,o,ke),text:L(e.text,o,Ie),spacing:De(e.spacing),border:i.group,font:t.group,shadow:Ce(o)},extensions:c}}s(M,"buildIR");var $e="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function B(e,o,n){for(let[r,i]of Object.entries(e)){let t=[...o,h(r)];y(i)?n.push(` --apollion-${t.join("-")}: ${b(i.value)};`):B(i,t,n)}}s(B,"emitVars");function H(e,o,n){for(let[r,i]of Object.entries(e)){let t=[...o,h(r)];y(i)?i.type==="color"&&n.push(` @property --apollion-${t.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${b(i.value)}; }`):H(i,t,n)}}s(H,"emitProperties");function P(e){let{brand:o,mode:n,surface:r,dimension:i}=e.meta,t=[$e,""];return t.push(`/* Variant: brand=${o} mode=${n} surface=${r} dimension=${i} */`,"",":root {"),B(e.groups,[],t),t.push("}",""),t.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),H(e.groups,[],t),t.push("}",""),t.join(`
|
|
2
|
-
`)}s(
|
|
3
|
-
`}s(
|
|
4
|
-
`
|
|
5
|
-
`}s(
|
|
1
|
+
var Pe=Object.defineProperty;var s=(e,n)=>Pe(e,"name",{value:n,configurable:!0}),Be=(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{mkdir as Ae,mkdtemp as wn,readFile as Tn,rename as vn,rm as Fe,writeFile as Ne}from"node:fs/promises";import{tmpdir as Cn}from"node:os";import{dirname as Le,join as A}from"node:path";import{defaultInputBorder as G}from"@apollion-dsi/core/themes/border";import{createDeth as He,levelValues as We}from"@apollion-dsi/core/themes/depth";import{defaultInputFont as I}from"@apollion-dsi/core/themes/font";import{defaultInputSpacing as K}from"@apollion-dsi/core/themes/spacing";import{converter as Je,formatHex as Ue,parse as ze}from"culori";import{DIMENSION_MULTIPLIERS as _e}from"@apollion-dsi/core/themes/dimension";function V({multiplier:e=.25,alias:n},o){let r=o!==void 0?_e[o]:e;return(...i)=>i.map(t=>{let a=typeof t=="string"?n[t]:t;return`${r*a}rem`}).join(" ")}s(V,"createSpacing");var P={"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 B(e){let n=Object.keys(P).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(B,"assertTokenMetaResolves");var Xe=Je("oklch");function y(e){return typeof e.type=="string"&&"value"in e}s(y,"isToken");function b(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(b,"kebab");function Q(e){return e.split(".").map(b).join(".")}s(Q,"kebabPath");function D(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(D,"rawValue");function $(e,n){return Number(e.toFixed(n))||0}s($,"round");function _(e){let n=Xe(ze(e));if(!n)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let o=[$(n.l,4),$(n.c,4),$(n.h??0,2)],r=Ue(n)??"#000000";return n.alpha!==void 0&&n.alpha!==1?{kind:"color",raw:e,components:o,alpha:$(n.alpha,4),hex:r}:{kind:"color",raw:e,components:o,hex:r}}s(_,"toColorValue");var ee=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function x(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(x,"toDimensionValue");function g(e){return{type:"color",value:_(e)}}s(g,"colorToken");function Z(e){let n={};for(let[o,r]of Object.entries(e))n[o]=g(r);return n}s(Z,"recordColorGroup");var Ye=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function ne(e){let n={};for(let o of Ye){let r=e[o];n[o]={base:g(r.base),dark:g(r.dark),action:g(r.action),active:g(r.active),light:g(r.light)}}return n.grayscale=Z(e.grayscale),n.neutral=Z(e.neutral),n.baseDark=g(e.baseDark??"#000000"),n.baseLight=g(e.baseLight??"#ffffff"),n.deepDark=g(e.deepDark??"#000000"),n.deepLight=g(e.deepLight??"#ffffff"),n}s(ne,"buildColorPrimitives");function oe(e){let n=V(K,e),o={};for(let r of Object.keys(K.alias))o[r]={type:"dimension",value:x(n(r))};return o}s(oe,"buildSpacePrimitives");function re(){let e={};for(let[n,o]of Object.entries(G.borderWidth))e[n]={type:"dimension",value:x(o)};return e}s(re,"buildBorderWidthPrimitives");function qe(e,n){return{color:ne(e),space:oe(n),borderWidth:re()}}s(qe,"buildPrimitives");var te={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"},ie={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function Ke(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(Ke,"lookupPrimitive");function O(e,n,o){let r={};for(let[i,t]of Object.entries(e)){let a=o[i],l=a?Ke(n,a):void 0;r[i]=a&&l===t?{type:"color",value:{kind:"ref",path:a,resolved:_(t)}}:g(t)}return r}s(O,"colorRefGroup");var se={xs:"space.xs",sm:"space.small",md:"space.medium",lg:"space.large",xl:"space.xl",xxl:"space.xxl"},Ze={none:"border-width.none",thin:"border-width.thin",regular:"border-width.regular",great:"border-width.great",bold:"border-width.bold"};function Qe(e,n){let o=n.split("."),r=o[0]==="border-width"?"borderWidth":o[0],i=e[r];for(let t of o.slice(1))if(i&&!y(i)&&t in i)i=i[t];else return;return i&&y(i)&&i.value.kind==="dimension"?i.value.raw:void 0}s(Qe,"lookupDimensionPrimitive");function H(e,n,o){let r={};for(let[i,t]of Object.entries(e)){let a=o[i],l=a?Qe(n,a):void 0;r[i]=a&&l===t?{type:"dimension",value:{kind:"ref",path:a,resolved:x(t)}}:{type:"dimension",value:x(t)}}return r}s(H,"dimensionRefGroup");function ae(e){let n={},o={};for(let[t,a]of Object.entries(G.borderRadius))ee.test(a)?n[t]={type:"dimension",value:x(a)}:o[t]=a;let r=H(G.borderWidth,e,Ze),i={};for(let[t,a]of Object.entries(G.borderStyle))i[t]={type:"strokeStyle",value:{kind:"strokeStyle",raw:a,style:a}};return{group:{radius:n,width:r,style:i},extensions:o}}s(ae,"buildBorder");function ce(){let e={};for(let[t,a]of Object.entries(I.fontFamily)){let l=a.replace(/;\s*$/,"").trim();e[t]={type:"fontFamily",value:{kind:"fontFamily",raw:l,family:l}}}let n={};for(let[t,a]of Object.entries(I.fontSize))n[t]={type:"dimension",value:{kind:"dimension",raw:`${a}px`,value:a,unit:"px"}};let o={};for(let[t,a]of Object.entries(I.fontWeight))o[t]={type:"fontWeight",value:{kind:"fontWeight",raw:`${a}`,weight:a}};let r={};for(let[t,a]of Object.entries(I.lineHeight))r[t]={type:"number",value:{kind:"number",raw:`${a}`,number:a}};let i={letterSpacing:I.letterSpacing,textTransform:I.textTransform,fontStyle:I.fontStyle};return{group:{family:e,size:n,weight:o,lineHeight:r},extensions:i}}s(ce,"buildFont");var en=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function nn(e){let n=e.trim(),o=n.startsWith("inset");o&&(n=n.slice(5).trim());let r=n.match(en),i=r?r[0]:"#000000",a=(r?n.slice(0,r.index).trim():n).split(/\s+/).filter(Boolean),l=s(f=>x(a[f]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:_(i),offsetX:l(0),offsetY:l(1),blur:l(2),spread:l(3),inset:o}}}s(nn,"parseShadow");function le(e){let n=He(e),o={};for(let r of Object.keys(We))o[r]={type:"shadow",value:nn(n(r))};return o}s(le,"buildShadow");function E(e,n,o){let r={};for(let[i,t]of Object.entries(e)){let a=n?`${n}.${b(i)}`:b(i);if(y(t)){o.add(a);let l=P[a];r[i]=l&&(l.description!==void 0||l.deprecated!==void 0)?{...t,...l.description!==void 0?{description:l.description}:{},...l.deprecated!==void 0?{deprecated:l.deprecated}:{}}:t}else r[i]=E(t,a,o)}return r}s(E,"decorateGroup");function on(e){let n=new Set,o=E(e.primitives,"",n),r=E(e.groups,"",n);return B(n),{...e,primitives:o,groups:r}}s(on,"decorateMeta");function W(e,n){return E(e,"",n)}s(W,"decorateSlice");function de(e,n,o){for(let[r,i]of Object.entries(e)){let t=n?`${n}.${b(r)}`:b(r);y(i)?o.add(t):de(i,t,o)}}s(de,"collectPaths");function ue(e){let n=new Set;for(let o of e)de(o.groups,"",n);B(n)}s(ue,"assertSlicesMetaComplete");function pe(){let e=re(),o=ae({borderWidth:e}),r=ce(),i={"com.apollion.font":r.extensions};Object.keys(o.extensions).length>0&&(i["com.apollion.border"]={radius:o.extensions});let t=new Set;return{groups:W({"border-width":e,border:o.group,font:r.group},t),extensions:i}}s(pe,"buildBaseIR");function fe(e,n){let o=ne(n),r=new Set;return{groups:W({color:o,bg:O(e.bg,n,te),text:O(e.text,n,ie),shadow:le(n)},r),extensions:{}}}s(fe,"buildColorIR");function me(e,n){let o=oe(n),r={space:o},i=new Set;return{groups:W({space:o,spacing:H(e.spacing,r,se)},i),extensions:{}}}s(me,"buildSpacingIR");function rn(e,n,o){let r={brand:o.brand,mode:o.mode,surface:o.surface,dimension:o.dimension},i=qe(n,o.dimension),t=ae(i),a=ce(),l={"com.apollion.variant":r,"com.apollion.font":a.extensions};Object.keys(t.extensions).length>0&&(l["com.apollion.border"]={radius:t.extensions});let f={description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${r.brand}/${r.mode}/${r.surface}/${r.dimension}.`,meta:r,primitives:i,groups:{bg:O(e.bg,n,te),text:O(e.text,n,ie),spacing:H(e.spacing,i,se),border:t.group,font:a.group,shadow:le(n)},extensions:l};return on(f)}s(rn,"buildIR");var ge=rn;var tn="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function ye(e,n,o){for(let[r,i]of Object.entries(e)){let t=[...n,b(r)];y(i)?o.push(` --apollion-${t.join("-")}: ${D(i.value)};`):ye(i,t,o)}}s(ye,"emitVars");function he(e,n,o){for(let[r,i]of Object.entries(e)){let t=[...n,b(r)];y(i)?i.type==="color"&&o.push(` @property --apollion-${t.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${D(i.value)}; }`):he(i,t,o)}}s(he,"emitProperties");function be(e){let{brand:n,mode:o,surface:r,dimension:i}=e.meta,t=[tn,""];return t.push(`/* Variant: brand=${n} mode=${o} surface=${r} dimension=${i} */`,"",":root {"),ye(e.groups,[],t),t.push("}",""),t.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),he(e.groups,[],t),t.push("}",""),t.join(`
|
|
2
|
+
`)}s(be,"renderCss");function Re(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(Re,"colorValue");function w(e){return{value:e.value,unit:e.unit}}s(w,"dimensionValue");function sn(e){let n=e.shadow,o={color:Re(n.color),offsetX:w(n.offsetX),offsetY:w(n.offsetY),blur:w(n.blur),spread:w(n.spread)};return n.inset&&(o.inset=!0),o}s(sn,"shadowValue");function an(e){switch(e.kind){case"ref":return`{${Q(e.path)}}`;case"color":return Re(e);case"dimension":return w(e);case"fontFamily":return e.family;case"fontWeight":return e.weight;case"number":return e.number;case"strokeStyle":return e.style;case"shadow":return sn(e)}}s(an,"projectValue");function cn(e){let n={$value:an(e.value),$type:e.type};return e.description!==void 0&&(n.$description=e.description),e.deprecated!==void 0&&(n.$deprecated=e.deprecated),n}s(cn,"projectToken");function J(e){let n={};for(let[o,r]of Object.entries(e))n[b(o)]=y(r)?cn(r):J(r);return n}s(J,"projectGroup");function U(e,n){let o={$description:n,...J(e.groups)};return Object.keys(e.extensions).length>0&&(o.$extensions=e.extensions),`${JSON.stringify(o,null,2)}
|
|
3
|
+
`}s(U,"renderSet");function Ie(e){return U(e,"Apollion DS \u2014 base set (axis-invariant: border + font). DTCG 2025.10.")}s(Ie,"renderBaseSet");function ke(e,n,o,r){return U(e,`Apollion DS \u2014 colour set. brand=${n} mode=${o} surface=${r}. DTCG 2025.10.`)}s(ke,"renderColorSet");function Se(e,n){return U(e,`Apollion DS \u2014 spacing set. dimension=${n}. DTCG 2025.10.`)}s(Se,"renderSpacingSet");function xe(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]}],t={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 set 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.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}"}},modeIsPlaceholder:!0}}};return`${JSON.stringify(t,null,2)}
|
|
4
|
+
`}s(xe,"renderResolver");var ln="// Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs.";function De(e,n,o){let r=" ".repeat(n);for(let[i,t]of Object.entries(e))y(t)?o.push(`${r}${JSON.stringify(i)}: ${JSON.stringify(D(t.value))},`):(o.push(`${r}${i}: {`),De(t,n+1,o),o.push(`${r}},`))}s(De,"emitGroup");function we(e){let{brand:n,mode:o,surface:r,dimension:i}=e.meta,t=[ln,`// Variant: brand=${n} mode=${o} surface=${r} dimension=${i}`,"","export const tokens = {"];return De(e.groups,1,t),t.push("} as const;","","export type Tokens = typeof tokens;",""),t.join(`
|
|
5
|
+
`)}s(we,"renderTs");var dn=["light","dark"],un=["positive","negative"],pn=["compact","normal","spacious"];function j(e){let n=e.modes??dn,o=e.surfaces??un,r=e.dimensions??pn,i=Object.entries(e.brands).sort(([a],[l])=>a.localeCompare(l)),t=[];for(let[a,l]of i)for(let f of n)for(let m of o)for(let d of r)t.push({brand:a,colors:l,mode:f,surface:m,dimension:d});return t}s(j,"expandVariants");function Te(e){return`${e.brand}.${e.mode}.${e.surface}.${e.dimension}`}s(Te,"variantName");import{createHash as fn}from"node:crypto";function X(e){return fn("sha256").update(e).digest("hex")}s(X,"sha256");function Y(e){return X(z(e))}s(Y,"hashConfig");function z(e){return e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?`[${e.map(z).join(",")}]`:`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${z(e[r])}`).join(",")}}`}s(z,"stableStringify");function ve(e){try{let{execSync:n}=Be("node:child_process");return n("git rev-parse --short HEAD",{cwd:e,stdio:["ignore","pipe","ignore"],encoding:"utf8"}).trim()}catch{return""}}s(ve,"detectGitCommit");function Ce(){return{node:process.version,platform:`${process.platform}-${process.arch}`}}s(Ce,"buildEnv");function Ve(e){let n=[...e.files].sort((r,i)=>r.path.localeCompare(i.path)),o={configHash:e.configHash,files:n,gitCommit:e.gitCommit,buildEnv:e.buildEnv};return`${JSON.stringify(o,null,2)}
|
|
6
|
+
`}s(Ve,"serializeManifest");var mn="json/sets",$e="json/resolver.json";function q(e){return`${mn}/${e}.json`}s(q,"setFile");function gn(e,n,o){return`${e}.color.${n}.${o}`}s(gn,"colorSetName");function yn(e){return`spacing.${e}`}s(yn,"spacingSetName");function M(e,n){e.includes(n)||e.push(n)}s(M,"pushUnique");function Ge(e){let n=j(e),o=[],r=[],i=[],t=[],a=new Set,l=[],f=new Set,m=[];for(let d of n){M(o,d.brand),M(r,d.mode),M(i,d.surface),M(t,d.dimension);let k=gn(d.brand,d.mode,d.surface);a.has(k)||(a.add(k),l.push({kind:"color",name:k,file:q(k),brand:d.brand,mode:d.mode,surface:d.surface}));let u=yn(d.dimension);f.has(u)||(f.add(u),m.push({kind:"spacing",name:u,file:q(u),dimension:d.dimension}))}return{base:{kind:"base",name:"base",file:q("base")},spacing:m,color:l,modifiers:{brand:o,mode:r,surface:i,dimension:t}}}s(Ge,"planSets");import{createFoundation as Me}from"@apollion-dsi/core/themes/foundation";import{createSemantic as kn}from"@apollion-dsi/core/themes/semantic";import{defaultInputSpacing as Sn}from"@apollion-dsi/core/themes/spacing";import{invertForSurface as xn}from"@apollion-dsi/core/themes/surface";import{converter as hn,formatHex as bn,interpolate as Rn,parse as Oe}from"culori";var fo=hn("oklch");function c(e,n,o){let r=Oe(e),i=Oe(n);if(!r||!i)return e;let t=Rn([r,i],"oklch");return bn(t(o))??e}s(c,"mixOklch");function In(e){return e?typeof e=="string"?e:e.base:"#000"}s(In,"coerceToHex");function h(e,n){let o=In(e),r=n.deepDark,i=n.deepLight;return{base:o,dark:c(o,r,.6),action:c(o,r,.2),active:c(o,i,.6),light:c(o,i,.9)}}s(h,"mountSingleColor");function Ee(e){let n=e.deepLight,o=e.deepDark;return{0:n,5:c(n,o,.05),10:c(n,o,.1),20:c(n,o,.2),30:c(n,o,.3),40:c(n,o,.4),50:c(n,o,.5),60:c(n,o,.6),70:c(n,o,.7),80:c(n,o,.8),90:c(n,o,.9),100:c(n,o,1)}}s(Ee,"mountGreyscaleColors");function je(e){let n=e.deepLight,o=e.deepDark,r=e.primary,i=s(a=>1/17*(a-1),"interpolation"),t=c(r,o,.5);return{0:c(t,n,i(18)),5:c(t,n,i(17.5)),10:c(t,n,i(17)),20:c(t,n,i(16)),30:c(t,n,i(15)),40:c(t,n,i(14)),50:c(t,n,i(13)),60:c(t,n,i(12)),70:c(t,n,i(11)),80:c(t,n,i(10)),90:c(t,n,i(9)),100:c(t,n,i(8)),110:c(t,n,i(7)),120:c(t,n,i(6)),130:c(t,n,i(5)),140:c(t,n,i(4)),150:c(t,n,i(3)),160:c(t,n,i(2)),170:t,180:c(t,o,.25)}}s(je,"mountNeutralColors");function Dn(e){return{baseDark:e.baseDark,baseLight:e.baseLight,deepDark:e.deepDark,deepLight:e.deepLight,transparent:e.transparent??"transparent",neutral:je(e),grayscale:Ee(e),main:h(e.main,e),opposite:h(e.opposite,e),complementary:h(e.complementary,e),danger:h(e.danger,e),information:h(e.information,e),success:h(e.success,e),warning:h(e.warning,e),primary:h(e.primary,e),secondary:h(e.secondary,e),tertiary:h(e.tertiary,e)}}s(Dn,"composeColors");function F(e,n=Sn){let o=Dn(e.colors),r=V(n,e.dimension),i=kn({colors:o,spacing:r}),t=Me(i);return e.surface==="negative"&&(t=Me(xn({semantic:i,colors:o},"negative").semantic)),{foundation:t,colors:o}}s(F,"buildVariantThemes");async function Mo(e){let{config:n,outDir:o,cwd:r=process.cwd(),verbose:i=!1}=e,t=j(n),a=n.output??{};if(t.length===0)throw new Error("apollion-tokens build: no variants (config.brands is empty)");let l=await wn(A(Cn(),"apollion-tokens-"));try{let f=[],m=s(async(u,R)=>{await Vn(l,u,R),f.push({path:u,sha256:X(R)}),i&&console.log(` \u2713 ${u}`)},"emit");if(a.json){let u=Ge(n),R=[],T=pe();R.push(T),await m(u.base.file,Ie(T));for(let p of u.spacing){let S=t.find(C=>C.dimension===p.dimension),{foundation:N}=F(S),v=me(N,p.dimension);R.push(v),await m(p.file,Se(v,p.dimension))}for(let p of u.color){let S=t.find(L=>L.brand===p.brand&&L.mode===p.mode&&L.surface===p.surface),{foundation:N,colors:v}=F(S),C=fe(N,v);R.push(C),await m(p.file,ke(C,p.brand,p.mode,p.surface))}ue(R),await m($e,xe(n,u))}if(a.css||a.ts)for(let u of t){let{foundation:R,colors:T}=F(u),p=ge(R,T,u),S=Te(u);a.css&&await m(`css/${S}.css`,be(p)),a.ts&&await m(`ts/${S}.d.ts`,we(p))}let d={configHash:Y(n),files:f,gitCommit:ve(r),buildEnv:Ce()},k=Ve(d);return await Ne(A(l,"manifest.json"),k),await Fe(o,{recursive:!0,force:!0}),await Ae(Le(o),{recursive:!0}),await vn(l,o),i&&console.log(`\u2713 ${f.length} files \u2192 ${o}`),{manifest:d,outDir:o}}catch(f){throw await Fe(l,{recursive:!0,force:!0}).catch(()=>{}),f}}s(Mo,"build");async function Fo(e){let{config:n,outDir:o}=e,r;try{r=JSON.parse(await Tn(A(o,"manifest.json"),"utf8"))}catch{return!1}return r.configHash===Y(n)}s(Fo,"check");async function Vn(e,n,o){let r=A(e,n);await Ae(Le(r),{recursive:!0}),await Ne(r,o)}s(Vn,"writeAt");export{Mo as build,Fo as check};
|
package/lib/cli.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var Re=Object.defineProperty;var s=(e,o)=>Re(e,"name",{value:o,configurable:!0}),Ie=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(o,n)=>(typeof require<"u"?require:o)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{readFile as ho}from"node:fs/promises";import{resolve as P}from"node:path";import{mkdir as pe,mkdtemp as to,readFile as ro,rename as io,rm as ue,writeFile as fe}from"node:fs/promises";import{tmpdir as so}from"node:os";import{dirname as de,join as S}from"node:path";import{defaultInputBorder as A}from"@apollion-dsi/core/themes/border";import{createDeth as xe,levelValues as we}from"@apollion-dsi/core/themes/depth";import{defaultInputFont as b}from"@apollion-dsi/core/themes/font";import{converter as De,formatHex as Ce,parse as Te}from"culori";var Se=De("oklch");function k(e){return typeof e.type=="string"&&"value"in e}s(k,"isToken");function I(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(I,"kebab");function H(e){return e.split(".").map(I).join(".")}s(H,"kebabPath");function x(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(x,"rawValue");function C(e,o){return Number(e.toFixed(o))||0}s(C,"round");function F(e){let o=Se(Te(e));if(!o)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let n=[C(o.l,4),C(o.c,4),C(o.h??0,2)],t=Ce(o)??"#000000";return o.alpha!==void 0&&o.alpha!==1?{kind:"color",raw:e,components:n,alpha:C(o.alpha,4),hex:t}:{kind:"color",raw:e,components:n,hex:t}}s(F,"toColorValue");var W=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function T(e){let o=W.exec(e.trim());if(o)return{kind:"dimension",raw:e,value:Number(o[1]),unit:o[2]};let n=Number.parseFloat(e);return{kind:"dimension",raw:e,value:Number.isFinite(n)?n:0,unit:"rem"}}s(T,"toDimensionValue");function m(e){return{type:"color",value:F(e)}}s(m,"colorToken");function _(e){let o={};for(let[n,t]of Object.entries(e))o[n]=m(t);return o}s(_,"recordColorGroup");var Ve=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function $e(e){let o={};for(let n of Ve){let t=e[n];o[n]={base:m(t.base),dark:m(t.dark),action:m(t.action),active:m(t.active),light:m(t.light)}}return o.grayscale=_(e.grayscale),o.neutral=_(e.neutral),o.baseDark=m(e.baseDark??"#000000"),o.baseLight=m(e.baseLight??"#ffffff"),o.deepDark=m(e.deepDark??"#000000"),o.deepLight=m(e.deepLight??"#ffffff"),o}s($e,"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"},Oe={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function je(e,o){let n=e;for(let t of o.split(".").slice(1))if(n&&typeof n=="object"&&t in n)n=n[t];else return;return typeof n=="string"?n:void 0}s(je,"lookupPrimitive");function B(e,o,n){let t={};for(let[i,r]of Object.entries(e)){let a=n[i],l=a?je(o,a):void 0;t[i]=a&&l===r?{type:"color",value:{kind:"ref",path:a,resolved:F(r)}}:m(r)}return t}s(B,"colorRefGroup");function Ae(e){let o={};for(let[n,t]of Object.entries(e))o[n]={type:"dimension",value:T(t)};return o}s(Ae,"dimensionGroup");function Fe(){let e={},o={};for(let[i,r]of Object.entries(A.borderRadius))W.test(r)?e[i]={type:"dimension",value:T(r)}:o[i]=r;let n={};for(let[i,r]of Object.entries(A.borderWidth))n[i]={type:"dimension",value:T(r)};let t={};for(let[i,r]of Object.entries(A.borderStyle))t[i]={type:"strokeStyle",value:{kind:"strokeStyle",raw:r,style:r}};return{group:{radius:e,width:n,style:t},extensions:o}}s(Fe,"buildBorder");function Ee(){let e={};for(let[r,a]of Object.entries(b.fontFamily)){let l=a.replace(/;\s*$/,"").trim();e[r]={type:"fontFamily",value:{kind:"fontFamily",raw:l,family:l}}}let o={};for(let[r,a]of Object.entries(b.fontSize))o[r]={type:"dimension",value:{kind:"dimension",raw:`${a}px`,value:a,unit:"px"}};let n={};for(let[r,a]of Object.entries(b.fontWeight))n[r]={type:"fontWeight",value:{kind:"fontWeight",raw:`${a}`,weight:a}};let t={};for(let[r,a]of Object.entries(b.lineHeight))t[r]={type:"number",value:{kind:"number",raw:`${a}`,number:a}};let i={letterSpacing:b.letterSpacing,textTransform:b.textTransform,fontStyle:b.fontStyle};return{group:{family:e,size:o,weight:n,lineHeight:t},extensions:i}}s(Ee,"buildFont");var Ge=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function Ne(e){let o=e.trim(),n=o.startsWith("inset");n&&(o=o.slice(5).trim());let t=o.match(Ge),i=t?t[0]:"#000000",a=(t?o.slice(0,t.index).trim():o).split(/\s+/).filter(Boolean),l=s(u=>T(a[u]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:F(i),offsetX:l(0),offsetY:l(1),blur:l(2),spread:l(3),inset:n}}}s(Ne,"parseShadow");function Le(e){let o=xe(e),n={};for(let t of Object.keys(we))n[t]={type:"shadow",value:Ne(o(t))};return n}s(Le,"buildShadow");function J(e,o,n){let t={brand:n.brand,mode:n.mode,surface:n.surface,dimension:n.dimension},i=Fe(),r=Ee(),a={"com.apollion.variant":t,"com.apollion.font":r.extensions};return Object.keys(i.extensions).length>0&&(a["com.apollion.border"]={radius:i.extensions}),{description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${t.brand}/${t.mode}/${t.surface}/${t.dimension}.`,meta:t,primitives:$e(o),groups:{bg:B(e.bg,o,ve),text:B(e.text,o,Oe),spacing:Ae(e.spacing),border:i.group,font:r.group,shadow:Le(o)},extensions:a}}s(J,"buildIR");var Me="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function z(e,o,n){for(let[t,i]of Object.entries(e)){let r=[...o,I(t)];k(i)?n.push(` --apollion-${r.join("-")}: ${x(i.value)};`):z(i,r,n)}}s(z,"emitVars");function U(e,o,n){for(let[t,i]of Object.entries(e)){let r=[...o,I(t)];k(i)?i.type==="color"&&n.push(` @property --apollion-${r.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${x(i.value)}; }`):U(i,r,n)}}s(U,"emitProperties");function X(e){let{brand:o,mode:n,surface:t,dimension:i}=e.meta,r=[Me,""];return r.push(`/* Variant: brand=${o} mode=${n} surface=${t} dimension=${i} */`,"",":root {"),z(e.groups,[],r),r.push("}",""),r.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),U(e.groups,[],r),r.push("}",""),r.join(`
|
|
3
|
-
`)}s(
|
|
4
|
-
`}s(
|
|
5
|
-
`
|
|
6
|
-
`}s(
|
|
7
|
-
`);
|
|
8
|
-
|
|
2
|
+
var Ye=Object.defineProperty;var s=(e,o)=>Ye(e,"name",{value:o,configurable:!0}),Ke=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(o,n)=>(typeof require<"u"?require:o)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{readFile as Xo}from"node:fs/promises";import{resolve as ne}from"node:path";import{mkdir as He,mkdtemp as Go,readFile as Po,rename as Mo,rm as Be,writeFile as We}from"node:fs/promises";import{tmpdir as Fo}from"node:os";import{dirname as Ue,join as L}from"node:path";import{defaultInputBorder as E}from"@apollion-dsi/core/themes/border";import{createDeth as Qe,levelValues as eo}from"@apollion-dsi/core/themes/depth";import{defaultInputFont as x}from"@apollion-dsi/core/themes/font";import{defaultInputSpacing as re}from"@apollion-dsi/core/themes/spacing";import{converter as oo,formatHex as no,parse as ro}from"culori";import{DIMENSION_MULTIPLIERS as Ze}from"@apollion-dsi/core/themes/dimension";function j({multiplier:e=.25,alias:o},n){let r=n!==void 0?Ze[n]:e;return(...i)=>i.map(t=>{let a=typeof t=="string"?o[t]:t;return`${r*a}rem`}).join(" ")}s(j,"createSpacing");var W={"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 U(e){let o=Object.keys(W).filter(n=>!e.has(n));if(o.length>0)throw new Error(`token-meta: ${o.length} stale TOKEN_META key(s) resolve to no IR node: ${o.join(", ")}. Update src/token-meta.ts to match the current IR paths.`)}s(U,"assertTokenMetaResolves");var to=oo("oklch");function b(e){return typeof e.type=="string"&&"value"in e}s(b,"isToken");function k(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(k,"kebab");function ie(e){return e.split(".").map(k).join(".")}s(ie,"kebabPath");function T(e){return e.kind==="ref"?e.resolved.raw:e.raw}s(T,"rawValue");function A(e,o){return Number(e.toFixed(o))||0}s(A,"round");function J(e){let o=to(ro(e));if(!o)return{kind:"color",raw:e,components:[0,0,0],hex:"#000000"};let n=[A(o.l,4),A(o.c,4),A(o.h??0,2)],r=no(o)??"#000000";return o.alpha!==void 0&&o.alpha!==1?{kind:"color",raw:e,components:n,alpha:A(o.alpha,4),hex:r}:{kind:"color",raw:e,components:n,hex:r}}s(J,"toColorValue");var se=/^(-?(?:\d+\.?\d*|\.\d+))(px|rem)$/;function v(e){let o=se.exec(e.trim());if(o)return{kind:"dimension",raw:e,value:Number(o[1]),unit:o[2]};let n=Number.parseFloat(e);return{kind:"dimension",raw:e,value:Number.isFinite(n)?n:0,unit:"rem"}}s(v,"toDimensionValue");function h(e){return{type:"color",value:J(e)}}s(h,"colorToken");function te(e){let o={};for(let[n,r]of Object.entries(e))o[n]=h(r);return o}s(te,"recordColorGroup");var io=["main","opposite","complementary","primary","secondary","tertiary","success","danger","warning","information"];function ae(e){let o={};for(let n of io){let r=e[n];o[n]={base:h(r.base),dark:h(r.dark),action:h(r.action),active:h(r.active),light:h(r.light)}}return o.grayscale=te(e.grayscale),o.neutral=te(e.neutral),o.baseDark=h(e.baseDark??"#000000"),o.baseLight=h(e.baseLight??"#ffffff"),o.deepDark=h(e.deepDark??"#000000"),o.deepLight=h(e.deepLight??"#ffffff"),o}s(ae,"buildColorPrimitives");function ce(e){let o=j(re,e),n={};for(let r of Object.keys(re.alias))n[r]={type:"dimension",value:v(o(r))};return n}s(ce,"buildSpacePrimitives");function le(){let e={};for(let[o,n]of Object.entries(E.borderWidth))e[o]={type:"dimension",value:v(n)};return e}s(le,"buildBorderWidthPrimitives");function so(e,o){return{color:ae(e),space:ce(o),borderWidth:le()}}s(so,"buildPrimitives");var de={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"},ue={onPrimary:"color.baseLight",onSecondary:"color.baseLight",onTertiary:"color.baseDark",onSuccess:"color.baseLight",onDanger:"color.baseLight",onWarning:"color.baseDark",onInfo:"color.baseLight"};function ao(e,o){let n=e;for(let r of o.split(".").slice(1))if(n&&typeof n=="object"&&r in n)n=n[r];else return;return typeof n=="string"?n:void 0}s(ao,"lookupPrimitive");function G(e,o,n){let r={};for(let[i,t]of Object.entries(e)){let a=n[i],c=a?ao(o,a):void 0;r[i]=a&&c===t?{type:"color",value:{kind:"ref",path:a,resolved:J(t)}}:h(t)}return r}s(G,"colorRefGroup");var pe={xs:"space.xs",sm:"space.small",md:"space.medium",lg:"space.large",xl:"space.xl",xxl:"space.xxl"},co={none:"border-width.none",thin:"border-width.thin",regular:"border-width.regular",great:"border-width.great",bold:"border-width.bold"};function lo(e,o){let n=o.split("."),r=n[0]==="border-width"?"borderWidth":n[0],i=e[r];for(let t of n.slice(1))if(i&&!b(i)&&t in i)i=i[t];else return;return i&&b(i)&&i.value.kind==="dimension"?i.value.raw:void 0}s(lo,"lookupDimensionPrimitive");function z(e,o,n){let r={};for(let[i,t]of Object.entries(e)){let a=n[i],c=a?lo(o,a):void 0;r[i]=a&&c===t?{type:"dimension",value:{kind:"ref",path:a,resolved:v(t)}}:{type:"dimension",value:v(t)}}return r}s(z,"dimensionRefGroup");function fe(e){let o={},n={};for(let[t,a]of Object.entries(E.borderRadius))se.test(a)?o[t]={type:"dimension",value:v(a)}:n[t]=a;let r=z(E.borderWidth,e,co),i={};for(let[t,a]of Object.entries(E.borderStyle))i[t]={type:"strokeStyle",value:{kind:"strokeStyle",raw:a,style:a}};return{group:{radius:o,width:r,style:i},extensions:n}}s(fe,"buildBorder");function me(){let e={};for(let[t,a]of Object.entries(x.fontFamily)){let c=a.replace(/;\s*$/,"").trim();e[t]={type:"fontFamily",value:{kind:"fontFamily",raw:c,family:c}}}let o={};for(let[t,a]of Object.entries(x.fontSize))o[t]={type:"dimension",value:{kind:"dimension",raw:`${a}px`,value:a,unit:"px"}};let n={};for(let[t,a]of Object.entries(x.fontWeight))n[t]={type:"fontWeight",value:{kind:"fontWeight",raw:`${a}`,weight:a}};let r={};for(let[t,a]of Object.entries(x.lineHeight))r[t]={type:"number",value:{kind:"number",raw:`${a}`,number:a}};let i={letterSpacing:x.letterSpacing,textTransform:x.textTransform,fontStyle:x.fontStyle};return{group:{family:e,size:o,weight:n,lineHeight:r},extensions:i}}s(me,"buildFont");var uo=/rgba?\([^)]*\)|#[0-9a-fA-F]+|[a-zA-Z]+$/;function po(e){let o=e.trim(),n=o.startsWith("inset");n&&(o=o.slice(5).trim());let r=o.match(uo),i=r?r[0]:"#000000",a=(r?o.slice(0,r.index).trim():o).split(/\s+/).filter(Boolean),c=s(d=>v(a[d]??"0px"),"dim");return{kind:"shadow",raw:e,shadow:{color:J(i),offsetX:c(0),offsetY:c(1),blur:c(2),spread:c(3),inset:n}}}s(po,"parseShadow");function ge(e){let o=Qe(e),n={};for(let r of Object.keys(eo))n[r]={type:"shadow",value:po(o(r))};return n}s(ge,"buildShadow");function P(e,o,n){let r={};for(let[i,t]of Object.entries(e)){let a=o?`${o}.${k(i)}`:k(i);if(b(t)){n.add(a);let c=W[a];r[i]=c&&(c.description!==void 0||c.deprecated!==void 0)?{...t,...c.description!==void 0?{description:c.description}:{},...c.deprecated!==void 0?{deprecated:c.deprecated}:{}}:t}else r[i]=P(t,a,n)}return r}s(P,"decorateGroup");function fo(e){let o=new Set,n=P(e.primitives,"",o),r=P(e.groups,"",o);return U(o),{...e,primitives:n,groups:r}}s(fo,"decorateMeta");function X(e,o){return P(e,"",o)}s(X,"decorateSlice");function ye(e,o,n){for(let[r,i]of Object.entries(e)){let t=o?`${o}.${k(r)}`:k(r);b(i)?n.add(t):ye(i,t,n)}}s(ye,"collectPaths");function he(e){let o=new Set;for(let n of e)ye(n.groups,"",o);U(o)}s(he,"assertSlicesMetaComplete");function be(){let e=le(),n=fe({borderWidth:e}),r=me(),i={"com.apollion.font":r.extensions};Object.keys(n.extensions).length>0&&(i["com.apollion.border"]={radius:n.extensions});let t=new Set;return{groups:X({"border-width":e,border:n.group,font:r.group},t),extensions:i}}s(be,"buildBaseIR");function Re(e,o){let n=ae(o),r=new Set;return{groups:X({color:n,bg:G(e.bg,o,de),text:G(e.text,o,ue),shadow:ge(o)},r),extensions:{}}}s(Re,"buildColorIR");function ke(e,o){let n=ce(o),r={space:n},i=new Set;return{groups:X({space:n,spacing:z(e.spacing,r,pe)},i),extensions:{}}}s(ke,"buildSpacingIR");function mo(e,o,n){let r={brand:n.brand,mode:n.mode,surface:n.surface,dimension:n.dimension},i=so(o,n.dimension),t=fe(i),a=me(),c={"com.apollion.variant":r,"com.apollion.font":a.extensions};Object.keys(t.extensions).length>0&&(c["com.apollion.border"]={radius:t.extensions});let d={description:`Apollion DS tokens \u2014 DTCG 2025.10. Variant: ${r.brand}/${r.mode}/${r.surface}/${r.dimension}.`,meta:r,primitives:i,groups:{bg:G(e.bg,o,de),text:G(e.text,o,ue),spacing:z(e.spacing,i,pe),border:t.group,font:a.group,shadow:ge(o)},extensions:c};return fo(d)}s(mo,"buildIR");var Ie=mo;var go="/* Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs. */";function xe(e,o,n){for(let[r,i]of Object.entries(e)){let t=[...o,k(r)];b(i)?n.push(` --apollion-${t.join("-")}: ${T(i.value)};`):xe(i,t,n)}}s(xe,"emitVars");function Se(e,o,n){for(let[r,i]of Object.entries(e)){let t=[...o,k(r)];b(i)?i.type==="color"&&n.push(` @property --apollion-${t.join("-")} { syntax: '<color>'; inherits: true; initial-value: ${T(i.value)}; }`):Se(i,t,n)}}s(Se,"emitProperties");function we(e){let{brand:o,mode:n,surface:r,dimension:i}=e.meta,t=[go,""];return t.push(`/* Variant: brand=${o} mode=${n} surface=${r} dimension=${i} */`,"",":root {"),xe(e.groups,[],t),t.push("}",""),t.push("@supports (background: paint(squircle)) or (color: oklch(0% 0 0)) {"),Se(e.groups,[],t),t.push("}",""),t.join(`
|
|
3
|
+
`)}s(we,"renderCss");function De(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(De,"colorValue");function C(e){return{value:e.value,unit:e.unit}}s(C,"dimensionValue");function yo(e){let o=e.shadow,n={color:De(o.color),offsetX:C(o.offsetX),offsetY:C(o.offsetY),blur:C(o.blur),spread:C(o.spread)};return o.inset&&(n.inset=!0),n}s(yo,"shadowValue");function ho(e){switch(e.kind){case"ref":return`{${ie(e.path)}}`;case"color":return De(e);case"dimension":return C(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(ho,"projectValue");function bo(e){let o={$value:ho(e.value),$type:e.type};return e.description!==void 0&&(o.$description=e.description),e.deprecated!==void 0&&(o.$deprecated=e.deprecated),o}s(bo,"projectToken");function q(e){let o={};for(let[n,r]of Object.entries(e))o[k(n)]=b(r)?bo(r):q(r);return o}s(q,"projectGroup");function Y(e,o){let n={$description:o,...q(e.groups)};return Object.keys(e.extensions).length>0&&(n.$extensions=e.extensions),`${JSON.stringify(n,null,2)}
|
|
4
|
+
`}s(Y,"renderSet");function ve(e){return Y(e,"Apollion DS \u2014 base set (axis-invariant: border + font). DTCG 2025.10.")}s(ve,"renderBaseSet");function Te(e,o,n,r){return Y(e,`Apollion DS \u2014 colour set. brand=${o} mode=${n} surface=${r}. DTCG 2025.10.`)}s(Te,"renderColorSet");function Ce(e,o){return Y(e,`Apollion DS \u2014 spacing set. dimension=${o}. DTCG 2025.10.`)}s(Ce,"renderSpacingSet");function $e(e,o){let{modifiers:n}=o,r=[{name:"brand",values:[...n.brand],default:n.brand[0]},{name:"mode",values:[...n.mode],default:n.mode[0]},{name:"surface",values:[...n.surface],default:n.surface[0]},{name:"dimension",values:[...n.dimension],default:n.dimension[0]}],t={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 set for the chosen dimension. NOTE: mode is a topology placeholder in this release (dark resolves identically to light until S6).",sets:[{name:o.base.name,source:o.base.file},...o.spacing.map(a=>({name:a.name,source:a.file})),...o.color.map(a=>({name:a.name,source:a.file}))],modifiers:r,$extensions:{"com.apollion.resolver":{composition:{always:[o.base.name],byModifier:{color:"${brand}.color.${mode}.${surface}",spacing:"spacing.${dimension}"}},modeIsPlaceholder:!0}}};return`${JSON.stringify(t,null,2)}
|
|
5
|
+
`}s($e,"renderResolver");var Ro="// Generated by apollion-tokens build \u2014 DO NOT EDIT. See apollion.config.mjs.";function Ve(e,o,n){let r=" ".repeat(o);for(let[i,t]of Object.entries(e))b(t)?n.push(`${r}${JSON.stringify(i)}: ${JSON.stringify(T(t.value))},`):(n.push(`${r}${i}: {`),Ve(t,o+1,n),n.push(`${r}},`))}s(Ve,"emitGroup");function Oe(e){let{brand:o,mode:n,surface:r,dimension:i}=e.meta,t=[Ro,`// Variant: brand=${o} mode=${n} surface=${r} dimension=${i}`,"","export const tokens = {"];return Ve(e.groups,1,t),t.push("} as const;","","export type Tokens = typeof tokens;",""),t.join(`
|
|
6
|
+
`)}s(Oe,"renderTs");var ko=["light","dark"],Io=["positive","negative"],xo=["compact","normal","spacious"];function M(e){let o=e.modes??ko,n=e.surfaces??Io,r=e.dimensions??xo,i=Object.entries(e.brands).sort(([a],[c])=>a.localeCompare(c)),t=[];for(let[a,c]of i)for(let d of o)for(let m of n)for(let p of r)t.push({brand:a,colors:c,mode:d,surface:m,dimension:p});return t}s(M,"expandVariants");function je(e){return`${e.brand}.${e.mode}.${e.surface}.${e.dimension}`}s(je,"variantName");import{createHash as So}from"node:crypto";function Z(e){return So("sha256").update(e).digest("hex")}s(Z,"sha256");function Q(e){return Z(K(e))}s(Q,"hashConfig");function K(e){return e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?`[${e.map(K).join(",")}]`:`{${Object.keys(e).sort().map(r=>`${JSON.stringify(r)}:${K(e[r])}`).join(",")}}`}s(K,"stableStringify");function Ae(e){try{let{execSync:o}=Ke("node:child_process");return o("git rev-parse --short HEAD",{cwd:e,stdio:["ignore","pipe","ignore"],encoding:"utf8"}).trim()}catch{return""}}s(Ae,"detectGitCommit");function Ee(){return{node:process.version,platform:`${process.platform}-${process.arch}`}}s(Ee,"buildEnv");function Ge(e){let o=[...e.files].sort((r,i)=>r.path.localeCompare(i.path)),n={configHash:e.configHash,files:o,gitCommit:e.gitCommit,buildEnv:e.buildEnv};return`${JSON.stringify(n,null,2)}
|
|
7
|
+
`}s(Ge,"serializeManifest");var wo="json/sets",Pe="json/resolver.json";function ee(e){return`${wo}/${e}.json`}s(ee,"setFile");function Do(e,o,n){return`${e}.color.${o}.${n}`}s(Do,"colorSetName");function vo(e){return`spacing.${e}`}s(vo,"spacingSetName");function F(e,o){e.includes(o)||e.push(o)}s(F,"pushUnique");function Me(e){let o=M(e),n=[],r=[],i=[],t=[],a=new Set,c=[],d=new Set,m=[];for(let p of o){F(n,p.brand),F(r,p.mode),F(i,p.surface),F(t,p.dimension);let w=Do(p.brand,p.mode,p.surface);a.has(w)||(a.add(w),c.push({kind:"color",name:w,file:ee(w),brand:p.brand,mode:p.mode,surface:p.surface}));let f=vo(p.dimension);d.has(f)||(d.add(f),m.push({kind:"spacing",name:f,file:ee(f),dimension:p.dimension}))}return{base:{kind:"base",name:"base",file:ee("base")},spacing:m,color:c,modifiers:{brand:n,mode:r,surface:i,dimension:t}}}s(Me,"planSets");import{createFoundation as _e}from"@apollion-dsi/core/themes/foundation";import{createSemantic as Oo}from"@apollion-dsi/core/themes/semantic";import{defaultInputSpacing as jo}from"@apollion-dsi/core/themes/spacing";import{invertForSurface as Ao}from"@apollion-dsi/core/themes/surface";import{converter as To,formatHex as Co,interpolate as $o,parse as Fe}from"culori";var Gn=To("oklch");function l(e,o,n){let r=Fe(e),i=Fe(o);if(!r||!i)return e;let t=$o([r,i],"oklch");return Co(t(n))??e}s(l,"mixOklch");function Vo(e){return e?typeof e=="string"?e:e.base:"#000"}s(Vo,"coerceToHex");function R(e,o){let n=Vo(e),r=o.deepDark,i=o.deepLight;return{base:n,dark:l(n,r,.6),action:l(n,r,.2),active:l(n,i,.6),light:l(n,i,.9)}}s(R,"mountSingleColor");function Ne(e){let o=e.deepLight,n=e.deepDark;return{0:o,5:l(o,n,.05),10:l(o,n,.1),20:l(o,n,.2),30:l(o,n,.3),40:l(o,n,.4),50:l(o,n,.5),60:l(o,n,.6),70:l(o,n,.7),80:l(o,n,.8),90:l(o,n,.9),100:l(o,n,1)}}s(Ne,"mountGreyscaleColors");function Le(e){let o=e.deepLight,n=e.deepDark,r=e.primary,i=s(a=>1/17*(a-1),"interpolation"),t=l(r,n,.5);return{0:l(t,o,i(18)),5:l(t,o,i(17.5)),10:l(t,o,i(17)),20:l(t,o,i(16)),30:l(t,o,i(15)),40:l(t,o,i(14)),50:l(t,o,i(13)),60:l(t,o,i(12)),70:l(t,o,i(11)),80:l(t,o,i(10)),90:l(t,o,i(9)),100:l(t,o,i(8)),110:l(t,o,i(7)),120:l(t,o,i(6)),130:l(t,o,i(5)),140:l(t,o,i(4)),150:l(t,o,i(3)),160:l(t,o,i(2)),170:t,180:l(t,n,.25)}}s(Le,"mountNeutralColors");function Eo(e){return{baseDark:e.baseDark,baseLight:e.baseLight,deepDark:e.deepDark,deepLight:e.deepLight,transparent:e.transparent??"transparent",neutral:Le(e),grayscale:Ne(e),main:R(e.main,e),opposite:R(e.opposite,e),complementary:R(e.complementary,e),danger:R(e.danger,e),information:R(e.information,e),success:R(e.success,e),warning:R(e.warning,e),primary:R(e.primary,e),secondary:R(e.secondary,e),tertiary:R(e.tertiary,e)}}s(Eo,"composeColors");function N(e,o=jo){let n=Eo(e.colors),r=j(o,e.dimension),i=Oo({colors:n,spacing:r}),t=_e(i);return e.surface==="negative"&&(t=_e(Ao({semantic:i,colors:n},"negative").semantic)),{foundation:t,colors:n}}s(N,"buildVariantThemes");async function Je(e){let{config:o,outDir:n,cwd:r=process.cwd(),verbose:i=!1}=e,t=M(o),a=o.output??{};if(t.length===0)throw new Error("apollion-tokens build: no variants (config.brands is empty)");let c=await Go(L(Fo(),"apollion-tokens-"));try{let d=[],m=s(async(f,I)=>{await No(c,f,I),d.push({path:f,sha256:Z(I)}),i&&console.log(` \u2713 ${f}`)},"emit");if(a.json){let f=Me(o),I=[],$=be();I.push($),await m(f.base.file,ve($));for(let g of f.spacing){let D=t.find(O=>O.dimension===g.dimension),{foundation:B}=N(D),V=ke(B,g.dimension);I.push(V),await m(g.file,Ce(V,g.dimension))}for(let g of f.color){let D=t.find(H=>H.brand===g.brand&&H.mode===g.mode&&H.surface===g.surface),{foundation:B,colors:V}=N(D),O=Re(B,V);I.push(O),await m(g.file,Te(O,g.brand,g.mode,g.surface))}he(I),await m(Pe,$e(o,f))}if(a.css||a.ts)for(let f of t){let{foundation:I,colors:$}=N(f),g=Ie(I,$,f),D=je(f);a.css&&await m(`css/${D}.css`,we(g)),a.ts&&await m(`ts/${D}.d.ts`,Oe(g))}let p={configHash:Q(o),files:d,gitCommit:Ae(r),buildEnv:Ee()},w=Ge(p);return await We(L(c,"manifest.json"),w),await Be(n,{recursive:!0,force:!0}),await He(Ue(n),{recursive:!0}),await Mo(c,n),i&&console.log(`\u2713 ${d.length} files \u2192 ${n}`),{manifest:p,outDir:n}}catch(d){throw await Be(c,{recursive:!0,force:!0}).catch(()=>{}),d}}s(Je,"build");async function ze(e){let{config:o,outDir:n}=e,r;try{r=JSON.parse(await Po(L(n,"manifest.json"),"utf8"))}catch{return!1}return r.configHash===Q(o)}s(ze,"check");async function No(e,o,n){let r=L(e,o);await He(Ue(r),{recursive:!0}),await We(r,n)}s(No,"writeAt");import{readFile as _o}from"node:fs/promises";import{resolve as Bo}from"node:path";import{createContext as Ho,Script as Wo}from"node:vm";import{z as u}from"zod";var y=u.string().regex(/^#([0-9a-fA-F]{3}){1,2}$|^transparent$|^rgb\(.*\)$|^oklch\(.*\)$/,{message:'Must be hex, rgb(), oklch(), or "transparent"'}),Lo=u.object({baseDark:u.string().optional(),baseLight:u.string().optional(),deepDark:y,deepLight:y,transparent:u.string().optional(),main:y.optional(),opposite:y.optional(),complementary:y.optional(),information:y.optional(),success:y.optional(),danger:y.optional(),warning:y.optional(),primary:y.optional(),secondary:y.optional(),tertiary:y.optional()}).passthrough(),Xe=u.object({brands:u.record(u.string(),Lo).refine(e=>Object.keys(e).length>0,{message:"apollion.config.mjs: brands must contain at least 1 entry"}),modes:u.array(u.enum(["light","dark"])).optional(),surfaces:u.array(u.enum(["positive","negative"])).optional(),dimensions:u.array(u.enum(["compact","normal","spacious"])).optional(),output:u.object({runtime:u.boolean().optional(),css:u.boolean().optional(),json:u.boolean().optional(),ts:u.boolean().optional()}).passthrough().optional()}).passthrough();var Uo=[/\brequire\s*\(/,/\bimport\s*\(/,/^\s*import\s+/m],Jo=1e3;var oe=class oe extends Error{constructor(n,r){super(n);this.configPath=r;this.name="ConfigLoadError"}};s(oe,"ConfigLoadError");var S=oe;async function qe(e){let o=Bo(e.configPath),n=await _o(o,"utf8");for(let d of Uo)if(d.test(n))throw new S(`apollion.config: dynamic require/import not allowed (matched ${d}). Declarative config only \u2014 see ADR-006 \xA73.8 B3.`,o);let r=n.replace(/(^|\n)\s*export\s+default\s+/,(d,m)=>`${m}__apollion_config_export = `);if(r===n)throw new S("apollion.config: missing `export default <object>;` \u2014 config must export a default object literal.",o);let i={__apollion_config_export:void 0,console:zo(),Symbol,Number,String,Boolean,Array,Object,JSON,Math,defineConfig:s(d=>d,"defineConfig")},t=Ho(i);try{new Wo(r,{filename:o}).runInContext(t,{timeout:Jo})}catch(d){throw new S(`apollion.config: evaluation failed \u2014 ${d instanceof Error?d.message:String(d)}`,o)}let a=i.__apollion_config_export;if(a===void 0)throw new S("apollion.config: `export default` produced undefined.",o);let c=Xe.safeParse(a);if(!c.success){let d=c.error.issues.map(m=>` ${m.path.join(".")||"(root)"}: ${m.message}`).join(`
|
|
8
|
+
`);throw new S(`apollion.config: schema validation failed \u2014
|
|
9
|
+
${d}`,o)}return c.data}s(qe,"loadConfig");function zo(){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(zo,"makeReadOnlyConsole");function qo(e){let o=e.slice(2),n=o[0];n!=="build"&&_(`Unknown command "${n??""}". Usage: apollion-tokens build [--check] [--verbose] --config <path> [--out <dir>]`);let r="apollion.config.mjs",i="dist",t=!1,a=!1;for(let c=1;c<o.length;c++){let d=o[c];switch(d){case"--config":r=o[++c]??_("--config needs a path");break;case"--out":i=o[++c]??_("--out needs a path");break;case"--check":t=!0;break;case"--verbose":a=!0;break;default:_(`Unknown flag "${d}"`)}}return{command:n,configPath:r,outDir:i,check:t,verbose:a}}s(qo,"parseArgs");function _(e){console.error(`apollion-tokens: ${e}`),process.exit(2)}s(_,"fail");async function Yo(e){let o=ne(e);if(o.endsWith(".json")){let n=await Xo(o,"utf8");return JSON.parse(n)}return qe({configPath:o})}s(Yo,"loadConfigFromPath");async function Ko(){let e=qo(process.argv),o=await Yo(e.configPath);if(e.check){await ze({config:o,outDir:ne(e.outDir)})||(console.error("apollion-tokens: dist/ is stale or missing (configHash mismatch). Re-run `apollion-tokens build` without --check."),process.exit(1)),console.log("apollion-tokens: dist/ is up-to-date with config.");return}let{manifest:n}=await Je({config:o,outDir:ne(e.outDir),verbose:e.verbose});console.log(`apollion-tokens: wrote ${n.files.length} file(s) \u2014 configHash=${n.configHash.slice(0,12)}\u2026`)}s(Ko,"main");Ko().catch(e=>{console.error(`apollion-tokens: ${e instanceof Error?e.message:String(e)}`),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollion-dsi/tokens",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Apollion Design System — Framework-agnostic design tokens",
|
|
5
5
|
"homepage": "https://github.com/apollion-ds/apollion",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"require": "./lib/config-loader.cjs"
|
|
34
34
|
},
|
|
35
35
|
"./dist/css/*": "./dist/css/*",
|
|
36
|
+
"./dist/json/resolver.json": "./dist/json/resolver.json",
|
|
37
|
+
"./dist/json/sets/*": "./dist/json/sets/*",
|
|
36
38
|
"./dist/json/*": "./dist/json/*",
|
|
37
39
|
"./dist/ts/*": "./dist/ts/*",
|
|
38
40
|
"./dist/manifest.json": "./dist/manifest.json"
|
|
@@ -70,7 +72,7 @@
|
|
|
70
72
|
},
|
|
71
73
|
"devDependencies": {
|
|
72
74
|
"@apollion-dsi/core": "workspace:*",
|
|
73
|
-
"@apollion-dsi/eslint-config": "0.
|
|
75
|
+
"@apollion-dsi/eslint-config": "0.8.0",
|
|
74
76
|
"@types/culori": "4.0.1",
|
|
75
77
|
"@types/jest": "30.0.0",
|
|
76
78
|
"@types/node": "25.7.0",
|
package/src/build.ts
CHANGED
|
@@ -7,9 +7,16 @@
|
|
|
7
7
|
* 3. Atomic `rename(tmpdir, outDir)` — if step 1 or 2 throws, `dist/` keeps
|
|
8
8
|
* its previous state. Never partial.
|
|
9
9
|
*
|
|
10
|
+
* **Output surfaces (R5):**
|
|
11
|
+
* - `dist/json/` — DTCG **Resolver**: `resolver.json` + reference-closed
|
|
12
|
+
* `sets/{base, spacing.<dimension>, <brand>.color.<mode>.<surface>}.json`.
|
|
13
|
+
* Hard cutover from the old per-variant JSON (pre-4.0 GA — no consumer reads
|
|
14
|
+
* `dist/json/*` yet). One manifest + O(b·m·s + d + 1) sets, not b·m·s·d docs.
|
|
15
|
+
* - `dist/css/` + `dist/ts/` — per-variant, fully resolved (unchanged).
|
|
16
|
+
*
|
|
10
17
|
* **Idempotency contract:** rerunning with the same `(config, gitHead,
|
|
11
18
|
* nodeVersion, platform)` produces byte-identical `dist/` + `manifest.json`.
|
|
12
|
-
* Verified by `__tests__/build
|
|
19
|
+
* Verified by `__tests__/build.test.ts`.
|
|
13
20
|
*
|
|
14
21
|
* **`--check` mode (CI gate):** read existing `manifest.json`, recompute
|
|
15
22
|
* the expected manifest from current config, compare. Exit 1 on drift.
|
|
@@ -24,13 +31,15 @@ import { tmpdir } from 'node:os';
|
|
|
24
31
|
import { dirname, join } from 'node:path';
|
|
25
32
|
|
|
26
33
|
import { renderCss } from './renderers/css';
|
|
27
|
-
import {
|
|
34
|
+
import { renderBaseSet, renderColorSet, renderResolver, renderSpacingSet } from './renderers/resolver';
|
|
28
35
|
import { renderTs } from './renderers/ts';
|
|
29
36
|
import type { ApollionConfig, Variant } from './config-schema';
|
|
30
37
|
import { expandVariants, variantName } from './config-schema';
|
|
31
|
-
import {
|
|
38
|
+
import type { IRSlice } from './ir';
|
|
39
|
+
import { assertSlicesMetaComplete, buildBaseIR, buildColorIR, buildFullIR, buildSpacingIR } from './ir';
|
|
32
40
|
import type { BuildManifest, ManifestFileEntry } from './manifest';
|
|
33
41
|
import { buildEnv, detectGitCommit, hashConfig, serializeManifest, sha256 } from './manifest';
|
|
42
|
+
import { planSets, RESOLVER_PATH } from './set-plan';
|
|
34
43
|
import { buildVariantThemes } from './theme-factory';
|
|
35
44
|
|
|
36
45
|
export interface BuildOptions {
|
|
@@ -59,34 +68,59 @@ export async function build(opts: BuildOptions): Promise<BuildResult> {
|
|
|
59
68
|
|
|
60
69
|
try {
|
|
61
70
|
const files: ManifestFileEntry[] = [];
|
|
71
|
+
const emit = async (path: string, content: string): Promise<void> => {
|
|
72
|
+
await writeAt(tmpRoot, path, content);
|
|
73
|
+
files.push({ path, sha256: sha256(content) });
|
|
74
|
+
if (verbose) console.log(` ✓ ${path}`);
|
|
75
|
+
};
|
|
62
76
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
// ── JSON surface (R5): Resolver manifest + reference-closed sets ─────────
|
|
78
|
+
// Hard cutover — no per-variant JSON. The base set is axis-invariant; colour
|
|
79
|
+
// sets vary by (brand × mode × surface); spacing sets vary by dimension.
|
|
80
|
+
// bg/text are dimension-invariant and spacing is brand/surface-invariant, so
|
|
81
|
+
// a single representative variant resolves each set's foundation.
|
|
82
|
+
if (output.json) {
|
|
83
|
+
const plan = planSets(config);
|
|
84
|
+
const slices: IRSlice[] = [];
|
|
85
|
+
|
|
86
|
+
const baseSlice = buildBaseIR();
|
|
87
|
+
slices.push(baseSlice);
|
|
88
|
+
await emit(plan.base.file, renderBaseSet(baseSlice));
|
|
89
|
+
|
|
90
|
+
for (const set of plan.spacing) {
|
|
91
|
+
const variant = variants.find((v) => v.dimension === set.dimension)!;
|
|
92
|
+
const { foundation } = buildVariantThemes(variant);
|
|
93
|
+
const slice = buildSpacingIR(foundation, set.dimension);
|
|
94
|
+
slices.push(slice);
|
|
95
|
+
await emit(set.file, renderSpacingSet(slice, set.dimension));
|
|
74
96
|
}
|
|
75
97
|
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
for (const set of plan.color) {
|
|
99
|
+
const variant = variants.find(
|
|
100
|
+
(v) => v.brand === set.brand && v.mode === set.mode && v.surface === set.surface,
|
|
101
|
+
)!;
|
|
102
|
+
const { foundation, colors } = buildVariantThemes(variant);
|
|
103
|
+
const slice = buildColorIR(foundation, colors);
|
|
104
|
+
slices.push(slice);
|
|
105
|
+
await emit(set.file, renderColorSet(slice, set.brand, set.mode, set.surface));
|
|
82
106
|
}
|
|
83
107
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
// Stale-key guard runs over the UNION of every emitted set (a single set
|
|
109
|
+
// is intentionally partial). Throws → atomic build aborts, dist untouched.
|
|
110
|
+
assertSlicesMetaComplete(slices);
|
|
111
|
+
|
|
112
|
+
await emit(RESOLVER_PATH, renderResolver(config, plan));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ── CSS + TS surfaces: per-variant, fully resolved (unchanged) ───────────
|
|
116
|
+
if (output.css || output.ts) {
|
|
117
|
+
for (const variant of variants) {
|
|
118
|
+
const { foundation, colors } = buildVariantThemes(variant);
|
|
119
|
+
const ir = buildFullIR(foundation, colors, variant);
|
|
120
|
+
const baseName = variantName(variant);
|
|
121
|
+
|
|
122
|
+
if (output.css) await emit(`css/${baseName}.css`, renderCss(ir));
|
|
123
|
+
if (output.ts) await emit(`ts/${baseName}.d.ts`, renderTs(ir));
|
|
90
124
|
}
|
|
91
125
|
}
|
|
92
126
|
|