@razorwind/tamagui 0.0.50 → 0.0.51
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
|
@@ -48,10 +48,10 @@ export function App() {
|
|
|
48
48
|
## Regenerate
|
|
49
49
|
|
|
50
50
|
Re-run Razorwind generate when tokens change so \`${e.outputPath}\` stays aligned with your design system.
|
|
51
|
-
`}const qe=new Set([`default`,`light`,`theme`]),Je=/^base(?:[A-Z]\w*|[._-].+)?$/i,Ye=/^ring(?:\.|$)/i,Xe=[`base`,`gray`,`grey`,`neutral`],Ze={css:`@tamagui/config/v5-css`,rn:`@tamagui/config/v5-rn`,reanimated:`@tamagui/config/v5-reanimated`,motion:`@tamagui/config/v5-motion`};function Qe(e){return qe.has(e)}function $e(e){return e===`dark`}function H(e,t){let n=new Map,r=t===`dark`?$e:Qe;for(let t of e){let e=t.theme?.toLowerCase();(!e||Je.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 et(e){return Ye.test(e.path)&&e.category===`shadow`}const tt=new Set([`fontSize`,`blur`]),nt=[`space`,`size`,`radius`,`zIndex`,`blur`,`fontSize`,`shadow`,`insetShadow`,`dropShadow`,`textShadow`,`boxShadow`,`fontWeight`];function rt(e){return/^px\(-?\d/.test(e)}function it(e){if(e.category===`radius`&&e.tokenKey?.startsWith(`borderRadius`)){let t=e.tokenKey.replace(/^borderRadius/,``);return t?w([t]):e.tokenKey}return e.tokenKey??``}function at(e,t){let n=q(e,t.byPath,t.byCssVar).tamaguiValue;if(e.category&&tt.has(e.category)&&typeof n==`number`)return`px(${n})`;if(typeof n==`string`){let r=Ct(n,t);return e.category===`dropShadow`?ot(r):r}return n}function ot(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 st(e){let t={},n=vt(e);for(let r of e){if(!r.category||r.category===`color`||!r.tokenKey||et(r))continue;let e=it(r);if(!e)continue;let i=at(r,n);if(typeof i==`string`&&St(i))continue;let a=t[r.category]??{};a[e]=i,t[r.category]=a}return t}function U(e){let t=e.path.replace(/^color\./i,``).replaceAll(`.`,``);return e.theme?`${e.theme}${t[0]?.toUpperCase()??``}${t.slice(1)}`:t}function W(e){return`tokens.color.${e}`}function ct(e,t){let n={},r=(e,t)=>{let r=t.cssValue;typeof r!=`string`||r.length===0||xt(r)||r===`[object Object]`||(n[e]=r)};for(let t of e)t.tokenKey&&(t.primitive?r(U(t),t):r(t.tokenKey,t));for(let e of t)!e.tokenKey||!e.primitive||r(U(e),e);return n}function lt(e){let t={};for(let n of e){if(!n.primitive)continue;let e=J(n);if(!e)continue;let r=U(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??U(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 ut(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 dt(e,t,n){if(e.tokenKey&&ut(e,t,n,e.tokenKey))return W(e.tokenKey);let r=q(e,t.byPath,t.byCssVar);if(r.tokenKey&&ut(e,t,n,r.tokenKey))return W(r.tokenKey);if(r.primitive){let i=U(r);if(ut(e,t,n,i))return W(i)}let i=K(e,t);if(i)return a(i)}function G(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`&&rt(t)?t:a(t);return`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:a(e)}: ${r}`}).join(`,
|
|
51
|
+
`}const qe=new Set([`default`,`light`,`theme`]),Je=/^base(?:[A-Z]\w*|[._-].+)?$/i,Ye=/^ring(?:\.|$)/i,Xe=[`base`,`gray`,`grey`,`neutral`],Ze={css:`@tamagui/config/v5-css`,rn:`@tamagui/config/v5-rn`,reanimated:`@tamagui/config/v5-reanimated`,motion:`@tamagui/config/v5-motion`};function Qe(e){return qe.has(e)}function $e(e){return e===`dark`}function H(e,t){let n=new Map,r=t===`dark`?$e:Qe;for(let t of e){let e=t.theme?.toLowerCase();(!e||Je.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 et(e){return Ye.test(e.path)&&e.category===`shadow`}const tt=new Set([`fontSize`,`blur`]),nt=[`space`,`size`,`radius`,`zIndex`,`blur`,`fontSize`,`shadow`,`insetShadow`,`dropShadow`,`textShadow`,`boxShadow`,`fontWeight`];function rt(e){return/^px\(-?\d/.test(e)}function it(e){if(e.category===`radius`&&e.tokenKey?.startsWith(`borderRadius`)){let t=e.tokenKey.replace(/^borderRadius/,``);return t?w([t]):e.tokenKey}return e.tokenKey??``}function at(e,t){let n=q(e,t.byPath,t.byCssVar).tamaguiValue;if(e.category&&tt.has(e.category)&&typeof n==`number`)return`px(${n})`;if(typeof n==`string`){let r=Ct(n,t);return e.category===`dropShadow`?ot(r):r}return n}function ot(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 st(e){let t={},n=vt(e);for(let r of e){if(!r.category||r.category===`color`||!r.tokenKey||et(r))continue;let e=it(r);if(!e)continue;let i=at(r,n);if(typeof i==`string`&&St(i))continue;let a=t[r.category]??{};a[e]=i,t[r.category]=a}return t}function U(e){let t=e.path.replace(/^color\./i,``).replaceAll(`.`,``);return e.theme?`${e.theme}${t[0]?.toUpperCase()??``}${t.slice(1)}`:t}function W(e){return`tokens.color.${e}.val`}function ct(e,t){let n={},r=(e,t)=>{let r=t.cssValue;typeof r!=`string`||r.length===0||xt(r)||r===`[object Object]`||(n[e]=r)};for(let t of e)t.tokenKey&&(t.primitive?r(U(t),t):r(t.tokenKey,t));for(let e of t)!e.tokenKey||!e.primitive||r(U(e),e);return n}function lt(e){let t={};for(let n of e){if(!n.primitive)continue;let e=J(n);if(!e)continue;let r=U(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??U(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 ut(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 dt(e,t,n){if(e.tokenKey&&ut(e,t,n,e.tokenKey))return W(e.tokenKey);let r=q(e,t.byPath,t.byCssVar);if(r.tokenKey&&ut(e,t,n,r.tokenKey))return W(r.tokenKey);if(r.primitive){let i=U(r);if(ut(e,t,n,i))return W(i)}let i=K(e,t);if(i)return a(i)}function G(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`&&rt(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 ft(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 pt(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 mt=/^\{([^{}]+)\}$/,ht=/\{([^{}]+)\}/g,gt=/^var\((--[^),\s]+)(?:\s*,[^)]*)?\)$/,_t=/var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g;function vt(e){return{byPath:new Map(e.map(e=>[e.path,e])),byCssVar:new Map(e.map(e=>[(0,t.toThemeCssVar)(e.path),e]))}}function yt(e){if(typeof e==`string`)return mt.exec(e.trim())?.[1]?.trim()}function bt(e){if(typeof e==`string`)return gt.exec(e.trim())?.[1]}function xt(e){return yt(e)!=null||bt(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(ht,(e,n)=>{let r=t.byPath.get(n.trim());return r?K(r,t)??e:e}).replace(_t,(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=yt(r.value);if(e){let n=t.get(e);if(!n||n.path===r.path)return r;r=n;continue}let a=bt(r.value)??bt(r.cssValue)??bt(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:w([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,[t]]of r.entries())a[`color${t}`]=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[
|
|
54
|
+
`)}\n${r}}`}const mt=/^\{([^{}]+)\}$/,ht=/\{([^{}]+)\}/g,gt=/^var\((--[^),\s]+)(?:\s*,[^)]*)?\)$/,_t=/var\((--[^),\s]+)(?:\s*,[^)]*)?\)/g;function vt(e){return{byPath:new Map(e.map(e=>[e.path,e])),byCssVar:new Map(e.map(e=>[(0,t.toThemeCssVar)(e.path),e]))}}function yt(e){if(typeof e==`string`)return mt.exec(e.trim())?.[1]?.trim()}function bt(e){if(typeof e==`string`)return gt.exec(e.trim())?.[1]}function xt(e){return yt(e)!=null||bt(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(ht,(e,n)=>{let r=t.byPath.get(n.trim());return r?K(r,t)??e:e}).replace(_t,(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=yt(r.value);if(e){let n=t.get(e);if(!n||n.path===r.path)return r;r=n;continue}let a=bt(r.value)??bt(r.cssValue)??bt(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:w([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,[t]]of r.entries())a[`color${t}`]=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[`color${r}`]=W(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(W(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();Qe(r)||$e(r)||t.has(r)||t.set(r,w([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 w(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:w(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=dt(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=vt(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=dt(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 Xe){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(H(t,`light`)),r=Y(H(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}=vt(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=vt(e),i=Y(e.filter(e=>e.category===`color`)),a={};for(let o of e){if(!et(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)=>G(e,t):ft;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(`,
|
package/dist/index.mjs
CHANGED
|
@@ -48,10 +48,10 @@ export function App() {
|
|
|
48
48
|
## Regenerate
|
|
49
49
|
|
|
50
50
|
Re-run Razorwind generate when tokens change so \`${e.outputPath}\` stays aligned with your design system.
|
|
51
|
-
`}const it=new Set([`default`,`light`,`theme`]),at=/^base(?:[A-Z]\w*|[._-].+)?$/i,ot=/^ring(?:\.|$)/i,st=[`base`,`gray`,`grey`,`neutral`],ct={css:`@tamagui/config/v5-css`,rn:`@tamagui/config/v5-rn`,reanimated:`@tamagui/config/v5-reanimated`,motion:`@tamagui/config/v5-motion`};function lt(e){return it.has(e)}function ut(e){return e===`dark`}function B(e,t){let n=new Map,r=t===`dark`?ut:lt;for(let t of e){let e=t.theme?.toLowerCase();(!e||at.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 dt(e){return ot.test(e.path)&&e.category===`shadow`}const ft=new Set([`fontSize`,`blur`]),pt=[`space`,`size`,`radius`,`zIndex`,`blur`,`fontSize`,`shadow`,`insetShadow`,`dropShadow`,`textShadow`,`boxShadow`,`fontWeight`];function mt(e){return/^px\(-?\d/.test(e)}function ht(e){if(e.category===`radius`&&e.tokenKey?.startsWith(`borderRadius`)){let t=e.tokenKey.replace(/^borderRadius/,``);return t?O([t]):e.tokenKey}return e.tokenKey??``}function gt(e,t){let n=q(e,t.byPath,t.byCssVar).tamaguiValue;if(e.category&&ft.has(e.category)&&typeof n==`number`)return`px(${n})`;if(typeof n==`string`){let r=Mt(n,t);return e.category===`dropShadow`?_t(r):r}return n}function _t(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 vt(e){let t={},n=W(e);for(let r of e){if(!r.category||r.category===`color`||!r.tokenKey||dt(r))continue;let e=ht(r);if(!e)continue;let i=gt(r,n);if(typeof i==`string`&&jt(i))continue;let a=t[r.category]??{};a[e]=i,t[r.category]=a}return t}function V(e){let t=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}`}function yt(e,t){let n={},r=(e,t)=>{let r=t.cssValue;typeof r!=`string`||r.length===0||G(r)||r===`[object Object]`||(n[e]=r)};for(let t of e)t.tokenKey&&(t.primitive?r(V(t),t):r(t.tokenKey,t));for(let e of t)!e.tokenKey||!e.primitive||r(V(e),e);return n}function bt(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 xt(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){if(e.tokenKey&&xt(e,t,n,e.tokenKey))return H(e.tokenKey);let r=q(e,t.byPath,t.byCssVar);if(r.tokenKey&&xt(e,t,n,r.tokenKey))return H(r.tokenKey);if(r.primitive){let i=V(r);if(xt(e,t,n,i))return H(i)}let i=K(e,t);if(i)return m(i)}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`&&mt(t)?t:m(t);return`${n}${/^[A-Z_$][\w$]*$/i.test(e)?e:m(e)}: ${r}`}).join(`,
|
|
51
|
+
`}const it=new Set([`default`,`light`,`theme`]),at=/^base(?:[A-Z]\w*|[._-].+)?$/i,ot=/^ring(?:\.|$)/i,st=[`base`,`gray`,`grey`,`neutral`],ct={css:`@tamagui/config/v5-css`,rn:`@tamagui/config/v5-rn`,reanimated:`@tamagui/config/v5-reanimated`,motion:`@tamagui/config/v5-motion`};function lt(e){return it.has(e)}function ut(e){return e===`dark`}function B(e,t){let n=new Map,r=t===`dark`?ut:lt;for(let t of e){let e=t.theme?.toLowerCase();(!e||at.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 dt(e){return ot.test(e.path)&&e.category===`shadow`}const ft=new Set([`fontSize`,`blur`]),pt=[`space`,`size`,`radius`,`zIndex`,`blur`,`fontSize`,`shadow`,`insetShadow`,`dropShadow`,`textShadow`,`boxShadow`,`fontWeight`];function mt(e){return/^px\(-?\d/.test(e)}function ht(e){if(e.category===`radius`&&e.tokenKey?.startsWith(`borderRadius`)){let t=e.tokenKey.replace(/^borderRadius/,``);return t?O([t]):e.tokenKey}return e.tokenKey??``}function gt(e,t){let n=q(e,t.byPath,t.byCssVar).tamaguiValue;if(e.category&&ft.has(e.category)&&typeof n==`number`)return`px(${n})`;if(typeof n==`string`){let r=Mt(n,t);return e.category===`dropShadow`?_t(r):r}return n}function _t(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 vt(e){let t={},n=W(e);for(let r of e){if(!r.category||r.category===`color`||!r.tokenKey||dt(r))continue;let e=ht(r);if(!e)continue;let i=gt(r,n);if(typeof i==`string`&&jt(i))continue;let a=t[r.category]??{};a[e]=i,t[r.category]=a}return t}function V(e){let t=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 yt(e,t){let n={},r=(e,t)=>{let r=t.cssValue;typeof r!=`string`||r.length===0||G(r)||r===`[object Object]`||(n[e]=r)};for(let t of e)t.tokenKey&&(t.primitive?r(V(t),t):r(t.tokenKey,t));for(let e of t)!e.tokenKey||!e.primitive||r(V(e),e);return n}function bt(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 xt(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){if(e.tokenKey&&xt(e,t,n,e.tokenKey))return H(e.tokenKey);let r=q(e,t.byPath,t.byCssVar);if(r.tokenKey&&xt(e,t,n,r.tokenKey))return H(r.tokenKey);if(r.primitive){let i=V(r);if(xt(e,t,n,i))return H(i)}let i=K(e,t);if(i)return m(i)}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`&&mt(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 At(e){if(typeof e==`string`)return Dt.exec(e.trim())?.[1]}function G(e){return kt(e)!=null||At(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&&!G(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=At(r.value)??At(r.cssValue)??At(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:O([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,[t]]of r.entries())a[`color${t}`]=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[
|
|
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 At(e){if(typeof e==`string`)return Dt.exec(e.trim())?.[1]}function G(e){return kt(e)!=null||At(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&&!G(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=At(r.value)??At(r.cssValue)??At(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:O([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,[t]]of r.entries())a[`color${t}`]=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[`color${r}`]=H(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(H(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();lt(r)||ut(r)||t.has(r)||t.set(r,O([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 O(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:O(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 st){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(B(t,`light`)),r=Y(B(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;G(l)||G(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(!dt(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(`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@razorwind/tamagui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
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": "364dd4c97b7a74b4e4a63563a7a83688f5d7581b"
|
|
110
110
|
}
|