It appears you have a well-structured Git repository with various files, including SVG icons and HTML documents. Here's a brief overview:

This commit is contained in:
2025-06-11 09:05:15 +02:00
parent 36c2466e53
commit 6d6aa954dd
15556 changed files with 1076330 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
Copyright (c) Bogdan Chadkin <trysound@yandex.ru>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,83 @@
# postcss-minify-font-values [![Build Status][ci-img]][ci]
> Minify font declarations with PostCSS.
This module will try to minimise the `font-family`, `font-weight` and `font` shorthand
properties; it can unquote font families where necessary, detect & remove
duplicates, and cut short a declaration after it finds a keyword. For more
examples, see the [tests](test).
```css
h1 {
font:bold 2.2rem/.9 "Open Sans Condensed", sans-serif;
}
p {
font-family: "Helvetica Neue", Arial, sans-serif, Helvetica;
font-weight: normal;
}
```
```css
h1 {
font:700 2.2rem/.9 Open Sans Condensed,sans-serif
}
p {
font-family: Helvetica Neue,Arial,sans-serif;
font-weight: 400;
}
```
## API
### minifyFontValues([options])
#### options
##### removeAfterKeyword
Type: `boolean`
Default: `false`
Pass `true` to remove font families after the module encounters a font keyword,
for example `sans-serif`.
##### removeDuplicates
Type: `boolean`
Default: `true`
Pass `false` to disable the module from removing duplicated font families.
##### removeQuotes
Type: `boolean` | `(prop: string) => '' | 'font' | 'font-family' | 'font-weight'`
Default: `true`
Pass `false` to disable the module from removing quotes from font families.
Note that oftentimes, this is a *safe optimisation* & is done safely. For more
details, see [Mathias Bynens' article][mathias].
Pass a function to determine whether a css variable is one of `font`, `font-family`, and `font-weight` to determine whether the variable needs to remove quotes.
## Usage
```js
postcss([ require('postcss-minify-font-values') ])
```
See [PostCSS] docs for examples for your environment.
## Contributors
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
# License
MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
[mathias]: https://mathiasbynens.be/notes/unquoted-font-family
[PostCSS]: https://github.com/postcss/postcss
[ci-img]: https://travis-ci.org/cssnano/postcss-minify-font-values.svg
[ci]: https://travis-ci.org/cssnano/postcss-minify-font-values

View File

@@ -0,0 +1,39 @@
{
"name": "postcss-minify-font-values",
"version": "7.0.1",
"description": "Minify font declarations with PostCSS",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"src",
"LICENSE",
"types"
],
"author": "Bogdan Chadkin <trysound@yandex.ru>",
"license": "MIT",
"keywords": [
"css",
"font",
"font-family",
"font-weight",
"optimise",
"postcss-plugin"
],
"dependencies": {
"postcss-value-parser": "^4.2.0"
},
"repository": "cssnano/cssnano",
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"homepage": "https://github.com/cssnano/cssnano",
"engines": {
"node": "^18.12.0 || ^20.9.0 || >=22.0"
},
"devDependencies": {
"postcss": "^8.5.3"
},
"peerDependencies": {
"postcss": "^8.4.32"
}
}

View File

@@ -0,0 +1,105 @@
'use strict';
const valueParser = require('postcss-value-parser');
const minifyWeight = require('./lib/minify-weight');
const minifyFamily = require('./lib/minify-family');
const minifyFont = require('./lib/minify-font');
/**
* @param {string} value
* @return {boolean}
*/
function hasVariableFunction(value) {
const lowerCasedValue = value.toLowerCase();
return lowerCasedValue.includes('var(') || lowerCasedValue.includes('env(');
}
/**
* @param {string} prop
* @param {string} value
* @param {Options} opts
* @return {string}
*/
function transform(prop, value, opts) {
let lowerCasedProp = prop.toLowerCase();
let variableType = '';
if (typeof opts.removeQuotes === 'function') {
variableType = opts.removeQuotes(prop);
opts.removeQuotes = true;
}
if (
(lowerCasedProp === 'font-weight' || variableType === 'font-weight') &&
!hasVariableFunction(value)
) {
return minifyWeight(value);
} else if (
(lowerCasedProp === 'font-family' || variableType === 'font-family') &&
!hasVariableFunction(value)
) {
const tree = valueParser(value);
tree.nodes = minifyFamily(tree.nodes, opts);
return tree.toString();
} else if (lowerCasedProp === 'font' || variableType === 'font') {
return minifyFont(value, opts);
}
return value;
}
/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean | ((prop: string) => '' | 'font' | 'font-family' | 'font-weight')}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts) {
opts = Object.assign(
{},
{
removeAfterKeyword: false,
removeDuplicates: true,
removeQuotes: true,
},
opts
);
return {
postcssPlugin: 'postcss-minify-font-values',
prepare() {
const cache = new Map();
return {
OnceExit(css) {
css.walkDecls(/font/i, (decl) => {
const value = decl.value;
if (!value) {
return;
}
const prop = decl.prop;
const cacheKey = `${prop}|${value}`;
if (cache.has(cacheKey)) {
decl.value = cache.get(cacheKey);
return;
}
const newValue = transform(prop, value, opts);
decl.value = newValue;
cache.set(cacheKey, newValue);
});
},
};
},
};
}
pluginCreator.postcss = true;
module.exports = pluginCreator;

