@cyclone-ui/theme-builder 0.0.33 → 0.0.35
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 +11 -0
- package/README.md +17 -22
- package/dist/preprocessor.cjs +1 -1
- package/dist/preprocessor.d.cts +2 -1
- package/dist/preprocessor.d.cts.map +1 -1
- package/dist/preprocessor.d.mts +2 -1
- package/dist/preprocessor.mjs +1 -1
- package/dist/preprocessor.mjs.map +1 -1
- package/package.json +3 -3
- package/src/preprocessor.ts +26 -2
- package/test/preprocessor.spec.ts +54 -0
- package/vitest.config.mts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Cyclone UI - Theme Builder
|
|
4
4
|
|
|
5
|
+
## [0.0.35](https://github.com/storm-software/cyclone-ui/releases/tag/theme-builder%400.0.35) (11/04/2026)
|
|
6
|
+
|
|
7
|
+
### Miscellaneous
|
|
8
|
+
|
|
9
|
+
- [nx migration] update-0-0-19 ([1bba628c7](https://github.com/storm-software/cyclone-ui/commit/1bba628c7))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- **theme-builder:** Added the `border` color token to themes ([47f36e073](https://github.com/storm-software/cyclone-ui/commit/47f36e073))
|
|
14
|
+
- **monorepo:** Resolve server rendering issues with newly added component files and linting failures ([199b43593](https://github.com/storm-software/cyclone-ui/commit/199b43593))
|
|
15
|
+
|
|
5
16
|
## [0.0.33](https://github.com/storm-software/cyclone-ui/releases/tag/theme-builder%400.0.33) (11/03/2026)
|
|
6
17
|
|
|
7
18
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -43,30 +43,25 @@ This package is part of the <b>🌀 Cyclone UI</b> monorepo. The repository cont
|
|
|
43
43
|
|
|
44
44
|
A package containing the theme building utilities and shared code used by the Cyclone UI project
|
|
45
45
|
|
|
46
|
-
<!-- START doctoc -->
|
|
46
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
47
47
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- [
|
|
55
|
-
- [
|
|
56
|
-
- [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- [Documentation](#documentation)
|
|
66
|
-
- [Changelog](#changelog)
|
|
67
|
-
- [Contributing](#contributing)
|
|
68
|
-
- [Contributors](#contributors)
|
|
69
|
-
- [💻 Visit stormsoftware.com to stay up to date with this developer](#-visit-stormsoftwarecom-to-stay-up-to-date-with-this-developer-1)
|
|
49
|
+
- [Quick Features](#quick-features)
|
|
50
|
+
- [Installing](#installing)
|
|
51
|
+
- [Usage](#usage)
|
|
52
|
+
- [Reduced Package Size](#reduced-package-size)
|
|
53
|
+
- [Development](#development)
|
|
54
|
+
- [Building](#building)
|
|
55
|
+
- [Running unit tests](#running-unit-tests)
|
|
56
|
+
- [Linting](#linting)
|
|
57
|
+
- [Storm Workspaces](#storm-workspaces)
|
|
58
|
+
- [Roadmap](#roadmap)
|
|
59
|
+
- [Support](#support)
|
|
60
|
+
- [License](#license)
|
|
61
|
+
- [Documentation](#documentation)
|
|
62
|
+
- [Changelog](#changelog)
|
|
63
|
+
- [Contributing](#contributing)
|
|
64
|
+
- [Contributors](#contributors)
|
|
70
65
|
|
|
71
66
|
<!-- END doctoc -->
|
|
72
67
|
|
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 ne(e){if(Array.isArray(e))return e.map(e=>ne(e));if(!i(e)||!(`color`in e))return e;let t=y(e.color);return t?{...e,color:t}:e}function re(e,t){if(t===`shadow`)return ne(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 b(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function ie(e,t){if(`$ref`in e&&!(`$value`in e))return{...e};let n=b(e,t);return`$value`in e?{...e,$value:re(e.$value,n)}:{...e}}function x(e,t){if(Array.isArray(e))return e.map(e=>x(e,t));if(!i(e))return e;if(a(e))return ie(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:x(i,n);return o}const ae={dark:`#ffffff`,light:`#0c0c0d`},oe={dark:`#ffffff`,light:`#000000`};function se(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 ce(e){if(i(e)&&i(e.color))return se(e.color.$description)}const le={name:`active`,brightness:1.45,useContrastPrimitive:!0},ue={name:`active`,brightness:1.25},de={name:`active`,brightness:1.125},fe={name:`active`,brightness:1.4},pe={name:`active`,brightness:1.8,useContrastPrimitive:!0},S={name:`inactive`,brightness:.8},C={name:`inactive`,brightness:.5,useContrastPrimitive:!0},w={name:`disabled`,opacity:.35,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},T={lowSaturation:[le,C,w],saturated:[ue,S,w]},me={lowSaturation:[de,C,w],saturated:T.saturated},E={name:`inactive`,brightness:.9},D={...w,opacity:.675,saturation:.925},O={lowSaturation:[{name:`active`,brightness:1.15},E,D],saturated:[{name:`active`,brightness:1.25},E,D]},he=[`shadows`];function k(e){return Object.entries(e).filter(e=>!he.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const A={lowSaturation:[pe,C,w],saturated:[fe,S,w]},ge={primary:T,secondary:me,link:T,outline:A},_e={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...T.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...T.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.1},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]}},ve={outline:A},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)&&b(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?ae[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)?oe[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!==ae[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=b(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=se(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),s=a(i)&&b(i);if(!a(i)||!o||s&&s!==`color`)return t;let c={...t};c.link??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} hyperlink text color (matches primary)`},t.group===`status`&&(c.outline??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} border and divider color (matches primary)`}),c[`on-primary`]??={...i,$type:`color`,$value:K(o),$description:`Generated text and icon color on ${e} primary backgrounds`},c.backdrop??={...i,$type:`color`,$value:P(U(o,.25),.75),$description:`Generated ${e} overlay backdrop color (primary, 30% darker at 75% opacity)`};let l;if(r&&!(`secondary`in t)){let t=Te(o,r);c.secondary={...i,$type:`color`,$value:t.secondary,$description:`Generated low-emphasis ${e} background for the ${r} theme`},l=t.onMuted??o}else if(a(t.secondary)){let e=N(t.secondary.$value,n);l=e&&K(e)}l&&!(`on-secondary`in t)&&(c[`on-secondary`]={...i,$type:`color`,$value:l,$description:`Generated text and icon color on ${e} secondary backgrounds`});for(let[e,t]of Object.entries(ge))c=Q(c,n,t,e,r);for(let[t,n]of Object.entries(c))a(n)&&(c[t]={theme:e,group:e,...n});return c}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=x(e),n=Se($(t,t,void 0,ce(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 ie={dark:`#ffffff`,light:`#0c0c0d`},ae={dark:`#ffffff`,light:`#000000`};function oe(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 se(e){if(i(e)&&i(e.color))return oe(e.color.$description)}const ce={name:`active`,brightness:1.45,useContrastPrimitive:!0},le={name:`active`,brightness:1.25},ue={name:`active`,brightness:1.125},de={name:`active`,brightness:1.4},fe={name:`active`,brightness:1.8,useContrastPrimitive:!0},C={name:`inactive`,brightness:.8},w={name:`inactive`,brightness:.5,useContrastPrimitive:!0},T={name:`disabled`,opacity:.35,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},E={lowSaturation:[ce,w,T],saturated:[le,C,T]},pe={lowSaturation:[ue,w,T],saturated:E.saturated},me={name:`inactive`,brightness:.9},D={...T,opacity:.675,saturation:.925},O={lowSaturation:[{name:`active`,brightness:1.15},me,D],saturated:[{name:`active`,brightness:1.25},me,D]},he=[`shadows`];function k(e){return Object.entries(e).filter(e=>!he.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const A={lowSaturation:[fe,w,T],saturated:[de,C,T]},ge={primary:E,secondary:pe,link:E,outline:A},_e={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...E.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...E.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.1},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]}},ve={outline:A},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?ie[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)?ae[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!==ie[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=oe(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)`},t.group===`status`&&(l.outline??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} border and divider 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,.25),.75),$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*.15)),n,a,o),$description:`Generated ${e} border color for secondary backgrounds (secondary, 15% ${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,se(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;
|
package/dist/preprocessor.d.cts
CHANGED
|
@@ -5,7 +5,8 @@ import { PreprocessedTokens } from "style-dictionary/types";
|
|
|
5
5
|
* `oklch()`. Root colors (emphasis, ink, subtle, subtlest, outline, backgrounds)
|
|
6
6
|
* stay in the root light and dark themes without rings. For each color group
|
|
7
7
|
* with a `primary` token (except excluded groups), a missing `secondary` background and `on-primary` /
|
|
8
|
-
* `on-secondary` text colors are generated,
|
|
8
|
+
* `on-secondary` text colors are generated, a missing `border` is derived from
|
|
9
|
+
* `secondary` (15% brighter, or darker in light themes), then hovered, active, inactive,
|
|
9
10
|
* and disabled variants are added to the outline, `foreground` and
|
|
10
11
|
* `background` group colors, and each theme color group's `primary`, `secondary`
|
|
11
12
|
* `link` and `outline` (`link`, and `outline` in `status` groups, default to
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;iBA0kDgB,oBACd,YAAY,qBACX"}
|
package/dist/preprocessor.d.mts
CHANGED
|
@@ -5,7 +5,8 @@ import { PreprocessedTokens } from "style-dictionary/types";
|
|
|
5
5
|
* `oklch()`. Root colors (emphasis, ink, subtle, subtlest, outline, backgrounds)
|
|
6
6
|
* stay in the root light and dark themes without rings. For each color group
|
|
7
7
|
* with a `primary` token (except excluded groups), a missing `secondary` background and `on-primary` /
|
|
8
|
-
* `on-secondary` text colors are generated,
|
|
8
|
+
* `on-secondary` text colors are generated, a missing `border` is derived from
|
|
9
|
+
* `secondary` (15% brighter, or darker in light themes), then hovered, active, inactive,
|
|
9
10
|
* and disabled variants are added to the outline, `foreground` and
|
|
10
11
|
* `background` group colors, and each theme color group's `primary`, `secondary`
|
|
11
12
|
* `link` and `outline` (`link`, and `outline` in `status` groups, default to
|
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 ne(e){if(Array.isArray(e))return e.map(e=>ne(e));if(!i(e)||!(`color`in e))return e;let t=y(e.color);return t?{...e,color:t}:e}function re(e,t){if(t===`shadow`)return ne(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 b(e,t){return typeof e.$type==`string`?e.$type:typeof e.type==`string`?e.type:t}function ie(e,t){if(`$ref`in e&&!(`$value`in e))return{...e};let n=b(e,t);return`$value`in e?{...e,$value:re(e.$value,n)}:{...e}}function x(e,t){if(Array.isArray(e))return e.map(e=>x(e,t));if(!i(e))return e;if(a(e))return ie(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:x(i,n);return o}const ae={dark:`#ffffff`,light:`#0c0c0d`},oe={dark:`#ffffff`,light:`#000000`};function se(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 ce(e){if(i(e)&&i(e.color))return se(e.color.$description)}const le={name:`active`,brightness:1.45,useContrastPrimitive:!0},ue={name:`active`,brightness:1.25},de={name:`active`,brightness:1.125},fe={name:`active`,brightness:1.4},pe={name:`active`,brightness:1.8,useContrastPrimitive:!0},S={name:`inactive`,brightness:.8},C={name:`inactive`,brightness:.5,useContrastPrimitive:!0},w={name:`disabled`,opacity:.35,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},T={lowSaturation:[le,C,w],saturated:[ue,S,w]},me={lowSaturation:[de,C,w],saturated:T.saturated},E={name:`inactive`,brightness:.9},D={...w,opacity:.675,saturation:.925},O={lowSaturation:[{name:`active`,brightness:1.15},E,D],saturated:[{name:`active`,brightness:1.25},E,D]},he=[`shadows`];function k(e){return Object.entries(e).filter(e=>!he.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const A={lowSaturation:[pe,C,w],saturated:[fe,S,w]},ge={primary:T,secondary:me,link:T,outline:A},_e={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...T.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...T.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.1},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]}},ve={outline:A},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)&&b(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?ae[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)?oe[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!==ae[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=b(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=se(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),s=a(i)&&b(i);if(!a(i)||!o||s&&s!==`color`)return t;let c={...t};c.link??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} hyperlink text color (matches primary)`},t.group===`status`&&(c.outline??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} border and divider color (matches primary)`}),c[`on-primary`]??={...i,$type:`color`,$value:K(o),$description:`Generated text and icon color on ${e} primary backgrounds`},c.backdrop??={...i,$type:`color`,$value:P(U(o,.25),.75),$description:`Generated ${e} overlay backdrop color (primary, 30% darker at 75% opacity)`};let l;if(r&&!(`secondary`in t)){let t=Te(o,r);c.secondary={...i,$type:`color`,$value:t.secondary,$description:`Generated low-emphasis ${e} background for the ${r} theme`},l=t.onMuted??o}else if(a(t.secondary)){let e=N(t.secondary.$value,n);l=e&&K(e)}l&&!(`on-secondary`in t)&&(c[`on-secondary`]={...i,$type:`color`,$value:l,$description:`Generated text and icon color on ${e} secondary backgrounds`});for(let[e,t]of Object.entries(ge))c=Q(c,n,t,e,r);for(let[t,n]of Object.entries(c))a(n)&&(c[t]={theme:e,group:e,...n});return c}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=x(e),n=Se($(t,t,void 0,ce(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 ie={dark:`#ffffff`,light:`#0c0c0d`},ae={dark:`#ffffff`,light:`#000000`};function oe(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 se(e){if(i(e)&&i(e.color))return oe(e.color.$description)}const ce={name:`active`,brightness:1.45,useContrastPrimitive:!0},le={name:`active`,brightness:1.25},ue={name:`active`,brightness:1.125},de={name:`active`,brightness:1.4},fe={name:`active`,brightness:1.8,useContrastPrimitive:!0},C={name:`inactive`,brightness:.8},w={name:`inactive`,brightness:.5,useContrastPrimitive:!0},T={name:`disabled`,opacity:.35,saturation:.85,fadeOver:`oklch(0.3839 0.0045 286.26)`},E={lowSaturation:[ce,w,T],saturated:[le,C,T]},pe={lowSaturation:[ue,w,T],saturated:E.saturated},me={name:`inactive`,brightness:.9},D={...T,opacity:.675,saturation:.925},O={lowSaturation:[{name:`active`,brightness:1.15},me,D],saturated:[{name:`active`,brightness:1.25},me,D]},he=[`shadows`];function k(e){return Object.entries(e).filter(e=>!he.includes(e[0])&&i(e[1])&&!a(e[1])&&a(e[1].primary))}const A={lowSaturation:[fe,w,T],saturated:[de,C,T]},ge={primary:E,secondary:pe,link:E,outline:A},_e={foreground:{lowSaturation:[{name:`hovered`,brightness:1.25},...E.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...E.saturated]},background:{lowSaturation:[{name:`hovered`,brightness:1.1},...O.lowSaturation],saturated:[{name:`hovered`,brightness:1.15},...O.saturated]}},ve={outline:A},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?ie[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)?ae[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!==ie[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=oe(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)`},t.group===`status`&&(l.outline??={...i,$type:`color`,$value:`{color.${e}.primary}`,$description:`Generated ${e} border and divider 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,.25),.75),$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*.15)),n,a,o),$description:`Generated ${e} border color for secondary backgrounds (secondary, 15% ${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,se(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};
|
|
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","HAIRLINE_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","OUTLINE_COLOR_STATE_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","isLightColor","isWhiteColor","isBlackColor","isDarkColor","LOW_SATURATION_WHITE_LIGHTNESS","LOW_SATURATION_BLACK_LIGHTNESS","isInteractionState","variant","isNearContrastPrimitive","directedBrightnessFactor","contrastPrimitive","contrastSideLightnessShift","stateContrastColor","primitive","stateBrightnessFactor","applyStateTransform","transformed","variantDetail","details","percent","createStateToken","detail","source","addColorStateTokens","group","names","onlyKey","baseVariants","hasHovered","tokenVariants","tokenParentTheme","variantKey","addThemeColorGroupTokens","onSecondary","pair","secondaryHex","addColorTokenGroups","root","populateEmptyBrandTheme","brand","injectColorStateVariants","childKey","withStates","tokenKey","tamaguiPreprocessor","converted","withRings","preprocessor_default","definePlugin"],"sources":[],"mappings":""}
|
|
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","HAIRLINE_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","OUTLINE_COLOR_STATE_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","isLightColor","isWhiteColor","isBlackColor","isDarkColor","LOW_SATURATION_WHITE_LIGHTNESS","LOW_SATURATION_BLACK_LIGHTNESS","isInteractionState","variant","isNearContrastPrimitive","directedBrightnessFactor","contrastPrimitive","contrastSideLightnessShift","stateContrastColor","primitive","stateBrightnessFactor","applyStateTransform","transformed","variantDetail","details","percent","createStateToken","detail","source","addColorStateTokens","group","names","onlyKey","baseVariants","hasHovered","tokenVariants","tokenParentTheme","variantKey","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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyclone-ui/theme-builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"style-dictionary": "^5.7.1"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@powerlines/plugin-tsdown": "^0.1.
|
|
82
|
+
"@powerlines/plugin-tsdown": "^0.1.620",
|
|
83
83
|
"@types/node": "^25.9.9",
|
|
84
|
-
"powerlines": "^0.47.
|
|
84
|
+
"powerlines": "^0.47.219"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/preprocessor.ts
CHANGED
|
@@ -634,6 +634,8 @@ const MAX_SUBTLE_COLOR_ADJUSTMENTS = 100;
|
|
|
634
634
|
const SUBTLE_COLOR_GAMUT_SEARCH_ITERATIONS = 32;
|
|
635
635
|
const BACKDROP_BRIGHTNESS = 0.25;
|
|
636
636
|
const BACKDROP_OPACITY = 0.75;
|
|
637
|
+
/** OKLCH lightness step for the rim around `secondary` backgrounds (brighter in dark, darker in light themes). */
|
|
638
|
+
const BORDER_LIGHTNESS_STEP = 0.15;
|
|
637
639
|
/** OKLCH lightness shift for hovered colors already near the contrast primitive. */
|
|
638
640
|
const CONTRAST_SIDE_ACTIVE_LIGHTNESS_SHIFT = 0.25;
|
|
639
641
|
|
|
@@ -1345,7 +1347,8 @@ function addColorStateTokens(
|
|
|
1345
1347
|
* missing `link` color and, for `status` groups, `outline` color (both
|
|
1346
1348
|
* aliasing `primary`), `on-primary` /
|
|
1347
1349
|
* `on-secondary` text colors, a `backdrop` overlay color (`primary` 30% darker
|
|
1348
|
-
* at 75% opacity, no state variants),
|
|
1350
|
+
* at 75% opacity, no state variants), a `border` color (`secondary` 15% brighter, or
|
|
1351
|
+
* 15% darker in light themes, no state variants), and state variants for `primary`, `secondary`,
|
|
1349
1352
|
* `link` and `outline`. Every token in the group gets the group name as
|
|
1350
1353
|
* its `theme` and `group`, so Tamagui places it in that child theme (e.g.
|
|
1351
1354
|
* `danger.on-primary` → `onPrimary` in the `danger` theme).
|
|
@@ -1419,6 +1422,26 @@ function addThemeColorGroupTokens(
|
|
|
1419
1422
|
};
|
|
1420
1423
|
}
|
|
1421
1424
|
|
|
1425
|
+
const secondaryHex =
|
|
1426
|
+
!("border" in group) &&
|
|
1427
|
+
isTokenNode(result.secondary) &&
|
|
1428
|
+
resolveColorHex(result.secondary.$value, tree);
|
|
1429
|
+
if (secondaryHex) {
|
|
1430
|
+
const { lightness, chroma, hue, alpha } = hexToOklch(secondaryHex);
|
|
1431
|
+
const direction = parentTheme === "light" ? -1 : 1;
|
|
1432
|
+
result.border = {
|
|
1433
|
+
...token,
|
|
1434
|
+
$type: "color",
|
|
1435
|
+
$value: oklchToGamutMappedHex(
|
|
1436
|
+
clamp01(lightness * (1 + direction * BORDER_LIGHTNESS_STEP)),
|
|
1437
|
+
chroma,
|
|
1438
|
+
hue,
|
|
1439
|
+
alpha
|
|
1440
|
+
),
|
|
1441
|
+
$description: `Generated ${name} border color for secondary backgrounds (secondary, ${Math.round(BORDER_LIGHTNESS_STEP * 100)}% ${direction > 0 ? "brighter" : "darker"})`
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1422
1445
|
for (const [key, variants] of Object.entries(THEME_COLOR_STATE_VARIANTS)) {
|
|
1423
1446
|
result = addColorStateTokens(result, tree, variants, key, parentTheme);
|
|
1424
1447
|
}
|
|
@@ -1568,7 +1591,8 @@ function injectColorStateVariants(
|
|
|
1568
1591
|
* `oklch()`. Root colors (emphasis, ink, subtle, subtlest, outline, backgrounds)
|
|
1569
1592
|
* stay in the root light and dark themes without rings. For each color group
|
|
1570
1593
|
* with a `primary` token (except excluded groups), a missing `secondary` background and `on-primary` /
|
|
1571
|
-
* `on-secondary` text colors are generated,
|
|
1594
|
+
* `on-secondary` text colors are generated, a missing `border` is derived from
|
|
1595
|
+
* `secondary` (15% brighter, or darker in light themes), then hovered, active, inactive,
|
|
1572
1596
|
* and disabled variants are added to the outline, `foreground` and
|
|
1573
1597
|
* `background` group colors, and each theme color group's `primary`, `secondary`
|
|
1574
1598
|
* `link` and `outline` (`link`, and `outline` in `status` groups, default to
|
|
@@ -126,6 +126,60 @@ describe("tamaguiPreprocessor", () => {
|
|
|
126
126
|
expect(result.color.info.backdrop.$value).toBe("#00000080");
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
it("generates a border color brighter than secondary for theme color groups", () => {
|
|
130
|
+
const result = tamaguiPreprocessor({
|
|
131
|
+
dark: {
|
|
132
|
+
color: {
|
|
133
|
+
base: {
|
|
134
|
+
primary: colorToken("#a1a1aa"),
|
|
135
|
+
secondary: colorToken("#37373b")
|
|
136
|
+
},
|
|
137
|
+
info: {
|
|
138
|
+
primary: colorToken("#4c4dfb"),
|
|
139
|
+
secondary: colorToken("#4c4dfb")
|
|
140
|
+
},
|
|
141
|
+
danger: { primary: colorToken("#ff5470") },
|
|
142
|
+
warning: {
|
|
143
|
+
primary: colorToken("#ffb020"),
|
|
144
|
+
border: colorToken("#ffffff")
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}) as any;
|
|
149
|
+
|
|
150
|
+
const { base, info, danger, warning } = result.dark.color;
|
|
151
|
+
expect(base.border).toMatchObject({ theme: "base", group: "base" });
|
|
152
|
+
for (const group of [base, info, danger]) {
|
|
153
|
+
expect(group.border.$value).toMatch(/^#[0-9a-f]{6}$/);
|
|
154
|
+
expect(relativeLuminance(group.border.$value)).toBeGreaterThan(
|
|
155
|
+
relativeLuminance(group.secondary.$value)
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
expect(base).not.toHaveProperty("border-hovered");
|
|
159
|
+
expect(warning.border.$value).toBe("#ffffff");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("generates a border color darker than secondary in light themes", () => {
|
|
163
|
+
const result = tamaguiPreprocessor({
|
|
164
|
+
light: {
|
|
165
|
+
color: {
|
|
166
|
+
base: {
|
|
167
|
+
primary: colorToken("#3f3f46"),
|
|
168
|
+
secondary: colorToken("#f4f4f5")
|
|
169
|
+
},
|
|
170
|
+
danger: { primary: colorToken("#336699") }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}) as any;
|
|
174
|
+
|
|
175
|
+
for (const group of [result.light.color.base, result.light.color.danger]) {
|
|
176
|
+
expect(group.border.$description).toMatch(/15% darker\)$/);
|
|
177
|
+
expect(relativeLuminance(group.border.$value)).toBeLessThan(
|
|
178
|
+
relativeLuminance(group.secondary.$value)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
129
183
|
it("generates missing on-primary text colors for theme color groups", () => {
|
|
130
184
|
const result = tamaguiPreprocessor({
|
|
131
185
|
color: {
|
package/vitest.config.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { nxViteTsPaths } from "@nx/vite/plugins/nx-tsconfig-paths.plugin";
|
|
2
1
|
import { defineConfig } from "vitest/config";
|
|
3
2
|
|
|
4
3
|
export default defineConfig(() => ({
|
|
4
|
+
resolve: {
|
|
5
|
+
tsconfigPaths: true
|
|
6
|
+
},
|
|
5
7
|
root: import.meta.dirname,
|
|
6
8
|
cacheDir: "../../node_modules/.vite/packages/theme-builder",
|
|
7
|
-
plugins: [
|
|
9
|
+
plugins: [],
|
|
8
10
|
test: {
|
|
9
11
|
name: "theme-builder",
|
|
10
12
|
watch: false,
|