aboutsummaryrefslogtreecommitdiff
path: root/node_modules/postcss-minify-font-values/lib
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/postcss-minify-font-values/lib
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/postcss-minify-font-values/lib')
-rw-r--r--node_modules/postcss-minify-font-values/lib/keywords.js44
-rw-r--r--node_modules/postcss-minify-font-values/lib/minify-family.js101
-rw-r--r--node_modules/postcss-minify-font-values/lib/minify-font.js50
-rw-r--r--node_modules/postcss-minify-font-values/lib/minify-weight.js3
-rw-r--r--node_modules/postcss-minify-font-values/lib/uniqs.js11
5 files changed, 209 insertions, 0 deletions
diff --git a/node_modules/postcss-minify-font-values/lib/keywords.js b/node_modules/postcss-minify-font-values/lib/keywords.js
new file mode 100644
index 00000000..db321726
--- /dev/null
+++ b/node_modules/postcss-minify-font-values/lib/keywords.js
@@ -0,0 +1,44 @@
+var keywords = module.exports = {
+ style: [
+ 'italic',
+ 'oblique'
+ ],
+ variant: [
+ 'small-caps'
+ ],
+ weight: [
+ '100',
+ '200',
+ '300',
+ '400',
+ '500',
+ '600',
+ '700',
+ '800',
+ '900',
+ 'bold',
+ 'lighter',
+ 'bolder'
+ ],
+ stretch: [
+ 'ultra-condensed',
+ 'extra-condensed',
+ 'condensed',
+ 'semi-condensed',
+ 'semi-expanded',
+ 'expanded',
+ 'extra-expanded',
+ 'ultra-expanded'
+ ],
+ size: [
+ 'xx-small',
+ 'x-small',
+ 'small',
+ 'medium',
+ 'large',
+ 'x-large',
+ 'xx-large',
+ 'larger',
+ 'smaller'
+ ]
+};
diff --git a/node_modules/postcss-minify-font-values/lib/minify-family.js b/node_modules/postcss-minify-font-values/lib/minify-family.js
new file mode 100644
index 00000000..3ad601f5
--- /dev/null
+++ b/node_modules/postcss-minify-font-values/lib/minify-family.js
@@ -0,0 +1,101 @@
+var stringify = require('postcss-value-parser').stringify;
+var uniqs = require('./uniqs')('monospace');
+
+// Note that monospace is missing intentionally from this list; we should not
+// remove instances of duplicated monospace keywords, it causes the font to be
+// rendered smaller in Chrome.
+
+var keywords = [
+ 'sans-serif',
+ 'serif',
+ 'fantasy',
+ 'cursive'
+];
+
+function intersection(haystack, array) {
+ return array.some(function (v) {
+ return ~haystack.indexOf(v);
+ });
+};
+
+module.exports = function (nodes, opts) {
+ var family = [];
+ var last = null;
+ var i, max;
+
+ nodes.forEach(function (node, index, nodes) {
+ var value = node.value;
+
+ if (node.type === 'string' || node.type === 'function') {
+ family.push(node);
+ } else if (node.type === 'word') {
+ if (!last) {
+ last = { type: 'word', value: '' };
+ family.push(last);
+ }
+
+ last.value += node.value;
+ } else if (node.type === 'space') {
+ if (last && index !== nodes.length - 1) {
+ last.value += ' ';
+ }
+ } else {
+ last = null;
+ }
+ });
+
+ family = family.map(function (node) {
+ if (node.type === 'string') {
+ if (
+ !opts.removeQuotes ||
+ intersection(node.value, keywords) ||
+ /[0-9]/.test(node.value.slice(0, 1))
+ ) {
+ return stringify(node);
+ }
+
+ var escaped = node.value.split(/\s/).map(function (word, index, words) {
+ var next = words[index + 1];
+ if (next && /^[^a-z]/i.test(next)) {
+ return word + '\\';
+ }
+
+ if (!/^[^a-z\d\xa0-\uffff_-]/i.test(word)) {
+ return word.replace(/([^a-z\d\xa0-\uffff_-])/gi, '\\$1');
+ }
+
+ if (/^[^a-z]/i.test(word) && index < 1) {
+ return '\\' + word;
+ }
+
+ return word;
+ }).join(' ');
+
+ if (escaped.length < node.value.length + 2) {
+ return escaped;
+ }
+ }
+
+ return stringify(node);
+ });
+
+ if (opts.removeAfterKeyword) {
+ for (i = 0, max = family.length; i < max; i += 1) {
+ if (~keywords.indexOf(family[i])) {
+ family = family.slice(0, i + 1);
+ break;
+ }
+ }
+ }
+
+ if (opts.removeDuplicates) {
+ family = uniqs(family);
+ }
+
+ return [
+ {
+ type: 'word',
+ value: family.join()
+ }
+ ];
+};
diff --git a/node_modules/postcss-minify-font-values/lib/minify-font.js b/node_modules/postcss-minify-font-values/lib/minify-font.js
new file mode 100644
index 00000000..3287fd64
--- /dev/null
+++ b/node_modules/postcss-minify-font-values/lib/minify-font.js
@@ -0,0 +1,50 @@
+var unit = require('postcss-value-parser').unit;
+var keywords = require('./keywords');
+var minifyFamily = require('./minify-family');
+var minifyWeight = require('./minify-weight');
+
+module.exports = function (nodes, opts) {
+ var i, max, node, familyStart, family;
+ var hasSize = false;
+
+ for (i = 0, max = nodes.length; i < max; i += 1) {
+ node = nodes[i];
+ if (node.type === 'word') {
+ if (node.value === 'normal' ||
+ ~keywords.style.indexOf(node.value) ||
+ ~keywords.variant.indexOf(node.value) ||
+ ~keywords.stretch.indexOf(node.value)) {
+ if (!hasSize) {
+ familyStart = i;
+ }
+ } else if (~keywords.weight.indexOf(node.value)) {
+ if (!hasSize) {
+ node.value = minifyWeight(node.value, opts);
+ familyStart = i;
+ }
+ } else if (~keywords.size.indexOf(node.value) || unit(node.value)) {
+ if (!hasSize) {
+ familyStart = i;
+ hasSize = true;
+ }
+ }
+ } else if (node.type === 'div') {
+ node.before = '';
+ node.after = '';
+ if (node.value === '/') {
+ familyStart = i + 1;
+ }
+ break;
+ } else if (node.type === 'space') {
+ node.value = ' ';
+ }
+ }
+
+ if (!isNaN(familyStart)) {
+ familyStart += 2;
+ family = minifyFamily(nodes.slice(familyStart), opts);
+ nodes = nodes.slice(0, familyStart).concat(family);
+ }
+
+ return nodes;
+};
diff --git a/node_modules/postcss-minify-font-values/lib/minify-weight.js b/node_modules/postcss-minify-font-values/lib/minify-weight.js
new file mode 100644
index 00000000..6b4cbfb5
--- /dev/null
+++ b/node_modules/postcss-minify-font-values/lib/minify-weight.js
@@ -0,0 +1,3 @@
+module.exports = function (value) {
+ return value === 'normal' ? '400' : value === 'bold' ? '700' : value;
+};
diff --git a/node_modules/postcss-minify-font-values/lib/uniqs.js b/node_modules/postcss-minify-font-values/lib/uniqs.js
new file mode 100644
index 00000000..a555b8e2
--- /dev/null
+++ b/node_modules/postcss-minify-font-values/lib/uniqs.js
@@ -0,0 +1,11 @@
+module.exports = function uniqueExcept (exclude) {
+ return function unique () {
+ var list = Array.prototype.concat.apply([], arguments);
+ return list.filter(function (item, i) {
+ if (item === exclude) {
+ return true;
+ }
+ return i === list.indexOf(item);
+ });
+ };
+};