You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@ttou/postcss-px-to-viewport

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ttou/postcss-px-to-viewport - npm Package Compare versions

Comparing version

to
1.1.6

out/index.mjs

@@ -8,2 +8,14 @@ # Changelog

## [1.1.6] - 2022-01-19
### Changed
- use rollup build source
## [1.1.5] - 2021-10-28
### Changed
- rewrite with typescript
## [1.1.4] - 2021-04-20

@@ -10,0 +22,0 @@

2

out/index.d.ts
import type { Plugin } from 'postcss';
import type { Options } from './types';
declare const _default: (options?: Options) => Plugin;
export = _default;
export default _default;

@@ -1,5 +0,129 @@

"use strict";
const postcss_1 = require("postcss");
const pixel_unit_regexp_1 = require("./pixel-unit-regexp");
const prop_list_matcher_1 = require("./prop-list-matcher");
'use strict';
var postcss = require('postcss');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var postcss__default = /*#__PURE__*/_interopDefaultLegacy(postcss);
// excluding regex trick: http://www.rexegg.com/regex-best-trick.html
// Not anything inside double quotes
// Not anything inside single quotes
// Not anything inside url()
// Any digit followed by px
// !singlequotes|!doublequotes|!url()|pixelunit
function getUnitRegexp(unit) {
return new RegExp('"[^"]+"|\'[^\']+\'|url\\([^\\)]+\\)|(\\d*\\.?\\d+)' + unit, 'g');
}
const filterPropList = {
exact: function (list) {
return list.filter(function (m) {
return m.match(/^[^\*\!]+$/);
});
},
contain: function (list) {
return list
.filter(function (m) {
return m.match(/^\*.+\*$/);
})
.map(function (m) {
return m.substr(1, m.length - 2);
});
},
endWith: function (list) {
return list
.filter(function (m) {
return m.match(/^\*[^\*]+$/);
})
.map(function (m) {
return m.substr(1);
});
},
startWith: function (list) {
return list
.filter(function (m) {
return m.match(/^[^\*\!]+\*$/);
})
.map(function (m) {
return m.substr(0, m.length - 1);
});
},
notExact: function (list) {
return list
.filter(function (m) {
return m.match(/^\![^\*].*$/);
})
.map(function (m) {
return m.substr(1);
});
},
notContain: function (list) {
return list
.filter(function (m) {
return m.match(/^\!\*.+\*$/);
})
.map(function (m) {
return m.substr(2, m.length - 3);
});
},
notEndWith: function (list) {
return list
.filter(function (m) {
return m.match(/^\!\*[^\*]+$/);
})
.map(function (m) {
return m.substr(2);
});
},
notStartWith: function (list) {
return list
.filter(function (m) {
return m.match(/^\![^\*]+\*$/);
})
.map(function (m) {
return m.substr(1, m.length - 2);
});
}
};
function createPropListMatcher(propList) {
const hasWild = propList.indexOf('*') > -1;
const matchAll = hasWild && propList.length === 1;
const lists = {
exact: filterPropList.exact(propList),
contain: filterPropList.contain(propList),
startWith: filterPropList.startWith(propList),
endWith: filterPropList.endWith(propList),
notExact: filterPropList.notExact(propList),
notContain: filterPropList.notContain(propList),
notStartWith: filterPropList.notStartWith(propList),
notEndWith: filterPropList.notEndWith(propList)
};
return function (prop) {
if (matchAll)
return true;
return ((hasWild ||
lists.exact.indexOf(prop) > -1 ||
lists.contain.some(function (m) {
return prop.indexOf(m) > -1;
}) ||
lists.startWith.some(function (m) {
return prop.indexOf(m) === 0;
}) ||
lists.endWith.some(function (m) {
return prop.indexOf(m) === prop.length - m.length;
})) &&
!(lists.notExact.indexOf(prop) > -1 ||
lists.notContain.some(function (m) {
return prop.indexOf(m) > -1;
}) ||
lists.notStartWith.some(function (m) {
return prop.indexOf(m) === 0;
}) ||
lists.notEndWith.some(function (m) {
return prop.indexOf(m) === prop.length - m.length;
})));
};
}
const defaults = {

@@ -23,63 +147,8 @@ unitToConvert: 'px',

const ignorePrevComment = 'px-to-viewport-ignore';
function getUnit(prop, opts) {
return prop.indexOf('font') === -1 ? opts.viewportUnit : opts.fontViewportUnit;
}
function createPxReplace(opts, viewportUnit, viewportSize) {
return function (m, $1) {
if (!$1)
return m;
const pixels = parseFloat($1);
if (pixels <= opts.minPixelValue)
return m;
const parsedVal = toFixed((pixels / viewportSize) * 100, opts.unitPrecision);
return parsedVal === 0 ? '0' : parsedVal + viewportUnit;
};
}
function checkRegExpOrArray(options, optionName) {
const option = options[optionName];
if (!option)
return;
if (Object.prototype.toString.call(option) === '[object RegExp]')
return;
if (Object.prototype.toString.call(option) === '[object Array]') {
let bad = false;
for (let i = 0; i < option.length; i++) {
if (Object.prototype.toString.call(option[i]) !== '[object RegExp]') {
bad = true;
break;
}
}
if (!bad)
return;
}
throw new Error('options.' + optionName + ' should be RegExp or Array of RegExp.');
}
function toFixed(number, precision) {
const multiplier = Math.pow(10, precision + 1);
const wholeNumber = Math.floor(number * multiplier);
return (Math.round(wholeNumber / 10) * 10) / multiplier;
}
function blacklistedSelector(blacklist, selector) {
if (typeof selector !== 'string')
return;
return blacklist.some(function (regex) {
if (typeof regex === 'string')
return selector.indexOf(regex) !== -1;
return selector.match(regex);
});
}
function declarationExists(decls, prop, value) {
return decls.some(function (decl) {
return decl.prop === prop && decl.value === value;
});
}
function validateParams(params, mediaQuery) {
return !params || (params && mediaQuery);
}
module.exports = (options = {}) => {
var index = (options = {}) => {
const opts = Object.assign({}, defaults, options);
checkRegExpOrArray(opts, 'exclude');
checkRegExpOrArray(opts, 'include');
const pxRegex = (0, pixel_unit_regexp_1.getUnitRegexp)(opts.unitToConvert);
const satisfyPropList = (0, prop_list_matcher_1.createPropListMatcher)(opts.propList);
const pxRegex = getUnitRegexp(opts.unitToConvert);
const satisfyPropList = createPropListMatcher(opts.propList);
const landscapeRules = [];

@@ -194,3 +263,3 @@ return {

if (landscapeRules.length > 0) {
const landscapeRoot = postcss_1.default.atRule({
const landscapeRoot = postcss__default["default"].atRule({
params: '(orientation: landscape)',

@@ -207,1 +276,58 @@ name: 'media'

};
function getUnit(prop, opts) {
return prop.indexOf('font') === -1 ? opts.viewportUnit : opts.fontViewportUnit;
}
function createPxReplace(opts, viewportUnit, viewportSize) {
return function (m, $1) {
if (!$1)
return m;
const pixels = parseFloat($1);
if (pixels <= opts.minPixelValue)
return m;
const parsedVal = toFixed((pixels / viewportSize) * 100, opts.unitPrecision);
return parsedVal === 0 ? '0' : parsedVal + viewportUnit;
};
}
function checkRegExpOrArray(options, optionName) {
const option = options[optionName];
if (!option)
return;
if (Object.prototype.toString.call(option) === '[object RegExp]')
return;
if (Object.prototype.toString.call(option) === '[object Array]') {
let bad = false;
for (let i = 0; i < option.length; i++) {
if (Object.prototype.toString.call(option[i]) !== '[object RegExp]') {
bad = true;
break;
}
}
if (!bad)
return;
}
throw new Error('options.' + optionName + ' should be RegExp or Array of RegExp.');
}
function toFixed(number, precision) {
const multiplier = Math.pow(10, precision + 1);
const wholeNumber = Math.floor(number * multiplier);
return (Math.round(wholeNumber / 10) * 10) / multiplier;
}
function blacklistedSelector(blacklist, selector) {
if (typeof selector !== 'string')
return;
return blacklist.some(function (regex) {
if (typeof regex === 'string')
return selector.indexOf(regex) !== -1;
return selector.match(regex);
});
}
function declarationExists(decls, prop, value) {
return decls.some(function (decl) {
return decl.prop === prop && decl.value === value;
});
}
function validateParams(params, mediaQuery) {
return !params || (params && mediaQuery);
}
module.exports = index;

@@ -1,5 +0,6 @@

"use strict";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
// excluding regex trick: http://www.rexegg.com/regex-best-trick.html
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUnitRegexp = void 0;
// Not anything inside double quotes

@@ -13,2 +14,3 @@ // Not anything inside single quotes

}
exports.getUnitRegexp = getUnitRegexp;

@@ -1,5 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPropListMatcher = exports.filterPropList = void 0;
exports.filterPropList = {
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const filterPropList = {
exact: function (list) {

@@ -78,10 +79,10 @@ return list.filter(function (m) {

const lists = {
exact: exports.filterPropList.exact(propList),
contain: exports.filterPropList.contain(propList),
startWith: exports.filterPropList.startWith(propList),
endWith: exports.filterPropList.endWith(propList),
notExact: exports.filterPropList.notExact(propList),
notContain: exports.filterPropList.notContain(propList),
notStartWith: exports.filterPropList.notStartWith(propList),
notEndWith: exports.filterPropList.notEndWith(propList)
exact: filterPropList.exact(propList),
contain: filterPropList.contain(propList),
startWith: filterPropList.startWith(propList),
endWith: filterPropList.endWith(propList),
notExact: filterPropList.notExact(propList),
notContain: filterPropList.notContain(propList),
notStartWith: filterPropList.notStartWith(propList),
notEndWith: filterPropList.notEndWith(propList)
};

@@ -114,2 +115,4 @@ return function (prop) {

}
exports.createPropListMatcher = createPropListMatcher;
exports.filterPropList = filterPropList;
{
"name": "@ttou/postcss-px-to-viewport",
"description": "A CSS post-processor that converts px to viewport units (vw, vh, vmin, vmax).",
"version": "1.1.5",
"version": "1.1.6",
"author": "Dmitry Karpunin <koderfunk@gmail.com>",

@@ -13,3 +13,12 @@ "license": "MIT",

"homepage": "https://gitee.com/jh_shot/postcss-px-to-viewport",
"exports": {
".": {
"require": "./out/index.js",
"import": "./out/index.mjs",
"types": "./out/index.d.ts"
}
},
"main": "out/index.js",
"module": "out/index.mjs",
"types": "out/index.d.ts",
"keywords": [

@@ -32,3 +41,5 @@ "css",

"scripts": {
"build": "tsc",
"build": "run-p build:*",
"build:src": "rollup -c",
"build:dts": "tsc",
"test": "jest",

@@ -42,25 +53,27 @@ "prebuild": "rimraf out",

"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@commitlint/cli": "^16.0.0",
"@commitlint/config-conventional": "^16.0.0",
"@rollup/plugin-typescript": "^8.3.0",
"@ttou/define-config": "^1.0.1",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"commitizen": "^4.2.3",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^10.0.0",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"husky": "^7.0.0",
"jest": "^27.3.1",
"lint-staged": "^10.5.4",
"postcss": ">=8.0.0",
"prettier": "^2.2.1",
"lint-staged": "^11.2.6",
"npm-run-all": "^4.1.5",
"postcss": "^8.0.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"rollup": "^2.64.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4"
"typescript": "^4.5.4"
},

@@ -71,3 +84,3 @@ "peerDependencies": {

"engines": {
"node": ">= 12.0.0"
"node": ">= 14.0.0"
},

@@ -74,0 +87,0 @@ "config": {

@@ -0,6 +1,6 @@

import type { Plugin, Rule } from 'postcss'
import postcss from 'postcss'
import { getUnitRegexp } from './pixel-unit-regexp'
import { createPropListMatcher } from './prop-list-matcher'
import type { Plugin, Rule } from 'postcss'
import type { Options } from './types'

@@ -28,3 +28,3 @@

export = (options: Options = {} as Options) => {
export default (options: Options = {} as Options) => {
const opts = Object.assign({}, defaults, options)

@@ -31,0 +31,0 @@

{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"declaration": true,
"emitDeclarationOnly": true,
"strict": true,

@@ -14,4 +15,5 @@ "baseUrl": ".",

"node_modules",
"spec"
"spec",
"out"
]
}