@empjs/plugin-lightningcss 3.0.0-rc.7 → 3.0.0-rc.9
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 +17 -1
- package/dist/index.js +1 -1
- package/dist/unit-tramsform.d.ts +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,4 +25,20 @@ export default defineConfig(store => {
|
|
|
25
25
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
##
|
|
28
|
+
## 增加变量
|
|
29
|
+
+ excludeSelectors 屏蔽选择器,如`[{type: 'class', name: 'cssModule'}]`
|
|
30
|
+
+ excludeUnit 防止转换`px`的写法,默认为 `ipx`;
|
|
31
|
+
+ (*) 加上横杠会出现不可预知问题 如 marign 1-px solid #222 会多出一个空格
|
|
32
|
+
+ `--px` 会解析成变量来处理,不会做 ignore 操作
|
|
33
|
+
```js
|
|
34
|
+
/**
|
|
35
|
+
* 屏蔽选择器 [{type: 'class', name: 'cssModule'}]
|
|
36
|
+
* @default []
|
|
37
|
+
*/
|
|
38
|
+
excludeSelectors: ExcludeSelectorsType[]
|
|
39
|
+
/**
|
|
40
|
+
* 屏蔽单位 大小写无法区分 只支持 -px 等横杠
|
|
41
|
+
* @default -px
|
|
42
|
+
*/
|
|
43
|
+
excludeUnit: string
|
|
44
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var C=Object.defineProperty;var R=(i,e)=>()=>(i&&(e=i(i=0)),e);var A=(i,e)=>{for(var t in e)C(i,t,{get:e[t],enumerable:!0})};var
|
|
1
|
+
var C=Object.defineProperty;var R=(i,e)=>()=>(i&&(e=i(i=0)),e);var A=(i,e)=>{for(var t in e)C(i,t,{get:e[t],enumerable:!0})};var g={};A(g,{LightningCSSMinifyPlugin:()=>c,default:()=>P});import{Buffer as T}from"node:buffer";import{transform as _}from"lightningcss";var p,E,c,P,x=R(()=>{"use strict";p="lightningcss-minify-plugin",E=/\.css(?:\?.*)?$/i,c=class{options;transform;constructor(e={}){let{implementation:t}=e;if(t&&typeof t.transform!="function")throw new TypeError(`[${p}]: implementation.transform must be an 'lightningcss' transform function. Received ${typeof t.transform}`);this.transform=t?.transform??_,this.options=e}apply(e){e.hooks.compilation.tap(p,t=>{t.hooks.processAssets.tapPromise({name:p,stage:t?.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE},async()=>await this.transformAssets(t)),t.hooks.statsPrinter.tap(p,s=>{s.hooks.print.for("asset.info.minimized").tap(p,(n,{green:r,formatFlag:o})=>n&&r&&o?r(o("minimized")):"")})})}async transformAssets(e){let{options:{devtool:t},webpack:{sources:{SourceMapSource:s,RawSource:n}}}=e.compiler,r=this.options.sourceMap===void 0?t&&t.includes("source-map"):this.options.sourceMap,{targets:o,...m}=this.options,u=e.getAssets().filter(a=>!a.info.minimized&&E.test(a.name));await Promise.all(u.map(async a=>{let{source:l,map:k}=a.source.sourceAndMap(),w=l.toString(),V=typeof l=="string"?T.from(l):l,d=this.transform({filename:a.name,code:V,minify:!0,sourceMap:r,...m}),h=d.code.toString();e.updateAsset(a.name,r?new s(h,a.name,JSON.parse(d.map.toString()),w,k,!0):new n(h),{...a.info,minimized:!0})}))}},P=c});import{composeVisitors as Z}from"lightningcss";import O from"browserslist";import{browserslistToTargets as L}from"lightningcss";var M=async(i,e)=>{if(e?.transform===!1)return;let{importResolve:t,chain:s}=i,n=["sass","less","css"],r=e?.transform||{},m={targets:L(O(i.empConfig.build.browserslist)),...r};for(let u of n){let a=s.module.rule(u),l=a.use("lightningcss").loader(t("./loader.cjs",import.meta.url)).options(m);["sass","less"].includes(u)&&l.before(`${u}Loader`),a.uses.delete("postcss")}},I=async(i,e)=>{if(e?.minify===!1)return;let{chain:t}=i,s=e?.minify||{},{LightningCSSMinifyPlugin:n}=await Promise.resolve().then(()=>(x(),g));t.optimization.minimizer("minCss").use(n,[s])},U=i=>({name:"@empjs/plugin-lightningcss",async rsConfig(e){await Promise.all([M(e,i),I(e,i)])}}),b=U;import{composeVisitors as S}from"lightningcss";var y=class{skipSelector=!1;skipVal=!1;isExclude;isDebug=!1;op={designWidth:320,minPixelValue:1,excludeSelectors:[],transformUnit:"",excludeUnit:"ipx",rootValue:16};debug(...e){this.isDebug&&console.log(...e)}Selector=e=>{this.skipSelector=!1;for(let t of e)this.isExclude(t)&&(this.skipSelector=!0)};Token={dimension:e=>{if(this.debug("dimension",e),e.unit===this.op.excludeUnit)return this.skipVal=!0,{type:"length",value:{unit:"px",value:e.value}}}};Length=e=>{if(this.debug(e,"skipVal",this.skipVal,"skipSelector",this.skipSelector),e.unit==="px"&&!this.skipSelector)if(Math.abs(e.value)>this.op.minPixelValue){if(this.skipVal)return this.skipVal=!1,{unit:"px",value:e.value};switch(this.op.transformUnit){case"rem":return{unit:"rem",value:e.value/this.op.rootValue};case"vw":return{unit:"vw",value:e.value/this.op.designWidth*100}}}else return{unit:"px",value:e.value}};pxToRem(e={}){return this.op.transformUnit="rem",this.op=Object.assign(this.op,e),this.isExclude=this.excludeFilter(this.op.excludeSelectors),{Selector:this.Selector,Token:this.Token,Length:this.Length}}pxToVw(e){return this.op.transformUnit="vw",this.op=Object.assign(this.op,e),this.isExclude=this.excludeFilter(this.op.excludeSelectors),{Selector:this.Selector,Token:this.Token,Length:this.Length}}excludeFilter(e){return s=>{if(this.debug(s,e),!s.name)return!1;for(let n of e)if(s.type===n.type&&(typeof n.name=="string"&&n.name===s.name||typeof n.name=="object"&&n.name.test(s.name)))return!0;return!1}}},f=new y;var v=class{px_to_rem(e){return S([f.pxToRem(e)])}px_to_viewport(e){return S([f.pxToVw(e)])}apply(e){return e=e||new Map,{Rule:{style(t){for(let s of t.value.selectors)if(s.length===1&&s[0].type==="type"&&s[0].name.startsWith("--"))return e.set(s[0].name,t.value.declarations),{type:"ignored",value:null};return t.value.rules=t.value.rules.filter(s=>{if(s.type==="unknown"&&s.value.name==="apply"){for(let n of s.value.prelude)if(n.type==="dashed-ident"&&e.has(n.value)){let r=e.get(n.value),o=t.value.declarations;o.declarations.push(...r.declarations),o.importantDeclarations.push(...r.importantDeclarations)}return!1}return!0}),t}}}}selector_prefix(){return{Selector(e){return[{type:"class",name:"prefix"},{type:"combinator",value:"descendant"},...e]}}}static_vars(e){return e=e||new Map,{Rule:{unknown(t){return e.set(t.name,t.prelude),[]}},Token:{"at-keyword"(t){if(e.has(t.value))return e.get(t.value)}}}}url(e){return{Url(t){return t.url=e+t.url,t}}}specific_environment_variables(e){let t={};for(let s in e)t[s]=()=>e[s];return{EnvironmentVariable:t}}env_function(e){return{EnvironmentVariable(t){if(t.name.type==="custom")return e[t.name.ident]}}}design_tokens(e){return{Function:{"design-token"(t){if(t.arguments.length===1&&t.arguments[0].type==="token"&&t.arguments[0].value.type==="string")return e[t.arguments[0].value.value]}}}}custom_units(){return{Token:{dimension(e){if(e.unit.startsWith("--"))return{type:"function",value:{name:"calc",arguments:[{type:"token",value:{type:"number",value:e.value}},{type:"token",value:{type:"delim",value:"*"}},{type:"var",value:{name:{ident:e.unit}}}]}}}}}}property_lookup(){return{Rule:{style(e){let t=new Map;for(let s of e.value.declarations.declarations){let n=s.property;s.property==="unparsed"&&(n=s.value.propertyId.property),t.set(n,s)}return e.value.declarations.declarations=e.value.declarations.declarations.map(s=>{if(s.property==="unparsed"&&s.value.value.length===1){let n=s.value.value[0];if(n.type==="token"&&n.value.type==="at-keyword"&&t.has(n.value.value)){let r=t.get(n.value.value);return{property:s.value.propertyId.property,value:r.value}}}return s}),e}}}}focus_visible(){return{Rule:{style(e){let t=null;for(let s of e.value.selectors)for(let[n,r]of s.entries())r.type==="pseudo-class"&&r.kind==="focus-visible"&&(t==null&&(t=[...e.value.selectors.map(o=>[...o])]),s[n]={type:"class",name:"focus-visible"});if(t)return[e,{type:"style",value:{...e.value,selectors:t}}]}}}}dark_theme_class(){return{Rule:{media(e){let t=e.value.query.mediaQueries[0];if(t.condition?.type==="feature"&&t.condition.value.type==="plain"&&t.condition.value.name==="prefers-color-scheme"&&t.condition.value.value.value==="dark"){let s=[e];for(let n of e.value.rules)if(n.type==="style"){let r=[];for(let o of n.value.selectors)r.push([{type:"type",name:"html"},{type:"attribute",name:"theme",operation:{operator:"equal",value:"dark"}},{type:"combinator",value:"descendant"},...o]),o.unshift({type:"type",name:"html"},{type:"pseudo-class",kind:"not",selectors:[[{type:"attribute",name:"theme",operation:{operator:"equal",value:"light"}}]]},{type:"combinator",value:"descendant"});s.push({type:"style",value:{...n.value,selectors:r}})}return s}}}}}fix_100vh(){return{Rule:{style(e){let t;for(let s of e.value.declarations.declarations)s.property==="height"&&s.value.type==="length-percentage"&&s.value.value.type==="dimension"&&s.value.value.value.unit==="vh"&&s.value.value.value.value===100&&(t||(t=structuredClone(e),t.value.declarations.declarations=[]),t.value.declarations.declarations.push({...s,value:{type:"stretch",vendorPrefix:["webkit"]}}));if(t)return[e,{type:"supports",value:{condition:{type:"declaration",propertyId:{property:"-webkit-touch-callout"},value:"none"},loc:e.value.loc,rules:[t]}}]}}}}logical_transforms(){return{Rule:{style(e){let t;for(let s of e.value.declarations.declarations)if(s.property==="transform"){let n=s.value.map(r=>{if(r.type!=="translateX")return r;t||(t=structuredClone(e),t.value.declarations.declarations=[]);let o;switch(r.value.type){case"dimension":o={type:"dimension",value:{unit:r.value.value.unit,value:-r.value.value.value}};break;case"percentage":o={type:"percentage",value:-r.value.value};break;case"calc":o={type:"calc",value:{type:"product",value:[-1,r.value.value]}};break}return{type:"translateX",value:o}});t&&(t.value.selectors.at(-1).push({type:"pseudo-class",kind:"dir",direction:"rtl"}),t.value.declarations.declarations.push({...s,value:n}))}if(t)return[e,t]}}}}hover_media_query(){return{Rule:{media(e){let t=e.value.query.mediaQueries;if(t.length===1&&t[0].condition&&t[0].condition.type==="feature"&&t[0].condition.value.type==="boolean"&&t[0].condition.value.name==="hover"){for(let s of e.value.rules)if(s.type==="style")for(let n of s.value.selectors)n.unshift({type:"class",name:"hoverable"},{type:"combinator",value:"descendant"});return e.value.rules}}}}}momentum_scrolling(e){return{Declaration:{overflow:e,"overflow-x":e,"overflow-y":e}}}size(){return{Declaration:{custom:{size(e){if(e.value[0].type==="length"){let t={type:"length-percentage",value:{type:"dimension",value:e.value[0].value}};return[{property:"width",value:t},{property:"height",value:t}]}}}}}}},z=new v;var K=b;export{Z as composeVisitors,K as default,z as postcss};
|
package/dist/unit-tramsform.d.ts
CHANGED
|
@@ -6,8 +6,17 @@ export type ExcludeSelectorsType = {
|
|
|
6
6
|
interface Options {
|
|
7
7
|
designWidth: number;
|
|
8
8
|
minPixelValue: number;
|
|
9
|
+
/**
|
|
10
|
+
* 屏蔽选择器 [{type: 'class', name: 'cssModule'}]
|
|
11
|
+
* @default []
|
|
12
|
+
*/
|
|
9
13
|
excludeSelectors: ExcludeSelectorsType[];
|
|
10
14
|
transformUnit: 'vw' | 'rem' | '';
|
|
15
|
+
/**
|
|
16
|
+
* 屏蔽单位 大小写无法区分 只支持 ipx 等纯字母变量
|
|
17
|
+
* 加上横杠会出现不可预知问题 如 marign 1-px solid #222 会多出一个空格
|
|
18
|
+
* @default ipx
|
|
19
|
+
*/
|
|
11
20
|
excludeUnit: string;
|
|
12
21
|
rootValue: number;
|
|
13
22
|
}
|