@thelastcookies/base-icon 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/_virtual/_plugin-vue_export-helper.js +8 -0
- package/dist/components/BaseIcon.d.ts +13 -0
- package/dist/components/BaseIcon.js +7 -0
- package/dist/components/BaseIcon.vue_vue_type_script_setup_true_lang.js +48 -0
- package/dist/components/BaseIcon.vue_vue_type_style_index_0_scoped_3f3679aa_lang.css +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +13 -0
- package/package.json +76 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present thelastcookies
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @thelastcookies/base-icon
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
基于 [@iconify/vue](https://docs.iconify.design/icon-components/vue/) 封装的 Vue3 图标组件,兼容 `i-mdi-*` 类名协议,支持在线按需拉取与离线集合注入。
|
|
4
|
+
|
|
5
|
+
依赖 `vue >= 3.5`(peerDependencies)。
|
|
6
|
+
|
|
7
|
+
## 本地预览 Sample
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
启动 playground,浏览器打开提示的地址即可查看尺寸、常用图标与协议等价示例,源码见 [playground/QueryIconSample.vue](playground/BaseIconSample.vue)。
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @thelastcookies/base-icon
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 在线模式(零配置)
|
|
22
|
+
|
|
23
|
+
不注入图标集合时,组件运行时按需从 iconify API 拉取图标数据:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createApp } from 'vue';
|
|
27
|
+
import BaseIcon from '@thelastcookies/base-icon';
|
|
28
|
+
|
|
29
|
+
const app = createApp(App).use(BaseIcon);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 离线模式(推荐生产环境)
|
|
33
|
+
|
|
34
|
+
安装对应集合包(如 `@iconify-json/mdi`,为可选 peer 依赖),在安装时注入:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createApp } from 'vue';
|
|
38
|
+
import BaseIcon from '@thelastcookies/base-icon';
|
|
39
|
+
import mdiIcons from '@iconify-json/mdi/icons.json';
|
|
40
|
+
|
|
41
|
+
const app = createApp(App).use(BaseIcon, {
|
|
42
|
+
collections: [mdiIcons],
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 组件内使用
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { BaseIcon } from '@thelastcookies/base-icon';
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<!-- UnoCSS 类名协议,自动解析为 mdi:magnify -->
|
|
55
|
+
<BaseIcon icon="i-mdi-magnify" :size="1.5" />
|
|
56
|
+
<!-- iconify 原生协议,直接透传 -->
|
|
57
|
+
<BaseIcon icon="mdi:magnify" />
|
|
58
|
+
<!-- 图片 / Logo 模式,icon 以 / 开头指向站点公共资源目录 -->
|
|
59
|
+
<BaseIcon type="logo" icon="/logo.svg" :size="2" />
|
|
60
|
+
</template>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> 注意:UnoCSS 类名协议约定 `i-` 后首段为集合名(如 `i-mdi-*` → `mdi:*`)。
|
|
64
|
+
> 若集合名本身含 `-`,请改用 iconify 原生协议。
|
|
65
|
+
|
|
66
|
+
## Props
|
|
67
|
+
|
|
68
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
69
|
+
| --- | --- | --- | --- |
|
|
70
|
+
| icon | `string \| (...args) => VNodeChild` | `''` | 图标名(支持 `i-mdi-*` 与 `mdi:*` 两种协议);image/logo 模式下为资源路径 |
|
|
71
|
+
| type | `'iconify' \| 'image' \| 'logo'` | `'iconify'` | 渲染模式,image/logo 走 `<img>` 渲染 |
|
|
72
|
+
| size | `number \| string` | `1` | 尺寸,单位 rem |
|
|
73
|
+
|
|
74
|
+
其余属性(class、style、事件等)通过 `v-bind="$attrs"` 透传。
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { VNodeChild } from 'vue';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
icon?: string | ((...args: any[]) => VNodeChild);
|
|
4
|
+
type?: 'iconify' | 'image' | 'logo';
|
|
5
|
+
size?: number | string;
|
|
6
|
+
};
|
|
7
|
+
declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
8
|
+
icon: string | ((...args: any[]) => VNodeChild);
|
|
9
|
+
type: "iconify" | "image" | "logo";
|
|
10
|
+
size: string | number;
|
|
11
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import e from "./BaseIcon.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
import './BaseIcon.vue_vue_type_style_index_0_scoped_3f3679aa_lang.css';/* empty css */
|
|
3
|
+
import t from "../_virtual/_plugin-vue_export-helper.js";
|
|
4
|
+
//#region src/components/BaseIcon.vue
|
|
5
|
+
var n = /*#__PURE__*/ t(e, [["__scopeId", "data-v-3f3679aa"]]);
|
|
6
|
+
//#endregion
|
|
7
|
+
export { n as default };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Icon as e } from "@iconify/vue";
|
|
2
|
+
import { computed as t, createBlock as n, createElementBlock as r, defineComponent as i, mergeProps as a, openBlock as o, unref as s } from "vue";
|
|
3
|
+
//#region src/components/BaseIcon.vue?vue&type=script&setup=true&lang.ts
|
|
4
|
+
var c = ["src", "alt"], l = /*@__PURE__*/ i({
|
|
5
|
+
__name: "BaseIcon",
|
|
6
|
+
props: {
|
|
7
|
+
icon: {
|
|
8
|
+
type: [String, Function],
|
|
9
|
+
default: ""
|
|
10
|
+
},
|
|
11
|
+
type: { default: "iconify" },
|
|
12
|
+
size: { default: 1 }
|
|
13
|
+
},
|
|
14
|
+
setup(i) {
|
|
15
|
+
let l = i, u = t(() => {
|
|
16
|
+
let e = l.icon;
|
|
17
|
+
if (!e) return "";
|
|
18
|
+
if (e.startsWith("i-")) {
|
|
19
|
+
let t = e.slice(2).split("-");
|
|
20
|
+
return `${t.shift() ?? ""}:${t.join("-")}`;
|
|
21
|
+
}
|
|
22
|
+
return e;
|
|
23
|
+
}), d = t(() => l.type === "iconify" ? {
|
|
24
|
+
height: `${Number(l.size)}rem`,
|
|
25
|
+
width: `${Number(l.size)}rem`
|
|
26
|
+
} : {
|
|
27
|
+
height: `${l.size}rem`,
|
|
28
|
+
width: `${l.size}rem`,
|
|
29
|
+
"line-height": `${l.size}rem`,
|
|
30
|
+
"font-size": `${l.size}rem`
|
|
31
|
+
}), f = t(() => {
|
|
32
|
+
let e = l.icon;
|
|
33
|
+
return e.startsWith("/") ? e.replace("/", "") : "";
|
|
34
|
+
});
|
|
35
|
+
return (t, l) => i.type === "iconify" ? (o(), n(s(e), a({ key: 0 }, t.$attrs, {
|
|
36
|
+
icon: u.value,
|
|
37
|
+
style: d.value,
|
|
38
|
+
class: "base-icon inline-block vertical-sub"
|
|
39
|
+
}), null, 16, ["icon", "style"])) : (o(), r("img", a({ key: 1 }, t.$attrs, {
|
|
40
|
+
class: { logo: i.type === "logo" },
|
|
41
|
+
style: ["base-icon", d.value],
|
|
42
|
+
src: f.value,
|
|
43
|
+
alt: i.type
|
|
44
|
+
}), null, 16, c));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
//#endregion
|
|
48
|
+
export { l as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.base-icon.logo[data-v-3f3679aa]{cursor:pointer;transition:filter .5s}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IconifyJSON } from '@iconify/vue';
|
|
2
|
+
import { App, Plugin } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* BaseIcon 安装配置项
|
|
5
|
+
*/
|
|
6
|
+
export interface BaseIconOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 离线图标集合,传入后完全离线渲染,不再请求 iconify 在线 API
|
|
9
|
+
* 集合数据来自 @iconify-json/* 包,例如:
|
|
10
|
+
* import mdiIcons from '@iconify-json/mdi/icons.json'
|
|
11
|
+
*/
|
|
12
|
+
collections?: IconifyJSON[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 安装 BaseIcon:注册离线图标集合并全局注册组件
|
|
16
|
+
* 传入 collections 时注册离线图标集合
|
|
17
|
+
*/
|
|
18
|
+
declare const install: (app: App, options?: BaseIconOptions) => void;
|
|
19
|
+
declare const BaseIcon: {
|
|
20
|
+
new (...args: any[]): import('vue').CreateComponentPublicInstanceWithMixins<Readonly<{
|
|
21
|
+
icon?: string | ((...args: any[]) => import('vue').VNodeChild);
|
|
22
|
+
type?: "iconify" | "image" | "logo";
|
|
23
|
+
size?: number | string;
|
|
24
|
+
}> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {
|
|
25
|
+
icon: string | ((...args: any[]) => import('vue').VNodeChild);
|
|
26
|
+
type: "iconify" | "image" | "logo";
|
|
27
|
+
size: string | number;
|
|
28
|
+
}, false, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {}, any, import('vue').ComponentProvideOptions, {
|
|
29
|
+
P: {};
|
|
30
|
+
B: {};
|
|
31
|
+
D: {};
|
|
32
|
+
C: {};
|
|
33
|
+
M: {};
|
|
34
|
+
Defaults: {};
|
|
35
|
+
}, Readonly<{
|
|
36
|
+
icon?: string | ((...args: any[]) => import('vue').VNodeChild);
|
|
37
|
+
type?: "iconify" | "image" | "logo";
|
|
38
|
+
size?: number | string;
|
|
39
|
+
}> & Readonly<{}>, {}, {}, {}, {}, {
|
|
40
|
+
icon: string | ((...args: any[]) => import('vue').VNodeChild);
|
|
41
|
+
type: "iconify" | "image" | "logo";
|
|
42
|
+
size: string | number;
|
|
43
|
+
}>;
|
|
44
|
+
__isFragment?: never;
|
|
45
|
+
__isTeleport?: never;
|
|
46
|
+
__isSuspense?: never;
|
|
47
|
+
} & import('vue').ComponentOptionsBase<Readonly<{
|
|
48
|
+
icon?: string | ((...args: any[]) => import('vue').VNodeChild);
|
|
49
|
+
type?: "iconify" | "image" | "logo";
|
|
50
|
+
size?: number | string;
|
|
51
|
+
}> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, {
|
|
52
|
+
icon: string | ((...args: any[]) => import('vue').VNodeChild);
|
|
53
|
+
type: "iconify" | "image" | "logo";
|
|
54
|
+
size: string | number;
|
|
55
|
+
}, {}, string, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, import('vue').ComponentProvideOptions> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & Plugin;
|
|
56
|
+
export default BaseIcon;
|
|
57
|
+
export { BaseIcon, install };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import e from "./components/BaseIcon.js";
|
|
2
|
+
import { addCollection as t } from "@iconify/vue";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
var n = (n, r) => {
|
|
5
|
+
r?.collections?.forEach((e) => {
|
|
6
|
+
t(e);
|
|
7
|
+
}), n.component("BaseIcon", e);
|
|
8
|
+
}, r = ((e) => {
|
|
9
|
+
let t = e;
|
|
10
|
+
return t.install = n, t;
|
|
11
|
+
})(e);
|
|
12
|
+
//#endregion
|
|
13
|
+
export { r as BaseIcon, r as default, n as install };
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thelastcookies/base-icon",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "基于 @iconify/vue 的图标组件,兼容 i-mdi-* 类名协议,支持在线按需拉取与离线集合注入",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "thelastcookies",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"vue",
|
|
10
|
+
"vue3",
|
|
11
|
+
"icon",
|
|
12
|
+
"iconify",
|
|
13
|
+
"mdi",
|
|
14
|
+
"component"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/thelastcookies/npm-packages.git",
|
|
19
|
+
"directory": "base-icon"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/thelastcookies/npm-packages/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/thelastcookies/npm-packages/tree/master/base-icon#readme",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./base-icon": {
|
|
37
|
+
"types": "./dist/components/BaseIcon.d.ts",
|
|
38
|
+
"import": "./dist/components/BaseIcon.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "vite playground",
|
|
46
|
+
"build": "vite build",
|
|
47
|
+
"check": "vue-tsc --noEmit",
|
|
48
|
+
"prepublishOnly": "pnpm build",
|
|
49
|
+
"p": "npm version patch",
|
|
50
|
+
"m": "npm version minor",
|
|
51
|
+
"ma": "npm version major",
|
|
52
|
+
"release-dry": "npm publish --dry-run",
|
|
53
|
+
"release": "npm publish --access public"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@iconify/vue": "^5.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"vue": ">=3.5.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@iconify-json/mdi": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@iconify-json/mdi": "^1.2.3",
|
|
68
|
+
"@iconify/utils": "^3.1.7",
|
|
69
|
+
"@types/node": "^25.6.0",
|
|
70
|
+
"@vitejs/plugin-vue": "^6.0.6",
|
|
71
|
+
"typescript": "^6.0.3",
|
|
72
|
+
"vite": "8.1.6",
|
|
73
|
+
"vite-plugin-dts": "^5.1.2",
|
|
74
|
+
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
75
|
+
"vue": "^3.5.33",
|
|
76
|
+
"vue-tsc": "^3.2.7"
|
|
77
|
+
}
|
|
78
|
+
}
|