├── snapshots
├── alipay
│ ├── alipay.json
│ ├── alipay.acss
│ ├── alipay.js
│ └── alipay.axml
├── kuaishou
│ ├── kuaishou.json
│ ├── kuaishou.css
│ ├── kuaishou.js
│ └── kuaishou.ksml
├── toutiao
│ ├── toutiao.json
│ ├── toutiao.ttss
│ ├── toutiao.js
│ └── toutiao.ttml
├── qq
│ ├── qq.qss
│ ├── qq.json
│ ├── qq.js
│ └── qq.qml
├── baidu
│ ├── baidu.css
│ ├── baidu.json
│ ├── baidu.js
│ └── baidu.swan
└── wechat
│ ├── wechat.wxss
│ ├── wechat.json
│ ├── wechat.js
│ └── wechat.wxml
├── src
├── templates
│ ├── alipay.json.template
│ ├── kuaishou.json.template
│ ├── toutiao.json.template
│ ├── qq.qss.template
│ ├── alipay.acss.template
│ ├── baidu.css.template
│ ├── wechat.wxss.template
│ ├── kuaishou.css.template
│ ├── toutiao.ttss.template
│ ├── baidu.json.template
│ ├── qq.json.template
│ ├── wechat.json.template
│ ├── qq.js.template
│ ├── kuaishou.js.template
│ ├── wechat.js.template
│ ├── toutiao.js.template
│ ├── baidu.js.template
│ └── alipay.js.template
├── libs
│ ├── whitespace.ts
│ ├── iconfont.json
│ ├── getTemplate.ts
│ ├── replace.ts
│ ├── fetchXml.ts
│ ├── getConfig.ts
│ ├── utils.ts
│ ├── generateKuaishouComponent.ts
│ ├── generateQqComponent.ts
│ ├── generateBaiduComponent.ts
│ ├── generateAlipayComponent.ts
│ ├── generateToutiaoComponent.ts
│ └── generateWechatComponent.ts
└── commands
│ ├── createQqIcon.ts
│ ├── createBaiduIcon.ts
│ ├── createAlipayIcon.ts
│ ├── createWechatIcon.ts
│ ├── createKuaishouIcon.ts
│ ├── createToutiaoIcon.ts
│ ├── help.ts
│ └── createJson.ts
├── .gitignore
├── images
├── symbol-url.png
└── multi-color-icon.jpg
├── scripts
├── config
│ ├── qq.json
│ ├── baidu.json
│ ├── alipay.json
│ ├── toutiao.json
│ ├── wechat.json
│ └── kuaishou.json
└── update-snapshot.sh
├── .editorconfig
├── publish.sh
├── CHANGELOG.md
├── tsconfig.json
├── LICENSE
├── package.json
├── README.md
└── yarn.lock
/snapshots/alipay/alipay.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/kuaishou/kuaishou.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/toutiao/toutiao.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/qq/qq.qss:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/alipay.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/kuaishou.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/toutiao.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "component": true
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/alipay/alipay.acss:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/baidu/baidu.css:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/wechat/wechat.wxss:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/qq.qss.template:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | *.log
3 | .idea/
4 | build/
5 | /iconfont.json
6 | .DS_Store
--------------------------------------------------------------------------------
/snapshots/kuaishou/kuaishou.css:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/qq/qq.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
5 |
--------------------------------------------------------------------------------
/snapshots/toutiao/toutiao.ttss:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/alipay.acss.template:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/baidu.css.template:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/wechat.wxss.template:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/snapshots/baidu/baidu.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
5 |
--------------------------------------------------------------------------------
/snapshots/wechat/wechat.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
5 |
--------------------------------------------------------------------------------
/src/templates/kuaishou.css.template:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/toutiao.ttss.template:
--------------------------------------------------------------------------------
1 | .icon {
2 | background-repeat: no-repeat;
3 | }
4 |
--------------------------------------------------------------------------------
/src/templates/baidu.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
5 |
--------------------------------------------------------------------------------
/src/templates/qq.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
5 |
--------------------------------------------------------------------------------
/src/templates/wechat.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
5 |
--------------------------------------------------------------------------------
/images/symbol-url.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iconfont-cli/mini-program-iconfont-cli/HEAD/images/symbol-url.png
--------------------------------------------------------------------------------
/src/libs/whitespace.ts:
--------------------------------------------------------------------------------
1 | export const whitespace = (repeat: number) => {
2 | return ' '.repeat(repeat);
3 | };
4 |
--------------------------------------------------------------------------------
/images/multi-color-icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iconfont-cli/mini-program-iconfont-cli/HEAD/images/multi-color-icon.jpg
--------------------------------------------------------------------------------
/src/libs/iconfont.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "请参考README.md,复制 http://iconfont.cn 官网提供的JS链接",
3 | "save_dir": "./iconfont",
4 | "use_rpx": false,
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 18
7 | }
8 |
--------------------------------------------------------------------------------
/scripts/config/qq.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js",
3 | "use_rpx": false,
4 | "save_dir": "./snapshots/qq",
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 24
7 | }
8 |
--------------------------------------------------------------------------------
/scripts/config/baidu.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js",
3 | "use_rpx": false,
4 | "save_dir": "./snapshots/baidu",
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 18
7 | }
8 |
--------------------------------------------------------------------------------
/scripts/config/alipay.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js",
3 | "use_rpx": false,
4 | "save_dir": "./snapshots/alipay",
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 18
7 | }
8 |
--------------------------------------------------------------------------------
/scripts/config/toutiao.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js",
3 | "use_rpx": true,
4 | "save_dir": "./snapshots/toutiao",
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 18
7 | }
8 |
--------------------------------------------------------------------------------
/scripts/config/wechat.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js",
3 | "use_rpx": false,
4 | "save_dir": "./snapshots/wechat",
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 20
7 | }
8 |
--------------------------------------------------------------------------------
/scripts/config/kuaishou.json:
--------------------------------------------------------------------------------
1 | {
2 | "symbol_url": "http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js",
3 | "use_rpx": false,
4 | "save_dir": "./snapshots/kuaishou",
5 | "trim_icon_prefix": "icon",
6 | "default_icon_size": 18
7 | }
8 |
--------------------------------------------------------------------------------
/src/libs/getTemplate.ts:
--------------------------------------------------------------------------------
1 | import fs from 'fs';
2 | import path from 'path';
3 |
4 | export const getTemplate = (fileName: string) => {
5 | return fs.readFileSync(path.join(__dirname, `../templates/${fileName}.template`)).toString();
6 | };
7 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [.*]
12 | insert_final_newline = false
13 |
--------------------------------------------------------------------------------
/src/commands/createQqIcon.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 | import { getConfig } from '../libs/getConfig';
5 | import { fetchXml } from '../libs/fetchXml';
6 | import { generateQqComponent } from '../libs/generateQqComponent';
7 |
8 | const config = getConfig();
9 |
10 | fetchXml(config.symbol_url).then((result) => {
11 | generateQqComponent(result, config);
12 | }).catch((e) => {
13 | console.error(colors.red(e.message || 'Unknown Error'));
14 | process.exit(1);
15 | });
16 |
--------------------------------------------------------------------------------
/src/commands/createBaiduIcon.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 | import { getConfig } from '../libs/getConfig';
5 | import { fetchXml } from '../libs/fetchXml';
6 | import { generateBaiduComponent } from '../libs/generateBaiduComponent';
7 |
8 | const config = getConfig();
9 |
10 | fetchXml(config.symbol_url).then((result) => {
11 | generateBaiduComponent(result, config);
12 | }).catch((e) => {
13 | console.error(colors.red(e.message || 'Unknown Error'));
14 | process.exit(1);
15 | });
16 |
--------------------------------------------------------------------------------
/src/commands/createAlipayIcon.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 | import { getConfig } from '../libs/getConfig';
5 | import { fetchXml } from '../libs/fetchXml';
6 | import { generateAlipayComponent } from '../libs/generateAlipayComponent';
7 |
8 | const config = getConfig();
9 |
10 | fetchXml(config.symbol_url).then((result) => {
11 | generateAlipayComponent(result, config);
12 | }).catch((e) => {
13 | console.error(colors.red(e.message || 'Unknown Error'));
14 | process.exit(1);
15 | });
16 |
--------------------------------------------------------------------------------
/src/commands/createWechatIcon.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 | import { getConfig } from '../libs/getConfig';
5 | import { fetchXml } from '../libs/fetchXml';
6 | import { generateWechatComponent } from '../libs/generateWechatComponent';
7 |
8 | const config = getConfig();
9 |
10 | fetchXml(config.symbol_url).then((result) => {
11 | generateWechatComponent(result, config);
12 | }).catch((e) => {
13 | console.error(colors.red(e.message || 'Unknown Error'));
14 | process.exit(1);
15 | });
16 |
--------------------------------------------------------------------------------
/src/commands/createKuaishouIcon.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 | import { getConfig } from '../libs/getConfig';
5 | import { fetchXml } from '../libs/fetchXml';
6 | import { generateKuaishouComponent } from '../libs/generateKuaishouComponent';
7 |
8 | const config = getConfig();
9 |
10 | fetchXml(config.symbol_url).then((result) => {
11 | generateKuaishouComponent(result, config);
12 | }).catch((e) => {
13 | console.error(colors.red(e.message || 'Unknown Error'));
14 | process.exit(1);
15 | });
16 |
--------------------------------------------------------------------------------
/src/commands/createToutiaoIcon.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 | import { getConfig } from '../libs/getConfig';
5 | import { fetchXml } from '../libs/fetchXml';
6 | import { generateToutiaoComponent } from '../libs/generateToutiaoComponent';
7 |
8 | const config = getConfig();
9 |
10 | fetchXml(config.symbol_url).then((result) => {
11 | generateToutiaoComponent(result, config);
12 | }).catch((e) => {
13 | console.error(colors.red(e.message || 'Unknown Error'));
14 | process.exit(1);
15 | });
16 |
--------------------------------------------------------------------------------
/scripts/update-snapshot.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | npx ts-node src/commands/createQqIcon.ts --config ./scripts/config/qq.json
4 | npx ts-node src/commands/createToutiaoIcon.ts --config ./scripts/config/toutiao.json
5 | npx ts-node src/commands/createKuaishouIcon.ts --config ./scripts/config/kuaishou.json
6 | npx ts-node src/commands/createBaiduIcon.ts --config ./scripts/config/baidu.json
7 | npx ts-node src/commands/createAlipayIcon.ts --config ./scripts/config/alipay.json
8 | npx ts-node src/commands/createWechatIcon.ts --config ./scripts/config/wechat.json
9 |
--------------------------------------------------------------------------------
/snapshots/qq/qq.js:
--------------------------------------------------------------------------------
1 | Component({
2 | properties: {
3 | // alipay | user | setup
4 | name: {
5 | type: String,
6 | },
7 | // string | string[]
8 | color: {
9 | type: null,
10 | observer: function(color) {
11 | this.setData({
12 | isStr: typeof color === 'string',
13 | });
14 | }
15 | },
16 | size: {
17 | type: Number,
18 | value: 24,
19 | observer: function(size) {
20 | this.setData({
21 | svgSize: size,
22 | });
23 | },
24 | },
25 | },
26 | data: {
27 | svgSize: 24,
28 | quot: '"',
29 | isStr: true,
30 | },
31 | });
32 |
--------------------------------------------------------------------------------
/publish.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | rm -rf ./build
4 | rm -rf ./src/iconfont
5 |
6 | ./node_modules/.bin/tsc
7 |
8 | mv ./build/src/* ./build
9 | rm -r ./build/src
10 | cp README.md package.json LICENSE ./build
11 | cp -rf src/templates ./build/templates
12 |
13 | old_registry=$(npm config get registry)
14 | npm config set registry https://registry.npmjs.org
15 | set +e
16 | whoami=$(npm whoami 2>/dev/null)
17 | set -e
18 |
19 | if [ -z "$whoami" ]
20 | then
21 | echo "login plz..."
22 | npm login
23 | fi
24 | echo "I am: $(npm whoami)"
25 |
26 | sleep 1
27 | echo "Begin publish..."
28 | npm publish ./build/ --access=public "$@"
29 |
30 | npm config set registry ${old_registry}
31 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 0.6.1
2 | 修复部分平台图标展示失败问题
3 |
4 | # 0.6.0
5 | [feat] npx iconfont-init 增加 `--output` 选项,可传入配置输出路径,默认为 iconfont.json
6 |
7 | [feat] npx iconfont-XXXXX 增加 `--config` 选项,可传入配置文件路径,默认为 iconfont.json
8 |
9 | # 0.5.5
10 | [fix] 修复 node 8.4.0 和之前版本无法初始化的问题
11 |
12 | # 0.5.4
13 | [fix] 修复rpx格式中,容器和svg尺寸不一致导致线条溢出问题
14 |
15 | [fix] 修复图标名称前缀有多个符号时无法彻底清除的问题
16 |
17 | # 0.5.3
18 | [fix] 修复rpx在各个小程序导致图标靠顶的问题
19 |
20 | # 0.5.0
21 | [feature] 增加QQ小程序
22 |
23 | # 0.4.0
24 | [feature] 增加头条小程序(字节跳动)
25 |
26 | # 0.3.4
27 | [fix] 执行文件头部增加蛇棒
28 |
29 | # 0.3.2
30 | [fix] 删除图标名称的边界符号
31 |
32 | # 0.3.0
33 | [feature] 增加百度小程序
34 |
35 | # 0.2.0
36 | [feature] 增加支付宝小程序
37 |
38 | # 0.1.0
39 | [fix] 修复微信不支持16进制颜色格式的写法
40 |
--------------------------------------------------------------------------------
/src/templates/qq.js.template:
--------------------------------------------------------------------------------
1 | Component({
2 | properties: {
3 | // #names#
4 | name: {
5 | type: String,
6 | },
7 | // string | string[]
8 | color: {
9 | type: null,
10 | observer: function(color) {
11 | this.setData({
12 | isStr: typeof color === 'string',
13 | });
14 | }
15 | },
16 | size: {
17 | type: Number,
18 | value: #size#,
19 | observer: function(size) {
20 | this.setData({
21 | svgSize: #rpx-1:size / 750 * qq.getSystemInfoSync().windowWidth:##rpx-0:size:#,
22 | });
23 | },
24 | },
25 | },
26 | data: {
27 | svgSize: #rpx-1:#size# / 750 * qq.getSystemInfoSync().windowWidth:##rpx-0:#size#:#,
28 | quot: '"',
29 | isStr: true,
30 | },
31 | });
32 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "commonjs",
5 | "allowJs": false,
6 | "declaration": true,
7 | "removeComments": false,
8 | "outDir": "./build",
9 | "rootDir": "./",
10 | "jsx": "react",
11 | "importHelpers": true,
12 | "downlevelIteration": true,
13 | "strict": true,
14 | "noImplicitAny": false,
15 | "strictNullChecks": true,
16 | "strictFunctionTypes": true,
17 | "strictBindCallApply": true,
18 | "strictPropertyInitialization": true,
19 | "noImplicitThis": true,
20 | "alwaysStrict": true,
21 |
22 | "noUnusedLocals": true,
23 | "noUnusedParameters": true,
24 | "noImplicitReturns": true,
25 | "noFallthroughCasesInSwitch": true,
26 | "moduleResolution": "node",
27 | "allowSyntheticDefaultImports": true,
28 | "esModuleInterop": true,
29 | "resolveJsonModule": true
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/commands/help.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import colors from 'colors';
4 |
5 | console.log([
6 | '',
7 | 'Usage:',
8 | '',
9 | ' ' + colors.green.bold('npx iconfont-init [--output]') + ' : Generate configuration file, default file name is iconfont.json',
10 | ' ' + colors.green.bold('npx iconfont-wechat [--config]') + ' : Generate wechat icon component',
11 | ' ' + colors.green.bold('npx iconfont-alipay [--config]') + ' : Generate alipay icon component',
12 | ' ' + colors.green.bold('npx iconfont-baidu [--config]') + ' : Generate baidu icon component',
13 | ' ' + colors.green.bold('npx iconfont-toutiao [--config]') + ' : Generate toutiao icon component',
14 | ' ' + colors.green.bold('npx iconfont-kuaishou [--config]') + ' : Generate kuaishou icon component',
15 | ' ' + colors.green.bold('npx iconfont-qq [--config]') + ' : Generate qq icon component',
16 | '',
17 | ].join('\n'));
18 |
--------------------------------------------------------------------------------
/src/commands/createJson.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import path from 'path';
4 | import fs from 'fs';
5 | import fse from 'fs-extra';
6 | import colors from 'colors';
7 | import minimist from 'minimist';
8 |
9 | const args = minimist<{ output: string }>(process.argv.slice(2));
10 |
11 | let outputPath = 'iconfont.json';
12 |
13 | if (args.output && typeof args.output === 'string') {
14 | outputPath = args.output;
15 |
16 | if (outputPath.split('.').pop() !== 'json') {
17 | outputPath += '.json';
18 | }
19 | }
20 |
21 | const targetFile = path.resolve(outputPath);
22 |
23 | if (fs.existsSync(targetFile)) {
24 | console.error(colors.red(`File "${outputPath}" was created before.`));
25 | } else {
26 | // fs.copyFileSync only can be used above node v8.5.0+
27 | fse.copySync(path.join(__dirname, '../libs/iconfont.json'), targetFile);
28 | console.log(colors.green(`File "${outputPath}" is created now. We recommend you add it to version control.`));
29 | }
30 |
--------------------------------------------------------------------------------
/src/libs/replace.ts:
--------------------------------------------------------------------------------
1 | export const replaceSize = (content: string, size: number) => {
2 | return content.replace(/#size#/g, String(size));
3 | };
4 |
5 | export const replaceNames = (content: string, names: string[]) => {
6 | return content.replace(/#names#/g, names.join(' | '));
7 | };
8 |
9 | export const replaceHexToRgb = (hex) => {
10 | const rgb: number[] = [];
11 |
12 | //去除前缀 # 号
13 | hex = hex.substr(1);
14 |
15 | if (hex.length === 3) {
16 | // 处理 '#abc' 成 '#aabbcc'
17 | hex = hex.replace(/(.)/g, '$1$1');
18 | }
19 |
20 | hex.replace(/../g, (color: string) => {
21 | // 按16进制将字符串转换为数字
22 | rgb.push(parseInt(color, 0x10));
23 |
24 | return color;
25 | });
26 |
27 | return 'rgb(' + rgb.join(',') + ')';
28 | };
29 |
30 | export const replaceIsRpx = (content: string, useRpx: boolean) => {
31 | return content
32 | .replace(/#rpx-1:(.+?):#/g, useRpx ? '$1' : '')
33 | .replace(/#rpx-0:(.+?):#/g, useRpx ? '' : '$1');
34 | };
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 原罪
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/libs/fetchXml.ts:
--------------------------------------------------------------------------------
1 | import axios from 'axios';
2 | import { parseString } from 'xml2js';
3 | import colors from 'colors';
4 |
5 | export interface XmlData {
6 | svg: {
7 | symbol: Array<{
8 | $: {
9 | viewBox: string;
10 | id: string;
11 | };
12 | path: Array<{
13 | $: {
14 | d: string;
15 | fill?: string;
16 | };
17 | }>;
18 | }>;
19 | }
20 | }
21 |
22 | export const fetchXml = async (url): Promise => {
23 | console.log('Fetching iconfont data...');
24 |
25 | try {
26 | const { data } = await axios.get(url);
27 | const matches = String(data).match(/'