@teacss/config 0.3.8 → 0.4.0

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.d.ts CHANGED
@@ -69,6 +69,18 @@ interface Namespace {
69
69
  semanticColor?: boolean;
70
70
  }
71
71
  /** Build the var-prefix → theme-key table, longest prefix first so nested namespaces stay deterministic. */
72
+ /**
73
+ * The theme keys `@custom` may write, i.e. the var scales.
74
+ *
75
+ * A scale maps a name straight to its value, so `--radius-pill` and
76
+ * `--shadow-brand` mean something. `animation` is a structural config record
77
+ * (`keyframes`, `durations`, `timingFns`, …) rather than a scale, and it was
78
+ * accepted only because it happens to be an object: `--animation-keyframes`
79
+ * classified as known, reported nothing, emitted nothing, and replaced the
80
+ * keyframe registry with a string, so every `animation:*` utility stopped
81
+ * matching. `colors` is the one scale that is deliberately two-level.
82
+ */
83
+ declare function scaleThemeKeys(theme: Record<string, unknown>): string[];
72
84
  declare function buildNamespaces(themeKeys: string[]): Namespace[];
73
85
  type CustomClassification = {
74
86
  ok: true;
@@ -225,4 +237,4 @@ declare function loadConfig<U extends UserConfig>(cwd?: string, configOrPath?: s
225
237
  */
226
238
  declare function createRecoveryConfigLoader<U extends UserConfig>(): (cwd?: string, configOrPath?: string | U, defaults?: UserConfigDefaults) => Promise<LoadConfigResult<U>>;
227
239
  //#endregion
228
- export { CustomClassification, CustomDiagnostic, CustomToThemeResult, EntryConfig, EntryCustomBlock, EntryCustomDecl, EntryShortcut, EntrySource, LoadConfigResult, Namespace, ResolveEntryResult, ScannedCustomBlock, ScannedCustomDeclaration, ScannedTopLevelAtRule, buildNamespaces, classifyCustomVar, createRecoveryConfigLoader, customToTheme, diagnoseCustom, entryDiscoveryFiles, findEntry, getPresetSourcesFromError as getConfigSourcesFromError, hasTopLevelDirective, loadConfig, parseEntry, resolveEntryConfig, resolvePresets, scanCustomBlocks, scanQuotedDirectives, scanTopLevelAtRules };
240
+ export { CustomClassification, CustomDiagnostic, CustomToThemeResult, EntryConfig, EntryCustomBlock, EntryCustomDecl, EntryShortcut, EntrySource, LoadConfigResult, Namespace, ResolveEntryResult, ScannedCustomBlock, ScannedCustomDeclaration, ScannedTopLevelAtRule, buildNamespaces, classifyCustomVar, createRecoveryConfigLoader, customToTheme, diagnoseCustom, entryDiscoveryFiles, findEntry, getPresetSourcesFromError as getConfigSourcesFromError, hasTopLevelDirective, loadConfig, parseEntry, resolveEntryConfig, resolvePresets, scaleThemeKeys, scanCustomBlocks, scanQuotedDirectives, scanTopLevelAtRules };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{createRequire as e}from"node:module";import*as t from"node:fs";import n,{existsSync as r,readFileSync as i,realpathSync as a}from"node:fs";import{dirname as o,extname as s,isAbsolute as c,join as l,relative as u,resolve as d,sep as f}from"node:path";import p from"node:process";import{consola as m}from"consola";import{expandClassGroups as h,resolveConfig as g,splitClassTokens as _}from"@teacss/core";import{glob as v}from"tinyglobby";import{Buffer as y}from"node:buffer";import{readFile as ee,stat as te}from"node:fs/promises";import{fileURLToPath as b,pathToFileURL as x}from"node:url";const S=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],ne=new Set(S);function re(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function C(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:re(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function w(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function T(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 w(e,t,r),r}function E(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&&ne.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||!ne.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 D(e,t){let n=C(t),r={},i=[];for(let t of e){let e=t.mode?T(T(r,`modes`),t.mode):r;for(let{property:r,value:a}of t.declarations){let t=E(r.startsWith(`--`)?r.slice(2):r,n);if(!t.ok){i.push(r);continue}let o=T(e,t.nsKey);t.twoLevel?w(T(o,t.colorName),t.step,a):w(o,t.rest||`DEFAULT`,a)}}return{theme:r,unknown:i}}const ie=/[A-Za-z0-9-]/,ae=/[\w-]/;function O(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function k(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 A(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=O(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=k(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function oe(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of j(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=k(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 se(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return j(e).some(e=>e.name===n)}function ce(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=O(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=k(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function le(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=O(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=k(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function j(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(e[r]===`/`&&e[r+1]===`*`){r=O(e,r,e.length)-1;continue}if(e[r]===`"`||e[r]===`'`){r=k(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(;ae.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=O(e,n,e.length)-1;else if(l===`"`||l===`'`)n=k(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:A(e,a,n),start:i,end:n+1,terminator:`;`}),r=n,c=!0;break}else if(s.length===0&&l===`{`){let s=le(e,n);s>=0&&(t.push({name:o,prelude:A(e,a,n),start:i,end:s+1,terminator:`block`}),r=s,c=!0);break}}if(!c&&A(e,a,e.length)===``){t.push({name:o,prelude:``,start:i,end:e.length,terminator:`eof`});break}}return t}function ue(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=O(e,i,n)-1;else if(t===`"`||t===`'`)i=k(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 de(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=O(e,i,n);else break;let t=ue(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&ie.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=O(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 M(e){let t=[];for(let n of j(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=ce(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:de(e,r+1,i),open:r,close:i})}return t}function fe(e){let t=e,n=/^url\(\s*([^)]*?)\s*\)$/i.exec(t);if(n)t=n[1];else if(/^url\(/i.test(t))return;let r=t[0];if(r===`"`||r===`'`){if(t.length<2||t[t.length-1]!==r)return;let e=t.slice(1,-1);return e.includes(r)?void 0:e}return n?t:void 0}function pe(e){return!(!e||e.startsWith(`//`)||/^[a-z][\w+.-]*:/i.test(e))}function me(e){return e.split(`\\`).join(`/`)}function he(e,t,n){if(c(e)||!e.startsWith(`./`)&&!e.startsWith(`../`))return e;let r=me(u(n,d(t,e)));return r.startsWith(`.`)?r:`./${r}`}function N(e,t){if(t.length===0)return e;t.sort((e,t)=>e.start-t.start);let n=``,r=0;for(let i of t)n+=e.slice(r,i.start)+i.replacement,r=i.end;return n+e.slice(r)}function ge(e,t,n){if(t===n)return e;let r=[];for(let i of j(e)){if(i.terminator!==`;`||i.name!==`preset`&&i.name!==`source`)continue;let a=i.prelude[0];if(a!==`"`&&a!==`'`||i.prelude[i.prelude.length-1]!==a)continue;let o=i.prelude.slice(1,-1),s=i.name===`source`&&o.startsWith(`!`),c=s?o.slice(1):o,l=he(c,t,n);if(l===c)continue;let u=e.slice(i.start,i.end).replace(i.prelude,`${a}${s?`!`:``}${l}${a}`);r.push({start:i.start,end:i.end,replacement:u})}return N(e,r)}function P(e,n,r,i,a){if(a>32)return e;let s=[];for(let c of j(e)){if(c.name!==`import`||c.terminator!==`;`)continue;let e=fe(c.prelude);if(e===void 0||!pe(e))continue;let l=d(n,e),u;try{u=t.statSync(l)}catch{continue}if(!u.isFile())continue;if(r.has(l)){s.push({start:c.start,end:c.end,replacement:``});continue}r.add(l),i.push(l);let f=o(l),p=P(t.readFileSync(l,`utf8`),f,r,i,a+1);p=ge(p,f,n),s.push({start:c.start,end:c.end,replacement:p})}return N(e,s)}function _e(e,t){if(!e.includes(`@import`))return{css:e,files:[]};let n=[];return{css:P(e,t,new Set,n,0),files:n}}function ve(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 F(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 I(e){let t=j(e),n=[],r=[],i=[],a=[],o=!1,s=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?o=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(s=!0),e.terminator!==`;`)continue;if(e.name===`shortcut`){let t=e.prelude.search(/\s/);if(t<=0)continue;let n=e.prelude.slice(0,t);if(!/^[A-Za-z_][\w-]*$/.test(n))continue;let r=F(e.prelude.slice(t).trimStart())?.trim();r&&i.push({name:n,expansion:r});continue}if(e.name!==`preset`&&e.name!==`source`&&e.name!==`safelist`)continue;let t=F(e.prelude)?.trim();if(!t)continue;if(e.name===`preset`){n.push(t);continue}if(e.name===`safelist`){a.push(t);continue}let c=t.startsWith(`!`),l=c?t.slice(1):t;l&&r.push({glob:l,exclude:c})}return{presets:n,sources:r,custom:o?M(e).map(({mode:e,declarations:t})=>({mode:e,declarations:t.map(({property:e,value:t})=>({property:e,value:ve(t).trim()}))})):[],shortcuts:i,safelist:a,hasTeacss:s}}let ye;function be(){return ye??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const L=new Map,R=new WeakMap,z=16*1024*1024,B=new Map;let V=0;const H={articles:`@teacss/preset-articles`,icons:`@teacss/preset-icons`,standard:`@teacss/preset-standard`};function xe(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 Se(t,n){if(t.startsWith(`.`)||c(t))return d(n,t);let r=e(d(n,`_`)),i=Object.hasOwn(H,t)?H[t]:void 0;return i?xe(i,r):r.resolve(t)}function U(e){return e.startsWith(`.`)||c(e)}function W(e){try{return a(e)}catch{return d(e)}}function Ce(e,t){let n=o(e),i=[];for(;;){if(t.has(n)){let e=t.get(n);for(let n of i)t.set(n,e);return e}if(i.push(n),r(d(n,`package.json`))){for(let e of i)t.set(e,n);return n}let e=o(n);if(e===n){for(let e of i)t.set(e,void 0);return}n=e}}function we(e,t){let n=u(t,e);return n===``||!c(n)&&n!==`..`&&!n.startsWith(`..${f}`)}function G(e,t,n){let r=Ce(e,n);return t.packageRoot===void 0?r===void 0&&we(e,t.fallbackRoot):r===t.packageRoot}function K(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!c(e.filename)))return;let a=W(e.filename);if(G(a,r,i)){t.add(a);for(let a of e.children)K(a,t,n,r,i)}}function Te(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`&&c(t))return W(t);if(typeof n==`string`&&n.startsWith(`file:`))return W(b(n));if(typeof r!=`string`)return;let i=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),a=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),s=i??a;if(!s)return;let l=s[1],u=s[2];if(!(!l||!u||!l.startsWith(`.`)&&!c(l)))return W(c(l)?l:d(o(u),l))}async function Ee(e,t){let n=L.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);L.set(e,a),await n;try{return{evaluation:t()}}finally{r(),L.get(e)===a&&L.delete(e)}}function De(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 q(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 J=Symbol(`uncacheable transform option`);function Y(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 J;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw J;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 J}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?Y(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw J;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw J;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw J;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${Y(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function Oe(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function ke(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function Ae(e){try{return Y({babel:ke(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function je(e,t,n,r){let i=y.byteLength(e)+y.byteLength(t)+y.byteLength(n);for(let e of r.dependencies)i+=y.byteLength(e);return i}function Me(e,t){let n=B.get(e);n&&(V-=n.bytes,B.delete(e));let r=je(e,t.source,t.code,t.facts);if(!(r>z))for(B.set(e,{...t,bytes:r}),V+=r;B.size>256||V>z;){let e=B.keys().next();if(e.done)break;let t=B.get(e.value);B.delete(e.value),t&&(V-=t.bytes)}}function Ne(e){return{...e,dependencies:Array.from(e.dependencies)}}function Pe(e,t,n,r,i,a){let o=t.filename?W(t.filename):n,s=Oe(e,t),c=Ae(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:B.get(l);if(l!==void 0&&u?.source===s.source)return B.delete(l),B.set(l,u),G(o,r,i)&&q(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 Me(l,{code:f.code,facts:e,source:s.source}),G(o,r,i)&&q(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=De(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&&Me(l,{code:t,facts:p,source:s.source}),G(o,r,i)&&q(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:Ne(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Fe=/\.[cm]?[jt]sx?$/;function Ie(e,t,n){let r=W(c(n)?n:d(o(t),n));if(s(r))return[r];let i=Array.from(new Set([``,...e.options.extensions??[],`.json`])),a=[r,d(r,`index`)].flatMap(e=>i.map(t=>`${e}${t}`));return a.push(d(r,`package.json`)),a}function Le(t,n,r){if(r.startsWith(`node:`))return[];try{let i=U(r)?t.esmResolve(r,{parentURL:x(n).href,try:!0}):e(n).resolve(r);if(!i)return U(r)?Ie(t,n,r):[];let a=i.startsWith(`file:`)?b(i):i;return c(a)?[W(a)]:[]}catch{return U(r)?Ie(t,n,r):[]}}async function Re(e,t,n,r,i,a,o){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Fe.test(s(d)))continue;let f;try{f=await ee(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=Pe(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,o);for(let e of p)for(let n of Le(t,d,e))a.has(n)||!G(n,r,i)||(a.add(n),c.push(n))}return l}async function ze(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-Cp5NmI8Q.js`);return n(e,import.meta.url,t)}catch{return}}function X(e,t){if(!e||typeof e!=`object`)return;let n=R.get(e)??[];R.set(e,Array.from(new Set([...n,...t])))}function Z(e){return e&&typeof e==`object`?[...R.get(e)??[]]:[]}async function Be(t,n,r){let i=W(t),a=e(i),s=Object.create(null),c=new Set([i]),l=new Map,u={packageRoot:Ce(i,l),fallbackRoot:o(i)},[{createJiti:d,transformer:f},p]=await Promise.all([be(),ze(i,r)]),m=d(i,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=Pe(f,e,i,u,l,p);return{code:t}}}),h=()=>{let e=new Set;for(let t of Object.values(s))K(t,c,e,u,l);for(let t of c)K(a.cache[t],c,e,u,l)};try{let e=await Re(i,m,f,u,l,c,p)??await ee(i,`utf8`),{evaluation:t}=await Ee(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete a.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:i,forceTranspile:!0})}),r=await t,o=r?.__esModule?r.default:r;if(o==null)throw Error(`@preset "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof o==`function`?await o():o;return h(),{preset:d,sources:Array.from(c)}}catch(e){h();let t=Te(e);throw X(e,t&&G(t,u,l)?[...c,t]:Array.from(c)),e}}async function Ve(e){let t=await te(e),n=x(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function He(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e=Se(a,t);try{let t;if(U(a)){let t=await Be(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}else t=await Ve(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 X(t,U(a)?[...r,W(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function Ue(e,t){return(await He(e,t)).presets}function We(e){return Object.keys(e).filter(t=>t!==`modes`&&t!==`defaultMode`&&e[t]!=null&&typeof e[t]==`object`)}async function Ge(e,t,n){let r=e.filter(e=>!e.exclude).map(e=>e.glob);if(r.length===0)return{shortcuts:[],safelist:[],files:[]};let a=await v(r,{cwd:t,absolute:!0,ignore:e.filter(e=>e.exclude).map(e=>e.glob),expandDirectories:!1}),o=new Set(n),s=a.filter(e=>e.endsWith(`.css`)&&!o.has(e)).sort(),c=[],l=[];for(let e of s){let t;try{t=i(e,`utf8`)}catch{continue}if(!t.includes(`@shortcut`)&&!t.includes(`@safelist`))continue;let n=I(t);c.push(...n.shortcuts),l.push(...n.safelist)}return{shortcuts:c,safelist:l,files:s}}async function Q(e,t){let n=_e(e,t),r=I(n.css),[i,a]=await Promise.all([r.presets.length?He(r.presets,t):{presets:[],sources:[]},Ge(r.sources,t,n.files)]),o=i.presets,s=We((await g({presets:o})).theme),{theme:c,unknown:l}=D(r.custom,s),u=[...r.sources.filter(e=>!e.exclude).map(e=>e.glob),...r.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)],d=[...a.shortcuts,...r.shortcuts],f=Object.fromEntries(d.map(({name:e,expansion:t})=>[e,t])),p=[...new Set([...a.safelist,...r.safelist].flatMap(e=>_(h(e))))];return{config:{presets:o,theme:c,...r.sources.length?{content:{filesystem:u}}:{},...d.length?{shortcuts:f}:{},...p.length?{safelist:p}:{}},unknown:l,hasTeacss:n.files.length===0?r.hasTeacss:I(e).hasTeacss,sources:[...n.files,...a.files,...i.sources]}}const Ke=S.join(` `);function qe(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 ${Ke}.`}function Je(e,t){let n=C(t),r=[];for(let t of M(e))for(let e of t.declarations){let{property:t,start:i,end:a}=e,o=E(t.slice(2),n);o.ok||r.push({property:t,start:i,end:a,reason:o.reason,message:qe(t,o.reason)})}return r}const Ye=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[Xe,...Ze]=Ye;function Qe(e){let t=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set(Z(e))).sort().map(e=>{try{let t=n.statSync(e);return`${e}:${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([t,r])}function $e(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 et(e){try{let t=n.readFileSync(e,`utf8`);return t.includes(`@teacss`)?j(t).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function tt(e){try{let t=JSON.parse(n.readFileSync(l(e,Xe),`utf8`))?.teacss?.entry;return typeof t==`string`?t:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function nt(e){let t=tt(e);if(t){let r=d(e,t);if(n.existsSync(r)&&n.statSync(r).isFile())return r}for(let t of Ze){let r=l(e,t);if(n.existsSync(r)&&n.statSync(r).isFile()&&et(r))return r}}async function $(e=p.cwd(),t=e,r={}){if(typeof t!=`string`)return{config:$e(r,t),sources:[]};let i=d(e,t),a=n.existsSync(i)&&n.statSync(i).isFile()?i:nt(i);if(!a)return{config:{...r},sources:[]};let s;try{s=await Q(n.readFileSync(a,`utf8`),o(a))}catch(e){throw X(e,[a]),e}let{config:c}=s,l=$e(r,c);return c.presets?.length||(r.presets?.length?l.presets=r.presets:m.warn(`[@teacss/config] "${a}" declares no @preset — no utilities will be generated. Add one, e.g. \`@preset "standard";\``)),{config:l,sources:Array.from(new Set([a,...s.sources]))}}function rt(){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,l=(e,t)=>e?n.get(e):t?o.get(t):void 0,u=async(e,t)=>{for(;;){let n=c(e,t),r=l(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=p.cwd(),l=c,f={})=>{let h=typeof l==`string`?d(c,l):void 0,g=typeof l==`object`&&l?l: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,l,f).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 u(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=Qe(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(m.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,...Z(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{C as buildNamespaces,E as classifyCustomVar,rt as createRecoveryConfigLoader,D as customToTheme,Je as diagnoseCustom,Ye as entryDiscoveryFiles,nt as findEntry,Z as getConfigSourcesFromError,se as hasTopLevelDirective,$ as loadConfig,I as parseEntry,Q as resolveEntryConfig,Ue as resolvePresets,M as scanCustomBlocks,oe as scanQuotedDirectives,j as scanTopLevelAtRules};
1
+ import{createRequire as e}from"node:module";import*as t from"node:fs";import n,{existsSync as r,readFileSync as i,realpathSync as a}from"node:fs";import{dirname as o,extname as s,isAbsolute as c,join as l,relative as u,resolve as d,sep as f}from"node:path";import p from"node:process";import{consola as m}from"consola";import{expandClassGroups as h,resolveConfig as g,splitClassTokens as _}from"@teacss/core";import{glob as v}from"tinyglobby";import{Buffer as y}from"node:buffer";import{readFile as ee,stat as te}from"node:fs/promises";import{fileURLToPath as b,pathToFileURL as x}from"node:url";const S=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],ne=new Set(S);function re(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function C(e){return Object.keys(e).filter(t=>{if(t===`modes`||t===`defaultMode`)return!1;let n=e[t];return typeof n!=`object`||!n?!1:t===`colors`||Object.values(n).every(e=>e==null||typeof e==`string`||typeof e==`number`||Array.isArray(e))})}function w(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:re(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function T(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function E(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 T(e,t,r),r}function D(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&&ne.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||!ne.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 O(e,t){let n=w(t),r={},i=[];for(let t of e){let e=t.mode?E(E(r,`modes`),t.mode):r;for(let{property:r,value:a}of t.declarations){let t=D(r.startsWith(`--`)?r.slice(2):r,n);if(!t.ok){i.push(r);continue}let o=E(e,t.nsKey);t.twoLevel?T(E(o,t.colorName),t.step,a):T(o,t.rest||`DEFAULT`,a)}}return{theme:r,unknown:i}}const ie=/[A-Za-z0-9-]/,ae=/[\w-]/;function k(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function A(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 j(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=k(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=A(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function oe(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of M(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=A(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 se(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return M(e).some(e=>e.name===n)}function ce(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=k(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=A(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function le(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=k(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=A(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function M(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(e[r]===`/`&&e[r+1]===`*`){r=k(e,r,e.length)-1;continue}if(e[r]===`"`||e[r]===`'`){r=A(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(;ae.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=k(e,n,e.length)-1;else if(l===`"`||l===`'`)n=A(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:j(e,a,n),start:i,end:n+1,terminator:`;`}),r=n,c=!0;break}else if(s.length===0&&l===`{`){let s=le(e,n);s>=0&&(t.push({name:o,prelude:j(e,a,n),start:i,end:s+1,terminator:`block`}),r=s,c=!0);break}}if(!c&&j(e,a,e.length)===``){t.push({name:o,prelude:``,start:i,end:e.length,terminator:`eof`});break}}return t}function ue(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=k(e,i,n)-1;else if(t===`"`||t===`'`)i=A(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 de(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=k(e,i,n);else break;let t=ue(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&ie.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=k(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 N(e){let t=[];for(let n of M(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=ce(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:de(e,r+1,i),open:r,close:i})}return t}function fe(e){let t=e,n=/^url\(\s*([^)]*?)\s*\)$/i.exec(t);if(n)t=n[1];else if(/^url\(/i.test(t))return;let r=t[0];if(r===`"`||r===`'`){if(t.length<2||t[t.length-1]!==r)return;let e=t.slice(1,-1);return e.includes(r)?void 0:e}return n?t:void 0}function P(e){return!(!e||e.startsWith(`//`)||/^[a-z][\w+.-]*:/i.test(e))}function pe(e){return e.split(`\\`).join(`/`)}function me(e,t,n,r){if(!P(e)||c(e)||!r&&!e.startsWith(`./`)&&!e.startsWith(`../`))return e;let i=pe(u(n,d(t,e)));return i.startsWith(`.`)?i:`./${i}`}function F(e,t){if(t.length===0)return e;t.sort((e,t)=>e.start-t.start);let n=``,r=0;for(let i of t)n+=e.slice(r,i.start)+i.replacement,r=i.end;return n+e.slice(r)}function he(e,t,n){if(t===n)return e;let r=[];for(let i of M(e)){if(i.terminator!==`;`||i.name!==`preset`&&i.name!==`source`)continue;let a=i.prelude[0];if(a!==`"`&&a!==`'`||i.prelude[i.prelude.length-1]!==a)continue;let o=i.prelude.slice(1,-1).trim(),s=i.name===`source`&&o.startsWith(`!`),c=s?o.slice(1):o,l=me(c,t,n,i.name===`source`);if(l===c)continue;let u=e.slice(i.start,i.end).replace(i.prelude,`${a}${s?`!`:``}${l}${a}`);r.push({start:i.start,end:i.end,replacement:u})}return F(e,r)}function I(e,n,r,i,a){if(a>32)return e;let s=[];for(let c of M(e)){if(c.name!==`import`||c.terminator!==`;`)continue;let e=fe(c.prelude);if(e===void 0||!P(e))continue;let l=d(n,e),u;try{u=t.statSync(l)}catch{continue}if(!u.isFile())continue;if(r.has(l)){s.push({start:c.start,end:c.end,replacement:``});continue}r.add(l),i.push(l);let f=o(l),p=I(t.readFileSync(l,`utf8`),f,r,i,a+1);p=he(p,f,n),s.push({start:c.start,end:c.end,replacement:p})}return F(e,s)}function ge(e,t){if(!e.includes(`@import`))return{css:e,files:[]};let n=[];return{css:I(e,t,new Set,n,0),files:n}}function _e(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 L(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 R(e){let t=M(e),n=[],r=[],i=[],a=[],o=!1,s=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?o=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(s=!0),e.terminator!==`;`)continue;if(e.name===`shortcut`){let t=e.prelude.search(/\s/);if(t<=0)continue;let n=e.prelude.slice(0,t);if(!/^[A-Za-z_][\w-]*$/.test(n))continue;let r=L(e.prelude.slice(t).trimStart())?.trim();r&&i.push({name:n,expansion:r});continue}if(e.name!==`preset`&&e.name!==`source`&&e.name!==`safelist`)continue;let t=L(e.prelude)?.trim();if(!t)continue;if(e.name===`preset`){n.push(t);continue}if(e.name===`safelist`){a.push(t);continue}let c=t.startsWith(`!`),l=c?t.slice(1):t;l&&r.push({glob:l,exclude:c})}return{presets:n,sources:r,custom:o?N(e).map(({mode:e,declarations:t})=>({mode:e,declarations:t.map(({property:e,value:t})=>({property:e,value:_e(t).trim()}))})):[],shortcuts:i,safelist:a,hasTeacss:s}}let ve;function ye(){return ve??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const z=new Map,B=new WeakMap,V=16*1024*1024,H=new Map;let U=0;const W={articles:`@teacss/preset-articles`,icons:`@teacss/preset-icons`,standard:`@teacss/preset-standard`};function be(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 xe(t,n){if(t.startsWith(`.`)||c(t))return d(n,t);let r=e(d(n,`_`)),i=Object.hasOwn(W,t)?W[t]:void 0;return i?be(i,r):r.resolve(t)}function G(e){return e.startsWith(`.`)||c(e)}function K(e){try{return a(e)}catch{return d(e)}}function Se(e,t){let n=o(e),i=[];for(;;){if(t.has(n)){let e=t.get(n);for(let n of i)t.set(n,e);return e}if(i.push(n),r(d(n,`package.json`))){for(let e of i)t.set(e,n);return n}let e=o(n);if(e===n){for(let e of i)t.set(e,void 0);return}n=e}}function Ce(e,t){let n=u(t,e);return n===``||!c(n)&&n!==`..`&&!n.startsWith(`..${f}`)}function q(e,t,n){let r=Se(e,n);return t.packageRoot===void 0?r===void 0&&Ce(e,t.fallbackRoot):r===t.packageRoot}function J(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!c(e.filename)))return;let a=K(e.filename);if(q(a,r,i)){t.add(a);for(let a of e.children)J(a,t,n,r,i)}}function we(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`&&c(t))return K(t);if(typeof n==`string`&&n.startsWith(`file:`))return K(b(n));if(typeof r!=`string`)return;let i=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),a=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),s=i??a;if(!s)return;let l=s[1],u=s[2];if(!(!l||!u||!l.startsWith(`.`)&&!c(l)))return K(c(l)?l:d(o(u),l))}async function Te(e,t){let n=z.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);z.set(e,a),await n;try{return{evaluation:t()}}finally{r(),z.get(e)===a&&z.delete(e)}}function Ee(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 Y(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 X=Symbol(`uncacheable transform option`);function Z(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 X;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw X;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 X}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?Z(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw X;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw X;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw X;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${Z(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function De(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function Oe(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function ke(e){try{return Z({babel:Oe(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ae(e,t,n,r){let i=y.byteLength(e)+y.byteLength(t)+y.byteLength(n);for(let e of r.dependencies)i+=y.byteLength(e);return i}function je(e,t){let n=H.get(e);n&&(U-=n.bytes,H.delete(e));let r=Ae(e,t.source,t.code,t.facts);if(!(r>V))for(H.set(e,{...t,bytes:r}),U+=r;H.size>256||U>V;){let e=H.keys().next();if(e.done)break;let t=H.get(e.value);H.delete(e.value),t&&(U-=t.bytes)}}function Me(e){return{...e,dependencies:Array.from(e.dependencies)}}function Ne(e,t,n,r,i,a){let o=t.filename?K(t.filename):n,s=De(e,t),c=ke(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:H.get(l);if(l!==void 0&&u?.source===s.source)return H.delete(l),H.set(l,u),q(o,r,i)&&Y(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 je(l,{code:f.code,facts:e,source:s.source}),q(o,r,i)&&Y(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=Ee(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&&je(l,{code:t,facts:p,source:s.source}),q(o,r,i)&&Y(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:Me(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Pe=/\.[cm]?[jt]sx?$/;function Fe(e,t,n){let r=K(c(n)?n:d(o(t),n));if(s(r))return[r];let i=Array.from(new Set([``,...e.options.extensions??[],`.json`])),a=[r,d(r,`index`)].flatMap(e=>i.map(t=>`${e}${t}`));return a.push(d(r,`package.json`)),a}function Ie(t,n,r){if(r.startsWith(`node:`))return[];try{let i=G(r)?t.esmResolve(r,{parentURL:x(n).href,try:!0}):e(n).resolve(r);if(!i)return G(r)?Fe(t,n,r):[];let a=i.startsWith(`file:`)?b(i):i;return c(a)?[K(a)]:[]}catch{return G(r)?Fe(t,n,r):[]}}async function Le(e,t,n,r,i,a,o){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Pe.test(s(d)))continue;let f;try{f=await ee(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=Ne(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,o);for(let e of p)for(let n of Ie(t,d,e))a.has(n)||!q(n,r,i)||(a.add(n),c.push(n))}return l}async function Re(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-Cp5NmI8Q.js`);return n(e,import.meta.url,t)}catch{return}}function Q(e,t){if(!e||typeof e!=`object`)return;let n=B.get(e)??[];B.set(e,Array.from(new Set([...n,...t])))}function $(e){return e&&typeof e==`object`?[...B.get(e)??[]]:[]}async function ze(t,n,r){let i=K(t),a=e(i),s=Object.create(null),c=new Set([i]),l=new Map,u={packageRoot:Se(i,l),fallbackRoot:o(i)},[{createJiti:d,transformer:f},p]=await Promise.all([ye(),Re(i,r)]),m=d(i,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=Ne(f,e,i,u,l,p);return{code:t}}}),h=()=>{let e=new Set;for(let t of Object.values(s))J(t,c,e,u,l);for(let t of c)J(a.cache[t],c,e,u,l)};try{let e=await Le(i,m,f,u,l,c,p)??await ee(i,`utf8`),{evaluation:t}=await Te(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete a.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:i,forceTranspile:!0})}),r=await t,o=r?.__esModule?r.default:r;if(o==null)throw Error(`@preset "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof o==`function`?await o():o;return h(),{preset:d,sources:Array.from(c)}}catch(e){h();let t=we(e);throw Q(e,t&&q(t,u,l)?[...c,t]:Array.from(c)),e}}async function Be(e){let t=await te(e),n=x(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function Ve(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e=xe(a,t);try{let t;if(G(a)){let t=await ze(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}else t=await Be(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 Q(t,G(a)?[...r,K(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function He(e,t){return(await Ve(e,t)).presets}async function Ue(e,t,n){let r=e.filter(e=>!e.exclude).map(e=>e.glob);if(r.length===0)return{shortcuts:[],safelist:[],files:[]};let a=await v(r,{cwd:t,absolute:!0,ignore:e.filter(e=>e.exclude).map(e=>e.glob),expandDirectories:!1}),o=new Set(n),s=a.filter(e=>e.endsWith(`.css`)&&!o.has(e)).sort(),c=[],l=[];for(let e of s){let t;try{t=i(e,`utf8`)}catch{continue}if(!t.includes(`@shortcut`)&&!t.includes(`@safelist`))continue;let n=R(t);c.push(...n.shortcuts),l.push(...n.safelist)}return{shortcuts:c,safelist:l,files:s}}async function We(e,t){let n=ge(e,t),r=R(n.css),[i,a]=await Promise.all([r.presets.length?Ve(r.presets,t):{presets:[],sources:[]},Ue(r.sources,t,n.files)]),o=i.presets,s=C((await g({presets:o})).theme),{theme:c,unknown:l}=O(r.custom,s),u=[...r.sources.filter(e=>!e.exclude).map(e=>e.glob),...r.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)],d=[...a.shortcuts,...r.shortcuts],f=Object.fromEntries(d.map(({name:e,expansion:t})=>[e,t])),p=[...new Set([...a.safelist,...r.safelist].flatMap(e=>_(h(e))))];return{config:{presets:o,theme:c,...r.sources.length?{content:{filesystem:u}}:{},...d.length?{shortcuts:f}:{},...p.length?{safelist:p}:{}},unknown:l,hasTeacss:n.files.length===0?r.hasTeacss:R(e).hasTeacss,sources:[...n.files,...a.files,...i.sources]}}const Ge=S.join(` `);function Ke(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 ${Ge}.`}function qe(e,t){let n=w(t),r=[];for(let t of N(e))for(let e of t.declarations){let{property:t,start:i,end:a}=e,o=D(t.slice(2),n);o.ok||r.push({property:t,start:i,end:a,reason:o.reason,message:Ke(t,o.reason)})}return r}const Je=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[Ye,...Xe]=Je;function Ze(e){let t=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set($(e))).sort().map(e=>{try{let t=n.statSync(e);return`${e}:${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([t,r])}function Qe(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 $e(e){try{let t=n.readFileSync(e,`utf8`);return t.includes(`@teacss`)?M(t).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function et(e){try{let t=JSON.parse(n.readFileSync(l(e,Ye),`utf8`))?.teacss?.entry;return typeof t==`string`?t:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function tt(e){let t=et(e);if(t){let r=d(e,t);if(n.existsSync(r)&&n.statSync(r).isFile())return r}for(let t of Xe){let r=l(e,t);if(n.existsSync(r)&&n.statSync(r).isFile()&&$e(r))return r}}async function nt(e=p.cwd(),t=e,r={}){if(typeof t!=`string`)return{config:Qe(r,t),sources:[]};let i=d(e,t),a=n.existsSync(i)&&n.statSync(i).isFile()?i:tt(i);if(!a)return{config:{...r},sources:[]};let s;try{s=await We(n.readFileSync(a,`utf8`),o(a))}catch(e){throw Q(e,[a]),e}let{config:c}=s,l=Qe(r,c);return c.presets?.length||(r.presets?.length?l.presets=r.presets:m.warn(`[@teacss/config] "${a}" declares no @preset — no utilities will be generated. Add one, e.g. \`@preset "standard";\``)),{config:l,sources:Array.from(new Set([a,...s.sources]))}}function rt(){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,l=(e,t)=>e?n.get(e):t?o.get(t):void 0,u=async(e,t)=>{for(;;){let n=c(e,t),r=l(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=p.cwd(),l=c,f={})=>{let h=typeof l==`string`?d(c,l):void 0,g=typeof l==`object`&&l?l: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=nt(c,l,f).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 u(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=Ze(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(m.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,...$(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{w as buildNamespaces,D as classifyCustomVar,rt as createRecoveryConfigLoader,O as customToTheme,qe as diagnoseCustom,Je as entryDiscoveryFiles,tt as findEntry,$ as getConfigSourcesFromError,se as hasTopLevelDirective,nt as loadConfig,R as parseEntry,We as resolveEntryConfig,He as resolvePresets,C as scaleThemeKeys,N as scanCustomBlocks,oe as scanQuotedDirectives,M as scanTopLevelAtRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/config",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
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.8",
25
+ "@teacss/core": "0.4.0",
26
26
  "consola": "^3.4.2",
27
27
  "jiti": "^2.7.0",
28
28
  "tinyglobby": "^0.2.17"