@teacss/directives 0.10.14 → 0.10.15

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/core.js CHANGED
@@ -1 +1 @@
1
- import{c as e,d as t,g as n,h as r,i,o as a,p as o,t as s}from"./screen-core-Ry20cGuO.js";export{e as formatMissingApplyTokens,a as generateApplyPreflights,t as missingApplyTokens,o as prepareApplyUtilities,r as renderStandaloneApplyUtility,n as resolveApplyTokens,i as resolveCssFunction,s as resolveScreenQuery};
1
+ import{c as e,d as t,g as n,h as r,i,o as a,p as o,t as s}from"./screen-core-BuUxmcvs.js";export{e as formatMissingApplyTokens,a as generateApplyPreflights,t as missingApplyTokens,o as prepareApplyUtilities,r as renderStandaloneApplyUtility,n as resolveApplyTokens,i as resolveCssFunction,s as resolveScreenQuery};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { MagicStringLike, SourceCodeTransformer, StringifiedUtil, TeacssGenerator } from "@teacss/core";
2
1
  import { CssDialect } from "@teacss/config";
2
+ import { MagicStringLike, SourceCodeTransformer, StringifiedUtil, TeacssGenerator } from "@teacss/core";
3
+ //#region src/css-items.d.ts
4
+ /** Whether a stylesheet is written for a preprocessor, whose `#{…}` and `@{…}` are interpolations; Stylus also reads an attached `{name}` as one. */
5
+ type Preprocessor = boolean | "stylus";
6
+ //#endregion
3
7
  //#region src/apply.d.ts
4
8
  /**
5
9
  * The rules written after an enclosing rule so far, and the at-rule heads still
@@ -99,8 +103,8 @@ export interface TransformerDirectivesContext {
99
103
  options: TransformerDirectivesOptions;
100
104
  applyVariable: string[];
101
105
  filename?: string;
102
- /** Sass, Less or Stylus source written with braces. */
103
- preprocessor: boolean;
106
+ /** Sass, Less or Stylus source written with braces; `"stylus"` for Stylus. */
107
+ preprocessor: Preprocessor;
104
108
  /** Applied payloads owned by this stylesheet, keyed by source offset. */
105
109
  applyUtilities: Map<number, StringifiedUtil[]>;
