mp-taro-kit 0.0.3 → 0.0.4
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/README.md +2 -2
- package/dist/core/configure.cjs +75 -0
- package/dist/core/configure.d.ts +18 -0
- package/dist/core/configure.js +69 -0
- package/dist/core/faces.cjs +2 -0
- package/dist/core/faces.d.ts +42 -0
- package/dist/core/faces.js +1 -0
- package/dist/core/index.cjs +30 -0
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.js +5 -1
- package/dist/core/request.cjs +60 -0
- package/dist/core/request.d.ts +27 -0
- package/dist/core/request.js +51 -0
- package/dist/core/router.cjs +71 -0
- package/dist/core/router.d.ts +11 -0
- package/dist/core/router.js +63 -0
- package/dist/core/storage.cjs +63 -0
- package/dist/core/storage.d.ts +6 -0
- package/dist/core/storage.js +57 -0
- package/dist/core/weapp.cjs +37 -0
- package/dist/core/weapp.d.ts +7 -0
- package/dist/core/weapp.js +32 -0
- package/dist/design/tokens.css +59 -9
- package/dist/runtime/index.cjs +13 -0
- package/dist/runtime/index.d.ts +5 -1
- package/dist/runtime/index.js +6 -1
- package/dist/runtime/loading-slot.cjs +44 -0
- package/dist/runtime/loading-slot.d.ts +15 -0
- package/dist/runtime/loading-slot.js +41 -0
- package/dist/runtime/notify.cjs +52 -0
- package/dist/runtime/notify.d.ts +19 -0
- package/dist/runtime/notify.js +49 -0
- package/dist/runtime/overlay-stack.cjs +49 -0
- package/dist/runtime/overlay-stack.d.ts +17 -0
- package/dist/runtime/overlay-stack.js +46 -0
- package/dist/runtime/singleton.cjs +17 -0
- package/dist/runtime/singleton.d.ts +6 -0
- package/dist/runtime/singleton.js +14 -0
- package/dist/runtime/thenable.cjs +17 -0
- package/dist/runtime/thenable.d.ts +7 -0
- package/dist/runtime/thenable.js +13 -0
- package/dist/styles/tokens.css +59 -9
- package/dist/ui/actions/Button.cjs +32 -0
- package/dist/ui/actions/Button.d.ts +13 -0
- package/dist/ui/actions/Button.js +29 -0
- package/dist/ui/actions/index.cjs +5 -0
- package/dist/ui/actions/index.d.ts +1 -0
- package/dist/ui/actions/index.js +1 -0
- package/dist/ui/actions/style/index.css +22 -0
- package/dist/ui/commands.cjs +86 -0
- package/dist/ui/commands.d.ts +21 -0
- package/dist/ui/commands.js +73 -0
- package/dist/ui/display/Badge.cjs +10 -0
- package/dist/ui/display/Badge.d.ts +9 -0
- package/dist/ui/display/Badge.js +7 -0
- package/dist/ui/display/Divider.cjs +9 -0
- package/dist/ui/display/Divider.d.ts +5 -0
- package/dist/ui/display/Divider.js +6 -0
- package/dist/ui/display/index.cjs +7 -0
- package/dist/ui/display/index.d.ts +2 -0
- package/dist/ui/display/index.js +2 -0
- package/dist/ui/display/style/index.css +30 -0
- package/dist/ui/feedback/Dialog.cjs +12 -0
- package/dist/ui/feedback/Dialog.d.ts +15 -0
- package/dist/ui/feedback/Dialog.js +9 -0
- package/dist/ui/feedback/Loading.cjs +12 -0
- package/dist/ui/feedback/Loading.d.ts +7 -0
- package/dist/ui/feedback/Loading.js +9 -0
- package/dist/ui/feedback/Toast.cjs +12 -0
- package/dist/ui/feedback/Toast.d.ts +9 -0
- package/dist/ui/feedback/Toast.js +9 -0
- package/dist/ui/feedback/index.cjs +9 -0
- package/dist/ui/feedback/index.d.ts +3 -0
- package/dist/ui/feedback/index.js +3 -0
- package/dist/ui/feedback/style/index.css +67 -0
- package/dist/ui/index.cjs +15 -0
- package/dist/ui/index.d.ts +4 -1
- package/dist/ui/index.js +2 -1
- package/dist/ui/infra/OverlayHost.cjs +33 -0
- package/dist/ui/infra/OverlayHost.d.ts +8 -0
- package/dist/ui/infra/OverlayHost.js +30 -0
- package/dist/ui/infra/SafeArea.cjs +10 -0
- package/dist/ui/infra/SafeArea.d.ts +8 -0
- package/dist/ui/infra/SafeArea.js +7 -0
- package/dist/ui/infra/index.cjs +11 -0
- package/dist/ui/infra/index.d.ts +3 -0
- package/dist/ui/infra/index.js +3 -0
- package/dist/ui/infra/style/index.css +83 -0
- package/dist/ui/infra/use-store.cjs +17 -0
- package/dist/ui/infra/use-store.d.ts +8 -0
- package/dist/ui/infra/use-store.js +12 -0
- package/dist/ui/layout/Mask.cjs +12 -0
- package/dist/ui/layout/Mask.d.ts +7 -0
- package/dist/ui/layout/Mask.js +9 -0
- package/dist/ui/layout/Overlay.cjs +11 -0
- package/dist/ui/layout/Overlay.d.ts +8 -0
- package/dist/ui/layout/Overlay.js +8 -0
- package/dist/ui/layout/Popup.cjs +13 -0
- package/dist/ui/layout/Popup.d.ts +11 -0
- package/dist/ui/layout/Popup.js +10 -0
- package/dist/ui/layout/index.cjs +9 -0
- package/dist/ui/layout/index.d.ts +3 -0
- package/dist/ui/layout/index.js +3 -0
- package/dist/ui/layout/style/index.css +51 -0
- package/dist/ui/navigation/Drawer.cjs +12 -0
- package/dist/ui/navigation/Drawer.d.ts +11 -0
- package/dist/ui/navigation/Drawer.js +9 -0
- package/dist/ui/navigation/Dropdown.cjs +12 -0
- package/dist/ui/navigation/Dropdown.d.ts +9 -0
- package/dist/ui/navigation/Dropdown.js +9 -0
- package/dist/ui/navigation/index.cjs +7 -0
- package/dist/ui/navigation/index.d.ts +2 -0
- package/dist/ui/navigation/index.js +2 -0
- package/dist/ui/navigation/style/index.css +42 -0
- package/dist/ui/state.cjs +20 -0
- package/dist/ui/state.d.ts +25 -0
- package/dist/ui/state.js +17 -0
- package/dist/utils/date.cjs +98 -0
- package/dist/utils/date.d.ts +18 -0
- package/dist/utils/date.js +89 -0
- package/dist/utils/i18n.cjs +31 -0
- package/dist/utils/i18n.d.ts +11 -0
- package/dist/utils/i18n.js +25 -0
- package/dist/utils/index.cjs +28 -0
- package/dist/utils/index.d.ts +5 -1
- package/dist/utils/index.js +6 -1
- package/dist/utils/messages.zh.cjs +13 -0
- package/dist/utils/messages.zh.d.ts +1 -0
- package/dist/utils/messages.zh.js +10 -0
- package/dist/utils/number.cjs +38 -0
- package/dist/utils/number.d.ts +6 -0
- package/dist/utils/number.js +33 -0
- package/dist/utils/path.cjs +33 -0
- package/dist/utils/path.d.ts +8 -0
- package/dist/utils/path.js +27 -0
- package/dist/utils/string.cjs +55 -0
- package/dist/utils/string.d.ts +8 -0
- package/dist/utils/string.js +50 -0
- package/package.json +4 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeTrim = safeTrim;
|
|
4
|
+
exports.baseNameOf = baseNameOf;
|
|
5
|
+
exports.truncateBytes = truncateBytes;
|
|
6
|
+
/** 去首尾空白;非字符串(null / undefined / number)安全返回空串。 */
|
|
7
|
+
function safeTrim(value) {
|
|
8
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 路径取末段(`/` 与 `\` 都认)。先剔尾斜杠,否则目录 `b/` 会渲染成空标签。
|
|
12
|
+
*/
|
|
13
|
+
function baseNameOf(path) {
|
|
14
|
+
if (typeof path !== 'string')
|
|
15
|
+
return '';
|
|
16
|
+
const trimmed = path.replace(/[\\/]+$/, '');
|
|
17
|
+
if (trimmed === '')
|
|
18
|
+
return path;
|
|
19
|
+
const cut = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
20
|
+
return cut < 0 ? trimmed : trimmed.slice(cut + 1);
|
|
21
|
+
}
|
|
22
|
+
function utf8Size(codePoint) {
|
|
23
|
+
if (codePoint <= 0x7f)
|
|
24
|
+
return 1;
|
|
25
|
+
if (codePoint <= 0x7ff)
|
|
26
|
+
return 2;
|
|
27
|
+
if (codePoint <= 0xffff)
|
|
28
|
+
return 3;
|
|
29
|
+
return 4;
|
|
30
|
+
}
|
|
31
|
+
/** 按 UTF-8 字节截断(中文 3 字节、emoji 4 字节),不切半个码点。 */
|
|
32
|
+
// 自己按码点算字节,不依赖 TextEncoder —— 小程序运行时未必提供该全局。
|
|
33
|
+
function truncateBytes(text, maxBytes, suffix = '…') {
|
|
34
|
+
if (typeof text !== 'string' || !Number.isFinite(maxBytes) || maxBytes <= 0)
|
|
35
|
+
return '';
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (const ch of text)
|
|
38
|
+
total += utf8Size(ch.codePointAt(0) ?? 0);
|
|
39
|
+
if (total <= maxBytes)
|
|
40
|
+
return text;
|
|
41
|
+
let suffixBytes = 0;
|
|
42
|
+
for (const ch of suffix)
|
|
43
|
+
suffixBytes += utf8Size(ch.codePointAt(0) ?? 0);
|
|
44
|
+
const budget = maxBytes - suffixBytes;
|
|
45
|
+
let out = '';
|
|
46
|
+
let used = 0;
|
|
47
|
+
for (const ch of budget <= 0 ? suffix : text) {
|
|
48
|
+
const size = utf8Size(ch.codePointAt(0) ?? 0);
|
|
49
|
+
if (used + size > (budget <= 0 ? maxBytes : budget))
|
|
50
|
+
break;
|
|
51
|
+
used += size;
|
|
52
|
+
out += ch;
|
|
53
|
+
}
|
|
54
|
+
return budget <= 0 ? out : out + suffix;
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** 去首尾空白;非字符串(null / undefined / number)安全返回空串。 */
|
|
2
|
+
export declare function safeTrim(value: unknown): string;
|
|
3
|
+
/**
|
|
4
|
+
* 路径取末段(`/` 与 `\` 都认)。先剔尾斜杠,否则目录 `b/` 会渲染成空标签。
|
|
5
|
+
*/
|
|
6
|
+
export declare function baseNameOf(path: string): string;
|
|
7
|
+
/** 按 UTF-8 字节截断(中文 3 字节、emoji 4 字节),不切半个码点。 */
|
|
8
|
+
export declare function truncateBytes(text: string, maxBytes: number, suffix?: string): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** 去首尾空白;非字符串(null / undefined / number)安全返回空串。 */
|
|
2
|
+
export function safeTrim(value) {
|
|
3
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 路径取末段(`/` 与 `\` 都认)。先剔尾斜杠,否则目录 `b/` 会渲染成空标签。
|
|
7
|
+
*/
|
|
8
|
+
export function baseNameOf(path) {
|
|
9
|
+
if (typeof path !== 'string')
|
|
10
|
+
return '';
|
|
11
|
+
const trimmed = path.replace(/[\\/]+$/, '');
|
|
12
|
+
if (trimmed === '')
|
|
13
|
+
return path;
|
|
14
|
+
const cut = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
15
|
+
return cut < 0 ? trimmed : trimmed.slice(cut + 1);
|
|
16
|
+
}
|
|
17
|
+
function utf8Size(codePoint) {
|
|
18
|
+
if (codePoint <= 0x7f)
|
|
19
|
+
return 1;
|
|
20
|
+
if (codePoint <= 0x7ff)
|
|
21
|
+
return 2;
|
|
22
|
+
if (codePoint <= 0xffff)
|
|
23
|
+
return 3;
|
|
24
|
+
return 4;
|
|
25
|
+
}
|
|
26
|
+
/** 按 UTF-8 字节截断(中文 3 字节、emoji 4 字节),不切半个码点。 */
|
|
27
|
+
// 自己按码点算字节,不依赖 TextEncoder —— 小程序运行时未必提供该全局。
|
|
28
|
+
export function truncateBytes(text, maxBytes, suffix = '…') {
|
|
29
|
+
if (typeof text !== 'string' || !Number.isFinite(maxBytes) || maxBytes <= 0)
|
|
30
|
+
return '';
|
|
31
|
+
let total = 0;
|
|
32
|
+
for (const ch of text)
|
|
33
|
+
total += utf8Size(ch.codePointAt(0) ?? 0);
|
|
34
|
+
if (total <= maxBytes)
|
|
35
|
+
return text;
|
|
36
|
+
let suffixBytes = 0;
|
|
37
|
+
for (const ch of suffix)
|
|
38
|
+
suffixBytes += utf8Size(ch.codePointAt(0) ?? 0);
|
|
39
|
+
const budget = maxBytes - suffixBytes;
|
|
40
|
+
let out = '';
|
|
41
|
+
let used = 0;
|
|
42
|
+
for (const ch of budget <= 0 ? suffix : text) {
|
|
43
|
+
const size = utf8Size(ch.codePointAt(0) ?? 0);
|
|
44
|
+
if (used + size > (budget <= 0 ? maxBytes : budget))
|
|
45
|
+
break;
|
|
46
|
+
used += size;
|
|
47
|
+
out += ch;
|
|
48
|
+
}
|
|
49
|
+
return budget <= 0 ? out : out + suffix;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mp-taro-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "基于 Taro + React 的小程序基础库(kit):UI 容器能力与通用操作功能封装(占位发布,API 未定)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -70,12 +70,14 @@
|
|
|
70
70
|
"ui"
|
|
71
71
|
],
|
|
72
72
|
"devDependencies": {
|
|
73
|
+
"@tarojs/components": "^4.3.2",
|
|
74
|
+
"@types/react": "^18.3.31",
|
|
73
75
|
"sass": "^1.107.1",
|
|
74
76
|
"typescript": "^5.9.3"
|
|
75
77
|
},
|
|
76
78
|
"scripts": {
|
|
77
79
|
"build": "node scripts/build.mjs",
|
|
78
|
-
"test": "node scripts/check.mjs",
|
|
80
|
+
"test": "node scripts/check.mjs && node --test tests/*.test.mjs",
|
|
79
81
|
"guard": "node scripts/check.mjs --release"
|
|
80
82
|
}
|
|
81
83
|
}
|