source: trip-planner-front/node_modules/postcss-minify-font-values/dist/index.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
10var _minifyWeight = _interopRequireDefault(require("./lib/minify-weight"));
11
12var _minifyFamily = _interopRequireDefault(require("./lib/minify-family"));
13
14var _minifyFont = _interopRequireDefault(require("./lib/minify-font"));
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18function hasVariableFunction(value) {
19 const lowerCasedValue = value.toLowerCase();
20 return lowerCasedValue.includes('var(') || lowerCasedValue.includes('env(');
21}
22
23function transform(prop, value, opts) {
24 let lowerCasedProp = prop.toLowerCase();
25
26 if (lowerCasedProp === 'font-weight' && !hasVariableFunction(value)) {
27 return (0, _minifyWeight.default)(value);
28 } else if (lowerCasedProp === 'font-family' && !hasVariableFunction(value)) {
29 const tree = (0, _postcssValueParser.default)(value);
30 tree.nodes = (0, _minifyFamily.default)(tree.nodes, opts);
31 return tree.toString();
32 } else if (lowerCasedProp === 'font') {
33 const tree = (0, _postcssValueParser.default)(value);
34 tree.nodes = (0, _minifyFont.default)(tree.nodes, opts);
35 return tree.toString();
36 }
37
38 return value;
39}
40
41function pluginCreator(opts) {
42 opts = Object.assign({}, {
43 removeAfterKeyword: false,
44 removeDuplicates: true,
45 removeQuotes: true
46 }, opts);
47 return {
48 postcssPlugin: 'postcss-minify-font-values',
49
50 prepare() {
51 const cache = {};
52 return {
53 OnceExit(css) {
54 css.walkDecls(/font/i, decl => {
55 const value = decl.value;
56
57 if (!value) {
58 return;
59 }
60
61 const prop = decl.prop;
62 const cacheKey = `${prop}|${value}`;
63
64 if (cache[cacheKey]) {
65 decl.value = cache[cacheKey];
66 return;
67 }
68
69 const newValue = transform(prop, value, opts);
70 decl.value = newValue;
71 cache[cacheKey] = newValue;
72 });
73 }
74
75 };
76 }
77
78 };
79}
80
81pluginCreator.postcss = true;
82var _default = pluginCreator;
83exports.default = _default;
84module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.