@teacss/directives 0.4.7 → 0.5.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/README.md +15 -39
- package/dist/core.d.ts +8 -8
- package/dist/core.js +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -1
- package/dist/{screen-core-Cd0-m9gz.js → screen-core-fFvftCEd.js} +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
# @teacss/directives
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
This package expands authoring helpers such as `@apply`, `@screen`,
|
|
8
|
-
`theme(...)`, and `icon(...)` before CSS is emitted by integrations.
|
|
9
|
-
|
|
10
|
-
It is a shared implementation for TeaCSS build-integration authors. The main
|
|
11
|
-
entry provides the source-transformer and CSS-entry helpers used by official
|
|
12
|
-
pipelines, while `@teacss/directives/core` exposes adapter-neutral primitives
|
|
13
|
-
for other CSS ASTs. It does not own source scanning, watching, or bundler
|
|
14
|
-
lifecycle; applications should normally select a build integration instead.
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
3
|
+
Shared transforms for TeaCSS CSS authoring helpers.
|
|
17
4
|
|
|
18
5
|
```css
|
|
19
6
|
.button {
|
|
@@ -29,26 +16,18 @@ lifecycle; applications should normally select a build integration instead.
|
|
|
29
16
|
}
|
|
30
17
|
```
|
|
31
18
|
|
|
32
|
-
`
|
|
33
|
-
|
|
19
|
+
The package handles `@apply`, `@screen`, `theme(...)`, and `icon(...)`.
|
|
20
|
+
`@screen at-*` selects the next greater comparable breakpoint as its upper
|
|
21
|
+
bound, including same-unit logical viewport (`svi`, `dvb`, etc.) and root-font
|
|
22
|
+
(`rex`, `rch`, `rcap`, `ric`) lengths. Different relative units remain incomparable.
|
|
23
|
+
`icon()` receives `<collection>-<icon-name>` without the `icon:` utility
|
|
24
|
+
prefix. Group syntax and attached `[]` values follow the same parsing rules as
|
|
25
|
+
class lists.
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
Official Vite, PostCSS, Rsbuild, Bun, and CLI pipelines use these transforms
|
|
28
|
+
automatically.
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
`--at-apply` forms, like every other class-list surface; a group body may hold
|
|
40
|
-
another group, and the outer condition chain lands after the inner one.
|
|
41
|
-
`theme("key", fallback)` inside an arbitrary value resolves the fallback when
|
|
42
|
-
the key is missing.
|
|
43
|
-
|
|
44
|
-
Used automatically by the Vite, PostCSS, Rsbuild, Bun, and CLI pipelines.
|
|
45
|
-
When an integration splices a CSS entry, a BOM and native `@charset` remain
|
|
46
|
-
before hoisted `@import` rules.
|
|
47
|
-
|
|
48
|
-
## Integration-author API
|
|
49
|
-
|
|
50
|
-
CSS adapters can reuse the same directive semantics through the public core
|
|
51
|
-
subpath:
|
|
30
|
+
Integration authors can reuse adapter-neutral semantics from the Core subpath:
|
|
52
31
|
|
|
53
32
|
```ts
|
|
54
33
|
import {
|
|
@@ -59,11 +38,8 @@ import {
|
|
|
59
38
|
} from "@teacss/directives/core";
|
|
60
39
|
```
|
|
61
40
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## Status
|
|
41
|
+
Core helpers do not mutate a stylesheet. The adapter supplies its AST and source
|
|
42
|
+
operations. When an integration splices an entry, native `@charset` and hoisted
|
|
43
|
+
`@import` rules stay before generated content.
|
|
67
44
|
|
|
68
|
-
Pre-1.0
|
|
69
|
-
TeaCSS build integration instead.
|
|
45
|
+
Pre-1.0. Applications should normally use a build adapter.
|
package/dist/core.d.ts
CHANGED
|
@@ -23,19 +23,19 @@ interface ApplyHost {
|
|
|
23
23
|
readonly selector: string;
|
|
24
24
|
readonly replacementSelector: string;
|
|
25
25
|
}
|
|
26
|
-
declare function resolveApplyTokens(classNames: readonly string[], generator: TeacssGenerator): Promise<ResolvedApplyToken[]>;
|
|
27
|
-
declare function missingApplyTokens(tokens: readonly ResolvedApplyToken[]): string[];
|
|
28
|
-
declare function formatMissingApplyTokens(missing: readonly string[]): string;
|
|
29
|
-
declare function prepareApplyUtilities(tokens: readonly ResolvedApplyToken[], parentOrders: ReadonlyMap<string, number>): PreparedApplyUtility[];
|
|
30
|
-
declare function renderStandaloneApplyUtility(host: ApplyHost, utility: StandaloneApplyUtility): string;
|
|
26
|
+
export declare function resolveApplyTokens(classNames: readonly string[], generator: TeacssGenerator): Promise<ResolvedApplyToken[]>;
|
|
27
|
+
export declare function missingApplyTokens(tokens: readonly ResolvedApplyToken[]): string[];
|
|
28
|
+
export declare function formatMissingApplyTokens(missing: readonly string[]): string;
|
|
29
|
+
export declare function prepareApplyUtilities(tokens: readonly ResolvedApplyToken[], parentOrders: ReadonlyMap<string, number>): PreparedApplyUtility[];
|
|
30
|
+
export declare function renderStandaloneApplyUtility(host: ApplyHost, utility: StandaloneApplyUtility): string;
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region src/function-core.d.ts
|
|
33
33
|
type ReadSourceRange = (start: number, end: number) => string;
|
|
34
34
|
/** Resolve a TeaCSS declaration-value function without mutating an adapter's source. */
|
|
35
|
-
declare function resolveCssFunction(generator: TeacssGenerator, node: FunctionNode, readSourceRange: ReadSourceRange, throwOnMissing?: boolean): Promise<string | undefined>;
|
|
35
|
+
export declare function resolveCssFunction(generator: TeacssGenerator, node: FunctionNode, readSourceRange: ReadSourceRange, throwOnMissing?: boolean): Promise<string | undefined>;
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region src/screen-core.d.ts
|
|
38
38
|
/** Resolve an `@screen` value to the media-query condition shared by CSS adapters. */
|
|
39
|
-
declare function resolveScreenQuery(rawBreakpoint: string, theme: object): string | undefined;
|
|
39
|
+
export declare function resolveScreenQuery(rawBreakpoint: string, theme: object): string | undefined;
|
|
40
40
|
//#endregion
|
|
41
|
-
export {
|
|
41
|
+
export type { ApplyHost, PreparedApplyUtility, ResolvedApplyToken, StandaloneApplyUtility };
|
package/dist/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./screen-core-
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./screen-core-fFvftCEd.js";export{i as formatMissingApplyTokens,t as missingApplyTokens,e as prepareApplyUtilities,r as renderStandaloneApplyUtility,a as resolveApplyTokens,n as resolveCssFunction,o as resolveScreenQuery};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MagicStringLike, SourceCodeTransformer, TeacssGenerator } from "@teacss/core";
|
|
2
2
|
import { customToTheme, diagnoseCustom, parseEntry, resolvePresets } from "@teacss/config";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
interface TransformerDirectivesOptions {
|
|
4
|
+
export interface TransformerDirectivesOptions {
|
|
5
5
|
enforce?: SourceCodeTransformer["enforce"];
|
|
6
6
|
/**
|
|
7
7
|
* Throw an error if utils or themes are not found.
|
|
@@ -27,7 +27,7 @@ interface TransformerDirectivesOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
varStyle?: false | string;
|
|
29
29
|
}
|
|
30
|
-
interface TransformerDirectivesContext {
|
|
30
|
+
export interface TransformerDirectivesContext {
|
|
31
31
|
code: MagicStringLike;
|
|
32
32
|
generator: TeacssGenerator;
|
|
33
33
|
options: TransformerDirectivesOptions;
|
|
@@ -37,7 +37,7 @@ interface TransformerDirectivesContext {
|
|
|
37
37
|
}
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/generateEntry.d.ts
|
|
40
|
-
interface GenerateEntryOptions {
|
|
40
|
+
export interface GenerateEntryOptions {
|
|
41
41
|
/** Entry file directory — base for `@preset` relative specifiers and `@source` globs. */
|
|
42
42
|
base: string;
|
|
43
43
|
/** Entry filename, when known, so local `@import` cycles include the root identity. */
|
|
@@ -50,7 +50,7 @@ interface GenerateEntryOptions {
|
|
|
50
50
|
/** Inline content to extract utilities from — skips `readSources` (tests / programmatic use). */
|
|
51
51
|
contents?: string[];
|
|
52
52
|
}
|
|
53
|
-
interface GenerateEntryResult {
|
|
53
|
+
export interface GenerateEntryResult {
|
|
54
54
|
/** Generated stylesheet (preflight `:root`/mode theme vars + utilities) to splice at `@teacss`. */
|
|
55
55
|
layers: string;
|
|
56
56
|
/** Absolute paths scanned (for watch registration). */
|
|
@@ -77,7 +77,7 @@ interface GenerateEntryResult {
|
|
|
77
77
|
* consumed directives) is the caller's job. The core engine is untouched — this
|
|
78
78
|
* is integration-layer orchestration.
|
|
79
79
|
*/
|
|
80
|
-
declare function generateEntry(entryCss: string, options: GenerateEntryOptions): Promise<GenerateEntryResult>;
|
|
80
|
+
export declare function generateEntry(entryCss: string, options: GenerateEntryOptions): Promise<GenerateEntryResult>;
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region src/spliceEntry.d.ts
|
|
83
83
|
/**
|
|
@@ -91,12 +91,12 @@ declare function generateEntry(entryCss: string, options: GenerateEntryOptions):
|
|
|
91
91
|
* Pure, css-tree-free: exact top-level at-rule ranges are scanned structurally
|
|
92
92
|
* and spliced out of the original.
|
|
93
93
|
*/
|
|
94
|
-
declare function spliceEntry(entryCss: string, layers: string): string;
|
|
94
|
+
export declare function spliceEntry(entryCss: string, layers: string): string;
|
|
95
95
|
//#endregion
|
|
96
96
|
//#region src/transform.d.ts
|
|
97
|
-
declare function transformDirectives(code: MagicStringLike, generator: TeacssGenerator, options: TransformerDirectivesOptions, filename?: string, originalCode?: string, offset?: number): Promise<void>;
|
|
97
|
+
export declare function transformDirectives(code: MagicStringLike, generator: TeacssGenerator, options: TransformerDirectivesOptions, filename?: string, originalCode?: string, offset?: number): Promise<void>;
|
|
98
98
|
//#endregion
|
|
99
99
|
//#region src/index.d.ts
|
|
100
|
-
|
|
100
|
+
export default function transformerDirectives(options?: TransformerDirectivesOptions): SourceCodeTransformer;
|
|
101
101
|
//#endregion
|
|
102
|
-
export {
|
|
102
|
+
export { customToTheme, diagnoseCustom, parseEntry, resolvePresets };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./screen-core-
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"./screen-core-fFvftCEd.js";import{createGenerator as s,expandClassGroups as c,expandVariantGroup as l,isCssId as u,splitClassTokens as d,toArray as f}from"@teacss/core";import{generate as p,parse as m,walk as h}from"css-tree";import{hasIconFn as g,hasThemeFn as _,transformThemeFn as v}from"@teacss/rule-helpers";import{customToTheme as y,diagnoseCustom as b,parseEntry as x,resolveEntryConfig as S,resolvePresets as C,scanTopLevelAtRules as w}from"@teacss/config";import{generateSources as T}from"@teacss/runtime/source-generation";async function E(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 D(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 D({code:n,generator:o,applyVariable:s,options:u,filename:f},m,h){let g=n.original,_,y=h.loc.end.offset;if(h.type===`Atrule`&&h.name===`apply`&&h.prelude&&h.prelude.type===`Raw`)_=k(h.prelude.value.trim());else if(h.type===`Atrule`&&h.name===`apply`&&!h.prelude&&h.block)y=O(g,y),_=g.slice(h.loc.start.offset+6,y).trim();else if(h.type===`Declaration`&&s.includes(h.property)&&(h.value.type===`Value`||h.value.type===`Raw`)){let e=g.slice(h.value.loc.start.offset,h.value.loc.end.offset).trim();e=k(e),_=d(e).map(e=>k(e)).join(` `)}if(!_)return;_=A(_),_=v(_,o.config.theme,u.throwOnMissing??!0);let b=d(l(c(_))),x=await a(b,o),S=t(x);if(S.length&&(u.throwOnMissing??!0))throw Error(`${i(S)}${f?` in ${f}`:``}`);let C=e(x,o.parentOrders),w=+(g[y]===`;`),T=[h.loc.start.offset,y+w];if(!C.length)return n.remove(...T),{consumedRange:T,hasInlineUtility:!1,standaloneCss:[]};let E,D=!1,j=[];for(let e of C)if(e.kind===`top-level`)j.push(e.body);else if(e.kind===`standalone`){if(!E){let e=m.prelude;E={prelude:e,selector:p(e),replacementSelector:n.slice(m.prelude.loc.start.offset,m.prelude.loc.end.offset)}}let t=r(E,e);j.push(t)}else D=!0,n.appendLeft(h.loc.start.offset,e.body);return n.remove(...T),{consumedRange:T,hasInlineUtility:D,standaloneCss:j}}function O(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 k(e){return e.replace(/^(['"])(.*)\1$/,`$2`)}function A(e){return e.replace(/\/\*[\s\S]*?\*\//g,``)}async function j({code:e,generator:t,options:r},i){let a=await n(t,i,(t,n)=>e.slice(t,n),r.throwOnMissing??!0);a!==void 0&&e.overwrite(i.loc.start.offset,i.loc.end.offset,a)}const M=/(@screen [^{]+).+/g;function N({code:e,generator:t},n){if(n.prelude?.type!==`Raw`)return;let r=o(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(M))e.overwrite(i+t.index,i+t.index+t[1].length,`@media ${r}`)}const P=new Set([`preset`,`source`,`shortcut`,`safelist`]);function F(e){let t=e.original;if(!t.includes(`@`))return;let n=w(t);if(!n.some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`))for(let t of n)(P.has(t.name)?t.terminator===`;`:t.name===`custom`&&t.terminator===`block`)&&e.remove(t.start,t.end)}function I(e){return e.includes(`@preset`)||e.includes(`@source`)||e.includes(`@shortcut`)||e.includes(`@safelist`)||e.includes(`@custom`)}async function L(e,t,n,r,i,a){let{applyVariable:o}=n,s=n.varStyle;o===void 0&&(o=s===void 0?[`--at-apply`]:s?[`${s}apply`]:[]),o=f(o||[]);let c=e=>e.includes(`@apply`)||o.some(t=>e.includes(t)),l=i||e.original,u=c(l),d=l.includes(`@screen`),p=_(l)||g(l);if(i===void 0&&I(l)&&F(e),!u&&!p&&!d)return;let v=m(l,{parseCustomProperty:!0,parseAtrulePrelude:!1,positions:!0,filename:r,offset:a});if(v.type!==`StyleSheet`)return;let y=[],b=new WeakSet,x=new WeakSet,S={options:n,applyVariable:o,generator:t,code:e,filename:r,offset:a},C=(i,a)=>L(e,t,n,r,i,a),w=async e=>{for(let t of e.block.children)t.type===`Raw`&&await C(t.value,t.loc.start.offset)};h(v,function(t){if(d&&t.type===`Atrule`&&t.name===`screen`)N(S,t);else if(p&&t.type===`Function`&&(t.name===`theme`||t.name===`icon`))return y.push(j(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(E(S,t,C))):t.type===`Raw`&&this.rule&&!b.has(this.rule)&&!x.has(this.rule)&&(x.add(this.rule),y.push(w(this.rule)))}),await Promise.all(y)}async function R(e,t){let{base:n,entryFile:r,readSources:i,contents:a}=t,o=await S(e,n,r),c=await s(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 T(c,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 z(e,t){let n=[],r=[],i=[];for(let a of w(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
2
|
`)}\n`:``)+a}function B(e={}){return{name:`@teacss/directives`,enforce:e.enforce,idFilter:u,transform:(t,n,r)=>L(t,r.generator,e,n)}}export{y as customToTheme,B as default,b as diagnoseCustom,R as generateEntry,x as parseEntry,C as resolvePresets,z as spliceEntry,L as transformDirectives};
|
|
@@ -1 +1 @@
|
|
|
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=[]
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/directives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -23,17 +23,17 @@
|
|
|
23
23
|
"dev": "tsdown --watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@teacss/config": "0.
|
|
27
|
-
"@teacss/core": "0.
|
|
28
|
-
"@teacss/rule-helpers": "0.
|
|
29
|
-
"@teacss/runtime": "0.
|
|
30
|
-
"@types/css-tree": "^2.
|
|
26
|
+
"@teacss/config": "0.5.0",
|
|
27
|
+
"@teacss/core": "0.5.0",
|
|
28
|
+
"@teacss/rule-helpers": "0.5.0",
|
|
29
|
+
"@teacss/runtime": "0.5.0",
|
|
30
|
+
"@types/css-tree": "^3.2.0",
|
|
31
31
|
"css-tree": "^3.2.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@teacss/preset-icons": "0.
|
|
35
|
-
"@teacss/preset-standard": "0.
|
|
36
|
-
"magic-string": "^1.
|
|
34
|
+
"@teacss/preset-icons": "0.5.0",
|
|
35
|
+
"@teacss/preset-standard": "0.5.0",
|
|
36
|
+
"magic-string": "^1.2.3"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=22.12.0"
|