@empjs/plugin-lightningcss 3.0.0-rc.1 → 3.0.0-rc.11

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 CHANGED
@@ -25,5 +25,20 @@ export default defineConfig(store => {
25
25
 
26
26
  ```
27
27
 
28
- ## ChangeLog
29
- + `v3.0.0-rc.1` 增加 `skipUppercasePx` 支持 默认为 `true`
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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { composeVisitors } from 'lightningcss';
1
2
  import empLightningcssPlugin from './plugin.js';
2
3
  import postcss from './postcss-polyfill.js';
3
- import { composeVisitors } from 'lightningcss';
4
4
  export default empLightningcssPlugin;
5
5
  export { postcss, composeVisitors };
6
+ export type { PxToRemOptions, PxToVwOptions } from './px-to-base.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var C=Object.defineProperty;var V=(r,e)=>()=>(r&&(e=r(r=0)),e);var w=(r,e)=>{for(var t in e)C(r,t,{get:e[t],enumerable:!0})};var d={};w(d,{LightningCSSMinifyPlugin:()=>c,default:()=>O});import{transform as A}from"lightningcss";import{Buffer as _}from"node:buffer";var p,T,c,O,g=V(()=>{"use strict";p="lightningcss-minify-plugin",T=/\.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??A,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:o,formatFlag:i})=>n&&o&&i?o(i("minimized")):"")})})}async transformAssets(e){let{options:{devtool:t},webpack:{sources:{SourceMapSource:s,RawSource:n}}}=e.compiler,o=this.options.sourceMap===void 0?t&&t.includes("source-map"):this.options.sourceMap,{targets:i,...m}=this.options,l=e.getAssets().filter(a=>!a.info.minimized&&T.test(a.name));await Promise.all(l.map(async a=>{let{source:u,map:R}=a.source.sourceAndMap(),S=u.toString(),k=typeof u=="string"?_.from(u):u,y=this.transform({filename:a.name,code:k,minify:!0,sourceMap:o,...m}),v=y.code.toString();e.updateAsset(a.name,o?new s(v,a.name,JSON.parse(y.map.toString()),S,R,!0):new n(v),{...a.info,minimized:!0})}))}},O=c});import{browserslistToTargets as E}from"lightningcss";import M from"browserslist";var L=async(r,e)=>{if(e?.transform===!1)return;let{importResolve:t,chain:s}=r,n=["sass","less","css"],o=e?.transform||{},m={targets:E(M(r.empConfig.build.browserslist)),...o};for(let l of n){let a=s.module.rule(l),u=a.use("lightningcss").loader(t("./loader.cjs",import.meta.url)).options(m);["sass","less"].includes(l)&&u.before(`${l}Loader`),a.uses.delete("postcss")}},z=async(r,e)=>{if(e?.minify===!1)return;let{chain:t}=r,s=e?.minify||{},{LightningCSSMinifyPlugin:n}=await Promise.resolve().then(()=>(g(),d));t.optimization.minimizer("minCss").use(n,[s])},U=r=>({name:"@empjs/plugin-lightningcss",async rsConfig(e){await Promise.all([L(e,r),z(e,r)])}}),h=U;var j={designWidth:320,minPixelValue:1,skipUppercasePx:!0,excludeSelectors:[]};function x(r,e){return s=>{if(!s.name)return!1;if(e&&["Px","PX"].includes(s.name))return!0;for(let n of r)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}}function b(r={}){let e=Object.assign(j,r),t=x(e.excludeSelectors,e.skipUppercasePx),s=!1;return{Selector(n){s=!1;for(let o of n)t(o)&&(s=!0)},Length(n){if(n.unit==="px"&&!s&&n.value>e.minPixelValue)return{unit:"vw",value:n.value/e.designWidth*100}}}}function P(r={}){let e=Object.assign({rootValue:16,excludeSelectors:[],minPixelValue:1,skipUppercasePx:!0},r),t=x(e.excludeSelectors,e.skipUppercasePx),s=!1;return{Selector(n){s=!1;for(let o of n)t(o)&&(s=!0)},Length(n){if(n.unit==="px"&&!s&&n.value>e.minPixelValue)return{unit:"rem",value:n.value/e.rootValue}}}}import{composeVisitors as G}from"lightningcss";var f=class{px_to_rem(e){return P(e)}px_to_viewport(e){return G([b(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 o=e.get(n.value),i=t.value.declarations;i.declarations.push(...o.declarations),i.importantDeclarations.push(...o.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 o=t.get(n.value.value);return{property:s.value.propertyId.property,value:o.value}}}return s}),e}}}}focus_visible(){return{Rule:{style(e){let t=null;for(let s of e.value.selectors)for(let[n,o]of s.entries())o.type==="pseudo-class"&&o.kind==="focus-visible"&&(t==null&&(t=[...e.value.selectors.map(i=>[...i])]),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 o=[];for(let i of n.value.selectors)o.push([{type:"type",name:"html"},{type:"attribute",name:"theme",operation:{operator:"equal",value:"dark"}},{type:"combinator",value:"descendant"},...i]),i.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:o}})}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(o=>{if(o.type!=="translateX")return o;t||(t=structuredClone(e),t.value.declarations.declarations=[]);let i;switch(o.value.type){case"dimension":i={type:"dimension",value:{unit:o.value.value.unit,value:-o.value.value.value}};break;case"percentage":i={type:"percentage",value:-o.value.value};break;case"calc":i={type:"calc",value:{type:"product",value:[-1,o.value.value]}};break}return{type:"translateX",value:i}});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}]}}}}}}},q=new f;import{composeVisitors as ee}from"lightningcss";var te=h;export{ee as composeVisitors,te as default,q as postcss};
1
+ var R=Object.defineProperty;var C=(i,e)=>()=>(i&&(e=i(i=0)),e);var T=(i,e)=>{for(var t in e)R(i,t,{get:e[t],enumerable:!0})};var g={};T(g,{LightningCSSMinifyPlugin:()=>c,default:()=>E});import{Buffer as A}from"node:buffer";import{transform as _}from"lightningcss";var p,P,c,E,x=C(()=>{"use strict";p="lightningcss-minify-plugin",P=/\.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,(o,{green:n,formatFlag:r})=>o&&n&&r?n(r("minimized")):"")})})}async transformAssets(e){let{options:{devtool:t},webpack:{sources:{SourceMapSource:s,RawSource:o}}}=e.compiler,n=this.options.sourceMap===void 0?t&&t.includes("source-map"):this.options.sourceMap,{targets:r,...m}=this.options,u=e.getAssets().filter(a=>!a.info.minimized&&P.test(a.name));await Promise.all(u.map(async a=>{let{source:l,map:S}=a.source.sourceAndMap(),w=l.toString(),V=typeof l=="string"?A.from(l):l,d=this.transform({filename:a.name,code:V,minify:!0,sourceMap:n,...m}),h=d.code.toString();e.updateAsset(a.name,n?new s(h,a.name,JSON.parse(d.map.toString()),w,S,!0):new o(h),{...a.info,minimized:!0})}))}},E=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,o=["sass","less","css"],n=e?.transform||{},m={targets:L(O(i.empConfig.build.browserslist)),...n};for(let u of o){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:o}=await Promise.resolve().then(()=>(x(),g));t.optimization.minimizer("minCss").use(o,[s])},U=i=>({name:"@empjs/plugin-lightningcss",async rsConfig(e){await Promise.all([M(e,i),I(e,i)])}}),b=U;import{composeVisitors as k}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),this.skipVal=!1,e.unit===this.op.excludeUnit)return this.skipVal=!0,{type:"length",value:{unit:"px",value:e.value}}}};Length=e=>{this.debug(e,"skipVal",this.skipVal,"skipSelector",this.skipSelector);let t={unit:"px",value:e.value};if(e.unit==="px"&&!this.skipSelector){if(Math.abs(e.value)>this.op.minPixelValue&&!this.skipVal)switch(this.op.transformUnit){case"rem":t={unit:"rem",value:e.value/this.op.rootValue};break;case"vw":t={unit:"vw",value:e.value/this.op.designWidth*100};break;default:break}return this.skipVal=!1,t}else this.skipVal=!1};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 o of e)if(s.type===o.type&&(typeof o.name=="string"&&o.name===s.name||typeof o.name=="object"&&o.name.test(s.name)))return!0;return!1}}},f=new y;var v=class{px_to_rem(e){return k([f.pxToRem(e)])}pxtorem=this.px_to_rem;pxtovw=this.px_to_viewport;px_to_viewport(e){return k([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 o of s.value.prelude)if(o.type==="dashed-ident"&&e.has(o.value)){let n=e.get(o.value),r=t.value.declarations;r.declarations.push(...n.declarations),r.importantDeclarations.push(...n.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 o=s.property;s.property==="unparsed"&&(o=s.value.propertyId.property),t.set(o,s)}return e.value.declarations.declarations=e.value.declarations.declarations.map(s=>{if(s.property==="unparsed"&&s.value.value.length===1){let o=s.value.value[0];if(o.type==="token"&&o.value.type==="at-keyword"&&t.has(o.value.value)){let n=t.get(o.value.value);return{property:s.value.propertyId.property,value:n.value}}}return s}),e}}}}focus_visible(){return{Rule:{style(e){let t=null;for(let s of e.value.selectors)for(let[o,n]of s.entries())n.type==="pseudo-class"&&n.kind==="focus-visible"&&(t==null&&(t=[...e.value.selectors.map(r=>[...r])]),s[o]={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 o of e.value.rules)if(o.type==="style"){let n=[];for(let r of o.value.selectors)n.push([{type:"type",name:"html"},{type:"attribute",name:"theme",operation:{operator:"equal",value:"dark"}},{type:"combinator",value:"descendant"},...r]),r.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:{...o.value,selectors:n}})}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 o=s.value.map(n=>{if(n.type!=="translateX")return n;t||(t=structuredClone(e),t.value.declarations.declarations=[]);let r;switch(n.value.type){case"dimension":r={type:"dimension",value:{unit:n.value.value.unit,value:-n.value.value.value}};break;case"percentage":r={type:"percentage",value:-n.value.value};break;case"calc":r={type:"calc",value:{type:"product",value:[-1,n.value.value]}};break}return{type:"translateX",value:r}});t&&(t.value.selectors.at(-1).push({type:"pseudo-class",kind:"dir",direction:"rtl"}),t.value.declarations.declarations.push({...s,value:o}))}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 o of s.value.selectors)o.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/loader.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var l=(n,t)=>{for(var r in t)m(n,r,{get:t[r],enumerable:!0})},h=(n,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!S.call(n,o)&&o!==r&&m(n,o,{get:()=>t[o],enumerable:!(e=d(t,o))||e.enumerable});return n};var L=n=>h(m({},"__esModule",{value:!0}),n);var v={};l(v,{default:()=>R});module.exports=L(v);var s=require("lightningcss"),c=require("node:buffer"),O="lightningcss-loader";async function C(n,t){let r=this.async(),e=this.getOptions(),{implementation:o,targets:f,...i}=e;if(o&&typeof o.transform!="function"){r(new TypeError(`[${O}]: options.implementation.transform must be an 'lightningcss' transform function. Received ${typeof o.transform}`));return}let u=o?.transform??s.transform;i.visitor&&(i.visitor=(0,s.composeVisitors)([i.visitor]));try{let{code:a,map:p}=u({filename:this.resourcePath,code:c.Buffer.from(n),sourceMap:this.sourceMap,targets:f,inputSourceMap:this.sourceMap&&t?JSON.stringify(t):void 0,errorRecovery:typeof e.errorRecovery<"u"?e.errorRecovery:!0,nonStandard:{deepSelectorCombinator:!0},...i}),g=a.toString();r(null,g,p&&JSON.parse(p.toString()))}catch(a){r(a)}}var R=C;
1
+ "use strict";var m=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var l=(n,t)=>{for(var r in t)m(n,r,{get:t[r],enumerable:!0})},h=(n,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!S.call(n,o)&&o!==r&&m(n,o,{get:()=>t[o],enumerable:!(e=d(t,o))||e.enumerable});return n};var L=n=>h(m({},"__esModule",{value:!0}),n);var v={};l(v,{default:()=>R});module.exports=L(v);var c=require("node:buffer"),s=require("lightningcss"),O="lightningcss-loader";async function C(n,t){let r=this.async(),e=this.getOptions(),{implementation:o,targets:f,...i}=e;if(o&&typeof o.transform!="function"){r(new TypeError(`[${O}]: options.implementation.transform must be an 'lightningcss' transform function. Received ${typeof o.transform}`));return}let u=o?.transform??s.transform;i.visitor&&(i.visitor=(0,s.composeVisitors)([i.visitor]));try{let{code:a,map:p}=u({filename:this.resourcePath,code:c.Buffer.from(n),sourceMap:this.sourceMap,targets:f,inputSourceMap:this.sourceMap&&t?JSON.stringify(t):void 0,errorRecovery:typeof e.errorRecovery<"u"?e.errorRecovery:!0,nonStandard:{deepSelectorCombinator:!0},...i}),g=a.toString();r(null,g,p&&JSON.parse(p.toString()))}catch(a){r(a)}}var R=C;
@@ -1,6 +1,6 @@
1
1
  import type { Visitor } from 'lightningcss';
2
- import type { vwOptions, PxToRemOptions } from './px-to-base.js';
3
- import { CustomAtRules } from 'lightningcss';
2
+ import { type CustomAtRules } from 'lightningcss';
3
+ import { type remOptions, type vwOptions } from './unit-tramsform.js';
4
4
  /**
5
5
  * // 插件编写 https://github.com/parcel-bundler/lightningcss/blob/master/node/test/visitor.test.mjs
6
6
  */
@@ -8,13 +8,9 @@ declare class PostcssConfig {
8
8
  /**
9
9
  * https://github.com/cuth/postcss-pxtorem
10
10
  */
11
- px_to_rem(op: PxToRemOptions): {
12
- Selector(selectors: import("lightningcss").Selector): void;
13
- Length(length: import("lightningcss").LengthValue): {
14
- unit: "rem";
15
- value: number;
16
- } | undefined;
17
- };
11
+ px_to_rem(op: remOptions): Visitor<CustomAtRules>;
12
+ pxtorem: (op: remOptions) => Visitor<CustomAtRules>;
13
+ pxtovw: (op: vwOptions) => Visitor<CustomAtRules>;
18
14
  /**
19
15
  * https://github.com/evrone/postcss-px-to-viewport
20
16
  */
@@ -1,18 +1,17 @@
1
1
  interface Options {
2
2
  designWidth: number;
3
3
  minPixelValue: number;
4
- skipUppercasePx: boolean;
5
4
  excludeSelectors: {
6
5
  type: string;
7
6
  name: RegExp | string;
8
7
  }[];
9
8
  }
10
- export declare function createExcludeFilter(excludes: Options['excludeSelectors'], skipUppercasePx: boolean): (testItem: {
9
+ export declare function createExcludeFilter(excludes: Options['excludeSelectors']): (testItem: {
11
10
  type: string;
12
11
  name?: string;
13
12
  }) => boolean;
14
- export type vwOptions = Partial<Options>;
15
- export declare function createPxToVwVisitor(userOptions?: vwOptions): {
13
+ export type PxToVwOptions = Partial<Options>;
14
+ export declare function createPxToVwVisitor(userOptions?: PxToVwOptions): {
16
15
  Selector(selectors: import("lightningcss").Selector): void;
17
16
  Length(length: import("lightningcss").LengthValue): {
18
17
  unit: "vw";
@@ -22,17 +21,33 @@ export declare function createPxToVwVisitor(userOptions?: vwOptions): {
22
21
  export type PxToRemOptions = {
23
22
  rootValue?: number;
24
23
  minPixelValue?: number;
25
- skipUppercasePx?: boolean;
26
24
  excludeSelectors?: {
27
25
  type: string;
28
26
  name: RegExp | string;
29
27
  }[];
28
+ excludeUnit?: string;
30
29
  };
31
30
  export declare function createPxToRemVisitor(options?: PxToRemOptions): {
32
31
  Selector(selectors: import("lightningcss").Selector): void;
32
+ Token: {
33
+ dimension(token: {
34
+ type: "dimension";
35
+ unit: string;
36
+ value: number;
37
+ }): {
38
+ type: "length";
39
+ value: {
40
+ unit: "px";
41
+ value: number;
42
+ };
43
+ } | undefined;
44
+ };
33
45
  Length(length: import("lightningcss").LengthValue): {
34
46
  unit: "rem";
35
47
  value: number;
48
+ } | {
49
+ unit: "px";
50
+ value: number;
36
51
  } | undefined;
37
52
  };
38
53
  export {};
@@ -0,0 +1,52 @@
1
+ import type { CustomAtRules, LengthValue, Selector, Visitor } from 'lightningcss';
2
+ export type ExcludeSelectorsType = {
3
+ type: string;
4
+ name: RegExp | string;
5
+ };
6
+ interface Options {
7
+ designWidth: number;
8
+ minPixelValue: number;
9
+ /**
10
+ * 屏蔽选择器 [{type: 'class', name: 'cssModule'}]
11
+ * @default []
12
+ */
13
+ excludeSelectors: ExcludeSelectorsType[];
14
+ transformUnit: 'vw' | 'rem' | '';
15
+ /**
16
+ * 屏蔽单位 大小写无法区分 只支持 ipx 等纯字母变量
17
+ * 加上横杠会出现不可预知问题 如 marign 1-px solid #222 会多出一个空格
18
+ * @default ipx
19
+ */
20
+ excludeUnit: string;
21
+ rootValue: number;
22
+ }
23
+ export type vwOptions = Partial<Options>;
24
+ export type remOptions = Partial<Options>;
25
+ export type ExcludeItemType = {
26
+ type: string;
27
+ name?: string;
28
+ };
29
+ export declare class UnitTramsform {
30
+ private skipSelector;
31
+ private skipVal;
32
+ private isExclude;
33
+ private isDebug;
34
+ op: Options;
35
+ debug(...args: any[]): void;
36
+ Selector: (selectors: Selector) => void;
37
+ Token: any;
38
+ Length: Visitor<CustomAtRules>['Length'];
39
+ pxToRem(options?: remOptions): {
40
+ Selector: (selectors: Selector) => void;
41
+ Token: any;
42
+ Length: ((length: LengthValue) => void | LengthValue) | undefined;
43
+ };
44
+ pxToVw(options: vwOptions): {
45
+ Selector: (selectors: Selector) => void;
46
+ Token: any;
47
+ Length: ((length: LengthValue) => void | LengthValue) | undefined;
48
+ };
49
+ excludeFilter(excludes: ExcludeSelectorsType[]): (item: ExcludeItemType) => boolean;
50
+ }
51
+ declare const _default: UnitTramsform;
52
+ export default _default;
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "@empjs/plugin-lightningcss",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.11",
4
4
  "description": "emp v3 lightningcss",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "type": "module",
8
- "files": [
9
- "dist"
10
- ],
11
- "maintainers": [
12
- "xuhongbin",
13
- "ckken"
14
- ],
8
+ "files": ["dist"],
9
+ "maintainers": ["xuhongbin", "ckken"],
15
10
  "repository": {
16
11
  "type": "git",
17
12
  "url": "git+https://github.com/empjs/emp.git",
@@ -41,10 +36,10 @@
41
36
  },
42
37
  "devDependencies": {
43
38
  "@empjs/cli": "workspace:*",
44
- "@rspack/core": "0.5.8",
39
+ "@rspack/core": "0.6.5",
45
40
  "cross-env": "^7.0.3",
46
41
  "esbuild": "^0.19.5",
47
42
  "rimraf": "^5.0.5",
48
43
  "tsc-alias": "^1.8.8"
49
44
  }
50
- }
45
+ }