@teacss/config 0.3.0 → 0.3.2
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.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import t,{existsSync as n,realpathSync as r}from"node:fs";import{dirname as i,extname as a,isAbsolute as o,join as s,relative as c,resolve as l,sep as u}from"node:path";import d from"node:process";import{consola as f}from"consola";import{resolveConfig as p}from"@teacss/core";import{Buffer as m}from"node:buffer";import{readFile as h,stat as g}from"node:fs/promises";import{fileURLToPath as _,pathToFileURL as v}from"node:url";const y=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],ee=new Set(y);function te(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function b(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:te(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function x(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function S(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(typeof n==`object`&&n&&!Array.isArray(n))return n;let r={};return x(e,t,r),r}function C(e,t){let n=t.filter(t=>e===t.prefix||e.startsWith(`${t.prefix}-`)),r=n.find(e=>e.key===`colors`),i=n.find(e=>e.semanticColor);if(r&&i){let t=e===`color`?``:e.slice(6),n=t.lastIndexOf(`-`),a=n>0?t.slice(0,n):``,o=n>0?t.slice(n+1):``;return a&&ee.has(o)?{ok:!0,nsKey:r.key,twoLevel:!0,rest:t,colorName:a,step:o}:a&&/^\d+$/.test(o)?{ok:!1,reason:`illegal-color-step`}:t?{ok:!0,nsKey:i.key,twoLevel:!1,rest:t}:{ok:!1,reason:`unknown-prefix`}}let a=n[0];if(!a)return{ok:!1,reason:`unknown-prefix`};let o=e===a.prefix?``:e.slice(a.prefix.length+1);if(a.twoLevel){let e=o.lastIndexOf(`-`),t=e>0?o.slice(0,e):``,n=e>0?o.slice(e+1):``;return!t||!ee.has(n)?{ok:!1,reason:`illegal-color-step`}:{ok:!0,nsKey:a.key,twoLevel:!0,rest:o,colorName:t,step:n}}return{ok:!0,nsKey:a.key,twoLevel:!1,rest:o}}function w(e,t){let n=b(t),r={},i=[];for(let t of e){let e=t.mode?S(S(r,`modes`),t.mode):r;for(let{property:r,value:a}of t.declarations){let t=C(r.startsWith(`--`)?r.slice(2):r,n);if(!t.ok){i.push(r);continue}let o=S(e,t.nsKey);t.twoLevel?x(S(o,t.colorName),t.step,a):x(o,t.rest||`DEFAULT`,a)}}return{theme:r,unknown:i}}const ne=/[A-Za-z0-9-]/,re=/[\w-]/;function T(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function E(e,t,n){let r=e[t];for(let i=t+1;i<n;i++)if(e[i]===`\\`)i++;else if(e[i]===r)return i+1;return n}function D(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=T(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=E(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function ie(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of O(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=E(t.prelude,0,t.prelude.length);i!==t.prelude.length||i<=1||t.prelude[i-1]!==e||n.push(t.prelude.slice(1,i-1))}return n}function ae(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return O(e).some(e=>e.name===n)}function oe(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=T(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=E(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function se(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=T(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=E(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function O(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(e[r]===`/`&&e[r+1]===`*`){r=T(e,r,e.length)-1;continue}if(e[r]===`"`||e[r]===`'`){r=E(e,r,e.length)-1;continue}if(e[r]===`{`){n++;continue}if(e[r]===`}`){n=Math.max(0,n-1);continue}if(n!==0||e[r]!==`@`)continue;let i=r,a=i+1;for(;re.test(e[a]??``);)a++;if(a===i+1)continue;let o=e.slice(i+1,a),s=[],c=!1;for(let n=a;n<e.length;n++){let l=e[n];if(l===`/`&&e[n+1]===`*`)n=T(e,n,e.length)-1;else if(l===`"`||l===`'`)n=E(e,n,e.length)-1;else if(l===`(`)s.push(`)`);else if(l===`[`)s.push(`]`);else if(l===s.at(-1))s.pop();else if(s.length===0&&l===`;`){t.push({name:o,prelude:D(e,a,n),start:i,end:n+1,terminator:`;`}),r=n,c=!0;break}else if(s.length===0&&l===`{`){let s=se(e,n);s>=0&&(t.push({name:o,prelude:D(e,a,n),start:i,end:s+1,terminator:`block`}),r=s,c=!0);break}}if(!c&&D(e,a,e.length)===``){t.push({name:o,prelude:``,start:i,end:e.length,terminator:`eof`});break}}return t}function ce(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=T(e,i,n)-1;else if(t===`"`||t===`'`)i=E(e,i,n)-1;else if(t===`(`)r.push(`)`);else if(t===`[`)r.push(`]`);else if(t===`{`)r.push(`}`);else if(t===r.at(-1))r.pop();else if(t===`;`&&r.length===0)return i}return n}function le(e,t,n){let r=[];for(let i=t;i<n;){for(;i<n;)if(/\s/.test(e[i]))i++;else if(e[i]===`/`&&e[i+1]===`*`)i=T(e,i,n);else break;let t=ce(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&ne.test(e[a]);)a++;if(a===i+2){i=t+1;continue}let o=a;for(;o<n;)if(/\s/.test(e[o]))o++;else if(e[o]===`/`&&e[o+1]===`*`)o=T(e,o,n);else break;if(e[o]!==`:`){i=t+1;continue}let s=o+1,c=e.slice(s,t),l=c.trim(),u=s+c.length-c.trimStart().length,d=u+l.length;r.push({property:e.slice(i,a),value:l,start:i,end:a,colon:o,valueStart:u,valueEnd:d}),i=t+1}return r}function k(e){let t=[];for(let n of O(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=oe(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:le(e,r+1,i),open:r,close:i})}return t}function ue(e){let t,n=0,r=null;for(let i=0;i<e.length;i++){let a=e[i];if(r)a===`\\`?i++:a===r&&(r=null);else if(a===`"`||a===`'`)r=a;else if(a===`/`&&e[i+1]===`*`){let r=e.indexOf(`*/`,i+2),a=r<0?e.length:r+2;(t??=[]).push(e.slice(n,i),` `),n=a,i=a-1}}return t?`${t.join(``)}${e.slice(n)}`:e}function de(e){let t=e[0];if(t===`"`||t===`'`)for(let n=1;n<e.length;n++){let r=e[n];if(r===`\\`)n++;else if(r===t)return n===e.length-1?e.slice(1,n):void 0}}function A(e){let t=O(e),n=[],r=[],i=!1,a=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?i=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(a=!0),e.terminator!==`;`||e.name!==`preset`&&e.name!==`source`)continue;let t=de(e.prelude)?.trim();if(!t)continue;if(e.name===`preset`){n.push(t);continue}let o=t.startsWith(`!`),s=o?t.slice(1):t;s&&r.push({glob:s,exclude:o})}return{presets:n,sources:r,custom:i?k(e).map(({mode:e,declarations:t})=>({mode:e,declarations:t.map(({property:e,value:t})=>({property:e,value:ue(t).trim()}))})):[],hasTeacss:a}}let fe;function pe(){return fe??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const j=new Map,M=new WeakMap,N=16*1024*1024,P=new Map;let F=0;const I={articles:`@teacss/preset-articles`,icons:`@teacss/preset-icons`,standard:`@teacss/preset-standard`};function me(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function he(t,n){if(t.startsWith(`.`)||o(t))return l(n,t);let r=e(l(n,`_`)),i=Object.hasOwn(I,t)?I[t]:void 0;return i?me(i,r):r.resolve(t)}function L(e){return e.startsWith(`.`)||o(e)}function R(e){try{return r(e)}catch{return l(e)}}function z(e,t){let r=i(e),a=[];for(;;){if(t.has(r)){let e=t.get(r);for(let n of a)t.set(n,e);return e}if(a.push(r),n(l(r,`package.json`))){for(let e of a)t.set(e,r);return r}let e=i(r);if(e===r){for(let e of a)t.set(e,void 0);return}r=e}}function ge(e,t){let n=c(t,e);return n===``||!o(n)&&n!==`..`&&!n.startsWith(`..${u}`)}function B(e,t,n){let r=z(e,n);return t.packageRoot===void 0?r===void 0&&ge(e,t.fallbackRoot):r===t.packageRoot}function V(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!o(e.filename)))return;let a=R(e.filename);if(B(a,r,i)){t.add(a);for(let a of e.children)V(a,t,n,r,i)}}function _e(e){if(!e||typeof e!=`object`)return;let t,n,r;try{t=Reflect.get(e,`path`),n=Reflect.get(e,`url`),r=Reflect.get(e,`message`)}catch{return}if(typeof t==`string`&&o(t))return R(t);if(typeof n==`string`&&n.startsWith(`file:`))return R(_(n));if(typeof r!=`string`)return;let a=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),s=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),c=a??s;if(!c)return;let u=c[1],d=c[2];if(!(!u||!d||!u.startsWith(`.`)&&!o(u)))return R(o(u)?u:l(i(d),u))}async function ve(e,t){let n=j.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);j.set(e,a),await n;try{return{evaluation:t()}}finally{r(),j.get(e)===a&&j.delete(e)}}function ye(e){return()=>({visitor:{AwaitExpression(t){t.getFunctionParent()||(e.hasTopLevelAwait=!0)},CallExpression(t){t.node.callee?.type===`Identifier`&&t.node.callee.name===`jitiImport`&&(e.hasDynamicImport=!0);let n=t.node.arguments?.[0];if(t.node.callee?.type!==`Identifier`||t.node.callee.name!==`require`)return;let r=n?.type===`StringLiteral`&&typeof n.value==`string`;r&&e.dependencies.add(n.value),typeof t.node.start==`number`&&(r?t.getFunctionParent()?e.hasNestedRequire=!0:e.hasTopLevelRequire=!0:e.hasNonLiteralRequire=!0)},ForOfStatement(t){t.node.await&&!t.getFunctionParent()&&(e.hasTopLevelAwait=!0)}}})}function H(e,t,n){if(e.hasDynamicImport)throw Error(`Dynamic imports are not supported in local preset modules: "${t}". Use static imports so TeaCSS can track and reload the complete graph.`);if(e.hasNonLiteralRequire)throw Error(`CommonJS require() specifiers must be string literals in local preset modules: "${t}".`);if(e.hasNestedRequire)throw Error(`CommonJS require() is only supported at module top level in local preset modules: "${t}".`);if(e.hasTopLevelRequire&&e.hasTopLevelAwait)throw Error(`CommonJS require() cannot be combined with top-level await in a local preset module: "${t}". Use a static import instead.`);if(t!==n&&e.hasTopLevelAwait)throw Error(`Top-level await is only supported in the local preset entry module: "${t}".`)}const U=Symbol(`uncacheable transform option`);function W(e,t=new Set){if(e===null)return`n`;if(typeof e==`string`)return`s${JSON.stringify(e)}`;if(typeof e==`boolean`)return e?`b1`:`b0`;if(typeof e==`number`)return Number.isNaN(e)?`dNaN`:e===1/0?`dInfinity`:e===-1/0?`d-Infinity`:Object.is(e,-0)?`d-0`:`d${JSON.stringify(e)}`;if(e===void 0)return`u`;if(typeof e!=`object`||t.has(e))throw U;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw U;let n=Number(t),r=Object.getOwnPropertyDescriptor(e,t);if(!Number.isSafeInteger(n)||n<0||String(n)!==t||n>=e.length||!r?.enumerable||!(`value`in r))throw U}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?W(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw U;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw U;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw U;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${W(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function be(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function xe(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function Se(e){try{return W({babel:xe(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ce(e,t,n,r){let i=m.byteLength(e)+m.byteLength(t)+m.byteLength(n);for(let e of r.dependencies)i+=m.byteLength(e);return i}function G(e,t){let n=P.get(e);n&&(F-=n.bytes,P.delete(e));let r=Ce(e,t.source,t.code,t.facts);if(!(r>N))for(P.set(e,{...t,bytes:r}),F+=r;P.size>256||F>N;){let e=P.keys().next();if(e.done)break;let t=P.get(e.value);P.delete(e.value),t&&(F-=t.bytes)}}function we(e){return{...e,dependencies:Array.from(e.dependencies)}}function K(e,t,n,r,i,a){let o=t.filename?R(t.filename):n,s=be(e,t),c=Se(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:P.get(l);if(l!==void 0&&u?.source===s.source)return P.delete(l),P.set(l,u),B(o,r,i)&&H(u.facts,o,n),{code:u.code,dependencies:u.facts.dependencies};let d=c===void 0?void 0:{filename:o,mode:c,source:s.source},f=d===void 0?void 0:a?.read(d);if(l!==void 0&&f){let e={...f.facts,dependencies:new Set(f.facts.dependencies)};return G(l,{code:f.code,facts:e,source:s.source}),B(o,r,i)&&H(e,o,n),{code:f.code,dependencies:e.dependencies}}let p={dependencies:new Set,hasDynamicImport:!1,hasNestedRequire:!1,hasNonLiteralRequire:!1,hasTopLevelAwait:!1,hasTopLevelRequire:!1},m=ye(p),h=Error.prepareStackTrace,g=Error.stackTraceLimit;try{let t=e.transform({...s,babel:{...s.babel,plugins:[...Array.isArray(s.babel?.plugins)?s.babel.plugins:[],m]}});return l!==void 0&&G(l,{code:t,facts:p,source:s.source}),B(o,r,i)&&H(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:we(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Te=/\.[cm]?[jt]sx?$/;function q(e,t,n){let r=R(o(n)?n:l(i(t),n));if(a(r))return[r];let s=Array.from(new Set([``,...e.options.extensions??[],`.json`])),c=[r,l(r,`index`)].flatMap(e=>s.map(t=>`${e}${t}`));return c.push(l(r,`package.json`)),c}function Ee(t,n,r){if(r.startsWith(`node:`))return[];try{let i=L(r)?t.esmResolve(r,{parentURL:v(n).href,try:!0}):e(n).resolve(r);if(!i)return L(r)?q(t,n,r):[];let a=i.startsWith(`file:`)?_(i):i;return o(a)?[R(a)]:[]}catch{return L(r)?q(t,n,r):[]}}async function De(e,t,n,r,i,o,s){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Te.test(a(d)))continue;let f;try{f=await h(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=K(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,s);for(let e of p)for(let n of Ee(t,d,e))o.has(n)||!B(n,r,i)||(o.add(n),c.push(n))}return l}async function Oe(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-Cp5NmI8Q.js`);return n(e,import.meta.url,t)}catch{return}}function J(e,t){if(!e||typeof e!=`object`)return;let n=M.get(e)??[];M.set(e,Array.from(new Set([...n,...t])))}function Y(e){return e&&typeof e==`object`?[...M.get(e)??[]]:[]}async function ke(t,n,r){let a=R(t),o=e(a),s=Object.create(null),c=new Set([a]),l=new Map,u={packageRoot:z(a,l),fallbackRoot:i(a)},[{createJiti:d,transformer:f},p]=await Promise.all([pe(),Oe(a,r)]),m=d(a,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=K(f,e,a,u,l,p);return{code:t}}}),g=()=>{let e=new Set;for(let t of Object.values(s))V(t,c,e,u,l);for(let t of c)V(o.cache[t],c,e,u,l)};try{let e=await De(a,m,f,u,l,c,p)??await h(a,`utf8`),{evaluation:t}=await ve(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete o.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:a,forceTranspile:!0})}),r=await t,i=r?.__esModule?r.default:r;if(i==null)throw Error(`@preset "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof i==`function`?await i():i;return g(),{preset:d,sources:Array.from(c)}}catch(e){g();let t=_e(e);throw J(e,t&&B(t,u,l)?[...c,t]:Array.from(c)),e}}async function Ae(e){let t=await g(e),n=v(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function X(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e=he(a,t);try{let t;if(L(a)){let t=await ke(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}else t=await Ae(e);if(t==null)throw Error(`@preset "${a}" has no default export (expected a Preset or preset factory)`);n.push(typeof t==`function`?await t():t)}catch(t){throw J(t,L(a)?[...r,R(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function je(e,t){return(await X(e,t)).presets}function Me(e){return Object.keys(e).filter(t=>t!==`modes`&&t!==`defaultMode`&&e[t]!=null&&typeof e[t]==`object`)}async function Z(e,t){let n=A(e),r=n.presets.length?await X(n.presets,t):{presets:[],sources:[]},i=r.presets,a=Me((await p({presets:i})).theme),{theme:o,unknown:s}=w(n.custom,a);return{config:{presets:i,theme:o,content:{filesystem:[...n.sources.filter(e=>!e.exclude).map(e=>e.glob),...n.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)]}},unknown:s,hasTeacss:n.hasTeacss,sources:r.sources}}const Ne=y.join(` `);function Pe(e,t){return t===`unknown-prefix`?`@custom var "${e}" matches no theme namespace — not registered (emitted as a plain :root var).`:`@custom var "${e}" has an illegal color step — palette steps are ${Ne}.`}function Fe(e,t){let n=b(t),r=[];for(let t of k(e))for(let e of t.declarations){let{property:t,start:i,end:a}=e,o=C(t.slice(2),n);o.ok||r.push({property:t,start:i,end:a,reason:o.reason,message:Pe(t,o.reason)})}return r}const Q=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[Ie,...Le]=Q;function Re(e,t){let n={...e};for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(t,e)?.enumerable)continue;let r=Reflect.get(t,e);r!==void 0&&Object.defineProperty(n,e,{value:r,configurable:!0,enumerable:!0,writable:!0})}return n}function ze(e){try{let n=t.readFileSync(e,`utf8`);return n.includes(`@teacss`)?O(n).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function Be(e){try{let n=JSON.parse(t.readFileSync(s(e,Ie),`utf8`))?.teacss?.entry;return typeof n==`string`?n:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function Ve(e){let n=Be(e);if(n){let r=l(e,n);if(t.existsSync(r)&&t.statSync(r).isFile())return r}for(let n of Le){let r=s(e,n);if(t.existsSync(r)&&t.statSync(r).isFile()&&ze(r))return r}}async function $(e=d.cwd(),n=e,r={}){if(typeof n!=`string`)return{config:Re(r,n),sources:[]};let a=l(e,n),o=t.existsSync(a)&&t.statSync(a).isFile()?a:Ve(a);if(!o)return{config:{...r},sources:[]};let s;try{s=await Z(t.readFileSync(o,`utf8`),i(o))}catch(e){throw J(e,[o]),e}let{config:c}=s,u=Re(r,c);return c.presets?.length||(r.presets?.length?u.presets=r.presets:f.warn(`[@teacss/config] "${o}" declares no @preset — no utilities will be generated. Add one, e.g. \`@preset "standard";\``)),{config:u,sources:Array.from(new Set([o,...s.sources]))}}function He(){let e=new Map,t=new Map,n=new Map,r=new WeakMap,i=new WeakMap,a=new WeakMap,o=(e,n)=>e?t.get(e):n?i.get(n):void 0,s=(e,t)=>e?n.get(e):t?a.get(t):void 0,c=async(e,t)=>{for(;;){let n=o(e,t),r=s(e,t);if(!r)return;let i=await r;if(o(e,t)===n)return i}};return(o=d.cwd(),s=o,u={})=>{let p=typeof s==`string`?l(o,s):void 0,m=typeof s==`object`&&s?s:void 0,h=p?(t.get(p)??0)+1:m?(i.get(m)??0)+1:0;p?t.set(p,h):m&&i.set(m,h);let g=$(o,s,u).then(n=>(p&&t.get(p)===h?e.set(p,n):m&&i.get(m)===h&&r.set(m,n),n),async n=>{let a=p?t.get(p)===h:!m||i.get(m)===h;if(!a){let e=await c(p,m);if(e)return e}let o=p?e.get(p):m?r.get(m):void 0;if(!o)throw n;if(a){f.error(`[@teacss/config] Error resolving config from the CSS entry:`,n);let e=Array.from(new Set([...o.sources,...Y(n)]));return e.length===o.sources.length?o:{...o,sources:e}}return o});return p?n.set(p,g):m&&a.set(m,g),g}}export{b as buildNamespaces,C as classifyCustomVar,He as createRecoveryConfigLoader,w as customToTheme,Fe as diagnoseCustom,Q as entryDiscoveryFiles,Ve as findEntry,Y as getConfigSourcesFromError,ae as hasTopLevelDirective,$ as loadConfig,A as parseEntry,Z as resolveEntryConfig,je as resolvePresets,k as scanCustomBlocks,ie as scanQuotedDirectives,O as scanTopLevelAtRules};
|
|
1
|
+
import{createRequire as e}from"node:module";import t,{existsSync as n,realpathSync as r}from"node:fs";import{dirname as i,extname as a,isAbsolute as o,join as s,relative as c,resolve as l,sep as u}from"node:path";import d from"node:process";import{consola as f}from"consola";import{resolveConfig as p}from"@teacss/core";import{Buffer as m}from"node:buffer";import{readFile as h,stat as g}from"node:fs/promises";import{fileURLToPath as _,pathToFileURL as v}from"node:url";const y=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],b=new Set(y);function ee(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function x(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:ee(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function S(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function C(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(typeof n==`object`&&n&&!Array.isArray(n))return n;let r={};return S(e,t,r),r}function w(e,t){let n=t.filter(t=>e===t.prefix||e.startsWith(`${t.prefix}-`)),r=n.find(e=>e.key===`colors`),i=n.find(e=>e.semanticColor);if(r&&i){let t=e===`color`?``:e.slice(6),n=t.lastIndexOf(`-`),a=n>0?t.slice(0,n):``,o=n>0?t.slice(n+1):``;return a&&b.has(o)?{ok:!0,nsKey:r.key,twoLevel:!0,rest:t,colorName:a,step:o}:a&&/^\d+$/.test(o)?{ok:!1,reason:`illegal-color-step`}:t?{ok:!0,nsKey:i.key,twoLevel:!1,rest:t}:{ok:!1,reason:`unknown-prefix`}}let a=n[0];if(!a)return{ok:!1,reason:`unknown-prefix`};let o=e===a.prefix?``:e.slice(a.prefix.length+1);if(a.twoLevel){let e=o.lastIndexOf(`-`),t=e>0?o.slice(0,e):``,n=e>0?o.slice(e+1):``;return!t||!b.has(n)?{ok:!1,reason:`illegal-color-step`}:{ok:!0,nsKey:a.key,twoLevel:!0,rest:o,colorName:t,step:n}}return{ok:!0,nsKey:a.key,twoLevel:!1,rest:o}}function T(e,t){let n=x(t),r={},i=[];for(let t of e){let e=t.mode?C(C(r,`modes`),t.mode):r;for(let{property:r,value:a}of t.declarations){let t=w(r.startsWith(`--`)?r.slice(2):r,n);if(!t.ok){i.push(r);continue}let o=C(e,t.nsKey);t.twoLevel?S(C(o,t.colorName),t.step,a):S(o,t.rest||`DEFAULT`,a)}}return{theme:r,unknown:i}}const te=/[A-Za-z0-9-]/,ne=/[\w-]/;function E(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function D(e,t,n){let r=e[t];for(let i=t+1;i<n;i++)if(e[i]===`\\`)i++;else if(e[i]===r)return i+1;return n}function O(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=E(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=D(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function re(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of k(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=D(t.prelude,0,t.prelude.length);i!==t.prelude.length||i<=1||t.prelude[i-1]!==e||n.push(t.prelude.slice(1,i-1))}return n}function ie(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return k(e).some(e=>e.name===n)}function ae(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=E(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=D(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function oe(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=E(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=D(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function k(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(e[r]===`/`&&e[r+1]===`*`){r=E(e,r,e.length)-1;continue}if(e[r]===`"`||e[r]===`'`){r=D(e,r,e.length)-1;continue}if(e[r]===`{`){n++;continue}if(e[r]===`}`){n=Math.max(0,n-1);continue}if(n!==0||e[r]!==`@`)continue;let i=r,a=i+1;for(;ne.test(e[a]??``);)a++;if(a===i+1)continue;let o=e.slice(i+1,a),s=[],c=!1;for(let n=a;n<e.length;n++){let l=e[n];if(l===`/`&&e[n+1]===`*`)n=E(e,n,e.length)-1;else if(l===`"`||l===`'`)n=D(e,n,e.length)-1;else if(l===`(`)s.push(`)`);else if(l===`[`)s.push(`]`);else if(l===s.at(-1))s.pop();else if(s.length===0&&l===`;`){t.push({name:o,prelude:O(e,a,n),start:i,end:n+1,terminator:`;`}),r=n,c=!0;break}else if(s.length===0&&l===`{`){let s=oe(e,n);s>=0&&(t.push({name:o,prelude:O(e,a,n),start:i,end:s+1,terminator:`block`}),r=s,c=!0);break}}if(!c&&O(e,a,e.length)===``){t.push({name:o,prelude:``,start:i,end:e.length,terminator:`eof`});break}}return t}function se(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=E(e,i,n)-1;else if(t===`"`||t===`'`)i=D(e,i,n)-1;else if(t===`(`)r.push(`)`);else if(t===`[`)r.push(`]`);else if(t===`{`)r.push(`}`);else if(t===r.at(-1))r.pop();else if(t===`;`&&r.length===0)return i}return n}function ce(e,t,n){let r=[];for(let i=t;i<n;){for(;i<n;)if(/\s/.test(e[i]))i++;else if(e[i]===`/`&&e[i+1]===`*`)i=E(e,i,n);else break;let t=se(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&te.test(e[a]);)a++;if(a===i+2){i=t+1;continue}let o=a;for(;o<n;)if(/\s/.test(e[o]))o++;else if(e[o]===`/`&&e[o+1]===`*`)o=E(e,o,n);else break;if(e[o]!==`:`){i=t+1;continue}let s=o+1,c=e.slice(s,t),l=c.trim(),u=s+c.length-c.trimStart().length,d=u+l.length;r.push({property:e.slice(i,a),value:l,start:i,end:a,colon:o,valueStart:u,valueEnd:d}),i=t+1}return r}function A(e){let t=[];for(let n of k(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=ae(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:ce(e,r+1,i),open:r,close:i})}return t}function le(e){let t,n=0,r=null;for(let i=0;i<e.length;i++){let a=e[i];if(r)a===`\\`?i++:a===r&&(r=null);else if(a===`"`||a===`'`)r=a;else if(a===`/`&&e[i+1]===`*`){let r=e.indexOf(`*/`,i+2),a=r<0?e.length:r+2;(t??=[]).push(e.slice(n,i),` `),n=a,i=a-1}}return t?`${t.join(``)}${e.slice(n)}`:e}function ue(e){let t=e[0];if(t===`"`||t===`'`)for(let n=1;n<e.length;n++){let r=e[n];if(r===`\\`)n++;else if(r===t)return n===e.length-1?e.slice(1,n):void 0}}function de(e){let t=k(e),n=[],r=[],i=!1,a=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?i=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(a=!0),e.terminator!==`;`||e.name!==`preset`&&e.name!==`source`)continue;let t=ue(e.prelude)?.trim();if(!t)continue;if(e.name===`preset`){n.push(t);continue}let o=t.startsWith(`!`),s=o?t.slice(1):t;s&&r.push({glob:s,exclude:o})}return{presets:n,sources:r,custom:i?A(e).map(({mode:e,declarations:t})=>({mode:e,declarations:t.map(({property:e,value:t})=>({property:e,value:le(t).trim()}))})):[],hasTeacss:a}}let fe;function pe(){return fe??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const j=new Map,M=new WeakMap,N=16*1024*1024,P=new Map;let F=0;const I={articles:`@teacss/preset-articles`,icons:`@teacss/preset-icons`,standard:`@teacss/preset-standard`};function me(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function he(t,n){if(t.startsWith(`.`)||o(t))return l(n,t);let r=e(l(n,`_`)),i=Object.hasOwn(I,t)?I[t]:void 0;return i?me(i,r):r.resolve(t)}function L(e){return e.startsWith(`.`)||o(e)}function R(e){try{return r(e)}catch{return l(e)}}function z(e,t){let r=i(e),a=[];for(;;){if(t.has(r)){let e=t.get(r);for(let n of a)t.set(n,e);return e}if(a.push(r),n(l(r,`package.json`))){for(let e of a)t.set(e,r);return r}let e=i(r);if(e===r){for(let e of a)t.set(e,void 0);return}r=e}}function ge(e,t){let n=c(t,e);return n===``||!o(n)&&n!==`..`&&!n.startsWith(`..${u}`)}function B(e,t,n){let r=z(e,n);return t.packageRoot===void 0?r===void 0&&ge(e,t.fallbackRoot):r===t.packageRoot}function V(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!o(e.filename)))return;let a=R(e.filename);if(B(a,r,i)){t.add(a);for(let a of e.children)V(a,t,n,r,i)}}function _e(e){if(!e||typeof e!=`object`)return;let t,n,r;try{t=Reflect.get(e,`path`),n=Reflect.get(e,`url`),r=Reflect.get(e,`message`)}catch{return}if(typeof t==`string`&&o(t))return R(t);if(typeof n==`string`&&n.startsWith(`file:`))return R(_(n));if(typeof r!=`string`)return;let a=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),s=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),c=a??s;if(!c)return;let u=c[1],d=c[2];if(!(!u||!d||!u.startsWith(`.`)&&!o(u)))return R(o(u)?u:l(i(d),u))}async function ve(e,t){let n=j.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);j.set(e,a),await n;try{return{evaluation:t()}}finally{r(),j.get(e)===a&&j.delete(e)}}function ye(e){return()=>({visitor:{AwaitExpression(t){t.getFunctionParent()||(e.hasTopLevelAwait=!0)},CallExpression(t){t.node.callee?.type===`Identifier`&&t.node.callee.name===`jitiImport`&&(e.hasDynamicImport=!0);let n=t.node.arguments?.[0];if(t.node.callee?.type!==`Identifier`||t.node.callee.name!==`require`)return;let r=n?.type===`StringLiteral`&&typeof n.value==`string`;r&&e.dependencies.add(n.value),typeof t.node.start==`number`&&(r?t.getFunctionParent()?e.hasNestedRequire=!0:e.hasTopLevelRequire=!0:e.hasNonLiteralRequire=!0)},ForOfStatement(t){t.node.await&&!t.getFunctionParent()&&(e.hasTopLevelAwait=!0)}}})}function H(e,t,n){if(e.hasDynamicImport)throw Error(`Dynamic imports are not supported in local preset modules: "${t}". Use static imports so TeaCSS can track and reload the complete graph.`);if(e.hasNonLiteralRequire)throw Error(`CommonJS require() specifiers must be string literals in local preset modules: "${t}".`);if(e.hasNestedRequire)throw Error(`CommonJS require() is only supported at module top level in local preset modules: "${t}".`);if(e.hasTopLevelRequire&&e.hasTopLevelAwait)throw Error(`CommonJS require() cannot be combined with top-level await in a local preset module: "${t}". Use a static import instead.`);if(t!==n&&e.hasTopLevelAwait)throw Error(`Top-level await is only supported in the local preset entry module: "${t}".`)}const U=Symbol(`uncacheable transform option`);function W(e,t=new Set){if(e===null)return`n`;if(typeof e==`string`)return`s${JSON.stringify(e)}`;if(typeof e==`boolean`)return e?`b1`:`b0`;if(typeof e==`number`)return Number.isNaN(e)?`dNaN`:e===1/0?`dInfinity`:e===-1/0?`d-Infinity`:Object.is(e,-0)?`d-0`:`d${JSON.stringify(e)}`;if(e===void 0)return`u`;if(typeof e!=`object`||t.has(e))throw U;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw U;let n=Number(t),r=Object.getOwnPropertyDescriptor(e,t);if(!Number.isSafeInteger(n)||n<0||String(n)!==t||n>=e.length||!r?.enumerable||!(`value`in r))throw U}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?W(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw U;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw U;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw U;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${W(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function be(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function xe(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function Se(e){try{return W({babel:xe(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ce(e,t,n,r){let i=m.byteLength(e)+m.byteLength(t)+m.byteLength(n);for(let e of r.dependencies)i+=m.byteLength(e);return i}function G(e,t){let n=P.get(e);n&&(F-=n.bytes,P.delete(e));let r=Ce(e,t.source,t.code,t.facts);if(!(r>N))for(P.set(e,{...t,bytes:r}),F+=r;P.size>256||F>N;){let e=P.keys().next();if(e.done)break;let t=P.get(e.value);P.delete(e.value),t&&(F-=t.bytes)}}function we(e){return{...e,dependencies:Array.from(e.dependencies)}}function K(e,t,n,r,i,a){let o=t.filename?R(t.filename):n,s=be(e,t),c=Se(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:P.get(l);if(l!==void 0&&u?.source===s.source)return P.delete(l),P.set(l,u),B(o,r,i)&&H(u.facts,o,n),{code:u.code,dependencies:u.facts.dependencies};let d=c===void 0?void 0:{filename:o,mode:c,source:s.source},f=d===void 0?void 0:a?.read(d);if(l!==void 0&&f){let e={...f.facts,dependencies:new Set(f.facts.dependencies)};return G(l,{code:f.code,facts:e,source:s.source}),B(o,r,i)&&H(e,o,n),{code:f.code,dependencies:e.dependencies}}let p={dependencies:new Set,hasDynamicImport:!1,hasNestedRequire:!1,hasNonLiteralRequire:!1,hasTopLevelAwait:!1,hasTopLevelRequire:!1},m=ye(p),h=Error.prepareStackTrace,g=Error.stackTraceLimit;try{let t=e.transform({...s,babel:{...s.babel,plugins:[...Array.isArray(s.babel?.plugins)?s.babel.plugins:[],m]}});return l!==void 0&&G(l,{code:t,facts:p,source:s.source}),B(o,r,i)&&H(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:we(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Te=/\.[cm]?[jt]sx?$/;function q(e,t,n){let r=R(o(n)?n:l(i(t),n));if(a(r))return[r];let s=Array.from(new Set([``,...e.options.extensions??[],`.json`])),c=[r,l(r,`index`)].flatMap(e=>s.map(t=>`${e}${t}`));return c.push(l(r,`package.json`)),c}function Ee(t,n,r){if(r.startsWith(`node:`))return[];try{let i=L(r)?t.esmResolve(r,{parentURL:v(n).href,try:!0}):e(n).resolve(r);if(!i)return L(r)?q(t,n,r):[];let a=i.startsWith(`file:`)?_(i):i;return o(a)?[R(a)]:[]}catch{return L(r)?q(t,n,r):[]}}async function De(e,t,n,r,i,o,s){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Te.test(a(d)))continue;let f;try{f=await h(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=K(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,s);for(let e of p)for(let n of Ee(t,d,e))o.has(n)||!B(n,r,i)||(o.add(n),c.push(n))}return l}async function Oe(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-Cp5NmI8Q.js`);return n(e,import.meta.url,t)}catch{return}}function J(e,t){if(!e||typeof e!=`object`)return;let n=M.get(e)??[];M.set(e,Array.from(new Set([...n,...t])))}function Y(e){return e&&typeof e==`object`?[...M.get(e)??[]]:[]}async function ke(t,n,r){let a=R(t),o=e(a),s=Object.create(null),c=new Set([a]),l=new Map,u={packageRoot:z(a,l),fallbackRoot:i(a)},[{createJiti:d,transformer:f},p]=await Promise.all([pe(),Oe(a,r)]),m=d(a,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=K(f,e,a,u,l,p);return{code:t}}}),g=()=>{let e=new Set;for(let t of Object.values(s))V(t,c,e,u,l);for(let t of c)V(o.cache[t],c,e,u,l)};try{let e=await De(a,m,f,u,l,c,p)??await h(a,`utf8`),{evaluation:t}=await ve(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete o.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:a,forceTranspile:!0})}),r=await t,i=r?.__esModule?r.default:r;if(i==null)throw Error(`@preset "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof i==`function`?await i():i;return g(),{preset:d,sources:Array.from(c)}}catch(e){g();let t=_e(e);throw J(e,t&&B(t,u,l)?[...c,t]:Array.from(c)),e}}async function Ae(e){let t=await g(e),n=v(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function X(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e=he(a,t);try{let t;if(L(a)){let t=await ke(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}else t=await Ae(e);if(t==null)throw Error(`@preset "${a}" has no default export (expected a Preset or preset factory)`);n.push(typeof t==`function`?await t():t)}catch(t){throw J(t,L(a)?[...r,R(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function je(e,t){return(await X(e,t)).presets}function Me(e){return Object.keys(e).filter(t=>t!==`modes`&&t!==`defaultMode`&&e[t]!=null&&typeof e[t]==`object`)}async function Z(e,t){let n=de(e),r=n.presets.length?await X(n.presets,t):{presets:[],sources:[]},i=r.presets,a=Me((await p({presets:i})).theme),{theme:o,unknown:s}=T(n.custom,a);return{config:{presets:i,theme:o,content:{filesystem:[...n.sources.filter(e=>!e.exclude).map(e=>e.glob),...n.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)]}},unknown:s,hasTeacss:n.hasTeacss,sources:r.sources}}const Ne=y.join(` `);function Pe(e,t){return t===`unknown-prefix`?`@custom var "${e}" matches no theme namespace — not registered (emitted as a plain :root var).`:`@custom var "${e}" has an illegal color step — palette steps are ${Ne}.`}function Fe(e,t){let n=x(t),r=[];for(let t of A(e))for(let e of t.declarations){let{property:t,start:i,end:a}=e,o=w(t.slice(2),n);o.ok||r.push({property:t,start:i,end:a,reason:o.reason,message:Pe(t,o.reason)})}return r}const Q=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[Ie,...Le]=Q;function Re(e){let n=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set(Y(e))).sort().map(e=>{try{let n=t.statSync(e);return`${e}:${n.mtimeMs}:${n.ctimeMs}:${n.size}:${n.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([n,r])}function ze(e,t){let n={...e};for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(t,e)?.enumerable)continue;let r=Reflect.get(t,e);r!==void 0&&Object.defineProperty(n,e,{value:r,configurable:!0,enumerable:!0,writable:!0})}return n}function Be(e){try{let n=t.readFileSync(e,`utf8`);return n.includes(`@teacss`)?k(n).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function Ve(e){try{let n=JSON.parse(t.readFileSync(s(e,Ie),`utf8`))?.teacss?.entry;return typeof n==`string`?n:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function He(e){let n=Ve(e);if(n){let r=l(e,n);if(t.existsSync(r)&&t.statSync(r).isFile())return r}for(let n of Le){let r=s(e,n);if(t.existsSync(r)&&t.statSync(r).isFile()&&Be(r))return r}}async function $(e=d.cwd(),n=e,r={}){if(typeof n!=`string`)return{config:ze(r,n),sources:[]};let a=l(e,n),o=t.existsSync(a)&&t.statSync(a).isFile()?a:He(a);if(!o)return{config:{...r},sources:[]};let s;try{s=await Z(t.readFileSync(o,`utf8`),i(o))}catch(e){throw J(e,[o]),e}let{config:c}=s,u=ze(r,c);return c.presets?.length||(r.presets?.length?u.presets=r.presets:f.warn(`[@teacss/config] "${o}" declares no @preset — no utilities will be generated. Add one, e.g. \`@preset "standard";\``)),{config:u,sources:Array.from(new Set([o,...s.sources]))}}function Ue(){let e=new Map,t=new Map,n=new Map,r=new Map,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=(e,n)=>e?t.get(e):n?a.get(n):void 0,u=(e,t)=>e?n.get(e):t?o.get(t):void 0,p=async(e,t)=>{for(;;){let n=c(e,t),r=u(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=d.cwd(),u=c,m={})=>{let h=typeof u==`string`?l(c,u):void 0,g=typeof u==`object`&&u?u:void 0,_=h?(t.get(h)??0)+1:g?(a.get(g)??0)+1:0;h?t.set(h,_):g&&a.set(g,_);let v=$(c,u,m).then(n=>(h&&t.get(h)===_?(e.set(h,n),r.delete(h)):g&&a.get(g)===_&&(i.set(g,n),s.delete(g)),n),async n=>{let o=h?t.get(h)===_:!g||a.get(g)===_;if(!o){let e=await p(h,g);if(e)return e}let c=h?e.get(h):g?i.get(g):void 0;if(!c)throw n;if(o){let e=Re(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(f.error(`[@teacss/config] Error resolving config from the CSS entry:`,n),h?r.set(h,e):g&&s.set(g,e));let t=Array.from(new Set([...c.sources,...Y(n)]));return t.length===c.sources.length?c:{...c,sources:t}}return c});return h?n.set(h,v):g&&o.set(g,v),v}}export{x as buildNamespaces,w as classifyCustomVar,Ue as createRecoveryConfigLoader,T as customToTheme,Fe as diagnoseCustom,Q as entryDiscoveryFiles,He as findEntry,Y as getConfigSourcesFromError,ie as hasTopLevelDirective,$ as loadConfig,de as parseEntry,Z as resolveEntryConfig,je as resolvePresets,A as scanCustomBlocks,re as scanQuotedDirectives,k as scanTopLevelAtRules};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/config",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "TeaCSS config loader — discovers the CSS entry and resolves its directives into a config (no teacss.config file).",
|
|
5
5
|
"homepage": "https://css.teasim.com",
|
|
6
6
|
"funding": "https://github.com/sponsors/billgo",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dev": "tsdown --watch"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@teacss/core": "0.3.
|
|
25
|
+
"@teacss/core": "0.3.2",
|
|
26
26
|
"consola": "^3.4.2",
|
|
27
27
|
"jiti": "^2.7.0"
|
|
28
28
|
},
|