@hlw-zbzs/gift 1.0.2 → 1.0.3

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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 平台标识集
3
+ */
4
+ type PlatformType = 'dy' | 'ks' | 'sph' | 'bili' | 'tk'
5
+
6
+ /**
7
+ * 平台信息项
8
+ */
9
+ interface PlatformInfo {
10
+ key: PlatformType
11
+ name: string
12
+ }
13
+
14
+ /**
15
+ * 礼物实体项
16
+ */
17
+ interface GiftItem {
18
+ /**
19
+ * 礼物自增号
20
+ */
21
+ id: number | string
22
+ /**
23
+ * 礼物展示名
24
+ */
25
+ name: string
26
+ /**
27
+ * 礼物价值数
28
+ */
29
+ price: number
30
+ /**
31
+ * 礼物图标串
32
+ */
33
+ url: string
34
+ /**
35
+ * 平台礼物号
36
+ */
37
+ giftId: string
38
+ /**
39
+ * 所属平台标
40
+ */
41
+ platform: string
42
+ }
43
+
44
+ /**
45
+ * 平台礼物表
46
+ */
47
+ declare const gifts: Record<PlatformType, GiftItem[]>;
48
+ /**
49
+ * 取平台礼物
50
+ * @param platform 平台标识符
51
+ * @returns 礼物列表项
52
+ */
53
+ declare function platGifts(platform: string): GiftItem[];
54
+ /**
55
+ * 查目标礼物
56
+ * @param query 查询内容项
57
+ * @param platform 平台标识符
58
+ * @returns 对应礼物项
59
+ */
60
+ declare function findGift(query: number | string, platform?: string): GiftItem | undefined;
61
+ /**
62
+ * 搜平台礼物
63
+ * @param keyword 检索关键词
64
+ * @param platform 平台标识符
65
+ * @returns 礼物列表项
66
+ */
67
+ declare function searchGifts(keyword: string, platform?: string): GiftItem[];
68
+ /**
69
+ * 获取礼物集
70
+ * @param platform 平台标识符
71
+ * @returns 礼物列表项
72
+ */
73
+ declare function getGifts(platform?: string): Promise<GiftItem[]>;
74
+
75
+ export { type GiftItem, type PlatformInfo, type PlatformType, findGift, getGifts, gifts, platGifts, searchGifts };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 平台标识集
3
+ */
4
+ type PlatformType = 'dy' | 'ks' | 'sph' | 'bili' | 'tk'
5
+
6
+ /**
7
+ * 平台信息项
8
+ */
9
+ interface PlatformInfo {
10
+ key: PlatformType
11
+ name: string
12
+ }
13
+
14
+ /**
15
+ * 礼物实体项
16
+ */
17
+ interface GiftItem {
18
+ /**
19
+ * 礼物自增号
20
+ */
21
+ id: number | string
22
+ /**
23
+ * 礼物展示名
24
+ */
25
+ name: string
26
+ /**
27
+ * 礼物价值数
28
+ */
29
+ price: number
30
+ /**
31
+ * 礼物图标串
32
+ */
33
+ url: string
34
+ /**
35
+ * 平台礼物号
36
+ */
37
+ giftId: string
38
+ /**
39
+ * 所属平台标
40
+ */
41
+ platform: string
42
+ }
43
+
44
+ /**
45
+ * 平台礼物表
46
+ */
47
+ declare const gifts: Record<PlatformType, GiftItem[]>;
48
+ /**
49
+ * 取平台礼物
50
+ * @param platform 平台标识符
51
+ * @returns 礼物列表项
52
+ */
53
+ declare function platGifts(platform: string): GiftItem[];
54
+ /**
55
+ * 查目标礼物
56
+ * @param query 查询内容项
57
+ * @param platform 平台标识符
58
+ * @returns 对应礼物项
59
+ */
60
+ declare function findGift(query: number | string, platform?: string): GiftItem | undefined;
61
+ /**
62
+ * 搜平台礼物
63
+ * @param keyword 检索关键词
64
+ * @param platform 平台标识符
65
+ * @returns 礼物列表项
66
+ */
67
+ declare function searchGifts(keyword: string, platform?: string): GiftItem[];
68
+ /**
69
+ * 获取礼物集
70
+ * @param platform 平台标识符
71
+ * @returns 礼物列表项
72
+ */
73
+ declare function getGifts(platform?: string): Promise<GiftItem[]>;
74
+
75
+ export { type GiftItem, type PlatformInfo, type PlatformType, findGift, getGifts, gifts, platGifts, searchGifts };
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ findGift: () => findGift,
23
+ getGifts: () => getGifts,
24
+ gifts: () => gifts,
25
+ platGifts: () => platGifts,
26
+ searchGifts: () => searchGifts
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/index.ts
31
+ var import_vue = require("@hlw-zbzs/vue");
32
+ var gifts = {
33
+ dy: [],
34
+ ks: [],
35
+ sph: [],
36
+ bili: [],
37
+ tk: []
38
+ };
39
+ function platGifts(platform) {
40
+ return gifts[platform] || [];
41
+ }
42
+ function findGift(query, platform = "dy") {
43
+ return platGifts(platform).find(
44
+ (item) => item.id === query || item.giftId === String(query) || item.name === query
45
+ );
46
+ }
47
+ function searchGifts(keyword, platform = "dy") {
48
+ if (!keyword) return platGifts(platform);
49
+ const kw = keyword.toLowerCase().trim();
50
+ return platGifts(platform).filter((item) => item.name.toLowerCase().includes(kw));
51
+ }
52
+ async function getGifts(platform) {
53
+ try {
54
+ const res = await (0, import_vue.get)("/plugin-base/api.v1.gift/index", platform ? { platform } : {});
55
+ const list = res.code === 1 && Array.isArray(res.data) ? res.data : [];
56
+ const items = list.map((item) => ({
57
+ id: item.id,
58
+ name: String(item.name || ""),
59
+ price: Number(item.price || 0),
60
+ url: String(item.url || ""),
61
+ giftId: String(item.gift_id ?? item.id ?? ""),
62
+ platform: String(item.platform || "")
63
+ }));
64
+ if (platform) {
65
+ const targetKey = platform;
66
+ if (gifts[targetKey]) {
67
+ gifts[targetKey] = items;
68
+ }
69
+ } else {
70
+ for (const currentKey of Object.keys(gifts)) {
71
+ gifts[currentKey] = items.filter((item) => item.platform === currentKey);
72
+ }
73
+ }
74
+ return items;
75
+ } catch (error) {
76
+ return platform ? platGifts(platform) : [];
77
+ }
78
+ }
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ findGift,
82
+ getGifts,
83
+ gifts,
84
+ platGifts,
85
+ searchGifts
86
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,56 @@
1
+ // src/index.ts
2
+ import { get } from "@hlw-zbzs/vue";
3
+ var gifts = {
4
+ dy: [],
5
+ ks: [],
6
+ sph: [],
7
+ bili: [],
8
+ tk: []
9
+ };
10
+ function platGifts(platform) {
11
+ return gifts[platform] || [];
12
+ }
13
+ function findGift(query, platform = "dy") {
14
+ return platGifts(platform).find(
15
+ (item) => item.id === query || item.giftId === String(query) || item.name === query
16
+ );
17
+ }
18
+ function searchGifts(keyword, platform = "dy") {
19
+ if (!keyword) return platGifts(platform);
20
+ const kw = keyword.toLowerCase().trim();
21
+ return platGifts(platform).filter((item) => item.name.toLowerCase().includes(kw));
22
+ }
23
+ async function getGifts(platform) {
24
+ try {
25
+ const res = await get("/plugin-base/api.v1.gift/index", platform ? { platform } : {});
26
+ const list = res.code === 1 && Array.isArray(res.data) ? res.data : [];
27
+ const items = list.map((item) => ({
28
+ id: item.id,
29
+ name: String(item.name || ""),
30
+ price: Number(item.price || 0),
31
+ url: String(item.url || ""),
32
+ giftId: String(item.gift_id ?? item.id ?? ""),
33
+ platform: String(item.platform || "")
34
+ }));
35
+ if (platform) {
36
+ const targetKey = platform;
37
+ if (gifts[targetKey]) {
38
+ gifts[targetKey] = items;
39
+ }
40
+ } else {
41
+ for (const currentKey of Object.keys(gifts)) {
42
+ gifts[currentKey] = items.filter((item) => item.platform === currentKey);
43
+ }
44
+ }
45
+ return items;
46
+ } catch (error) {
47
+ return platform ? platGifts(platform) : [];
48
+ }
49
+ }
50
+ export {
51
+ findGift,
52
+ getGifts,
53
+ gifts,
54
+ platGifts,
55
+ searchGifts
56
+ };
package/package.json CHANGED
@@ -1,60 +1,31 @@
1
1
  {
2
2
  "name": "@hlw-zbzs/gift",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Multi-Platform Live Stream Gift Data and Utilities (Douyin, Kuaishou, WeChat Channels, Bilibili, TikTok)",
5
- "main": "index.ts",
6
- "types": "index.ts",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
7
8
  "exports": {
8
9
  ".": {
9
- "types": "./index.ts",
10
- "import": "./index.ts",
11
- "require": "./index.ts",
12
- "default": "./index.ts"
13
- },
14
- "./dy": {
15
- "types": "./src/platforms/dy.ts",
16
- "import": "./src/platforms/dy.ts",
17
- "require": "./src/platforms/dy.ts",
18
- "default": "./src/platforms/dy.ts"
19
- },
20
- "./ks": {
21
- "types": "./src/platforms/ks.ts",
22
- "import": "./src/platforms/ks.ts",
23
- "require": "./src/platforms/ks.ts",
24
- "default": "./src/platforms/ks.ts"
25
- },
26
- "./sph": {
27
- "types": "./src/platforms/sph.ts",
28
- "import": "./src/platforms/sph.ts",
29
- "require": "./src/platforms/sph.ts",
30
- "default": "./src/platforms/sph.ts"
31
- },
32
- "./bili": {
33
- "types": "./src/platforms/bili.ts",
34
- "import": "./src/platforms/bili.ts",
35
- "require": "./src/platforms/bili.ts",
36
- "default": "./src/platforms/bili.ts"
37
- },
38
- "./tk": {
39
- "types": "./src/platforms/tk.ts",
40
- "import": "./src/platforms/tk.ts",
41
- "require": "./src/platforms/tk.ts",
42
- "default": "./src/platforms/tk.ts"
43
- },
44
- "./*": {
45
- "types": "./src/*.ts",
46
- "import": "./src/*.ts",
47
- "require": "./src/*.ts",
48
- "default": "./src/*.ts"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
49
14
  }
50
15
  },
51
16
  "files": [
52
- "index.ts",
53
- "src/"
17
+ "dist"
54
18
  ],
55
- "dependencies": {},
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "prepublishOnly": "pnpm build"
22
+ },
23
+ "dependencies": {
24
+ "@hlw-zbzs/vue": "workspace:*"
25
+ },
56
26
  "devDependencies": {
57
27
  "@types/node": "^22.14.1",
28
+ "tsup": "^8.5.1",
58
29
  "typescript": "^5.8.3"
59
30
  },
