@teacss/directives 0.5.1 → 0.5.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 +13 -0
- package/dist/core.d.ts +5 -1
- package/dist/core.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -2
- package/dist/screen-core-Dxp40_3u.js +1 -0
- package/package.json +7 -7
- package/dist/screen-core-fFvftCEd.js +0 -1
package/README.md
CHANGED
|
@@ -27,10 +27,17 @@ class lists.
|
|
|
27
27
|
Official Vite, PostCSS, Rsbuild, Bun, and CLI pipelines use these transforms
|
|
28
28
|
automatically.
|
|
29
29
|
|
|
30
|
+
With Standard's `preflight: "on-demand"`, applied utilities carry their required
|
|
31
|
+
theme variables in the consuming stylesheet, including non-entry CSS modules.
|
|
32
|
+
This does not generate additional utility selectors or repeat static resets
|
|
33
|
+
and full-theme preflights. Replacing or removing the module removes its
|
|
34
|
+
dependencies too.
|
|
35
|
+
|
|
30
36
|
Integration authors can reuse adapter-neutral semantics from the Core subpath:
|
|
31
37
|
|
|
32
38
|
```ts
|
|
33
39
|
import {
|
|
40
|
+
generateApplyPreflights,
|
|
34
41
|
prepareApplyUtilities,
|
|
35
42
|
resolveApplyTokens,
|
|
36
43
|
resolveCssFunction,
|
|
@@ -41,5 +48,11 @@ import {
|
|
|
41
48
|
Core helpers do not mutate a stylesheet. The adapter supplies its AST and source
|
|
42
49
|
operations. When an integration splices an entry, native `@charset` and hoisted
|
|
43
50
|
`@import` rules stay before generated content.
|
|
51
|
+
After resolving all applies, pass their flattened utility payloads to
|
|
52
|
+
`generateApplyPreflights(generator, generated, filename)` and append its CSS at the
|
|
53
|
+
stylesheet's top level. It preserves configured CSS layers and keeps dependency
|
|
54
|
+
state local to that stylesheet. Pass the filename so conventional `.module.css`
|
|
55
|
+
stylesheets keep generated theme selectors global while author selectors remain
|
|
56
|
+
local.
|
|
44
57
|
|
|
45
58
|
Pre-1.0. Applications should normally use a build adapter.
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TeacssGenerator } from "@teacss/core";
|
|
1
|
+
import { StringifiedUtil, TeacssGenerator } from "@teacss/core";
|
|
2
2
|
import { FunctionNode, SelectorList } from "css-tree";
|
|
3
3
|
//#region src/apply-core.d.ts
|
|
4
4
|
type ResolvedApplyToken = readonly [name: string, utilities: Awaited<ReturnType<TeacssGenerator["parseToken"]>>];
|
|
@@ -29,6 +29,10 @@ export declare function formatMissingApplyTokens(missing: readonly string[]): st
|
|
|
29
29
|
export declare function prepareApplyUtilities(tokens: readonly ResolvedApplyToken[], parentOrders: ReadonlyMap<string, number>): PreparedApplyUtility[];
|
|
30
30
|
export declare function renderStandaloneApplyUtility(host: ApplyHost, utility: StandaloneApplyUtility): string;
|
|
31
31
|
//#endregion
|
|
32
|
+
//#region src/apply-preflights.d.ts
|
|
33
|
+
/** Carry dependency-sensitive preflights with the stylesheet that inlined the utilities. */
|
|
34
|
+
export declare function generateApplyPreflights<Theme extends object>(generator: TeacssGenerator<Theme>, generated: readonly StringifiedUtil<Theme>[], filename?: string): Promise<string>;
|
|
35
|
+
//#endregion
|
|
32
36
|
//#region src/function-core.d.ts
|
|
33
37
|
type ReadSourceRange = (start: number, end: number) => string;
|
|
34
38
|
/** Resolve a TeaCSS declaration-value function without mutating an adapter's source. */
|
package/dist/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,
|
|
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-Dxp40_3u.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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MagicStringLike, SourceCodeTransformer, TeacssGenerator } from "@teacss/core";
|
|
1
|
+
import { MagicStringLike, SourceCodeTransformer, StringifiedUtil, TeacssGenerator } from "@teacss/core";
|
|
2
2
|
import { customToTheme, diagnoseCustom, parseEntry, resolvePresets } from "@teacss/config";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
export interface TransformerDirectivesOptions {
|
|
@@ -34,6 +34,8 @@ export interface TransformerDirectivesContext {
|
|
|
34
34
|
applyVariable: string[];
|
|
35
35
|
offset?: number;
|
|
36
36
|
filename?: string;
|
|
37
|
+
/** Applied payloads owned by this stylesheet, keyed by source offset. */
|
|
38
|
+
applyUtilities?: Map<number, StringifiedUtil[]>;
|
|
37
39
|
}
|
|
38
40
|
//#endregion
|
|
39
41
|
//#region src/generateEntry.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,
|
|
2
|
-
`)}\n`:``)+a}function
|
|
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-Dxp40_3u.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{customToTheme as b,diagnoseCustom as x,parseEntry as S,resolveEntryConfig as C,resolvePresets as w,scanTopLevelAtRules as T}from"@teacss/config";import{generateSources as E}from"@teacss/runtime/source-generation";async function D(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 O(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 O({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=A(g.prelude.value.trim());else if(g.type===`Atrule`&&g.name===`apply`&&!g.prelude&&g.block)b=k(_,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=A(e),v=f(e).map(e=>A(e)).join(` `)}if(!v)return;v=j(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,M=[];for(let e of w)if(e.kind===`top-level`)M.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);M.push(t)}else O=!0,r.appendLeft(g.loc.start.offset,e.body);return r.remove(...E),{consumedRange:E,hasInlineUtility:O,standaloneCss:M}}function k(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 A(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function j(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function M({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 N=/(@screen [^{]+).+/g;function P({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(N))e.overwrite(i+t.index,i+t.index+t[1].length,`@media ${r}`)}const F=new Set([`preset`,`source`,`shortcut`,`safelist`]);function I(e){let t=e.original;if(!t.includes(`@`))return;let n=T(t);if(!n.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))for(let t of n)(F.has(t.name)?t.terminator===`;`:t.name===`custom`&&t.terminator===`block`)&&e.remove(t.start,t.end)}function L(e){return e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}async function R(e,t,n,r,i,o){let s=new Map;await z(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 z(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&&L(u)&&I(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)=>z(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`)P(C,t);else if(m&&t.type===`Function`&&(t.name===`theme`||t.name===`icon`))return b.push(M(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(D(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 B(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await C(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 E(s,d,f);return{layers:p.getLayers()||``,files:d,unknown:o.unknown,undeclared:o.undeclared,matched:p.matched.size,hasTeacss:o.hasTeacss,hasPreset:!!o.config.presets?.length}}function V(e,t){let n=[],r=[],i=[];for(let a of T(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:``})):(a.name===`preset`||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
|
+
`)}\n`:``)+a}function H(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:d,transform:(t,n,r)=>R(t,r.generator,e,n)}}export{b as customToTheme,H as default,x as diagnoseCustom,B as generateEntry,S as parseEntry,w as resolvePresets,V as spliceEntry,R 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,parse as s,walk as c}from"css-tree";import{calcMaxWidthBySize as l,hasIconFn as u,hasThemeFn as d,transformThemeFn as f,transformThemeString as p}from"@teacss/rule-helpers";function m(e){try{let t=s(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function h(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function g(e){return e.filter(([,e])=>e==null).map(([e])=>e)}function _(e){return`[@teacss] @apply: no rule matched ${e.map(e=>`"${e}"`).join(`, `)}`}function v(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 y(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 b(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)x(a,e)}let t=e[1],n=e[3],r=t===void 0&&n===void 0&&m(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&&x(a,s)}return i.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&v(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 x(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 S(e,t){let n=e.selector;t.selector&&t.selector!==`.\\-`&&(n=C(e.prelude,t.selector));let r=`${n}{${t.body}}`;if(t.parent){let n=y(t.parent);r=n.length>1?`${n.join(`{`)}{${r}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${r}}`:`${t.parent}{${r}}`}return r}function C(e,t){let n=s(`${t}{}`,{context:`rule`}).prelude;if(!t.includes(`.\\-`))return o(n);let r=a(n);return r.children.clear(),e.children.forEach(e=>{n.children.forEach(t=>{let n=a(t);c(n,{visit:`ClassSelector`,enter(t,n,r){t.name===`\\-`&&r.replace(n,a(e).children)}}),r.children.appendData(n)})}),o(r)}function w(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)}}function T(e){let t=s(e);return c(t,{visit:`Rule`,enter(e){this.atrule&&/(?:^|-)keyframes$/i.test(this.atrule.name)||e.prelude.type===`SelectorList`&&(e.prelude.children=e.prelude.children.map(e=>s(`:global(${o(e)})`,{context:`selector`})))}}),o(t)}async function E(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=w(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:w(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(),/\.module\.(?:css|postcss|scss|sass|less|styl|stylus)$/i.test(a?.split(/[?#]/,1)[0]??``)?T(l.css):l.css}async function D(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=p(t.children.first.value,e.config.theme,!i&&r);return a===void 0&&i&&(a=await O(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(f(a,e.config.theme,r)),k(e,i,a)}}}async function O(e,t,n){if(!d(t)&&!u(t))return t;let r=[],i=[],a=s(t,{context:`value`,parseCustomProperty:!0,positions:!0});c(a,function(a){if(!(a.type!==`Function`||a.name!==`theme`&&a.name!==`icon`||!a.loc))return i.push(D(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 k(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 A(e){return typeof e==`string`?t(e)??void 0:void 0}function j(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: ${l(e)})`:`(min-width: ${e})`}let c=Object.entries(s),u=c.find(([e])=>e===n);if(!u)throw Error(`breakpoint ${n} not found`);let d=u[1],f=A(d),p,m;if(f!==void 0)for(let[e,t]of c){if(e===n)continue;let r=A(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: ${l(p)})`}`}export{g as a,h as c,_ as i,D as n,b as o,E as r,S as s,j as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/directives",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.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,16 +23,16 @@
|
|
|
23
23
|
"dev": "tsdown --watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@teacss/config": "0.5.
|
|
27
|
-
"@teacss/core": "0.5.
|
|
28
|
-
"@teacss/rule-helpers": "0.5.
|
|
29
|
-
"@teacss/runtime": "0.5.
|
|
26
|
+
"@teacss/config": "0.5.2",
|
|
27
|
+
"@teacss/core": "0.5.2",
|
|
28
|
+
"@teacss/rule-helpers": "0.5.2",
|
|
29
|
+
"@teacss/runtime": "0.5.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.5.
|
|
35
|
-
"@teacss/preset-standard": "0.5.
|
|
34
|
+
"@teacss/preset-icons": "0.5.2",
|
|
35
|
+
"@teacss/preset-standard": "0.5.2",
|
|
36
36
|
"magic-string": "^1.2.3"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{comparableWidth as e,notNull as t}from"@teacss/core";import{clone as n,generate as r,parse as i,walk as a}from"css-tree";import{calcMaxWidthBySize as o,hasIconFn as s,hasThemeFn as c,transformThemeFn as l,transformThemeString as u}from"@teacss/rule-helpers";function d(e){try{let t=i(e,{context:`declarationList`});for(let e of t.children)if(e.type===`Atrule`)return!0}catch{}return!1}async function f(e,t){return await Promise.all(e.map(async e=>[e,await t.parseToken(e,`-`)]))}function p(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 h(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 g(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){let r=e.flatMap(([,e])=>e??[]).filter(t).sort((e,t)=>(e[3]?n.get(e[3])??0:0)-(t[3]?n.get(t[3])??0:0)||e[0]-t[0]);if(!r.length)return[];let i=[],a;for(let e of r){if(!a&&i.length===64){a=new Map;for(let e of i)v(a,e)}let t=e[1],n=e[3],r=t===void 0&&n===void 0&&d(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&&v(a,s)}return i.map(({topLevel:e,value:[,t,n,r,i]})=>{let a=t&&h(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 v(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 y(e,t){let n=e.selector;t.selector&&t.selector!==`.\\-`&&(n=b(e.prelude,t.selector));let r=`${n}{${t.body}}`;if(t.parent){let n=g(t.parent);r=n.length>1?`${n.join(`{`)}{${r}${`}`.repeat(n.length)}`:t.parent===`.\\-`?`${e.replacementSelector}{${r}}`:`${t.parent}{${r}}`}return r}function b(e,t){let o=i(`${t}{}`,{context:`rule`}).prelude;if(!t.includes(`.\\-`))return r(o);let s=n(o);return s.children.clear(),e.children.forEach(e=>{o.children.forEach(t=>{let r=n(t);a(r,{visit:`ClassSelector`,enter(t,r,i){t.name===`\\-`&&i.replace(r,n(e).children)}}),s.children.appendData(r)})}),r(s)}async function x(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=u(t.children.first.value,e.config.theme,!i&&r);return a===void 0&&i&&(a=await S(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(l(a,e.config.theme,r)),C(e,i,a)}}}async function S(e,t,n){if(!c(t)&&!s(t))return t;let r=[],o=[],l=i(t,{context:`value`,parseCustomProperty:!0,positions:!0});a(l,function(i){if(!(i.type!==`Function`||i.name!==`theme`&&i.name!==`icon`||!i.loc))return o.push(x(e,i,(e,n)=>t.slice(e,n),n).then(e=>{e!==void 0&&r.push({start:i.loc.start.offset,end:i.loc.end.offset,value:e})})),this.skip}),await Promise.all(o);let u=t;for(let e of r.sort((e,t)=>t.start-e.start))u=`${u.slice(0,e.start)}${e.value}${u.slice(e.end)}`;return u}async function C(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 w(t){return typeof t==`string`?e(t)??void 0:void 0}function T(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:s}=t,c=a??s??{};if(r!==`at`){if(!Object.hasOwn(c,n))throw Error(`breakpoint ${n} not found`);let e=c[n];return r===`lt`?`(max-width: ${o(e)})`:`(min-width: ${e})`}let l=Object.entries(c),u=l.find(([e])=>e===n);if(!u)throw Error(`breakpoint ${n} not found`);let d=u[1],f=w(d),p,m;if(f!==void 0)for(let[e,t]of l){if(e===n)continue;let r=w(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: ${o(p)})`}`}export{_ as a,p as i,x as n,y as o,m as r,f as s,T as t};
|