更新前端静态网页获取方式,放弃使用后端获取api

This commit is contained in:
2025-09-09 10:47:51 +08:00
parent 6889ca37e5
commit 44a4f1bae1
25558 changed files with 2463152 additions and 153 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,81 @@
# 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`
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].
## 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,40 @@
{
"name": "postcss-minify-font-values",
"version": "5.1.0",
"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": "^10 || ^12 || >=14.0"
},
"devDependencies": {
"postcss": "^8.2.15"
},
"peerDependencies": {
"postcss": "^8.2.15"
},
"readme": "# postcss-minify-font-values [![Build Status][ci-img]][ci]\n\n> Minify font declarations with PostCSS.\n\nThis module will try to minimise the `font-family`, `font-weight` and `font` shorthand\nproperties; it can unquote font families where necessary, detect & remove\nduplicates, and cut short a declaration after it finds a keyword. For more\nexamples, see the [tests](test).\n\n```css\nh1 {\n font:bold 2.2rem/.9 \"Open Sans Condensed\", sans-serif;\n}\n\np {\n font-family: \"Helvetica Neue\", Arial, sans-serif, Helvetica;\n font-weight: normal;\n}\n```\n\n```css\nh1 {\n font:700 2.2rem/.9 Open Sans Condensed,sans-serif\n}\n\np {\n font-family: Helvetica Neue,Arial,sans-serif;\n font-weight: 400;\n}\n```\n\n## API\n\n### minifyFontValues([options])\n\n#### options\n\n##### removeAfterKeyword\n\nType: `boolean`\nDefault: `false`\n\nPass `true` to remove font families after the module encounters a font keyword,\nfor example `sans-serif`.\n\n##### removeDuplicates\n\nType: `boolean`\nDefault: `true`\n\nPass `false` to disable the module from removing duplicated font families.\n\n##### removeQuotes\n\nType: `boolean`\nDefault: `true`\n\nPass `false` to disable the module from removing quotes from font families.\nNote that oftentimes, this is a *safe optimisation* & is done safely. For more\ndetails, see [Mathias Bynens' article][mathias].\n\n## Usage\n\n```js\npostcss([ require('postcss-minify-font-values') ])\n```\n\nSee [PostCSS] docs for examples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n# License\n\nMIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)\n\n[mathias]: https://mathiasbynens.be/notes/unquoted-font-family\n[PostCSS]: https://github.com/postcss/postcss\n[ci-img]: https://travis-ci.org/cssnano/postcss-minify-font-values.svg\n[ci]: https://travis-ci.org/cssnano/postcss-minify-font-values\n"
}

View File

@@ -0,0 +1,98 @@
'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();
if (lowerCasedProp === 'font-weight' && !hasVariableFunction(value)) {
return minifyWeight(value);
} else if (lowerCasedProp === 'font-family' && !hasVariableFunction(value)) {
const tree = valueParser(value);
tree.nodes = minifyFamily(tree.nodes, opts);
return tree.toString();
} else if (lowerCasedProp === 'font') {
const tree = valueParser(value);
tree.nodes = minifyFont(tree.nodes, opts);
return tree.toString();
}
return value;
}
/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean}} 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,17 @@
export = pluginCreator;
/** @typedef {{removeAfterKeyword?: boolean, removeDuplicates?: boolean, removeQuotes?: boolean}} 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 };
}
type Options = {
removeAfterKeyword?: boolean;
removeDuplicates?: boolean;
removeQuotes?: boolean;
};
declare var postcss: true;