feat(common): 添加工具

This commit is contained in:
2026-04-20 17:54:26 +08:00
parent 7ff223fa32
commit b10d613987
64 changed files with 8342 additions and 16243 deletions
-3
View File
@@ -1,3 +0,0 @@
import rootConfig from "../../eslint.config.js";
export default [...rootConfig];
+5 -4
View File
@@ -49,18 +49,19 @@
"release": "standard-version",
"commit": "cz",
"lint-staged": "lint-staged",
"test": "jest"
"test": "vitest run"
},
"dependencies": {
"dayjs": "^1.11.13",
"js-easing-functions": "^1.0.3",
"lodash-es": "^4.17.21",
"lodash-es": "catalog:",
"text-encoding": "^0.7.0"
},
"devDependencies": {
"@types/lodash": "^4.17.16",
"@types/lodash-es": "^4.17.12",
"@types/lodash-es": "catalog:",
"vite": "catalog:",
"vite-plugin-dts": "catalog:"
"vite-plugin-dts": "catalog:",
"vitest": "catalog:"
}
}
+1
View File
@@ -4,3 +4,4 @@ export * from "./printer";
export * from "./time";
export * from "./timer";
export * from "./input-rule";
export * from "./ui";
+47
View File
@@ -0,0 +1,47 @@
/*
* @file: /src/ui/function.ts
* @description: 缓动函数之类的,与框架无关,只做计算
* @author: tsl (randy1924@163.com)
* @date: 2026-03-19 11:50:59
* @lastModified: 2026-03-19 15:51:48
* @lastModifiedBy: tsl (randy1924@163.com)
*/
import { easeOutSine } from "js-easing-functions";
/**
* 缓慢滚动到结束值(使用缓动函数)
* @param start 滚动开始值,px
* @param end 滚动结束值,px
* @param duration 完成动画所需的时间,ms
* @param cb 回调函数,参数为当前值,px
*/
export async function slowlyScroll(
start: number,
end: number,
duration: number,
cb?: (value: number) => void,
): Promise<void> {
return new Promise<void>((resolve) => {
const startTime = Date.now();
const distance = end - start;
const intervalId = setInterval(() => {
const currentTime = Date.now();
const elapsed = currentTime - startTime;
// 使用 easeOutSine 缓动函数
// 参数:已过去时间、初始值、改变量、总持续时间
const currentValue = easeOutSine(elapsed, start, distance, duration);
cb?.(currentValue);
if (elapsed >= duration) {
// 清除定时器
clearInterval(intervalId);
// 确保最后一次调用使用准确的结束值
cb?.(end);
resolve();
}
}, 16); // 约60fps
});
}
+10
View File
@@ -0,0 +1,10 @@
/*
* @file: /src/ui/index.ts
* @description:
* @author: tsl (randy1924@163.com)
* @date: 2026-03-19 15:32:51
* @lastModified: 2026-03-19 15:46:00
* @lastModifiedBy: tsl (randy1924@163.com)
*/
export * from "./function";
+1 -1
View File
@@ -1,4 +1,4 @@
import { test, expect, describe } from "@jest/globals";
import { test, expect, describe } from "vitest";
import { getValueOfRule, InputOptions } from "../src/input-rule";
describe("getValueOfRule - 文本模式 (text: true)", () => {
+1 -1
View File
@@ -1,4 +1,4 @@
import { test, expect } from "@jest/globals";
import { test, expect } from "vitest";
import { Permission } from "../src/permission";
test("测试 Permission#isValid()", () => {
-1
View File
@@ -7,6 +7,5 @@
"paths": {
"@/*": ["src/*"]
},
"outDir": "./dist"
}
}
+12 -12
View File
@@ -1,31 +1,31 @@
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const __dirname = fileURLToPath(new URL(".", import.meta.url));
export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs'],
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
entry: resolve(__dirname, "src/index.ts"),
formats: ["es", "cjs"],
fileName: (format) => `index.${format === "es" ? "mjs" : "cjs"}`,
},
rollupOptions: {
external: ['dayjs', 'lodash-es', 'text-encoding', 'tslib'],
external: ["dayjs", "lodash-es", "text-encoding", "tslib"],
},
sourcemap: true,
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
"@": resolve(__dirname, "src"),
},
},
plugins: [
dts({
include: ['src'],
outDir: 'dist',
include: ["src"],
outDir: "dist",
}),
],
});