View File

@@ -0,0 +1,40 @@
'use strict';
module.exports = {
style: new Set(['italic', 'oblique']),
variant: new Set(['small-caps']),
weight: new Set([
'100',
'200',
'300',
'400',
'500',
'600',
'700',
'800',
'900',
'bold',
'lighter',
'bolder',
]),
stretch: new Set([
'ultra-condensed',
'extra-condensed',
'condensed',
'semi-condensed',
'semi-expanded',
'expanded',
'extra-expanded',
'ultra-expanded',
]),
size: new Set([
'xx-small',
'x-small',
'small',
'medium',
'large',
'x-large',
'xx-large',
'larger',
'smaller',
]),
};

View File

@@ -0,0 +1,248 @@
'use strict';
const { stringify } = require('postcss-value-parser');
/**
* @param {string[]} list
* @return {string[]}
*/
function uniqueFontFamilies(list) {
return list.filter((item, i) => {
if (item.toLowerCase() === 'monospace') {
return true;
}
return i === list.indexOf(item);
});
}
const globalKeywords = ['inherit', 'initial', 'unset'];
const genericFontFamilykeywords = new Set([
'sans-serif',
'serif',
'fantasy',
'cursive',
'monospace',
'system-ui',
]);
/**
* @param {string} value
* @param {number} length
* @return {string[]}
*/
function makeArray(value, length) {
let array = [];
while (length--) {
array[length] = value;
}
return array;
}
// eslint-disable-next-line no-useless-escape
const regexSimpleEscapeCharacters = /[ !"#$%&'()*+,.\/;<=>?@\[\\\]^`{|}~]/;
/**
* @param {string} string
* @param {boolean} escapeForString
* @return {string}
*/
function escape(string, escapeForString) {
let counter = 0;
let character;
let charCode;
let value;
let output = '';
while (counter < string.length) {
character = string.charAt(counter++);
charCode = character.charCodeAt(0);
// \r is already tokenized away at this point
// `:` can be escaped as `\:`, but that fails in IE < 8
if (!escapeForString && /[\t\n\v\f:]/.test(character)) {
value = '\\' + charCode.toString(16) + ' ';
} else if (
!escapeForString &&
regexSimpleEscapeCharacters.test(character)
) {
value = '\\' + character;
} else {
value = character;
}
output += value;
}
if (!escapeForString) {
if (/^-[-\d]/.test(output)) {
output = '\\-' + output.slice(1);
}
const firstChar = string.charAt(0);
if (/\d/.test(firstChar)) {
output = '\\3' + firstChar + ' ' + output.slice(1);
}
}
return output;
}
const regexKeyword = new RegExp(
[...genericFontFamilykeywords].concat(globalKeywords).join('|'),
'i'
);
const regexInvalidIdentifier = /^(-?\d|--)/;
const regexSpaceAtStart = /^\x20/;
const regexWhitespace = /[\t\n\f\r\x20]/g;
const regexIdentifierCharacter = /^[a-zA-Z\d\xa0-\uffff_-]+$/;
const regexConsecutiveSpaces = /(\\(?:[a-fA-F0-9]{1,6}\x20|\x20))?(\x20{2,})/g;
const regexTrailingEscape = /\\[a-fA-F0-9]{0,6}\x20$/;
const regexTrailingSpace = /\x20$/;
/**
* @param {string} string
* @return {string}
*/
function escapeIdentifierSequence(string) {
let identifiers = string.split(regexWhitespace);
let index = 0;
/** @type {string[] | string} */
let result = [];
let escapeResult;
while (index < identifiers.length) {
let subString = identifiers[index++];
if (subString === '') {
result.push(subString);
continue;
}
escapeResult = escape(subString, false);
if (regexIdentifierCharacter.test(subString)) {
// the font family name part consists of allowed characters exclusively
if (regexInvalidIdentifier.test(subString)) {
// the font family name part starts with two hyphens, a digit, or a
// hyphen followed by a digit
if (index === 1) {
// if this is the first item
result.push(escapeResult);
} else {
// if its not the first item, we can simply escape the space
// between the two identifiers to merge them into a single
// identifier rather than escaping the start characters of the
// second identifier
result[index - 2] += '\\';
result.push(escape(subString, true));
}
} else {
// the font family name part doesnt start with two hyphens, a digit,
// or a hyphen followed by a digit
result.push(escapeResult);
}
} else {
// the font family name part contains invalid identifier characters
result.push(escapeResult);
}
}
result = result.join(' ').replace(regexConsecutiveSpaces, ($0, $1, $2) => {
const spaceCount = $2.length;
const escapesNeeded = Math.floor(spaceCount / 2);
const array = makeArray('\\ ', escapesNeeded);
if (spaceCount % 2) {
array[escapesNeeded - 1] += '\\ ';
}
return ($1 || '') + ' ' + array.join(' ');
});
// Escape trailing spaces unless theyre already part of an escape
if (regexTrailingSpace.test(result) && !regexTrailingEscape.test(result)) {
result = result.replace(regexTrailingSpace, '\\ ');
}
if (regexSpaceAtStart.test(result)) {
result = '\\ ' + result.slice(1);
}
return result;
}
/**
* @param {import('postcss-value-parser').Node[]} nodes
* @param {import('../index').Options} opts
* @return {import('postcss-value-parser').WordNode[]}
*/
module.exports = function (nodes, opts) {
/** @type {import('postcss-value-parser').Node[]} */
const family = [];
/** @type {import('postcss-value-parser').WordNode | null} */
let last = null;
let i, max;
nodes.forEach((node, index, arr) => {
if (node.type === 'string' || node.type === 'function') {
family.push(node);
} else if (node.type === 'word') {
if (!last) {
last = /** @type {import('postcss-value-parser').WordNode} */ ({
type: 'word',
value: '',
});
family.push(last);
}
last.value += node.value;
} else if (node.type === 'space') {
if (last && index !== arr.length - 1) {
last.value += ' ';
}
} else {
last = null;
}
});
let normalizedFamilies = family.map((node) => {
if (node.type === 'string') {
const isKeyword = regexKeyword.test(node.value);
if (
!opts.removeQuotes ||
isKeyword ||
/[0-9]/.test(node.value.slice(0, 1))
) {
return stringify(node);
}
let escaped = escapeIdentifierSequence(node.value);
if (escaped.length < node.value.length + 2) {
return escaped;
}
}
return stringify(node);
});
if (opts.removeAfterKeyword) {
for (i = 0, max = normalizedFamilies.length; i < max; i += 1) {
if (genericFontFamilykeywords.has(normalizedFamilies[i].toLowerCase())) {
normalizedFamilies = normalizedFamilies.slice(0, i + 1);
break;
}
}
}
if (opts.removeDuplicates) {
normalizedFamilies = uniqueFontFamilies(normalizedFamilies);
}
return [
/** @type {import('postcss-value-parser').WordNode} */ ({
type: 'word',
value: normalizedFamilies.join(),
}),
];
};

View File

@@ -0,0 +1,90 @@
'use strict';
const valueParser = require('postcss-value-parser');
const keywords = require('./keywords');
const minifyFamily = require('./minify-family');
const minifyWeight = require('./minify-weight');
/**
* Adds missing spaces before strings.
*
* @param toBeSpliced {Set<number>}
* @param {import('postcss-value-parser').Node[]} nodes
* @return {void}
*/
function normalizeNodes(nodes, toBeSpliced) {
for (const index of toBeSpliced) {
nodes.splice(
index,
0,
/** @type {import('postcss-value-parser').SpaceNode} */ ({
type: 'space',
value: ' ',
})
);
}
}
/**
* @param {string} unminified
* @param {import('../index').Options} opts
* @return {string}
*/
module.exports = function (unminified, opts) {
const tree = valueParser(unminified);
const nodes = tree.nodes;
let familyStart = NaN;
let hasSize = false;
const toBeSpliced = new Set();
for (const [i, node] of nodes.entries()) {
if (node.type === 'string' && i > 0 && nodes[i - 1].type !== 'space') {
toBeSpliced.add(i);
}
if (node.type === 'word') {
if (hasSize) {
continue;
}
const value = node.value.toLowerCase();
if (
value === 'normal' ||
value === 'inherit' ||
value === 'initial' ||
value === 'unset'
) {
familyStart = i;
} else if (keywords.style.has(value) || valueParser.unit(value)) {
familyStart = i;
} else if (keywords.variant.has(value)) {
familyStart = i;
} else if (keywords.weight.has(value)) {
node.value = minifyWeight(value);
familyStart = i;
} else if (keywords.stretch.has(value)) {
familyStart = i;
} else if (keywords.size.has(value) || valueParser.unit(value)) {
familyStart = i;
hasSize = true;
}
} else if (
node.type === 'function' &&
nodes[i + 1] &&
nodes[i + 1].type === 'space'
) {
familyStart = i;
} else if (node.type === 'div' && node.value === '/') {
familyStart = i + 1;
break;
}
}
normalizeNodes(nodes, toBeSpliced);
familyStart += 2;
const family = minifyFamily(nodes.slice(familyStart), opts);
tree.nodes = nodes.slice(0, familyStart).concat(family);
return tree.toString();
};

View File

@@ -0,0 +1,14 @@
'use strict';
/**
* @param {string} value
* @return {string}
*/
module.exports = function (value) {
const lowerCasedValue = value.toLowerCase();
return lowerCasedValue === 'normal'
? '400'
: lowerCasedValue === 'bold'
? '700'
: value;
};

View File

@@ -0,0 +1,18 @@
export = pluginCreator;
/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean | ((prop: string) => '' | 'font' | 'font-family' | 'font-weight')}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(opts: Options): import("postcss").Plugin;
declare namespace pluginCreator {
export { postcss, Options };
}
declare var postcss: true;
type Options = {
removeAfterKeyword?: boolean;
removeDuplicates?: boolean;
removeQuotes?: boolean | ((prop: string) => "" | "font" | "font-family" | "font-weight");
};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAmDA,8KAA8K;AAE9K;;;;GAIG;AACH,qCAHW,OAAO,GACN,OAAO,SAAS,EAAE,MAAM,CA6CnC;;;;;eAlDa;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,EAAE,GAAG,MAAM,GAAG,aAAa,GAAG,aAAa,CAAC,CAAA;CAAC"}

