@cyclone-ui/theme-builder 0.0.42 → 0.0.43
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/CHANGELOG.md +6 -0
- package/dist/preprocessor.cjs +1 -1
- package/dist/preprocessor.d.cts +4 -2
- package/dist/preprocessor.d.cts.map +1 -1
- package/dist/preprocessor.d.mts +4 -2
- package/dist/preprocessor.mjs +1 -1
- package/dist/preprocessor.mjs.map +1 -1
- package/package.json +1 -1
- package/src/preprocessor.ts +131 -50
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Cyclone UI - Theme Builder
|
|
4
4
|
|
|
5
|
+
## [0.0.43](https://github.com/storm-software/cyclone-ui/releases/tag/theme-builder%400.0.43) (11/06/2026)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **theme-builder:** Resolve issue generating color token variants ([bd2fc29c9](https://github.com/storm-software/cyclone-ui/commit/bd2fc29c9))
|
|
10
|
+
|
|
5
11
|
## [0.0.42](https://github.com/storm-software/cyclone-ui/releases/tag/theme-builder%400.0.42) (11/06/2026)
|
|
6
12
|
|
|
7
13
|
### Features
|
package/dist/preprocessor.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin");const t=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,n=/^oklch\(\s*([0-9.]+%?|none)\s+([0-9.]+|none)\s+([0-9.]+|none)(?:\s*\/\s*([0-9.%]+))?\s*\)$/i,r=/* @__PURE__ */ new Set([`$schema`,`$type`,`$description`,`$extensions`,`$extends`,`$deprecated`,`$root`,`$value`,`$ref`,`theme`,`group`,`semantic`,`palette`,`primitive`]);function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function a(e){return i(e)&&(`$value`in e||`$ref`in e)}function o(e){let t=e.trim();return t.startsWith(`{`)||t.startsWith(`var(`)}function s(e){return Math.min(1,Math.max(0,e))}function c(e){let t=s(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function l(e){let t=s(e);return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function u(e){return Math.round(c(e)*255).toString(16).padStart(2,`0`)}function d(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function f(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function p(e){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3||t.length===4?`#${[...t].map(e=>e+e).join(``)}`:`#${t}`}function m(e){if(typeof e==`string`){let n=e.trim();if(!t.test(n))return;let r=p(n).toLowerCase();return r.length===9&&r.endsWith(`ff`)?r.slice(0,7):r}if(i(e)){if(typeof e.hex==`string`&&t.test(e.hex)){let t=p(e.hex).toLowerCase().slice(0,7),n=v(e.alpha);return n!==void 0&&n<1?`${t}${f(n)}`:t}if(e.colorSpace===`srgb`&&Array.isArray(e.components)&&e.components.length>=3){let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t===void 0||n===void 0||r===void 0)return;let i=`#${d(t)}${d(n)}${d(r)}`,a=v(e.alpha);return a!==void 0&&a<1?`${i}${f(a)}`:i}}}function h(e,t,n){let r=n*Math.PI/180,i=t*Math.cos(r),a=t*Math.sin(r),o=e+.3963377774*i+.2158037573*a,s=e-.1055613458*i-.0638541728*a,c=e-.0894841775*i-1.291485548*a,l=o**3,u=s**3,d=c**3;return{red:4.0767416621*l-3.3077115913*u+.2309699292*d,green:-1.2684380046*l+2.6097574011*u-.3413193965*d,blue:-.0041960863*l-.7034186147*u+1.707614701*d}}function g(e,t,n,r){let{red:i,green:a,blue:o}=h(e,t,n),s=`#${u(i)}${u(a)}${u(o)}`;return r===void 0||r>=1?s:`${s}${f(r)}`}function _(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e!=`string`||e===`none`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function v(e){if(typeof e==`number`&&Number.isFinite(e))return e>1?e/100:e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);if(Number.isFinite(t))return e.includes(`%`)||t>1?t/100:t}function ee(e){let t=n.exec(e.trim());if(!t)return;let r=_(t[1]),i=_(t[2]),a=_(t[3]);if(r!==void 0&&i!==void 0&&a!==void 0)return t[1]?.includes(`%`)&&(r/=100),g(r,i,a,v(t[4]))}function te(e){if(!Array.isArray(e.components)||e.components.length<3)return;let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t!==void 0&&n!==void 0&&r!==void 0)return t>1&&(t/=100),g(t,n,r,v(e.alpha))}function y(e){if(typeof e==`string`)return o(e)?void 0:ee(e)??m(e)??void 0;if(i(e))return typeof e.colorSpace==`string`&&e.colorSpace.toLowerCase()===`oklch`?te(e):m(e)??void 0}function b(e){if(Array.isArray(e))return e.map(e=>b(e));if(!i(e)||!(`color`in e))return e;let t=y(e.color);return t?{...e,color:t}:e}function ne(e,t){if(t===`shadow`)return b(e);if(t===`border`&&i(e)&&`color`in e){let t=y(e.color);return t?{...e,color:t}:e}return t===`color`||t===void 0?y(e)??e:e}function x(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function re(e,t){if(`$ref`in e&&!(`$value`in e))return{...e};let n=x(e,t);return`$value`in e?{...e,$value:ne(e.$value,n)}:{...e}}function S(e,t){if(Array.isArray(e))return e.map(e=>S(e,t));if(!i(e))return e;if(a(e))return re(e,t);let n=typeof e.$type==`string`?e.$type:t,o={};for(let[t,i]of Object.entries(e))o[t]=r.has(t)||t.startsWith(`$`)?i:S(i,n);return o}const C={dark:`#ffffff`,light:`#0c0c0d`},ie={dark:`#ffffff`,light:`#000000`};function w(e){if(typeof e!=`string`)return;let t=/\b(dark|light)[\s-]+theme\b/i.exec(e)?.[1];return t?.toLowerCase()===`dark`?`dark`:t?.toLowerCase()===`light`?`light`:void 0}function ae(e){if(i(e)&&i(e.color))return w(e.color.$description)}const oe={name:`active`,brightness:1.45,useContrastPrimitive:!0},se={name:`active`,brightness:1.25},ce={name:`active`,brightness:1.175},le={name:`active`,brightness:1.8,useContrastPrimitive:!0},T={name:`inactive`,brightness:.8},E={name:`inactive`,brightness:.5,useContrastPrimitive:!0},D={name:`disabled`,opacity:.15,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},O={lowSaturation:[oe,E,D],saturated:[se,T,D]},ue={lowSaturation:[ce,E,D],saturated:O.saturated},de={name:`inactive`,brightness:.9},fe={...D,opacity:.25,saturation:.925},pe={lowSaturation:[{name:`active`,brightness:1.3},de,fe],saturated:[{name:`active`,brightness:1.25},de,fe]},me=[`shadows`];function k(e){return Object.entries(e).filter(e=>!me.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const he={lowSaturation:[{name:`hovered`,brightness:1.4},le,E,D],saturated:[{name:`hovered`,brightness:1.2},{name:`active`,brightness:1.4},T,D]},A={lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.125},...O.saturated]},ge={primary:A,secondary:{lowSaturation:[{name:`hovered`,brightness:1.08},...ue.lowSaturation],saturated:A.saturated},link:A},_e={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.15},...pe.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...pe.saturated]}},ve={hairline:he},j=7.5,M=.01;function ye(e){return e.toLowerCase().endsWith(`-hovered`)||e.toLowerCase().endsWith(`-active`)||e.toLowerCase().endsWith(`-inactive`)||e.toLowerCase().endsWith(`-disabled`)}function be(e,t){let n=e;for(let e of t.split(`.`).filter(Boolean)){if(!i(n)||!(e in n))return;n=n[e]}return a(n)?n:void 0}function N(e,t,n=/* @__PURE__ */ new Set){let r=y(e);if(r)return r;if(typeof e!=`string`)return;let i=/^\{([^{}]+)\}$/.exec(e.trim());if(!i?.[1]||n.has(i[1]))return;n.add(i[1]);let a=be(t,i[1]);if(a&&`$value`in a)return N(a.$value,t,n)}function P(e,t){let n=p(e).toLowerCase(),r=n.slice(0,7),i=s((n.length===9?Number.parseInt(n.slice(7,9),16)/255:1)*t);return i>=1?r:`${r}${f(i)}`}function xe(e,t,n){let r=p(e).toLowerCase(),i=p(y(t)??t).toLowerCase(),a=s((r.length===9?Number.parseInt(r.slice(7,9),16)/255:1)*n),o=e=>d((Number.parseInt(r.slice(e,e+2),16)*a+Number.parseInt(i.slice(e,e+2),16)*(1-a))/255);return`#${o(1)}${o(3)}${o(5)}`}function F(e,t,n=!1){if(Array.isArray(e))return e.map(e=>F(e,t,n));if(!i(e))return e;if(n&&a(e)&&x(e)===`shadow`){let n=e.$value,r=e=>{if(!i(e)||!(`color`in e))return e;let n=N(e.color,t);return n?{...e,color:P(n,R(n)?.1:.15)}:e};return{...e,$value:Array.isArray(n)?n.map((e,t)=>t===n.length-1?r(e):e):r(n)}}let r={};for(let[i,a]of Object.entries(e))r[i]=F(a,t,n||i.toLowerCase()===`ring`);return r}const I={value:0,unit:`px`};function L(e,t){return{color:e,offsetX:I,offsetY:I,blur:I,spread:{value:t,unit:`px`}}}function Se(e){if(!i(e)||!i(e.color))return e;let t=e.color,n=i(e.ring)?{...e.ring}:{},r=!1;for(let[e]of k(t)){let t=`{color.${e}.primary}`,i=e=>L(`{color.elevated}`,e),a={[e]:[`${e} 3px focus ring with no gap`,[L(t,3)]],[`${e}-subtle`]:[`${e} 1px outline focus ring with no gap`,[L(t,1)]],[`${e}-offset`]:[`${e} 3px focus ring with a 3px gap`,[i(3),L(t,7)]],[`${e}-subtle-offset`]:[`${e} 1px focus ring with a 2px gap`,[i(2),L(t,3)]]};for(let[t,[i,o]]of Object.entries(a))t in n||(n[t]={$description:`Generated ${i}`,$type:`shadow`,$value:o,theme:e},r=!0)}return r?{...e,ring:n}:e}function R(e){return B(e).chroma<.02}function z(e){let t=p(e).toLowerCase();return t.slice(1,3)===t.slice(3,5)&&t.slice(3,5)===t.slice(5,7)}function B(e){let t=p(e).toLowerCase(),n=l(Number.parseInt(t.slice(1,3),16)/255),r=l(Number.parseInt(t.slice(3,5),16)/255),i=l(Number.parseInt(t.slice(5,7),16)/255),a=t.length===9?Number.parseInt(t.slice(7,9),16)/255:void 0,o=.4122214708*n+.5363325363*r+.0514459929*i,s=.2119034982*n+.6806995451*r+.1073969566*i,c=.0883024619*n+.2817188376*r+.6299787005*i,u=Math.cbrt(o),d=Math.cbrt(s),f=Math.cbrt(c),m=.2104542553*u+.793617785*d-.0040720468*f,h=1.9779984951*u-2.428592205*d+.4505937099*f,g=.0259040371*u+.7827717662*d-.808675766*f,_=Math.hypot(h,g),v=Math.atan2(g,h)*180/Math.PI;return v<0&&(v+=360),{lightness:m,chroma:_,hue:v,alpha:a}}function V({red:e,green:t,blue:n}){return e>=0&&e<=1&&t>=0&&t<=1&&n>=0&&n<=1}function H(e,t,n,r){if(V(h(e,t,n)))return g(e,t,n,r);let i=0,a=t;for(let t=0;t<32;t+=1){let t=(i+a)/2;V(h(e,t,n))?i=t:a=t}return g(e,i,n,r)}function U(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e);return g(s(n*t),r,i,a)}function Ce(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e);return g(s(n+t),r,i,a)}function we(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e);return g(n,r*s(t),i,a)}function W(e){let t=p(e).toLowerCase(),n=e=>{let n=Number.parseInt(t.slice(e,e+2),16)/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4};return .2126*n(1)+.7152*n(3)+.0722*n(5)}function G(e,t){let n=W(e),r=W(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function K(e){let t=G(e,`#FAFAFA`);return t>=2?`#FAFAFA`:G(e,`#151518`)*.5>t?`#151518`:`#FAFAFA`}function Te(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e),o=t===`light`?1:-1,c=-o,l=n,u=n,d=e,f=e;for(let t=0;t<100;t+=1){if(l=s(l+o*M),d=H(l,r,i,a),G(d,f)>=j)return f===e?{secondary:d}:{secondary:d,onMuted:f};if(u=s(u+c*M),f=H(u,r,i,a),G(d,f)>=j)return{secondary:d,onMuted:f};if((l===0||l===1)&&(u===0||u===1))break}throw Error(`Unable to generate an accessible secondary pair for ${e}`)}function Ee(e,t){return t===`dark`?q(e):t===`light`?!J(e):B(e).lightness>=.5}function De(e,t){return!Ee(e,t)}const Oe=B(`#fefefe`).lightness,ke=B(`#262626`).lightness;function q(e){return B(e).lightness>=(R(e)?Oe:.75)}function J(e){return B(e).lightness<=(R(e)?ke:.25)}function Y(e){return e.name===`hovered`||e.name===`active`}function X(e,t){return t===`dark`?q(e):t===`light`&&J(e)}function Ae(e,t,n){return De(e,n)?t:2-t}function Z(e,t){return e.useContrastPrimitive&&t?C[t]:void 0}function je(e,t,n){if(t.name===`hovered`&&Z(t,n)&&X(e,n))return n===`dark`?-.25:.25}function Me(e,t,n){let r=Z(t,n);return r&&n&&t.name===`active`&&X(e,n)?ie[n]:r}function Ne(e,t,n){return t.brightness===void 0?1:Z(t,n)?Y(t)?1:t.brightness:Ae(e,t.brightness,n)}function Pe(e,t,n){let r=je(e,t,n),i=r===void 0?Me(e,t,n):void 0,a=i??e;return r===void 0?t.brightness!==void 0&&!(i&&Y(t))&&(a=U(a,Ne(a,t,n))):a=Ce(e,r),t.saturation!==void 0&&!z(e)&&(a=we(a,t.saturation),t.fadeOver===void 0)?a:t.fadeOver===void 0?t.opacity===void 0?a:P(a,t.opacity):xe(a,t.fadeOver,t.opacity??1)}function Fe(e,t,n){let r=[],i=je(t,e,n),a=Me(t,e,n);if(i!==void 0)r.push(`${Math.round(Math.abs(i)*100)}% ${i<0?`darker`:`lighter`}`);else if(a&&Y(e))r.push(n&&a!==C[n]?`pure ${n===`dark`?`white`:`black`}`:`${n} contrast primitive`);else if(e.brightness!==void 0){let i=Ne(t,e,n),a=Math.round((i-1)*100);r.push(a>=0?`${a}% brighter`:`${Math.abs(a)}% darker`)}return e.saturation!==void 0&&!z(t)&&r.push(`${Math.round(e.saturation*100)}% saturation`),e.fadeOver===void 0?e.opacity!==void 0&&(e.saturation===void 0||z(t))&&r.push(`${Math.round(e.opacity*100)}% opacity`):r.push(`${Math.round((e.opacity??1)*100)}% over ${e.fadeOver}`),r.join(`, `)||e.name}function Ie(e,t,n,r){let i=Fe(n,t,r),a=Pe(t,n,r);return{...e,$type:`color`,$value:a,$description:typeof e.$description==`string`?`${e.$description} (${n.name}, ${i})`:`${n.name} state at ${i}`}}function Q(e,t,n,r,i){let o={...e},s=r?[r]:Object.keys(e);for(let r of s){if(r.startsWith(`$`)||ye(r))continue;let s=e[r];if(!a(s))continue;let c=x(s);if(c&&c!==`color`)continue;let l=N(s.$value,t);if(!l)continue;let u=R(l)?n.lowSaturation:n.saturated,d=u.some(e=>e.name===`hovered`),f=u.flatMap(e=>e.name===`active`&&!d?[{...e,name:`hovered`},e]:[e]),p=w(s.$description)??i;for(let e of f){let t=`${r}-${e.name}`;t in o||(o[t]=Ie(s,l,e,p))}}return o}function Le(e,t,n,r){let i=t.primary,o=a(i)&&N(i.$value,n),c=a(i)&&x(i);if(!a(i)||!o||c&&c!==`color`)return t;let l={...t};l.link??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} hyperlink text color (matches primary)`},l[`on-primary`]??={...i,$type:`color`,$value:K(o),$description:`Generated text and icon color on ${e} primary backgrounds`},l.backdrop??={...i,$type:`color`,$value:P(U(o,.375),.15),$description:`Generated ${e} overlay backdrop color (primary, 30% darker at 75% opacity)`};let u;if(r&&!(`secondary`in t)){let t=Te(o,r);l.secondary={...i,$type:`color`,$value:t.secondary,$description:`Generated low-emphasis ${e} background for the ${r} theme`},u=t.onMuted??o}else if(a(t.secondary)){let e=N(t.secondary.$value,n);u=e&&K(e)}u&&!(`on-secondary`in t)&&(l[`on-secondary`]={...i,$type:`color`,$value:u,$description:`Generated text and icon color on ${e} secondary backgrounds`});let d=!(`border`in t)&&a(l.secondary)&&N(l.secondary.$value,n);if(d){let{lightness:t,chroma:n,hue:a,alpha:o}=B(d),c=r===`light`?-1:1;l.border={...i,$type:`color`,$value:H(s(t*(1+c*.25)),n,a,o),$description:`Generated ${e} border color for secondary backgrounds (secondary, 25% ${c>0?`brighter`:`darker`})`}}for(let[e,t]of Object.entries(ge))l=Q(l,n,t,e,r);for(let[t,n]of Object.entries(l))a(n)&&(l[t]={theme:e,group:e,...n});return l}function Re(e){let t={...e};for(let[n,r]of Object.entries(e)){let e=n.replace(/^on-/,``).replace(/-(?:hovered|active|inactive|disabled)$/i,``);e!==n&&a(r)&&!(`group`in r)&&(t[n]={...r,group:e})}return t}function ze(e){let t=e.base,n=e.brand;return!i(t)||a(t)||!i(n)||a(n)||Object.entries(n).some(([e,t])=>!r.has(e)&&!e.startsWith(`$`)&&a(t))?e:{...e,brand:{...t,...n}}}function $(e,t,n,o){if(Array.isArray(e))return e.map(e=>$(e,t,void 0,o));if(!i(e)||a(e))return e;let s={};for(let[n,i]of Object.entries(e))s[n]=r.has(n)||n.startsWith(`$`)?i:$(i,t,n,n===`dark`||n===`light`?n:o);let c=s;if(n===`color`){c=ze(c);for(let[e,n]of k(c))c[e]=Le(e,n,t,o);for(let[e,n]of Object.entries(c)){let r=a(n)&&typeof n.group==`string`?_e[n.group]:void 0;r&&(c=Q(c,t,r,e,o))}}for(let[e,n]of Object.entries(ve))a(c[e])&&(c=Q(c,t,n,e,o));return n===`color`?Re(c):c}function Be(e){let t=S(e),n=Se($(t,t,void 0,ae(t)));return F(n,n)}var Ve=(0,e.definePlugin)(()=>({name:`cyclone-ui:tamagui-preprocessor`,preprocessors:[{name:`tamagui-preprocessor`,preprocessor:Be}]}));exports.default=Ve,exports.tamaguiPreprocessor=Be;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("@razorwind/core/plugin");const t=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,n=/^oklch\(\s*([0-9.]+%?|none)\s+([0-9.]+|none)\s+([0-9.]+|none)(?:\s*\/\s*([0-9.%]+))?\s*\)$/i,r=/* @__PURE__ */ new Set([`$schema`,`$type`,`$description`,`$extensions`,`$extends`,`$deprecated`,`$root`,`$value`,`$ref`,`theme`,`group`,`semantic`,`palette`,`primitive`]);function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function a(e){return i(e)&&(`$value`in e||`$ref`in e)}function o(e){let t=e.trim();return t.startsWith(`{`)||t.startsWith(`var(`)}function s(e){return Math.min(1,Math.max(0,e))}function c(e){let t=s(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function l(e){let t=s(e);return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function u(e){return Math.round(c(e)*255).toString(16).padStart(2,`0`)}function d(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function f(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function p(e){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3||t.length===4?`#${[...t].map(e=>e+e).join(``)}`:`#${t}`}function m(e){if(typeof e==`string`){let n=e.trim();if(!t.test(n))return;let r=p(n).toLowerCase();return r.length===9&&r.endsWith(`ff`)?r.slice(0,7):r}if(i(e)){if(typeof e.hex==`string`&&t.test(e.hex)){let t=p(e.hex).toLowerCase().slice(0,7),n=v(e.alpha);return n!==void 0&&n<1?`${t}${f(n)}`:t}if(e.colorSpace===`srgb`&&Array.isArray(e.components)&&e.components.length>=3){let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t===void 0||n===void 0||r===void 0)return;let i=`#${d(t)}${d(n)}${d(r)}`,a=v(e.alpha);return a!==void 0&&a<1?`${i}${f(a)}`:i}}}function h(e,t,n){let r=n*Math.PI/180,i=t*Math.cos(r),a=t*Math.sin(r),o=e+.3963377774*i+.2158037573*a,s=e-.1055613458*i-.0638541728*a,c=e-.0894841775*i-1.291485548*a,l=o**3,u=s**3,d=c**3;return{red:4.0767416621*l-3.3077115913*u+.2309699292*d,green:-1.2684380046*l+2.6097574011*u-.3413193965*d,blue:-.0041960863*l-.7034186147*u+1.707614701*d}}function g(e,t,n,r){let{red:i,green:a,blue:o}=h(e,t,n),s=`#${u(i)}${u(a)}${u(o)}`;return r===void 0||r>=1?s:`${s}${f(r)}`}function _(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e!=`string`||e===`none`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function v(e){if(typeof e==`number`&&Number.isFinite(e))return e>1?e/100:e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);if(Number.isFinite(t))return e.includes(`%`)||t>1?t/100:t}function ee(e){let t=n.exec(e.trim());if(!t)return;let r=_(t[1]),i=_(t[2]),a=_(t[3]);if(r!==void 0&&i!==void 0&&a!==void 0)return t[1]?.includes(`%`)&&(r/=100),g(r,i,a,v(t[4]))}function te(e){if(!Array.isArray(e.components)||e.components.length<3)return;let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t!==void 0&&n!==void 0&&r!==void 0)return t>1&&(t/=100),g(t,n,r,v(e.alpha))}function y(e){if(typeof e==`string`)return o(e)?void 0:ee(e)??m(e)??void 0;if(i(e))return typeof e.colorSpace==`string`&&e.colorSpace.toLowerCase()===`oklch`?te(e):m(e)??void 0}function b(e){if(Array.isArray(e))return e.map(e=>b(e));if(!i(e)||!(`color`in e))return e;let t=y(e.color);return t?{...e,color:t}:e}function ne(e,t){if(t===`shadow`)return b(e);if(t===`border`&&i(e)&&`color`in e){let t=y(e.color);return t?{...e,color:t}:e}return t===`color`||t===void 0?y(e)??e:e}function x(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function re(e,t){if(`$ref`in e&&!(`$value`in e))return{...e};let n=x(e,t);return`$value`in e?{...e,$value:ne(e.$value,n)}:{...e}}function S(e,t){if(Array.isArray(e))return e.map(e=>S(e,t));if(!i(e))return e;if(a(e))return re(e,t);let n=typeof e.$type==`string`?e.$type:t,o={};for(let[t,i]of Object.entries(e))o[t]=r.has(t)||t.startsWith(`$`)?i:S(i,n);return o}const C={dark:`#ffffff`,light:`#0c0c0d`},ie={dark:`#ffffff`,light:`#000000`};function w(e){if(typeof e!=`string`)return;let t=/\b(dark|light)[\s-]+theme\b/i.exec(e)?.[1];return t?.toLowerCase()===`dark`?`dark`:t?.toLowerCase()===`light`?`light`:void 0}function ae(e){if(i(e)&&i(e.color))return w(e.color.$description)}const oe={name:`active`,brightness:1.45,useContrastPrimitive:!0},se={name:`active`,brightness:1.25},ce={name:`active`,brightness:1.175},le={name:`active`,brightness:1.8,useContrastPrimitive:!0},T={name:`inactive`,brightness:.8},E={name:`inactive`,brightness:.5,useContrastPrimitive:!0},D={name:`disabled`,opacity:.15,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},O={lowSaturation:[oe,E,D],saturated:[se,T,D]},ue={lowSaturation:[ce,T,D],saturated:O.saturated},k={name:`inactive`,brightness:.9},de={...D,opacity:.25,saturation:.925},fe={lowSaturation:[{name:`active`,brightness:1.3},k,de],saturated:[{name:`active`,brightness:1.25},k,de]},pe=[`shadows`];function A(e){return Object.entries(e).filter(e=>!pe.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const me={lowSaturation:[{name:`hovered`,brightness:1.4},le,E,D],saturated:[{name:`hovered`,brightness:1.2},{name:`active`,brightness:1.4},T,D]},j={lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.125},...O.saturated]},he={primary:j,secondary:{lowSaturation:[{name:`hovered`,brightness:1.08},...ue.lowSaturation],saturated:j.saturated},link:j},ge={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.15},...fe.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...fe.saturated]}},_e={hairline:me},M=7.5,N=.01;function ve(e){return e.toLowerCase().endsWith(`-hovered`)||e.toLowerCase().endsWith(`-active`)||e.toLowerCase().endsWith(`-inactive`)||e.toLowerCase().endsWith(`-disabled`)}function ye(e,t){let n=e;for(let e of t.split(`.`).filter(Boolean)){if(!i(n)||!(e in n))return;n=n[e]}return a(n)?n:void 0}function P(e,t,n=/* @__PURE__ */ new Set){let r=y(e);if(r)return r;if(typeof e!=`string`)return;let i=/^\{([^{}]+)\}$/.exec(e.trim());if(!i?.[1]||n.has(i[1]))return;n.add(i[1]);let a=ye(t,i[1]);if(a&&`$value`in a)return P(a.$value,t,n)}function F(e,t){let n=p(e).toLowerCase(),r=n.slice(0,7),i=s((n.length===9?Number.parseInt(n.slice(7,9),16)/255:1)*t);return i>=1?r:`${r}${f(i)}`}function be(e,t,n){let r=p(e).toLowerCase(),i=p(y(t)??t).toLowerCase(),a=s((r.length===9?Number.parseInt(r.slice(7,9),16)/255:1)*n),o=e=>d((Number.parseInt(r.slice(e,e+2),16)*a+Number.parseInt(i.slice(e,e+2),16)*(1-a))/255);return`#${o(1)}${o(3)}${o(5)}`}function I(e,t,n=!1){if(Array.isArray(e))return e.map(e=>I(e,t,n));if(!i(e))return e;if(n&&a(e)&&x(e)===`shadow`){let n=e.$value,r=e=>{if(!i(e)||!(`color`in e))return e;let n=P(e.color,t);return n?{...e,color:F(n,z(n)?.1:.15)}:e};return{...e,$value:Array.isArray(n)?n.map((e,t)=>t===n.length-1?r(e):e):r(n)}}let r={};for(let[i,a]of Object.entries(e))r[i]=I(a,t,n||i.toLowerCase()===`ring`);return r}const L={value:0,unit:`px`};function R(e,t){return{color:e,offsetX:L,offsetY:L,blur:L,spread:{value:t,unit:`px`}}}function xe(e){if(!i(e)||!i(e.color))return e;let t=e.color,n=i(e.ring)?{...e.ring}:{},r=!1;for(let[e]of A(t)){let t=`{color.${e}.primary}`,i=e=>R(`{color.elevated}`,e),a={[e]:[`${e} 3px focus ring with no gap`,[R(t,3)]],[`${e}-subtle`]:[`${e} 1px outline focus ring with no gap`,[R(t,1)]],[`${e}-offset`]:[`${e} 3px focus ring with a 3px gap`,[i(3),R(t,7)]],[`${e}-subtle-offset`]:[`${e} 1px focus ring with a 2px gap`,[i(2),R(t,3)]]};for(let[t,[i,o]]of Object.entries(a))t in n||(n[t]={$description:`Generated ${i}`,$type:`shadow`,$value:o,theme:e},r=!0)}return r?{...e,ring:n}:e}function z(e){return V(e).chroma<.02}function B(e){let t=p(e).toLowerCase();return t.slice(1,3)===t.slice(3,5)&&t.slice(3,5)===t.slice(5,7)}function V(e){let t=p(e).toLowerCase(),n=l(Number.parseInt(t.slice(1,3),16)/255),r=l(Number.parseInt(t.slice(3,5),16)/255),i=l(Number.parseInt(t.slice(5,7),16)/255),a=t.length===9?Number.parseInt(t.slice(7,9),16)/255:void 0,o=.4122214708*n+.5363325363*r+.0514459929*i,s=.2119034982*n+.6806995451*r+.1073969566*i,c=.0883024619*n+.2817188376*r+.6299787005*i,u=Math.cbrt(o),d=Math.cbrt(s),f=Math.cbrt(c),m=.2104542553*u+.793617785*d-.0040720468*f,h=1.9779984951*u-2.428592205*d+.4505937099*f,g=.0259040371*u+.7827717662*d-.808675766*f,_=Math.hypot(h,g),v=Math.atan2(g,h)*180/Math.PI;return v<0&&(v+=360),{lightness:m,chroma:_,hue:v,alpha:a}}function H({red:e,green:t,blue:n}){return e>=0&&e<=1&&t>=0&&t<=1&&n>=0&&n<=1}function U(e,t,n,r){if(H(h(e,t,n)))return g(e,t,n,r);let i=0,a=t;for(let t=0;t<32;t+=1){let t=(i+a)/2;H(h(e,t,n))?i=t:a=t}return g(e,i,n,r)}function Se(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e);return g(s(n*t),r,i,a)}function Ce(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e);return g(s(n+t),r,i,a)}function we(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e);return g(n,r*s(t),i,a)}function W(e){let t=p(e).toLowerCase(),n=e=>{let n=Number.parseInt(t.slice(e,e+2),16)/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4};return .2126*n(1)+.7152*n(3)+.0722*n(5)}function G(e,t){let n=W(e),r=W(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function K(e){let t=G(e,`#FAFAFA`);return t>=2?`#FAFAFA`:G(e,`#151518`)*.5>t?`#151518`:`#FAFAFA`}function Te(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e),o=t===`light`?1:-1,c=-o,l=n,u=n,d=e,f=e;for(let t=0;t<100;t+=1){if(l=s(l+o*N),d=U(l,r,i,a),G(d,f)>=M)return f===e?{secondary:d}:{secondary:d,onMuted:f};if(u=s(u+c*N),f=U(u,r,i,a),G(d,f)>=M)return{secondary:d,onMuted:f};if((l===0||l===1)&&(u===0||u===1))break}throw Error(`Unable to generate an accessible secondary pair for ${e}`)}const Ee=V(`#fefefe`).lightness,De=V(`#262626`).lightness;function Oe(e){return V(e).lightness>=(z(e)?Ee:.75)}function ke(e){return V(e).lightness<=(z(e)?De:.25)}function q(e){return e.name===`hovered`||e.name===`active`}function J(e,t){return t===`dark`?Oe(e):t===`light`&&ke(e)}function Y(e,t){return t??(V(e).lightness>=.5?`light`:`dark`)}function X(e,t){let{lightness:n}=V(e);return t===`light`?1-n:n}function Z(e,t,n){let{chroma:r,hue:i,alpha:a}=V(e);return U(s(n===`light`?1-t:t),r,i,a)}function Ae(e,t,n){return t.name===`hovered`&&J(e,n)}function je(e,t,n){return(t.brightness??1)>=1!==Ae(e,t,n)}function Me(e,t,n){let r=X(e,n),i=(Ae(e,t,n)?r:V(e).lightness)*Math.abs((t.brightness??1)-1);return Z(e,je(e,t,n)?r+Math.min(i,(1-r)/2):r-i,n)}function Ne(e,t){return e.useContrastPrimitive&&t?C[t]:void 0}function Pe(e,t,n){if(t.name===`hovered`&&Ne(t,n)&&J(e,n))return n===`dark`?-.25:.25}function Fe(e,t,n){let r=Ne(t,n);return r&&n&&t.name===`active`&&J(e,n)?ie[n]:r}function Ie(e,t,n){let r=Pe(e,t,n),i=r===void 0?Fe(e,t,n):void 0,a=Y(e,n),o=i??e;return r===void 0?t.brightness!==void 0&&!(i&&q(t))&&(o=i?Z(i,X(i,a)*t.brightness,a):Me(e,t,a)):o=Ce(e,r),t.saturation!==void 0&&!B(e)&&(o=we(o,t.saturation),t.fadeOver===void 0)?o:t.fadeOver===void 0?t.opacity===void 0?o:F(o,t.opacity):be(o,t.fadeOver,t.opacity??1)}function Le(e,t,n){let r=[],i=Pe(t,e,n),a=Fe(t,e,n);if(i!==void 0)r.push(`${Math.round(Math.abs(i)*100)}% ${i<0?`darker`:`lighter`}`);else if(a&&q(e))r.push(n&&a!==C[n]?`pure ${n===`dark`?`white`:`black`}`:`${n} contrast primitive`);else if(e.brightness!==void 0){let i=Y(t,n);r.push(a?`${Math.round(e.brightness*100)}% of the ${i} contrast primitive's brightness`:`${Math.round(Math.abs(e.brightness-1)*100)}% ${je(t,e,i)?`brighter`:`less bright`}`)}return e.saturation!==void 0&&!B(t)&&r.push(`${Math.round(e.saturation*100)}% saturation`),e.fadeOver===void 0?e.opacity!==void 0&&(e.saturation===void 0||B(t))&&r.push(`${Math.round(e.opacity*100)}% opacity`):r.push(`${Math.round((e.opacity??1)*100)}% over ${e.fadeOver}`),r.join(`, `)||e.name}function Re(e,t,n,r){let i=Le(n,t,r),a=Ie(t,n,r);return{...e,$type:`color`,$value:a,$description:typeof e.$description==`string`?`${e.$description} (${n.name}, ${i})`:`${n.name} state at ${i}`}}function Q(e,t,n,r,i){let o={...e},s=r?[r]:Object.keys(e);for(let r of s){if(r.startsWith(`$`)||ve(r))continue;let s=e[r];if(!a(s))continue;let c=x(s);if(c&&c!==`color`)continue;let l=P(s.$value,t);if(!l)continue;let u=z(l)?n.lowSaturation:n.saturated,d=u.some(e=>e.name===`hovered`),f=u.flatMap(e=>e.name===`active`&&!d?[{...e,name:`hovered`},e]:[e]),p=w(s.$description)??i;for(let e of f){let t=`${r}-${e.name}`;t in o||(o[t]=Re(s,l,e,p))}let m=`${r}-active`,h=o[m];if(!(m in e)&&a(h)&&typeof h.$value==`string`){let e=Y(l,p),n=Math.max(...[l,o[`${r}-hovered`]?.$value,o[`${r}-inactive`]?.$value].map(e=>P(e,t)).filter(e=>e!==void 0).map(t=>X(t,e)));X(h.$value,e)<n&&(o[m]={...h,$value:Z(h.$value,n,e)})}}return o}function ze(e,t,n,r){let i=t.primary,o=a(i)&&P(i.$value,n),c=a(i)&&x(i);if(!a(i)||!o||c&&c!==`color`)return t;let l={...t};l.link??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} hyperlink text color (matches primary)`},l[`on-primary`]??={...i,$type:`color`,$value:K(o),$description:`Generated text and icon color on ${e} primary backgrounds`},l.backdrop??={...i,$type:`color`,$value:F(Se(o,.375),.15),$description:`Generated ${e} overlay backdrop color (primary, 30% darker at 75% opacity)`};let u;if(r&&!(`secondary`in t)){let t=Te(o,r);l.secondary={...i,$type:`color`,$value:t.secondary,$description:`Generated low-emphasis ${e} background for the ${r} theme`},u=t.onMuted??o}else if(a(t.secondary)){let e=P(t.secondary.$value,n);u=e&&K(e)}u&&!(`on-secondary`in t)&&(l[`on-secondary`]={...i,$type:`color`,$value:u,$description:`Generated text and icon color on ${e} secondary backgrounds`});let d=!(`border`in t)&&a(l.secondary)&&P(l.secondary.$value,n);if(d){let{lightness:t,chroma:n,hue:a,alpha:o}=V(d),c=r===`light`?-1:1;l.border={...i,$type:`color`,$value:U(s(t*(1+c*.25)),n,a,o),$description:`Generated ${e} border color for secondary backgrounds (secondary, 25% ${c>0?`brighter`:`darker`})`}}for(let[e,t]of Object.entries(he))l=Q(l,n,t,e,r);for(let[t,n]of Object.entries(l))a(n)&&(l[t]={theme:e,group:e,...n});return l}function Be(e){let t={...e};for(let[n,r]of Object.entries(e)){let e=n.replace(/^on-/,``).replace(/-(?:hovered|active|inactive|disabled)$/i,``);e!==n&&a(r)&&!(`group`in r)&&(t[n]={...r,group:e})}return t}function Ve(e){let t=e.base,n=e.brand;return!i(t)||a(t)||!i(n)||a(n)||Object.entries(n).some(([e,t])=>!r.has(e)&&!e.startsWith(`$`)&&a(t))?e:{...e,brand:{...t,...n}}}function $(e,t,n,o){if(Array.isArray(e))return e.map(e=>$(e,t,void 0,o));if(!i(e)||a(e))return e;let s={};for(let[n,i]of Object.entries(e))s[n]=r.has(n)||n.startsWith(`$`)?i:$(i,t,n,n===`dark`||n===`light`?n:o);let c=s;if(n===`color`){c=Ve(c);for(let[e,n]of A(c))c[e]=ze(e,n,t,o);for(let[e,n]of Object.entries(c)){let r=a(n)&&typeof n.group==`string`?ge[n.group]:void 0;r&&(c=Q(c,t,r,e,o))}}for(let[e,n]of Object.entries(_e))a(c[e])&&(c=Q(c,t,n,e,o));return n===`color`?Be(c):c}function He(e){let t=S(e),n=xe($(t,t,void 0,ae(t)));return I(n,n)}var Ue=(0,e.definePlugin)(()=>({name:`cyclone-ui:tamagui-preprocessor`,preprocessors:[{name:`tamagui-preprocessor`,preprocessor:He}]}));exports.default=Ue,exports.tamaguiPreprocessor=He;
|
package/dist/preprocessor.d.cts
CHANGED
|
@@ -14,8 +14,10 @@ import { PreprocessedTokens } from "style-dictionary/types";
|
|
|
14
14
|
* primitive (backgrounds use a half-strength shift of their own lightness; hovered
|
|
15
15
|
* colors already near that primitive shift toward the middle, while active
|
|
16
16
|
* ones become pure white or black); saturated
|
|
17
|
-
* colors scale their own lightness.
|
|
18
|
-
*
|
|
17
|
+
* colors scale their own lightness. "Brighter" means lighter in dark themes and
|
|
18
|
+
* darker in light themes: active states are never less bright than the normal,
|
|
19
|
+
* hovered, or inactive states, and hovered states take a smaller step than
|
|
20
|
+
* active (reversing only for colors near the contrast primitive). Tokens in a theme color group get the
|
|
19
21
|
* group name as `theme` and `group`, unless already set; root state and `on-*`
|
|
20
22
|
* tokens get their main token name as `group` (e.g. `hairline-active` →
|
|
21
23
|
* `hairline`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preprocessor.d.cts","names":[],"sources":["../src/preprocessor.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"preprocessor.d.cts","names":[],"sources":["../src/preprocessor.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;iBAwqDgB,oBACd,YAAY,qBACX"}
|
package/dist/preprocessor.d.mts
CHANGED
|
@@ -14,8 +14,10 @@ import { PreprocessedTokens } from "style-dictionary/types";
|
|
|
14
14
|
* primitive (backgrounds use a half-strength shift of their own lightness; hovered
|
|
15
15
|
* colors already near that primitive shift toward the middle, while active
|
|
16
16
|
* ones become pure white or black); saturated
|
|
17
|
-
* colors scale their own lightness.
|
|
18
|
-
*
|
|
17
|
+
* colors scale their own lightness. "Brighter" means lighter in dark themes and
|
|
18
|
+
* darker in light themes: active states are never less bright than the normal,
|
|
19
|
+
* hovered, or inactive states, and hovered states take a smaller step than
|
|
20
|
+
* active (reversing only for colors near the contrast primitive). Tokens in a theme color group get the
|
|
19
21
|
* group name as `theme` and `group`, unless already set; root state and `on-*`
|
|
20
22
|
* tokens get their main token name as `group` (e.g. `hairline-active` →
|
|
21
23
|
* `hairline`).
|
package/dist/preprocessor.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{definePlugin as e}from"@razorwind/core/plugin";const t=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,n=/^oklch\(\s*([0-9.]+%?|none)\s+([0-9.]+|none)\s+([0-9.]+|none)(?:\s*\/\s*([0-9.%]+))?\s*\)$/i,r=/* @__PURE__ */ new Set([`$schema`,`$type`,`$description`,`$extensions`,`$extends`,`$deprecated`,`$root`,`$value`,`$ref`,`theme`,`group`,`semantic`,`palette`,`primitive`]);function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function a(e){return i(e)&&(`$value`in e||`$ref`in e)}function o(e){let t=e.trim();return t.startsWith(`{`)||t.startsWith(`var(`)}function s(e){return Math.min(1,Math.max(0,e))}function c(e){let t=s(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function l(e){let t=s(e);return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function u(e){return Math.round(c(e)*255).toString(16).padStart(2,`0`)}function d(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function f(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function p(e){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3||t.length===4?`#${[...t].map(e=>e+e).join(``)}`:`#${t}`}function m(e){if(typeof e==`string`){let n=e.trim();if(!t.test(n))return;let r=p(n).toLowerCase();return r.length===9&&r.endsWith(`ff`)?r.slice(0,7):r}if(i(e)){if(typeof e.hex==`string`&&t.test(e.hex)){let t=p(e.hex).toLowerCase().slice(0,7),n=v(e.alpha);return n!==void 0&&n<1?`${t}${f(n)}`:t}if(e.colorSpace===`srgb`&&Array.isArray(e.components)&&e.components.length>=3){let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t===void 0||n===void 0||r===void 0)return;let i=`#${d(t)}${d(n)}${d(r)}`,a=v(e.alpha);return a!==void 0&&a<1?`${i}${f(a)}`:i}}}function h(e,t,n){let r=n*Math.PI/180,i=t*Math.cos(r),a=t*Math.sin(r),o=e+.3963377774*i+.2158037573*a,s=e-.1055613458*i-.0638541728*a,c=e-.0894841775*i-1.291485548*a,l=o**3,u=s**3,d=c**3;return{red:4.0767416621*l-3.3077115913*u+.2309699292*d,green:-1.2684380046*l+2.6097574011*u-.3413193965*d,blue:-.0041960863*l-.7034186147*u+1.707614701*d}}function g(e,t,n,r){let{red:i,green:a,blue:o}=h(e,t,n),s=`#${u(i)}${u(a)}${u(o)}`;return r===void 0||r>=1?s:`${s}${f(r)}`}function _(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e!=`string`||e===`none`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function v(e){if(typeof e==`number`&&Number.isFinite(e))return e>1?e/100:e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);if(Number.isFinite(t))return e.includes(`%`)||t>1?t/100:t}function ee(e){let t=n.exec(e.trim());if(!t)return;let r=_(t[1]),i=_(t[2]),a=_(t[3]);if(r!==void 0&&i!==void 0&&a!==void 0)return t[1]?.includes(`%`)&&(r/=100),g(r,i,a,v(t[4]))}function te(e){if(!Array.isArray(e.components)||e.components.length<3)return;let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t!==void 0&&n!==void 0&&r!==void 0)return t>1&&(t/=100),g(t,n,r,v(e.alpha))}function y(e){if(typeof e==`string`)return o(e)?void 0:ee(e)??m(e)??void 0;if(i(e))return typeof e.colorSpace==`string`&&e.colorSpace.toLowerCase()===`oklch`?te(e):m(e)??void 0}function b(e){if(Array.isArray(e))return e.map(e=>b(e));if(!i(e)||!(`color`in e))return e;let t=y(e.color);return t?{...e,color:t}:e}function ne(e,t){if(t===`shadow`)return b(e);if(t===`border`&&i(e)&&`color`in e){let t=y(e.color);return t?{...e,color:t}:e}return t===`color`||t===void 0?y(e)??e:e}function x(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function re(e,t){if(`$ref`in e&&!(`$value`in e))return{...e};let n=x(e,t);return`$value`in e?{...e,$value:ne(e.$value,n)}:{...e}}function S(e,t){if(Array.isArray(e))return e.map(e=>S(e,t));if(!i(e))return e;if(a(e))return re(e,t);let n=typeof e.$type==`string`?e.$type:t,o={};for(let[t,i]of Object.entries(e))o[t]=r.has(t)||t.startsWith(`$`)?i:S(i,n);return o}const C={dark:`#ffffff`,light:`#0c0c0d`},ie={dark:`#ffffff`,light:`#000000`};function w(e){if(typeof e!=`string`)return;let t=/\b(dark|light)[\s-]+theme\b/i.exec(e)?.[1];return t?.toLowerCase()===`dark`?`dark`:t?.toLowerCase()===`light`?`light`:void 0}function ae(e){if(i(e)&&i(e.color))return w(e.color.$description)}const oe={name:`active`,brightness:1.45,useContrastPrimitive:!0},se={name:`active`,brightness:1.25},ce={name:`active`,brightness:1.175},le={name:`active`,brightness:1.8,useContrastPrimitive:!0},T={name:`inactive`,brightness:.8},E={name:`inactive`,brightness:.5,useContrastPrimitive:!0},D={name:`disabled`,opacity:.15,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},O={lowSaturation:[oe,E,D],saturated:[se,T,D]},ue={lowSaturation:[ce,E,D],saturated:O.saturated},de={name:`inactive`,brightness:.9},fe={...D,opacity:.25,saturation:.925},pe={lowSaturation:[{name:`active`,brightness:1.3},de,fe],saturated:[{name:`active`,brightness:1.25},de,fe]},me=[`shadows`];function k(e){return Object.entries(e).filter(e=>!me.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const he={lowSaturation:[{name:`hovered`,brightness:1.4},le,E,D],saturated:[{name:`hovered`,brightness:1.2},{name:`active`,brightness:1.4},T,D]},A={lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.125},...O.saturated]},ge={primary:A,secondary:{lowSaturation:[{name:`hovered`,brightness:1.08},...ue.lowSaturation],saturated:A.saturated},link:A},_e={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.15},...pe.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...pe.saturated]}},ve={hairline:he},j=7.5,M=.01;function ye(e){return e.toLowerCase().endsWith(`-hovered`)||e.toLowerCase().endsWith(`-active`)||e.toLowerCase().endsWith(`-inactive`)||e.toLowerCase().endsWith(`-disabled`)}function be(e,t){let n=e;for(let e of t.split(`.`).filter(Boolean)){if(!i(n)||!(e in n))return;n=n[e]}return a(n)?n:void 0}function N(e,t,n=/* @__PURE__ */ new Set){let r=y(e);if(r)return r;if(typeof e!=`string`)return;let i=/^\{([^{}]+)\}$/.exec(e.trim());if(!i?.[1]||n.has(i[1]))return;n.add(i[1]);let a=be(t,i[1]);if(a&&`$value`in a)return N(a.$value,t,n)}function P(e,t){let n=p(e).toLowerCase(),r=n.slice(0,7),i=s((n.length===9?Number.parseInt(n.slice(7,9),16)/255:1)*t);return i>=1?r:`${r}${f(i)}`}function xe(e,t,n){let r=p(e).toLowerCase(),i=p(y(t)??t).toLowerCase(),a=s((r.length===9?Number.parseInt(r.slice(7,9),16)/255:1)*n),o=e=>d((Number.parseInt(r.slice(e,e+2),16)*a+Number.parseInt(i.slice(e,e+2),16)*(1-a))/255);return`#${o(1)}${o(3)}${o(5)}`}function F(e,t,n=!1){if(Array.isArray(e))return e.map(e=>F(e,t,n));if(!i(e))return e;if(n&&a(e)&&x(e)===`shadow`){let n=e.$value,r=e=>{if(!i(e)||!(`color`in e))return e;let n=N(e.color,t);return n?{...e,color:P(n,R(n)?.1:.15)}:e};return{...e,$value:Array.isArray(n)?n.map((e,t)=>t===n.length-1?r(e):e):r(n)}}let r={};for(let[i,a]of Object.entries(e))r[i]=F(a,t,n||i.toLowerCase()===`ring`);return r}const I={value:0,unit:`px`};function L(e,t){return{color:e,offsetX:I,offsetY:I,blur:I,spread:{value:t,unit:`px`}}}function Se(e){if(!i(e)||!i(e.color))return e;let t=e.color,n=i(e.ring)?{...e.ring}:{},r=!1;for(let[e]of k(t)){let t=`{color.${e}.primary}`,i=e=>L(`{color.elevated}`,e),a={[e]:[`${e} 3px focus ring with no gap`,[L(t,3)]],[`${e}-subtle`]:[`${e} 1px outline focus ring with no gap`,[L(t,1)]],[`${e}-offset`]:[`${e} 3px focus ring with a 3px gap`,[i(3),L(t,7)]],[`${e}-subtle-offset`]:[`${e} 1px focus ring with a 2px gap`,[i(2),L(t,3)]]};for(let[t,[i,o]]of Object.entries(a))t in n||(n[t]={$description:`Generated ${i}`,$type:`shadow`,$value:o,theme:e},r=!0)}return r?{...e,ring:n}:e}function R(e){return B(e).chroma<.02}function z(e){let t=p(e).toLowerCase();return t.slice(1,3)===t.slice(3,5)&&t.slice(3,5)===t.slice(5,7)}function B(e){let t=p(e).toLowerCase(),n=l(Number.parseInt(t.slice(1,3),16)/255),r=l(Number.parseInt(t.slice(3,5),16)/255),i=l(Number.parseInt(t.slice(5,7),16)/255),a=t.length===9?Number.parseInt(t.slice(7,9),16)/255:void 0,o=.4122214708*n+.5363325363*r+.0514459929*i,s=.2119034982*n+.6806995451*r+.1073969566*i,c=.0883024619*n+.2817188376*r+.6299787005*i,u=Math.cbrt(o),d=Math.cbrt(s),f=Math.cbrt(c),m=.2104542553*u+.793617785*d-.0040720468*f,h=1.9779984951*u-2.428592205*d+.4505937099*f,g=.0259040371*u+.7827717662*d-.808675766*f,_=Math.hypot(h,g),v=Math.atan2(g,h)*180/Math.PI;return v<0&&(v+=360),{lightness:m,chroma:_,hue:v,alpha:a}}function V({red:e,green:t,blue:n}){return e>=0&&e<=1&&t>=0&&t<=1&&n>=0&&n<=1}function H(e,t,n,r){if(V(h(e,t,n)))return g(e,t,n,r);let i=0,a=t;for(let t=0;t<32;t+=1){let t=(i+a)/2;V(h(e,t,n))?i=t:a=t}return g(e,i,n,r)}function U(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e);return g(s(n*t),r,i,a)}function Ce(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e);return g(s(n+t),r,i,a)}function we(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e);return g(n,r*s(t),i,a)}function W(e){let t=p(e).toLowerCase(),n=e=>{let n=Number.parseInt(t.slice(e,e+2),16)/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4};return .2126*n(1)+.7152*n(3)+.0722*n(5)}function G(e,t){let n=W(e),r=W(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function K(e){let t=G(e,`#FAFAFA`);return t>=2?`#FAFAFA`:G(e,`#151518`)*.5>t?`#151518`:`#FAFAFA`}function Te(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=B(e),o=t===`light`?1:-1,c=-o,l=n,u=n,d=e,f=e;for(let t=0;t<100;t+=1){if(l=s(l+o*M),d=H(l,r,i,a),G(d,f)>=j)return f===e?{secondary:d}:{secondary:d,onMuted:f};if(u=s(u+c*M),f=H(u,r,i,a),G(d,f)>=j)return{secondary:d,onMuted:f};if((l===0||l===1)&&(u===0||u===1))break}throw Error(`Unable to generate an accessible secondary pair for ${e}`)}function Ee(e,t){return t===`dark`?q(e):t===`light`?!J(e):B(e).lightness>=.5}function De(e,t){return!Ee(e,t)}const Oe=B(`#fefefe`).lightness,ke=B(`#262626`).lightness;function q(e){return B(e).lightness>=(R(e)?Oe:.75)}function J(e){return B(e).lightness<=(R(e)?ke:.25)}function Y(e){return e.name===`hovered`||e.name===`active`}function X(e,t){return t===`dark`?q(e):t===`light`&&J(e)}function Ae(e,t,n){return De(e,n)?t:2-t}function Z(e,t){return e.useContrastPrimitive&&t?C[t]:void 0}function je(e,t,n){if(t.name===`hovered`&&Z(t,n)&&X(e,n))return n===`dark`?-.25:.25}function Me(e,t,n){let r=Z(t,n);return r&&n&&t.name===`active`&&X(e,n)?ie[n]:r}function Ne(e,t,n){return t.brightness===void 0?1:Z(t,n)?Y(t)?1:t.brightness:Ae(e,t.brightness,n)}function Pe(e,t,n){let r=je(e,t,n),i=r===void 0?Me(e,t,n):void 0,a=i??e;return r===void 0?t.brightness!==void 0&&!(i&&Y(t))&&(a=U(a,Ne(a,t,n))):a=Ce(e,r),t.saturation!==void 0&&!z(e)&&(a=we(a,t.saturation),t.fadeOver===void 0)?a:t.fadeOver===void 0?t.opacity===void 0?a:P(a,t.opacity):xe(a,t.fadeOver,t.opacity??1)}function Fe(e,t,n){let r=[],i=je(t,e,n),a=Me(t,e,n);if(i!==void 0)r.push(`${Math.round(Math.abs(i)*100)}% ${i<0?`darker`:`lighter`}`);else if(a&&Y(e))r.push(n&&a!==C[n]?`pure ${n===`dark`?`white`:`black`}`:`${n} contrast primitive`);else if(e.brightness!==void 0){let i=Ne(t,e,n),a=Math.round((i-1)*100);r.push(a>=0?`${a}% brighter`:`${Math.abs(a)}% darker`)}return e.saturation!==void 0&&!z(t)&&r.push(`${Math.round(e.saturation*100)}% saturation`),e.fadeOver===void 0?e.opacity!==void 0&&(e.saturation===void 0||z(t))&&r.push(`${Math.round(e.opacity*100)}% opacity`):r.push(`${Math.round((e.opacity??1)*100)}% over ${e.fadeOver}`),r.join(`, `)||e.name}function Ie(e,t,n,r){let i=Fe(n,t,r),a=Pe(t,n,r);return{...e,$type:`color`,$value:a,$description:typeof e.$description==`string`?`${e.$description} (${n.name}, ${i})`:`${n.name} state at ${i}`}}function Q(e,t,n,r,i){let o={...e},s=r?[r]:Object.keys(e);for(let r of s){if(r.startsWith(`$`)||ye(r))continue;let s=e[r];if(!a(s))continue;let c=x(s);if(c&&c!==`color`)continue;let l=N(s.$value,t);if(!l)continue;let u=R(l)?n.lowSaturation:n.saturated,d=u.some(e=>e.name===`hovered`),f=u.flatMap(e=>e.name===`active`&&!d?[{...e,name:`hovered`},e]:[e]),p=w(s.$description)??i;for(let e of f){let t=`${r}-${e.name}`;t in o||(o[t]=Ie(s,l,e,p))}}return o}function Le(e,t,n,r){let i=t.primary,o=a(i)&&N(i.$value,n),c=a(i)&&x(i);if(!a(i)||!o||c&&c!==`color`)return t;let l={...t};l.link??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} hyperlink text color (matches primary)`},l[`on-primary`]??={...i,$type:`color`,$value:K(o),$description:`Generated text and icon color on ${e} primary backgrounds`},l.backdrop??={...i,$type:`color`,$value:P(U(o,.375),.15),$description:`Generated ${e} overlay backdrop color (primary, 30% darker at 75% opacity)`};let u;if(r&&!(`secondary`in t)){let t=Te(o,r);l.secondary={...i,$type:`color`,$value:t.secondary,$description:`Generated low-emphasis ${e} background for the ${r} theme`},u=t.onMuted??o}else if(a(t.secondary)){let e=N(t.secondary.$value,n);u=e&&K(e)}u&&!(`on-secondary`in t)&&(l[`on-secondary`]={...i,$type:`color`,$value:u,$description:`Generated text and icon color on ${e} secondary backgrounds`});let d=!(`border`in t)&&a(l.secondary)&&N(l.secondary.$value,n);if(d){let{lightness:t,chroma:n,hue:a,alpha:o}=B(d),c=r===`light`?-1:1;l.border={...i,$type:`color`,$value:H(s(t*(1+c*.25)),n,a,o),$description:`Generated ${e} border color for secondary backgrounds (secondary, 25% ${c>0?`brighter`:`darker`})`}}for(let[e,t]of Object.entries(ge))l=Q(l,n,t,e,r);for(let[t,n]of Object.entries(l))a(n)&&(l[t]={theme:e,group:e,...n});return l}function Re(e){let t={...e};for(let[n,r]of Object.entries(e)){let e=n.replace(/^on-/,``).replace(/-(?:hovered|active|inactive|disabled)$/i,``);e!==n&&a(r)&&!(`group`in r)&&(t[n]={...r,group:e})}return t}function ze(e){let t=e.base,n=e.brand;return!i(t)||a(t)||!i(n)||a(n)||Object.entries(n).some(([e,t])=>!r.has(e)&&!e.startsWith(`$`)&&a(t))?e:{...e,brand:{...t,...n}}}function $(e,t,n,o){if(Array.isArray(e))return e.map(e=>$(e,t,void 0,o));if(!i(e)||a(e))return e;let s={};for(let[n,i]of Object.entries(e))s[n]=r.has(n)||n.startsWith(`$`)?i:$(i,t,n,n===`dark`||n===`light`?n:o);let c=s;if(n===`color`){c=ze(c);for(let[e,n]of k(c))c[e]=Le(e,n,t,o);for(let[e,n]of Object.entries(c)){let r=a(n)&&typeof n.group==`string`?_e[n.group]:void 0;r&&(c=Q(c,t,r,e,o))}}for(let[e,n]of Object.entries(ve))a(c[e])&&(c=Q(c,t,n,e,o));return n===`color`?Re(c):c}function Be(e){let t=S(e),n=Se($(t,t,void 0,ae(t)));return F(n,n)}var Ve=e(()=>({name:`cyclone-ui:tamagui-preprocessor`,preprocessors:[{name:`tamagui-preprocessor`,preprocessor:Be}]}));export{Ve as default,Be as tamaguiPreprocessor};
|
|
1
|
+
import{definePlugin as e}from"@razorwind/core/plugin";const t=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,n=/^oklch\(\s*([0-9.]+%?|none)\s+([0-9.]+|none)\s+([0-9.]+|none)(?:\s*\/\s*([0-9.%]+))?\s*\)$/i,r=/* @__PURE__ */ new Set([`$schema`,`$type`,`$description`,`$extensions`,`$extends`,`$deprecated`,`$root`,`$value`,`$ref`,`theme`,`group`,`semantic`,`palette`,`primitive`]);function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function a(e){return i(e)&&(`$value`in e||`$ref`in e)}function o(e){let t=e.trim();return t.startsWith(`{`)||t.startsWith(`var(`)}function s(e){return Math.min(1,Math.max(0,e))}function c(e){let t=s(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function l(e){let t=s(e);return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function u(e){return Math.round(c(e)*255).toString(16).padStart(2,`0`)}function d(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function f(e){return Math.round(s(e)*255).toString(16).padStart(2,`0`)}function p(e){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3||t.length===4?`#${[...t].map(e=>e+e).join(``)}`:`#${t}`}function m(e){if(typeof e==`string`){let n=e.trim();if(!t.test(n))return;let r=p(n).toLowerCase();return r.length===9&&r.endsWith(`ff`)?r.slice(0,7):r}if(i(e)){if(typeof e.hex==`string`&&t.test(e.hex)){let t=p(e.hex).toLowerCase().slice(0,7),n=v(e.alpha);return n!==void 0&&n<1?`${t}${f(n)}`:t}if(e.colorSpace===`srgb`&&Array.isArray(e.components)&&e.components.length>=3){let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t===void 0||n===void 0||r===void 0)return;let i=`#${d(t)}${d(n)}${d(r)}`,a=v(e.alpha);return a!==void 0&&a<1?`${i}${f(a)}`:i}}}function h(e,t,n){let r=n*Math.PI/180,i=t*Math.cos(r),a=t*Math.sin(r),o=e+.3963377774*i+.2158037573*a,s=e-.1055613458*i-.0638541728*a,c=e-.0894841775*i-1.291485548*a,l=o**3,u=s**3,d=c**3;return{red:4.0767416621*l-3.3077115913*u+.2309699292*d,green:-1.2684380046*l+2.6097574011*u-.3413193965*d,blue:-.0041960863*l-.7034186147*u+1.707614701*d}}function g(e,t,n,r){let{red:i,green:a,blue:o}=h(e,t,n),s=`#${u(i)}${u(a)}${u(o)}`;return r===void 0||r>=1?s:`${s}${f(r)}`}function _(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e!=`string`||e===`none`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function v(e){if(typeof e==`number`&&Number.isFinite(e))return e>1?e/100:e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);if(Number.isFinite(t))return e.includes(`%`)||t>1?t/100:t}function ee(e){let t=n.exec(e.trim());if(!t)return;let r=_(t[1]),i=_(t[2]),a=_(t[3]);if(r!==void 0&&i!==void 0&&a!==void 0)return t[1]?.includes(`%`)&&(r/=100),g(r,i,a,v(t[4]))}function te(e){if(!Array.isArray(e.components)||e.components.length<3)return;let t=_(e.components[0]),n=_(e.components[1]),r=_(e.components[2]);if(t!==void 0&&n!==void 0&&r!==void 0)return t>1&&(t/=100),g(t,n,r,v(e.alpha))}function y(e){if(typeof e==`string`)return o(e)?void 0:ee(e)??m(e)??void 0;if(i(e))return typeof e.colorSpace==`string`&&e.colorSpace.toLowerCase()===`oklch`?te(e):m(e)??void 0}function b(e){if(Array.isArray(e))return e.map(e=>b(e));if(!i(e)||!(`color`in e))return e;let t=y(e.color);return t?{...e,color:t}:e}function ne(e,t){if(t===`shadow`)return b(e);if(t===`border`&&i(e)&&`color`in e){let t=y(e.color);return t?{...e,color:t}:e}return t===`color`||t===void 0?y(e)??e:e}function x(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function re(e,t){if(`$ref`in e&&!(`$value`in e))return{...e};let n=x(e,t);return`$value`in e?{...e,$value:ne(e.$value,n)}:{...e}}function S(e,t){if(Array.isArray(e))return e.map(e=>S(e,t));if(!i(e))return e;if(a(e))return re(e,t);let n=typeof e.$type==`string`?e.$type:t,o={};for(let[t,i]of Object.entries(e))o[t]=r.has(t)||t.startsWith(`$`)?i:S(i,n);return o}const C={dark:`#ffffff`,light:`#0c0c0d`},ie={dark:`#ffffff`,light:`#000000`};function w(e){if(typeof e!=`string`)return;let t=/\b(dark|light)[\s-]+theme\b/i.exec(e)?.[1];return t?.toLowerCase()===`dark`?`dark`:t?.toLowerCase()===`light`?`light`:void 0}function ae(e){if(i(e)&&i(e.color))return w(e.color.$description)}const oe={name:`active`,brightness:1.45,useContrastPrimitive:!0},se={name:`active`,brightness:1.25},ce={name:`active`,brightness:1.175},le={name:`active`,brightness:1.8,useContrastPrimitive:!0},T={name:`inactive`,brightness:.8},E={name:`inactive`,brightness:.5,useContrastPrimitive:!0},D={name:`disabled`,opacity:.15,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},O={lowSaturation:[oe,E,D],saturated:[se,T,D]},ue={lowSaturation:[ce,T,D],saturated:O.saturated},k={name:`inactive`,brightness:.9},de={...D,opacity:.25,saturation:.925},fe={lowSaturation:[{name:`active`,brightness:1.3},k,de],saturated:[{name:`active`,brightness:1.25},k,de]},pe=[`shadows`];function A(e){return Object.entries(e).filter(e=>!pe.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const me={lowSaturation:[{name:`hovered`,brightness:1.4},le,E,D],saturated:[{name:`hovered`,brightness:1.2},{name:`active`,brightness:1.4},T,D]},j={lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.125},...O.saturated]},he={primary:j,secondary:{lowSaturation:[{name:`hovered`,brightness:1.08},...ue.lowSaturation],saturated:j.saturated},link:j},ge={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.15},...fe.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...fe.saturated]}},_e={hairline:me},M=7.5,N=.01;function ve(e){return e.toLowerCase().endsWith(`-hovered`)||e.toLowerCase().endsWith(`-active`)||e.toLowerCase().endsWith(`-inactive`)||e.toLowerCase().endsWith(`-disabled`)}function ye(e,t){let n=e;for(let e of t.split(`.`).filter(Boolean)){if(!i(n)||!(e in n))return;n=n[e]}return a(n)?n:void 0}function P(e,t,n=/* @__PURE__ */ new Set){let r=y(e);if(r)return r;if(typeof e!=`string`)return;let i=/^\{([^{}]+)\}$/.exec(e.trim());if(!i?.[1]||n.has(i[1]))return;n.add(i[1]);let a=ye(t,i[1]);if(a&&`$value`in a)return P(a.$value,t,n)}function F(e,t){let n=p(e).toLowerCase(),r=n.slice(0,7),i=s((n.length===9?Number.parseInt(n.slice(7,9),16)/255:1)*t);return i>=1?r:`${r}${f(i)}`}function be(e,t,n){let r=p(e).toLowerCase(),i=p(y(t)??t).toLowerCase(),a=s((r.length===9?Number.parseInt(r.slice(7,9),16)/255:1)*n),o=e=>d((Number.parseInt(r.slice(e,e+2),16)*a+Number.parseInt(i.slice(e,e+2),16)*(1-a))/255);return`#${o(1)}${o(3)}${o(5)}`}function I(e,t,n=!1){if(Array.isArray(e))return e.map(e=>I(e,t,n));if(!i(e))return e;if(n&&a(e)&&x(e)===`shadow`){let n=e.$value,r=e=>{if(!i(e)||!(`color`in e))return e;let n=P(e.color,t);return n?{...e,color:F(n,z(n)?.1:.15)}:e};return{...e,$value:Array.isArray(n)?n.map((e,t)=>t===n.length-1?r(e):e):r(n)}}let r={};for(let[i,a]of Object.entries(e))r[i]=I(a,t,n||i.toLowerCase()===`ring`);return r}const L={value:0,unit:`px`};function R(e,t){return{color:e,offsetX:L,offsetY:L,blur:L,spread:{value:t,unit:`px`}}}function xe(e){if(!i(e)||!i(e.color))return e;let t=e.color,n=i(e.ring)?{...e.ring}:{},r=!1;for(let[e]of A(t)){let t=`{color.${e}.primary}`,i=e=>R(`{color.elevated}`,e),a={[e]:[`${e} 3px focus ring with no gap`,[R(t,3)]],[`${e}-subtle`]:[`${e} 1px outline focus ring with no gap`,[R(t,1)]],[`${e}-offset`]:[`${e} 3px focus ring with a 3px gap`,[i(3),R(t,7)]],[`${e}-subtle-offset`]:[`${e} 1px focus ring with a 2px gap`,[i(2),R(t,3)]]};for(let[t,[i,o]]of Object.entries(a))t in n||(n[t]={$description:`Generated ${i}`,$type:`shadow`,$value:o,theme:e},r=!0)}return r?{...e,ring:n}:e}function z(e){return V(e).chroma<.02}function B(e){let t=p(e).toLowerCase();return t.slice(1,3)===t.slice(3,5)&&t.slice(3,5)===t.slice(5,7)}function V(e){let t=p(e).toLowerCase(),n=l(Number.parseInt(t.slice(1,3),16)/255),r=l(Number.parseInt(t.slice(3,5),16)/255),i=l(Number.parseInt(t.slice(5,7),16)/255),a=t.length===9?Number.parseInt(t.slice(7,9),16)/255:void 0,o=.4122214708*n+.5363325363*r+.0514459929*i,s=.2119034982*n+.6806995451*r+.1073969566*i,c=.0883024619*n+.2817188376*r+.6299787005*i,u=Math.cbrt(o),d=Math.cbrt(s),f=Math.cbrt(c),m=.2104542553*u+.793617785*d-.0040720468*f,h=1.9779984951*u-2.428592205*d+.4505937099*f,g=.0259040371*u+.7827717662*d-.808675766*f,_=Math.hypot(h,g),v=Math.atan2(g,h)*180/Math.PI;return v<0&&(v+=360),{lightness:m,chroma:_,hue:v,alpha:a}}function H({red:e,green:t,blue:n}){return e>=0&&e<=1&&t>=0&&t<=1&&n>=0&&n<=1}function U(e,t,n,r){if(H(h(e,t,n)))return g(e,t,n,r);let i=0,a=t;for(let t=0;t<32;t+=1){let t=(i+a)/2;H(h(e,t,n))?i=t:a=t}return g(e,i,n,r)}function Se(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e);return g(s(n*t),r,i,a)}function Ce(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e);return g(s(n+t),r,i,a)}function we(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e);return g(n,r*s(t),i,a)}function W(e){let t=p(e).toLowerCase(),n=e=>{let n=Number.parseInt(t.slice(e,e+2),16)/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4};return .2126*n(1)+.7152*n(3)+.0722*n(5)}function G(e,t){let n=W(e),r=W(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function K(e){let t=G(e,`#FAFAFA`);return t>=2?`#FAFAFA`:G(e,`#151518`)*.5>t?`#151518`:`#FAFAFA`}function Te(e,t){let{lightness:n,chroma:r,hue:i,alpha:a}=V(e),o=t===`light`?1:-1,c=-o,l=n,u=n,d=e,f=e;for(let t=0;t<100;t+=1){if(l=s(l+o*N),d=U(l,r,i,a),G(d,f)>=M)return f===e?{secondary:d}:{secondary:d,onMuted:f};if(u=s(u+c*N),f=U(u,r,i,a),G(d,f)>=M)return{secondary:d,onMuted:f};if((l===0||l===1)&&(u===0||u===1))break}throw Error(`Unable to generate an accessible secondary pair for ${e}`)}const Ee=V(`#fefefe`).lightness,De=V(`#262626`).lightness;function Oe(e){return V(e).lightness>=(z(e)?Ee:.75)}function ke(e){return V(e).lightness<=(z(e)?De:.25)}function q(e){return e.name===`hovered`||e.name===`active`}function J(e,t){return t===`dark`?Oe(e):t===`light`&&ke(e)}function Y(e,t){return t??(V(e).lightness>=.5?`light`:`dark`)}function X(e,t){let{lightness:n}=V(e);return t===`light`?1-n:n}function Z(e,t,n){let{chroma:r,hue:i,alpha:a}=V(e);return U(s(n===`light`?1-t:t),r,i,a)}function Ae(e,t,n){return t.name===`hovered`&&J(e,n)}function je(e,t,n){return(t.brightness??1)>=1!==Ae(e,t,n)}function Me(e,t,n){let r=X(e,n),i=(Ae(e,t,n)?r:V(e).lightness)*Math.abs((t.brightness??1)-1);return Z(e,je(e,t,n)?r+Math.min(i,(1-r)/2):r-i,n)}function Ne(e,t){return e.useContrastPrimitive&&t?C[t]:void 0}function Pe(e,t,n){if(t.name===`hovered`&&Ne(t,n)&&J(e,n))return n===`dark`?-.25:.25}function Fe(e,t,n){let r=Ne(t,n);return r&&n&&t.name===`active`&&J(e,n)?ie[n]:r}function Ie(e,t,n){let r=Pe(e,t,n),i=r===void 0?Fe(e,t,n):void 0,a=Y(e,n),o=i??e;return r===void 0?t.brightness!==void 0&&!(i&&q(t))&&(o=i?Z(i,X(i,a)*t.brightness,a):Me(e,t,a)):o=Ce(e,r),t.saturation!==void 0&&!B(e)&&(o=we(o,t.saturation),t.fadeOver===void 0)?o:t.fadeOver===void 0?t.opacity===void 0?o:F(o,t.opacity):be(o,t.fadeOver,t.opacity??1)}function Le(e,t,n){let r=[],i=Pe(t,e,n),a=Fe(t,e,n);if(i!==void 0)r.push(`${Math.round(Math.abs(i)*100)}% ${i<0?`darker`:`lighter`}`);else if(a&&q(e))r.push(n&&a!==C[n]?`pure ${n===`dark`?`white`:`black`}`:`${n} contrast primitive`);else if(e.brightness!==void 0){let i=Y(t,n);r.push(a?`${Math.round(e.brightness*100)}% of the ${i} contrast primitive's brightness`:`${Math.round(Math.abs(e.brightness-1)*100)}% ${je(t,e,i)?`brighter`:`less bright`}`)}return e.saturation!==void 0&&!B(t)&&r.push(`${Math.round(e.saturation*100)}% saturation`),e.fadeOver===void 0?e.opacity!==void 0&&(e.saturation===void 0||B(t))&&r.push(`${Math.round(e.opacity*100)}% opacity`):r.push(`${Math.round((e.opacity??1)*100)}% over ${e.fadeOver}`),r.join(`, `)||e.name}function Re(e,t,n,r){let i=Le(n,t,r),a=Ie(t,n,r);return{...e,$type:`color`,$value:a,$description:typeof e.$description==`string`?`${e.$description} (${n.name}, ${i})`:`${n.name} state at ${i}`}}function Q(e,t,n,r,i){let o={...e},s=r?[r]:Object.keys(e);for(let r of s){if(r.startsWith(`$`)||ve(r))continue;let s=e[r];if(!a(s))continue;let c=x(s);if(c&&c!==`color`)continue;let l=P(s.$value,t);if(!l)continue;let u=z(l)?n.lowSaturation:n.saturated,d=u.some(e=>e.name===`hovered`),f=u.flatMap(e=>e.name===`active`&&!d?[{...e,name:`hovered`},e]:[e]),p=w(s.$description)??i;for(let e of f){let t=`${r}-${e.name}`;t in o||(o[t]=Re(s,l,e,p))}let m=`${r}-active`,h=o[m];if(!(m in e)&&a(h)&&typeof h.$value==`string`){let e=Y(l,p),n=Math.max(...[l,o[`${r}-hovered`]?.$value,o[`${r}-inactive`]?.$value].map(e=>P(e,t)).filter(e=>e!==void 0).map(t=>X(t,e)));X(h.$value,e)<n&&(o[m]={...h,$value:Z(h.$value,n,e)})}}return o}function ze(e,t,n,r){let i=t.primary,o=a(i)&&P(i.$value,n),c=a(i)&&x(i);if(!a(i)||!o||c&&c!==`color`)return t;let l={...t};l.link??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} hyperlink text color (matches primary)`},l[`on-primary`]??={...i,$type:`color`,$value:K(o),$description:`Generated text and icon color on ${e} primary backgrounds`},l.backdrop??={...i,$type:`color`,$value:F(Se(o,.375),.15),$description:`Generated ${e} overlay backdrop color (primary, 30% darker at 75% opacity)`};let u;if(r&&!(`secondary`in t)){let t=Te(o,r);l.secondary={...i,$type:`color`,$value:t.secondary,$description:`Generated low-emphasis ${e} background for the ${r} theme`},u=t.onMuted??o}else if(a(t.secondary)){let e=P(t.secondary.$value,n);u=e&&K(e)}u&&!(`on-secondary`in t)&&(l[`on-secondary`]={...i,$type:`color`,$value:u,$description:`Generated text and icon color on ${e} secondary backgrounds`});let d=!(`border`in t)&&a(l.secondary)&&P(l.secondary.$value,n);if(d){let{lightness:t,chroma:n,hue:a,alpha:o}=V(d),c=r===`light`?-1:1;l.border={...i,$type:`color`,$value:U(s(t*(1+c*.25)),n,a,o),$description:`Generated ${e} border color for secondary backgrounds (secondary, 25% ${c>0?`brighter`:`darker`})`}}for(let[e,t]of Object.entries(he))l=Q(l,n,t,e,r);for(let[t,n]of Object.entries(l))a(n)&&(l[t]={theme:e,group:e,...n});return l}function Be(e){let t={...e};for(let[n,r]of Object.entries(e)){let e=n.replace(/^on-/,``).replace(/-(?:hovered|active|inactive|disabled)$/i,``);e!==n&&a(r)&&!(`group`in r)&&(t[n]={...r,group:e})}return t}function Ve(e){let t=e.base,n=e.brand;return!i(t)||a(t)||!i(n)||a(n)||Object.entries(n).some(([e,t])=>!r.has(e)&&!e.startsWith(`$`)&&a(t))?e:{...e,brand:{...t,...n}}}function $(e,t,n,o){if(Array.isArray(e))return e.map(e=>$(e,t,void 0,o));if(!i(e)||a(e))return e;let s={};for(let[n,i]of Object.entries(e))s[n]=r.has(n)||n.startsWith(`$`)?i:$(i,t,n,n===`dark`||n===`light`?n:o);let c=s;if(n===`color`){c=Ve(c);for(let[e,n]of A(c))c[e]=ze(e,n,t,o);for(let[e,n]of Object.entries(c)){let r=a(n)&&typeof n.group==`string`?ge[n.group]:void 0;r&&(c=Q(c,t,r,e,o))}}for(let[e,n]of Object.entries(_e))a(c[e])&&(c=Q(c,t,n,e,o));return n===`color`?Be(c):c}function He(e){let t=S(e),n=xe($(t,t,void 0,ae(t)));return I(n,n)}var Ue=e(()=>({name:`cyclone-ui:tamagui-preprocessor`,preprocessors:[{name:`tamagui-preprocessor`,preprocessor:He}]}));export{Ue as default,He as tamaguiPreprocessor};
|
|
2
2
|
//# sourceMappingURL=preprocessor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preprocessor.mjs","names":["HEX_RE","OKLCH_RE","RESERVED_KEYS","isPlainObject","value","isTokenNode","isAlias","trimmed","clamp01","toSrgb","clipped","channel","fromSrgb","hexChannel","srgbHexChannel","alphaHex","alpha","expandHex","hex","digit","colorValueToHex","expanded","parseAlpha","red","parseComponent","green","blue","oklchToLinearSrgb","hueRad","hue","a","chroma","b","l_","lightness","m_","s_","l3","m3","s3","oklchToHex","parsed","oklchStringToHex","match","oklchObjectToHex","convertColor","convertShadow","layer","color","convertValue","type","resolveType","token","inheritedType","mapTokenNode","walk","node","item","groupType","result","key","CONTRAST_PRIMITIVES","PURE_CONTRAST_COLORS","parentThemeFromDescription","description","theme","parentThemeFromDictionary","dictionary","LOW_SATURATION_COLOR_STATE_ACTIVE","COLOR_STATE_ACTIVE","SUBTLE_LOW_SATURATION_COLOR_STATE_ACTIVE","INCREASED_LOW_SATURATION_COLOR_STATE_ACTIVE","COLOR_STATE_INACTIVE","LOW_SATURATION_COLOR_STATE_INACTIVE","COLOR_STATE_DISABLED","DEFAULT_COLOR_STATE_VARIANTS","SUBTLE_COLOR_STATE_VARIANTS","BACKGROUND_COLOR_STATE_INACTIVE","BACKGROUND_COLOR_STATE_DISABLED","BACKGROUND_COLOR_STATE_VARIANTS","NONE_THEME_COLOR_KEYS","themeColorGroups","entry","HAIRLINE_COLOR_STATE_VARIANTS","THEME_COLOR_STATE_HOVERED_VARIANTS","THEME_COLOR_STATE_VARIANTS","COLOR_STATE_TOKEN_GROUPS","COLOR_STATE_VARIANTS","MINIMUM_SUBTLE_CONTRAST_RATIO","SUBTLE_COLOR_LIGHTNESS_STEP","isStateVariantKey","getTokenAtPath","tree","part","path","resolveColorHex","direct","ref","seen","applyOpacity","rgb","opacity","applyFadeOver","foreground","base","background","offset","applyRingOpacity","inRingGroup","applyToLayer","isLowSaturation","index","ZERO","ringLayer","spread","addMissingRingTokens","ring","changed","name","ringColor","gap","variants","hexToOklch","isGreyscale","l","m","s","isInSrgbGamut","oklchToGamutMappedHex","minimumChroma","maximumChroma","candidateChroma","applyBrightness","factor","applyLightnessShift","shift","applySaturation","relativeLuminance","contrastRatio","firstLuminance","first","secondLuminance","second","lighter","darker","createOnColor","whiteContrast","createMutedColor","secondaryDirection","parentTheme","onMutedDirection","secondaryLightness","onMutedLightness","secondary","onMuted","
|
|
1
|
+
{"version":3,"file":"preprocessor.mjs","names":["HEX_RE","OKLCH_RE","RESERVED_KEYS","isPlainObject","value","isTokenNode","isAlias","trimmed","clamp01","toSrgb","clipped","channel","fromSrgb","hexChannel","srgbHexChannel","alphaHex","alpha","expandHex","hex","digit","colorValueToHex","expanded","parseAlpha","red","parseComponent","green","blue","oklchToLinearSrgb","hueRad","hue","a","chroma","b","l_","lightness","m_","s_","l3","m3","s3","oklchToHex","parsed","oklchStringToHex","match","oklchObjectToHex","convertColor","convertShadow","layer","color","convertValue","type","resolveType","token","inheritedType","mapTokenNode","walk","node","item","groupType","result","key","CONTRAST_PRIMITIVES","PURE_CONTRAST_COLORS","parentThemeFromDescription","description","theme","parentThemeFromDictionary","dictionary","LOW_SATURATION_COLOR_STATE_ACTIVE","COLOR_STATE_ACTIVE","SUBTLE_LOW_SATURATION_COLOR_STATE_ACTIVE","INCREASED_LOW_SATURATION_COLOR_STATE_ACTIVE","COLOR_STATE_INACTIVE","LOW_SATURATION_COLOR_STATE_INACTIVE","COLOR_STATE_DISABLED","DEFAULT_COLOR_STATE_VARIANTS","SUBTLE_COLOR_STATE_VARIANTS","BACKGROUND_COLOR_STATE_INACTIVE","BACKGROUND_COLOR_STATE_DISABLED","BACKGROUND_COLOR_STATE_VARIANTS","NONE_THEME_COLOR_KEYS","themeColorGroups","entry","HAIRLINE_COLOR_STATE_VARIANTS","THEME_COLOR_STATE_HOVERED_VARIANTS","THEME_COLOR_STATE_VARIANTS","COLOR_STATE_TOKEN_GROUPS","COLOR_STATE_VARIANTS","MINIMUM_SUBTLE_CONTRAST_RATIO","SUBTLE_COLOR_LIGHTNESS_STEP","isStateVariantKey","getTokenAtPath","tree","part","path","resolveColorHex","direct","ref","seen","applyOpacity","rgb","opacity","applyFadeOver","foreground","base","background","offset","applyRingOpacity","inRingGroup","applyToLayer","isLowSaturation","index","ZERO","ringLayer","spread","addMissingRingTokens","ring","changed","name","ringColor","gap","variants","hexToOklch","isGreyscale","l","m","s","isInSrgbGamut","oklchToGamutMappedHex","minimumChroma","maximumChroma","candidateChroma","applyBrightness","factor","applyLightnessShift","shift","applySaturation","relativeLuminance","contrastRatio","firstLuminance","first","secondLuminance","second","lighter","darker","createOnColor","whiteContrast","createMutedColor","secondaryDirection","parentTheme","onMutedDirection","secondaryLightness","onMutedLightness","secondary","onMuted","LOW_SATURATION_WHITE_LIGHTNESS","LOW_SATURATION_BLACK_LIGHTNESS","isWhiteColor","isBlackColor","isInteractionState","variant","isNearContrastPrimitive","stateTheme","themeBrightness","withThemeBrightness","brightness","isReversedState","isBrighterState","applyStateBrightness","step","contrastPrimitive","contrastSideLightnessShift","stateContrastColor","primitive","applyStateTransform","transformed","variantDetail","details","createStateToken","detail","source","addColorStateTokens","group","names","onlyKey","baseVariants","hasHovered","tokenVariants","tokenParentTheme","variantKey","activeKey","active","floor","addThemeColorGroupTokens","onSecondary","pair","secondaryHex","direction","addColorTokenGroups","root","populateEmptyBrandTheme","brand","injectColorStateVariants","childKey","withStates","tokenKey","tamaguiPreprocessor","converted","withRings","preprocessor_default","definePlugin"],"sources":[],"mappings":""}
|
package/package.json
CHANGED
package/src/preprocessor.ts
CHANGED
|
@@ -401,8 +401,10 @@ interface ColorStateVariant {
|
|
|
401
401
|
/** Multiplier applied to OKLCH chroma for non-greyscale colors. */
|
|
402
402
|
saturation?: number;
|
|
403
403
|
/**
|
|
404
|
-
* Multiplier applied to OKLCH lightness (e.g. 1.1 = 10%).
|
|
405
|
-
*
|
|
404
|
+
* Multiplier applied to OKLCH lightness (e.g. 1.1 = 10%). Values above 1 are
|
|
405
|
+
* brighter: lighter in dark themes, darker in light themes. Active states
|
|
406
|
+
* are never less bright than the color's normal, hovered, or inactive states;
|
|
407
|
+
* hovered states reverse for colors already near the contrast primitive.
|
|
406
408
|
*/
|
|
407
409
|
brightness?: number;
|
|
408
410
|
/** Resolve state colors from the parent theme's contrast primitive. */
|
|
@@ -505,10 +507,14 @@ const DEFAULT_COLOR_STATE_VARIANTS: ColorStateVariants = {
|
|
|
505
507
|
saturated: [COLOR_STATE_ACTIVE, COLOR_STATE_INACTIVE, COLOR_STATE_DISABLED]
|
|
506
508
|
};
|
|
507
509
|
|
|
510
|
+
/**
|
|
511
|
+
* Subtle (secondary) colors dim their own lightness when inactive; the
|
|
512
|
+
* contrast primitive's mid-grey would be brighter than these backgrounds.
|
|
513
|
+
*/
|
|
508
514
|
const SUBTLE_COLOR_STATE_VARIANTS: ColorStateVariants = {
|
|
509
515
|
lowSaturation: [
|
|
510
516
|
SUBTLE_LOW_SATURATION_COLOR_STATE_ACTIVE,
|
|
511
|
-
|
|
517
|
+
COLOR_STATE_INACTIVE,
|
|
512
518
|
COLOR_STATE_DISABLED
|
|
513
519
|
],
|
|
514
520
|
saturated: DEFAULT_COLOR_STATE_VARIANTS.saturated
|
|
@@ -1069,22 +1075,6 @@ function createMutedColor(
|
|
|
1069
1075
|
throw new Error(`Unable to generate an accessible secondary pair for ${hex}`);
|
|
1070
1076
|
}
|
|
1071
1077
|
|
|
1072
|
-
function isLightColor(hex: string, parentTheme?: ParentTheme): boolean {
|
|
1073
|
-
if (parentTheme === "dark") {
|
|
1074
|
-
return isWhiteColor(hex);
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
if (parentTheme === "light") {
|
|
1078
|
-
return !isBlackColor(hex);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
return hexToOklch(hex).lightness >= 0.5;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
function isDarkColor(hex: string, parentTheme?: ParentTheme): boolean {
|
|
1085
|
-
return !isLightColor(hex, parentTheme);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
1078
|
/** Low-saturation colors only count as white / black past ≈ #dddddd / #262626. */
|
|
1089
1079
|
const LOW_SATURATION_WHITE_LIGHTNESS = hexToOklch("#fefefe").lightness;
|
|
1090
1080
|
const LOW_SATURATION_BLACK_LIGHTNESS = hexToOklch("#262626").lightness;
|
|
@@ -1117,13 +1107,83 @@ function isNearContrastPrimitive(
|
|
|
1117
1107
|
: parentTheme === "light" && isBlackColor(hex);
|
|
1118
1108
|
}
|
|
1119
1109
|
|
|
1120
|
-
/**
|
|
1121
|
-
function
|
|
1110
|
+
/** Without a parent theme, dark colors brighten like a dark theme (and vice versa). */
|
|
1111
|
+
function stateTheme(hex: string, parentTheme?: ParentTheme): ParentTheme {
|
|
1112
|
+
return parentTheme ?? (hexToOklch(hex).lightness >= 0.5 ? "light" : "dark");
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/** Brightness is OKLCH lightness in dark themes and its inverse in light themes. */
|
|
1116
|
+
function themeBrightness(hex: string, parentTheme: ParentTheme): number {
|
|
1117
|
+
const { lightness } = hexToOklch(hex);
|
|
1118
|
+
|
|
1119
|
+
return parentTheme === "light" ? 1 - lightness : lightness;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
function withThemeBrightness(
|
|
1122
1123
|
hex: string,
|
|
1123
|
-
|
|
1124
|
-
parentTheme
|
|
1125
|
-
):
|
|
1126
|
-
|
|
1124
|
+
brightness: number,
|
|
1125
|
+
parentTheme: ParentTheme
|
|
1126
|
+
): string {
|
|
1127
|
+
const { chroma, hue, alpha } = hexToOklch(hex);
|
|
1128
|
+
|
|
1129
|
+
return oklchToGamutMappedHex(
|
|
1130
|
+
clamp01(parentTheme === "light" ? 1 - brightness : brightness),
|
|
1131
|
+
chroma,
|
|
1132
|
+
hue,
|
|
1133
|
+
alpha
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Only hovered states reverse, for colors already near the contrast primitive
|
|
1139
|
+
* (which can't get meaningfully brighter); active states never become less
|
|
1140
|
+
* bright.
|
|
1141
|
+
*/
|
|
1142
|
+
function isReversedState(
|
|
1143
|
+
hex: string,
|
|
1144
|
+
variant: ColorStateVariant,
|
|
1145
|
+
parentTheme: ParentTheme
|
|
1146
|
+
): boolean {
|
|
1147
|
+
return (
|
|
1148
|
+
variant.name === "hovered" && isNearContrastPrimitive(hex, parentTheme)
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
function isBrighterState(
|
|
1153
|
+
hex: string,
|
|
1154
|
+
variant: ColorStateVariant,
|
|
1155
|
+
parentTheme: ParentTheme
|
|
1156
|
+
): boolean {
|
|
1157
|
+
return (
|
|
1158
|
+
(variant.brightness ?? 1) >= 1 !==
|
|
1159
|
+
isReversedState(hex, variant, parentTheme)
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* Step `hex` by the state's `brightness` (a multiple of its OKLCH lightness).
|
|
1165
|
+
* Brighter steps stop halfway to pure white / black so bright colors keep
|
|
1166
|
+
* their hue instead of blowing out. Reversed steps scale with brightness so
|
|
1167
|
+
* pure black still moves in light themes.
|
|
1168
|
+
*/
|
|
1169
|
+
function applyStateBrightness(
|
|
1170
|
+
hex: string,
|
|
1171
|
+
variant: ColorStateVariant,
|
|
1172
|
+
parentTheme: ParentTheme
|
|
1173
|
+
): string {
|
|
1174
|
+
const brightness = themeBrightness(hex, parentTheme);
|
|
1175
|
+
const step =
|
|
1176
|
+
(isReversedState(hex, variant, parentTheme)
|
|
1177
|
+
? brightness
|
|
1178
|
+
: hexToOklch(hex).lightness) * Math.abs((variant.brightness ?? 1) - 1);
|
|
1179
|
+
|
|
1180
|
+
return withThemeBrightness(
|
|
1181
|
+
hex,
|
|
1182
|
+
isBrighterState(hex, variant, parentTheme)
|
|
1183
|
+
? brightness + Math.min(step, (1 - brightness) / 2)
|
|
1184
|
+
: brightness - step,
|
|
1185
|
+
parentTheme
|
|
1186
|
+
);
|
|
1127
1187
|
}
|
|
1128
1188
|
|
|
1129
1189
|
function contrastPrimitive(
|
|
@@ -1178,22 +1238,6 @@ function stateContrastColor(
|
|
|
1178
1238
|
: primitive;
|
|
1179
1239
|
}
|
|
1180
1240
|
|
|
1181
|
-
function stateBrightnessFactor(
|
|
1182
|
-
hex: string,
|
|
1183
|
-
variant: ColorStateVariant,
|
|
1184
|
-
parentTheme?: ParentTheme
|
|
1185
|
-
): number {
|
|
1186
|
-
if (variant.brightness === undefined) {
|
|
1187
|
-
return 1;
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
if (contrastPrimitive(variant, parentTheme)) {
|
|
1191
|
-
return isInteractionState(variant) ? 1 : variant.brightness;
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
return directedBrightnessFactor(hex, variant.brightness, parentTheme);
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
1241
|
function applyStateTransform(
|
|
1198
1242
|
hex: string,
|
|
1199
1243
|
variant: ColorStateVariant,
|
|
@@ -1204,6 +1248,7 @@ function applyStateTransform(
|
|
|
1204
1248
|
shift === undefined
|
|
1205
1249
|
? stateContrastColor(hex, variant, parentTheme)
|
|
1206
1250
|
: undefined;
|
|
1251
|
+
const theme = stateTheme(hex, parentTheme);
|
|
1207
1252
|
let transformed = primitive ?? hex;
|
|
1208
1253
|
|
|
1209
1254
|
if (shift !== undefined) {
|
|
@@ -1212,10 +1257,15 @@ function applyStateTransform(
|
|
|
1212
1257
|
variant.brightness !== undefined &&
|
|
1213
1258
|
!(primitive && isInteractionState(variant))
|
|
1214
1259
|
) {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1260
|
+
// Non-interaction states scale the primitive's brightness directly
|
|
1261
|
+
// (e.g. inactive at 50% is mid-grey in both dark and light themes).
|
|
1262
|
+
transformed = primitive
|
|
1263
|
+
? withThemeBrightness(
|
|
1264
|
+
primitive,
|
|
1265
|
+
themeBrightness(primitive, theme) * variant.brightness,
|
|
1266
|
+
theme
|
|
1267
|
+
)
|
|
1268
|
+
: applyStateBrightness(hex, variant, theme);
|
|
1219
1269
|
}
|
|
1220
1270
|
|
|
1221
1271
|
if (variant.saturation !== undefined && !isGreyscale(hex)) {
|
|
@@ -1256,11 +1306,12 @@ function variantDetail(
|
|
|
1256
1306
|
: `${parentTheme} contrast primitive`
|
|
1257
1307
|
);
|
|
1258
1308
|
} else if (variant.brightness !== undefined) {
|
|
1259
|
-
const
|
|
1260
|
-
const percent = Math.round((factor - 1) * 100);
|
|
1309
|
+
const theme = stateTheme(hex, parentTheme);
|
|
1261
1310
|
|
|
1262
1311
|
details.push(
|
|
1263
|
-
|
|
1312
|
+
primitive
|
|
1313
|
+
? `${Math.round(variant.brightness * 100)}% of the ${theme} contrast primitive's brightness`
|
|
1314
|
+
: `${Math.round(Math.abs(variant.brightness - 1) * 100)}% ${isBrighterState(hex, variant, theme) ? "brighter" : "less bright"}`
|
|
1264
1315
|
);
|
|
1265
1316
|
}
|
|
1266
1317
|
|
|
@@ -1358,6 +1409,34 @@ function addColorStateTokens(
|
|
|
1358
1409
|
tokenParentTheme
|
|
1359
1410
|
);
|
|
1360
1411
|
}
|
|
1412
|
+
|
|
1413
|
+
// Generated active states are never less bright than the color or its
|
|
1414
|
+
// hovered / inactive states.
|
|
1415
|
+
const activeKey = `${name}-active`;
|
|
1416
|
+
const active = result[activeKey];
|
|
1417
|
+
if (
|
|
1418
|
+
!(activeKey in group) &&
|
|
1419
|
+
isTokenNode(active) &&
|
|
1420
|
+
typeof active.$value === "string"
|
|
1421
|
+
) {
|
|
1422
|
+
const theme = stateTheme(hex, tokenParentTheme);
|
|
1423
|
+
const floor = Math.max(
|
|
1424
|
+
...[
|
|
1425
|
+
hex,
|
|
1426
|
+
result[`${name}-hovered`]?.$value,
|
|
1427
|
+
result[`${name}-inactive`]?.$value
|
|
1428
|
+
]
|
|
1429
|
+
.map(value => resolveColorHex(value, tree))
|
|
1430
|
+
.filter((value): value is string => value !== undefined)
|
|
1431
|
+
.map(value => themeBrightness(value, theme))
|
|
1432
|
+
);
|
|
1433
|
+
if (themeBrightness(active.$value, theme) < floor) {
|
|
1434
|
+
result[activeKey] = {
|
|
1435
|
+
...active,
|
|
1436
|
+
$value: withThemeBrightness(active.$value, floor, theme)
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1361
1440
|
}
|
|
1362
1441
|
|
|
1363
1442
|
return result;
|
|
@@ -1614,8 +1693,10 @@ function injectColorStateVariants(
|
|
|
1614
1693
|
* primitive (backgrounds use a half-strength shift of their own lightness; hovered
|
|
1615
1694
|
* colors already near that primitive shift toward the middle, while active
|
|
1616
1695
|
* ones become pure white or black); saturated
|
|
1617
|
-
* colors scale their own lightness.
|
|
1618
|
-
*
|
|
1696
|
+
* colors scale their own lightness. "Brighter" means lighter in dark themes and
|
|
1697
|
+
* darker in light themes: active states are never less bright than the normal,
|
|
1698
|
+
* hovered, or inactive states, and hovered states take a smaller step than
|
|
1699
|
+
* active (reversing only for colors near the contrast primitive). Tokens in a theme color group get the
|
|
1619
1700
|
* group name as `theme` and `group`, unless already set; root state and `on-*`
|
|
1620
1701
|
* tokens get their main token name as `group` (e.g. `hairline-active` →
|
|
1621
1702
|
* `hairline`).
|