@empjs/plugin-postcss 3.0.0 → 4.0.0-alpha.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/dist/index.d.ts +4 -6
- package/dist/index.js +1 -1
- package/dist/plugins.d.ts +5 -0
- package/dist/px-to-vw/pixel-unit-regexp.d.ts +1 -0
- package/dist/px-to-vw/prop-list-matcher.d.ts +11 -0
- package/dist/pxtovw.d.ts +1 -2
- package/dist/pxtovw.js +1 -1
- package/package.json +10 -16
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -17
- package/dist/pxtovw.cjs +0 -1
- package/dist/pxtovw.d.cts +0 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { GlobalStore } from '@empjs/cli';
|
|
2
|
-
|
|
3
|
-
type PluginPostcssType = {
|
|
1
|
+
import type { GlobalStore } from '@empjs/cli';
|
|
2
|
+
export type PluginPostcssType = {
|
|
4
3
|
postcssOptions?: any;
|
|
5
4
|
};
|
|
6
5
|
declare const _default: (o?: PluginPostcssType) => {
|
|
7
6
|
name: string;
|
|
8
7
|
rsConfig(store: GlobalStore): Promise<void>;
|
|
9
8
|
};
|
|
10
|
-
|
|
9
|
+
export default _default;
|
|
11
10
|
declare const postcss: {
|
|
12
11
|
autoprefixer(o?: {}): {}[];
|
|
13
12
|
pxtorem(o?: {}): {}[];
|
|
14
13
|
pxtovw(o?: {}): {}[];
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
export { type PluginPostcssType, _default as default, postcss };
|
|
15
|
+
export { postcss };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import e from"node:module";let s=e.createRequire(import.meta.url),o={autoprefixer:(e={})=>[s.resolve("autoprefixer"),e],pxtorem:(e={})=>(e={rootValue:16,unitPrecision:5,propList:["*"],selectorBlackList:[],replace:!0,mediaQuery:!1,minPixelValue:0,...e},[s.resolve("postcss-pxtorem"),e]),pxtovw:(e={})=>(e={unitToConvert:"px",viewportWidth:320,viewportHeight:568,unitPrecision:5,viewportUnit:"vw",fontViewportUnit:"vw",selectorBlackList:[],propList:["*"],minPixelValue:1,mediaQuery:!1,replace:!0,landscape:!1,landscapeUnit:"vw",landscapeWidth:568,...e},[s.resolve("./pxtovw.js"),e])};export default((e={})=>({name:"@empjs/plugin-postcss",async rsConfig(o){let{chain:t}=o,r={};for(let o of(e.postcssOptions&&(r.postcssOptions=e.postcssOptions),["sass","less","css"])){let e=t.module.rule(o).use("postcss").loader(s.resolve("postcss-loader")).options(r);["sass","less"].includes(o)&&e.before(`${o}Loader`)}}}));export{o as postcss};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getUnitRegexp(unit: any): RegExp;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const filterPropList: {
|
|
2
|
+
exact: (list: any[]) => any[];
|
|
3
|
+
contain: (list: any[]) => string[];
|
|
4
|
+
endWith: (list: any[]) => string[];
|
|
5
|
+
startWith: (list: any[]) => string[];
|
|
6
|
+
notExact: (list: any[]) => string[];
|
|
7
|
+
notContain: (list: any[]) => string[];
|
|
8
|
+
notEndWith: (list: any[]) => string[];
|
|
9
|
+
notStartWith: (list: any[]) => string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function createPropListMatcher(propList: any): (prop: any) => boolean;
|
package/dist/pxtovw.d.ts
CHANGED
package/dist/pxtovw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{atRule as
|
|
1
|
+
import"node:module";import{atRule as t}from"postcss";let e={unitToConvert:"px",viewportWidth:320,viewportHeight:568,unitPrecision:5,viewportUnit:"vw",fontViewportUnit:"vw",selectorBlackList:[],propList:["*"],minPixelValue:1,mediaQuery:!1,replace:!0,landscape:!1,landscapeUnit:"vw",landscapeWidth:568};function n(t,e,n){return function(r,i){var o,u;let a;if(!i)return r;let l=Number.parseFloat(i);if(l<=t.minPixelValue)return r;let c=(o=l/n*100,u=t.unitPrecision,10*Math.round(Math.floor(o*(a=10**(u+1)))/10)/a);return 0===c?"0":c+e}}function r(t,e){if("[object RegExp]"!==Object.prototype.toString.call(t))throw Error("options.exclude should be RegExp.");return null!==e.match(t)}export default(i=>{var o;let u,a,l,c=Object.assign({},e,i),p=RegExp("\"[^\"]+\"|'[^']+'|url\\([^\\)]+\\)|(\\d*\\.?\\d+)"+c.unitToConvert,"g"),f=(a=(u=(o=c.propList).indexOf("*")>-1)&&1===o.length,l={exact:o.filter(function(t){return t.match(/^[^*!]+$/)}),contain:o.filter(function(t){return t.match(/^\*.+\*$/)}).map(function(t){return t.substr(1,t.length-2)}),startWith:o.filter(function(t){return t.match(/^[^*!]+\*$/)}).map(function(t){return t.substr(0,t.length-1)}),endWith:o.filter(function(t){return t.match(/^\*[^*]+$/)}).map(function(t){return t.substr(1)}),notExact:o.filter(function(t){return t.match(/^![^*].*$/)}).map(function(t){return t.substr(1)}),notContain:o.filter(function(t){return t.match(/^!\*.+\*$/)}).map(function(t){return t.substr(2,t.length-3)}),notStartWith:o.filter(function(t){return t.match(/^![^*]+\*$/)}).map(function(t){return t.substr(1,t.length-2)}),notEndWith:o.filter(function(t){return t.match(/^!\*[^*]+$/)}).map(function(t){return t.substr(2)})},function(t){return!!a||(u||l.exact.indexOf(t)>-1||l.contain.some(function(e){return t.indexOf(e)>-1})||l.startWith.some(function(e){return 0===t.indexOf(e)})||l.endWith.some(function(e){return t.indexOf(e)===t.length-e.length}))&&!(l.notExact.indexOf(t)>-1||l.notContain.some(function(e){return t.indexOf(e)>-1})||l.notStartWith.some(function(e){return 0===t.indexOf(e)})||l.notEndWith.some(function(e){return t.indexOf(e)===t.length-e.length}))}),s=[];return{postcssPlugin:"postcss-px-to-viewport",Once(e){if(e.walkRules(function(t){let e=t.source&&t.source.input.file;if(c.exclude&&e)if("[object RegExp]"===Object.prototype.toString.call(c.exclude)){if(r(c.exclude,e))return}else if("[object Array]"===Object.prototype.toString.call(c.exclude)){for(let t=0;t<c.exclude.length;t++)if(r(c.exclude[t],e))return}else throw Error("options.exclude should be RegExp or Array.");if(!function(t,e){if("string"==typeof e)return t.some(function(t){return"string"==typeof t?-1!==e.indexOf(t):e.match(t)})}(c.selectorBlackList,t.selector)){var i,o;if(c.landscape&&!t.parent.params){let e=t.clone().removeAll();t.walkDecls(function(t){-1===t.value.indexOf(c.unitToConvert)||f(t.prop)&&e.append(t.clone({value:t.value.replace(p,n(c,c.landscapeUnit,c.landscapeWidth))}))}),e.nodes.length>0&&s.push(e)}i=t.parent.params,o=c.mediaQuery,(!i||i&&o)&&t.walkDecls(function(e,r){var i,o,u,a,l;let s,d;if(-1===e.value.indexOf(c.unitToConvert)||!f(e.prop))return;let h=t.parent.params;c.landscape&&h&&-1!==h.indexOf("landscape")?(s=c.landscapeUnit,d=c.landscapeWidth):(i=e.prop,o=c,s=-1===i.indexOf("font")?o.viewportUnit:o.fontViewportUnit,d=c.viewportWidth);let m=e.value.replace(p,n(c,s,d));u=e.parent,a=e.prop,l=m,u.some(function(t){return t.prop===a&&t.value===l})||(c.replace?e.value=m:e.parent.insertAfter(r,e.clone({value:m})))})}}),s.length>0){let n=t({params:"(orientation: landscape)",name:"media"});s.forEach(function(t){n.append(t)}),e.append(n)}}}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empjs/plugin-postcss",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "emp postcss plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,27 +22,21 @@
|
|
|
22
22
|
"keywords": [
|
|
23
23
|
"postcss"
|
|
24
24
|
],
|
|
25
|
-
"main": "dist/index.js",
|
|
26
|
-
"types": "dist/index.d.ts",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
"require": {
|
|
34
|
-
"default": "./dist/index.cjs",
|
|
35
|
-
"types": "./dist/index.d.cts"
|
|
36
|
-
}
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
37
32
|
}
|
|
38
33
|
},
|
|
39
34
|
"engines": {
|
|
40
|
-
"node": "
|
|
35
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
41
36
|
},
|
|
42
37
|
"author": "Ken",
|
|
43
38
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"@empjs/cli": "3.0.0"
|
|
39
|
+
"@empjs/cli": "4.0.0-alpha.1"
|
|
46
40
|
},
|
|
47
41
|
"dependencies": {
|
|
48
42
|
"postcss": "^8.4.38",
|
|
@@ -51,7 +45,7 @@
|
|
|
51
45
|
"postcss-pxtorem": "^6.1.0"
|
|
52
46
|
},
|
|
53
47
|
"scripts": {
|
|
54
|
-
"build": "
|
|
55
|
-
"dev": "
|
|
48
|
+
"build": "rslib build --env-mode production",
|
|
49
|
+
"dev": "rslib build --watch --env-mode development"
|
|
56
50
|
}
|
|
57
51
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var a=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var g=(e,s)=>{for(var t in s)i(e,t,{get:s[t],enumerable:!0})},l=(e,s,t,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of m(s))!v.call(e,o)&&o!==t&&i(e,o,{get:()=>s[o],enumerable:!(r=f(s,o))||r.enumerable});return e};var n=(e,s,t)=>(t=e!=null?a(d(e)):{},l(s||!e||!e.__esModule?i(t,"default",{value:e,enumerable:!0}):t,e)),x=e=>l(i({},"__esModule",{value:!0}),e);var L={};g(L,{default:()=>y,postcss:()=>w});module.exports=x(L);var c={autoprefixer(e={}){return[require.resolve("autoprefixer"),e]},pxtorem(e={}){return e={rootValue:16,unitPrecision:5,propList:["*"],selectorBlackList:[],replace:!0,mediaQuery:!1,minPixelValue:0,...e},[require.resolve("postcss-pxtorem"),e]},pxtovw(e={}){return e={unitToConvert:"px",viewportWidth:320,viewportHeight:568,unitPrecision:5,viewportUnit:"vw",fontViewportUnit:"vw",selectorBlackList:[],propList:["*"],minPixelValue:1,mediaQuery:!1,replace:!0,landscape:!1,landscapeUnit:"vw",landscapeWidth:568,...e},[require.resolve("./pxtovw.cjs"),e]}};var y=(e={})=>({name:"@empjs/plugin-postcss",async rsConfig(s){let{chain:t}=s,r=["sass","less","css"],o={};e.postcssOptions&&(o.postcssOptions=e.postcssOptions);for(let p of r){let u=t.module.rule(p).use("postcss").loader(require.resolve("postcss-loader")).options(o);["sass","less"].includes(p)&&u.before(`${p}Loader`)}}}),w=c;0&&(module.exports={postcss});
|
package/dist/index.d.cts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { GlobalStore } from '@empjs/cli';
|
|
2
|
-
|
|
3
|
-
type PluginPostcssType = {
|
|
4
|
-
postcssOptions?: any;
|
|
5
|
-
};
|
|
6
|
-
declare const _default: (o?: PluginPostcssType) => {
|
|
7
|
-
name: string;
|
|
8
|
-
rsConfig(store: GlobalStore): Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
declare const postcss: {
|
|
12
|
-
autoprefixer(o?: {}): {}[];
|
|
13
|
-
pxtorem(o?: {}): {}[];
|
|
14
|
-
pxtovw(o?: {}): {}[];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { type PluginPostcssType, _default as default, postcss };
|
package/dist/pxtovw.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var R=(t,n)=>{for(var i in n)h(t,i,{get:n[i],enumerable:!0})},P=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of O(n))!E.call(t,e)&&e!==i&&h(t,e,{get:()=>n[e],enumerable:!(r=W(n,e))||r.enumerable});return t};var U=t=>P(h({},"__esModule",{value:!0}),t);var M={};R(M,{default:()=>S});module.exports=U(M);var w=require("postcss");function x(t){return new RegExp(`"[^"]+"|'[^']+'|url\\([^\\)]+\\)|(\\d*\\.?\\d+)`+t,"g")}var c={exact:function(t){return t.filter(function(n){return n.match(/^[^\*\!]+$/)})},contain:function(t){return t.filter(function(n){return n.match(/^\*.+\*$/)}).map(function(n){return n.substr(1,n.length-2)})},endWith:function(t){return t.filter(function(n){return n.match(/^\*[^\*]+$/)}).map(function(n){return n.substr(1)})},startWith:function(t){return t.filter(function(n){return n.match(/^[^\*\!]+\*$/)}).map(function(n){return n.substr(0,n.length-1)})},notExact:function(t){return t.filter(function(n){return n.match(/^\![^\*].*$/)}).map(function(n){return n.substr(1)})},notContain:function(t){return t.filter(function(n){return n.match(/^\!\*.+\*$/)}).map(function(n){return n.substr(2,n.length-3)})},notEndWith:function(t){return t.filter(function(n){return n.match(/^\!\*[^\*]+$/)}).map(function(n){return n.substr(2)})},notStartWith:function(t){return t.filter(function(n){return n.match(/^\![^\*]+\*$/)}).map(function(n){return n.substr(1,n.length-2)})}};function m(t){let n=t.indexOf("*")>-1,i=n&&t.length===1,r={exact:c.exact(t),contain:c.contain(t),startWith:c.startWith(t),endWith:c.endWith(t),notExact:c.notExact(t),notContain:c.notContain(t),notStartWith:c.notStartWith(t),notEndWith:c.notEndWith(t)};return function(e){return i?!0:(n||r.exact.indexOf(e)>-1||r.contain.some(function(a){return e.indexOf(a)>-1})||r.startWith.some(function(a){return e.indexOf(a)===0})||r.endWith.some(function(a){return e.indexOf(a)===e.length-a.length}))&&!(r.notExact.indexOf(e)>-1||r.notContain.some(function(a){return e.indexOf(a)>-1})||r.notStartWith.some(function(a){return e.indexOf(a)===0})||r.notEndWith.some(function(a){return e.indexOf(a)===e.length-a.length}))}}var C={unitToConvert:"px",viewportWidth:320,viewportHeight:568,unitPrecision:5,viewportUnit:"vw",fontViewportUnit:"vw",selectorBlackList:[],propList:["*"],minPixelValue:1,mediaQuery:!1,replace:!0,landscape:!1,landscapeUnit:"vw",landscapeWidth:568},S=t=>{let n=Object.assign({},C,t),i=x(n.unitToConvert),r=m(n.propList),e=[];return{postcssPlugin:"postcss-px-to-viewport",Once(a){if(a.walkRules(function(u){let f=u.source&&u.source.input.file;if(n.exclude&&f)if(Object.prototype.toString.call(n.exclude)==="[object RegExp]"){if(b(n.exclude,f))return}else if(Object.prototype.toString.call(n.exclude)==="[object Array]"){for(let o=0;o<n.exclude.length;o++)if(b(n.exclude[o],f))return}else throw new Error("options.exclude should be RegExp or Array.");if(!V(n.selectorBlackList,u.selector)){if(n.landscape&&!u.parent.params){let o=u.clone().removeAll();u.walkDecls(function(s){s.value.indexOf(n.unitToConvert)!==-1&&r(s.prop)&&o.append(s.clone({value:s.value.replace(i,v(n,n.landscapeUnit,n.landscapeWidth))}))}),o.nodes.length>0&&e.push(o)}A(u.parent.params,n.mediaQuery)&&u.walkDecls(function(o,s){if(o.value.indexOf(n.unitToConvert)===-1||!r(o.prop))return;let l,p,y=u.parent.params;n.landscape&&y&&y.indexOf("landscape")!==-1?(l=n.landscapeUnit,p=n.landscapeWidth):(l=j(o.prop,n),p=n.viewportWidth);let d=o.value.replace(i,v(n,l,p));$(o.parent,o.prop,d)||(n.replace?o.value=d:o.parent.insertAfter(s,o.clone({value:d})))})}}),e.length>0){let u=(0,w.atRule)({params:"(orientation: landscape)",name:"media"});e.forEach(function(f){u.append(f)}),a.append(u)}}}};function j(t,n){return t.indexOf("font")===-1?n.viewportUnit:n.fontViewportUnit}function v(t,n,i){return function(r,e){if(!e)return r;let a=Number.parseFloat(e);if(a<=t.minPixelValue)return r;let u=k(a/i*100,t.unitPrecision);return u===0?"0":u+n}}function k(t,n){let i=10**(n+1),r=Math.floor(t*i);return Math.round(r/10)*10/i}function V(t,n){if(typeof n=="string")return t.some(function(i){return typeof i=="string"?n.indexOf(i)!==-1:n.match(i)})}function b(t,n){if(Object.prototype.toString.call(t)!=="[object RegExp]")throw new Error("options.exclude should be RegExp.");return n.match(t)!==null}function $(t,n,i){return t.some(function(r){return r.prop===n&&r.value===i})}function A(t,n){return!t||t&&n}
|