@taprootio/espalier 2.16.0 → 2.18.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/custom-elements.json +1416 -1065
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/pickers/esp-picker-menu.js +1 -1
- package/dist/root/helpers/compute-theme-properties.js +1 -1
- package/dist/root/helpers/compute-variants.js +1 -1
- package/dist/shared/color-engine.js +1 -1
- package/dist/shared/esp-element-base.js +1 -1
- package/dist/shared/theme-fit-report.d.ts +162 -0
- package/dist/shared/theme-fit-report.js +1 -0
- package/dist/shared/theme-fit-trace.js +0 -0
- package/dist/shared/theme.d.ts +220 -5
- package/dist/shared/theme.js +1 -1
- package/dist/shared/variant-engine.js +1 -0
- package/package.json +1 -1
package/dist/shared/theme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ACCEPTED_COLOR_FORMS as v,parseCssColor as $,parseOklch as I,serializeOklch as T}from"./color-engine.js";const h=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"],B=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning"],R=["analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning"],d=["surface","raised1","raised2","raised3","raised4","accent","muted","text","border","ink","shadow"],w={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},A={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},y={background:{source:"primary",lightness:"surface"},layer1:{source:"primary",lightness:"raised1"},layer2:{source:"primary",lightness:"raised2"},layer3:{source:"primary",lightness:"raised3"},layer4:{source:"primary",lightness:"raised4"},actionBackground:{source:"primary",lightness:"raised3"},actionText:{source:"primary",lightness:"ink"},border:{source:"primary",lightness:"border"},shadow:{source:"primary",lightness:"shadow"},text:{source:"primary",lightness:"text"},dangerText:{source:"danger",lightness:"text"},headings:{source:"primary",lightness:"muted"},headingsHover:{source:"primary",lightness:"text"},link:{source:"complementary",lightness:"accent"},linkHover:{source:"complementary",lightness:"text"},linkHoverBg:{source:"triadic-left",lightness:"raised2"},inputCaret:{source:"triadic-right",lightness:"ink"},inputSelection:{source:"complementary",lightness:"text"},inputSelectionBg:{source:"triadic-left",lightness:"raised2"}},f=.4;function b(){const i={};for(const e of h)i[e]={min:0,max:f};return i}const M={seedColor:"oklch(0.7 0.125 216)",fontBody:"",fontHeadings:"",fontBrand:"",fontMonospace:"",fontWeightBody:"normal",fontWeightHeadings:"bold",fontWeightBrand:"bold",fontWeightMonospace:"normal",stylesheets:[],rootFontSize:16,typeRatio:1.25,spaceRatio:1.618,borderRadius:.2,viewportMin:320,viewportMax:1200,angles:{analogous:30,complementary:180,splitComplementary:30,triadic:120},semanticHues:{danger:27,success:150,warning:90},variantChroma:{},chroma:b(),semanticMappings:{...y}},L={...M,chroma:b(),semanticMappings:{...y},lightness:{...w}},D={...M,chroma:b(),semanticMappings:{...y},lightness:{...A}},S=new Set(["__proto__","constructor","prototype"]);function l(i){return!S.has(i)}function E(i,e){return S.has(i)?void 0:e}function U(i){return`--esp-color-${i.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function _(i){try{const e=atob(i),s=JSON.parse(e,E);return typeof s!="object"||s===null||Array.isArray(s)?null:s}catch{return null}}function k(i){return btoa(JSON.stringify(i))}function j(i){if(I(i))return i;const e=$(i);return e?T(e):i}function K(i,e){const s={...i,seedColor:typeof e.seedColor=="string"?j(e.seedColor):i.seedColor,fontBody:e.fontBody??i.fontBody,fontHeadings:e.fontHeadings??i.fontHeadings,fontBrand:e.fontBrand??i.fontBrand,fontMonospace:e.fontMonospace??i.fontMonospace,fontWeightBody:String(e.fontWeightBody??i.fontWeightBody),fontWeightHeadings:String(e.fontWeightHeadings??i.fontWeightHeadings),fontWeightBrand:String(e.fontWeightBrand??i.fontWeightBrand),fontWeightMonospace:String(e.fontWeightMonospace??i.fontWeightMonospace),stylesheets:e.stylesheets??[...i.stylesheets],rootFontSize:e.rootFontSize??i.rootFontSize,typeRatio:e.typeRatio??i.typeRatio,spaceRatio:e.spaceRatio??i.spaceRatio,borderRadius:e.borderRadius??i.borderRadius,viewportMin:e.viewportMin??i.viewportMin,viewportMax:e.viewportMax??i.viewportMax,angles:{...i.angles,...e.angles},semanticHues:{...i.semanticHues,...e.semanticHues},variantChroma:{...i.variantChroma,...e.variantChroma},lightness:{...i.lightness,...e.lightness},chroma:C(i.chroma,e.chroma),semanticMappings:C(i.semanticMappings,e.semanticMappings)};return e.pageBackgroundImage!==void 0&&(s.pageBackgroundImage=e.pageBackgroundImage),e.pageBackgroundImageOpacity!==void 0&&(s.pageBackgroundImageOpacity=e.pageBackgroundImageOpacity),e.boxBackgroundImage!==void 0&&(s.boxBackgroundImage=e.boxBackgroundImage),e.boxBackgroundImageOpacity!==void 0&&(s.boxBackgroundImageOpacity=e.boxBackgroundImageOpacity),e.vellumOpacity!==void 0&&(s.vellumOpacity=e.vellumOpacity),e.vellumBackgroundImage!==void 0&&(s.vellumBackgroundImage=e.vellumBackgroundImage),e.vellumBackgroundImageOpacity!==void 0&&(s.vellumBackgroundImageOpacity=e.vellumBackgroundImageOpacity),s}function C(i,e){if(!e)return{...i};const s={...i};for(const c of Object.keys(e)){const u=e[c];u!==void 0&&(s[c]=u)}return s}function z(i){const e=[],s=[];let c;try{c=atob(i)}catch{return e.push("Failed to decode Base64 string."),{valid:!1,errors:e,warnings:s}}let u;try{u=JSON.parse(c)}catch{return e.push("Decoded string is not valid JSON."),{valid:!1,errors:e,warnings:s}}if(typeof u!="object"||u===null||Array.isArray(u))return e.push("Theme must be a JSON object."),{valid:!1,errors:e,warnings:s};const o=u;"seedColor"in o&&(typeof o.seedColor!="string"?e.push("seedColor must be a string."):$(o.seedColor)||e.push(`seedColor is not a valid CSS color: "${o.seedColor}". Accepted forms: ${v}.`));for(const t of["fontBody","fontHeadings","fontBrand","fontMonospace"])t in o&&typeof o[t]!="string"&&e.push(`${t} must be a string.`);const g=["normal","bold","lighter","bolder"],p=["inherit","initial","unset","revert","revert-layer"];for(const t of["fontWeightBody","fontWeightHeadings","fontWeightBrand","fontWeightMonospace"])if(t in o){const n=o[t];if(typeof n=="number")(n<1||n>1e3)&&e.push(`${t} numeric value must be 1\u20131000 (got ${n}).`);else if(typeof n=="string"){const a=g.includes(n)||p.includes(n);if(/^\d+$/.test(n)){const x=Number(n);(x<1||x>1e3)&&e.push(`${t} numeric value must be 1\u20131000 (got "${n}").`)}else a||s.push(`${t} = "${n}" is not a standard font-weight value.`)}else e.push(`${t} must be a string or number.`)}"stylesheets"in o&&(Array.isArray(o.stylesheets)?o.stylesheets.some(t=>typeof t!="string")&&e.push("Every entry in stylesheets must be a string."):e.push("stylesheets must be an array of strings."));const m=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[t,n,a]of m)if(t in o)if(typeof o[t]!="number"||!isFinite(o[t]))e.push(`${t} must be a finite number.`);else{const r=o[t];n!==void 0&&r<n&&e.push(`${t} must be \u2265 ${n} (got ${r}).`),a!==void 0&&r>a&&s.push(`${t} = ${r} is unusually high (max ${a}).`)}for(const t of["typeRatio","spaceRatio"])if(t in o)if(typeof o[t]!="number"||!isFinite(o[t]))e.push(`${t} must be a finite number.`);else{const n=o[t];n<=1&&e.push(`${t} must be > 1 (got ${n}).`);const a=t==="typeRatio"?1.3:2;n>a&&s.push(`${t} = ${n} is very high (max ${a}); scales may be extreme.`)}if("viewportMin"in o&&"viewportMax"in o){const t=o.viewportMin,n=o.viewportMax;typeof t=="number"&&typeof n=="number"&&t>=n&&e.push(`viewportMin (${t}) must be less than viewportMax (${n}).`)}if("angles"in o)if(typeof o.angles!="object"||o.angles===null)e.push("angles must be an object.");else{const t=o.angles;for(const n of["analogous","complementary","splitComplementary","triadic"])if(n in t)if(typeof t[n]!="number"||!isFinite(t[n]))e.push(`angles.${n} must be a finite number.`);else{const a=t[n];(a<0||a>360)&&s.push(`angles.${n} = ${a} is outside 0\u2013360.`)}}if("semanticHues"in o)if(typeof o.semanticHues!="object"||o.semanticHues===null)e.push("semanticHues must be an object.");else{const t=o.semanticHues;for(const n of["danger","success","warning"])if(n in t)if(typeof t[n]!="number"||!isFinite(t[n]))e.push(`semanticHues.${n} must be a finite number.`);else{const a=t[n];(a<0||a>360)&&s.push(`semanticHues.${n} = ${a} is outside 0\u2013360.`)}}if("variantChroma"in o)if(typeof o.variantChroma!="object"||o.variantChroma===null)e.push("variantChroma must be an object.");else{const t=o.variantChroma;for(const n of R)if(n in t)if(typeof t[n]!="number"||!isFinite(t[n]))e.push(`variantChroma["${n}"] must be a finite number.`);else{const a=t[n];a<0&&e.push(`variantChroma["${n}"] must be \u2265 0 (got ${a}).`),a>f&&s.push(`variantChroma["${n}"] = ${a} exceeds ${f}.`)}}if("lightness"in o)if(typeof o.lightness!="object"||o.lightness===null)e.push("lightness must be an object.");else{const t=o.lightness;for(const n of d)if(n in t)if(typeof t[n]!="number"||!isFinite(t[n]))e.push(`lightness.${n} must be a finite number.`);else{const a=t[n];(a<0||a>1)&&e.push(`lightness.${n} must be 0\u20131 (got ${a}).`)}}if("chroma"in o)if(typeof o.chroma!="object"||o.chroma===null)e.push("chroma must be an object.");else{const t=o.chroma;for(const n of h)if(n in t){const a=t[n];if(typeof a!="object"||a===null){e.push(`chroma.${n} must be { min, max }.`);continue}const r=a;(typeof r.min!="number"||r.min<0)&&e.push(`chroma.${n}.min must be \u2265 0.`),(typeof r.max!="number"||r.max<0||r.max>f)&&e.push(`chroma.${n}.max must be 0\u2013${f}.`),typeof r.min=="number"&&typeof r.max=="number"&&r.min>r.max&&e.push(`chroma.${n}.min (${r.min}) must be \u2264 max (${r.max}).`)}}if("semanticMappings"in o)if(typeof o.semanticMappings!="object"||o.semanticMappings===null)e.push("semanticMappings must be an object.");else{const t=o.semanticMappings;for(const n of h)if(n in t){const a=t[n];if(typeof a!="object"||a===null){e.push(`semanticMappings.${n} must be { source, lightness }.`);continue}const r=a;(typeof r.source!="string"||!B.includes(r.source))&&e.push(`semanticMappings.${n}.source must be one of: ${B.join(", ")}.`),(typeof r.lightness!="string"||!d.includes(r.lightness))&&e.push(`semanticMappings.${n}.lightness must be one of: ${d.join(", ")}.`)}}for(const t of["pageBackgroundImage","boxBackgroundImage","vellumBackgroundImage"])t in o&&typeof o[t]!="string"&&e.push(`${t} must be a string.`);for(const t of["pageBackgroundImageOpacity","boxBackgroundImageOpacity","vellumOpacity","vellumBackgroundImageOpacity"])if(t in o)if(typeof o[t]!="number"||!isFinite(o[t]))e.push(`${t} must be a finite number.`);else{const n=o[t];(n<0||n>1)&&e.push(`${t} must be 0\u20131 (got ${n}).`)}return{valid:e.length===0,errors:e,warnings:s}}const W=["angles","chroma","lightness","semanticHues","semanticMappings","variantChroma"];function F(i,e){const s={};for(const[c,u]of Object.entries(i))l(c)&&(s[c]=u);for(const[c,u]of Object.entries(e))u!==void 0&&l(c)&&(s[c]=u);for(const c of W){const u=i[c],o=e[c];if(u&&typeof u=="object"&&!Array.isArray(u)&&o&&typeof o=="object"&&!Array.isArray(o)){const g={};for(const[p,m]of Object.entries(u))l(p)&&(g[p]=m);for(const[p,m]of Object.entries(o))m!==void 0&&l(p)&&(g[p]=m);s[c]=g}}return s}function G(...i){let e={};for(const s of i){if(!s)continue;const c=_(s);c&&(e=F(e,c))}return k(e)}function O(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const H={borderRadius:.1,fontBody:'"Noto Sans", sans-serif',fontWeightBody:"normal",fontHeadings:'"Inika", serif',fontWeightHeadings:"normal",fontBrand:'"Inika", serif',fontWeightBrand:"normal",fontMonospace:'"JetBrains Mono", monospace',fontWeightMonospace:"normal",seedColor:"oklch(.07 0.15 216)"};function J(i){return k({...H,pageBackgroundImage:`url("${O(i)}")`,pageBackgroundImageOpacity:.5})}function P(i){return k({...H,pageBackgroundImage:`url("${O(i)}")`,pageBackgroundImageOpacity:.55})}export{B as COLOR_SOURCES,A as DEFAULT_DARK_LIGHTNESS,D as DEFAULT_DARK_THEME,w as DEFAULT_LIGHT_LIGHTNESS,L as DEFAULT_LIGHT_THEME,y as DEFAULT_SEMANTIC_MAPPINGS,d as LIGHTNESS_KEYS,W as NESTED_THEME_KEYS,h as SEMANTIC_COLOR_NAMES,R as VARIANT_COLOR_SOURCES,P as buildTaprootDarkTheme,J as buildTaprootLightTheme,k as encodeTheme,G as layerThemes,F as mergePartials,K as mergeTheme,_ as parseTheme,U as semanticToCSS,z as validateTheme};
|
|
1
|
+
import{ACCEPTED_COLOR_FORMS as j,apcaContrast as J,deriveSemantic as Y,parseCssColor as O,parseOklch as X,serializeOklch as Z}from"./color-engine.js";import{computeVariants as q,parseAnchorSource as Q,resolveAnchorColor as ee,resolveMappingSource as ne}from"./variant-engine.js";const L=/^[a-z][a-z0-9-]*$/;function te(t){return Q(t)}function xe(t,e){return ee(t,e)}const E=["canvas","ink","accent","action","structure"],N={canvas:{color:[["background","surface"],["layer1","raised1"],["layer2","raised2"],["layer3","raised3"],["layer4","raised4"]]},ink:{color:[["text","text"],["inputSelection","text"]],heading:[["headings","muted"],["headingsHover","ink"]]},accent:{color:[["linkHoverBg","raised2"],["inputSelectionBg","raised2"],["inputCaret","ink"]],text:[["link","accent"],["linkHover","text"]]},action:{color:[["actionBackground","muted"]],ink:[["actionText","surface"]]},structure:{color:[["border","border"],["shadow","shadow"]]}},oe=new Set(["action.color"]),se={canvas:"background",ink:"text",accent:"link",action:"actionBackground",structure:"border"},re={"action.ink":{role:"canvas",slot:"color"}},ie=.45;function W(t,e){const i=F.actionText,a=[...x].sort((p,m)=>t[p]-t[m]||x.indexOf(p)-x.indexOf(m)),u=e?a.filter(p=>e(p)>=i.targetLc):a,s=u.length>0?u:a;let l,f=1/0;for(const p of s){const m=Math.abs(t[p]-ie);m<f&&(f=m,l=p)}return l??"muted"}function ae(t,e){const i=e[t]>.5;let a=x[0];for(const u of x)(i?e[u]<e[a]:e[u]>e[a])&&(a=u);return a}function A(t,e){if(t===void 0)return;if(typeof t=="string")return e==="color"?t:void 0;const i=t[e];return typeof i=="string"?i:void 0}function D(t,e,i,a={}){const u={},s={};for(const[l,f]of Object.entries(a.explicitMappings??{}))f!==void 0&&(s[l]=f.lightness);for(const l of E){const f=t[l];if(f!==void 0)for(const[p,m]of Object.entries(N[l])){const h=re[`${l}.${p}`];let n=A(f,p),o=!1;if(n===void 0&&(h&&(n=A(t[h.role],h.slot),n??=i[se[h.role]]?.source,o=n!==void 0),n??=A(f,"color")),n!==void 0)for(const[r,c]of m){let g=c;if(oe.has(`${l}.${p}`))g=W(e,a.actionSurfaceContrast?y=>a.actionSurfaceContrast(n,y):void 0);else if(o&&h){const y=F[r],b=(y&&s[y.bg])??W(e,a.actionSurfaceContrast?S=>a.actionSurfaceContrast(A(f,"color"),S):void 0);g=ae(b,e)}u[r]={source:n,lightness:g}}}}return u}const F={text:{bg:"background",targetLc:75},dangerText:{bg:"background",targetLc:75},headings:{bg:"background",targetLc:60},headingsHover:{bg:"background",targetLc:60},link:{bg:"background",targetLc:75},linkHover:{bg:"background",targetLc:75},actionText:{bg:"actionBackground",targetLc:75},inputCaret:{bg:"layer2",targetLc:60},inputSelection:{bg:"inputSelectionBg",targetLc:60}},I=["background","layer1","layer2","layer3","layer4","actionBackground","actionText","border","shadow","text","dangerText","headings","headingsHover","link","linkHover","linkHoverBg","inputCaret","inputSelection","inputSelectionBg"],T=["primary","analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning"],ce=["analogous-left","analogous-right","complementary","split-complementary-left","split-complementary-right","triadic-left","triadic-right","danger","success","warning"],x=["surface","raised1","raised2","raised3","raised4","accent","muted","text","border","ink","shadow"],ue={surface:.99,raised1:.97,raised2:.9,raised3:.8,raised4:.72,accent:.5,muted:.45,text:.35,border:.3,ink:.25,shadow:.2},le={surface:.15,raised1:.2,raised2:.3,raised3:.4,raised4:.36,accent:.6,muted:.75,text:.85,border:.7,ink:.95,shadow:.6},w={background:{source:"primary",lightness:"surface"},layer1:{source:"primary",lightness:"raised1"},layer2:{source:"primary",lightness:"raised2"},layer3:{source:"primary",lightness:"raised3"},layer4:{source:"primary",lightness:"raised4"},actionBackground:{source:"primary",lightness:"raised3"},actionText:{source:"primary",lightness:"ink"},border:{source:"primary",lightness:"border"},shadow:{source:"primary",lightness:"shadow"},text:{source:"primary",lightness:"text"},dangerText:{source:"danger",lightness:"text"},headings:{source:"primary",lightness:"muted"},headingsHover:{source:"primary",lightness:"text"},link:{source:"complementary",lightness:"accent"},linkHover:{source:"complementary",lightness:"text"},linkHoverBg:{source:"triadic-left",lightness:"raised2"},inputCaret:{source:"triadic-right",lightness:"ink"},inputSelection:{source:"complementary",lightness:"text"},inputSelectionBg:{source:"triadic-left",lightness:"raised2"}},v=.4;function R(){const t={};for(const e of I)t[e]={min:0,max:v};return t}const P={seedColor:"oklch(0.7 0.125 216)",fontBody:"",fontHeadings:"",fontBrand:"",fontMonospace:"",fontWeightBody:"normal",fontWeightHeadings:"bold",fontWeightBrand:"bold",fontWeightMonospace:"normal",stylesheets:[],rootFontSize:16,typeRatio:1.25,spaceRatio:1.618,borderRadius:.2,viewportMin:320,viewportMax:1200,angles:{analogous:30,complementary:180,splitComplementary:30,triadic:120},semanticHues:{danger:27,success:150,warning:90},variantChroma:{},chroma:R(),semanticMappings:{...w},anchors:{},roles:{}},fe={...P,chroma:R(),semanticMappings:{...w},anchors:{},roles:{},lightness:{...ue}},pe={...P,chroma:R(),semanticMappings:{...w},anchors:{},roles:{},lightness:{...le}},M=new WeakMap;M.set(fe,new Set),M.set(pe,new Set);const K=new Set(["__proto__","constructor","prototype"]);function d(t){return!K.has(t)}function ge(t,e){return K.has(t)?void 0:e}function Se(t){return`--esp-color-${t.replace(/([A-Z])/g,"-$1").replace(/(\d)/g,"-$1").toLowerCase()}`}function me(t){try{const e=atob(t),i=JSON.parse(e,ge);return typeof i!="object"||i===null||Array.isArray(i)?null:i}catch{return null}}function H(t){return btoa(JSON.stringify(t))}function _(t){if(X(t))return t;const e=O(t);return e?Z(e):t}function U(t,e){const i={};for(const[a,u]of Object.entries(t))d(a)&&(i[a]=u);if(!e)return i;for(const[a,u]of Object.entries(e)){if(u===void 0||!d(a))continue;const s=i[a];if(s!==void 0&&typeof u=="object"&&u!==null){const l={};if(typeof s=="string")l.color=s;else for(const[f,p]of Object.entries(s))d(f)&&(l[f]=p);for(const[f,p]of Object.entries(u))p!==void 0&&d(f)&&(l[f]=p);i[a]=l;continue}i[a]=u}return i}function de(t){const e={};for(const[i,a]of Object.entries(t)){if(!d(i))continue;if(typeof a=="string"){e[i]=_(a);continue}const u={};for(const[s,l]of Object.entries(a))d(s)&&(u[s]=typeof l=="string"?_(l):l);e[i]=u}return e}function z(t){const e=O(t.seedColor);if(!e)return;const i=q(e,t);return(a,u)=>{const s=ne(a,i,t.anchors)??i.primary,l=t.chroma.actionBackground,f=Y(s,t.lightness[u],l.min,l.max),p={l:f.l>.5?0:1,c:0,h:0};return Math.abs(J(p,f))}}function he(t){const e=M.get(t);if(e)return new Set(e);const i=new Set,a=D(t.roles,t.lightness,t.semanticMappings,{actionSurfaceContrast:z(t)});for(const[u,s]of Object.entries(a)){const l=t.semanticMappings[u];(l.source!==s.source||l.lightness!==s.lightness)&&i.add(u)}return i}function Oe(t,e){const i={...t.roles,...e.roles},a={...t.lightness,...e.lightness},u=de(U(t.anchors,e.anchors)),s=typeof e.seedColor=="string"?_(e.seedColor):t.seedColor,l=e.semanticMappings,f={...t.angles,...e.angles},p={...t.semanticHues,...e.semanticHues},m={...t.variantChroma,...e.variantChroma},h=B(t.chroma,e.chroma),n=he(t),o=new Set(n),r={};for(const $ of n)r[$]=t.semanticMappings[$];for(const[$,C]of Object.entries(l??{}))C!==void 0&&(o.add($),r[$]=C);const c=B(t.semanticMappings,l),g=z({angles:f,anchors:u,chroma:h,lightness:a,seedColor:s,semanticHues:p,variantChroma:m}),y=D(i,a,c,{explicitMappings:r,actionSurfaceContrast:g}),b={};for(const[$,C]of Object.entries(y))o.has($)||(b[$]=C);const S=B(B(t.semanticMappings,b),l),k={...t,seedColor:s,fontBody:e.fontBody??t.fontBody,fontHeadings:e.fontHeadings??t.fontHeadings,fontBrand:e.fontBrand??t.fontBrand,fontMonospace:e.fontMonospace??t.fontMonospace,fontWeightBody:String(e.fontWeightBody??t.fontWeightBody),fontWeightHeadings:String(e.fontWeightHeadings??t.fontWeightHeadings),fontWeightBrand:String(e.fontWeightBrand??t.fontWeightBrand),fontWeightMonospace:String(e.fontWeightMonospace??t.fontWeightMonospace),stylesheets:e.stylesheets??[...t.stylesheets],rootFontSize:e.rootFontSize??t.rootFontSize,typeRatio:e.typeRatio??t.typeRatio,spaceRatio:e.spaceRatio??t.spaceRatio,borderRadius:e.borderRadius??t.borderRadius,viewportMin:e.viewportMin??t.viewportMin,viewportMax:e.viewportMax??t.viewportMax,angles:f,semanticHues:p,variantChroma:m,lightness:a,chroma:h,semanticMappings:S,anchors:u,roles:i};return e.pageBackgroundImage!==void 0&&(k.pageBackgroundImage=e.pageBackgroundImage),e.pageBackgroundImageOpacity!==void 0&&(k.pageBackgroundImageOpacity=e.pageBackgroundImageOpacity),e.boxBackgroundImage!==void 0&&(k.boxBackgroundImage=e.boxBackgroundImage),e.boxBackgroundImageOpacity!==void 0&&(k.boxBackgroundImageOpacity=e.boxBackgroundImageOpacity),e.vellumOpacity!==void 0&&(k.vellumOpacity=e.vellumOpacity),e.vellumBackgroundImage!==void 0&&(k.vellumBackgroundImage=e.vellumBackgroundImage),e.vellumBackgroundImageOpacity!==void 0&&(k.vellumBackgroundImageOpacity=e.vellumBackgroundImageOpacity),M.set(k,new Set(o)),k}function B(t,e){if(!e)return{...t};const i={...t};for(const a of Object.keys(e)){const u=e[a];u!==void 0&&(i[a]=u)}return i}function ve(t){const e=[],i=[];let a;try{a=atob(t)}catch{return e.push("Failed to decode Base64 string."),{valid:!1,errors:e,warnings:i}}let u;try{u=JSON.parse(a)}catch{return e.push("Decoded string is not valid JSON."),{valid:!1,errors:e,warnings:i}}if(typeof u!="object"||u===null||Array.isArray(u))return e.push("Theme must be a JSON object."),{valid:!1,errors:e,warnings:i};const s=u;"seedColor"in s&&(typeof s.seedColor!="string"?e.push("seedColor must be a string."):O(s.seedColor)||e.push(`seedColor is not a valid CSS color: "${s.seedColor}". Accepted forms: ${j}.`));for(const n of["fontBody","fontHeadings","fontBrand","fontMonospace"])n in s&&typeof s[n]!="string"&&e.push(`${n} must be a string.`);const l=["normal","bold","lighter","bolder"],f=["inherit","initial","unset","revert","revert-layer"];for(const n of["fontWeightBody","fontWeightHeadings","fontWeightBrand","fontWeightMonospace"])if(n in s){const o=s[n];if(typeof o=="number")(o<1||o>1e3)&&e.push(`${n} numeric value must be 1\u20131000 (got ${o}).`);else if(typeof o=="string"){const r=l.includes(o)||f.includes(o);if(/^\d+$/.test(o)){const g=Number(o);(g<1||g>1e3)&&e.push(`${n} numeric value must be 1\u20131000 (got "${o}").`)}else r||i.push(`${n} = "${o}" is not a standard font-weight value.`)}else e.push(`${n} must be a string or number.`)}"stylesheets"in s&&(Array.isArray(s.stylesheets)?s.stylesheets.some(n=>typeof n!="string")&&e.push("Every entry in stylesheets must be a string."):e.push("stylesheets must be an array of strings."));const p=[["rootFontSize",1,100],["borderRadius",0,10],["viewportMin",100,1e4],["viewportMax",200,1e4]];for(const[n,o,r]of p)if(n in s)if(typeof s[n]!="number"||!isFinite(s[n]))e.push(`${n} must be a finite number.`);else{const c=s[n];o!==void 0&&c<o&&e.push(`${n} must be \u2265 ${o} (got ${c}).`),r!==void 0&&c>r&&i.push(`${n} = ${c} is unusually high (max ${r}).`)}for(const n of["typeRatio","spaceRatio"])if(n in s)if(typeof s[n]!="number"||!isFinite(s[n]))e.push(`${n} must be a finite number.`);else{const o=s[n];o<=1&&e.push(`${n} must be > 1 (got ${o}).`);const r=n==="typeRatio"?1.3:2;o>r&&i.push(`${n} = ${o} is very high (max ${r}); scales may be extreme.`)}if("viewportMin"in s&&"viewportMax"in s){const n=s.viewportMin,o=s.viewportMax;typeof n=="number"&&typeof o=="number"&&n>=o&&e.push(`viewportMin (${n}) must be less than viewportMax (${o}).`)}if("angles"in s)if(typeof s.angles!="object"||s.angles===null)e.push("angles must be an object.");else{const n=s.angles;for(const o of["analogous","complementary","splitComplementary","triadic"])if(o in n)if(typeof n[o]!="number"||!isFinite(n[o]))e.push(`angles.${o} must be a finite number.`);else{const r=n[o];(r<0||r>360)&&i.push(`angles.${o} = ${r} is outside 0\u2013360.`)}}if("semanticHues"in s)if(typeof s.semanticHues!="object"||s.semanticHues===null)e.push("semanticHues must be an object.");else{const n=s.semanticHues;for(const o of["danger","success","warning"])if(o in n)if(typeof n[o]!="number"||!isFinite(n[o]))e.push(`semanticHues.${o} must be a finite number.`);else{const r=n[o];(r<0||r>360)&&i.push(`semanticHues.${o} = ${r} is outside 0\u2013360.`)}}if("variantChroma"in s)if(typeof s.variantChroma!="object"||s.variantChroma===null)e.push("variantChroma must be an object.");else{const n=s.variantChroma;for(const o of ce)if(o in n)if(typeof n[o]!="number"||!isFinite(n[o]))e.push(`variantChroma["${o}"] must be a finite number.`);else{const r=n[o];r<0&&e.push(`variantChroma["${o}"] must be \u2265 0 (got ${r}).`),r>v&&i.push(`variantChroma["${o}"] = ${r} exceeds ${v}.`)}}if("lightness"in s)if(typeof s.lightness!="object"||s.lightness===null)e.push("lightness must be an object.");else{const n=s.lightness;for(const o of x)if(o in n)if(typeof n[o]!="number"||!isFinite(n[o]))e.push(`lightness.${o} must be a finite number.`);else{const r=n[o];(r<0||r>1)&&e.push(`lightness.${o} must be 0\u20131 (got ${r}).`)}}if("chroma"in s)if(typeof s.chroma!="object"||s.chroma===null)e.push("chroma must be an object.");else{const n=s.chroma;for(const o of I)if(o in n){const r=n[o];if(typeof r!="object"||r===null){e.push(`chroma.${o} must be { min, max }.`);continue}const c=r;(typeof c.min!="number"||c.min<0)&&e.push(`chroma.${o}.min must be \u2265 0.`),(typeof c.max!="number"||c.max<0||c.max>v)&&e.push(`chroma.${o}.max must be 0\u2013${v}.`),typeof c.min=="number"&&typeof c.max=="number"&&c.min>c.max&&e.push(`chroma.${o}.min (${c.min}) must be \u2264 max (${c.max}).`)}}if("anchors"in s)if(typeof s.anchors!="object"||s.anchors===null||Array.isArray(s.anchors))e.push("anchors must be an object of named colors.");else for(const[n,o]of Object.entries(s.anchors))if(d(n)?L.test(n)||e.push(`anchors: "${n}" is not a valid anchor name; use a lowercase slug (letters, digits, hyphens).`):e.push(`anchors: "${n}" is a reserved JavaScript property name and cannot be an anchor name; rename it.`),T.includes(n)&&e.push(`anchors: "${n}" collides with a reserved color source name.`),typeof o=="string")O(o)||e.push(`anchors.${n} is not a valid CSS color: "${o}". Accepted forms: ${j}.`);else if(typeof o=="object"&&o!==null&&!Array.isArray(o)){const r=o;typeof r.color!="string"&&e.push(`anchors.${n} must declare its base "color".`);for(const[c,g]of Object.entries(r))d(c)?c!=="color"&&!L.test(c)&&e.push(`anchors.${n}: "${c}" is not a valid slot name; use a lowercase slug.`):e.push(`anchors.${n}: "${c}" is a reserved JavaScript property name and cannot be a slot name; rename it.`),typeof g!="string"?e.push(`anchors.${n}.${c} must be a CSS color string.`):O(g)||e.push(`anchors.${n}.${c} is not a valid CSS color: "${g}". Accepted forms: ${j}.`)}else e.push(`anchors.${n} must be a color string or a { color, \u2026slots } object.`);const m=new Map;if("anchors"in s&&typeof s.anchors=="object"&&s.anchors!==null&&!Array.isArray(s.anchors))for(const[n,o]of Object.entries(s.anchors))m.set(n,o);function h(n,o){if(!n.startsWith("anchor:")){T.includes(n)||e.push(`${o} must be one of: ${T.join(", ")}, or a declared anchor as anchor:<name> / anchor:<name>.<slot>.`);return}const r=te(n);if(!r){e.push(`${o} "${n}" is not valid anchor syntax; use anchor:<name> or anchor:<name>.<slot>.`);return}if(!m.has(r.name)){const c=[...m.keys()];e.push(`${o} references undeclared anchor "${r.name}". Declared anchors: ${c.length>0?c.join(", "):"(none)"}.`);return}if(r.slot!==void 0){const c=m.get(r.name);if(typeof(typeof c=="object"&&c!==null&&!Array.isArray(c)?c[r.slot]:void 0)!="string"){const y=typeof c=="object"&&c!==null?Object.keys(c).filter(b=>b!=="color"):[];e.push(`${o} references unknown slot "${r.slot}" on anchor "${r.name}". Declared slots: ${y.length>0?y.join(", "):"(none)"}.`)}}}if("roles"in s)if(typeof s.roles!="object"||s.roles===null||Array.isArray(s.roles))e.push("roles must be an object.");else{const n=s.roles;for(const[o,r]of Object.entries(n)){if(!E.includes(o)){e.push(`roles.${o} is not a role; expected one of: ${E.join(", ")}. (The status family is reserved and is not a role.)`);continue}const c=o,g=N[c];if(typeof r=="string"){h(r,`roles.${c}`);continue}if(typeof r!="object"||r===null||Array.isArray(r)){e.push(`roles.${c} must be a color source or a { color, \u2026slots } object.`);continue}const y=r;typeof y.color!="string"&&e.push(`roles.${c} must declare its base "color".`);for(const[b,S]of Object.entries(y)){if(!Object.prototype.hasOwnProperty.call(g,b)||!d(b)){const k=Object.keys(g).filter($=>$!=="color");e.push(`roles.${c}.${b} is not a slot of the ${c} role. Declared slots: ${k.length>0?k.join(", "):"(none)"}.`);continue}typeof S!="string"?e.push(`roles.${c}.${b} must be a color source string.`):h(S,`roles.${c}.${b}`)}}}if("semanticMappings"in s)if(typeof s.semanticMappings!="object"||s.semanticMappings===null)e.push("semanticMappings must be an object.");else{const n=s.semanticMappings;for(const o of I)if(o in n){const r=n[o];if(typeof r!="object"||r===null){e.push(`semanticMappings.${o} must be { source, lightness }.`);continue}const c=r;typeof c.source!="string"?e.push(`semanticMappings.${o}.source must be a string.`):h(c.source,`semanticMappings.${o}.source`),(typeof c.lightness!="string"||!x.includes(c.lightness))&&e.push(`semanticMappings.${o}.lightness must be one of: ${x.join(", ")}.`)}}for(const n of["pageBackgroundImage","boxBackgroundImage","vellumBackgroundImage"])n in s&&typeof s[n]!="string"&&e.push(`${n} must be a string.`);for(const n of["pageBackgroundImageOpacity","boxBackgroundImageOpacity","vellumOpacity","vellumBackgroundImageOpacity"])if(n in s)if(typeof s[n]!="number"||!isFinite(s[n]))e.push(`${n} must be a finite number.`);else{const o=s[n];(o<0||o>1)&&e.push(`${n} must be 0\u20131 (got ${o}).`)}return{valid:e.length===0,errors:e,warnings:i}}const ye=["anchors","angles","roles","chroma","lightness","semanticHues","semanticMappings","variantChroma"];function be(t,e){const i={};for(const[a,u]of Object.entries(t))d(a)&&(i[a]=u);for(const[a,u]of Object.entries(e))u!==void 0&&d(a)&&(i[a]=u);for(const a of ye){const u=t[a],s=e[a];if(u&&typeof u=="object"&&!Array.isArray(u)&&s&&typeof s=="object"&&!Array.isArray(s)){if(a==="anchors"){i[a]=U(u,s);continue}const l={};for(const[f,p]of Object.entries(u))d(f)&&(l[f]=p);for(const[f,p]of Object.entries(s))p!==void 0&&d(f)&&(l[f]=p);i[a]=l}}return i}function Ce(...t){let e={};for(const i of t){if(!i)continue;const a=me(i);a&&(e=be(e,a))}return H(e)}function G(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}const V={borderRadius:.1,fontBody:'"Noto Sans", sans-serif',fontWeightBody:"normal",fontHeadings:'"Inika", serif',fontWeightHeadings:"normal",fontBrand:'"Inika", serif',fontWeightBrand:"normal",fontMonospace:'"JetBrains Mono", monospace',fontWeightMonospace:"normal",seedColor:"oklch(.07 0.15 216)"};function Ae(t){return H({...V,pageBackgroundImage:`url("${G(t)}")`,pageBackgroundImageOpacity:.5})}function Me(t){return H({...V,pageBackgroundImage:`url("${G(t)}")`,pageBackgroundImageOpacity:.55})}export{L as ANCHOR_SLUG_PATTERN,T as COLOR_SOURCES,le as DEFAULT_DARK_LIGHTNESS,pe as DEFAULT_DARK_THEME,ue as DEFAULT_LIGHT_LIGHTNESS,fe as DEFAULT_LIGHT_THEME,w as DEFAULT_SEMANTIC_MAPPINGS,x as LIGHTNESS_KEYS,ye as NESTED_THEME_KEYS,E as ROLE_NAMES,re as ROLE_PAIRED_INK,N as ROLE_TOKEN_PLAN,I as SEMANTIC_COLOR_NAMES,F as TOKEN_PAIRINGS,ce as VARIANT_COLOR_SOURCES,Me as buildTaprootDarkTheme,Ae as buildTaprootLightTheme,D as compileRoles,H as encodeTheme,Ce as layerThemes,be as mergePartials,Oe as mergeTheme,te as parseAnchorSource,me as parseTheme,xe as resolveAnchorColor,Se as semanticToCSS,ve as validateTheme};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseCssColor as u,rotateHue as o}from"./color-engine.js";const m=/^anchor:([^.]+)(?:\.(.+))?$/;function s(t){const l=m.exec(t);return l?l[2]===void 0?{name:l[1]}:{name:l[1],slot:l[2]}:null}function h(t,l){const n=t[l.name];if(n===void 0)return null;if(typeof n=="string")return l.slot===void 0?n:null;const a=n[l.slot??"color"];return typeof a=="string"?a:null}function y(t,l,n){const a=s(t);if(!a)return l[t]??null;const c=h(n,a);return c===null?null:u(c)}const p=.6,g=.85;function S(t,l){const{angles:n,semanticHues:a,variantChroma:c}=l,r=e=>c[e]??t.c,i=Math.min(g,Math.max(p,t.l));return{primary:t,"analogous-left":{l:t.l,c:r("analogous-left"),h:o(t.h,-n.analogous)},"analogous-right":{l:t.l,c:r("analogous-right"),h:o(t.h,n.analogous)},complementary:{l:t.l,c:r("complementary"),h:o(t.h,n.complementary)},"split-complementary-left":{l:t.l,c:r("split-complementary-left"),h:o(t.h,n.complementary-n.splitComplementary)},"split-complementary-right":{l:t.l,c:r("split-complementary-right"),h:o(t.h,n.complementary+n.splitComplementary)},"triadic-left":{l:t.l,c:r("triadic-left"),h:o(t.h,n.triadic)},"triadic-right":{l:t.l,c:r("triadic-right"),h:o(t.h,-n.triadic)},danger:{l:i,c:r("danger"),h:o(a.danger,0)},success:{l:i,c:r("success"),h:o(a.success,0)},warning:{l:i,c:r("warning"),h:o(a.warning,0)}}}export{S as computeVariants,s as parseAnchorSource,h as resolveAnchorColor,y as resolveMappingSource};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taprootio/espalier",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"packageManager": "bun@1.3.12",
|
|
5
5
|
"description": "Espalier — a themeable, accessible, framework-agnostic, enterprise-grade design system built on web standards and love.",
|
|
6
6
|
"customElements": "custom-elements.json",
|