@teacss/directives 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,7 @@ After resolving all applies, pass their flattened utility payloads to
53
53
  stylesheet's top level. It preserves configured CSS layers and keeps dependency
54
54
  state local to that stylesheet. Pass the filename so conventional `.module.css`
55
55
  stylesheets keep generated theme selectors global. Also pass it to
56
- `renderStandaloneApplyUtility`: fixed dependency selectors and mode scope
57
- boundaries stay global while the application host remains local.
56
+ `renderStandaloneApplyUtility`: fixed dependency selectors, html mode selectors and configured
57
+ aliases stay global while the application host remains local.
58
58
 
59
59
  Pre-1.0. Applications should normally use a build adapter.
package/dist/core.js CHANGED
@@ -1 +1 @@
1
- import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./screen-core-60rY0zso.js";export{n as formatMissingApplyTokens,a as generateApplyPreflights,e as missingApplyTokens,i as prepareApplyUtilities,o as renderStandaloneApplyUtility,t as resolveApplyTokens,r as resolveCssFunction,s as resolveScreenQuery};
1
+ import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./screen-core-LhuCZHM6.js";export{n as formatMissingApplyTokens,a as generateApplyPreflights,e as missingApplyTokens,i as prepareApplyUtilities,o as renderStandaloneApplyUtility,t as resolveApplyTokens,r as resolveCssFunction,s as resolveScreenQuery};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./screen-core-60rY0zso.js";import{createGenerator as c,expandClassGroups as l,expandVariantGroup as u,isCssId as d,splitClassTokens as f,toArray as p}from"@teacss/core";import{generate as m,parse as h,walk as g}from"css-tree";import{hasIconFn as _,hasThemeFn as v,transformThemeFn as y}from"@teacss/rule-helpers";import{ROLE_DIRECTIVES as b,customToTheme as x,diagnoseCustom as S,parseEntry as C,resolveEntryConfig as w,resolvePresets as T,scanTopLevelAtRules as E}from"@teacss/config";import{generateSources as D}from"@teacss/runtime/source-generation";async function O(e,t,n){let r=[],i=[],a=!1;for(let o of t.block.children)if(o.type===`Raw`)await n(o.value,o.loc.start.offset);else{let n=await k(e,t,o);if(!n)continue;r.push(n.consumedRange),i.push(...n.standaloneCss),a||=n.hasInlineUtility}let o=e.code.original,s=t.block.loc.start.offset+1,c=!1;for(let[e,t]of r){if(o.slice(s,e).trim()){c=!0;break}s=t}c||=!!o.slice(s,t.block.loc.end.offset-1).trim(),!a&&!c&&r.length>0&&e.code.remove(t.loc.start.offset,t.loc.end.offset);for(let n of i)e.code.appendLeft(t.loc.end.offset,n)}async function k({code:r,generator:a,applyVariable:s,options:c,filename:d,applyUtilities:p},h,g){let _=r.original,v,b=g.loc.end.offset;if(g.type===`Atrule`&&g.name===`apply`&&g.prelude&&g.prelude.type===`Raw`)v=j(g.prelude.value.trim());else if(g.type===`Atrule`&&g.name===`apply`&&!g.prelude&&g.block)b=A(_,b),v=_.slice(g.loc.start.offset+6,b).trim();else if(g.type===`Declaration`&&s.includes(g.property)&&(g.value.type===`Value`||g.value.type===`Raw`)){let e=_.slice(g.value.loc.start.offset,g.value.loc.end.offset).trim();e=j(e),v=f(e).map(e=>j(e)).join(` `)}if(!v)return;v=M(v),v=y(v,a.config.theme,c.throwOnMissing??!0);let x=f(u(l(v))),S=await t(x,a),C=e(S);if(C.length&&(c.throwOnMissing??!0))throw Error(`${n(C)}${d?` in ${d}`:``}`);let w=i(S,a.parentOrders);p?.set(g.loc.start.offset,S.flatMap(([,e])=>e??[]));let T=+(_[b]===`;`),E=[g.loc.start.offset,b+T];if(!w.length)return r.remove(...E),{consumedRange:E,hasInlineUtility:!1,standaloneCss:[]};let D,O=!1,k=[];for(let e of w)if(e.kind===`top-level`)k.push(e.body);else if(e.kind===`standalone`){if(!D){let e=h.prelude;D={prelude:e,selector:m(e),replacementSelector:r.slice(h.prelude.loc.start.offset,h.prelude.loc.end.offset)}}let t=o(D,e,d);k.push(t)}else O=!0,r.appendLeft(g.loc.start.offset,e.body);return r.remove(...E),{consumedRange:E,hasInlineUtility:O,standaloneCss:k}}function A(e,t){let n=t;for(;e[n]===`@`;){let t=0;for(n++;n<e.length;){let r=e[n];if(r===`[`||r===`(`)t++;else if(r===`]`||r===`)`)t--;else if(t===0&&(/\s/.test(r)||r===`;`||r===`{`||r===`}`))break;n++}}return n}function j(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function M(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function N({code:e,generator:t,options:n},i){let a=await r(t,i,(t,n)=>e.slice(t,n),n.throwOnMissing??!0);a!==void 0&&e.overwrite(i.loc.start.offset,i.loc.end.offset,a)}const P=/(@screen [^{]+).+/g;function F({code:e,generator:t},n){if(n.prelude?.type!==`Raw`)return;let r=s(n.prelude.value,t.config.theme);if(!r)return;let i=n.loc.start.offset,a=e.original.slice(i,n.loc.end.offset);for(let t of a.matchAll(P))e.overwrite(i+t.index,i+t.index+t[1].length,`@media ${r}`)}const I=new Set([`presets`,`source`,`shortcut`,`safelist`,...b]);function L(e){let t=e.original;if(!t.includes(`@`))return;let n=E(t);if(!n.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))for(let t of n)(I.has(t.name)?t.terminator===`;`:t.name===`custom`&&t.terminator===`block`)&&e.remove(t.start,t.end)}function R(e){return b.some(t=>e.includes(`@${t}`))||e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}async function z(e,t,n,r,i,o){let s=new Map;await B(e,t,n,s,r,i,o);let c=[...s].sort(([e],[t])=>e-t).flatMap(([,e])=>e),l=await a(t,c,r);l&&e.appendLeft(e.original.length,`\n${l}`)}async function B(e,t,n,r,i,a,o){let{applyVariable:s}=n,c=n.varStyle;s===void 0&&(s=c===void 0?[`--at-apply`]:c?[`${c}apply`]:[]),s=p(s||[]);let l=e=>e.includes(`@apply`)||s.some(t=>e.includes(t)),u=a||e.original,d=l(u),f=u.includes(`@screen`),m=v(u)||_(u);if(a===void 0&&R(u)&&L(e),!d&&!m&&!f)return;let y=h(u,{parseCustomProperty:!0,parseAtrulePrelude:!1,positions:!0,filename:i,offset:o});if(y.type!==`StyleSheet`)return;let b=[],x=new WeakSet,S=new WeakSet,C={options:n,applyVariable:s,generator:t,code:e,filename:i,offset:o,applyUtilities:r},w=(a,o)=>B(e,t,n,r,i,a,o),T=async e=>{for(let t of e.block.children)t.type===`Raw`&&await w(t.value,t.loc.start.offset)};g(y,function(t){if(f&&t.type===`Atrule`&&t.name===`screen`)F(C,t);else if(m&&t.type===`Function`&&(t.name===`theme`||t.name===`icon`))return b.push(N(C,t)),this.skip;else d&&t.type===`Rule`&&l(e.original.slice(t.loc.start.offset,t.loc.end.offset))?(x.add(t),b.push(O(C,t,w))):t.type===`Raw`&&this.rule&&!x.has(this.rule)&&!S.has(this.rule)&&(S.add(this.rule),b.push(T(this.rule)))}),await Promise.all(b)}async function V(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await w(e,n,r),s=await c(o.config),l=[],u=[];for(let e of o.config.content?.filesystem??[])e.startsWith(`!`)?u.push(e.slice(1)):l.push(e);let{files:d,sources:f}=a?{files:[],sources:a}:i?await i(l,u):{files:[],sources:[]},p=await D(s,d,f);return{layers:p.getLayers()||``,files:d,unknown:o.unknown,matched:p.matched.size,hasTeacss:o.hasTeacss,hasPreset:!!o.config.presets?.length}}function H(e,t){let n=[],r=[],i=[];for(let a of E(e))a.name===`charset`&&a.terminator===`;`?(n.push(e.slice(a.start,a.end)),i.push({start:a.start,end:a.end,replacement:``})):a.name===`import`&&a.terminator===`;`?(r.push(e.slice(a.start,a.end)),i.push({start:a.start,end:a.end,replacement:``})):(b.includes(a.name)||a.name===`presets`||a.name===`source`||a.name===`shortcut`||a.name===`safelist`)&&a.terminator===`;`||a.name===`custom`&&a.terminator===`block`?i.push({start:a.start,end:a.end,replacement:``}):a.name===`teacss`&&a.prelude===``&&a.terminator!==`block`&&i.push({start:a.start,end:a.end,replacement:t});i.sort((e,t)=>e.start-t.start);let a=``,o=0;for(let t of i)a+=e.slice(o,t.start)+t.replacement,o=t.end;a+=e.slice(o);let s=a.startsWith(``)?``:``;s&&(a=a.slice(1));let c=[...n,...r];return s+(c.length?`${c.join(`
1
+ import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./screen-core-LhuCZHM6.js";import{createGenerator as c,expandClassGroups as l,expandVariantGroup as u,isCssId as d,splitClassTokens as f,toArray as p}from"@teacss/core";import{generate as m,parse as h,walk as g}from"css-tree";import{hasIconFn as _,hasThemeFn as v,transformThemeFn as y}from"@teacss/rule-helpers";import{ROLE_DIRECTIVES as b,customToTheme as x,diagnoseCustom as S,parseEntry as C,resolveEntryConfig as w,resolvePresets as T,scanTopLevelAtRules as E}from"@teacss/config";import{generateSources as D}from"@teacss/runtime/source-generation";async function O(e,t,n){let r=[],i=[],a=!1;for(let o of t.block.children)if(o.type===`Raw`)await n(o.value,o.loc.start.offset);else{let n=await k(e,t,o);if(!n)continue;r.push(n.consumedRange),i.push(...n.standaloneCss),a||=n.hasInlineUtility}let o=e.code.original,s=t.block.loc.start.offset+1,c=!1;for(let[e,t]of r){if(o.slice(s,e).trim()){c=!0;break}s=t}c||=!!o.slice(s,t.block.loc.end.offset-1).trim(),!a&&!c&&r.length>0&&e.code.remove(t.loc.start.offset,t.loc.end.offset);for(let n of i)e.code.appendLeft(t.loc.end.offset,n)}async function k({code:r,generator:a,applyVariable:s,options:c,filename:d,applyUtilities:p},h,g){let _=r.original,v,b=g.loc.end.offset;if(g.type===`Atrule`&&g.name===`apply`&&g.prelude&&g.prelude.type===`Raw`)v=j(g.prelude.value.trim());else if(g.type===`Atrule`&&g.name===`apply`&&!g.prelude&&g.block)b=A(_,b),v=_.slice(g.loc.start.offset+6,b).trim();else if(g.type===`Declaration`&&s.includes(g.property)&&(g.value.type===`Value`||g.value.type===`Raw`)){let e=_.slice(g.value.loc.start.offset,g.value.loc.end.offset).trim();e=j(e),v=f(e).map(e=>j(e)).join(` `)}if(!v)return;v=M(v),v=y(v,a.config.theme,c.throwOnMissing??!0);let x=f(u(l(v))),S=await t(x,a),C=e(S);if(C.length&&(c.throwOnMissing??!0))throw Error(`${n(C)}${d?` in ${d}`:``}`);let w=i(S,a.parentOrders);p?.set(g.loc.start.offset,S.flatMap(([,e])=>e??[]));let T=+(_[b]===`;`),E=[g.loc.start.offset,b+T];if(!w.length)return r.remove(...E),{consumedRange:E,hasInlineUtility:!1,standaloneCss:[]};let D,O=!1,k=[];for(let e of w)if(e.kind===`top-level`)k.push(e.body);else if(e.kind===`standalone`){if(!D){let e=h.prelude;D={prelude:e,selector:m(e),replacementSelector:r.slice(h.prelude.loc.start.offset,h.prelude.loc.end.offset)}}let t=o(D,e,d);k.push(t)}else O=!0,r.appendLeft(g.loc.start.offset,e.body);return r.remove(...E),{consumedRange:E,hasInlineUtility:O,standaloneCss:k}}function A(e,t){let n=t;for(;e[n]===`@`;){let t=0;for(n++;n<e.length;){let r=e[n];if(r===`[`||r===`(`)t++;else if(r===`]`||r===`)`)t--;else if(t===0&&(/\s/.test(r)||r===`;`||r===`{`||r===`}`))break;n++}}return n}function j(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function M(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function N({code:e,generator:t,options:n},i){let a=await r(t,i,(t,n)=>e.slice(t,n),n.throwOnMissing??!0);a!==void 0&&e.overwrite(i.loc.start.offset,i.loc.end.offset,a)}const P=/(@screen [^{]+).+/g;function F({code:e,generator:t},n){if(n.prelude?.type!==`Raw`)return;let r=s(n.prelude.value,t.config.theme);if(!r)return;let i=n.loc.start.offset,a=e.original.slice(i,n.loc.end.offset);for(let t of a.matchAll(P))e.overwrite(i+t.index,i+t.index+t[1].length,`@media ${r}`)}const I=new Set([`presets`,`source`,`shortcut`,`safelist`,...b]);function L(e){let t=e.original;if(!t.includes(`@`))return;let n=E(t);if(!n.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))for(let t of n)(I.has(t.name)?t.terminator===`;`:t.name===`custom`&&t.terminator===`block`)&&e.remove(t.start,t.end)}function R(e){return b.some(t=>e.includes(`@${t}`))||e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}async function z(e,t,n,r,i,o){let s=new Map;await B(e,t,n,s,r,i,o);let c=[...s].sort(([e],[t])=>e-t).flatMap(([,e])=>e),l=await a(t,c,r);l&&e.appendLeft(e.original.length,`\n${l}`)}async function B(e,t,n,r,i,a,o){let{applyVariable:s}=n,c=n.varStyle;s===void 0&&(s=c===void 0?[`--at-apply`]:c?[`${c}apply`]:[]),s=p(s||[]);let l=e=>e.includes(`@apply`)||s.some(t=>e.includes(t)),u=a||e.original,d=l(u),f=u.includes(`@screen`),m=v(u)||_(u);if(a===void 0&&R(u)&&L(e),!d&&!m&&!f)return;let y=h(u,{parseCustomProperty:!0,parseAtrulePrelude:!1,positions:!0,filename:i,offset:o});if(y.type!==`StyleSheet`)return;let b=[],x=new WeakSet,S=new WeakSet,C={options:n,applyVariable:s,generator:t,code:e,filename:i,offset:o,applyUtilities:r},w=(a,o)=>B(e,t,n,r,i,a,o),T=async e=>{for(let t of e.block.children)t.type===`Raw`&&await w(t.value,t.loc.start.offset)};g(y,function(t){if(f&&t.type===`Atrule`&&t.name===`screen`)F(C,t);else if(m&&t.type===`Function`&&(t.name===`theme`||t.name===`icon`))return b.push(N(C,t)),this.skip;else d&&t.type===`Rule`&&l(e.original.slice(t.loc.start.offset,t.loc.end.offset))?(x.add(t),b.push(O(C,t,w))):t.type===`Raw`&&this.rule&&!x.has(this.rule)&&!S.has(this.rule)&&(S.add(this.rule),b.push(T(this.rule)))}),await Promise.all(b)}async function V(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await w(e,n,r),s=await c(o.config),l=[],u=[];for(let e of o.config.content?.filesystem??[])e.startsWith(`!`)?u.push(e.slice(1)):l.push(e);let{files:d,sources:f}=a?{files:[],sources:a}:i?await i(l,u):{files:[],sources:[]},p=await D(s,d,f);return{layers:p.getLayers()||``,files:d,unknown:o.unknown,matched:p.matched.size,hasTeacss:o.hasTeacss,hasPreset:!!o.config.presets?.length}}function H(e,t){let n=[],r=[],i=[];for(let a of E(e))a.name===`charset`&&a.terminator===`;`?(n.push(e.slice(a.start,a.end)),i.push({start:a.start,end:a.end,replacement:``})):a.name===`import`&&a.terminator===`;`?(r.push(e.slice(a.start,a.end)),i.push({start:a.start,end:a.end,replacement:``})):(b.includes(a.name)||a.name===`presets`||a.name===`source`||a.name===`shortcut`||a.name===`safelist`)&&a.terminator===`;`||a.name===`custom`&&a.terminator===`block`?i.push({start:a.start,end:a.end,replacement:``}):a.name===`teacss`&&a.prelude===``&&a.terminator!==`block`&&i.push({start:a.start,end:a.end,replacement:t});i.sort((e,t)=>e.start-t.start);let a=``,o=0;for(let t of i)a+=e.slice(o,t.start)+t.replacement,o=t.end;a+=e.slice(o);let s=a.startsWith(``)?``:``;s&&(a=a.slice(1));let c=[...n,...r];return s+(c.length?`${c.join(`
2
2
  `)}\n`:``)+a}function U(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:d,transform:(t,n,r)=>z(t,r.generator,e,n)}}export{x as customToTheme,U as default,S as diagnoseCustom,V as generateEntry,C as parseEntry,T as resolvePresets,H as spliceEntry,z as transformDirectives};
@@ -0,0 +1 @@
1
+ import{clone as e,comparableWidth as t,createGenerator as n,notNull as r,toArray as i}from"@teacss/core";import{clone as a,generate as o,ident as s,parse as c,walk as l}from"css-tree";import{calcMaxWidthBySize as u,hasIconFn as d,hasThemeFn as f,transformThemeFn as p,transformThemeString as m}from"@teacss/rule-helpers";function h(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=>o(e));return n.length===2&&/^:root:where\(html[:[]/.test(n[0])&&n[1]===`${n[0].slice(5)} *`}function g(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=c(e),i=e=>{e.children=e.children.map(e=>c(`:global(${o(e)})`,{context:`selector`}))};return l(r,{enter(e,t,r){if(e.type===`PseudoClassSelector`&&e.name===`global`)return this.skip;if(!n&&h(e)){let n=c(`:global(${o(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))}}),o(r)}function _(e){try{let t=c(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function v(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function y(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function b(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function x(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 S(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 C(e,t){let n=e.flatMap(([,e])=>e??[]).filter(r).sort((e,n)=>(e[3]?t.get(e[3])??0:0)-(n[3]?t.get(n[3])??0:0)||e[0]-n[0]);if(!n.length)return[];let i=[],a;for(let e of n){if(!a&&i.length===64){a=new Map;for(let e of i)w(a,e)}let t=e[1],n=e[3],r=t===void 0&&n===void 0&&_(e[2]),o=a?a.get(n)?.get(t)?.get(r):i.find(e=>e.value[1]===t&&e.value[3]===n&&e.topLevel===r);if(o){o.value[2]+=e[2];continue}let s={topLevel:r,value:[...e]};i.push(s),a&&w(a,s)}return i.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&x(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}})}function w(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 T(e,t,n){let r=e.selector,i=!1;if(t.selector&&t.selector!==`.\\-`){let n=E(e.prelude,t.selector);r=n.selector,i=!n.hasHost}let a=g(`${r}{${t.body}}`,n,i);if(t.parent){let n=S(t.parent);a=n.length>1?`${n.join(`{`)}{${a}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${a}}`:`${t.parent}{${a}}`}return g(a,n,!1)}function E(e,t){let n=c(`${t}{}`,{context:`rule`}).prelude,r=!1;if(l(n,{enter(e){if(h(e))return this.skip;e.type===`ClassSelector`&&s.decode(e.name)===`-`&&(r=!0)}}),!r)return{selector:o(n),hasHost:r};let i=a(n);return i.children.clear(),e.children.forEach(e=>{n.children.forEach(t=>{let n=a(t);l(n,{enter(t,n,r){if(h(t))return this.skip;t.type===`ClassSelector`&&s.decode(t.name)===`-`&&r.replace(n,a(e).children)}}),i.children.appendData(n)})}),{selector:o(i),hasHost:r}}function D(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 O(t,r,a){if(!r.length)return``;let o=t.config,s=[],c=()=>{if(t.config!==o)throw Error(`[@teacss] Configuration changed while generating @apply dependencies; retry the stylesheet transform.`)};for(let n of i(o.preflights)){let i=D(n,`getCSS`);if(!i)continue;let a=await Reflect.apply(i,n,[{generator:t,generated:[],theme:o.theme}]);c();let l=await Reflect.apply(i,n,[{generator:t,generated:e(r),theme:o.theme}]);c(),l&&l!==a&&s.push({layer:D(n,`layer`),getCSS:()=>l})}if(!s.length)return``;let l=await(await n({layers:o.layers,sortLayers:o.sortLayers,outputToCssLayers:o.outputToCssLayers,preflights:s})).generate(new Set,{safelist:!1});return c(),g(l.css,a,!0)}async function k(e,t,n,r=!0){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 i;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&&(i=[e[1].loc.start.offset,t.children.last.loc.end.offset])}let a=m(t.children.first.value,e.config.theme,!i&&r);return a===void 0&&i&&(a=await A(e,n(i[0],i[1]),r)),a}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(p(a,e.config.theme,r)),j(e,i,a)}}}async function A(e,t,n){if(!f(t)&&!d(t))return t;let r=[],i=[],a=c(t,{context:`value`,parseCustomProperty:!0,positions:!0});l(a,function(a){if(!(a.type!==`Function`||a.name!==`theme`&&a.name!==`icon`||!a.loc))return i.push(k(e,a,(e,n)=>t.slice(e,n),n).then(e=>{e!==void 0&&r.push({start:a.loc.start.offset,end:a.loc.end.offset,value:e})})),this.skip}),await Promise.all(i);let o=t;for(let e of r.sort((e,t)=>t.start-e.start))o=`${o.slice(0,e.start)}${e.value}${o.slice(e.end)}`;return o}async function j(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 M(e){return typeof e==`string`?t(e)??void 0:void 0}function N(e,t){let n=e.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: ${u(e)})`:`(min-width: ${e})`}let c=Object.entries(s),l=c.find(([e])=>e===n);if(!l)throw Error(`breakpoint ${n} not found`);let d=l[1],f=M(d),p,m;if(f!==void 0)for(let[e,t]of c){if(e===n)continue;let r=M(t);r===void 0||r.unit!==f.unit||r.value<=f.value||m!==void 0&&(r.value>m.value||r.value===m.value&&t>=p)||(p=t,m=r)}return`(min-width: ${d})${p===void 0?``:` and (max-width: ${u(p)})`}`}export{y as a,v as c,b as i,k as n,C as o,O as r,T as s,N as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/directives",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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",
@@ -23,17 +23,17 @@
23
23
  "dev": "tsdown --watch"
24
24
  },
25
25
  "dependencies": {
26
- "@teacss/config": "0.6.0",
27
- "@teacss/core": "0.6.0",
28
- "@teacss/rule-helpers": "0.6.0",
29
- "@teacss/runtime": "0.6.0",
26
+ "@teacss/config": "0.6.2",
27
+ "@teacss/core": "0.6.2",
28
+ "@teacss/rule-helpers": "0.6.2",
29
+ "@teacss/runtime": "0.6.2",
30
30
  "@types/css-tree": "^3.2.0",
31
31
  "css-tree": "^3.2.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@teacss/preset-icons": "0.6.0",
35
- "@teacss/preset-official": "0.6.0",
36
- "@teacss/preset-standard": "0.6.0",
34
+ "@teacss/preset-icons": "0.6.2",
35
+ "@teacss/preset-official": "0.6.2",
36
+ "@teacss/preset-standard": "0.6.2",
37
37
  "magic-string": "^1.2.3"
38
38
  },
39
39
  "engines": {
@@ -1 +0,0 @@
1
- import{clone as e,comparableWidth as t,createGenerator as n,notNull as r,toArray as i}from"@teacss/core";import{clone as a,generate as o,ident as s,parse as c,walk as l}from"css-tree";import{calcMaxWidthBySize as u,hasIconFn as d,hasThemeFn as f,transformThemeFn as p,transformThemeString as m}from"@teacss/rule-helpers";function h(e,t,n){if(!/\.module\.(?:css|postcss|scss|sass|less|styl|stylus)$/i.test(t?.split(/[?#]/,1)[0]??``)||!n&&!/@scope\s*\(/i.test(e))return e;let r=c(e),i=e=>{e.children=e.children.map(e=>c(`:global(${o(e)})`,{context:`selector`}))};return l(r,{enter(e){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))}}),o(r)}function g(e){try{let t=c(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function _(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function v(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function y(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function b(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 x(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 S(e,t){let n=e.flatMap(([,e])=>e??[]).filter(r).sort((e,n)=>(e[3]?t.get(e[3])??0:0)-(n[3]?t.get(n[3])??0:0)||e[0]-n[0]);if(!n.length)return[];let i=[],a;for(let e of n){if(!a&&i.length===64){a=new Map;for(let e of i)C(a,e)}let t=e[1],n=e[3],r=t===void 0&&n===void 0&&g(e[2]),o=a?a.get(n)?.get(t)?.get(r):i.find(e=>e.value[1]===t&&e.value[3]===n&&e.topLevel===r);if(o){o.value[2]+=e[2];continue}let s={topLevel:r,value:[...e]};i.push(s),a&&C(a,s)}return i.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&b(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}})}function C(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 w(e,t,n){let r=e.selector,i=!1;if(t.selector&&t.selector!==`.\\-`){let n=T(e.prelude,t.selector);r=n.selector,i=!n.hasHost}let a=h(`${r}{${t.body}}`,n,i);if(t.parent){let n=x(t.parent);a=n.length>1?`${n.join(`{`)}{${a}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${a}}`:`${t.parent}{${a}}`}return h(a,n,!1)}function T(e,t){let n=c(`${t}{}`,{context:`rule`}).prelude,r=!1;if(l(n,{visit:`ClassSelector`,enter(e){s.decode(e.name)===`-`&&(r=!0)}}),!r)return{selector:o(n),hasHost:r};let i=a(n);return i.children.clear(),e.children.forEach(e=>{n.children.forEach(t=>{let n=a(t);l(n,{visit:`ClassSelector`,enter(t,n,r){s.decode(t.name)===`-`&&r.replace(n,a(e).children)}}),i.children.appendData(n)})}),{selector:o(i),hasHost:r}}function E(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 D(t,r,a){if(!r.length)return``;let o=t.config,s=[],c=()=>{if(t.config!==o)throw Error(`[@teacss] Configuration changed while generating @apply dependencies; retry the stylesheet transform.`)};for(let n of i(o.preflights)){let i=E(n,`getCSS`);if(!i)continue;let a=await Reflect.apply(i,n,[{generator:t,generated:[],theme:o.theme}]);c();let l=await Reflect.apply(i,n,[{generator:t,generated:e(r),theme:o.theme}]);c(),l&&l!==a&&s.push({layer:E(n,`layer`),getCSS:()=>l})}if(!s.length)return``;let l=await(await n({layers:o.layers,sortLayers:o.sortLayers,outputToCssLayers:o.outputToCssLayers,preflights:s})).generate(new Set,{safelist:!1});return c(),h(l.css,a,!0)}async function O(e,t,n,r=!0){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 i;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&&(i=[e[1].loc.start.offset,t.children.last.loc.end.offset])}let a=m(t.children.first.value,e.config.theme,!i&&r);return a===void 0&&i&&(a=await k(e,n(i[0],i[1]),r)),a}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(p(a,e.config.theme,r)),A(e,i,a)}}}async function k(e,t,n){if(!f(t)&&!d(t))return t;let r=[],i=[],a=c(t,{context:`value`,parseCustomProperty:!0,positions:!0});l(a,function(a){if(!(a.type!==`Function`||a.name!==`theme`&&a.name!==`icon`||!a.loc))return i.push(O(e,a,(e,n)=>t.slice(e,n),n).then(e=>{e!==void 0&&r.push({start:a.loc.start.offset,end:a.loc.end.offset,value:e})})),this.skip}),await Promise.all(i);let o=t;for(let e of r.sort((e,t)=>t.start-e.start))o=`${o.slice(0,e.start)}${e.value}${o.slice(e.end)}`;return o}async function A(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 j(e){return typeof e==`string`?t(e)??void 0:void 0}function M(e,t){let n=e.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: ${u(e)})`:`(min-width: ${e})`}let c=Object.entries(s),l=c.find(([e])=>e===n);if(!l)throw Error(`breakpoint ${n} not found`);let d=l[1],f=j(d),p,m;if(f!==void 0)for(let[e,t]of c){if(e===n)continue;let r=j(t);r===void 0||r.unit!==f.unit||r.value<=f.value||m!==void 0&&(r.value>m.value||r.value===m.value&&t>=p)||(p=t,m=r)}return`(min-width: ${d})${p===void 0?``:` and (max-width: ${u(p)})`}`}export{v as a,_ as c,y as i,O as n,S as o,D as r,w as s,M as t};