@teacss/vite-ts 0.0.0-stage → 0.10.1

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
4
+ Copyright (c) 2026-PRESENT Billgo <hi@billgo.me>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,57 @@
1
- # Temporary Holding Version
1
+ # @teacss/vite-ts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vite plugin for TeaCSS.
4
+
5
+ ```ts
6
+ import { defineConfig } from "vite";
7
+ import { pluginTeacss } from "@teacss/vite-ts";
8
+
9
+ export default defineConfig({
10
+ plugins: [pluginTeacss()],
11
+ });
12
+ ```
13
+
14
+ ```ts
15
+ import "virtual:teacss.css";
16
+ ```
17
+
18
+ ```css
19
+ @presets "standard";
20
+ @source "./src/**/*.{ts,tsx}";
21
+ @teacss;
22
+ ```
23
+
24
+ The plugin scans Vite modules, transforms TeaCSS directives, provides stylesheet
25
+ HMR, and emits final CSS assets. Production waits for transformed modules,
26
+ passes generated rules through Vite's CSS transform and minifier, and includes
27
+ the final CSS digest in dependent chunk hashes. Fixed asset names stay fixed.
28
+ Generated utility CSS has no build sourcemap.
29
+
30
+ When Lightning CSS is configured, calculated Bézier x coordinates are guarded
31
+ before direct CSS/CSS Modules parsing and generated-preflight optimization.
32
+ With the PostCSS transformer, the guard runs after user plugins and imports,
33
+ before Lightning CSS minification. Authored source maps are retained.
34
+ Native Lightning CSS processing captures the exact CSS returned by Vite's
35
+ resolver, including compiled Sass and Less in entries and imports. Original
36
+ source locations identify proven calculated timing values for repair before
37
+ minification. CSS Modules, assets, source maps and user visitors retain their
38
+ native behavior. Preprocessor hooks run once; compiler options, worker selection
39
+ and import resolution remain Vite-owned. No transformer change is needed.
40
+ See the [easing audit](../../docs/knowledge/steps-and-cubic-bezier-easing.md#authored-css-exposure)
41
+ for coverage and limitations.
42
+
43
+
44
+ Pre-1.0. Install this adapter and the entry's preset packages as development dependencies.
45
+
46
+ Development and production watch builds track source-scanned CSS declarations,
47
+ including new files, deleted files, recreated files, and initially missing external
48
+ absolute `@source` roots. This updates shortcuts and safelists; utility extraction
49
+ still follows Vite's loaded module graph and pipeline filters.
50
+ A bounded declaration check every 500 ms also recovers changes omitted by native
51
+ callbacks; unchanged declarations do not reload configuration or rebuild.
52
+
53
+ Glob-matched CSS file symlinks observe their physical file targets through
54
+ filtered shallow parent watches, including recovery after a failed member read.
55
+ Nested source directory symlinks observe physical target changes, including empty
56
+ targets and target deletion or recreation. Missing routes use shallow parent
57
+ observation. Failed reads retain the last accepted configuration.
@@ -0,0 +1 @@
1
+ import{readFileSync as e}from"node:fs";import{prepareEasingStylesheet as t}from"@teacss/directives/internal/easing";import{composeVisitors as n,transform as r}from"lightningcss";const i=new Set([`animation`,`animation-timing-function`,`transition`,`transition-timing-function`]);function a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function o(e){if(!a(e)||typeof e.type!=`string`||!a(e.value)||!a(e.value.loc))return;let{line:t,column:n}=e.value.loc;if(typeof t==`number`&&typeof n==`number`&&typeof e.value.loc.source_index==`number`)return{type:e.type,value:e.value,key:`${e.type}:${t}:${n}`}}function s(e,t=[]){if(Array.isArray(e))for(let n of e)s(n,t);else if(a(e)){let n=o(e);n&&t.push(n);for(let n of Object.values(e))s(n,t)}return t}function c(e,t=[]){if(Array.isArray(e))for(let n of e)c(n,t);else if(a(e)){if(o(e))return t;if(Array.isArray(e.declarations)&&Array.isArray(e.importantDeclarations))t.push(e);else for(let n of Object.values(e))c(n,t)}return t}function l(e){return a(e)&&typeof e.property==`string`&&i.has(e.property)}function u(e,t){return JSON.stringify(e)===JSON.stringify(t)}function d(e,t,n){let i=[];return r({...n,filename:t,code:Buffer.from(e),minify:!1,sourceMap:!1,visitor:{StyleSheet(e){i=s(e.rules)}}}),i}function f(n,r,i){let a=new Map;if(i===void 0&&!/\.css$/i.test(n))return a;let o=i??e(n,`utf8`),s=t(o);if(o===s)return a;let f=d(o,n,r),p=d(s,n,r);if(f.length!==p.length)return a;for(let e=0;e<f.length;e++){let t=f[e],n=p[e];if(t.type!==n.type)continue;let r=c(t.value),i=c(n.value);if(r.length!==i.length)continue;let o=[];for(let e=0;e<r.length;e++)for(let t of[`declarations`,`importantDeclarations`]){let n=r[e][t].filter(l),a=i[e][t].filter(l);n.length===a.length&&!u(n,a)&&o.push({before:n,after:a,block:e,field:t})}o.length&&a.set(t.key,o)}return a}function p(e,t=!1,r=()=>!1){return function(i){if(this&&r(this.filename))return typeof e.visitor==`function`?e.visitor.call(this,i):e.visitor??{};function d(e){if(t&&typeof e?.resolver?.read!=`function`&&!(e?.code instanceof Uint8Array))throw Error(`TeaCSS requires the Lightning CSS visitor factory to expose native source input before parsing.`)}d(this);let p=typeof e.visitor==`function`?e.visitor.call(this,i):e.visitor;d(this);let m=new Map;this?.code&&m.set(this.filename,Buffer.from(this.code).toString());let h=this?.resolver,g=h?.read;this&&h&&g&&(this.resolver={...h,resolve:h.resolve?.bind(h),async read(e){let t=await g.call(h,e);return m.set(e,t),t}});let _=n([{Rule(){},RuleExit(){},Declaration(){}},p??{}]),v=[],y=this,b=e,x=!1,S=[],C=new Map,w=[];function T(e){if(!a(e.value.loc))return;let n=e.value.loc.source_index;if(typeof n!=`number`)return;let r=m.get(v[n]);if(t&&r===void 0)throw Error(`TeaCSS did not capture Lightning CSS input for ${v[n]}. The native source boundary is incompatible.`);if(n===0&&r===void 0)return;let i=C.get(n);return i||(i=f(v[n],b,r),C.set(n,i)),i.get(e.key)}function E(e){let t=T(e);if(!t)return;let n=c(e.value);for(let e of t){let t=n[e.block]?.[e.field];if(!t||!u(t.filter(l),e.before))continue;let r=0;for(let n=0;n<t.length;n++)l(t[n])&&(t[n]=e.after[r++])}}return{...p,StyleSheet(t){v=t.sources;let n=/\.module\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/.test(v[0]);if(b=y?{...y,cssModules:y.cssModules??!1}:{...e,cssModules:n?e.cssModules??!0:!1},!p?.StyleSheet)return;for(let e of s(t.rules))E(e);let r=p.StyleSheet(t);return x=!!r,r},Rule(e){w=[];let t=x||S.at(-1)?.authoritative===!0;S.push({authoritative:t,exits:1});let n=o(e),r=!t&&n?T(n):void 0;if(n&&r){let e=c(n.value);for(let t=0;t<e.length;t++)for(let n of[`importantDeclarations`,`declarations`]){let i=e[t][n].filter(l),a=r.find(e=>e.block===t&&e.field===n&&u(i,e.before));for(let e=0;e<i.length;e++)w.push({before:i[e],after:a?.after[e]??i[e]})}}if(!p?.Rule)return;if(!t)for(let t of s(e))E(t);let i=_.Rule(e);if(i){w=[];let e=S[S.length-1];e.authoritative=!0,e.exits=Array.isArray(i)?i.length:1,e.exits===0&&S.pop()}return i},RuleExit(e){let t=S.at(-1);return t&&--t.exits===0&&S.pop(),_.RuleExit(e)},Declaration(e){let t=e;if(l(e)){let n=w.shift();n&&u(e,n.before)?t=n.after:w=[]}let n=_.Declaration(t);if(n)return n;if(!u(e,t))return t}}}}export{p as createEasingImportVisitor};
package/dist/impl.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { n as TeacssVitePluginConfig } from "./types-BplrH0_C.js";
2
+ import { UserConfigDefaults } from "@teacss/core";
3
+ import { Plugin } from "vite";
4
+ //#region src/impl.d.ts
5
+ export declare function createTeacssPlugins<Theme extends object>(configOrPath?: TeacssVitePluginConfig<Theme> | string, defaults?: UserConfigDefaults): Plugin[];
6
+ //#endregion
package/dist/impl.js ADDED
@@ -0,0 +1,2 @@
1
+ import{createHash as e}from"node:crypto";import{mkdtempSync as t,realpathSync as n,rmSync as r,watch as i,writeFileSync as a}from"node:fs";import{tmpdir as o}from"node:os";import{basename as s,join as c,posix as l,resolve as u}from"node:path";import d from"node:process";import f from"@jridgewell/remapping";import{entryDiscoveryFiles as p}from"@teacss/config";import{SourceWatchRegistry as m,createSourceDeclarationCheck as h,planSourceWatches as g,probeSourceDeclarations as _,sourceDeclarationMemberPaths as v,sourceDeclarationStateOf as ee,sourceDeclarationWatchTargets as y}from"@teacss/config/internal/source-scan";import{CSS_PLACEHOLDER as b,isCssId as x}from"@teacss/core";import{prepareEasingCss as te,prepareEasingStylesheet as ne}from"@teacss/directives/internal/easing";import{applyTransformerPipeline as re,createContext as ie,getModuleOutput as ae}from"@teacss/runtime";import{bundledAssetName as S,collectBundledAssets as oe,rewriteBundledAssets as se}from"@teacss/runtime/internal/bundled-assets";import ce from"magic-string";import{normalizePath as C,preprocessCSS as le,transformWithEsbuild as ue}from"vite";function w(e){return e.includes(`@apply`)||e.includes(`--at-apply`)||e.includes(`@screen`)||e.includes(`theme(`)||e.includes(`icon(`)}const T=async()=>{let{default:e}=await import(`@teacss/directives`);return e()};function de(e=T){let t;return{name:`@teacss/directives`,idFilter:x,async transform(n,r,i){if(w(n.original))return await(await(t??=e())).transform?.(n,r,i)}}}function fe(e,t,n){let r,a=!1,o=0,s,c=Promise.resolve(),l=new m((e,t,n)=>i(e,{recursive:n},t),()=>f(),n),u=h(e,async e=>{await c,!a&&e.signature!==r?.signature&&await f()},n);function d(){l.reconcile(g(y(e())))}function f(){if(!a)return c=c.then(async()=>{if(a)return;d();let n=o,i=s,c=await _(e()),l=await i;if(a||n!==o||(l&&(r=l),s=void 0,c.signature===r?.signature))return;let u=r;r=c;try{await t()}catch(e){throw r=u,e}!a&&n===o&&(r=c)}).catch(n),c}function p(){a=!0,u.retire(),l.retire()}return{resolved(){a||(d(),o++,s=_(e(),!0,r),s.catch(n),f())},retire:p,async close(){p(),await u.close(),await c}}}const pe=new Set([`virtual:teacss.css`,`teacss.css`]),E=`/*! ${b} */`,me=`teacss:css-ready`;function D(e,t,n){let r=e.lastIndexOf(t);return r<0||r+t.length!==e.length||r>0&&e[r-1]!==`/`?e:`${e.slice(0,r)}${n}`}function he(e,t,n){let r;try{r=JSON.parse(e)}catch{return e}let i=!1,a=e=>{if(typeof e==`string`){let r=D(e,t,n);return i||=r!==e,r}if(Array.isArray(e))return e.map(a);if(e&&typeof e==`object`)for(let[t,n]of Object.entries(e))e[t]=a(n);return e};return a(r),i?JSON.stringify(r,void 0,2):e}function ge(e,t){let n=0,r=``;for(let i=t;i<e.length;i++){let t=e[i];if(r){t===`\\`?i++:t===r&&(r=``);continue}if(t===`"`||t===`'`||t==="`")r=t;else if(t===`[`)n++;else if(t===`]`&&--n===0)return i}return-1}function O(e,t,n=0){for(let r=n;r<e.length;r++){let n=e[r];if(n===`'`||n===`"`||n==="`"){let t=n;for(r++;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t)break;continue}if(n===`/`&&e[r+1]===`/`){let t=e.indexOf(`
2
+ `,r+2);if(t<0)return-1;r=t;continue}if(n===`/`&&e[r+1]===`*`){let t=e.indexOf(`*/`,r+2);if(t<0)return-1;r=t+1;continue}if(e.startsWith(t,r))return r}return-1}function _e(e,t,n){let r=O(e,`const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=`);if(r<0)return e;let i=r+56;if(e[i]!==`[`)return e;let a=ge(e,i);if(a<0||!e.startsWith(`)))=>i.map(i=>d[i]);`,a+1)||O(e,`__vite__mapDeps([`,a+20+1)<0)return e;let o=JSON.stringify(t),s=e.slice(i,a+1),c=s.replaceAll(o,JSON.stringify(n));return c===s?e:`${e.slice(0,i)}${c}${e.slice(a+1)}`}const k={chrome:`chrome`,edge:`edge`,firefox:`firefox`,hermes:!1,ie:`ie`,ios:`ios_saf`,node:!1,opera:`opera`,rhino:!1,safari:`safari`},A={2015:[`chrome49`,`edge13`,`safari10`,`ios10`,`firefox44`,`opera36`],2016:[`chrome50`,`edge13`,`safari10`,`ios10`,`firefox43`,`opera37`],2017:[`chrome58`,`edge15`,`safari11`,`ios11`,`firefox52`,`opera45`],2018:[`chrome63`,`edge79`,`safari12`,`ios12`,`firefox58`,`opera50`],2019:[`chrome73`,`edge79`,`safari12.1`,`ios12.1`,`firefox64`,`opera60`],2020:[`chrome80`,`edge80`,`safari14.1`,`ios14.5`,`firefox80`,`opera67`],2021:[`chrome85`,`edge85`,`safari14.1`,`ios14.5`,`firefox80`,`opera71`],2022:[`chrome94`,`edge94`,`safari16.4`,`ios16.4`,`firefox93`,`opera80`],2023:[`chrome110`,`edge110`,`safari16.4`,`ios16.4`,`firefox146`,`opera96`],2024:[`chrome119`,`edge119`,`safari17.4`,`ios17.4`,`firefox145`,`opera105`],2025:[`chrome136`,`edge136`,`safari26.0`,`ios26.0`,`firefox138`,`opera121`]};function ve(e){let t={},n=(Array.isArray(e)?e:e?[e]:[]).flatMap(e=>{let t=/^es(6|\d{4})$/.exec(e);if(!t)return e;let n=t[1]===`6`?2015:Number(t[1]),r=A[n];if(!r)throw Error(`Unsupported target "${e}"`);return r});for(let e of n){if(e===`esnext`)continue;let n=/^([a-z_]+)(\d+)(?:\.(\d+))?$/i.exec(e),r=n&&k[n[1].toLowerCase()];if(r===!1)continue;if(!n||!r)throw Error(`Unsupported target "${e}"`);let i=Number(n[2])<<16|Number(n[3]??0)<<8;(!t[r]||i<t[r])&&(t[r]=i)}return t}function j(i,m={}){let h,g=i;if(i&&typeof i==`object`){h=i.lightningcss;let e={...i};delete e.lightningcss,delete e.mode,g=Object.keys(e).length?e:void 0}let _,y=ie(g,{envMode:d.env.NODE_ENV===`development`?`dev`:`build`,...m,transformers:[...m.transformers??[],de()]},e=>{_=ee(e)}),b=`/__tea.css`,x,w=!1,T=!0,D,ge,O,k,A=!1,j,M,N=new Set,P,F,I,ye=0;async function L(){P??=fe(()=>_,async()=>{w?await He():I&&a(I,String(++ye))},e=>x?.logger.error(e instanceof Error?e.message:String(e)));try{await P.resolved()}catch(e){throw P.retire(),P=void 0,e}}async function R(){let e=P;P=void 0,await e?.close(),F&&r(F,{recursive:!0,force:!0}),F=void 0,I=void 0}function be(e){let t=new Set(v(_).map(C));for(let n of N)t.has(n)||e(n);I&&e(I)}let z=new Map,B=new Map,V=new Map,H=new Set,U,W,G=0,xe=!1,K,q,J=0,Y=0,X,Z;function Se(){Z=void 0}function Ce(e=y.root){let t=y.getConfigFileList().map(C),n=new Set(t);if(typeof g==`object`){N=n;return}let r=C(typeof g==`string`?u(e,g):e);if(!t.includes(r))for(let e of p)n.add(C(c(r,e)));N=n}async function we(){let{prefix:e}=await y.getVMPRegexes();return b=`/${e}.css`,b}let Te=new Map,Q=new WeakMap,$=new WeakMap;function Ee(e){let t=S(e);return Te.set(t,e),`${x?.base??`/`}__teacss_fonts/${t}`}async function De(){let e=`url(${JSON.stringify(`${x?.base??`/`}__teacss_fonts/`).slice(0,-1)}`,t=(await se(await Oe(),Ee)).toString().replaceAll(e,`URL${e.slice(3)}`);return T=/@import/i.test(t),t}async function Oe(){await y.flushTasks();let e=Z;if(e&&e.config===y.generator.config&&e.tokens.length===y.tokens.size){let t=0,n=!0;for(let r of y.tokens)if(e.tokens[t++]!==r){n=!1;break}if(n)return await e.promise}let t=[...y.tokens],n={config:y.generator.config,promise:y.generator.generate(t,{minify:!1}).then(({css:e})=>e),tokens:t};Z=n;try{return await n.promise}catch(e){throw Z===n&&(Z=void 0),e}}async function ke(){let e=await Oe(),t=x;if(!t||!(`environments`in t))return e;let n=u(t.root,b.slice(1)),r=t.css.transformer===`lightningcss`,i=r?ne(e):e;if(r&&t.build.cssMinify===`lightningcss`&&!/@import/i.test(i))return Ae(i,n,t);let a=r&&t.build.cssMinify?{...t,build:{...t.build,cssMinify:!1}}:t,o=(await le(i,n,a)).code;if(!t.build.cssMinify)return o;if(t.build.cssMinify===`esbuild`){let e=t.esbuild||{},r={charset:e.charset,legalComments:e.legalComments,logLevel:e.logLevel,logLimit:e.logLimit,logOverride:e.logOverride},i=e.minifyIdentifiers!=null||e.minifySyntax!=null||e.minifyWhitespace!=null?{minifyIdentifiers:e.minifyIdentifiers??!0,minifySyntax:e.minifySyntax??!0,minifyWhitespace:e.minifyWhitespace??!0}:{minify:!0},a=await ue(o,n,{...r,...i,loader:`css`,sourcemap:!1,target:t.build.cssTarget||void 0},void 0,t,void 0,!0);for(let e of a.warnings)t.logger.warn(`[esbuild css minify] ${e.text}`);return a.code}return Ae(ne(o),n,t)}async function Ae(e,t,n){let{transform:r}=await import(`lightningcss`),i=n.css.lightningcss?.visitor,a=r({...n.css.lightningcss,visitor:i===D?ge:i,code:Buffer.from(e),cssModules:void 0,filename:t,minify:!0,targets:ve(n.build.cssTarget)});for(let e of a.warnings)n.logger.warn(`[lightningcss minify] ${e.message}`);return new TextDecoder().decode(a.code)}function je(){if(!O)return;let e=O;U&&clearTimeout(U),U=setTimeout(()=>{U=void 0;let t=W,n=(async()=>{if(t&&await t.catch(()=>{}),O!==e||(A?Y:J)>=G||(await Be(),await e.waitForRequestsIdle?.(),O!==e||(A?Y:J)>=G))return;let n=G,r=e.moduleGraph.getModuleById(b);if(!r){J=n,A&&(Y=n);return}A?(e.moduleGraph.invalidateModule(r),e.watcher.emit(`change`,r.file??b),Y=n,J=n):(e.moduleGraph.invalidateModule(r),J=n)})();W=n,n.then(()=>{W===n&&(W=void 0,O===e&&(A?Y:J)<G&&je())},t=>{W===n&&(W=void 0),e.config.logger.error(`TeaCSS failed to invalidate its virtual stylesheet`,{error:t})})},20)}function Me(){Se(),O&&(G++,je())}function Ne(e){if(!O)return;let t=!1;for(let n of e){let e=O.moduleGraph.getModuleById(n);e&&(O.moduleGraph.invalidateModule(e),t=!0)}t&&O.ws.send({type:`full-reload`})}function Pe(){U&&clearTimeout(U),U=void 0,A=!1,j?.(),j=void 0,M?.(),M=void 0,O=void 0,W=void 0}function Fe(){k??=y.onInvalidate(Me)}function Ie(){Se(),Pe(),k?.(),k=void 0}async function Le(e,t){let n={};z.set(t,n),B.set(t,e);try{let r=await re(y,e,t);return z.get(t)===n?(r?V.set(t,r.code):V.delete(t),y.filter(e,t)?await y.extract(r?.code??e,t):y.modules.has(t)&&await y.extract(``,t),r??null):r??null}finally{z.get(t)===n&&z.delete(t)}}async function Re(e,t){X&&await X;let n=Le(e,t),r=n.then(()=>{},()=>{});H.add(r);try{return await n}finally{H.delete(r)}}async function ze(e){let t=new Set(e),n=new Set([...B.keys(),...V.keys()]),r=[];for(let e of n)t.has(e)||(z.delete(e),B.delete(e),V.delete(e),r.push(y.extract(``,e)));await Promise.all(r)}async function Be(){for(;H.size;)await Promise.all(H)}async function Ve(){let e=Array.from(B),t=new Map(e.map(([e,t])=>[e,V.get(e)??t]));try{await y.reloadConfig()}finally{Ce(y.root),(O||I)&&await L()}await we();let n=[];for(let[r,i]of e){let e=ae(y,r)??i;e===i?V.delete(r):V.set(r,e),e!==t.get(r)&&n.push(r)}Ne(n)}async function He(){let e=X,t=(async()=>{e&&await e.catch(()=>{}),await Be(),await Ve()})();X=t;try{await t}finally{X===t&&(X=void 0)}}let Ue={name:`teacss`,enforce:`pre`,config(e,t){if(h===!1)return;let n=typeof h==`object`?h:void 0,r={};return e.css?.transformer===void 0&&(t.command===`build`||h!==void 0)&&(r.css={transformer:`lightningcss`,...n?{lightningcss:n}:{}}),e.build?.cssMinify===void 0&&(r.build={cssMinify:`lightningcss`}),r},async configResolved(e){if(x=e,e.css.transformer===`lightningcss`){let{createEasingImportVisitor:t}=await import(`./easing-imports-DvRhTc2n.js`),n=e.css.lightningcss??{};ge=n.visitor,D=t(n,!0,e=>w&&e===b&&!T),e.css.lightningcss={...n,visitor:D}}w=e.command===`serve`,await y.updateRoot(e.root),Ce(e.root),await we(),Fe()},async buildStart(){Q.set(this.environment??y,new Map),$.set(this.environment??y,new Set),xe=!1,K=void 0,q=void 0,Fe(),Ce(),!w&&x?.build?.watch?(I||(F=n(t(c(o(),`teacss-vite-watch-`))),I=c(F,`invalidate`),a(I,`0`)),be(e=>this.addWatchFile(e)),await L()):be(e=>this.addWatchFile(e))},async buildEnd(t){if(w||t)return;if(typeof this.getModuleIds==`function`&&await ze(this.getModuleIds()),!(xe||typeof this.getModuleInfo==`function`&&this.getModuleInfo(b)!=null)){q=void 0;return}K=await ke();let n=Q.get(this.environment??y)??new Map;Q.set(this.environment??y,n);for(let{asset:e}of oe(K))n.has(e.digest)||n.set(e.digest,this.emitFile({type:`asset`,name:S(e),source:e.bytes}));q=e(`sha256`).update(K).digest(`hex`)},configureServer(e){Pe(),O=e,e.middlewares?.use((t,n,r)=>{let i=`${e.config.base}__teacss_fonts/`,a=t.url?.split(`?`,1)[0],o=a?.startsWith(i)?Te.get(a.slice(i.length)):void 0;if(!o)return r();n.setHeader(`Content-Type`,`font/woff2`),n.setHeader(`Cache-Control`,`public, max-age=31536000, immutable`),n.end(o.bytes)}),L().catch(t=>e.config?.logger.error(String(t))),Fe();let t=()=>{O===e&&(A=!0,Y<G&&je())};if(e.hot?.on(me,t),j=()=>e.hot?.off(me,t),e.httpServer){let t=()=>{O===e&&(Ie(),R())};e.httpServer.once(`close`,t),M=()=>e.httpServer?.off(`close`,t)}},async closeBundle(){Ie(),(w||!x?.build?.watch)&&await R()},async closeWatcher(){Ie(),await R()},transformIndexHtml:{order:`pre`,async handler(e,{filename:t}){y.filter(e,t)?await y.extract(e,t):y.modules.has(t)&&await y.extract(``,t)}},async resolveId(e){return pe.has(e)||pe.has(e.replace(/^\//,``))||e.startsWith(`${b}?`)?b:null},async load(e){return e===b?w?await De():(xe=!0,E):null},async transform(e,t){if(t===b)return null;let n=await Re(e,t);if(!w||!/\.css(?:$|\?)/i.test(t))return n;let r=await se(n?.code??e,Ee);if(!r.hasChanged())return n;let i=r.generateMap({hires:!0,includeContent:!0,source:t});return{code:r.toString(),map:n?.map?f([i,n.map],()=>null).toString():i}},async watchChange(e,t){if(e===I||N.has(C(e)))try{await He()}finally{be(e=>this.addWatchFile(e))}else X&&await X;if(t.event===`delete`){let t=new Set([e]);for(let n of[...y.modules.keys(),...z.keys(),...B.keys()])(n===e||n.startsWith(`${e}?`))&&t.add(n);for(let e of t)z.delete(e),B.delete(e),V.delete(e);await Promise.all(Array.from(t,e=>y.extract(``,e)))}},async generateBundle(e,t){if(w)return;let n,r=Q.get(this.environment??y)??new Map;for(let[i,a]of Object.entries(t)){if(a.type!==`asset`||!a.fileName.endsWith(`.css`))continue;let o=typeof a.source==`string`?a.source:new TextDecoder().decode(a.source);if(!o.includes(E)&&!o.includes(`;teacss=v1-`))continue;o.includes(E)&&(n??=K??await ke());let c=new Set,u=async e=>(await se(o.replaceAll(E,n??``),t=>{let n=r.get(t.digest);n||(n=this.emitFile({type:`asset`,name:S(t),source:t.bytes}),r.set(t.digest,n));let i=this.getFileName(n);c.add(i);let a=x?.base??`/`;return a===`./`||a===``?`./${l.relative(l.dirname(e),i)}`:`${a}${i}`})).toString(),d=await u(a.fileName);for(let e of Object.values(t))if(e.type===`chunk`&&e.viteMetadata?.importedCss.has(a.fileName))for(let t of c)e.viteMetadata.importedAssets.add(t);let f=typeof e.assetFileNames!=`string`||e.assetFileNames.includes(`[hash`);if(typeof e.assetFileNames==`function`){let t={name:a.name,names:a.names,originalFileName:a.originalFileName??void 0,originalFileNames:a.originalFileNames,type:`asset`},n=e.assetFileNames({...t,source:a.source}),r=e.assetFileNames({...t,source:d});f=r.includes(`[hash`)||r!==n}if(!x||!(`environments`in x)||!f){a.source=d;continue}let p=e=>this.getFileName(this.emitFile({type:`asset`,name:a.name||s(a.fileName),...a.originalFileName?{originalFileName:a.originalFileName}:{},source:e})),m=p(d),h=await u(m);if(h!==d){let e=$.get(this.environment??y)??new Set;if(e.add(m),$.set(this.environment??y,e),d=h,m=p(d),await u(m)!==d)throw Error(`TeaCSS CSS output naming changes its font-relative directory after URL resolution`)}let g=new Set,_=x.build.manifest,v=x.build.ssrManifest;_&&g.add(typeof _==`string`?_:`.vite/manifest.json`),v&&g.add(typeof v==`string`?v:`.vite/ssr-manifest.json`);for(let e of Object.values(t))e.viteMetadata?.importedCss.delete(a.fileName)&&e.viteMetadata.importedCss.add(m),e.type===`chunk`?e.code=_e(e.code,a.fileName,m):e!==a&&typeof e.source==`string`&&g.has(e.fileName)&&(e.source=he(e.source,a.fileName,m));delete t[i]}}},We={name:`teacss:api`,enforce:`post`,api:{getContext:()=>y,getMode:()=>`global`},transform(e,t){return!w||t!==b||!e.includes(`import.meta.hot`)?null:`${e}\nimport.meta.hot.send(${JSON.stringify(me)});`},augmentChunkHash(){return q},generateBundle:{order:`post`,async handler(e,t){let n=Ue.generateBundle;typeof n==`function`&&await n.call(this,e,t,!1);let r=$.get(this.environment??y);for(let e of r??[])delete t[e];r?.clear()}}};function Ge(e){return{name:e?`teacss:easing-source`:`teacss:easing-output`,enforce:e,transform(t,n){let r=x;if(!r||r.css.transformer!==`lightningcss`&&r.build.cssMinify!==`lightningcss`||!/\.(?:css|scss|sass|less|styl|stylus|sss)(?:$|\?)/i.test(n)||/[?&](?:raw|url)(?:&|$)/.test(n)||e&&(r.css.transformer!==`lightningcss`||!/\.css(?:$|\?)/i.test(n)))return null;let i=new ce(t);return te(i),i.hasChanged()?{code:i.toString(),map:i.generateMap({hires:!0,includeContent:!0,source:n})}:null}}}return[Ue,We,Ge(`pre`),Ge()]}export{j as createTeacssPlugins};
@@ -0,0 +1,8 @@
1
+ import { n as TeacssVitePluginConfig, t as TeacssVitePluginAPI } from "./types-BplrH0_C.js";
2
+ import { UserConfigDefaults } from "@teacss/core";
3
+ import { Plugin } from "vite";
4
+ //#region src/index.d.ts
5
+ export declare function defineConfig<Theme extends object>(config: TeacssVitePluginConfig<Theme>): TeacssVitePluginConfig<Theme>;
6
+ export declare function pluginTeacss<Theme extends object>(configOrPath?: TeacssVitePluginConfig<Theme> | string, defaults?: UserConfigDefaults): Plugin[];
7
+ //#endregion
8
+ export { TeacssVitePluginAPI, TeacssVitePluginConfig };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{createRequire as e}from"node:module";import{enableNodeCompileCache as t}from"@teacss/runtime/internal/compile-cache";function n(e){return e}t();const r=e(import.meta.url);function i(e,t={}){let n,i=()=>(n??=r("./impl.js").createTeacssPlugins(e,t),n),a=(e,t)=>function(...n){return i()[e][t].call(this,...n)},o=(e,t)=>function(...n){return i()[e][t].handler.call(this,...n)};return[{name:`teacss`,enforce:`pre`,config:a(0,`config`),configResolved:a(0,`configResolved`),buildStart:a(0,`buildStart`),buildEnd:a(0,`buildEnd`),configureServer:a(0,`configureServer`),closeBundle:a(0,`closeBundle`),closeWatcher:a(0,`closeWatcher`),transformIndexHtml:{order:`pre`,handler:o(0,`transformIndexHtml`)},resolveId:a(0,`resolveId`),load:a(0,`load`),transform:a(0,`transform`),watchChange:a(0,`watchChange`),generateBundle:a(0,`generateBundle`)},{name:`teacss:api`,enforce:`post`,api:{getContext:()=>i()[1].api?.getContext(),getMode:()=>`global`},transform:a(1,`transform`),augmentChunkHash:a(1,`augmentChunkHash`),generateBundle:{order:`post`,handler:o(1,`generateBundle`)}},{name:`teacss:easing-source`,enforce:`pre`,transform:a(2,`transform`)},{name:`teacss:easing-output`,enforce:void 0,transform:a(3,`transform`)}]}export{n as defineConfig,i as pluginTeacss};
@@ -0,0 +1,32 @@
1
+ import { TeacssPluginContext, UserConfig } from "@teacss/core";
2
+ import { LightningCSSOptions } from "vite";
3
+ //#region src/types.d.ts
4
+ interface TeacssVitePluginConfig<Theme extends object = object> extends UserConfig<Theme> {
5
+ /**
6
+ * Generation mode. Only `global` is supported (a single virtual stylesheet
7
+ * collecting every utility found across the project).
8
+ *
9
+ * @default "global"
10
+ */
11
+ mode?: "global";
12
+ /**
13
+ * Drive Vite's CSS pipeline with **lightningcss** instead of PostCSS + esbuild:
14
+ * sets `css.transformer: "lightningcss"` (replaces PostCSS) and
15
+ * `build.cssMinify: "lightningcss"` (replaces esbuild's CSS minifier). On by
16
+ * default — pass `false` to keep Vite's PostCSS + esbuild pipeline, or an
17
+ * object to forward lightningcss options (e.g. `targets`, `drafts`). Only
18
+ * fields you haven't set yourself are touched, so an explicit
19
+ * `css.transformer` / `build.cssMinify` always wins. Left unset, the
20
+ * transformer applies to builds only and the dev server keeps PostCSS;
21
+ * `true` or an options object applies it to the dev server too.
22
+ *
23
+ * @default true
24
+ */
25
+ lightningcss?: boolean | LightningCSSOptions;
26
+ }
27
+ interface TeacssVitePluginAPI {
28
+ getContext: () => TeacssPluginContext<TeacssVitePluginConfig>;
29
+ getMode: () => "global";
30
+ }
31
+ //#endregion
32
+ export { TeacssVitePluginConfig as n, TeacssVitePluginAPI as t };
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@teacss/vite-ts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.1",
4
+ "description": "Vite plugin for TeaCSS.",
5
+ "homepage": "https://css.teasim.com",
6
+ "funding": "https://github.com/sponsors/billgo",
7
+ "license": "MIT",
8
+ "author": "Billgo <hi@billgo.me>",
9
+ "sideEffects": false,
10
+ "type": "module",
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./impl": "./dist/impl.js",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "bunx tsdown --config tsdown.config.mts",
23
+ "dev": "tsdown --watch"
24
+ },
25
+ "dependencies": {
26
+ "@jridgewell/remapping": "^2.3.5",
27
+ "@teacss/config": "0.10.1",
28
+ "@teacss/core": "0.10.1",
29
+ "@teacss/directives": "0.10.1",
30
+ "@teacss/runtime": "0.10.1",
31
+ "lightningcss": "^1.33.0",
32
+ "magic-string": "^1.2.3"
33
+ },
34
+ "devDependencies": {
35
+ "consola": "^3.4.2",
36
+ "vite": "^8.2.2"
37
+ },
38
+ "peerDependencies": {
39
+ "vite": ">=8.0.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=22.12.0"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }