koishi-plugin-bilibili-notify 3.2.9-rc.0 → 3.2.9-rc.2
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/lib/index.js +220 -250
- package/lib/index.mjs +220 -250
- package/lib/static/render.js +107 -0
- package/package.json +2 -2
- package/readme.md +4 -5
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自动适配的词云渲染函数,直到填满画布
|
|
3
|
+
* @param {HTMLCanvasElement} canvas - canvas 元素
|
|
4
|
+
* @param {Array<[string, number]>} words - 词数组 [['哈哈', 20], ['666', 10]]
|
|
5
|
+
* @param {Object} options - 选项
|
|
6
|
+
*/
|
|
7
|
+
function renderAutoFitWordCloud(canvas, words, options = {}) {
|
|
8
|
+
const ctx = canvas.getContext("2d");
|
|
9
|
+
const style = getComputedStyle(canvas);
|
|
10
|
+
const cssWidth = parseInt(style.width);
|
|
11
|
+
const cssHeight = parseInt(style.height);
|
|
12
|
+
const ratio = window.devicePixelRatio || 1;
|
|
13
|
+
|
|
14
|
+
// 设置高清分辨率
|
|
15
|
+
canvas.width = cssWidth * ratio;
|
|
16
|
+
canvas.height = cssHeight * ratio;
|
|
17
|
+
ctx.scale(ratio, ratio);
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
fontFamily = 'sans-serif',
|
|
21
|
+
maxFontSize = 72,
|
|
22
|
+
minFontSize = 12,
|
|
23
|
+
densityTarget = 0.25,
|
|
24
|
+
weightExponent = 0.5,
|
|
25
|
+
rotationSteps = 2,
|
|
26
|
+
rotateRatio = 0.4,
|
|
27
|
+
color = () => ['#007CF0', '#00DFD8', '#7928CA', '#FF0080', '#FF4D4D', '#F9CB28'][Math.floor(Math.random() * 6)],
|
|
28
|
+
backgroundColor = 'transparent'
|
|
29
|
+
} = options;
|
|
30
|
+
|
|
31
|
+
const weightFactor = createDynamicWeightFactor(words, cssWidth, cssHeight, {
|
|
32
|
+
maxFontSize,
|
|
33
|
+
minFontSize,
|
|
34
|
+
densityTarget,
|
|
35
|
+
weightExponent
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
WordCloud(canvas, {
|
|
39
|
+
list: words,
|
|
40
|
+
gridSize: Math.max(2, Math.floor(cssWidth / 100)), // 自动调整 gridSize
|
|
41
|
+
weightFactor,
|
|
42
|
+
fontFamily,
|
|
43
|
+
color,
|
|
44
|
+
rotateRatio,
|
|
45
|
+
rotationSteps,
|
|
46
|
+
backgroundColor,
|
|
47
|
+
drawOutOfBound: false,
|
|
48
|
+
origin: [cssWidth / 2, cssHeight / 2],
|
|
49
|
+
width: cssWidth,
|
|
50
|
+
height: cssHeight,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* function createDynamicWeightFactor(words, width, height, {
|
|
55
|
+
maxFontSize = 72,
|
|
56
|
+
minFontSize = 12,
|
|
57
|
+
densityTarget = 0.25
|
|
58
|
+
} = {}) {
|
|
59
|
+
const weights = words.map(w => w[1]);
|
|
60
|
+
const maxWeight = Math.max(...weights);
|
|
61
|
+
const minWeight = Math.min(...weights);
|
|
62
|
+
const range = maxWeight - minWeight || 1;
|
|
63
|
+
|
|
64
|
+
// 移除基于词数的自动缩放
|
|
65
|
+
const realMax = maxFontSize;
|
|
66
|
+
const realMin = minFontSize;
|
|
67
|
+
|
|
68
|
+
// 改为基于画布面积的密度控制
|
|
69
|
+
const areaPerWord = (width * height * densityTarget) / words.length;
|
|
70
|
+
const sizeScale = Math.min(1, Math.sqrt(areaPerWord / 500)); // 500是可调基准值
|
|
71
|
+
|
|
72
|
+
return function weightFactor(weight) {
|
|
73
|
+
const norm = (weight - minWeight) / range;
|
|
74
|
+
// 应用三次方曲线让大小差异更明显
|
|
75
|
+
const sizeRatio = Math.pow(norm, 0.33);
|
|
76
|
+
return realMin + (realMax - realMin) * sizeRatio * sizeScale;
|
|
77
|
+
};
|
|
78
|
+
} */
|
|
79
|
+
|
|
80
|
+
function createDynamicWeightFactor(words, width, height, {
|
|
81
|
+
maxFontSize = 72,
|
|
82
|
+
minFontSize = 12,
|
|
83
|
+
densityTarget = 0.25,
|
|
84
|
+
weightExponent = 0.5 // 新增权重指数参数
|
|
85
|
+
} = {}) {
|
|
86
|
+
const weights = words.map(w => w[1]);
|
|
87
|
+
const maxWeight = Math.max(...weights);
|
|
88
|
+
const minWeight = Math.min(...weights);
|
|
89
|
+
const range = Math.max(1, maxWeight - minWeight); // 确保不为0
|
|
90
|
+
|
|
91
|
+
// 计算权重转换曲线
|
|
92
|
+
const weightCurve = (weight) => {
|
|
93
|
+
const normalized = (weight - minWeight) / range;
|
|
94
|
+
// 使用指数曲线放大差异
|
|
95
|
+
return Math.pow(normalized, weightExponent);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// 计算动态缩放比例(基于画布面积和词数)
|
|
99
|
+
const areaScale = Math.sqrt((width * height * densityTarget) / words.length) / 20;
|
|
100
|
+
const sizeScale = Math.min(1, Math.max(0.3, areaScale)); // 限制在0.3-1之间
|
|
101
|
+
|
|
102
|
+
return function (weight) {
|
|
103
|
+
const curveValue = weightCurve(weight);
|
|
104
|
+
// 应用非线性放大
|
|
105
|
+
return minFontSize + (maxFontSize - minFontSize) * curveValue * sizeScale;
|
|
106
|
+
};
|
|
107
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-bilibili-notify",
|
|
3
3
|
"description": "Koishi bilibili notify plugin",
|
|
4
|
-
"version": "3.2.9-rc.
|
|
4
|
+
"version": "3.2.9-rc.2",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Akokko <admin@akokko.com>"
|
|
7
7
|
],
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@akokko/blive-message-listener": "^0.5.1",
|
|
39
|
+
"@node-rs/jieba": "^2.0.1",
|
|
39
40
|
"@satorijs/element": "^3.1.8",
|
|
40
41
|
"axios": "^1.10.0",
|
|
41
42
|
"axios-cookiejar-support": "^6.0.2",
|
|
@@ -45,7 +46,6 @@
|
|
|
45
46
|
"luxon": "^3.6.1",
|
|
46
47
|
"md5": "^2.3.0",
|
|
47
48
|
"qrcode": "^1.5.4",
|
|
48
|
-
"segmentit": "^2.0.3",
|
|
49
49
|
"tough-cookie": "^5.1.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
package/readme.md
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
- koishi-plugin-bilibili-notify [](https://www.npmjs.com/package/koishi-plugin-bilibili-notify)
|
|
8
|
-
- [重要通知](#重要通知)
|
|
9
8
|
- [重新订阅](#重新订阅)
|
|
10
9
|
- [功能](#功能)
|
|
11
10
|
- [注意事项](#注意事项)
|
|
@@ -16,10 +15,6 @@
|
|
|
16
15
|
- [感谢](#感谢)
|
|
17
16
|
- [License](#License)
|
|
18
17
|
|
|
19
|
-
## 重要通知
|
|
20
|
-
> [!WARNING]
|
|
21
|
-
> `3.2.5-alpha.x` 目前均为测试版本,请不要更新🙅
|
|
22
|
-
|
|
23
18
|
## 重新订阅
|
|
24
19
|
> [!NOTE]
|
|
25
20
|
>由于版本 `2.0.0-alpha.7` 重构了订阅功能,从 `2.0.0-alpha.7` 以前版本升级到以后版本的需重新订阅
|
|
@@ -305,7 +300,11 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
305
300
|
> - ver 3.2.9-alpha.2 修复:`AxiosError: Request failed with status code 404 xxx at async BiliAPI.checkIfTokenNeedRefresh`、潜在cookie相关bug、弹幕词云bug `Error: 生成图片失败!错误: TimeoutError: Navigation timeout of 30000 ms exceeded`
|
|
306
301
|
> - ver 3.2.9-alpha.3 修复:词云生成空白
|
|
307
302
|
> - ver 3.2.9-alpha.4 修复:弹幕词云bug `Error: 生成图片失败!错误: TimeoutError: Navigation timeout of 30000 ms exceeded`
|
|
303
|
+
|
|
304
|
+
> [!NOTE]
|
|
308
305
|
> - ver 3.2.9-rc.0 优化:弹幕词云生成效果、选项 `pushTime` 设置为0时可关闭该功能; 新增:选项 `wordcloud` 可选择在直播结束后是否生成弹幕词云
|
|
306
|
+
> - ver 3.2.9-rc.1 优化:弹幕词云生成效果;
|
|
307
|
+
> - ver 3.2.9-rc.2 优化:弹幕词云生成效果;
|
|
309
308
|
|
|
310
309
|
## 交流群
|
|
311
310
|
|