60
31
  "publishConfig": {
package/index.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * @file @hlw-zbzs/gift - 多平台直播礼物数据与查询工具包
3
- */
4
-
5
- export type * from './types'
6
- export * from './src/platforms'
7
- export * from './src/core'
package/src/core.ts DELETED
@@ -1,93 +0,0 @@
1
- /**
2
- * @file 礼物数据管理与查询工具模块
3
- */
4
-
5
- import type { PlatformType, GiftItem } from './types'
6
- import { PLATFORM_GIFTS } from './platforms'
7
-
8
- const giftMap = new Map<PlatformType, Map<string | number, GiftItem>>()
9
- const nameMap = new Map<PlatformType, Map<string, GiftItem>>()
10
-
11
- function initStore() {
12
- for (const [platform, gifts] of Object.entries(PLATFORM_GIFTS)) {
13
- const pKey = platform as PlatformType
14
- const idLookup = new Map<string | number, GiftItem>()
15
- const nameLookup = new Map<string, GiftItem>()
16
-
17
- for (const gift of gifts) {
18
- idLookup.set(gift.id, gift)
19
- idLookup.set(String(gift.id), gift)
20
- nameLookup.set(gift.name, gift)
21
- }
22
-
23
- giftMap.set(pKey, idLookup)
24
- nameMap.set(pKey, nameLookup)
25
- }
26
- }
27
-
28
- initStore()
29
-
30
- /**
31
- * 获取指定平台的礼物列表
32
- */
33
- export function getGifts(platform: PlatformType = 'dy'): GiftItem[] {
34
- return PLATFORM_GIFTS[platform] || []
35
- }
36
-
37
- /**
38
- * 根据 ID 查询礼物
39
- */
40
- export function getById(id: number | string, platform: PlatformType = 'dy'): GiftItem | undefined {
41
- const map = giftMap.get(platform)
42
- return map?.get(id) || map?.get(String(id))
43
- }
44
-
45
- /**
46
- * 根据礼物名称查询礼物
47
- */
48
- export function getByName(name: string, platform: PlatformType = 'dy'): GiftItem | undefined {
49
- const map = nameMap.get(platform)
50
- return map?.get(name)
51
- }
52
-
53
- /**
54
- * 智能查找礼物 (优先ID,其次名称)
55
- */
56
- export function findGift(query: number | string, platform: PlatformType = 'dy'): GiftItem | undefined {
57
- if (query === undefined || query === null || query === '') return undefined
58
- const map = giftMap.get(platform)
59
- const byId = map?.get(query) || map?.get(String(query))
60
- if (byId) return byId
61
- if (typeof query === 'string') {
62
- return nameMap.get(platform)?.get(query)
63
- }
64
- return undefined
65
- }
66
-
67
- /**
68
- * 关键字搜索礼物列表
69
- */
70
- export function searchGifts(keyword: string, platform: PlatformType = 'dy'): GiftItem[] {
71
- if (!keyword) return getGifts(platform)
72
- const kw = keyword.toLowerCase().trim()
73
- const gifts = getGifts(platform)
74
- return gifts.filter((item) => item.name.toLowerCase().includes(kw))
75
- }
76
-
77
- /**
78
- * 动态注册或覆盖平台礼物数据
79
- */
80
- export function setGifts(platform: PlatformType, gifts: GiftItem[]): void {
81
- PLATFORM_GIFTS[platform] = gifts
82
- const idLookup = new Map<string | number, GiftItem>()
83
- const nameLookup = new Map<string, GiftItem>()
84
-
85
- for (const gift of gifts) {
86
- idLookup.set(gift.id, gift)
87
- idLookup.set(String(gift.id), gift)
88
- nameLookup.set(gift.name, gift)
89
- }
90
-
91
- giftMap.set(platform, idLookup)
92
- nameMap.set(platform, nameLookup)
93
- }
@@ -1,62 +0,0 @@
1
- [
2
- {
3
- "id": 31036,
4
- "name": "小花花",
5
- "price": 1,
6
- "image": "https://s1.hdslb.com/bfs/live/8b40d0470890e7d573995383af8a8ae074d485d9.png"
7
- },
8
- {
9
- "id": 31164,
10
- "name": "粉丝团灯牌",
11
- "price": 1,
12
- "image": "https://s1.hdslb.com/bfs/live/e051dfd4557678f8edcac4993ed00a0935cbd9cc.png"
13
- },
14
- {
15
- "id": 1,
16
- "name": "辣条",
17
- "price": 1,
18
- "image": "https://s1.hdslb.com/bfs/live/8b40d0470890e7d573995383af8a8ae074d485d9.png"
19
- },
20
- {
21
- "id": 34315,
22
- "name": "喜欢你",
23
- "price": 99,
24
- "image": "https://s1.hdslb.com/bfs/live/5d940270c22a17fa2ff17a0713b4383b6febd945.png"
25
- },
26
- {
27
- "id": 31122,
28
- "name": "星愿水晶球",
29
- "price": 1000,
30
- "image": "https://s1.hdslb.com/bfs/live/288536798081e855e8f645bed6a2d2d27f411ee5.png"
31
- },
32
- {
33
- "id": 10003,
34
- "name": "舰长",
35
- "price": 1980,
36
- "image": "https://i0.hdslb.com/bfs/activity-plat/static/20220125/7f8dc1e417a6c1d6a509a66770dc060e/ohMHzbhJdN.png"
37
- },
38
- {
39
- "id": 35566,
40
- "name": "落日飞车",
41
- "price": 2000,
42
- "image": "https://s1.hdslb.com/bfs/live/93939d794de3e967b8564dc46487097124a192a0.png"
43
- },
44
- {
45
- "id": 34998,
46
- "name": "小电视飞船",
47
- "price": 29990,
48
- "image": "https://s1.hdslb.com/bfs/live/48884b1b1d3bf9df185f43ff6651748040faf5de.png"
49
- },
50
- {
51
- "id": 10002,
52
- "name": "提督",
53
- "price": 19980,
54
- "image": "https://i0.hdslb.com/bfs/activity-plat/static/20220125/7f8dc1e417a6c1d6a509a66770dc060e/ohMHzbhJdN.png"
55
- },
56
- {
57
- "id": 10001,
58
- "name": "总督",
59
- "price": 199980,
60
- "image": "https://i0.hdslb.com/bfs/activity-plat/static/20220125/7f8dc1e417a6c1d6a509a66770dc060e/ohMHzbhJdN.png"
61
- }
62
- ]