@empjs/plugin-lightningcss 3.0.0-rc.0 → 3.0.0-rc.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/README.md CHANGED
@@ -24,3 +24,6 @@ export default defineConfig(store => {
24
24
  })
25
25
 
26
26
  ```
27
+
28
+ ## ChangeLog
29
+ + `v3.0.0-rc.1` 增加 `skipUppercasePx` 支持 默认为 `true`
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var w=Object.defineProperty;var k=(r,e)=>()=>(r&&(e=r(r=0)),e);var P=(r,e)=>{for(var t in e)w(r,t,{get:e[t],enumerable:!0})};var d={};P(d,{LightningCSSMinifyPlugin:()=>c,default:()=>O});import{transform as A}from"lightningcss";import{Buffer as _}from"node:buffer";var p,T,c,O,g=k(()=>{"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,n=>{n.hooks.print.for("asset.info.minimized").tap(p,(o,{green:s,formatFlag:i})=>o&&s&&i?s(i("minimized")):"")})})}async transformAssets(e){let{options:{devtool:t},webpack:{sources:{SourceMapSource:n,RawSource:o}}}=e.compiler,s=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:S}=a.source.sourceAndMap(),C=u.toString(),V=typeof u=="string"?_.from(u):u,y=this.transform({filename:a.name,code:V,minify:!0,sourceMap:s,...m}),v=y.code.toString();e.updateAsset(a.name,s?new n(v,a.name,JSON.parse(y.map.toString()),C,S,!0):new o(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:n}=r,o=["sass","less","css"],s=e?.transform||{},m={targets:E(M(r.empConfig.build.browserslist)),...s};for(let l of o){let a=n.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,n=e?.minify||{},{LightningCSSMinifyPlugin:o}=await Promise.resolve().then(()=>(g(),d));t.optimization.minimizer("minCss").use(o,[n])},j=r=>({name:"@empjs/plugin-lightningcss",async rsConfig(e){await Promise.all([L(e,r),z(e,r)])}}),h=j;var G={designWidth:320,minPixelValue:1,excludeSelectors:[]};function x(r){return t=>{if(!t.name)return!1;for(let n of r)if(t.type===n.type&&(typeof n.name=="string"&&n.name===t.name||typeof n.name=="object"&&n.name.test(t.name)))return!0;return!1}}function b(r={}){let e=Object.assign(G,r),t=x(e.excludeSelectors),n=!1;return{Selector(o){n=!1;for(let s of o)t(s)&&(n=!0)},Length(o){if(o.unit==="px"&&!n&&o.value>e.minPixelValue)return{unit:"vw",value:o.value/e.designWidth*100}}}}function R(r={}){let e=Object.assign({rootValue:16,excludeSelectors:[],minPixelValue:1},r),t=x(e.excludeSelectors),n=!1;return{Selector(o){n=!1;for(let s of o)t(s)&&(n=!0)},Length(o){if(o.unit==="px"&&!n&&o.value>e.minPixelValue)return{unit:"rem",value:o.value/e.rootValue}}}}import{composeVisitors as q}from"lightningcss";var f=class{px_to_rem(e){return R(e)}px_to_viewport(e){return q([b(e)])}apply(e){return e=e||new Map,{Rule:{style(t){for(let n of t.value.selectors)if(n.length===1&&n[0].type==="type"&&n[0].name.startsWith("--"))return e.set(n[0].name,t.value.declarations),{type:"ignored",value:null};return t.value.rules=t.value.rules.filter(n=>{if(n.type==="unknown"&&n.value.name==="apply"){for(let o of n.value.prelude)if(o.type==="dashed-ident"&&e.has(o.value)){let s=e.get(o.value),i=t.value.declarations;i.declarations.push(...s.declarations),i.importantDeclarations.push(...s.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 n in e)t[n]=()=>e[n];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 n of e.value.declarations.declarations){let o=n.property;n.property==="unparsed"&&(o=n.value.propertyId.property),t.set(o,n)}return e.value.declarations.declarations=e.value.declarations.declarations.map(n=>{if(n.property==="unparsed"&&n.value.value.length===1){let o=n.value.value[0];if(o.type==="token"&&o.value.type==="at-keyword"&&t.has(o.value.value)){let s=t.get(o.value.value);return{property:n.value.propertyId.property,value:s.value}}}return n}),e}}}}focus_visible(){return{Rule:{style(e){let t=null;for(let n of e.value.selectors)for(let[o,s]of n.entries())s.type==="pseudo-class"&&s.kind==="focus-visible"&&(t==null&&(t=[...e.value.selectors.map(i=>[...i])]),n[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 n=[e];for(let o of e.value.rules)if(o.type==="style"){let s=[];for(let i of o.value.selectors)s.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"});n.push({type:"style",value:{...o.value,selectors:s}})}return n}}}}}fix_100vh(){return{Rule:{style(e){let t;for(let n of e.value.declarations.declarations)n.property==="height"&&n.value.type==="length-percentage"&&n.value.value.type==="dimension"&&n.value.value.value.unit==="vh"&&n.value.value.value.value===100&&(t||(t=structuredClone(e),t.value.declarations.declarations=[]),t.value.declarations.declarations.push({...n,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 n of e.value.declarations.declarations)if(n.property==="transform"){let o=n.value.map(s=>{if(s.type!=="translateX")return s;t||(t=structuredClone(e),t.value.declarations.declarations=[]);let i;switch(s.value.type){case"dimension":i={type:"dimension",value:{unit:s.value.value.unit,value:-s.value.value.value}};break;case"percentage":i={type:"percentage",value:-s.value.value};break;case"calc":i={type:"calc",value:{type:"product",value:[-1,s.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({...n,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 n of e.value.rules)if(n.type==="style")for(let o of n.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}]}}}}}}},W=new f;import{composeVisitors as ee}from"lightningcss";var te=h;export{ee as composeVisitors,te as default,W as postcss};
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,12 +1,13 @@
1
1
  interface Options {
2
2
  designWidth: number;
3
3
  minPixelValue: number;
4
+ skipUppercasePx: boolean;
4
5
  excludeSelectors: {
5
6
  type: string;
6
7
  name: RegExp | string;
7
8
  }[];
8
9
  }
9
- export declare function createExcludeFilter(excludes: Options['excludeSelectors']): (testItem: {
10
+ export declare function createExcludeFilter(excludes: Options['excludeSelectors'], skipUppercasePx: boolean): (testItem: {
10
11
  type: string;
11
12
  name?: string;
12
13
  }) => boolean;
@@ -21,6 +22,7 @@ export declare function createPxToVwVisitor(userOptions?: vwOptions): {
21
22
  export type PxToRemOptions = {
22
23
  rootValue?: number;
23
24
  minPixelValue?: number;
25
+ skipUppercasePx?: boolean;
24
26
  excludeSelectors?: {
25
27
  type: string;
26
28
  name: RegExp | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empjs/plugin-lightningcss",
3
- "version": "3.0.0-rc.0",
3
+ "version": "3.0.0-rc.1",
4
4
  "description": "emp v3 lightningcss",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",