106
110
  /** At-rules an `@apply` inside a style rule writes, each once, for the end of the stylesheet. */
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import{C as e,S as t,_ as n,a as r,b as i,c as a,d as o,f as s,g as c,h as l,i as u,l as d,m as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y,v as b,w as x,x as S,y as C}from"./screen-core-Ry20cGuO.js";import{createGenerator as w,expandClassGroups as ee,expandVariantGroup as te,isCssId as T,splitClassTokens as E,toArray as D}from"@teacss/core";import{hasIconFn as O,hasThemeFn as k,transformThemeFn as ne,transformThemeString as re}from"@teacss/rule-helpers";import{ROLE_DIRECTIVES as A,blankLineComments as ie,cssDialectOf as ae,customPropertyValueEnd as oe,declarationStartsAfter as se,resolveEntryConfig as ce,scanTopLevelAtRules as j}from"@teacss/config";import{generateSources as le}from"@teacss/runtime/source-generation";var ue=class e{moved;head;outer;depth;constructor(e,t,n,r){this.moved=e,this.head=t,this.outer=n,this.depth=r}static root(t){return new e({end:t,css:``,open:[]},``,void 0,0)}within(t){return new e(this.moved,t,this,this.depth+1)}place(e){let{moved:t}=this,n=[],r=this;for(;r.depth>0&&t.open[r.depth-1]!==r;)n.push(r),r=r.outer;t.css+=`}`.repeat(t.open.length-r.depth),t.open.length=r.depth;for(let e of n.reverse())t.css+=`${e.head}{`,t.open.push(e);t.css+=e}},de=class e{hosts;inPlace;plain;nesting;constructor(e,t,n,r){this.hosts=e,this.inPlace=t,this.plain=n,this.nesting=r}static root(t,n,r){return new e([{condition:ue.root(n),selector:t,element:``}],void 0,!1,r)}within(t){let n=this.hosts.map(e=>({...e,condition:e.condition.within(t)}));return new e(n,this.inPlace===void 0?void 0:`&`,this.plain,this.nesting)}nested(t,r){let i=n(t);if(!i)return;let{taking:a,others:o}=i,s,c=this.plain;if(this.hosts.every(e=>e.nested===void 0)){let e=this.hosts[0],{groups:t,plain:n}=f(e.selector);c=!r&&n.length>0,r&&n.length&&t.push({bases:n,element:``}),s=t.map(({bases:t,element:n})=>{let i=b(a,this.anchored(t,a),r);return{condition:e.condition,selector:C(i,n),nested:d(i),element:n}})}else{let e=d(a);s=this.hosts.map(t=>({condition:t.condition.within(t.nested??``),selector:C(a,t.element),nested:e,element:t.element}))}let l=c?t.trim():o.length?d(o):void 0;return new e(s,l,c,this.nesting)}anchored(e,t){return this.nesting===`style-rule`?_(e,t,!1):this.nesting===`scope`?_(e,t,!0):e}standaloneHosts(){let e=this.hosts.map((e,t)=>[t,e.selector]);return this.inPlace===void 0?e:[...e,[void 0,this.inPlace]]}};function fe(e){return e.kind===`rule`?e.rule.block:e.block}function pe(e){return e.enclosing?e.enclosing.standaloneHosts():[[void 0,e.kind===`rule`?e.selector:e.host]]}function M(e,t){return Error(`[@teacss] @apply: "${e}" is outside a style rule or @scope${t?` in ${t}`:``}`)}function me(e){return Error(`[@teacss] @apply: no token to apply${e?` in ${e}`:``}`)}function he(e,t){return Error(`[@teacss] @apply: "${e}" needs a selector or condition, which a @keyframes block cannot hold${t?` in ${t}`:``}`)}async function ge(e,t,n){let r=[],i=[],a=!1,[o,s]=fe(t);for(let c of S(e.source,o,s,e.preprocessor)){if(c.kind===`rule`){await n(c);continue}let o=await ye(e,t,c);o&&(r.push(o.consumedRange),i.push(...o.standalone),a||=o.hasInlineUtility)}if(t.kind===`rule`&&!a&&r.length>0){let n=o;r.every(([t,r])=>{let i=!e.source.slice(n,t).trim();return n=r,i})&&!e.source.slice(n,s).trim()&&e.code.remove(t.rule.start,t.rule.end)}return i}function _e({code:e},t,n,r){let i=t.kind===`rule`?t.rule.end:t.block[1];if(t.kind===`rule`&&!t.enclosing&&n){let{moved:t}=n.hosts[0].condition;t.css&&(e.appendLeft(t.end,t.css+`}`.repeat(t.open.length)),t.css=``,t.open=[])}for(let n of r)n.moved!==void 0&&t.enclosing?t.enclosing.hosts[n.moved].condition.place(n.css):e.appendLeft(i,n.css)}const ve=e=>e===`style-rule`||e===`keyframes`;async function ye(e,t,n){let{code:i,source:u,generator:d,applyVariable:f,options:p,filename:m,applyUtilities:g,hoisted:_,nesting:v}=e,y,b;if(n.kind===`at-rule`&&n.name===`apply`)b=n.prelude[1],y=P(u.slice(...n.prelude));else if(n.kind===`declaration`&&f.includes(n.name))b=u[n.end-1]===`;`?n.end-1:n.end,y=E(P(u.slice(n.value[0],b).trim())).map(e=>P(e)).join(` `);else return;y=be(y),y=ne(y,d.config.theme,p.throwOnMissing??!0,r(d));let x=E(te(ee(y)));if(!x.length)throw me(m);let S=await c(x,d),C=o(S);if(C.length&&(p.throwOnMissing??!0))throw Error(`${a(C)}${m?` in ${m}`:``}`);let w=h(S,d.parentOrders,d.config.layers,e=>d.sheetOrder(e));g.set(n.start,S.flatMap(([,e])=>e??[]));let T=[n.start,u[n.end-1]===`;`?n.end:b];if(!w.length)return i.remove(...T),{consumedRange:T,hasInlineUtility:!1,standalone:[]};let D,O=!1,k=[];for(let e of w)if(e.kind===`top-level`)v===`top-level`||v===`scope`?k.push({css:e.body}):N(_,e.body);else if(e.kind===`standalone`){D??=pe(t).map(([e,t])=>[e,s(t)]);let n=e.selector?.startsWith(`@`)??!1;for(let[t,r]of D){let i=l(r,e,m);if(i){if(v===`keyframes`&&!n)throw he(y,m);n&&ve(v)?N(_,i):k.push({css:i,moved:t})}}}else O=!0,i.appendLeft(n.start,e.body);return i.remove(...T),{consumedRange:T,hasInlineUtility:O,standalone:k}}function N(e,t){for(let n of S(t,0,t.length,!1)){let r=t.slice(n.start,n.end);e.includes(r)||e.push(r)}}function P(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function be(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function F({code:e,source:t,generator:n,options:r,applyUtilities:i},a,o,s){let c=await u(n,a,(e,n)=>t.slice(e,n),r.throwOnMissing??!0,s);if(c!==void 0)return e.overwrite(a.loc.start.offset,a.loc.end.offset,c),o!==void 0&&c.includes(`var(`)&&i.set(a.loc.start.offset,[[0,void 0,`${o}:${c};`,void 0,void 0,void 0,void 0]]),c}function xe({code:e,source:t,generator:n},r){let i=v(t.slice(...r.prelude),n.config.theme);i&&e.overwrite(r.start,r.block?r.block[0]-1:r.prelude[1],`@media ${i}`)}const Se=new Set([`presets`,`source`,`shortcut`,`safelist`,...A]);function Ce(e,t,n=`css`){let r=new Set;if(!t.includes(`@`))return r;let i=j(t,!1,n);if(i.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))return r;for(let t of i)(Se.has(t.name)?t.terminator===`;`:t.name===`custom`&&(t.terminator===`block`||t.terminator===`;`))&&(e.remove(t.start,t.end),r.add(t.start));return r}function we(e){return A.some(t=>e.includes(`@${t}`))||e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}function Te(e){return/^(?:property|font-face|font-palette-values|counter-style)$/i.test(e)}function Ee(e){return e?.split(`?`).flatMap(e=>/\.(scss|sass|less|styl|stylus)$/.exec(e)?.[1]??[])[0]}function De(e,t){let n=[];for(let r=t+1;r<e.length;r++){let i=e[r];if(i===`\\`)r++;else if(i===e[t])return{close:r,lineBreaks:n};else(i===`
2
- `||i===`\r`||i===`\f`)&&n.push(r)}}function Oe(e,n,r){let a=n!==`css`,o=``,s=0,c=0,l=0,u=0,d=!1,f=!0;for(let p=0;p<e.length;p++){let m=e[p];if(m===`/`&&e[p+1]===`*`){let t=e.indexOf(`*/`,p+2);p=t===-1?e.length:t+1;continue}if(a&&m===`/`&&e[p+1]===`/`){let t=p;for(;t<e.length&&e[t]!==`
3
- `&&e[t]!==`\r`&&e[t]!==`\f`;)t++;o+=e.slice(s,p)+` `.repeat(t-p),s=t,p=t-1;continue}if(a&&f&&oe(e,p,n)>p&&r(/^--[\w-]*/.exec(e.slice(p,p+256))[0])){p=oe(e,p,n)-1,f=!1;continue}if(f=se(m,f,n),m===`\\`)p++;else if(m===`"`||m===`'`){let n=De(e,p);if(n){for(let t of n.lineBreaks)o+=`${e.slice(s,t)} `,s=t+1;p=n.close}else p=t(e,p,e.length)-1}else if(i(e,p)){let t=x(e,p,e.length,a);d=t===-1,p=(d?e.length:t)-1}else if(m===`(`)u++;else if(m===`)`&&u)u--;else if(u&&!a)continue;else m===`}`?c=Math.max(0,c-1):m===`{`&&(l=Math.max(l,++c))}return{source:s?o+e.slice(s):e,blockDepth:l,unclosedUrl:d}}function ke(e,t){return e.startsWith(t)&&!/[\w-]/.test(e[t.length]??``)}function Ae(e,t,n,r){return S(e,t,n,!0).some(t=>{let n=t.kind===`rule`||t.kind===`at-rule`?t.block:void 0;return W(e.slice(t.start,n?.[0]??t.end)).split(`
4
- `).slice(1).some(e=>r.some(t=>ke(e.trimStart(),t)))||n!==void 0&&Ae(e,n[0],n[1],r)})}async function I(t,n,r,i){let a=Ee(i),o=D((r.applyVariable??[`--at-apply`])||[]),{source:s,blockDepth:c,unclosedUrl:l}=Oe(t.original,ae(i),e=>!o.includes(e)),u=s.includes(`@apply`)||o.some(e=>s.includes(e)),d=s.includes(`@screen`),f=k(s)||O(s),p=we(s)?Ce(t,s,ae(i)):new Set;if(!u&&!f&&!d)return;if(a===`sass`)throw Error(`TeaCSS directives need braces; indented Sass is not supported, write it as SCSS${i?` in ${i}`:``}`);if(c>512)throw Error(`[@teacss] CSS blocks nest deeper than 512 levels${i?` in ${i}`:``}`);if(l)throw Error(`[@teacss] url() is not closed${i?` in ${i}`:``}`);let h=e(s,a!==void 0);if(h===`block`)throw Error(`CSS block is not closed${i?` in ${i}`:``}`);if(h===`bracket`&&a!==void 0)return;if(h&&a===void 0)throw Error(`CSS statement has no semicolon or block${i?` in ${i}`:``}`);if((a===`styl`||a===`stylus`)&&Ae(s,0,s.length,[`@apply`,`@screen`,...o]))throw Error(`TeaCSS directives need braces; indented Stylus is not supported, write it with braces${i?` in ${i}`:``}`);let g=new Map,_=[],v={options:r,applyVariable:o,generator:n,code:t,source:s,filename:i,preprocessor:a!==void 0,applyUtilities:g,hoisted:_,nesting:`top-level`,literalColors:!1,hasApply:u,hasScreen:d,hasFn:f,stripped:p};await B(v,S(s,0,s.length,v.preprocessor),void 0),_.length&&t.appendLeft(t.original.length,`\n${_.join(``)}`);let y=[...g].sort(([e],[t])=>e-t).flatMap(([,e])=>e),b=await m(n,y,i);b&&t.appendLeft(t.original.length,`\n${b}`)}const L=({source:e,applyVariable:t},[n,r])=>{let i=e.slice(n,r);return i.includes(`@apply`)||t.some(e=>i.includes(e))},R=e=>e===`top-level`||e===`scope`?`style-rule`:e;async function z(e,t,n){let{nesting:r,enclosing:i,literalColors:a}=e;Object.assign(e,t);try{await n()}finally{Object.assign(e,{nesting:r,enclosing:i,literalColors:a})}}async function B(e,t,n){for(let r of t)if(!e.stripped.has(r.start)){if(r.kind===`rule`)await Z(e,r);else if(r.kind===`at-rule`){if(r.name===`apply`&&!H(e,r))throw M(e.source.slice(...r.prelude),e.filename);await Le(e,r,n)}else if(r.kind===`declaration`){if(n===void 0&&e.hasApply&&e.applyVariable.includes(r.name))throw M(e.source.slice(...r.value),e.filename);await $(e,r)}else await V(e,r)}}async function V(e,{start:t,end:n,rulesets:r}){await Fe(e,[t,r[0]?.[0]??n]);for(let t of r)await G(e,t)}function H({source:e,preprocessor:t},{block:n,prelude:r}){return t&&!n&&e.startsWith(`:`,r[0])}function je({source:e},{name:t,prelude:n}){return t===`mixin`||t===`include`||e.slice(...n)===`:`}function U(e,n,r,i){let a=0;for(let o=n;o<e.length;o++){let n=e[o];if(n===`\\`)o++;else if(n===`"`||n===`'`)o=t(e,o,e.length)-1;else if(n===r)a++;else if(n===i&&--a===0)return o+1}return e.length}function W(e){let n=``,r=0;for(let i=0;i<e.length;){let a=e[i],o;if(a===`\\`){i+=2;continue}if(a===`"`||a===`'`)o=t(e,i,e.length);else if(a===`[`)o=U(e,i,`[`,`]`);else if((a===`#`||a===`@`)&&e[i+1]===`{`)o=U(e,i+1,`{`,`}`);else if(e.startsWith(`/*`,i)){let t=e.indexOf(`*/`,i+2);o=t===-1?e.length:t+2}else{i++;continue}n+=e.slice(r,i)+` `.repeat(o-i),r=o,i=o}return n+e.slice(r)}function Me(e){let t=W(e);return/^[.#]?[\w-]+\s*\(/.test(t)||/[\s)]when[\s(]/.test(t)||t.includes(`:extend(`)}function G(e,t){return z(e,{nesting:R(e.nesting),enclosing:void 0},()=>X(e,t,`&`))}function Ne({generator:e},t,n){if(/^screen$/i.test(t)){let t=v(n,e.config.theme);return t===void 0?void 0:`@media ${t}`}return/^(?:media|supports|container|layer|starting-style)$/i.test(t)?`@${t} ${n}`:void 0}function Pe({generator:e},t){let n=/^theme\(\s*(?:"([^"]*)"|'([^']*)')\s*[,)]/.exec(t);return n!==null&&re(n[1]??n[2],e.config.theme,!1)!==void 0&&g(t)}function K(e,[t,n]){let{source:r,hasFn:i,preprocessor:a}=e;return!i||!k(r.slice(t,n))?[]:p(r.slice(t,n),t,(t,n)=>n!==`.`&&n!==`#`&&(a?Pe(e,t):/^theme\(\s*["']/.test(t)))}function q(e,t){if(K(e,t).length)throw Error(`[@teacss] theme() cannot be resolved in "${e.source.slice(...t).trim()}"; use it in a declaration value, an at-rule condition or a preprocessor value${e.filename?` in ${e.filename}`:``}`)}function J({source:e,hasFn:t,filename:n},[r,i]){let a=e.slice(r,i);if(t&&O(a)&&p(a,r,(e,t)=>t!==`.`&&t!==`#`&&/^icon\(\s*["']/.test(e)).length)throw Error(`[@teacss] icon() cannot be resolved in "${a.trim()}"; use it in a declaration value${n?` in ${n}`:``}`)}async function Y(e,t,n,r){let i=e.source.slice(...t);for(let a of K(e,t).reverse()){let o=await F(e,a,n,r);o!==void 0&&(i=`${i.slice(0,a.loc.start.offset-t[0])}${o}${i.slice(a.loc.end.offset-t[0])}`)}return i}async function Fe(e,t){return e.preprocessor?Y(e,t,`value`,e.literalColors):(q(e,t),J(e,t),e.source.slice(...t))}async function Ie(e,t){let[n,r]=t.prelude,i=/^(?:include|mixin|function)$/.test(t.name)?/^(?:\s|\/\*[\s\S]*?\*\/)*[\w.-]+/.exec(e.source.slice(n,r))?.[0].length??0:0,a=/^(?:media|supports|container|custom-media|import)$/i.test(t.name);return e.preprocessor||J(e,[n+i,r]),!a&&!e.preprocessor?(q(e,[n+i,r]),e.source.slice(n,r)):e.source.slice(n,n+i)+await Y(e,[n+i,r],a?void 0:t.name,a||e.literalColors)}async function Le(e,t,n){let r=await Ie(e,t);e.hasScreen&&t.name===`screen`&&!H(e,t)&&xe(e,t);let{block:i}=t;if(!i)return;if(e.preprocessor&&je(e,t))return G(e,i);if(/keyframes$/i.test(t.name))return z(e,{nesting:`keyframes`,enclosing:e.enclosing},()=>X(e,i,void 0));let a=/^scope$/i.test(t.name),o=a?`:scope`:n,s;if(e.enclosing&&o===`&`){let n=Ne(e,t.name,r);n!==void 0&&(s=e.enclosing.within(n))}await z(e,{nesting:a&&!e.preprocessor&&e.nesting===`top-level`?`scope`:e.nesting,enclosing:s,literalColors:e.literalColors||Te(t.name)},()=>X(e,i,o))}async function X(e,t,n){if(n!==void 0&&e.hasApply&&L(e,t))return Q(e,{kind:`nested`,block:t,host:n,enclosing:e.enclosing});await B(e,S(e.source,t[0],t[1],e.preprocessor),n)}async function Z(e,t){let n=await Fe(e,t.prelude);if(e.preprocessor&&Me(n))return G(e,t.block);if(e.hasApply&&L(e,[t.start,t.end]))return Q(e,{kind:`rule`,rule:t,selector:n,enclosing:e.enclosing?.nested(n,e.preprocessor)});await z(e,{nesting:R(e.nesting),enclosing:e.enclosing},()=>B(e,S(e.source,t.block[0],t.block[1],e.preprocessor),`&`))}function Re({nesting:e},t){return t.enclosing||t.kind!==`rule`?t.enclosing:y(t.selector)?de.root(t.selector,t.rule.end,e):void 0}async function Q(e,t){let n=Re(e,t),r=n!==void 0,i=t.kind===`rule`?R(e.nesting):e.nesting,a=await ge(e,t,t=>r?Promise.resolve():z(e,{nesting:i,enclosing:void 0},()=>Z(e,t))),o=t.kind===`rule`?t.rule.block:t.block;await z(e,{nesting:i,enclosing:n},async()=>{for(let n of S(e.source,o[0],o[1],e.preprocessor))n.kind===`declaration`?e.applyVariable.includes(n.name)||await $(e,n):n.kind===`at-rule`?n.name!==`apply`&&await Le(e,n,t.kind===`rule`?`&`:t.host):n.kind===`call`?await V(e,n):r&&await Z(e,n)}),_e(e,t,n,a)}async function $(e,{name:t,value:n}){if(!e.hasFn)return;let r=e.source.slice(...n);if(k(r)||O(r))for(let i of p(r,n[0]))await F(e,i,t,e.literalColors)}async function ze(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await ce(e,n,r),s=await w(o.config),c=[],l=[];for(let e of o.config.content?.filesystem??[])e.startsWith(`!`)?l.push(e.slice(1)):c.push(e);let{files:u,sources:d}=a?{files:[],sources:a}:i?await i(c,l):{files:[],sources:[]},f=await le(s,u,d);return{layers:f.getLayers()||``,files:u,unknown:o.unknown,matched:f.matched.size,hasTeacss:o.hasTeacss,hasPreset:!!o.config.presets?.length}}const Be=/\/\*[\s\S]*?\*\//g;function Ve(e){let n=0;for(let r=0;r<e.length;r++){let a=e[r];if(a===`\\`){if(r===e.length-1)return!1;r++}else if(e.startsWith(`/*`,r)){let t=e.indexOf(`*/`,r+2);if(t<0)return!1;r=t+1}else if(a===`"`||a===`'`){let n=t(e,r,e.length);if(n-1===r||e[n-1]!==a)return!1;r=n-1}else if(i(e,r)){let t=x(e,r,e.length,!1);if(t<0)return!1;r=t-1}else if(a===`(`)n++;else if(a===`)`&&--n<0)return!1}return n===0}function He(e,t,n=`css`){let r=[],i=[],a=[],o=!0,s=0,c=n===`css`?e:ie(e,n);for(let l of j(e,!1,n)){o&&=!e.slice(s,l.start).replace(Be,``).trim(),s=l.end;let n=l.name.toLowerCase();if(n===`charset`&&l.terminator===`;`)r.push(e.slice(l.start,l.end)),a.push({start:l.start,end:l.end,replacement:``});else if((n===`import`||n===`layer`&&o)&&l.terminator===`;`)i.push(e.slice(l.start,l.end)),a.push({start:l.start,end:l.end,replacement:``});else if(n===`import`&&l.terminator===`eof`&&Ve(c.slice(l.start,l.end).trimEnd())){let t=l.start+c.slice(l.start,l.end).trimEnd().length;i.push(`${e.slice(l.start,t)};${e.slice(t,l.end).trimEnd()}`),a.push({start:l.start,end:l.end,replacement:``})}else(A.includes(l.name)||l.name===`presets`||l.name===`source`||l.name===`shortcut`||l.name===`safelist`)&&l.terminator===`;`||l.name===`custom`&&(l.terminator===`block`||l.terminator===`;`)?a.push({start:l.start,end:l.end,replacement:``}):(l.name===`teacss`&&l.prelude===``&&l.terminator!==`block`&&a.push({start:l.start,end:l.end,replacement:t}),o=!1)}a.sort((e,t)=>e.start-t.start);let l=``;s=0;for(let t of a)l+=e.slice(s,t.start)+t.replacement,s=t.end;l+=e.slice(s);let u=l.startsWith(``)?``:``;u&&(l=l.slice(1));let d=[...r,...i];return u+(d.length?`${d.join(`
5
- `)}\n`:``)+l}function Ue(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:T,transform:(t,n,r)=>I(t,r.generator,e,n)}}export{Ue as default,ze as generateEntry,He as spliceEntry,I as transformDirectives};
1
+ import{C as e,E as t,S as n,T as r,_ as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,v as S,w as C,x as w,y as T}from"./screen-core-BuUxmcvs.js";import{ROLE_DIRECTIVES as E,blankLineComments as D,cssDialectOf as O,resolveEntryConfig as ee,scanTopLevelAtRules as k,stylusTokenEnd as te}from"@teacss/config";import{createGenerator as ne,expandClassGroups as re,isCssId as ie,splitClassTokens as A,toArray as ae}from"@teacss/core";import{hasIconFn as j,hasThemeFn as M,transformThemeFn as oe,transformThemeString as se}from"@teacss/rule-helpers";import{generateSources as ce}from"@teacss/runtime/source-generation";var le=class e{moved;head;outer;depth;constructor(e,t,n,r){this.moved=e,this.head=t,this.outer=n,this.depth=r}static root(t){return new e({end:t,css:``,open:[]},``,void 0,0)}within(t){return new e(this.moved,t,this,this.depth+1)}place(e){let{moved:t}=this,n=[],r=this;for(;r.depth>0&&t.open[r.depth-1]!==r;)n.push(r),r=r.outer;t.css+=`}`.repeat(t.open.length-r.depth),t.open.length=r.depth;for(let e of n.reverse())t.css+=`${e.head}{`,t.open.push(e);t.css+=e}},ue=class e{hosts;inPlace;plain;nesting;constructor(e,t,n,r){this.hosts=e,this.inPlace=t,this.plain=n,this.nesting=r}static root(t,n,r){return new e([{condition:le.root(n),selector:t,element:``}],void 0,!1,r)}within(t){let n=this.hosts.map(e=>({...e,condition:e.condition.within(t)}));return new e(n,this.inPlace===void 0?void 0:`&`,this.plain,this.nesting)}nested(t,n){let r=i(t);if(!r)return;let{taking:a,others:o}=r,s,c=this.plain;if(this.hosts.every(e=>e.nested===void 0)){let e=this.hosts[0],{groups:t,plain:r}=m(e.selector);c=!n&&r.length>0,n&&r.length&&t.push({bases:r,element:``}),s=t.map(({bases:t,element:r})=>{let i=S(a,this.anchored(t,a),n);return{condition:e.condition,selector:T(i,r),nested:p(i),element:r}})}else{let e=p(a);s=this.hosts.map(t=>({condition:t.condition.within(t.nested??``),selector:T(a,t.element),nested:e,element:t.element}))}let l=c?t.trim():o.length?p(o):void 0;return new e(s,l,c,this.nesting)}anchored(e,t){return this.nesting===`style-rule`?y(e,t,!1):this.nesting===`scope`?y(e,t,!0):e}standaloneHosts(){let e=this.hosts.map((e,t)=>[t,e.selector]);return this.inPlace===void 0?e:[...e,[void 0,this.inPlace]]}};function de(e){return e.kind===`rule`?e.rule.block:e.block}function fe(e){return e.enclosing?e.enclosing.standaloneHosts():[[void 0,e.kind===`rule`?e.selector:e.host]]}function N(e,t){return Error(`[@teacss] @apply: "${e}" is outside a style rule or @scope${t?` in ${t}`:``}`)}function pe(e){return Error(`[@teacss] @apply: no token to apply${e?` in ${e}`:``}`)}function me(e,t){return Error(`[@teacss] @apply: "${e}" needs a selector or condition, which a @keyframes block cannot hold${t?` in ${t}`:``}`)}async function he(t,n,r){let i=[],a=[],o=!1,[s,c]=de(n);for(let l of e(t.source,s,c,t.preprocessor)){if(l.kind===`rule`){await r(l);continue}let e=await ve(t,n,l);e&&(i.push(e.consumedRange),a.push(...e.standalone),o||=e.hasInlineUtility)}if(n.kind===`rule`&&!o&&i.length>0){let e=s;i.every(([n,r])=>{let i=!t.source.slice(e,n).trim();return e=r,i})&&!t.source.slice(e,c).trim()&&t.code.remove(n.rule.start,n.rule.end)}return a}function ge({code:e},t,n,r){let i=t.kind===`rule`?t.rule.end:t.block[1];if(t.kind===`rule`&&!t.enclosing&&n){let{moved:t}=n.hosts[0].condition;t.css&&(e.appendLeft(t.end,t.css+`}`.repeat(t.open.length)),t.css=``,t.open=[])}for(let n of r)n.moved!==void 0&&t.enclosing?t.enclosing.hosts[n.moved].condition.place(n.css):e.appendLeft(i,n.css)}const _e=e=>e===`style-rule`||e===`keyframes`;async function ve(e,t,n){let{code:r,source:i,generator:o,applyVariable:f,options:p,filename:m,applyUtilities:h,hoisted:g,nesting:v}=e,y,b;if(n.kind===`at-rule`&&n.name===`apply`)b=n.prelude[1],y=F(i.slice(...n.prelude));else if(n.kind===`declaration`&&f.includes(n.name))b=i[n.end-1]===`;`?n.end-1:n.end,y=A(F(i.slice(n.value[0],b).trim())).map(e=>F(e)).join(` `);else return;y=be(y),y=oe(y,o.config.theme,p.throwOnMissing??!0,a(o));let x=A(re(y));if(!x.length)throw pe(m);let S=await u(x,o),C=c(S);if(C.length&&(p.throwOnMissing??!0))throw Error(`${s(C)}${m?` in ${m}`:``}`);let w=_(S,o.parentOrders,o.config.layers,e=>o.sheetOrder(e));h.set(n.start,S.flatMap(([,e])=>e??[]));let T=[n.start,i[n.end-1]===`;`?n.end:b];if(!w.length)return r.remove(...T),{consumedRange:T,hasInlineUtility:!1,standalone:[]};let E,D=!1,O=[];for(let e of w)if(e.kind===`top-level`)v===`top-level`||v===`scope`?O.push({css:e.body}):P(g,e.body);else if(e.kind===`standalone`){E??=fe(t).map(([e,t])=>[e,l(t)]);let n=e.selector?.startsWith(`@`)??!1;for(let[t,r]of E){let i=d(r,e,m);if(i){if(v===`keyframes`&&!n)throw me(y,m);n&&_e(v)?P(g,i):O.push({css:i,moved:t})}}}else D=!0,r.appendLeft(n.start,e.body);return r.remove(...T),{consumedRange:T,hasInlineUtility:D,standalone:O}}function P(e,t){for(let n of ye(t))e.includes(n)||e.push(n)}function ye(t){if(r(t,!1)!==void 0)return[t];try{return e(t,0,t.length,!1,!0).map(e=>t.slice(e.start,e.end))}catch(e){if(e instanceof o)return[t];throw e}}function F(e){return e.replace(/^(['"])([\s\S]*)\1$/,`$2`)}function be(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function I({code:e,source:t,generator:n,options:r,applyUtilities:i},a,o,s){let c=await f(n,a,(e,n)=>t.slice(e,n),r.throwOnMissing??!0,s);if(c!==void 0)return e.overwrite(a.loc.start.offset,a.loc.end.offset,c),o!==void 0&&c.includes(`var(`)&&i.set(a.loc.start.offset,[[0,void 0,`${o}:${c};`,void 0,void 0,void 0,void 0]]),c}function xe({code:e,source:t,generator:n},r){let i=b(t.slice(...r.prelude),n.config.theme);i&&e.overwrite(r.start,r.block?r.block[0]-1:r.prelude[1],`@media ${i}`)}const Se=new Set([`presets`,`source`,`shortcut`,`safelist`,...E]);function Ce(e,t,n=`css`){let r=new Set;if(!t.includes(`@`))return r;let i=k(t,!1,n);if(i.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))return r;for(let t of i)(Se.has(t.name)?t.terminator===`;`:t.name===`custom`&&(t.terminator===`block`||t.terminator===`;`))&&(e.remove(t.start,t.end),r.add(t.start));return r}function we(e){return E.some(t=>e.includes(`@${t}`))||e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}function Te(e){return/^(?:property|font-face|font-palette-values|counter-style)$/i.test(e)}function Ee(e){return e?.split(`?`).flatMap(e=>/\.(scss|sass|less|styl|stylus)$/i.exec(e)?.[1]?.toLowerCase()??[])[0]}function De(e,t){let n=[];for(let r=t+1;r<e.length;r++){let i=e[r];if(i===`\\`)r++;else if(i===e[t])return{close:r,lineBreaks:n};else(i===`
2
+ `||i===`\r`||i===`\f`)&&n.push(r)}}function Oe(e,r,i){let a=r!==`css`,o=a?D(e,r,i):e,s=``,c=0;for(let e=0;e<o.length;e++){let r=o[e];if(r===`/`&&o[e+1]===`*`){let t=o.indexOf(`*/`,e+2);e=t===-1?o.length:t+1}else if(r===`\\`)e++;else if(r===`"`||r===`'`){let t=De(o,e);if(t){for(let e of t.lineBreaks)s+=`${o.slice(c,e)} `,c=e+1;e=t.close}else e=C(o,e,o.length)-1}else if(n(o,e)){let n=t(o,e,o.length,a);e=(n===-1?o.length:n)-1}}return c?s+o.slice(c):o}function ke(e,t){return e.startsWith(t)&&!/[\w-]/.test(e[t.length]??``)}function L(t,n,r,i){return e(t,n,r,`stylus`).some(e=>{let n=e.kind===`rule`||e.kind===`at-rule`?e.block:void 0;return K(t.slice(e.start,n?.[0]??e.end)).split(`
3
+ `).slice(1).some(e=>i.some(t=>ke(e.trimStart(),t)))||n!==void 0&&L(t,n[0],n[1],i)})}async function R(t,n,i,a){let s=Ee(a),c=ae((i.applyVariable??[`--at-apply`])||[]),l=Oe(t.original,O(a),e=>e===`--at-apply`||c.includes(e)),u=l.includes(`@apply`)||c.some(e=>l.includes(e)),d=l.includes(`@screen`),f=M(l)||j(l),p=we(l)?Ce(t,l,O(a)):new Set;if(!u&&!f&&!d)return;if(s===`sass`)throw Error(`TeaCSS directives need braces; indented Sass is not supported, write it as SCSS${a?` in ${a}`:``}`);let m=s===void 0?!1:s===`styl`||s===`stylus`?`stylus`:!0,h=r(l,m);if(h)throw Error(`${h}${a?` in ${a}`:``}`);if((s===`styl`||s===`stylus`)&&L(l,0,l.length,[`@apply`,`@screen`,...c]))throw Error(`TeaCSS directives need braces; indented Stylus is not supported, write it with braces${a?` in ${a}`:``}`);let _=new Map,v=[],y={options:i,applyVariable:c,generator:n,code:t,source:l,filename:a,preprocessor:m,applyUtilities:_,hoisted:v,nesting:`top-level`,literalColors:!1,hasApply:u,hasScreen:d,hasFn:f,stripped:p,depth:0};try{await H(y,e(l,0,l.length,y.preprocessor,!0),void 0)}catch(e){throw e instanceof o?Error(`${e.message}${a?` in ${a}`:``}`):e}v.length&&t.appendLeft(t.original.length,`\n${v.join(``)}`);let b=[..._].sort(([e],[t])=>e-t).flatMap(([,e])=>e),x=await g(n,b,a);x&&t.appendLeft(t.original.length,`\n${x}`)}const Ae=({source:e,applyVariable:t},[n,r])=>{let i=e.slice(n,r);return i.includes(`@apply`)||t.some(e=>i.includes(e))},z=e=>e===`top-level`||e===`scope`?`style-rule`:e;async function B(e,t,n){let{nesting:r,enclosing:i,literalColors:a}=e;Object.assign(e,t);try{await n()}finally{Object.assign(e,{nesting:r,enclosing:i,literalColors:a})}}async function V(e,t){if(e.depth>512)throw Error(`CSS blocks nest deeper than 512 levels${e.filename?` in ${e.filename}`:``}`);e.depth++;try{await t()}finally{e.depth--}}async function H(e,t,n){for(let r of t)if(!e.stripped.has(r.start)){if(r.kind===`rule`)await Q(e,r);else if(r.kind===`at-rule`){if(r.name===`apply`&&!W(e,r))throw N(e.source.slice(...r.prelude),e.filename);await ze(e,r,n)}else if(r.kind===`declaration`){if(n===void 0&&e.hasApply&&e.applyVariable.includes(r.name))throw N(e.source.slice(...r.value),e.filename);await $(e,r)}else await U(e,r)}}function U(e,t){return V(e,()=>je(e,t))}async function je(e,{start:t,end:n,rulesets:r}){await Le(e,[t,r[0]?.[0]??n]);for(let t of r)await q(e,t)}function W({source:e,preprocessor:t},{block:n,prelude:r}){return t&&!n&&e.startsWith(`:`,r[0])}function Me({source:e},{name:t,prelude:n}){return t===`mixin`||t===`include`||e.slice(...n)===`:`}function G(e,t,n,r){let i=0;for(let a=t;a<e.length;a++){let t=e[a];if(t===`\\`)a++;else if(t===`"`||t===`'`)a=C(e,a,e.length)-1;else if(t===n)i++;else if(t===r&&--i===0)return a+1}return e.length}function K(e){let t=``,n=0;for(let r=0;r<e.length;){let i=e[r],a;if(i===`\\`){r+=2;continue}if(i===`"`||i===`'`)a=C(e,r,e.length);else if(i===`[`)a=G(e,r,`[`,`]`);else if((i===`#`||i===`@`)&&e[r+1]===`{`)a=G(e,r+1,`{`,`}`);else if(i===`{`&&te(e,r,e.length)!==void 0)a=G(e,r,`{`,`}`);else if(e.startsWith(`/*`,r)){let t=e.indexOf(`*/`,r+2);a=t===-1?e.length:t+2}else{r++;continue}t+=e.slice(n,r)+` `.repeat(a-r),n=a,r=a}return t+e.slice(n)}function Ne(e){let t=K(e);return/^[.#]?[\w-]+\s*\(/.test(t)||/[\s)]when[\s(]/.test(t)||t.includes(`:extend(`)}function q(e,t){return B(e,{nesting:z(e.nesting),enclosing:void 0},()=>Z(e,t,`&`))}function Pe({generator:e},t,n){if(/^screen$/i.test(t)){let t=b(n,e.config.theme);return t===void 0?void 0:`@media ${t}`}return/^(?:media|supports|container|layer|starting-style)$/i.test(t)?`@${t} ${n}`:void 0}function Fe({generator:e},t){let n=/^theme\(\s*(?:"([^"]*)"|'([^']*)')\s*[,)]/.exec(t);return n!==null&&se(n[1]??n[2],e.config.theme,!1)!==void 0&&v(t)}function J(e,[t,n]){let{source:r,hasFn:i,preprocessor:a}=e;return!i||!M(r.slice(t,n))?[]:h(r.slice(t,n),t,(t,n)=>n!==`.`&&n!==`#`&&(a?Fe(e,t):/^theme\(\s*["']/.test(t)))}function Y(e,t){if(J(e,t).length)throw Error(`[@teacss] theme() cannot be resolved in "${e.source.slice(...t).trim()}"; use it in a declaration value, an at-rule condition or a preprocessor value${e.filename?` in ${e.filename}`:``}`)}function X({source:e,hasFn:t,filename:n},[r,i]){let a=e.slice(r,i);if(t&&j(a)&&h(a,r,(e,t)=>t!==`.`&&t!==`#`&&/^icon\(\s*["']/.test(e)).length)throw Error(`[@teacss] icon() cannot be resolved in "${a.trim()}"; use it in a declaration value${n?` in ${n}`:``}`)}async function Ie(e,t,n,r){let i=e.source.slice(...t);for(let a of J(e,t).reverse()){let o=await I(e,a,n,r);o!==void 0&&(i=`${i.slice(0,a.loc.start.offset-t[0])}${o}${i.slice(a.loc.end.offset-t[0])}`)}return i}async function Le(e,t){return e.preprocessor?Ie(e,t,`value`,e.literalColors):(Y(e,t),X(e,t),e.source.slice(...t))}async function Re(e,t){let[n,r]=t.prelude,i=/^(?:include|mixin|function)$/.test(t.name)?/^(?:\s|\/\*[\s\S]*?\*\/)*[\w.-]+/.exec(e.source.slice(n,r))?.[0].length??0:0,a=/^(?:media|supports|container|custom-media|import)$/i.test(t.name);return e.preprocessor||X(e,[n+i,r]),!a&&!e.preprocessor?(Y(e,[n+i,r]),e.source.slice(n,r)):e.source.slice(n,n+i)+await Ie(e,[n+i,r],a?void 0:t.name,a||e.literalColors)}function ze(e,t,n){return V(e,()=>Be(e,t,n))}async function Be(e,t,n){let r=await Re(e,t);e.hasScreen&&t.name===`screen`&&!W(e,t)&&xe(e,t);let{block:i}=t;if(!i)return;if(e.preprocessor&&Me(e,t))return q(e,i);if(/keyframes$/i.test(t.name))return B(e,{nesting:`keyframes`,enclosing:e.enclosing},()=>Z(e,i,void 0));let a=/^scope$/i.test(t.name),o=a?`:scope`:n,s;if(e.enclosing&&o===`&`){let n=Pe(e,t.name,r);n!==void 0&&(s=e.enclosing.within(n))}await B(e,{nesting:a&&!e.preprocessor&&e.nesting===`top-level`?`scope`:e.nesting,enclosing:s,literalColors:e.literalColors||Te(t.name)},()=>Z(e,i,o))}async function Z(e,t,n){if(n!==void 0&&e.hasApply&&Ae(e,t))return Ue(e,{kind:`nested`,block:t,host:n,enclosing:e.enclosing});await H(e,w(e.source,t[0],t[1],e.preprocessor),n)}function Q(e,t){return V(e,()=>Ve(e,t))}async function Ve(t,n){let r=await Le(t,n.prelude);if(t.preprocessor&&Ne(r))return q(t,n.block);if(t.hasApply&&Ae(t,[n.start,n.end]))return Ue(t,{kind:`rule`,rule:n,selector:r,enclosing:t.enclosing?.nested(r,t.preprocessor!==!1)});await B(t,{nesting:z(t.nesting),enclosing:t.enclosing},()=>H(t,e(t.source,n.block[0],n.block[1],t.preprocessor),`&`))}function He({nesting:e},t){return t.enclosing||t.kind!==`rule`?t.enclosing:x(t.selector)?ue.root(t.selector,t.rule.end,e):void 0}async function Ue(t,n){let r=He(t,n),i=r!==void 0,a=n.kind===`rule`?z(t.nesting):t.nesting,o=await he(t,n,e=>i?Promise.resolve():B(t,{nesting:a,enclosing:void 0},()=>Q(t,e))),s=n.kind===`rule`?n.rule.block:n.block;await B(t,{nesting:a,enclosing:r},async()=>{for(let r of e(t.source,s[0],s[1],t.preprocessor))r.kind===`declaration`?t.applyVariable.includes(r.name)||await $(t,r):r.kind===`at-rule`?r.name!==`apply`&&await ze(t,r,n.kind===`rule`?`&`:n.host):r.kind===`call`?await U(t,r):i&&await Q(t,r)}),ge(t,n,r,o)}async function $(e,{name:t,value:n}){if(!e.hasFn)return;let r=e.source.slice(...n);if(M(r)||j(r))for(let i of h(r,n[0]))await I(e,i,t,e.literalColors)}async function We(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await ee(e,n,r),s=await ne(o.config),c=[],l=[];for(let e of o.config.content?.filesystem??[])e.startsWith(`!`)?l.push(e.slice(1)):c.push(e);let{files:u,sources:d}=a?{files:[],sources:a}:i?await i(c,l):{files:[],sources:[]},f=await ce(s,u,d);return{layers:f.getLayers()||``,files:u,unknown:o.unknown,matched:f.matched.size,hasTeacss:o.hasTeacss,hasPreset:!!o.config.presets?.length}}const Ge=/\/\*[\s\S]*?\*\//g;function Ke(e){let r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`){if(i===e.length-1)return!1;i++}else if(e.startsWith(`/*`,i)){let t=e.indexOf(`*/`,i+2);if(t<0)return!1;i=t+1}else if(a===`"`||a===`'`){let t=C(e,i,e.length);if(t-1===i||e[t-1]!==a)return!1;i=t-1}else if(n(e,i)){let n=t(e,i,e.length,!1);if(n<0)return!1;i=n-1}else if(a===`(`)r++;else if(a===`)`&&--r<0)return!1}return r===0}function qe(e,t,n=`css`){let r=[],i=[],a=[],o=!0,s=0,c=n===`css`?e:D(e,n);for(let l of k(e,!1,n)){o&&=!e.slice(s,l.start).replace(Ge,``).trim(),s=l.end;let n=l.name.toLowerCase();if(n===`charset`&&l.terminator===`;`)r.push(e.slice(l.start,l.end)),a.push({start:l.start,end:l.end,replacement:``});else if((n===`import`||n===`layer`&&o)&&l.terminator===`;`)i.push(e.slice(l.start,l.end)),a.push({start:l.start,end:l.end,replacement:``});else if(n===`import`&&l.terminator===`eof`&&Ke(c.slice(l.start,l.end).trimEnd())){let t=l.start+c.slice(l.start,l.end).trimEnd().length;i.push(`${e.slice(l.start,t)};${e.slice(t,l.end).trimEnd()}`),a.push({start:l.start,end:l.end,replacement:``})}else(E.includes(l.name)||l.name===`presets`||l.name===`source`||l.name===`shortcut`||l.name===`safelist`)&&l.terminator===`;`||l.name===`custom`&&(l.terminator===`block`||l.terminator===`;`)?a.push({start:l.start,end:l.end,replacement:``}):(l.name===`teacss`&&l.prelude===``&&l.terminator!==`block`&&a.push({start:l.start,end:l.end,replacement:t}),o=!1)}a.sort((e,t)=>e.start-t.start);let l=``;s=0;for(let t of a)l+=e.slice(s,t.start)+t.replacement,s=t.end;l+=e.slice(s);let u=l.startsWith(``)?``:``;u&&(l=l.slice(1));let d=[...r,...i];return u+(d.length?`${d.join(`
4
+ `)}\n`:``)+l}function Je(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:ie,transform:(t,n,r)=>R(t,r.generator,e,n)}}export{Je as default,We as generateEntry,qe as spliceEntry,R as transformDirectives};
@@ -0,0 +1,2 @@
1
+ import{stylusInterpolationEnd as e,stylusTokenEnd as t}from"@teacss/config";import{DEFAULT_LAYERS as n,LAYER_UTILITIES as r,clone as i,comparableWidth as a,compareParentAtRules as o,createGenerator as s,isPseudoElementChain as c,notNull as l,toArray as u}from"@teacss/core";import{List as d,clone as f,generate as p,ident as m,parse as h,walk as g}from"css-tree";import{calcMaxWidthBySize as _,findCssFunctionStart as ee,hasIconFn as te,hasThemeFn as ne,isCssNameCharacter as re,isCssWhitespace as ie,transformThemeFn as ae,transformThemeString as oe}from"@teacss/rule-helpers";function v(e,t){return(e[t]===`#`||e[t]===`@`)&&e[t+1]===`{`}function y(e,t,n){for(let r=t+1;r<n;r++){let n=e[r];if(n===`\\`)r++;else if(n===e[t])return r+1;else if(n===`
2
+ `||n===`\r`||n===`\f`)return r}return n}function b(e,t){if(e[t]!==`u`&&e[t]!==`U`||e.slice(t,t+4).toLowerCase()!==`url(`)return!1;let n=e[t-1];if(n===`.`||n===`#`||re(n))return!1;let r=t+4;for(;ie(e[r]);)r++;return e[r]!==`"`&&e[r]!==`'`}function x(e,t,n,r){let i=0;for(let a=t+4;a<n;a++){let t=e[a];if(t===`\\`)a++;else if(r&&v(e,a))i++,a++;else if(i)t===`}`?i--:(t===`"`||t===`'`)&&(a=y(e,a,n)-1);else if(t===`)`)return a+1}return-1}function S(e,t,n,r){let i=e[t];if(i===`\\`)return Math.min(t+2,n);if(i===`"`||i===`'`)return y(e,t,n);if(i===`/`&&e[t+1]===`*`){let r=e.indexOf(`*/`,t+2);return r===-1||r+2>n?n:r+2}if(b(e,t)){let i=x(e,t,n,r);return i===-1?n:i}return t}function C(e){if(e===`(`)return`)`;if(e===`[`)return`]`}function w(t,n,r,i,a){let o=[],s=n;for(;s<r;){let n=S(t,s,r,a);if(n!==s){s=n;continue}if(a===`stylus`){let n=e(t,s,r);if(n!==void 0){s=n+1;continue}}if(a&&v(t,s)){o.push(`}`),s+=2;continue}let c=t[s],l=C(c);if(l)o.push(l);else if(i&&c===`{`)o.push(`}`);else if(o.at(-1)===c)o.pop();else if(!o.length){if(c===`{`)return{type:`block`,at:s};if(c===`;`)return{type:`semicolon`,at:s};if(c===`}`)return{type:`end`,at:s}}s++}return{type:`end`,at:r,open:o.length>0}}function T(t,n,r,i){let a=[],o=1,s=n+1;for(;s<r;){let n=S(t,s,r,i);if(n!==s){s=n;continue}if(i===`stylus`){let n=e(t,s,r);if(n!==void 0){s=n+1;continue}}if(i&&v(t,s)){a.push(`}`),s+=2;continue}let c=t[s],l=C(c);if(l)a.push(l);else if(a.at(-1)===c)a.pop();else if(!a.length){if(c===`{`)o++;else if(c===`}`&&--o===0)return s}s++}return r}function E(t,n,r,i){let a=[],o=n;for(;o<r;){let n=S(t,o,r,i);if(n!==o){o=n;continue}if(i===`stylus`){let n=e(t,o,r);if(n!==void 0){o=n+1;continue}}if(i&&v(t,o)){a.push(`}`),o+=2;continue}let s=t[o],c=C(s);if(c)a.push(c);else if(a.at(-1)===s)a.pop();else if(!a.length&&s===`:`)return o;o++}return-1}function D(e,t,n){let r=e.slice(t,n),i=t+r.length-r.trimStart().length;return[i,i+r.trim().length]}function se(e,[t,n]){let r=/\s*!\s*important$/i.exec(e.slice(t,n));return r?[t,t+r.index]:[t,n]}function O(e,t,n,r){let i=E(e,t,n,r);if(i===-1)return`declaration requires a property name and colon`;let[a,o]=D(e,t,i),s=D(e,i+1,n),c=e.slice(a,o),l=c.startsWith(`--`);if(!c||s[0]===s[1]&&!l)return`declaration property name and value must be non-empty`;let u=se(e,s);return u[0]===u[1]&&!l?`declaration value before !important must be non-empty`:{name:c,value:u}}function ce(e,t,n,r){let i=O(e,t,n,r);return typeof i==`string`?void 0:i}function le(t,n,r,i){let a=[],o=n;for(;o<r;){let n=S(t,o,r,!0);if(n!==o){o=n;continue}let s=i===`stylus`?e(t,o,r):void 0;if(s!==void 0){o=s+1;continue}if(v(t,o)){o=T(t,o+1,r,i)+1;continue}if(t[o]===`{`){let e=T(t,o,r,i);a.push([o+1,e]),o=e}o++}return a}function k(e,t,n){let r=t;for(;r<n&&/[\w-]/.test(e[r]);)r++;return r}var A=class{message;constructor(e){this.message=e}};const j=e=>{throw new A(e)};function M(e,t,n){let r=e.indexOf(`*/`,t+2);return r===-1||r+2>n?j(`unclosed CSS comment`):r+2}function ue(e){return/[A-Za-z0-9_\\-]/.test(e)||e.charCodeAt(0)>=128}function N(e,t,n){if(e[t]!==`(`||t<3||e.slice(t-3,t).toLowerCase()!==`url`||t>3&&ue(e[t-4]))return;let r=t+1;for(;r<n&&/[ \t\n\f\r]/.test(e[r]);)r++;if(e[r]===`"`||e[r]===`'`)return;let i=0;for(let r=t;r<n;r++)if(e[r]===`\\`)r++;else if(e[r]===`(`)i++;else if(e[r]===`)`&&--i===0)return r+1;return n}function P(t,n,r,i){let a=[],o,s=1,c=n;for(;c<r;){let n=t[c];if(o){n===`\\`?c+=2:(n===o&&(o=void 0),c++);continue}if(n===`\\`){c+=2;continue}if(n===`/`&&t[c+1]===`*`){c=M(t,c,r);continue}if(i.interpolation===`stylus`){let n=e(t,c,r);if(n!==void 0){c=n+1;continue}}if(i.interpolation&&v(t,c)){a.push(`}`),c+=2;continue}let l=N(t,c,r);if(l!==void 0){c=l;continue}if(n===`"`||n===`'`)o=n;else if(n===`(`||n===`[`)a.push(n===`(`?`)`:`]`);else if(!i.block&&i.nestBraces&&n===`{`)a.push(`}`);else if(a.at(-1)===n)a.pop();else if(!a.length&&i.block){if(n===`{`&&++s>512&&j(`CSS blocks nest deeper than 512 levels`),n===`}`&&--s===0)return{at:c,type:`block`,open:!1,quoted:!1}}else if(!a.length){if(n===`{`)return{at:c,type:`block`,open:!1,quoted:!1};if(n===`;`)return{at:c,type:`semicolon`,open:!1,quoted:!1};n===`}`&&j(`unexpected closing brace`)}c++}return i.block&&j(`CSS block is not closed`),{at:r,type:`end`,open:a.length>0,quoted:o!==void 0}}function de(e,t,n,r){return ce(e,t,n,r)!==void 0}function fe(t,n,r,i){let a;for(let o=n;o<r;o++){let n=t[o];a?n===`\\`?o++:n===a&&(a=void 0):n===`\\`?o++:n===`/`&&t[o+1]===`*`?o=M(t,o,r)-1:i===`stylus`&&e(t,o,r)!==void 0?o=e(t,o,r):v(t,o)?o=P(t,o+2,r,{block:!0,nestBraces:!1,interpolation:i}).at:N(t,o,r)===void 0?n===`"`||n===`'`?a=n:n===`{`&&(o=P(t,o+1,r,{block:!0,nestBraces:!1,interpolation:i}).at):o=N(t,o,r)-1}}function pe(e,t){let n=e.length,r=0;try{for(;r<n;){if(/\s/.test(e[r])){r++;continue}if(e.startsWith(`/*`,r)){r=M(e,r,n);continue}e[r]===`}`&&j(`unexpected closing brace`);let i=e.startsWith(`@apply`,r)&&k(e,r+1,n)===r+6,a=P(e,r,n,{block:!1,nestBraces:i,interpolation:t});a.type===`end`&&!t&&(e[r]!==`@`||a.open||a.quoted)&&j(`CSS statement has no semicolon or block`),t&&a.type!==`block`&&(e[r]!==`@`||v(e,r))&&!de(e,r,a.at,t)&&fe(e,r,a.at,t);let o=a.type===`block`?P(e,a.at+1,n,{block:!0,nestBraces:!1,interpolation:t}).at+1:a.at+1;!t&&e[r]===`@`&&k(e,r+1,a.at)===r+1&&j(`at-rule name is empty`),!t&&e[r]!==`@`&&a.type!==`block`&&j(`qualified rule requires a block`),r=o}}catch(e){if(e instanceof A)return e.message;throw e}}function F(e,t,n,r,i=!1){let a=[],o=t;for(;o<n;){if(e.startsWith(`/*`,o)){o=S(e,o,n,r);continue}if(/[\s;}]/.test(e[o])){if(i&&!r&&e[o]===`;`)throw new A(`qualified rule requires a block`);o++;continue}let t=o,s=w(e,t,n,e.startsWith(`@apply`,t)&&k(e,t+1,n)===t+6,r);!i&&s.type===`block`&&e.startsWith(`--`,t)&&E(e,t,s.at,r)!==-1&&(s=w(e,t,n,!0,r));let c=s.at,l=s.type===`semicolon`?c+1:c,u;if(s.type===`block`){let t=T(e,c,n,r);u=[c+1,t],l=Math.min(t+1,n)}if(o=l,e[t]===`@`&&!(r&&v(e,t))){let n=k(e,t+1,c);if(n===t+1&&i&&!r)throw new A(`at-rule name is empty`);n>t+1&&a.push({kind:`at-rule`,start:t,end:l,name:e.slice(t+1,n),prelude:D(e,n,c),block:u})}else if(u)a.push({kind:`rule`,start:t,end:l,prelude:D(e,t,c),block:u});else if(i&&!r)throw new A(`qualified rule requires a block`);else{let n=O(e,t,c,r);if(typeof n!=`string`)a.push({kind:`declaration`,start:t,end:l,...n});else if(r)a.push({kind:`call`,start:t,end:l,rulesets:le(e,t,c,r)});else throw new A(n)}}return a}function me(e,t,n,r){try{return F(e,t,n,r,!0)}catch(i){if(!(i instanceof A))throw i;return F(e,t,n,r)}}function I(e){if(e.type!==`PseudoClassSelector`||e.name!==`is`)return!1;let t=e.children?.first;if(t?.type!==`SelectorList`)return!1;let n=t.children.toArray().map(e=>p(e));return n.length===2&&/^:root:where\(html[:[]/.test(n[0])&&n[1]===`${n[0].slice(5)} *`}function L(e,t,n){if(!/\.module\.(?:css|postcss|scss|sass|less|styl|stylus)$/i.test(t?.split(/[?#]/,1)[0]??``)||!n&&!/@scope\s*\(|:root:where\(html/i.test(e))return e;let r=h(e),i=e=>{e.children=e.children.map(e=>h(`:global(${p(e)})`,{context:`selector`}))};return g(r,{enter(e,t,r){if(e.type===`PseudoClassSelector`&&e.name===`global`)return this.skip;if(!n&&I(e)){let n=h(`:global(${p(e)})`,{context:`selector`});return r.replace(t,n.children),this.skip}if(e.type===`Scope`){e.root?.type===`SelectorList`&&i(e.root),e.limit?.type===`SelectorList`&&i(e.limit);return}n&&e.type===`Rule`&&(this.atrule&&/(?:^|-)keyframes$/i.test(this.atrule.name)||e.prelude.type===`SelectorList`&&i(e.prelude))}}),p(r)}const he=/([0-9a-f]*)/g;function ge(e,t){let n=0;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`\\`)r++;else if(t===`"`||t===`'`)r=y(e,r,e.length)-1;else if(t===`{`)n++;else if(t===`}`&&--n===0)return r+1}}function _e(e){if(!e.includes(`{`))return e;let n=``,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`)i++;else if(a===`"`||a===`'`)i=y(e,i,e.length)-1;else if(v(e,i)||t(e,i,e.length)!==void 0){let a=t(e,i,e.length),o=a===void 0?ge(e,i):a+1;if(o===void 0)return e;let s=Array.from({length:o-i},(t,n)=>e.charCodeAt(i+n).toString(16).padStart(4,`0`));n+=`${e.slice(r,i)}${s.join(``)}`,r=o,i=o-1}}return n+e.slice(r)}function R(e){return e.replace(he,(e,t)=>String.fromCharCode(...t.match(/.{4}/g).map(e=>Number.parseInt(e,16))))}function z(e){try{return h(_e(e),{context:`selectorList`})}catch{let t={type:`TypeSelector`,name:e.trim()},n={type:`Selector`,children:new d().fromArray([t])};return{type:`SelectorList`,children:new d().fromArray([n])}}}function ve(e){let t=z(e);return{prelude:t,selector:R(p(t)),replacementSelector:e}}function ye(e){return K(z(e)).some(e=>W(e)<e.length)}function be(e){try{let t=h(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function xe(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function Se(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function Ce(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function we(e){let t=!1,n=0,r,i=``;for(let a=0;a<e.length;a++){let o=e[a];if(t){o===`*`&&e[a+1]===`/`&&(t=!1,a++);continue}if(r){o===`\\`?a++:o===r&&(r=void 0);continue}if(o===`/`&&e[a+1]===`*`){t=!0,a++;continue}if(o===`\\`){a++;continue}if(o===`"`||o===`'`){r=o;continue}if(!/\s/.test(o)||e[a+1]!==`$`||e[a+2]!==`$`||!/\s/.test(e[a+3]??``))continue;let s=a+4;for(;s<e.length&&/\s/.test(e[s]);)s++;i+=`${e.slice(n,a)} `,n=s,a=s-1}return n?i+e.slice(n):e}function Te(e){let t=[],n=0,r=!1,i=0,a,o=0;for(let s=0;s<e.length;s++){let c=e[s];r?c===`*`&&e[s+1]===`/`&&(r=!1,s++):a?c===`\\`?s++:c===a&&(a=void 0):c===`/`&&e[s+1]===`*`?(r=!0,s++):c===`"`||c===`'`?a=c:c===`(`?i++:c===`)`?i>0&&i--:c===`[`?n++:c===`]`?n>0&&n--:n===0&&i===0&&e.startsWith(` $$ `,s)&&(t.push(e.slice(o,s)),s+=3,o=s+1)}return t.push(e.slice(o)),t}function Ee(e){let t=new Set,n=[];for(let i=e.length-1;i>=0;i--){let[,a,o,s,c]=e[i],l=JSON.stringify([c?.layer??r,a,s,o,!!c?.noMerge]);t.has(l)||(t.add(l),n.push(e[i]))}return n.reverse()}function De(e){return[...e].sort((e,t)=>e[0]-t[0])}function Oe(e,t,i=n,a=De){let s=e=>Object.hasOwn(i,e)?i[e]??0:0,c=new Map;for(let t of e.flatMap(([,e])=>e??[]).filter(l)){let e=t[4]?.layer??r,n=t[3]??``,i=JSON.stringify([e,n]),a=c.get(i);a?a.utilities.push(t):c.set(i,{layer:e,parent:n,utilities:[t]})}let u=[...c.values()].sort((e,n)=>{let r=e.layer===n.layer?0:e.layer<n.layer?-1:1;return s(e.layer)-s(n.layer)||r||o(t,e.parent,n.parent)}).flatMap(e=>Ee(a(e.utilities)));if(!u.length)return[];let d=e.map(([e])=>e),f=[],p=[],m,h;for(let e of u){let t=e[4]?.layer??r;if(t!==m&&(m=t,p=[],h=void 0),!h&&p.length===64){h=new Map;for(let e of p)H(h,e)}let n=e[1],i=n?.includes(`.\\-`)?ke(n,d)??n:n,a=e[3],o=i===void 0&&a===void 0&&be(e[2]),s=h?h.get(a)?.get(i)?.get(o):p.find(e=>e.value[1]===i&&e.value[3]===a&&e.topLevel===o);if(s){s.value[2]+=e[2];continue}let c=[...e];c[1]=i;let l={topLevel:o,value:c};f.push(l),p.push(l),h&&H(h,l)}return f.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&we(t),o=!!(a&&i?.noMerge);return e?{kind:`top-level`,body:n}:r||a&&a!==`.\\-`||o?{kind:`standalone`,selector:a,body:n,parent:r,noMerge:o}:{kind:`inline`,body:n}})}const B=e=>e.type===`ClassSelector`&&m.decode(e.name)===`-`;function ke(e,t){let n=h(e,{context:`selectorList`});return V(n,t)?p(n):void 0}function V(e,t){let n=!1;return e.children.forEach(e=>{e.type===`Selector`&&(n=Ae(e,t)||n)}),n}function Ae(e,t){let n=e=>e.type===`ClassSelector`&&!B(e)&&t.includes(m.decode(e.name)),r=e.children.toArray(),i=[],a=!1;for(let e=0;e<r.length;){let o=r.findIndex((t,n)=>n>=e&&t.type===`Combinator`);o=o===-1?r.length:o+1;let s=r.slice(e,o);e=o;let c=s.filter(n).length;if(!c||!s.some(B)){for(let e of s)e.type===`PseudoClassSelector`&&e.children&&!I(e)&&e.children.forEach(e=>{e.type===`SelectorList`&&(a=V(e,t)||a)}),i.push(e);continue}a=!0;for(let e of s)if(!n(e)&&(i.push(e),B(e)))for(let e=0;e<c;e++)i.push(h(`:is(.\\-)`,{context:`selector`}).children.first)}return a&&(e.children=new d().fromArray(i)),a}function H(e,t){let n=t.value[3],r=e.get(n);r||(r=new Map,e.set(n,r));let i=t.value[1],a=r.get(i);a||(a=new Map,r.set(i,a)),a.set(t.topLevel,t)}function je(e,t,n){let r=e.selector,i=!1;if(t.selector&&t.selector!==`.\\-`){let n=Me(e.prelude,t.selector);if(r=n.selector,!n.selector)return``;i=!n.hasHost}let a=L(`${r}{${t.body}}`,n,i);if(t.parent){let n=Te(t.parent);a=n.length>1?`${n.join(`{`)}{${a}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${a}}`:`${t.parent}{${a}}`}return L(a,n,!1)}function Me(e,t){let n=h(`${t}{}`,{context:`rule`}).prelude,r=!1;if(g(n,{enter(e){if(I(e))return this.skip;e.type===`ClassSelector`&&m.decode(e.name)===`-`&&(r=!0)}}),!r)return{selector:p(n),hasHost:r};let i=f(n);return i.children.clear(),e.children.forEach(e=>{let t=e.children.toArray(),r=W(t),a=t.slice(r);n.children.forEach(e=>{let n=f(e);if(g(n,{enter(e,n,i){if(I(e))return this.skip;e.type===`ClassSelector`&&m.decode(e.name)===`-`&&i.replace(n,new d().fromArray(t.slice(0,r).map(e=>f(e))))}}),a.length){let e=n.children.toArray(),t=W(e),r=[...a.map(e=>f(e)),...e.slice(t)];if(!Ne(r))return;n.children=new d().fromArray([...e.slice(0,t),...r])}i.children.appendData(n)})}),{selector:R(p(i)),hasHost:r}}function Ne(e){let t=e.filter(U).map(e=>m.decode(e.name).toLowerCase());return t.length===2&&(t[0]===`before`||t[0]===`after`)&&t[1]===`marker`||c(G(e))}const Pe=new Set([`before`,`after`,`first-line`,`first-letter`]);function U(e){return e.type===`PseudoElementSelector`||e.type===`PseudoClassSelector`&&e.children===null&&Pe.has(m.decode(e.name).toLowerCase())}function W(e){let t=e.length;for(;t>0&&e[t-1].type!==`Combinator`;)t--;let n=e.slice(t).findIndex(U);return n===-1?e.length:t+n}function G(e){return R(p({type:`Selector`,children:new d().fromArray([...e])}))}function K(e){return e.children.toArray().map(e=>e.children.toArray())}function Fe(e){return e.map(G).join(`,`)}function Ie(e){let t=e.length;for(;t>0&&e[t-1].type!==`Combinator`;)t--;return t}function q(e){if(e.type!==`PseudoClassSelector`)return;let t=e.children?.first;return t?.type===`SelectorList`?K(t):void 0}function J(e,t){return e.some(e=>e.some(e=>{if(e.type===`NestingSelector`)return!0;if(e.type!==`PseudoClassSelector`)return!1;if(e.children===null)return t&&m.decode(e.name).toLowerCase()===`scope`;let n=q(e);return n!==void 0&&J(n,t)}))}function Y(e){let t=Ie(e),n=!1;for(let[r,i]of e.entries()){if(i.type===`Combinator`&&r===0)return!1;if(i.type===`NestingSelector`){let i=e[r+1]?.type;if(r<t||i===`TypeSelector`||i===`Percentage`)return!1;n=!0;continue}let a=q(i);if(a&&J(a,!1)||r>=t&&U(i))return!1}return n}function Le(e){let t=K(z(e)),n=t.filter(Y);return n.length?{taking:n,others:t.filter(e=>!Y(e))}:void 0}function Re(e){let t=[],n=[];for(let r of K(z(e))){let e=W(r);if(e===r.length){n.push(r);continue}let i=G(r.slice(e)),a=r.slice(0,e);(!a.length||a.at(-1).type===`Combinator`)&&a.push({type:`TypeSelector`,name:`*`});let o=t.find(e=>e.element===i);o?o.bases.push(a):t.push({bases:[a],element:i})}return{groups:t,plain:n}}function ze(e,t,n){return t.every(e=>e[0]?.type===`NestingSelector`)?[...e]:e.map(e=>J([e],n)?e:[{type:`NestingSelector`},{type:`Combinator`,name:` `},...e])}function X(e,t){return e.flatMap(e=>e.type===`NestingSelector`?[...t]:[e])}function Be(e,t,n){if(n)return t.flatMap(t=>e.map(e=>X(e,t)));let[r]=t,i=e.every(e=>e.every((t,n)=>t.type!==`NestingSelector`||n===0||e[n-1].type===`Combinator`));if(t.length===1&&!r.some(e=>e.type===`Combinator`)&&(r[0]?.type!==`TypeSelector`||i))return e.map(e=>X(e,r));let a=t.map(e=>({type:`Selector`,children:new d().fromArray(e)})),o={type:`SelectorList`,children:new d().fromArray(a)},s={type:`PseudoClassSelector`,name:`is`,children:new d().fromArray([o])};return e.map(e=>X(e,[s]))}function Ve(e,t){return e.map(e=>G(e)+t).join(`,`)}function Z(e,t){let n=e;for(;n!==null&&n!==Object.prototype&&n!==Array.prototype&&n!==Function.prototype;){if(Object.hasOwn(n,t))return Reflect.get(e,t);n=Object.getPrototypeOf(n)}}async function He(e,t,n){if(!t.length)return``;let r=e.config,a=[],o=()=>{if(e.config!==r)throw Error(`[@teacss] Configuration changed while generating @apply dependencies; retry the stylesheet transform.`)};for(let n of u(r.preflights)){let s=Z(n,`getCSS`);if(!s)continue;let c=await Reflect.apply(s,n,[{generator:e,generated:[],theme:r.theme}]);o();let l=await Reflect.apply(s,n,[{generator:e,generated:i(t),theme:r.theme}]);o(),l&&l!==c&&a.push({layer:Z(n,`layer`),getCSS:()=>l})}if(!a.length)return``;let c=await(await s({layers:r.layers,sortLayers:r.sortLayers,outputToCssLayers:r.outputToCssLayers,preflights:a})).generate(new Set,{safelist:!1});return o(),L(c.css,n,!0)}function Q(e){if(!e.config.presets?.flat().some(e=>e.name===`@teacss/preset-standard`))return;let t=e.config.theme,n=Object.hasOwn(t,`colors`)?t.colors:void 0;return(e,t)=>{let r=typeof n==`object`&&n&&Object.hasOwn(n,e)?n[e]:void 0;if(typeof r==`object`&&r&&Object.hasOwn(r,t)&&r[t]!=null)return`var(--color-${e}-${t})`}}function $(e){let t=e.config.theme,n=Object.hasOwn(t,`colors`)&&t.colors!=null&&typeof t.colors==`object`?t.colors:{},r=(e,t)=>{let r=Object.hasOwn(n,e)?n[e]:void 0;return typeof r==`object`&&r&&Object.hasOwn(r,t)?r[t]:void 0};return(e,t)=>{let i=r(e,t);for(let e=0;e<=Object.keys(n).length&&typeof i==`string`;e++){let e=Ue(i,t);if(!e)break;let n=r(e.palette,t)??e.fallback;if(n===void 0)break;i=n}return typeof i==`string`?i:void 0}}function Ue(e,t){if(!e.startsWith(`var(--color-`)||!e.endsWith(`)`))return;let n=e.slice(12,-1),r=n.indexOf(`,`),i=r===-1?n:n.slice(0,r).trimEnd();if(i.endsWith(`-${t}`))return{palette:i.slice(0,-t.length-1),fallback:r===-1?void 0:n.slice(r+1).trim()}}function We(e){let t=e?.charCodeAt(0)??32;return t===127||t<32&&t!==9&&t!==10&&t!==12&&t!==13}function Ge(e,t,n){let r=e.slice(t,n),i=0;for(let t=n;t<e.length;){let n=e[t],a=t+1;if(n===`\\`?a=t+2:n===`"`||n===`'`?a=y(e,t,e.length):n===`(`?i++:n===`)`&&i--,r+=i>1&&(n!==`(`||i!==2)||We(n)?`_`.repeat(a-t):e.slice(t,a),i===0)return r;t=a}}function Ke(e,t=0,n=()=>!0){let r=[];for(let i=0;;){let[a,o]=[`theme`,`icon`].map(t=>[ee(e,t,i),t]).reduce((e,t)=>e[0]===-1||t[0]!==-1&&t[0]<e[0]?t:e);if(a===-1)return r;let s=Ge(e,a,a+o.length);if(s===void 0)return r;n(s,e[a-1])&&r.push(h(s,{context:`value`,positions:!0,offset:t+a}).children.first),i=a+s.length}}function qe(e){try{return h(e,{context:`value`}),!0}catch{return!1}}function Je(e,t,n,r=!0,i=!1){return Ye(e,t,n,r,i,0)}async function Ye(e,t,n,r,i,a){switch(t.name){case`theme`:{if(!t.children.size)throw Error(`theme() expect exact one argument`);if(t.children.first.type!==`String`)throw Error(`theme() expect a string argument`);let o;if(t.children.size>1){let e=t.children.toArray().slice(1);if(e[0].type!==`Operator`||e[0].value!==`,`)throw Error(`theme() expect a comma between expression string and default value`);e.length>1&&(o=[e[1].loc.start.offset,t.children.last.loc.end.offset])}let s=oe(t.children.first.value,e.config.theme,!o&&r,i?$(e):Q(e));return s===void 0&&o&&(s=await Xe(e,n(o[0],o[1]),r,i,a+1)),s}case`icon`:{let n=t.children.toArray().filter(e=>e.type===`String`).map(e=>e.value);if(n.length===0)throw Error(`icon() expects at least one argument`);let[i,a]=n;return a&&=encodeURIComponent(ae(a,e.config.theme,r,$(e))),Ze(e,i,a)}}}async function Xe(e,t,n,r,i){if(!ne(t)&&!te(t))return t;if(i>512)throw Error(`theme() fallbacks nest too deeply`);let a=t;for(let o of Ke(t).reverse()){let s=await Ye(e,o,(e,n)=>t.slice(e,n),n,r,i);s!==void 0&&(a=`${a.slice(0,o.loc.start.offset)}${s}${a.slice(o.loc.end.offset)}`)}return a}async function Ze(e,t,n){let r=e.config.presets?.flat()?.find(e=>e.name===`@teacss/preset-icons`);if(!r){console.warn(`@teacss/preset-icons not found, icon() directive will be kept as-is`);return}let i=r.api,a=await i.resolveIcon(t);if(!a)return;let o=i.encodeSvgForCss(a.svg);return`url("data:image/svg+xml;utf8,${n?o.replace(/currentcolor/gi,n):o}")`}function Qe(e){return typeof e==`string`?a(e)??void 0:void 0}function $e(e,t){let n=e.replace(/\/\*[\s\S]*?\*\//g,``).trim();if(!n)return;let r=``,i=n.match(/^(?:(lt|at)-)?([\w-]+)$/);i&&(r=i[1],n=i[2]);let{breakpoint:a,breakpoints:o}=t,s=a??o??{};if(r!==`at`){if(!Object.hasOwn(s,n))throw Error(`breakpoint ${n} not found`);let e=s[n];return r===`lt`?`(max-width: ${_(e)})`:`(min-width: ${e})`}let c=Object.entries(s),l=c.find(([e])=>e===n);if(!l)throw Error(`breakpoint ${n} not found`);let u=l[1],d=Qe(u),f,p;if(d!==void 0)for(let[e,t]of c){if(e===n)continue;let r=Qe(t);r===void 0||r.unit!==d.unit||r.value<=d.value||p!==void 0&&(r.value>p.value||r.value===p.value&&t>=f)||(f=t,p=r)}return`(min-width: ${u})${f===void 0?``:` and (max-width: ${_(f)})`}`}export{F as C,x as E,b as S,pe as T,Le as _,Q as a,A as b,Ce as c,Se as d,ve as f,xe as g,je as h,Je as i,Fe as l,Re as m,Ke as n,He as o,Oe as p,qe as r,ze as s,$e as t,ye as u,Be as v,y as w,me as x,Ve as y};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/directives",
3
- "version": "0.10.14",
3
+ "version": "0.10.15",
4
4
  "description": "Build-time CSS directive transformer for TeaCSS — @apply, theme(), icon(), and @screen.",
5
5
  "homepage": "https://css.teasim.com",
6
6
  "funding": "https://github.com/sponsors/billgo",
@@ -24,17 +24,17 @@
24
24
  "dev": "tsdown --watch"
25
25
  },
26
26
  "dependencies": {
27
- "@teacss/config": "0.10.14",
28
- "@teacss/core": "0.10.14",
29
- "@teacss/rule-helpers": "0.10.14",
30
- "@teacss/runtime": "0.10.14",
27
+ "@teacss/config": "0.10.15",
28
+ "@teacss/core": "0.10.15",
29
+ "@teacss/rule-helpers": "0.10.15",
30
+ "@teacss/runtime": "0.10.15",
31
31
  "@types/css-tree": "^3.2.0",
32
32
  "css-tree": "^3.2.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@teacss/preset-icons": "0.10.14",
36
- "@teacss/preset-official": "0.10.14",
37
- "@teacss/preset-standard": "0.10.14",
35
+ "@teacss/preset-icons": "0.10.15",
36
+ "@teacss/preset-official": "0.10.15",
37
+ "@teacss/preset-standard": "0.10.15",
38
38
  "magic-string": "^1.2.3"
39
39
  },
40
40
  "engines": {
@@ -1,2 +0,0 @@
1
- import{DEFAULT_LAYERS as e,LAYER_UTILITIES as t,clone as n,comparableWidth as r,compareParentAtRules as i,createGenerator as a,isPseudoElementChain as o,notNull as s,toArray as c}from"@teacss/core";import{List as l,clone as u,generate as d,ident as f,parse as p,walk as m}from"css-tree";import{calcMaxWidthBySize as h,findCssFunctionStart as ee,hasIconFn as te,hasThemeFn as ne,isCssNameCharacter as re,isCssWhitespace as ie,transformThemeFn as ae,transformThemeString as oe}from"@teacss/rule-helpers";function g(e,t){return(e[t]===`#`||e[t]===`@`)&&e[t+1]===`{`}function _(e,t,n){for(let r=t+1;r<n;r++){let n=e[r];if(n===`\\`)r++;else if(n===e[t])return r+1;else if(n===`
2
- `||n===`\r`||n===`\f`)return r}return n}function v(e,t){if(e[t]!==`u`&&e[t]!==`U`||e.slice(t,t+4).toLowerCase()!==`url(`)return!1;let n=e[t-1];if(n===`.`||n===`#`||re(n))return!1;let r=t+4;for(;ie(e[r]);)r++;return e[r]!==`"`&&e[r]!==`'`}function y(e,t,n,r){let i=0;for(let a=t+4;a<n;a++){let t=e[a];if(t===`\\`)a++;else if(r&&g(e,a))i++,a++;else if(i)t===`}`?i--:(t===`"`||t===`'`)&&(a=_(e,a,n)-1);else if(t===`)`)return a+1}return-1}function b(e,t,n,r){let i=e[t];if(i===`\\`)return Math.min(t+2,n);if(i===`"`||i===`'`)return _(e,t,n);if(i===`/`&&e[t+1]===`*`){let r=e.indexOf(`*/`,t+2);return r===-1||r+2>n?n:r+2}if(v(e,t)){let i=y(e,t,n,r);return i===-1?n:i}return t}function x(e){if(e===`(`)return`)`;if(e===`[`)return`]`}function S(e,t,n,r,i){let a=[],o=t;for(;o<n;){let t=b(e,o,n,i);if(t!==o){o=t;continue}if(i&&g(e,o)){a.push(`}`),o+=2;continue}let s=e[o],c=x(s);if(c)a.push(c);else if(r&&s===`{`)a.push(`}`);else if(a.at(-1)===s)a.pop();else if(!a.length){if(s===`{`)return{type:`block`,at:o};if(s===`;`)return{type:`semicolon`,at:o};if(s===`}`)return{type:`end`,at:o}}o++}return{type:`end`,at:n,open:a.length>0}}function C(e,t,n,r){let i=[],a=1,o=t+1;for(;o<n;){let t=b(e,o,n,r);if(t!==o){o=t;continue}if(r&&g(e,o)){i.push(`}`),o+=2;continue}let s=e[o],c=x(s);if(c)i.push(c);else if(i.at(-1)===s)i.pop();else if(!i.length){if(s===`{`)a++;else if(s===`}`&&--a===0)return o}o++}return n}function w(e,t,n,r){let i=[],a=t;for(;a<n;){let t=b(e,a,n,r);if(t!==a){a=t;continue}if(r&&g(e,a)){i.push(`}`),a+=2;continue}let o=e[a],s=x(o);if(s)i.push(s);else if(i.at(-1)===o)i.pop();else if(!i.length&&o===`:`)return a;a++}return-1}function T(e,t,n){let r=e.slice(t,n),i=t+r.length-r.trimStart().length;return[i,i+r.trim().length]}function se(e,[t,n]){let r=/(?:\s*!\s*(?:important|default|global))+$/i.exec(e.slice(t,n));return r?[t,t+r.index]:[t,n]}function ce(e,t,n,r){let i=w(e,t,n,r);if(i===-1)return;let[a,o]=T(e,t,i),s=T(e,i+1,n),c=e.slice(a,o);if(c&&(s[0]!==s[1]||c.startsWith(`--`)))return{name:c,value:se(e,s)}}function le(e,t,n){let r=[],i=t;for(;i<n;){let t=b(e,i,n,!0);if(t!==i){i=t;continue}if(g(e,i)){i=C(e,i+1,n,!0)+1;continue}if(e[i]===`{`){let t=C(e,i,n,!0);r.push([i+1,t]),i=t}i++}return r}function E(e,t,n){let r=t;for(;r<n&&/[\w-]/.test(e[r]);)r++;return r}function ue(e,t){let n=e.length,r=0;for(;r<n;){if(e.startsWith(`/*`,r)){r=b(e,r,n,t);continue}if(/[\s;}]/.test(e[r])){r++;continue}let i=e.startsWith(`@apply`,r)&&E(e,r+1,n)===r+6,a=S(e,r,n,i,t);if(a.type===`block`){let i=C(e,a.at,n,t);if(i===n)return`block`;r=i+1}else if(a.type===`end`&&a.at===n&&(a.open||e[r]!==`@`))return a.open?`bracket`:`statement`;else r=a.at+1}}function de(e,t,n,r){let i=[],a=t;for(;a<n;){if(e.startsWith(`/*`,a)){a=b(e,a,n,r);continue}if(/[\s;}]/.test(e[a])){a++;continue}let t=a,o=S(e,t,n,e.startsWith(`@apply`,t)&&E(e,t+1,n)===t+6,r);o.type===`block`&&e.startsWith(`--`,t)&&w(e,t,o.at,r)!==-1&&(o=S(e,t,n,!0,r));let s=o.at,c=o.type===`semicolon`?s+1:s,l;if(o.type===`block`){let t=C(e,s,n,r);l=[s+1,t],c=Math.min(t+1,n)}if(a=c,e[t]===`@`&&!(r&&g(e,t))){let n=E(e,t+1,s);n>t+1&&i.push({kind:`at-rule`,start:t,end:c,name:e.slice(t+1,n),prelude:T(e,n,s),block:l})}else if(l)i.push({kind:`rule`,start:t,end:c,prelude:T(e,t,s),block:l});else{let n=ce(e,t,s,r);n?i.push({kind:`declaration`,start:t,end:c,...n}):r&&i.push({kind:`call`,start:t,end:c,rulesets:le(e,t,s)})}}return i}function D(e){if(e.type!==`PseudoClassSelector`||e.name!==`is`)return!1;let t=e.children?.first;if(t?.type!==`SelectorList`)return!1;let n=t.children.toArray().map(e=>d(e));return n.length===2&&/^:root:where\(html[:[]/.test(n[0])&&n[1]===`${n[0].slice(5)} *`}function O(e,t,n){if(!/\.module\.(?:css|postcss|scss|sass|less|styl|stylus)$/i.test(t?.split(/[?#]/,1)[0]??``)||!n&&!/@scope\s*\(|:root:where\(html/i.test(e))return e;let r=p(e),i=e=>{e.children=e.children.map(e=>p(`:global(${d(e)})`,{context:`selector`}))};return m(r,{enter(e,t,r){if(e.type===`PseudoClassSelector`&&e.name===`global`)return this.skip;if(!n&&D(e)){let n=p(`:global(${d(e)})`,{context:`selector`});return r.replace(t,n.children),this.skip}if(e.type===`Scope`){e.root?.type===`SelectorList`&&i(e.root),e.limit?.type===`SelectorList`&&i(e.limit);return}n&&e.type===`Rule`&&(this.atrule&&/(?:^|-)keyframes$/i.test(this.atrule.name)||e.prelude.type===`SelectorList`&&i(e.prelude))}}),d(r)}const fe=/([0-9a-f]*)/g;function pe(e,t){let n=0;for(let r=t+1;r<e.length;r++){let t=e[r];if(t===`\\`)r++;else if(t===`"`||t===`'`)r=_(e,r,e.length)-1;else if(t===`{`)n++;else if(t===`}`&&--n===0)return r+1}}function me(e){if(!e.includes(`{`))return e;let t=``,n=0;for(let r=0;r<e.length;r++){let i=e[r];if(i===`\\`)r++;else if(i===`"`||i===`'`)r=_(e,r,e.length)-1;else if(g(e,r)){let i=pe(e,r);if(i===void 0)return e;let a=Array.from({length:i-r},(t,n)=>e.charCodeAt(r+n).toString(16).padStart(4,`0`));t+=`${e.slice(n,r)}${a.join(``)}`,n=i,r=i-1}}return t+e.slice(n)}function k(e){return e.replace(fe,(e,t)=>String.fromCharCode(...t.match(/.{4}/g).map(e=>Number.parseInt(e,16))))}function A(e){try{return p(me(e),{context:`selectorList`})}catch{let t={type:`TypeSelector`,name:e.trim()},n={type:`Selector`,children:new l().fromArray([t])};return{type:`SelectorList`,children:new l().fromArray([n])}}}function he(e){let t=A(e);return{prelude:t,selector:k(d(t)),replacementSelector:e}}function ge(e){return U(A(e)).some(e=>V(e)<e.length)}function _e(e){try{let t=p(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function ve(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function j(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function M(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function N(e){let t=!1,n=0,r,i=``;for(let a=0;a<e.length;a++){let o=e[a];if(t){o===`*`&&e[a+1]===`/`&&(t=!1,a++);continue}if(r){o===`\\`?a++:o===r&&(r=void 0);continue}if(o===`/`&&e[a+1]===`*`){t=!0,a++;continue}if(o===`\\`){a++;continue}if(o===`"`||o===`'`){r=o;continue}if(!/\s/.test(o)||e[a+1]!==`$`||e[a+2]!==`$`||!/\s/.test(e[a+3]??``))continue;let s=a+4;for(;s<e.length&&/\s/.test(e[s]);)s++;i+=`${e.slice(n,a)} `,n=s,a=s-1}return n?i+e.slice(n):e}function P(e){let t=[],n=0,r=!1,i=0,a,o=0;for(let s=0;s<e.length;s++){let c=e[s];r?c===`*`&&e[s+1]===`/`&&(r=!1,s++):a?c===`\\`?s++:c===a&&(a=void 0):c===`/`&&e[s+1]===`*`?(r=!0,s++):c===`"`||c===`'`?a=c:c===`(`?i++:c===`)`?i>0&&i--:c===`[`?n++:c===`]`?n>0&&n--:n===0&&i===0&&e.startsWith(` $$ `,s)&&(t.push(e.slice(o,s)),s+=3,o=s+1)}return t.push(e.slice(o)),t}function F(e){let n=new Set,r=[];for(let i=e.length-1;i>=0;i--){let[,a,o,s,c]=e[i],l=JSON.stringify([c?.layer??t,a,s,o,!!c?.noMerge]);n.has(l)||(n.add(l),r.push(e[i]))}return r.reverse()}function ye(e){return[...e].sort((e,t)=>e[0]-t[0])}function be(n,r,a=e,o=ye){let c=e=>Object.hasOwn(a,e)?a[e]??0:0,l=new Map;for(let e of n.flatMap(([,e])=>e??[]).filter(s)){let n=e[4]?.layer??t,r=e[3]??``,i=JSON.stringify([n,r]),a=l.get(i);a?a.utilities.push(e):l.set(i,{layer:n,parent:r,utilities:[e]})}let u=[...l.values()].sort((e,t)=>{let n=e.layer===t.layer?0:e.layer<t.layer?-1:1;return c(e.layer)-c(t.layer)||n||i(r,e.parent,t.parent)}).flatMap(e=>F(o(e.utilities)));if(!u.length)return[];let d=n.map(([e])=>e),f=[],p=[],m,h;for(let e of u){let n=e[4]?.layer??t;if(n!==m&&(m=n,p=[],h=void 0),!h&&p.length===64){h=new Map;for(let e of p)R(h,e)}let r=e[1],i=r?.includes(`.\\-`)?xe(r,d)??r:r,a=e[3],o=i===void 0&&a===void 0&&_e(e[2]),s=h?h.get(a)?.get(i)?.get(o):p.find(e=>e.value[1]===i&&e.value[3]===a&&e.topLevel===o);if(s){s.value[2]+=e[2];continue}let c=[...e];c[1]=i;let l={topLevel:o,value:c};f.push(l),p.push(l),h&&R(h,l)}return f.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&N(t),o=!!(a&&i?.noMerge);return e?{kind:`top-level`,body:n}:r||a&&a!==`.\\-`||o?{kind:`standalone`,selector:a,body:n,parent:r,noMerge:o}:{kind:`inline`,body:n}})}const I=e=>e.type===`ClassSelector`&&f.decode(e.name)===`-`;function xe(e,t){let n=p(e,{context:`selectorList`});return L(n,t)?d(n):void 0}function L(e,t){let n=!1;return e.children.forEach(e=>{e.type===`Selector`&&(n=Se(e,t)||n)}),n}function Se(e,t){let n=e=>e.type===`ClassSelector`&&!I(e)&&t.includes(f.decode(e.name)),r=e.children.toArray(),i=[],a=!1;for(let e=0;e<r.length;){let o=r.findIndex((t,n)=>n>=e&&t.type===`Combinator`);o=o===-1?r.length:o+1;let s=r.slice(e,o);e=o;let c=s.filter(n).length;if(!c||!s.some(I)){for(let e of s)e.type===`PseudoClassSelector`&&e.children&&!D(e)&&e.children.forEach(e=>{e.type===`SelectorList`&&(a=L(e,t)||a)}),i.push(e);continue}a=!0;for(let e of s)if(!n(e)&&(i.push(e),I(e)))for(let e=0;e<c;e++)i.push(p(`:is(.\\-)`,{context:`selector`}).children.first)}return a&&(e.children=new l().fromArray(i)),a}function R(e,t){let n=t.value[3],r=e.get(n);r||(r=new Map,e.set(n,r));let i=t.value[1],a=r.get(i);a||(a=new Map,r.set(i,a)),a.set(t.topLevel,t)}function Ce(e,t,n){let r=e.selector,i=!1;if(t.selector&&t.selector!==`.\\-`){let n=we(e.prelude,t.selector);if(r=n.selector,!n.selector)return``;i=!n.hasHost}let a=O(`${r}{${t.body}}`,n,i);if(t.parent){let n=P(t.parent);a=n.length>1?`${n.join(`{`)}{${a}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${a}}`:`${t.parent}{${a}}`}return O(a,n,!1)}function we(e,t){let n=p(`${t}{}`,{context:`rule`}).prelude,r=!1;if(m(n,{enter(e){if(D(e))return this.skip;e.type===`ClassSelector`&&f.decode(e.name)===`-`&&(r=!0)}}),!r)return{selector:d(n),hasHost:r};let i=u(n);return i.children.clear(),e.children.forEach(e=>{let t=e.children.toArray(),r=V(t),a=t.slice(r);n.children.forEach(e=>{let n=u(e);if(m(n,{enter(e,n,i){if(D(e))return this.skip;e.type===`ClassSelector`&&f.decode(e.name)===`-`&&i.replace(n,new l().fromArray(t.slice(0,r).map(e=>u(e))))}}),a.length){let e=n.children.toArray(),t=V(e),r=[...a.map(e=>u(e)),...e.slice(t)];if(!z(r))return;n.children=new l().fromArray([...e.slice(0,t),...r])}i.children.appendData(n)})}),{selector:k(d(i)),hasHost:r}}function z(e){let t=e.filter(B).map(e=>f.decode(e.name).toLowerCase());return t.length===2&&(t[0]===`before`||t[0]===`after`)&&t[1]===`marker`||o(H(e))}const Te=new Set([`before`,`after`,`first-line`,`first-letter`]);function B(e){return e.type===`PseudoElementSelector`||e.type===`PseudoClassSelector`&&e.children===null&&Te.has(f.decode(e.name).toLowerCase())}function V(e){let t=e.length;for(;t>0&&e[t-1].type!==`Combinator`;)t--;let n=e.slice(t).findIndex(B);return n===-1?e.length:t+n}function H(e){return k(d({type:`Selector`,children:new l().fromArray([...e])}))}function U(e){return e.children.toArray().map(e=>e.children.toArray())}function Ee(e){return e.map(H).join(`,`)}function De(e){let t=e.length;for(;t>0&&e[t-1].type!==`Combinator`;)t--;return t}function W(e){if(e.type!==`PseudoClassSelector`)return;let t=e.children?.first;return t?.type===`SelectorList`?U(t):void 0}function G(e,t){return e.some(e=>e.some(e=>{if(e.type===`NestingSelector`)return!0;if(e.type!==`PseudoClassSelector`)return!1;if(e.children===null)return t&&f.decode(e.name).toLowerCase()===`scope`;let n=W(e);return n!==void 0&&G(n,t)}))}function K(e){let t=De(e),n=!1;for(let[r,i]of e.entries()){if(i.type===`Combinator`&&r===0)return!1;if(i.type===`NestingSelector`){let i=e[r+1]?.type;if(r<t||i===`TypeSelector`||i===`Percentage`)return!1;n=!0;continue}let a=W(i);if(a&&G(a,!1)||r>=t&&B(i))return!1}return n}function Oe(e){let t=U(A(e)),n=t.filter(K);return n.length?{taking:n,others:t.filter(e=>!K(e))}:void 0}function ke(e){let t=[],n=[];for(let r of U(A(e))){let e=V(r);if(e===r.length){n.push(r);continue}let i=H(r.slice(e)),a=r.slice(0,e);(!a.length||a.at(-1).type===`Combinator`)&&a.push({type:`TypeSelector`,name:`*`});let o=t.find(e=>e.element===i);o?o.bases.push(a):t.push({bases:[a],element:i})}return{groups:t,plain:n}}function Ae(e,t,n){return t.every(e=>e[0]?.type===`NestingSelector`)?[...e]:e.map(e=>G([e],n)?e:[{type:`NestingSelector`},{type:`Combinator`,name:` `},...e])}function q(e,t){return e.flatMap(e=>e.type===`NestingSelector`?[...t]:[e])}function je(e,t,n){if(n)return t.flatMap(t=>e.map(e=>q(e,t)));let[r]=t,i=e.every(e=>e.every((t,n)=>t.type!==`NestingSelector`||n===0||e[n-1].type===`Combinator`));if(t.length===1&&!r.some(e=>e.type===`Combinator`)&&(r[0]?.type!==`TypeSelector`||i))return e.map(e=>q(e,r));let a=t.map(e=>({type:`Selector`,children:new l().fromArray(e)})),o={type:`SelectorList`,children:new l().fromArray(a)},s={type:`PseudoClassSelector`,name:`is`,children:new l().fromArray([o])};return e.map(e=>q(e,[s]))}function Me(e,t){return e.map(e=>H(e)+t).join(`,`)}function J(e,t){let n=e;for(;n!==null&&n!==Object.prototype&&n!==Array.prototype&&n!==Function.prototype;){if(Object.hasOwn(n,t))return Reflect.get(e,t);n=Object.getPrototypeOf(n)}}async function Ne(e,t,r){if(!t.length)return``;let i=e.config,o=[],s=()=>{if(e.config!==i)throw Error(`[@teacss] Configuration changed while generating @apply dependencies; retry the stylesheet transform.`)};for(let r of c(i.preflights)){let a=J(r,`getCSS`);if(!a)continue;let c=await Reflect.apply(a,r,[{generator:e,generated:[],theme:i.theme}]);s();let l=await Reflect.apply(a,r,[{generator:e,generated:n(t),theme:i.theme}]);s(),l&&l!==c&&o.push({layer:J(r,`layer`),getCSS:()=>l})}if(!o.length)return``;let l=await(await a({layers:i.layers,sortLayers:i.sortLayers,outputToCssLayers:i.outputToCssLayers,preflights:o})).generate(new Set,{safelist:!1});return s(),O(l.css,r,!0)}function Y(e){if(!e.config.presets?.flat().some(e=>e.name===`@teacss/preset-standard`))return;let t=e.config.theme,n=Object.hasOwn(t,`colors`)?t.colors:void 0;return(e,t)=>{let r=typeof n==`object`&&n&&Object.hasOwn(n,e)?n[e]:void 0;if(typeof r==`object`&&r&&Object.hasOwn(r,t)&&r[t]!=null)return`var(--color-${e}-${t})`}}function X(e){let t=e.config.theme,n=Object.hasOwn(t,`colors`)&&t.colors!=null&&typeof t.colors==`object`?t.colors:{},r=(e,t)=>{let r=Object.hasOwn(n,e)?n[e]:void 0;return typeof r==`object`&&r&&Object.hasOwn(r,t)?r[t]:void 0};return(e,t)=>{let i=r(e,t);for(let e=0;e<=Object.keys(n).length&&typeof i==`string`;e++){let e=Pe(i,t);if(!e)break;let n=r(e.palette,t)??e.fallback;if(n===void 0)break;i=n}return typeof i==`string`?i:void 0}}function Pe(e,t){if(!e.startsWith(`var(--color-`)||!e.endsWith(`)`))return;let n=e.slice(12,-1),r=n.indexOf(`,`),i=r===-1?n:n.slice(0,r).trimEnd();if(i.endsWith(`-${t}`))return{palette:i.slice(0,-t.length-1),fallback:r===-1?void 0:n.slice(r+1).trim()}}function Fe(e,t,n){let r=e.slice(t,n),i=0;for(let t=n;t<e.length;){let n=e[t],a=t+1;if(n===`\\`?a=t+2:n===`"`||n===`'`?a=_(e,t,e.length):n===`(`?i++:n===`)`&&i--,r+=i>1&&(n!==`(`||i!==2)?`_`.repeat(a-t):e.slice(t,a),i===0)return r;t=a}}function Z(e,t=0,n=()=>!0){let r=[];for(let i=0;;){let[a,o]=[`theme`,`icon`].map(t=>[ee(e,t,i),t]).reduce((e,t)=>e[0]===-1||t[0]!==-1&&t[0]<e[0]?t:e);if(a===-1)return r;let s=Fe(e,a,a+o.length);if(s===void 0)return r;n(s,e[a-1])&&r.push(p(s,{context:`value`,positions:!0,offset:t+a}).children.first),i=a+s.length}}function Ie(e){try{return p(e,{context:`value`}),!0}catch{return!1}}function Le(e,t,n,r=!0,i=!1){return Q(e,t,n,r,i,0)}async function Q(e,t,n,r,i,a){switch(t.name){case`theme`:{if(!t.children.size)throw Error(`theme() expect exact one argument`);if(t.children.first.type!==`String`)throw Error(`theme() expect a string argument`);let o;if(t.children.size>1){let e=t.children.toArray().slice(1);if(e[0].type!==`Operator`||e[0].value!==`,`)throw Error(`theme() expect a comma between expression string and default value`);e.length>1&&(o=[e[1].loc.start.offset,t.children.last.loc.end.offset])}let s=oe(t.children.first.value,e.config.theme,!o&&r,i?X(e):Y(e));return s===void 0&&o&&(s=await Re(e,n(o[0],o[1]),r,i,a+1)),s}case`icon`:{let n=t.children.toArray().filter(e=>e.type===`String`).map(e=>e.value);if(n.length===0)throw Error(`icon() expects at least one argument`);let[i,a]=n;return a&&=encodeURIComponent(ae(a,e.config.theme,r,X(e))),ze(e,i,a)}}}async function Re(e,t,n,r,i){if(!ne(t)&&!te(t))return t;if(i>512)throw Error(`theme() fallbacks nest too deeply`);let a=t;for(let o of Z(t).reverse()){let s=await Q(e,o,(e,n)=>t.slice(e,n),n,r,i);s!==void 0&&(a=`${a.slice(0,o.loc.start.offset)}${s}${a.slice(o.loc.end.offset)}`)}return a}async function ze(e,t,n){let r=e.config.presets?.flat()?.find(e=>e.name===`@teacss/preset-icons`);if(!r){console.warn(`@teacss/preset-icons not found, icon() directive will be kept as-is`);return}let i=r.api,a=await i.resolveIcon(t);if(!a)return;let o=i.encodeSvgForCss(a.svg);return`url("data:image/svg+xml;utf8,${n?o.replace(/currentcolor/gi,n):o}")`}function $(e){return typeof e==`string`?r(e)??void 0:void 0}function Be(e,t){let n=e.replace(/\/\*[\s\S]*?\*\//g,``).trim();if(!n)return;let r=``,i=n.match(/^(?:(lt|at)-)?([\w-]+)$/);i&&(r=i[1],n=i[2]);let{breakpoint:a,breakpoints:o}=t,s=a??o??{};if(r!==`at`){if(!Object.hasOwn(s,n))throw Error(`breakpoint ${n} not found`);let e=s[n];return r===`lt`?`(max-width: ${h(e)})`:`(min-width: ${e})`}let c=Object.entries(s),l=c.find(([e])=>e===n);if(!l)throw Error(`breakpoint ${n} not found`);let u=l[1],d=$(u),f,p;if(d!==void 0)for(let[e,t]of c){if(e===n)continue;let r=$(t);r===void 0||r.unit!==d.unit||r.value<=d.value||p!==void 0&&(r.value>p.value||r.value===p.value&&t>=f)||(f=t,p=r)}return`(min-width: ${u})${f===void 0?``:` and (max-width: ${h(f)})`}`}export{ue as C,_ as S,Oe as _,Y as a,v as b,M as c,j as d,he as f,ve as g,Ce as h,Le as i,Ee as l,ke as m,Z as n,Ne as o,be as p,Ie as r,Ae as s,Be as t,ge as u,je as v,y as w,de as x,Me as y};