@teacss/directives 0.9.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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-BdZNM9q8.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-Bix5v4_e.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-BdZNM9q8.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,resolveEntryConfig as x,scanTopLevelAtRules as S}from"@teacss/config";import{generateSources as C}from"@teacss/runtime/source-generation";async function w(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 T(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 T({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=D(g.prelude.value.trim());else if(g.type===`Atrule`&&g.name===`apply`&&!g.prelude&&g.block)b=E(_,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=D(e),v=f(e).map(e=>D(e)).join(` `)}if(!v)return;v=O(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,a.config.layers);p?.set(g.loc.start.offset,S.flatMap(([,e])=>e??[]));let T=+(_[b]===`;`),k=[g.loc.start.offset,b+T];if(!w.length)return r.remove(...k),{consumedRange:k,hasInlineUtility:!1,standaloneCss:[]};let A,j=!1,M=[];for(let e of w)if(e.kind===`top-level`)M.push(e.body);else if(e.kind===`standalone`){if(!A){let e=h.prelude;A={prelude:e,selector:m(e),replacementSelector:r.slice(h.prelude.loc.start.offset,h.prelude.loc.end.offset)}}let t=o(A,e,d);M.push(t)}else j=!0,r.appendLeft(g.loc.start.offset,e.body);return r.remove(...k),{consumedRange:k,hasInlineUtility:j,standaloneCss:M}}function E(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 D(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function O(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function k({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 A=/(@screen [^{]+).+/g;function j({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(A))e.overwrite(i+t.index,i+t.index+t[1].length,`@media ${r}`)}const M=new Set([`presets`,`source`,`shortcut`,`safelist`,...b]);function N(e){let t=e.original;if(!t.includes(`@`))return;let n=S(t);if(!n.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))for(let t of n)(M.has(t.name)?t.terminator===`;`:t.name===`custom`&&(t.terminator===`block`||t.terminator===`;`))&&e.remove(t.start,t.end)}function P(e){return b.some(t=>e.includes(`@${t}`))||e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}const F=Symbol.for(`@teacss/engine/instance`);function I(e){let t=e.applyVariable;return(t===void 0||(Array.isArray(t)?t.length===1&&t[0]===`--at-apply`:t===`--at-apply`))&&(e.throwOnMissing===void 0||e.throwOnMissing===!0)}async function L(e,t,n,r,i,o){let s=t[F];if(s&&i===void 0&&I(n)){let t=s.transformStylesheet(r??``,e.original);if(t)for(let{start:n,end:r,text:i}of t.edits)n===r?e.appendLeft(n,i):e.overwrite(n,r,i);return}let c=new Map;await R(e,t,n,c,r,i,o);let l=[...c].sort(([e],[t])=>e-t).flatMap(([,e])=>e),u=await a(t,l,r);u&&e.appendLeft(e.original.length,`\n${u}`)}async function R(e,t,n,r,i,a,o){let s=p((n.applyVariable??[`--at-apply`])||[]),c=e=>e.includes(`@apply`)||s.some(t=>e.includes(t)),l=a||e.original,u=c(l),d=l.includes(`@screen`),f=v(l)||_(l);if(a===void 0&&P(l)&&N(e),!u&&!f&&!d)return;let m=h(l,{parseCustomProperty:!0,parseAtrulePrelude:!1,positions:!0,filename:i,offset:o});if(m.type!==`StyleSheet`)return;let y=[],b=new WeakSet,x=new WeakSet,S={options:n,applyVariable:s,generator:t,code:e,filename:i,offset:o,applyUtilities:r},C=(a,o)=>R(e,t,n,r,i,a,o),T=async e=>{for(let t of e.block.children)t.type===`Raw`&&await C(t.value,t.loc.start.offset)};g(m,function(t){if(d&&t.type===`Atrule`&&t.name===`screen`)j(S,t);else if(f&&t.type===`Function`&&(t.name===`theme`||t.name===`icon`))return y.push(k(S,t)),this.skip;else u&&t.type===`Rule`&&c(e.original.slice(t.loc.start.offset,t.loc.end.offset))?(b.add(t),y.push(w(S,t,C))):t.type===`Raw`&&this.rule&&!b.has(this.rule)&&!x.has(this.rule)&&(x.add(this.rule),y.push(T(this.rule)))}),await Promise.all(y)}async function z(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await x(e,n,r),s=await c(o.config,{engine:`auto`}),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 C(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 B(e,t){let n=[],r=[],i=[];for(let a of S(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`||a.terminator===`;`)?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
- `)}\n`:``)+a}function V(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:d,transform:(t,n,r)=>L(t,r.generator,e,n)}}export{V as default,z as generateEntry,B as spliceEntry,L as transformDirectives};
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-Bix5v4_e.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,resolveEntryConfig as x,scanTopLevelAtRules as S}from"@teacss/config";import{generateSources as C}from"@teacss/runtime/source-generation";async function w(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 T(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 T({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=D(g.prelude.value.trim());else if(g.type===`Atrule`&&g.name===`apply`&&!g.prelude&&g.block)b=E(_,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=D(e),v=f(e).map(e=>D(e)).join(` `)}if(!v)return;v=O(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,a.config.layers);p?.set(g.loc.start.offset,S.flatMap(([,e])=>e??[]));let T=+(_[b]===`;`),k=[g.loc.start.offset,b+T];if(!w.length)return r.remove(...k),{consumedRange:k,hasInlineUtility:!1,standaloneCss:[]};let A,j=!1,M=[];for(let e of w)if(e.kind===`top-level`)M.push(e.body);else if(e.kind===`standalone`){if(!A){let e=h.prelude;A={prelude:e,selector:m(e),replacementSelector:r.slice(h.prelude.loc.start.offset,h.prelude.loc.end.offset)}}let t=o(A,e,d);M.push(t)}else j=!0,r.appendLeft(g.loc.start.offset,e.body);return r.remove(...k),{consumedRange:k,hasInlineUtility:j,standaloneCss:M}}function E(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 D(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function O(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function k({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 A=/(@screen [^{]+).+/g;function j({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(A))e.overwrite(i+t.index,i+t.index+t[1].length,`@media ${r}`)}const M=new Set([`presets`,`source`,`shortcut`,`safelist`,...b]);function N(e){let t=e.original;if(!t.includes(`@`))return;let n=S(t);if(!n.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))for(let t of n)(M.has(t.name)?t.terminator===`;`:t.name===`custom`&&(t.terminator===`block`||t.terminator===`;`))&&e.remove(t.start,t.end)}function P(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 F(e,t,n,r,i,o){let s=new Map;await I(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 I(e,t,n,r,i,a,o){let s=p((n.applyVariable??[`--at-apply`])||[]),c=e=>e.includes(`@apply`)||s.some(t=>e.includes(t)),l=a||e.original,u=c(l),d=l.includes(`@screen`),f=v(l)||_(l);if(a===void 0&&P(l)&&N(e),!u&&!f&&!d)return;let m=h(l,{parseCustomProperty:!0,parseAtrulePrelude:!1,positions:!0,filename:i,offset:o});if(m.type!==`StyleSheet`)return;let y=[],b=new WeakSet,x=new WeakSet,S={options:n,applyVariable:s,generator:t,code:e,filename:i,offset:o,applyUtilities:r},C=(a,o)=>I(e,t,n,r,i,a,o),T=async e=>{for(let t of e.block.children)t.type===`Raw`&&await C(t.value,t.loc.start.offset)};g(m,function(t){if(d&&t.type===`Atrule`&&t.name===`screen`)j(S,t);else if(f&&t.type===`Function`&&(t.name===`theme`||t.name===`icon`))return y.push(k(S,t)),this.skip;else u&&t.type===`Rule`&&c(e.original.slice(t.loc.start.offset,t.loc.end.offset))?(b.add(t),y.push(w(S,t,C))):t.type===`Raw`&&this.rule&&!b.has(this.rule)&&!x.has(this.rule)&&(x.add(this.rule),y.push(T(this.rule)))}),await Promise.all(y)}async function L(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await x(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 C(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 R(e,t){let n=[],r=[],i=[];for(let a of S(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`||a.terminator===`;`)?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
+ `)}\n`:``)+a}function z(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:d,transform:(t,n,r)=>F(t,r.generator,e,n)}}export{z as default,L as generateEntry,R as spliceEntry,F as transformDirectives};
@@ -1 +1 @@
1
- import{DEFAULT_LAYERS as e,LAYER_UTILITIES as t,clone as n,comparableWidth as r,compareParentAtRules as i,createGenerator as a,notNull as o,toArray as s}from"@teacss/core";import{clone as c,generate as l,ident as u,parse as d,walk as f}from"css-tree";import{calcMaxWidthBySize as p,hasIconFn as m,hasThemeFn as h,transformThemeFn as g,transformThemeString as _}from"@teacss/rule-helpers";function v(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=>l(e));return n.length===2&&/^:root:where\(html[:[]/.test(n[0])&&n[1]===`${n[0].slice(5)} *`}function y(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=d(e),i=e=>{e.children=e.children.map(e=>d(`:global(${l(e)})`,{context:`selector`}))};return f(r,{enter(e,t,r){if(e.type===`PseudoClassSelector`&&e.name===`global`)return this.skip;if(!n&&v(e)){let n=d(`:global(${l(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))}}),l(r)}function b(e){try{let t=d(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function x(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function S(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function C(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function w(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 T(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 E(n,r,a=e){let s=e=>Object.hasOwn(a,e)?a[e]??0:0,c=n.flatMap(([,e])=>e??[]).filter(o).sort((e,n)=>{let a=e[4]?.layer??t,o=n[4]?.layer??t,c=a===o?0:a<o?-1:1;return s(a)-s(o)||c||i(r,e[3]??``,n[3]??``)||e[0]-n[0]});if(!c.length)return[];let l=[],u=[],d,f;for(let e of c){let n=e[4]?.layer??t;if(n!==d&&(d=n,u=[],f=void 0),!f&&u.length===64){f=new Map;for(let e of u)D(f,e)}let r=e[1],i=e[3],a=r===void 0&&i===void 0&&b(e[2]),o=f?f.get(i)?.get(r)?.get(a):u.find(e=>e.value[1]===r&&e.value[3]===i&&e.topLevel===a);if(o){o.value[2]+=e[2];continue}let s={topLevel:a,value:[...e]};l.push(s),u.push(s),f&&D(f,s)}return l.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&w(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 D(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 O(e,t,n){let r=e.selector,i=!1;if(t.selector&&t.selector!==`.\\-`){let n=k(e.prelude,t.selector);r=n.selector,i=!n.hasHost}let a=y(`${r}{${t.body}}`,n,i);if(t.parent){let n=T(t.parent);a=n.length>1?`${n.join(`{`)}{${a}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${a}}`:`${t.parent}{${a}}`}return y(a,n,!1)}function k(e,t){let n=d(`${t}{}`,{context:`rule`}).prelude,r=!1;if(f(n,{enter(e){if(v(e))return this.skip;e.type===`ClassSelector`&&u.decode(e.name)===`-`&&(r=!0)}}),!r)return{selector:l(n),hasHost:r};let i=c(n);return i.children.clear(),e.children.forEach(e=>{n.children.forEach(t=>{let n=c(t);f(n,{enter(t,n,r){if(v(t))return this.skip;t.type===`ClassSelector`&&u.decode(t.name)===`-`&&r.replace(n,c(e).children)}}),i.children.appendData(n)})}),{selector:l(i),hasHost:r}}function A(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 j(e,t,r){if(!t.length)return``;await e[Symbol.for(`@teacss/engine/materialize`)]?.();let i=e.config,o=[],c=()=>{if(e.config!==i)throw Error(`[@teacss] Configuration changed while generating @apply dependencies; retry the stylesheet transform.`)};for(let r of s(i.preflights)){let a=A(r,`getCSS`);if(!a)continue;let s=await Reflect.apply(a,r,[{generator:e,generated:[],theme:i.theme}]);c();let l=await Reflect.apply(a,r,[{generator:e,generated:n(t),theme:i.theme}]);c(),l&&l!==s&&o.push({layer:A(r,`layer`),getCSS:()=>l})}if(!o.length)return``;let l=await(await a({layers:i.layers,sortLayers:i.sortLayers,outputToCssLayers:i.outputToCssLayers,preflights:o},{engine:`ts`})).generate(new Set,{safelist:!1});return c(),y(l.css,r,!0)}async function M(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=_(t.children.first.value,e.config.theme,!i&&r);return a===void 0&&i&&(a=await N(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(g(a,e.config.theme,r)),P(e,i,a)}}}async function N(e,t,n){if(!h(t)&&!m(t))return t;let r=[],i=[],a=d(t,{context:`value`,parseCustomProperty:!0,positions:!0});f(a,function(a){if(!(a.type!==`Function`||a.name!==`theme`&&a.name!==`icon`||!a.loc))return i.push(M(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 P(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 F(e){return typeof e==`string`?r(e)??void 0:void 0}function I(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: ${p(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=F(u),f,m;if(d!==void 0)for(let[e,t]of c){if(e===n)continue;let r=F(t);r===void 0||r.unit!==d.unit||r.value<=d.value||m!==void 0&&(r.value>m.value||r.value===m.value&&t>=f)||(f=t,m=r)}return`(min-width: ${u})${f===void 0?``:` and (max-width: ${p(f)})`}`}export{S as a,x as c,C as i,M as n,E as o,j as r,O as s,I as t};
1
+ import{DEFAULT_LAYERS as e,LAYER_UTILITIES as t,clone as n,comparableWidth as r,compareParentAtRules as i,createGenerator as a,notNull as o,toArray as s}from"@teacss/core";import{clone as c,generate as l,ident as u,parse as d,walk as f}from"css-tree";import{calcMaxWidthBySize as p,hasIconFn as m,hasThemeFn as h,transformThemeFn as g,transformThemeString as _}from"@teacss/rule-helpers";function v(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=>l(e));return n.length===2&&/^:root:where\(html[:[]/.test(n[0])&&n[1]===`${n[0].slice(5)} *`}function y(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=d(e),i=e=>{e.children=e.children.map(e=>d(`:global(${l(e)})`,{context:`selector`}))};return f(r,{enter(e,t,r){if(e.type===`PseudoClassSelector`&&e.name===`global`)return this.skip;if(!n&&v(e)){let n=d(`:global(${l(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))}}),l(r)}function b(e){try{let t=d(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function x(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function S(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function C(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function w(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 T(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 E(n,r,a=e){let s=e=>Object.hasOwn(a,e)?a[e]??0:0,c=n.flatMap(([,e])=>e??[]).filter(o).sort((e,n)=>{let a=e[4]?.layer??t,o=n[4]?.layer??t,c=a===o?0:a<o?-1:1;return s(a)-s(o)||c||i(r,e[3]??``,n[3]??``)||e[0]-n[0]});if(!c.length)return[];let l=[],u=[],d,f;for(let e of c){let n=e[4]?.layer??t;if(n!==d&&(d=n,u=[],f=void 0),!f&&u.length===64){f=new Map;for(let e of u)D(f,e)}let r=e[1],i=e[3],a=r===void 0&&i===void 0&&b(e[2]),o=f?f.get(i)?.get(r)?.get(a):u.find(e=>e.value[1]===r&&e.value[3]===i&&e.topLevel===a);if(o){o.value[2]+=e[2];continue}let s={topLevel:a,value:[...e]};l.push(s),u.push(s),f&&D(f,s)}return l.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&w(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 D(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 O(e,t,n){let r=e.selector,i=!1;if(t.selector&&t.selector!==`.\\-`){let n=k(e.prelude,t.selector);r=n.selector,i=!n.hasHost}let a=y(`${r}{${t.body}}`,n,i);if(t.parent){let n=T(t.parent);a=n.length>1?`${n.join(`{`)}{${a}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${a}}`:`${t.parent}{${a}}`}return y(a,n,!1)}function k(e,t){let n=d(`${t}{}`,{context:`rule`}).prelude,r=!1;if(f(n,{enter(e){if(v(e))return this.skip;e.type===`ClassSelector`&&u.decode(e.name)===`-`&&(r=!0)}}),!r)return{selector:l(n),hasHost:r};let i=c(n);return i.children.clear(),e.children.forEach(e=>{n.children.forEach(t=>{let n=c(t);f(n,{enter(t,n,r){if(v(t))return this.skip;t.type===`ClassSelector`&&u.decode(t.name)===`-`&&r.replace(n,c(e).children)}}),i.children.appendData(n)})}),{selector:l(i),hasHost:r}}function A(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 j(e,t,r){if(!t.length)return``;let i=e.config,o=[],c=()=>{if(e.config!==i)throw Error(`[@teacss] Configuration changed while generating @apply dependencies; retry the stylesheet transform.`)};for(let r of s(i.preflights)){let a=A(r,`getCSS`);if(!a)continue;let s=await Reflect.apply(a,r,[{generator:e,generated:[],theme:i.theme}]);c();let l=await Reflect.apply(a,r,[{generator:e,generated:n(t),theme:i.theme}]);c(),l&&l!==s&&o.push({layer:A(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 c(),y(l.css,r,!0)}async function M(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=_(t.children.first.value,e.config.theme,!i&&r);return a===void 0&&i&&(a=await N(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(g(a,e.config.theme,r)),P(e,i,a)}}}async function N(e,t,n){if(!h(t)&&!m(t))return t;let r=[],i=[],a=d(t,{context:`value`,parseCustomProperty:!0,positions:!0});f(a,function(a){if(!(a.type!==`Function`||a.name!==`theme`&&a.name!==`icon`||!a.loc))return i.push(M(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 P(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 F(e){return typeof e==`string`?r(e)??void 0:void 0}function I(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: ${p(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=F(u),f,m;if(d!==void 0)for(let[e,t]of c){if(e===n)continue;let r=F(t);r===void 0||r.unit!==d.unit||r.value<=d.value||m!==void 0&&(r.value>m.value||r.value===m.value&&t>=f)||(f=t,m=r)}return`(min-width: ${u})${f===void 0?``:` and (max-width: ${p(f)})`}`}export{S as a,x as c,C as i,M as n,E as o,j as r,O as s,I as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/directives",
3
- "version": "0.9.4",
3
+ "version": "0.10.0",
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.9.4",
28
- "@teacss/core": "0.9.4",
29
- "@teacss/rule-helpers": "0.9.4",
30
- "@teacss/runtime": "0.9.4",
27
+ "@teacss/config": "0.10.0",
28
+ "@teacss/core": "0.10.0",
29
+ "@teacss/rule-helpers": "0.10.0",
30
+ "@teacss/runtime": "0.10.0",
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.9.4",
36
- "@teacss/preset-official": "0.9.4",
37
- "@teacss/preset-standard": "0.9.4",
35
+ "@teacss/preset-icons": "0.10.0",
36
+ "@teacss/preset-official": "0.10.0",
37
+ "@teacss/preset-standard": "0.10.0",
38
38
  "magic-string": "^1.2.3"
39
39
  },
40
40
  "engines": {