@teacss/vite-ts 0.0.0-stage → 0.10.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/LICENSE +22 -0
- package/README.md +56 -2
- package/dist/easing-imports-DvRhTc2n.js +1 -0
- package/dist/impl.d.ts +6 -0
- package/dist/impl.js +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/types-BplrH0_C.d.ts +32 -0
- package/package.json +45 -4
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
|
-
#
|
|
1
|
+
# @teacss/vite-ts
|
|
2
2
|
|
|
3
|
-
|
|
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](https://github.com/teacss/teacss-rs/blob/master/notes/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{existsSync as t,mkdtempSync as n,realpathSync as r,rmSync as i,watch as a,writeFileSync as o}from"node:fs";import{tmpdir as s}from"node:os";import{basename as c,join as l,posix as u,resolve as d}from"node:path";import f from"node:process";import p from"@jridgewell/remapping";import{entryDiscoveryFiles as m}from"@teacss/config";import{SourceWatchRegistry as h,createSourceDeclarationCheck as g,planSourceWatches as _,probeSourceDeclarations as v,sourceDeclarationMemberPaths as y,sourceDeclarationStateOf as ee,sourceDeclarationWatchTargets as b}from"@teacss/config/internal/source-scan";import{CSS_PLACEHOLDER as x,isCssId as S}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 oe,collectBundledAssets as se,rewriteBundledAssets as ce}from"@teacss/runtime/internal/bundled-assets";import le from"magic-string";import{normalizePath as C,preprocessCSS as ue,transformWithEsbuild as de}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 fe(e=T){let t;return{name:`@teacss/directives`,idFilter:S,async transform(n,r,i){if(w(n.original))return await(await(t??=e())).transform?.(n,r,i)}}}function pe(e,t,n){let r,i=!1,o=0,s,c=Promise.resolve(),l=new h((e,t,n)=>a(e,{recursive:n},t),()=>f(),n),u=g(e,async e=>{await c,!i&&e.signature!==r?.signature&&await f()},n);function d(){l.reconcile(_(b(e())))}function f(){if(!i)return c=c.then(async()=>{if(i)return;d();let n=o,a=s,c=await v(e()),l=await a;if(i||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}!i&&n===o&&(r=c)}).catch(n),c}function p(){i=!0,u.retire(),l.retire()}return{resolved(){i||(d(),o++,s=v(e(),!0,r),s.catch(n),f())},retire:p,async close(){p(),await u.close(),await c}}}const me=new Set([`virtual:teacss.css`,`teacss.css`]),he=`/*! ${x} */`,ge=`${x};`,E=`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 _e(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 O(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 k(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 ve(e,t,n){let r=k(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=O(e,i);if(a<0||!e.startsWith(`)))=>i.map(i=>d[i]);`,a+1)||k(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 A={chrome:`chrome`,edge:`edge`,firefox:`firefox`,hermes:!1,ie:`ie`,ios:`ios_saf`,node:!1,opera:`opera`,rhino:!1,safari:`safari`},j={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 ye(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=j[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&&A[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 M(a,h={}){let g,_=a;if(a&&typeof a==`object`){g=a.lightningcss;let e={...a};delete e.lightningcss,delete e.mode,_=Object.keys(e).length?e:void 0}let v,b,S=ie(_,{envMode:f.env.NODE_ENV===`development`?`dev`:`build`,...h,transformers:[...h.transformers??[],fe()]},e=>{b=ee(e)}),w=`/__tea.css`,T,D=!1,O=!0,k,A,j,M,N=!1,P,be,F=new Set,I,L,R,xe=0;async function Se(){I??=pe(()=>b,async()=>{D?await Ke():R&&o(R,String(++xe))},e=>T?.logger.error(e instanceof Error?e.message:String(e)));try{await I.resolved()}catch(e){throw I.retire(),I=void 0,e}}async function Ce(){let e=I;I=void 0,await e?.close(),L&&i(L,{recursive:!0,force:!0}),L=void 0,R=void 0}function we(e){let n=new Set(y(b).map(C)),r=[...F].filter(e=>!n.has(e));for(let t of r)e(t);R&&e(R);let i=r.filter(e=>!t(e));i.length&&j?.watcher?.add(i)}let z=new Map,B=new Map,V=new Map,H=new Set,U,W,G=0,Te=!1,K,q,J=0,Y=0,X,Z;function Ee(){Z=void 0}function De(e=S.root){let t=S.getConfigFileList().map(C),n=new Set(t);if(typeof _==`object`){F=n;return}let r=C(typeof _==`string`?d(e,_):e);if(!t.includes(r))for(let e of m)n.add(C(l(r,e)));F=n}async function Oe(){let{prefix:e}=await S.getVMPRegexes();return w=`/${e}.css`,w}let ke=new Map,Q=new WeakMap,$=new WeakMap;function Ae(e){let t=oe(e);return ke.set(t,e),`${T?.base??`/`}__teacss_fonts/${t}`}async function je(){let e=`url(${JSON.stringify(`${T?.base??`/`}__teacss_fonts/`).slice(0,-1)}`,t=(await ce(await Me(),Ae)).toString().replaceAll(e,`URL${e.slice(3)}`);return O=/@import/i.test(t),t}async function Me(){await S.flushTasks();let e=Z;if(e&&e.config===S.generator.config&&e.tokens.length===S.tokens.size){let t=0,n=!0;for(let r of S.tokens)if(e.tokens[t++]!==r){n=!1;break}if(n)return await e.promise}let t=[...S.tokens],n={config:S.generator.config,promise:S.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 Ne(e){let t=await Me(),n=T;if(!n||!(`environments`in n))return t;let r=e??n.build.cssMinify,i=d(n.root,w.slice(1)),a=n.css.transformer===`lightningcss`,o=a?ne(t):t;if(a&&r===`lightningcss`&&!/@import/i.test(o))return Pe(o,i,n);let s={...n,build:{...n.build,cssMinify:!a&&r}},c=(await ue(o,i,s)).code;if(!r)return c;if(r===`esbuild`){let e=n.esbuild||{},t={charset:e.charset,legalComments:e.legalComments,logLevel:e.logLevel,logLimit:e.logLimit,logOverride:e.logOverride},r=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 de(c,i,{...t,...r,loader:`css`,sourcemap:!1,target:n.build.cssTarget||void 0},void 0,n,void 0,!0);for(let e of a.warnings)n.logger.warn(`[esbuild css minify] ${e.text}`);return a.code}return Pe(ne(c),i,n)}async function Pe(e,t,n){let{transform:r}=await import(`lightningcss`),i=n.css.lightningcss?.visitor,a=r({...n.css.lightningcss,visitor:i===k?A:i,code:Buffer.from(e),cssModules:void 0,filename:t,minify:!0,targets:ye(n.build.cssTarget)});for(let e of a.warnings)n.logger.warn(`[lightningcss minify] ${e.message}`);return new TextDecoder().decode(a.code)}function Fe(){if(!j)return;let e=j;U&&clearTimeout(U),U=setTimeout(()=>{U=void 0;let t=W,n=(async()=>{if(t&&await t.catch(()=>{}),j!==e||(N?Y:J)>=G||(await We(),await e.waitForRequestsIdle?.(),j!==e||(N?Y:J)>=G))return;let n=G,r=e.moduleGraph.getModuleById(w);if(!r){J=n,N&&(Y=n);return}N?(e.moduleGraph.invalidateModule(r),e.watcher.emit(`change`,r.file??w),Y=n,J=n):(e.moduleGraph.invalidateModule(r),J=n)})();W=n,n.then(()=>{W===n&&(W=void 0,j===e&&(N?Y:J)<G&&Fe())},t=>{W===n&&(W=void 0),e.config.logger.error(`TeaCSS failed to invalidate its virtual stylesheet`,{error:t})})},20)}function Ie(){Ee(),j&&(G++,Fe())}function Le(e){if(!j)return;let t=!1;for(let n of e){let e=j.moduleGraph.getModuleById(n);e&&(j.moduleGraph.invalidateModule(e),t=!0)}t&&j.ws.send({type:`full-reload`})}function Re(){U&&clearTimeout(U),U=void 0,N=!1,P?.(),P=void 0,be?.(),be=void 0,j=void 0,W=void 0}function ze(){M??=S.onInvalidate(Ie)}function Be(){Ee(),Re(),M?.(),M=void 0}async function Ve(e,t){let n={};z.set(t,n),B.set(t,e);try{let r=await re(S,e,t);return z.get(t)===n?(r?V.set(t,r.code):V.delete(t),S.filter(e,t)?await S.extract(r?.code??e,t):S.modules.has(t)&&await S.extract(``,t),r??null):r??null}finally{z.get(t)===n&&z.delete(t)}}async function He(e,t){X&&await X;let n=Ve(e,t),r=n.then(()=>{},()=>{});H.add(r);try{return await n}finally{H.delete(r)}}async function Ue(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(S.extract(``,e)));await Promise.all(r)}async function We(){for(;H.size;)await Promise.all(H)}async function Ge(){let e=Array.from(B),t=new Map(e.map(([e,t])=>[e,V.get(e)??t]));try{await S.reloadConfig()}finally{De(S.root),(j||R)&&await Se()}await Oe();let n=[];for(let[r,i]of e){let e=ae(S,r)??i;e===i?V.delete(r):V.set(r,e),e!==t.get(r)&&n.push(r)}Le(n)}async function Ke(){let e=X,t=(async()=>{e&&await e.catch(()=>{}),await We(),await Ge()})();X=t;try{await t}finally{X===t&&(X=void 0)}}let qe={name:`teacss`,enforce:`pre`,config(e,t){if(v=void 0,g===!1)return;let n=typeof g==`object`?g:void 0,r={};return e.css?.transformer===void 0&&(t.command===`build`||g!==void 0)&&(r.css={transformer:`lightningcss`,...n?{lightningcss:n}:{}}),e.build?.cssMinify===void 0?(v=new Set(Object.entries(e.environments??{}).flatMap(([e,t])=>t.build?.cssMinify===void 0?[]:[e])),e.build?.minify!==!1&&(r.build={cssMinify:`lightningcss`}),r):r},configEnvironment(e,t){if(!v||v.has(e))return null;let{cssMinify:n,minify:r}=t.build??{};return n===void 0?r===!1?null:{build:{cssMinify:`lightningcss`}}:n===`lightningcss`&&r===!1?{build:{cssMinify:!1}}:null},async configResolved(e){if(T=e,e.css.transformer===`lightningcss`){let{createEasingImportVisitor:t}=await import(`./easing-imports-DvRhTc2n.js`),n=e.css.lightningcss??{};A=n.visitor,k=t(n,!0,e=>D&&e===w&&!O),e.css.lightningcss={...n,visitor:k}}D=e.command===`serve`,await S.updateRoot(e.root),De(e.root),await Oe(),ze()},async buildStart(){Q.set(this.environment??S,new Map),$.set(this.environment??S,new Set),Te=!1,K=void 0,q=void 0,ze(),De(),!D&&T?.build?.watch?(R||(L=r(n(l(s(),`teacss-vite-watch-`))),R=l(L,`invalidate`),o(R,`0`)),we(e=>this.addWatchFile(e)),await Se()):we(e=>this.addWatchFile(e))},async buildEnd(t){if(D||t)return;if(typeof this.getModuleIds==`function`&&await Ue(this.getModuleIds()),!(Te||typeof this.getModuleInfo==`function`&&this.getModuleInfo(w)!=null)){q=void 0;return}K=await Ne(this.environment?.config?.build?.cssMinify);let n=Q.get(this.environment??S)??new Map;Q.set(this.environment??S,n);for(let{asset:e}of se(K))n.has(e.digest)||n.set(e.digest,this.emitFile({type:`asset`,name:oe(e),source:e.bytes}));q=e(`sha256`).update(K).digest(`hex`)},configureServer(e){Re(),j=e,e.middlewares?.use((t,n,r)=>{let i=`${e.config.base}__teacss_fonts/`,a=t.url?.split(`?`,1)[0],o=a?.startsWith(i)?ke.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)}),Se().catch(t=>e.config?.logger.error(String(t))),ze();let t=()=>{j===e&&(N=!0,Y<G&&Fe())};if(e.hot?.on(E,t),P=()=>e.hot?.off(E,t),e.httpServer){let t=()=>{j===e&&(Be(),Ce())};e.httpServer.once(`close`,t),be=()=>e.httpServer?.off(`close`,t)}},async closeBundle(){Be(),(D||!T?.build?.watch)&&await Ce()},async closeWatcher(){Be(),await Ce()},transformIndexHtml:{order:`pre`,async handler(e,{filename:t}){S.filter(e,t)?await S.extract(e,t):S.modules.has(t)&&await S.extract(``,t)}},async resolveId(e){return me.has(e)||me.has(e.replace(/^\//,``))||e.startsWith(`${w}?`)?w:null},async load(e){return e===w?D?await je():(Te=!0,(this.environment?.config?.build?.cssMinify??T?.build?.cssMinify)===`esbuild`?ge:he):null},async transform(e,t){if(t===w)return null;let n=await He(e,t);if(!D||!/\.css(?:$|\?)/i.test(t))return n;let r=await ce(n?.code??e,Ae);if(!r.hasChanged())return n;let i=r.generateMap({hires:!0,includeContent:!0,source:t});return{code:r.toString(),map:n?.map?p([i,n.map],()=>null).toString():i}},async watchChange(e,t){if(e===R||F.has(C(e)))try{await Ke()}finally{we(e=>this.addWatchFile(e))}else X&&await X;if(t.event===`delete`){let t=new Set([e]);for(let n of[...S.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=>S.extract(``,e)))}},async generateBundle(e,t){if(D)return;let n,r=Q.get(this.environment??S)??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),s=o.includes(x);if(!s&&!o.includes(`;teacss=v1-`))continue;s&&(n??=K??await Ne(this.environment?.config?.build?.cssMinify));let l=new Set,d=async e=>(await ce(o.replaceAll(he,n??``).replaceAll(ge,n??``),t=>{let n=r.get(t.digest);n||(n=this.emitFile({type:`asset`,name:oe(t),source:t.bytes}),r.set(t.digest,n));let i=this.getFileName(n);l.add(i);let a=T?.base??`/`;return a===`./`||a===``?`./${u.relative(u.dirname(e),i)}`:`${a}${i}`})).toString(),f=await d(a.fileName);for(let e of Object.values(t))if(e.type===`chunk`&&e.viteMetadata?.importedCss.has(a.fileName))for(let t of l)e.viteMetadata.importedAssets.add(t);let p=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:f});p=r.includes(`[hash`)||r!==n}if(!T||!(`environments`in T)||!p){a.source=f;continue}let m=e=>this.getFileName(this.emitFile({type:`asset`,name:a.name||c(a.fileName),...a.originalFileName?{originalFileName:a.originalFileName}:{},source:e})),h=m(f),g=await d(h);if(g!==f){let e=$.get(this.environment??S)??new Set;if(e.add(h),$.set(this.environment??S,e),f=g,h=m(f),await d(h)!==f)throw Error(`TeaCSS CSS output naming changes its font-relative directory after URL resolution`)}let _=new Set,v=T.build.manifest,y=T.build.ssrManifest;v&&_.add(typeof v==`string`?v:`.vite/manifest.json`),y&&_.add(typeof y==`string`?y:`.vite/ssr-manifest.json`);for(let e of Object.values(t))e.viteMetadata?.importedCss.delete(a.fileName)&&e.viteMetadata.importedCss.add(h),e.type===`chunk`?e.code=ve(e.code,a.fileName,h):e!==a&&typeof e.source==`string`&&_.has(e.fileName)&&(e.source=_e(e.source,a.fileName,h));delete t[i]}}},Je={name:`teacss:api`,enforce:`post`,api:{getContext:()=>S,getMode:()=>`global`},transform(e,t){return!D||t!==w||!e.includes(`import.meta.hot`)?null:`${e}\nimport.meta.hot.send(${JSON.stringify(E)});`},augmentChunkHash(){return q},generateBundle:{order:`post`,async handler(e,t){let n=qe.generateBundle;typeof n==`function`&&await n.call(this,e,t,!1);let r=$.get(this.environment??S);for(let e of r??[])delete t[e];r?.clear()}}};function Ye(e){return{name:e?`teacss:easing-source`:`teacss:easing-output`,enforce:e,transform(t,n){let r=T;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 le(t);return te(i),i.hasChanged()?{code:i.toString(),map:i.generateMap({hires:!0,includeContent:!0,source:n})}:null}}}return[qe,Je,Ye(`pre`),Ye()]}export{M as createTeacssPlugins};
|
package/dist/index.d.ts
ADDED
|
@@ -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`),configEnvironment:a(0,`configEnvironment`),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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.10.2",
|
|
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.2",
|
|
28
|
+
"@teacss/core": "0.10.2",
|
|
29
|
+
"@teacss/directives": "0.10.2",
|
|
30
|
+
"@teacss/runtime": "0.10.2",
|
|
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
|
+
}
|