@razorwind/tamagui 0.0.52 → 0.0.53
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/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -51,11 +51,11 @@ Re-run Razorwind generate when tokens change so \`${e.outputPath}\` stays aligne
|
|
|
51
51
|
`}const Ye=new Set([`default`,`light`,`theme`]),Xe=/^base(?:[A-Z]\w*|[._-].+)?$/i,Ze=/^ring(?:\.|$)/i,Qe=[`base`,`gray`,`grey`,`neutral`],$e={css:`@tamagui/config/v5-css`,rn:`@tamagui/config/v5-rn`,reanimated:`@tamagui/config/v5-reanimated`,motion:`@tamagui/config/v5-motion`};function et(e){return Ye.has(e)}function tt(e){return e===`dark`}function B(e,t){let n=new Map,r=t===`dark`?tt:et;for(let t of e){let e=t.theme?.toLowerCase();(!e||Xe.test(e))&&n.set(t.path,t)}for(let t of e){let e=t.theme?.toLowerCase();e&&r(e)&&n.set(t.path,t)}return[...n.values()]}function nt(e){return Ze.test(e.path)&&e.category===`shadow`}const rt=new Set([`fontSize`,`blur`]),it=[`space`,`size`,`radius`,`zIndex`,`blur`,`fontSize`,`shadow`,`insetShadow`,`dropShadow`,`textShadow`,`boxShadow`,`fontWeight`];function at(e){return/^px\(-?\d/.test(e)}function ot(e){if(e.category===`radius`&&e.tokenKey?.startsWith(`borderRadius`)){let t=e.tokenKey.replace(/^borderRadius/,``);return t?C([t]):e.tokenKey}return e.tokenKey??``}function st(e,t){let n=q(e,t.byPath,t.byCssVar).tamaguiValue;if(e.category&&rt.has(e.category)&&typeof n==`number`)return`px(${n})`;if(typeof n==`string`){let r=Ct(n,t);return e.category===`dropShadow`?ct(r):r}return n}function ct(e){return e.includes(`drop-shadow(`)?e:e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.replace(/^inset\s+/i,``).split(/\s+/);if(t.length>=5){let[e,n,r]=t;return`drop-shadow(${e} ${n} ${r} ${t.slice(4).join(` `)})`}return`drop-shadow(${e.replace(/^inset\s+/i,``)})`}).join(` `)}function lt(e){let t={},n=W(e);for(let r of e){if(!r.category||r.category===`color`||!r.tokenKey||nt(r))continue;let e=ot(r);if(!e)continue;let i=st(r,n);if(typeof i==`string`&&St(i))continue;let a=t[r.category]??{};a[e]=i,t[r.category]=a}return t}function V(e){let t=e.tokenKey??e.path.replace(/^color\./i,``).replaceAll(`.`,``);return e.theme?`${e.theme}${t[0]?.toUpperCase()??``}${t.slice(1)}`:t}function H(e){return`tokens.color.${e}.val`}function ut(e,t){let n={},r=W(e),i=W(t),a=(e,t)=>{if(!e.tokenKey)return;let r=K(e,t);typeof r==`string`&&r.length!==0&&r!==`[object Object]`&&(n[V(e)]=r)};for(let t of e)a(t,r);for(let e of t)a(e,i);return n}function dt(e){let t={};for(let n of e){if(!n.primitive)continue;let e=J(n);if(!e)continue;let r=V(n);if(!r)continue;let i=t[e.name]??{};i[`${e.name}${e.step}`]=r,t[e.name]=i}let n=Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=2));if(Object.keys(n).length>0)return n;let r={};for(let t of e){let e=J(t);if(!e)continue;let n=t.tokenKey??V(t);if(!n)continue;let i=r[e.name]??{};i[`${e.name}${e.step}`]=n,r[e.name]=i}return Object.fromEntries(Object.entries(r).filter(([,e])=>Object.keys(e).length>=3))}function U(e,t,n,r){let i=n[r];if(typeof i!=`string`)return!1;let a=K(e,t);return a!=null&&a===i}function ft(e,t,n){let r=V(e);if(U(e,t,n,r))return H(r);if(e.tokenKey&&e.tokenKey!==r&&U(e,t,n,e.tokenKey))return H(e.tokenKey);let i=q(e,t.byPath,t.byCssVar),o=V(i);if(o!==r&&U(e,t,n,o))return H(o);if(i.tokenKey&&i.tokenKey!==o&&U(e,t,n,i.tokenKey))return H(i.tokenKey);if(i.primitive){let r=V(i);if(U(e,t,n,r))return H(r)}let s=K(e,t);if(s)return a(s)}function pt(e,t=2){let n=` `.repeat(t),r=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t,void 0,{numeric:!0}));return r.length===0?`{}`:`{\n${r.map(([e,t])=>{let r=typeof t==`string`&&at(t)?t:a(t);return`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:a(e)}: ${r}`}).join(`,
|
|
52
52
|
`)}\n${` `.repeat(Math.max(t-2,0))}}`}function mt(e,t=2){let n=` `.repeat(t),r=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t,void 0,{numeric:!0}));return r.length===0?`{}`:`{\n${r.map(([e,t])=>`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:a(e)}: ${t}`).join(`,
|
|
53
53
|
`)}\n${` `.repeat(Math.max(t-2,0))}}`}function ht(e,t=2){let n=` `.repeat(t),r=` `.repeat(Math.max(t-2,0)),i=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t,void 0,{numeric:!0}));return i.length===0?`{\n${n}...theme\n${r}}`:`{\n${n}...theme,\n${i.map(([e,t])=>`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:a(e)}: ${t}`).join(`,
|
|
54
|
-
`)}\n${r}}`}const gt=/^\{([^{}]+)\}$/,_t=/\{([^{}]+)\}/g,vt=/^var\((--[^),\s]+)(?:\s*,[^)]*)?\)$/,yt=/var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g;function W(e){return{byPath:new Map(e.map(e=>[e.path,e])),byCssVar:new Map(e.map(e=>[(0,t.toThemeCssVar)(e.path),e]))}}function bt(e){if(typeof e==`string`)return gt.exec(e.trim())?.[1]?.trim()}function G(e){if(typeof e==`string`)return vt.exec(e.trim())?.[1]}function xt(e){return bt(e)!=null||G(e)!=null}function St(e){return/var\(|\{[^{}]+\}/.test(e)}function K(e,t){let n=q(e,t.byPath,t.byCssVar);if(n.category!=null&&n.category!==`color`)return;let r=[n.cssValue,n.tamaguiValue];for(let e of r)if(typeof e==`string`&&e.length>0&&!xt(e))return e}function Ct(e,t){return e.replace(_t,(e,n)=>{let r=t.byPath.get(n.trim());return r?K(r,t)??e:e}).replace(yt,(e,n)=>{let r=t.byCssVar.get(n);return r?K(r,t)??e:e})}function q(e,t,n){let r=e,i=new Set;for(let e=0;e<8;e++){if(i.has(r.path))return r;i.add(r.path);let e=bt(r.value);if(e){let n=t.get(e);if(!n||n.path===r.path)return r;r=n;continue}let a=G(r.value)??G(r.cssValue)??G(r.tamaguiValue);if(a){let e=n.get(a);if(!e||e.path===r.path)return r;r=e;continue}return r}return r}function wt(e){return/^[A-Z_$][\w$]*$/i.test(e)?`theme.${e}`:`theme[${a(e)}]`}function Tt(e,t){return t<1?e:t+1-e}function Et(e,t){return e.length<2?!1:X(e,t).some((t,n)=>t!==e[n])}function Dt(e,t,n,r){let i=n[t];if(!i||r!==`dark`)return e;let a=$(i,t);return a.length<2||!Et(a.map(([,e])=>e),r)?e:Tt(e,a[a.length-1][0])}function Ot(e,t,n,r){let i=J(e);if(!i)return;let a=Dt(i.step,i.name,n,r);if(t&&i.name.toLowerCase()===t.toLowerCase()||n[i.name])return`${i.name}${a}`}function kt(e){if(e>=1&&e<=12)return e;if(e>=100&&e<=900&&e%100==0)return e/100}function J(e){let t=e.path.split(`.`).filter(Boolean),n=t.at(-1);if(n&&/^\d+$/.test(n)){let e=kt(Number(n)),r=t.at(-2);if(e!=null&&r&&!/^(?:color|colours?|palette)$/i.test(r))return{name:C([r]),step:e}}if(!e.tokenKey)return;let r=/^([A-Z]+)(\d{1,3})$/i.exec(e.tokenKey);if(!r)return;let[,i=``,a=``]=r,o=kt(Number(a));if(o!=null)return{name:i,step:o}}function At(e,t,n,r){let i=e[t]??{};i[`${t}${n}`]=r,e[t]=i}function jt(e){let t={};for(let n of e){if(typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&At(t,e.name,e.step,n.tamaguiValue)}return Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=3))}function Y(e){let t={};for(let n of e){if(!n.primitive||typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&At(t,e.name,e.step,n.tamaguiValue)}let n=Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=2));return Object.keys(n).length>0?n:jt(e)}function X(e,t){if(e.length<2)return[...e];let n=Ft(e[0]),r=Ft(e[e.length-1]);if(n==null||r==null||n===r)return[...e];let i=n>r;return t===`light`?i?[...e]:e.toReversed():i?e.toReversed():[...e]}function Z(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function Mt(e){let t=e.startsWith(`#`)?e.slice(1):``;if((t.length===3||t.length===4)&&(t=[...t].map(e=>e+e).join(``)),t.length===8&&(t=t.slice(0,6)),t.length!==6||/[^0-9a-f]/i.test(t))return;let n=Number.parseInt(t.slice(0,2),16)/255,r=Number.parseInt(t.slice(2,4),16)/255,i=Number.parseInt(t.slice(4,6),16)/255;return .2126*Z(n)+.7152*Z(r)+.0722*Z(i)}function Q(e){let t=e.trim();if(t.endsWith(`%`)){let e=Number.parseFloat(t);return Number.isFinite(e)?e/100:void 0}let n=Number.parseFloat(t);return Number.isFinite(n)?n:void 0}function Nt(e){return e>1?e/100:e}function Pt(e,t){let n=RegExp(`^${t}\\((.+)\\)$`,`i`).exec(e.trim());if(n?.[1])return n[1].split(/[\s,/]+/).filter(Boolean)}function Ft(e){let t=e.trim();if(!t||t.startsWith(`var(`)||t.includes(`{`))return;let n=Mt(t);if(n!=null)return n;let r=Pt(t,`oklch`);if(r?.[0]){let e=Q(r[0]);return e==null?void 0:Nt(e)}let i=Pt(t,`hsla?`);if(i?.[2]){let e=Q(i[2]);return e==null?void 0:Nt(e)}let a=Pt(t,`rgba?`);if(a?.[0]&&a[1]&&a[2]){let e=Q(a[0]),t=Q(a[1]),n=Q(a[2]);if(e==null||t==null||n==null)return;let r=(e,t)=>t.trim().endsWith(`%`)||e<=1?e:e/255;return .2126*Z(r(e,a[0]))+.7152*Z(r(t,a[1]))+.0722*Z(r(n,a[2]))}}function $(e,t){let n=[],r=t.toLowerCase();for(let[i,a]of Object.entries(e)){if(!i.toLowerCase().startsWith(r))continue;let e=i.slice(t.length);/^\d+$/.test(e)&&n.push([Number(e),a])}return n.sort(([e],[t])=>e-t),n}function It(e,t,n){let r=$(e,t);if(r.length===0)return e;let i=X(r.map(([,e])=>e),n),a={};for(let[e,[
|
|
54
|
+
`)}\n${r}}`}const gt=/^\{([^{}]+)\}$/,_t=/\{([^{}]+)\}/g,vt=/^var\((--[^),\s]+)(?:\s*,[^)]*)?\)$/,yt=/var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g;function W(e){return{byPath:new Map(e.map(e=>[e.path,e])),byCssVar:new Map(e.map(e=>[(0,t.toThemeCssVar)(e.path),e]))}}function bt(e){if(typeof e==`string`)return gt.exec(e.trim())?.[1]?.trim()}function G(e){if(typeof e==`string`)return vt.exec(e.trim())?.[1]}function xt(e){return bt(e)!=null||G(e)!=null}function St(e){return/var\(|\{[^{}]+\}/.test(e)}function K(e,t){let n=q(e,t.byPath,t.byCssVar);if(n.category!=null&&n.category!==`color`)return;let r=[n.cssValue,n.tamaguiValue];for(let e of r)if(typeof e==`string`&&e.length>0&&!xt(e))return e}function Ct(e,t){return e.replace(_t,(e,n)=>{let r=t.byPath.get(n.trim());return r?K(r,t)??e:e}).replace(yt,(e,n)=>{let r=t.byCssVar.get(n);return r?K(r,t)??e:e})}function q(e,t,n){let r=e,i=new Set;for(let e=0;e<8;e++){if(i.has(r.path))return r;i.add(r.path);let e=bt(r.value);if(e){let n=t.get(e);if(!n||n.path===r.path)return r;r=n;continue}let a=G(r.value)??G(r.cssValue)??G(r.tamaguiValue);if(a){let e=n.get(a);if(!e||e.path===r.path)return r;r=e;continue}return r}return r}function wt(e){return/^[A-Z_$][\w$]*$/i.test(e)?`theme.${e}`:`theme[${a(e)}]`}function Tt(e,t){return t<1?e:t+1-e}function Et(e,t){return e.length<2?!1:X(e,t).some((t,n)=>t!==e[n])}function Dt(e,t,n,r){let i=n[t];if(!i||r!==`dark`)return e;let a=$(i,t);return a.length<2||!Et(a.map(([,e])=>e),r)?e:Tt(e,a[a.length-1][0])}function Ot(e,t,n,r){let i=J(e);if(!i)return;let a=Dt(i.step,i.name,n,r);if(t&&i.name.toLowerCase()===t.toLowerCase()||n[i.name])return`${i.name}${a}`}function kt(e){if(e>=1&&e<=12)return e;if(e>=100&&e<=900&&e%100==0)return e/100}function J(e){let t=e.path.split(`.`).filter(Boolean),n=t.at(-1);if(n&&/^\d+$/.test(n)){let e=kt(Number(n)),r=t.at(-2);if(e!=null&&r&&!/^(?:color|colours?|palette)$/i.test(r))return{name:C([r]),step:e}}if(!e.tokenKey)return;let r=/^([A-Z]+)(\d{1,3})$/i.exec(e.tokenKey);if(!r)return;let[,i=``,a=``]=r,o=kt(Number(a));if(o!=null)return{name:i,step:o}}function At(e,t,n,r){let i=e[t]??{};i[`${t}${n}`]=r,e[t]=i}function jt(e){let t={};for(let n of e){if(typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&At(t,e.name,e.step,n.tamaguiValue)}return Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=3))}function Y(e){let t={};for(let n of e){if(!n.primitive||typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&At(t,e.name,e.step,n.tamaguiValue)}let n=Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=2));return Object.keys(n).length>0?n:jt(e)}function X(e,t){if(e.length<2)return[...e];let n=Ft(e[0]),r=Ft(e[e.length-1]);if(n==null||r==null||n===r)return[...e];let i=n>r;return t===`light`?i?[...e]:e.toReversed():i?e.toReversed():[...e]}function Z(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function Mt(e){let t=e.startsWith(`#`)?e.slice(1):``;if((t.length===3||t.length===4)&&(t=[...t].map(e=>e+e).join(``)),t.length===8&&(t=t.slice(0,6)),t.length!==6||/[^0-9a-f]/i.test(t))return;let n=Number.parseInt(t.slice(0,2),16)/255,r=Number.parseInt(t.slice(2,4),16)/255,i=Number.parseInt(t.slice(4,6),16)/255;return .2126*Z(n)+.7152*Z(r)+.0722*Z(i)}function Q(e){let t=e.trim();if(t.endsWith(`%`)){let e=Number.parseFloat(t);return Number.isFinite(e)?e/100:void 0}let n=Number.parseFloat(t);return Number.isFinite(n)?n:void 0}function Nt(e){return e>1?e/100:e}function Pt(e,t){let n=RegExp(`^${t}\\((.+)\\)$`,`i`).exec(e.trim());if(n?.[1])return n[1].split(/[\s,/]+/).filter(Boolean)}function Ft(e){let t=e.trim();if(!t||t.startsWith(`var(`)||t.includes(`{`))return;let n=Mt(t);if(n!=null)return n;let r=Pt(t,`oklch`);if(r?.[0]){let e=Q(r[0]);return e==null?void 0:Nt(e)}let i=Pt(t,`hsla?`);if(i?.[2]){let e=Q(i[2]);return e==null?void 0:Nt(e)}let a=Pt(t,`rgba?`);if(a?.[0]&&a[1]&&a[2]){let e=Q(a[0]),t=Q(a[1]),n=Q(a[2]);if(e==null||t==null||n==null)return;let r=(e,t)=>t.trim().endsWith(`%`)||e<=1?e:e/255;return .2126*Z(r(e,a[0]))+.7152*Z(r(t,a[1]))+.0722*Z(r(n,a[2]))}}function $(e,t){let n=[],r=t.toLowerCase();for(let[i,a]of Object.entries(e)){if(!i.toLowerCase().startsWith(r))continue;let e=i.slice(t.length);/^\d+$/.test(e)&&n.push([Number(e),a])}return n.sort(([e],[t])=>e-t),n}function It(e,t,n){let r=$(e,t);if(r.length===0)return e;let i=X(r.map(([,e])=>e),n),a={};for(let[e,[n]]of r.entries())a[`${t}${n}`]=i[e]??r[e][1];return a}function Lt(e,t,n){let r=t[n];return e.find(([,e])=>e===r)?.[0]??e[n]?.[0]??n+1}function Rt(e,t,n,r){let i=$(e,n);if(i.length===0)return{};let a=X(i.map(([,e])=>e),r),o={};for(let[e,[r]]of i.entries()){let s=t[`${n}${Lt(i,a,e)}`];s&&(o[`${n}${r}`]=H(s))}return o}function zt(e,t,n,r){let i=$(e,n);if(i.length<2)return;let a=X(i.map(([,e])=>e),r),o=[];for(let[e]of i.entries()){let r=t[`${n}${Lt(i,a,e)}`];if(!r)return;o.push(H(r))}let s=[...o],c=s.at(-1);if(c!=null){for(;s.length<12;)s.push(c);return`[${s.join(`,`)}]`}}function Bt(e,t){return $(e,t).length>=2}function Vt(e){if(e.length>=12)return e.slice(0,12);let t=[...e],n=t.at(-1);if(n==null)return t;for(;t.length<12;)t.push(n);return t}function Ht(e,t,n){let r=$(e,t);if(!(r.length<2))return Vt(X(r.map(([,e])=>e),n))}function Ut(e){let t=new Map;for(let n of e){let e=n.childTheme?.trim();if(!e)continue;let r=e.toLowerCase();et(r)||tt(r)||t.has(r)||t.set(r,C([e]))}return[...t.values()].toSorted((e,t)=>e.localeCompare(t))}function Wt(e,t){let n=t.toLowerCase(),r=e.split(/(?=[A-Z])/).filter(Boolean).filter(e=>e.toLowerCase()!==n);if(r.length!==0)return C(r)}function Gt(e){return e.toLowerCase()===`base`}function Kt(e){let t=e.split(/(?=[A-Z])/).filter(Boolean),n=t.at(-1)?.toLowerCase();if((n===`primary`||n===`secondary`||n===`tertiary`)&&!(t.length<2))return{role:C(t.slice(0,-1)),rank:n}}function qt(e){return e.category===`color`&&!e.primitive&&!!e.tokenKey}function Jt(e,t,n){let r=new Map,i={};for(let a of e){if(!qt(a)||!a.tokenKey)continue;let e=a.childTheme?.toLowerCase();if(e&&e!==`base`)continue;let o=ft(a,t,n);if(!o)continue;let s=Kt(a.tokenKey);if(s){let e=r.get(s.role)??{};e[s.rank]=o,r.set(s.role,e);continue}if(e===`base`){let e=Wt(a.tokenKey,`base`);e&&(i[e]=o)}}let a={...i};for(let[e,t]of r){t.primary&&(a[e]=t.primary);let n=t.secondary??t.tertiary;n&&(a[`${e}Subtle`]=n)}return a}function Yt(e,t){let n=W(e),r={};for(let i of Ut(e)){if(Gt(i)){let a=Jt(e,n,t);Object.keys(a).length>0&&(r[i]=a);continue}let a={},o=i.toLowerCase();for(let r of e){if(!qt(r)||r.childTheme?.toLowerCase()!==o)continue;let e=Wt(r.tokenKey,i);if(!e)continue;let s=ft(r,n,t);s&&(a[e]=s)}Object.keys(a).length>0&&(r[i]=a)}return r}function Xt(e,t){let n=new Map(Object.entries(e).map(([e,t])=>[e.toLowerCase(),{name:e,scale:t}]));for(let e of Qe){let r=n.get(e);if(!r)continue;let i=Ht(r.scale,r.name,t);if(i)return{name:r.name,palette:i}}}function Zt(e){let t=e.filter(e=>e.category===`color`||e.primitive),n=Y(B(t,`light`)),r=Y(B(t,`dark`)),i=Xt(n,`light`),a=Xt(r,`dark`);return{lightPalette:i?.palette,darkPalette:a?.palette,lightBaseName:i?.name,darkBaseName:a?.name}}function Qt(e,t,n){let r=Y(e),{byPath:i,byCssVar:o}=W(e),s={};for(let c of e){if(c.category!==`color`||!c.tokenKey||c.primitive||/^[A-Z]+\d{1,3}$/i.test(c.tokenKey)&&r[c.tokenKey.replace(/\d{1,3}$/,``)])continue;let e=q(c,i,o),l=Ot(e,t,r,n);if(l){s[c.tokenKey]=wt(l);continue}let u=e.tamaguiValue;xt(u)||xt(e.cssValue)||(typeof u==`string`||typeof u==`number`)&&(s[c.tokenKey]=a(u))}return s}function $t(e){return e.replaceAll(`\\`,`\\\\`).replaceAll("`","\\`").replaceAll("${","\\${")}function en(e,t,n,r,i){let a=q(e,t.byPath,t.byCssVar),o=Ot(a,n,r,i);if(o)return{kind:`theme`,property:o};let s=K(a,t);if(s)return{kind:`text`,value:s}}function tn(e,t,n,r,i){let a=[],o=/\{([^{}]+)\}|var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g,s=0;for(let c of e.matchAll(o)){let o=c.index??0;o>s&&a.push({kind:`text`,value:e.slice(s,o)});let l=c[1]?t.byPath.get(c[1].trim()):c[2]?t.byCssVar.get(c[2]):void 0;if(!l)return;let u=en(l,t,n,r,i);if(!u)return;a.push(u),s=o+c[0].length}return s<e.length&&a.push({kind:`text`,value:e.slice(s)}),a}function nn(e){return e.some(e=>e.kind===`theme`)?`\`${e.map(e=>e.kind===`theme`?`\${${wt(e.property)}}`:$t(e.value)).join(``)}\``:a(e.map(e=>e.kind===`text`?e.value:``).join(``))}function rn(e,t,n){let r=W(e),i=Y(e.filter(e=>e.category===`color`)),a={};for(let o of e){if(!nt(o)||!o.tokenKey)continue;let e=typeof o.tamaguiValue==`string`?o.tamaguiValue:o.cssValue;if(typeof e!=`string`||e.length===0)continue;let s=tn(e,r,t,i,n);s&&(a[o.tokenKey]=nn(s))}return a}function an(e,t,n,r,i){let a=new Set([...Object.keys(e),...Object.keys(t)]);if(a.size===0)return;let o=[];for(let s of[...a].toSorted((e,t)=>e.localeCompare(t))){let a=e[s]??t[s]??{},c=t[s]??e[s]??{};if(Object.keys(a).length===0||Object.keys(c).length===0)continue;let l=Bt(a,s)||Bt(c,s),u,d;if(i&&l?(u=Rt(a,n[s]??r[s]??{},s,`light`),d=Rt(c,r[s]??n[s]??{},s,`dark`)):l?(u=It(a,s,`light`),d=It(c,s,`dark`)):(u=a,d=c),Object.keys(u).length===0||Object.keys(d).length===0)continue;let f=l&&!i?(e,t)=>pt(e,t):mt;o.push(` ${s}: {
|
|
55
55
|
light: ${f(u,8)},
|
|
56
56
|
dark: ${f(d,8)}
|
|
57
57
|
}`)}if(o.length!==0)return`{\n${o.join(`,
|
|
58
|
-
`)}\n }`}function on(e){let t=new Set;for(let n of e)for(let e of Object.values(n)){for(let n of e.matchAll(/theme\.([A-Z_$][\w$]*)/gi))n[1]&&t.add(n[1]);for(let n of e.matchAll(/theme\[(['"])(.+?)\1\]/g))t.add(n[2])}return[...t]}function sn(e,t){let n=new Set;for(let r of[e,t])for(let e of Object.values(r))for(let t of Object.keys(e))n.add(t);return[...n]}function cn(e,t){let n=Math.max(e?.length??0,t?.length??0);if(n===0)return[];let r=[];for(let e=1;e<=Math.min(n,12);e++)r.push(`
|
|
58
|
+
`)}\n }`}function on(e){let t=new Set;for(let n of e)for(let e of Object.values(n)){for(let n of e.matchAll(/theme\.([A-Z_$][\w$]*)/gi))n[1]&&t.add(n[1]);for(let n of e.matchAll(/theme\[(['"])(.+?)\1\]/g))t.add(n[2])}return[...t]}function sn(e,t){let n=new Set;for(let r of[e,t])for(let e of Object.values(r))for(let t of Object.keys(e))n.add(t);return[...n]}function cn(e,t){let n=Math.max(e?.length??0,t?.length??0);if(n===0)return[];let r=[];for(let e=1;e<=Math.min(n,12);e++)r.push(`base${e}`);return r}function ln(e){let t=new Set;for(let n of Object.keys(e.lightSemantic))t.add(n);for(let n of Object.keys(e.darkSemantic))t.add(n);for(let n of on([e.lightSemantic,e.darkSemantic]))t.add(n);for(let n of sn(e.lightScales,e.darkScales))t.add(n);for(let n of cn(e.lightPalette,e.darkPalette))t.add(n);return[...t].toSorted((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))}function un(e){return` ${/^[A-Z_$][\w$]*$/i.test(e)?e:a(e)}: string;`}function dn(e,t){if(e.length!==0)return[`/**`,` * Theme values available on \`useTheme()\` and \`$\` style props for the ${t.specName||`design system`}.`,` *`," * Derived from design tokens mapped by `createV5Theme` and `getTheme`.",` *`,` * @see https://tamagui.dev/docs/guides/theme-builder#gettheme`,` */`,`export interface AppTheme {`,...e.map(un),`}`,``]}function fn(e,t,n={}){let r=e.fonts??{},i=n.useDefaultConfig===!0,o=n.animations??`css`,s=n.includeTypeAugmentation!==!1,c=t.filter(e=>e.category===`color`),l=B(c,`light`),u=B(c,`dark`),d=u.length>0?u:l,f=ut(l,u),p=Object.keys(f).length>0,m=dt(l),h=dt(d),g=Y(l),_=Y(d),ee={...g,...Yt(l,f)},te={..._,...Yt(d,f)},{lightPalette:v,darkPalette:ne,lightBaseName:y,darkBaseName:b}=Zt(t),re=an(ee,te,m,h,p),ie=p&&y?zt(g[y]??{},m[y]??{},y,`light`):void 0,x=p&&b?zt(_[b]??{},h[b]??{},b,`dark`):void 0,S=B(t,`light`),ae=B(t,`dark`),C=u.length>0?ae:S,oe=u.length>0?b:y,w={...Qt(l,y,`light`),...rn(S,y,`light`)},T={...Qt(u.length>0?u:l,oe,`dark`),...rn(C,oe,`dark`)},se=dn(ln({lightSemantic:w,darkSemantic:T,lightScales:ee,darkScales:te,lightPalette:v,darkPalette:ne}),{specName:e.name}),ce=lt(S),E=[];Object.keys(f).length>0&&E.push(` color: ${pt(f,4)}`);for(let e of it){let t=ce[e];t&&Object.keys(t).length>0&&E.push(` ${e}: ${pt(t,4)}`)}let D=[];ie?D.push(` lightPalette: ${ie}`):v&&D.push(` lightPalette: ${a(v)}`),x?D.push(` darkPalette: ${x}`):ne&&D.push(` darkPalette: ${a(ne)}`),re&&D.push(` childrenThemes: ${re}`),(Object.keys(w).length>0||Object.keys(T).length>0)&&D.push(` getTheme: ({ theme, scheme }: { theme: AppTheme; scheme: "light" | "dark" }) => {
|
|
59
59
|
return scheme === "dark"
|
|
60
60
|
? ${ht(T,8)}
|
|
61
61
|
: ${ht(w,8)};
|
package/dist/index.mjs
CHANGED
|
@@ -51,11 +51,11 @@ Re-run Razorwind generate when tokens change so \`${e.outputPath}\` stays aligne
|
|
|
51
51
|
`}const at=new Set([`default`,`light`,`theme`]),ot=/^base(?:[A-Z]\w*|[._-].+)?$/i,st=/^ring(?:\.|$)/i,ct=[`base`,`gray`,`grey`,`neutral`],lt={css:`@tamagui/config/v5-css`,rn:`@tamagui/config/v5-rn`,reanimated:`@tamagui/config/v5-reanimated`,motion:`@tamagui/config/v5-motion`};function ut(e){return at.has(e)}function dt(e){return e===`dark`}function z(e,t){let n=new Map,r=t===`dark`?dt:ut;for(let t of e){let e=t.theme?.toLowerCase();(!e||ot.test(e))&&n.set(t.path,t)}for(let t of e){let e=t.theme?.toLowerCase();e&&r(e)&&n.set(t.path,t)}return[...n.values()]}function ft(e){return st.test(e.path)&&e.category===`shadow`}const pt=new Set([`fontSize`,`blur`]),mt=[`space`,`size`,`radius`,`zIndex`,`blur`,`fontSize`,`shadow`,`insetShadow`,`dropShadow`,`textShadow`,`boxShadow`,`fontWeight`];function ht(e){return/^px\(-?\d/.test(e)}function gt(e){if(e.category===`radius`&&e.tokenKey?.startsWith(`borderRadius`)){let t=e.tokenKey.replace(/^borderRadius/,``);return t?D([t]):e.tokenKey}return e.tokenKey??``}function _t(e,t){let n=q(e,t.byPath,t.byCssVar).tamaguiValue;if(e.category&&pt.has(e.category)&&typeof n==`number`)return`px(${n})`;if(typeof n==`string`){let r=Mt(n,t);return e.category===`dropShadow`?vt(r):r}return n}function vt(e){return e.includes(`drop-shadow(`)?e:e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.replace(/^inset\s+/i,``).split(/\s+/);if(t.length>=5){let[e,n,r]=t;return`drop-shadow(${e} ${n} ${r} ${t.slice(4).join(` `)})`}return`drop-shadow(${e.replace(/^inset\s+/i,``)})`}).join(` `)}function yt(e){let t={},n=W(e);for(let r of e){if(!r.category||r.category===`color`||!r.tokenKey||ft(r))continue;let e=gt(r);if(!e)continue;let i=_t(r,n);if(typeof i==`string`&&jt(i))continue;let a=t[r.category]??{};a[e]=i,t[r.category]=a}return t}function B(e){let t=e.tokenKey??e.path.replace(/^color\./i,``).replaceAll(`.`,``);return e.theme?`${e.theme}${t[0]?.toUpperCase()??``}${t.slice(1)}`:t}function V(e){return`tokens.color.${e}.val`}function bt(e,t){let n={},r=W(e),i=W(t),a=(e,t)=>{if(!e.tokenKey)return;let r=K(e,t);typeof r==`string`&&r.length!==0&&r!==`[object Object]`&&(n[B(e)]=r)};for(let t of e)a(t,r);for(let e of t)a(e,i);return n}function xt(e){let t={};for(let n of e){if(!n.primitive)continue;let e=J(n);if(!e)continue;let r=B(n);if(!r)continue;let i=t[e.name]??{};i[`${e.name}${e.step}`]=r,t[e.name]=i}let n=Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=2));if(Object.keys(n).length>0)return n;let r={};for(let t of e){let e=J(t);if(!e)continue;let n=t.tokenKey??B(t);if(!n)continue;let i=r[e.name]??{};i[`${e.name}${e.step}`]=n,r[e.name]=i}return Object.fromEntries(Object.entries(r).filter(([,e])=>Object.keys(e).length>=3))}function H(e,t,n,r){let i=n[r];if(typeof i!=`string`)return!1;let a=K(e,t);return a!=null&&a===i}function St(e,t,n){let r=B(e);if(H(e,t,n,r))return V(r);if(e.tokenKey&&e.tokenKey!==r&&H(e,t,n,e.tokenKey))return V(e.tokenKey);let i=q(e,t.byPath,t.byCssVar),a=B(i);if(a!==r&&H(e,t,n,a))return V(a);if(i.tokenKey&&i.tokenKey!==a&&H(e,t,n,i.tokenKey))return V(i.tokenKey);if(i.primitive){let r=B(i);if(H(e,t,n,r))return V(r)}let o=K(e,t);if(o)return m(o)}function U(e,t=2){let n=` `.repeat(t),r=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t,void 0,{numeric:!0}));return r.length===0?`{}`:`{\n${r.map(([e,t])=>{let r=typeof t==`string`&&ht(t)?t:m(t);return`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:m(e)}: ${r}`}).join(`,
|
|
52
52
|
`)}\n${` `.repeat(Math.max(t-2,0))}}`}function Ct(e,t=2){let n=` `.repeat(t),r=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t,void 0,{numeric:!0}));return r.length===0?`{}`:`{\n${r.map(([e,t])=>`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:m(e)}: ${t}`).join(`,
|
|
53
53
|
`)}\n${` `.repeat(Math.max(t-2,0))}}`}function wt(e,t=2){let n=` `.repeat(t),r=` `.repeat(Math.max(t-2,0)),i=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t,void 0,{numeric:!0}));return i.length===0?`{\n${n}...theme\n${r}}`:`{\n${n}...theme,\n${i.map(([e,t])=>`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:m(e)}: ${t}`).join(`,
|
|
54
|
-
`)}\n${r}}`}const Tt=/^\{([^{}]+)\}$/,Et=/\{([^{}]+)\}/g,Dt=/^var\((--[^),\s]+)(?:\s*,[^)]*)?\)$/,Ot=/var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g;function W(e){return{byPath:new Map(e.map(e=>[e.path,e])),byCssVar:new Map(e.map(e=>[s(e.path),e]))}}function kt(e){if(typeof e==`string`)return Tt.exec(e.trim())?.[1]?.trim()}function G(e){if(typeof e==`string`)return Dt.exec(e.trim())?.[1]}function At(e){return kt(e)!=null||G(e)!=null}function jt(e){return/var\(|\{[^{}]+\}/.test(e)}function K(e,t){let n=q(e,t.byPath,t.byCssVar);if(n.category!=null&&n.category!==`color`)return;let r=[n.cssValue,n.tamaguiValue];for(let e of r)if(typeof e==`string`&&e.length>0&&!At(e))return e}function Mt(e,t){return e.replace(Et,(e,n)=>{let r=t.byPath.get(n.trim());return r?K(r,t)??e:e}).replace(Ot,(e,n)=>{let r=t.byCssVar.get(n);return r?K(r,t)??e:e})}function q(e,t,n){let r=e,i=new Set;for(let e=0;e<8;e++){if(i.has(r.path))return r;i.add(r.path);let e=kt(r.value);if(e){let n=t.get(e);if(!n||n.path===r.path)return r;r=n;continue}let a=G(r.value)??G(r.cssValue)??G(r.tamaguiValue);if(a){let e=n.get(a);if(!e||e.path===r.path)return r;r=e;continue}return r}return r}function Nt(e){return/^[A-Z_$][\w$]*$/i.test(e)?`theme.${e}`:`theme[${m(e)}]`}function Pt(e,t){return t<1?e:t+1-e}function Ft(e,t){return e.length<2?!1:X(e,t).some((t,n)=>t!==e[n])}function It(e,t,n,r){let i=n[t];if(!i||r!==`dark`)return e;let a=$(i,t);return a.length<2||!Ft(a.map(([,e])=>e),r)?e:Pt(e,a[a.length-1][0])}function Lt(e,t,n,r){let i=J(e);if(!i)return;let a=It(i.step,i.name,n,r);if(t&&i.name.toLowerCase()===t.toLowerCase()||n[i.name])return`${i.name}${a}`}function Rt(e){if(e>=1&&e<=12)return e;if(e>=100&&e<=900&&e%100==0)return e/100}function J(e){let t=e.path.split(`.`).filter(Boolean),n=t.at(-1);if(n&&/^\d+$/.test(n)){let e=Rt(Number(n)),r=t.at(-2);if(e!=null&&r&&!/^(?:color|colours?|palette)$/i.test(r))return{name:D([r]),step:e}}if(!e.tokenKey)return;let r=/^([A-Z]+)(\d{1,3})$/i.exec(e.tokenKey);if(!r)return;let[,i=``,a=``]=r,o=Rt(Number(a));if(o!=null)return{name:i,step:o}}function zt(e,t,n,r){let i=e[t]??{};i[`${t}${n}`]=r,e[t]=i}function Bt(e){let t={};for(let n of e){if(typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&zt(t,e.name,e.step,n.tamaguiValue)}return Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=3))}function Y(e){let t={};for(let n of e){if(!n.primitive||typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&zt(t,e.name,e.step,n.tamaguiValue)}let n=Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=2));return Object.keys(n).length>0?n:Bt(e)}function X(e,t){if(e.length<2)return[...e];let n=Wt(e[0]),r=Wt(e[e.length-1]);if(n==null||r==null||n===r)return[...e];let i=n>r;return t===`light`?i?[...e]:e.toReversed():i?e.toReversed():[...e]}function Z(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function Vt(e){let t=e.startsWith(`#`)?e.slice(1):``;if((t.length===3||t.length===4)&&(t=[...t].map(e=>e+e).join(``)),t.length===8&&(t=t.slice(0,6)),t.length!==6||/[^0-9a-f]/i.test(t))return;let n=Number.parseInt(t.slice(0,2),16)/255,r=Number.parseInt(t.slice(2,4),16)/255,i=Number.parseInt(t.slice(4,6),16)/255;return .2126*Z(n)+.7152*Z(r)+.0722*Z(i)}function Q(e){let t=e.trim();if(t.endsWith(`%`)){let e=Number.parseFloat(t);return Number.isFinite(e)?e/100:void 0}let n=Number.parseFloat(t);return Number.isFinite(n)?n:void 0}function Ht(e){return e>1?e/100:e}function Ut(e,t){let n=RegExp(`^${t}\\((.+)\\)$`,`i`).exec(e.trim());if(n?.[1])return n[1].split(/[\s,/]+/).filter(Boolean)}function Wt(e){let t=e.trim();if(!t||t.startsWith(`var(`)||t.includes(`{`))return;let n=Vt(t);if(n!=null)return n;let r=Ut(t,`oklch`);if(r?.[0]){let e=Q(r[0]);return e==null?void 0:Ht(e)}let i=Ut(t,`hsla?`);if(i?.[2]){let e=Q(i[2]);return e==null?void 0:Ht(e)}let a=Ut(t,`rgba?`);if(a?.[0]&&a[1]&&a[2]){let e=Q(a[0]),t=Q(a[1]),n=Q(a[2]);if(e==null||t==null||n==null)return;let r=(e,t)=>t.trim().endsWith(`%`)||e<=1?e:e/255;return .2126*Z(r(e,a[0]))+.7152*Z(r(t,a[1]))+.0722*Z(r(n,a[2]))}}function $(e,t){let n=[],r=t.toLowerCase();for(let[i,a]of Object.entries(e)){if(!i.toLowerCase().startsWith(r))continue;let e=i.slice(t.length);/^\d+$/.test(e)&&n.push([Number(e),a])}return n.sort(([e],[t])=>e-t),n}function Gt(e,t,n){let r=$(e,t);if(r.length===0)return e;let i=X(r.map(([,e])=>e),n),a={};for(let[e,[
|
|
54
|
+
`)}\n${r}}`}const Tt=/^\{([^{}]+)\}$/,Et=/\{([^{}]+)\}/g,Dt=/^var\((--[^),\s]+)(?:\s*,[^)]*)?\)$/,Ot=/var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g;function W(e){return{byPath:new Map(e.map(e=>[e.path,e])),byCssVar:new Map(e.map(e=>[s(e.path),e]))}}function kt(e){if(typeof e==`string`)return Tt.exec(e.trim())?.[1]?.trim()}function G(e){if(typeof e==`string`)return Dt.exec(e.trim())?.[1]}function At(e){return kt(e)!=null||G(e)!=null}function jt(e){return/var\(|\{[^{}]+\}/.test(e)}function K(e,t){let n=q(e,t.byPath,t.byCssVar);if(n.category!=null&&n.category!==`color`)return;let r=[n.cssValue,n.tamaguiValue];for(let e of r)if(typeof e==`string`&&e.length>0&&!At(e))return e}function Mt(e,t){return e.replace(Et,(e,n)=>{let r=t.byPath.get(n.trim());return r?K(r,t)??e:e}).replace(Ot,(e,n)=>{let r=t.byCssVar.get(n);return r?K(r,t)??e:e})}function q(e,t,n){let r=e,i=new Set;for(let e=0;e<8;e++){if(i.has(r.path))return r;i.add(r.path);let e=kt(r.value);if(e){let n=t.get(e);if(!n||n.path===r.path)return r;r=n;continue}let a=G(r.value)??G(r.cssValue)??G(r.tamaguiValue);if(a){let e=n.get(a);if(!e||e.path===r.path)return r;r=e;continue}return r}return r}function Nt(e){return/^[A-Z_$][\w$]*$/i.test(e)?`theme.${e}`:`theme[${m(e)}]`}function Pt(e,t){return t<1?e:t+1-e}function Ft(e,t){return e.length<2?!1:X(e,t).some((t,n)=>t!==e[n])}function It(e,t,n,r){let i=n[t];if(!i||r!==`dark`)return e;let a=$(i,t);return a.length<2||!Ft(a.map(([,e])=>e),r)?e:Pt(e,a[a.length-1][0])}function Lt(e,t,n,r){let i=J(e);if(!i)return;let a=It(i.step,i.name,n,r);if(t&&i.name.toLowerCase()===t.toLowerCase()||n[i.name])return`${i.name}${a}`}function Rt(e){if(e>=1&&e<=12)return e;if(e>=100&&e<=900&&e%100==0)return e/100}function J(e){let t=e.path.split(`.`).filter(Boolean),n=t.at(-1);if(n&&/^\d+$/.test(n)){let e=Rt(Number(n)),r=t.at(-2);if(e!=null&&r&&!/^(?:color|colours?|palette)$/i.test(r))return{name:D([r]),step:e}}if(!e.tokenKey)return;let r=/^([A-Z]+)(\d{1,3})$/i.exec(e.tokenKey);if(!r)return;let[,i=``,a=``]=r,o=Rt(Number(a));if(o!=null)return{name:i,step:o}}function zt(e,t,n,r){let i=e[t]??{};i[`${t}${n}`]=r,e[t]=i}function Bt(e){let t={};for(let n of e){if(typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&zt(t,e.name,e.step,n.tamaguiValue)}return Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=3))}function Y(e){let t={};for(let n of e){if(!n.primitive||typeof n.tamaguiValue!=`string`)continue;let e=J(n);e&&zt(t,e.name,e.step,n.tamaguiValue)}let n=Object.fromEntries(Object.entries(t).filter(([,e])=>Object.keys(e).length>=2));return Object.keys(n).length>0?n:Bt(e)}function X(e,t){if(e.length<2)return[...e];let n=Wt(e[0]),r=Wt(e[e.length-1]);if(n==null||r==null||n===r)return[...e];let i=n>r;return t===`light`?i?[...e]:e.toReversed():i?e.toReversed():[...e]}function Z(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function Vt(e){let t=e.startsWith(`#`)?e.slice(1):``;if((t.length===3||t.length===4)&&(t=[...t].map(e=>e+e).join(``)),t.length===8&&(t=t.slice(0,6)),t.length!==6||/[^0-9a-f]/i.test(t))return;let n=Number.parseInt(t.slice(0,2),16)/255,r=Number.parseInt(t.slice(2,4),16)/255,i=Number.parseInt(t.slice(4,6),16)/255;return .2126*Z(n)+.7152*Z(r)+.0722*Z(i)}function Q(e){let t=e.trim();if(t.endsWith(`%`)){let e=Number.parseFloat(t);return Number.isFinite(e)?e/100:void 0}let n=Number.parseFloat(t);return Number.isFinite(n)?n:void 0}function Ht(e){return e>1?e/100:e}function Ut(e,t){let n=RegExp(`^${t}\\((.+)\\)$`,`i`).exec(e.trim());if(n?.[1])return n[1].split(/[\s,/]+/).filter(Boolean)}function Wt(e){let t=e.trim();if(!t||t.startsWith(`var(`)||t.includes(`{`))return;let n=Vt(t);if(n!=null)return n;let r=Ut(t,`oklch`);if(r?.[0]){let e=Q(r[0]);return e==null?void 0:Ht(e)}let i=Ut(t,`hsla?`);if(i?.[2]){let e=Q(i[2]);return e==null?void 0:Ht(e)}let a=Ut(t,`rgba?`);if(a?.[0]&&a[1]&&a[2]){let e=Q(a[0]),t=Q(a[1]),n=Q(a[2]);if(e==null||t==null||n==null)return;let r=(e,t)=>t.trim().endsWith(`%`)||e<=1?e:e/255;return .2126*Z(r(e,a[0]))+.7152*Z(r(t,a[1]))+.0722*Z(r(n,a[2]))}}function $(e,t){let n=[],r=t.toLowerCase();for(let[i,a]of Object.entries(e)){if(!i.toLowerCase().startsWith(r))continue;let e=i.slice(t.length);/^\d+$/.test(e)&&n.push([Number(e),a])}return n.sort(([e],[t])=>e-t),n}function Gt(e,t,n){let r=$(e,t);if(r.length===0)return e;let i=X(r.map(([,e])=>e),n),a={};for(let[e,[n]]of r.entries())a[`${t}${n}`]=i[e]??r[e][1];return a}function Kt(e,t,n){let r=t[n];return e.find(([,e])=>e===r)?.[0]??e[n]?.[0]??n+1}function qt(e,t,n,r){let i=$(e,n);if(i.length===0)return{};let a=X(i.map(([,e])=>e),r),o={};for(let[e,[r]]of i.entries()){let s=t[`${n}${Kt(i,a,e)}`];s&&(o[`${n}${r}`]=V(s))}return o}function Jt(e,t,n,r){let i=$(e,n);if(i.length<2)return;let a=X(i.map(([,e])=>e),r),o=[];for(let[e]of i.entries()){let r=t[`${n}${Kt(i,a,e)}`];if(!r)return;o.push(V(r))}let s=[...o],c=s.at(-1);if(c!=null){for(;s.length<12;)s.push(c);return`[${s.join(`,`)}]`}}function Yt(e,t){return $(e,t).length>=2}function Xt(e){if(e.length>=12)return e.slice(0,12);let t=[...e],n=t.at(-1);if(n==null)return t;for(;t.length<12;)t.push(n);return t}function Zt(e,t,n){let r=$(e,t);if(!(r.length<2))return Xt(X(r.map(([,e])=>e),n))}function Qt(e){let t=new Map;for(let n of e){let e=n.childTheme?.trim();if(!e)continue;let r=e.toLowerCase();ut(r)||dt(r)||t.has(r)||t.set(r,D([e]))}return[...t.values()].toSorted((e,t)=>e.localeCompare(t))}function $t(e,t){let n=t.toLowerCase(),r=e.split(/(?=[A-Z])/).filter(Boolean).filter(e=>e.toLowerCase()!==n);if(r.length!==0)return D(r)}function en(e){return e.toLowerCase()===`base`}function tn(e){let t=e.split(/(?=[A-Z])/).filter(Boolean),n=t.at(-1)?.toLowerCase();if((n===`primary`||n===`secondary`||n===`tertiary`)&&!(t.length<2))return{role:D(t.slice(0,-1)),rank:n}}function nn(e){return e.category===`color`&&!e.primitive&&!!e.tokenKey}function rn(e,t,n){let r=new Map,i={};for(let a of e){if(!nn(a)||!a.tokenKey)continue;let e=a.childTheme?.toLowerCase();if(e&&e!==`base`)continue;let o=St(a,t,n);if(!o)continue;let s=tn(a.tokenKey);if(s){let e=r.get(s.role)??{};e[s.rank]=o,r.set(s.role,e);continue}if(e===`base`){let e=$t(a.tokenKey,`base`);e&&(i[e]=o)}}let a={...i};for(let[e,t]of r){t.primary&&(a[e]=t.primary);let n=t.secondary??t.tertiary;n&&(a[`${e}Subtle`]=n)}return a}function an(e,t){let n=W(e),r={};for(let i of Qt(e)){if(en(i)){let a=rn(e,n,t);Object.keys(a).length>0&&(r[i]=a);continue}let a={},o=i.toLowerCase();for(let r of e){if(!nn(r)||r.childTheme?.toLowerCase()!==o)continue;let e=$t(r.tokenKey,i);if(!e)continue;let s=St(r,n,t);s&&(a[e]=s)}Object.keys(a).length>0&&(r[i]=a)}return r}function on(e,t){let n=new Map(Object.entries(e).map(([e,t])=>[e.toLowerCase(),{name:e,scale:t}]));for(let e of ct){let r=n.get(e);if(!r)continue;let i=Zt(r.scale,r.name,t);if(i)return{name:r.name,palette:i}}}function sn(e){let t=e.filter(e=>e.category===`color`||e.primitive),n=Y(z(t,`light`)),r=Y(z(t,`dark`)),i=on(n,`light`),a=on(r,`dark`);return{lightPalette:i?.palette,darkPalette:a?.palette,lightBaseName:i?.name,darkBaseName:a?.name}}function cn(e,t,n){let r=Y(e),{byPath:i,byCssVar:a}=W(e),o={};for(let s of e){if(s.category!==`color`||!s.tokenKey||s.primitive||/^[A-Z]+\d{1,3}$/i.test(s.tokenKey)&&r[s.tokenKey.replace(/\d{1,3}$/,``)])continue;let e=q(s,i,a),c=Lt(e,t,r,n);if(c){o[s.tokenKey]=Nt(c);continue}let l=e.tamaguiValue;At(l)||At(e.cssValue)||(typeof l==`string`||typeof l==`number`)&&(o[s.tokenKey]=m(l))}return o}function ln(e){return e.replaceAll(`\\`,`\\\\`).replaceAll("`","\\`").replaceAll("${","\\${")}function un(e,t,n,r,i){let a=q(e,t.byPath,t.byCssVar),o=Lt(a,n,r,i);if(o)return{kind:`theme`,property:o};let s=K(a,t);if(s)return{kind:`text`,value:s}}function dn(e,t,n,r,i){let a=[],o=/\{([^{}]+)\}|var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g,s=0;for(let c of e.matchAll(o)){let o=c.index??0;o>s&&a.push({kind:`text`,value:e.slice(s,o)});let l=c[1]?t.byPath.get(c[1].trim()):c[2]?t.byCssVar.get(c[2]):void 0;if(!l)return;let u=un(l,t,n,r,i);if(!u)return;a.push(u),s=o+c[0].length}return s<e.length&&a.push({kind:`text`,value:e.slice(s)}),a}function fn(e){return e.some(e=>e.kind===`theme`)?`\`${e.map(e=>e.kind===`theme`?`\${${Nt(e.property)}}`:ln(e.value)).join(``)}\``:m(e.map(e=>e.kind===`text`?e.value:``).join(``))}function pn(e,t,n){let r=W(e),i=Y(e.filter(e=>e.category===`color`)),a={};for(let o of e){if(!ft(o)||!o.tokenKey)continue;let e=typeof o.tamaguiValue==`string`?o.tamaguiValue:o.cssValue;if(typeof e!=`string`||e.length===0)continue;let s=dn(e,r,t,i,n);s&&(a[o.tokenKey]=fn(s))}return a}function mn(e,t,n,r,i){let a=new Set([...Object.keys(e),...Object.keys(t)]);if(a.size===0)return;let o=[];for(let s of[...a].toSorted((e,t)=>e.localeCompare(t))){let a=e[s]??t[s]??{},c=t[s]??e[s]??{};if(Object.keys(a).length===0||Object.keys(c).length===0)continue;let l=Yt(a,s)||Yt(c,s),u,d;if(i&&l?(u=qt(a,n[s]??r[s]??{},s,`light`),d=qt(c,r[s]??n[s]??{},s,`dark`)):l?(u=Gt(a,s,`light`),d=Gt(c,s,`dark`)):(u=a,d=c),Object.keys(u).length===0||Object.keys(d).length===0)continue;let f=l&&!i?(e,t)=>U(e,t):Ct;o.push(` ${s}: {
|
|
55
55
|
light: ${f(u,8)},
|
|
56
56
|
dark: ${f(d,8)}
|
|
57
57
|
}`)}if(o.length!==0)return`{\n${o.join(`,
|
|
58
|
-
`)}\n }`}function hn(e){let t=new Set;for(let n of e)for(let e of Object.values(n)){for(let n of e.matchAll(/theme\.([A-Z_$][\w$]*)/gi))n[1]&&t.add(n[1]);for(let n of e.matchAll(/theme\[(['"])(.+?)\1\]/g))t.add(n[2])}return[...t]}function gn(e,t){let n=new Set;for(let r of[e,t])for(let e of Object.values(r))for(let t of Object.keys(e))n.add(t);return[...n]}function _n(e,t){let n=Math.max(e?.length??0,t?.length??0);if(n===0)return[];let r=[];for(let e=1;e<=Math.min(n,12);e++)r.push(`
|
|
58
|
+
`)}\n }`}function hn(e){let t=new Set;for(let n of e)for(let e of Object.values(n)){for(let n of e.matchAll(/theme\.([A-Z_$][\w$]*)/gi))n[1]&&t.add(n[1]);for(let n of e.matchAll(/theme\[(['"])(.+?)\1\]/g))t.add(n[2])}return[...t]}function gn(e,t){let n=new Set;for(let r of[e,t])for(let e of Object.values(r))for(let t of Object.keys(e))n.add(t);return[...n]}function _n(e,t){let n=Math.max(e?.length??0,t?.length??0);if(n===0)return[];let r=[];for(let e=1;e<=Math.min(n,12);e++)r.push(`base${e}`);return r}function vn(e){let t=new Set;for(let n of Object.keys(e.lightSemantic))t.add(n);for(let n of Object.keys(e.darkSemantic))t.add(n);for(let n of hn([e.lightSemantic,e.darkSemantic]))t.add(n);for(let n of gn(e.lightScales,e.darkScales))t.add(n);for(let n of _n(e.lightPalette,e.darkPalette))t.add(n);return[...t].toSorted((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))}function yn(e){return` ${/^[A-Z_$][\w$]*$/i.test(e)?e:m(e)}: string;`}function bn(e,t){if(e.length!==0)return[`/**`,` * Theme values available on \`useTheme()\` and \`$\` style props for the ${t.specName||`design system`}.`,` *`," * Derived from design tokens mapped by `createV5Theme` and `getTheme`.",` *`,` * @see https://tamagui.dev/docs/guides/theme-builder#gettheme`,` */`,`export interface AppTheme {`,...e.map(yn),`}`,``]}function xn(e,t,n={}){let r=e.fonts??{},i=n.useDefaultConfig===!0,a=n.animations??`css`,o=n.includeTypeAugmentation!==!1,s=t.filter(e=>e.category===`color`),c=z(s,`light`),l=z(s,`dark`),u=l.length>0?l:c,d=bt(c,l),f=Object.keys(d).length>0,p=xt(c),h=xt(u),g=Y(c),_=Y(u),ee={...g,...an(c,d)},te={..._,...an(u,d)},{lightPalette:v,darkPalette:y,lightBaseName:b,darkBaseName:x}=sn(t),ne=mn(ee,te,p,h,f),re=f&&b?Jt(g[b]??{},p[b]??{},b,`light`):void 0,ie=f&&x?Jt(_[x]??{},h[x]??{},x,`dark`):void 0,S=z(t,`light`),ae=z(t,`dark`),oe=l.length>0?ae:S,se=l.length>0?x:b,C={...cn(c,b,`light`),...pn(S,b,`light`)},ce={...cn(l.length>0?l:c,se,`dark`),...pn(oe,se,`dark`)},le=bn(vn({lightSemantic:C,darkSemantic:ce,lightScales:ee,darkScales:te,lightPalette:v,darkPalette:y}),{specName:e.name}),ue=yt(S),w=[];Object.keys(d).length>0&&w.push(` color: ${U(d,4)}`);for(let e of mt){let t=ue[e];t&&Object.keys(t).length>0&&w.push(` ${e}: ${U(t,4)}`)}let T=[];re?T.push(` lightPalette: ${re}`):v&&T.push(` lightPalette: ${m(v)}`),ie?T.push(` darkPalette: ${ie}`):y&&T.push(` darkPalette: ${m(y)}`),ne&&T.push(` childrenThemes: ${ne}`),(Object.keys(C).length>0||Object.keys(ce).length>0)&&T.push(` getTheme: ({ theme, scheme }: { theme: AppTheme; scheme: "light" | "dark" }) => {
|
|
59
59
|
return scheme === "dark"
|
|
60
60
|
? ${wt(ce,8)}
|
|
61
61
|
: ${wt(C,8)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@razorwind/tamagui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Razorwind plugin that creates Tamagui theme tokens from Razorwind design tokens.",
|
|
6
6
|
"repository": {
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"typescript": "^6.0.3"
|
|
107
107
|
},
|
|
108
108
|
"publishConfig": { "access": "public" },
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "5148c797bd51b06f175b3b3490f2dab971423f61"
|
|
110
110
|
}
|