View File

@@ -0,0 +1,6 @@
export let style: Set<string>;
export let variant: Set<string>;
export let weight: Set<string>;
export let stretch: Set<string>;
export let size: Set<string>;
//# sourceMappingURL=keywords.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/lib/keywords.js"],"names":[],"mappings":""}

View File

@@ -0,0 +1,3 @@
declare function _exports(nodes: import("postcss-value-parser").Node[], opts: import("../index").Options): import("postcss-value-parser").WordNode[];
export = _exports;
//# sourceMappingURL=minify-family.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"minify-family.d.ts","sourceRoot":"","sources":["../../src/lib/minify-family.js"],"names":[],"mappings":"AAiLiB,iCAJN,OAAO,sBAAsB,EAAE,IAAI,EAAE,QACrC,OAAO,UAAU,EAAE,OAAO,GACzB,OAAO,sBAAsB,EAAE,QAAQ,EAAE,CAwEpD"}

View File

@@ -0,0 +1,3 @@
declare function _exports(unminified: string, opts: import("../index").Options): string;
export = _exports;
//# sourceMappingURL=minify-font.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"minify-font.d.ts","sourceRoot":"","sources":["../../src/lib/minify-font.js"],"names":[],"mappings":"AA+BiB,sCAJN,MAAM,QACN,OAAO,UAAU,EAAE,OAAO,GACzB,MAAM,CA4DjB"}

View File

@@ -0,0 +1,3 @@
declare function _exports(value: string): string;
export = _exports;
//# sourceMappingURL=minify-weight.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"minify-weight.d.ts","sourceRoot":"","sources":["../../src/lib/minify-weight.js"],"names":[],"mappings":"AAKiB,iCAHN,MAAM,GACL,MAAM,CAUjB"}