@hlw-uni/mp-vue 2.1.11 → 2.1.12

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,7 @@
1
+ /**
2
+ * 算法集:把通用算法包成 useXxx composable,业务侧统一从这里取。
3
+ *
4
+ * 已有:
5
+ * - useUuid RFC 4122 v4,32 字符 hex
6
+ */
7
+ export { useUuid } from './uuid';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * UUID v4 生成器(RFC 4122 v4 算法),返回 32 字符 hex(无连字符)。
3
+ *
4
+ * 用途:当 nonce、idempotency key、临时唯一标识用。
5
+ *
6
+ * 算法:
7
+ * 1. 生成 16 字节随机源
8
+ * 2. byte 6 高 4 位置成 0100 标版本号 v4
9
+ * 3. byte 8 高 2 位置成 10 标变体(RFC 4122)
10
+ * 4. 16 字节转 hex 拼成 32 字符串
11
+ *
12
+ * 注意:随机源用 Math.random(小程序兼容兜底),加密强度有限,
13
+ * 不能用于密钥派生 / token 签发,只能挡重放。
14
+ */
15
+ export declare function useUuid(): {
16
+ v4: () => string;
17
+ };
@@ -16,6 +16,7 @@ export { useContact, setConfigContact, type ContactConfig, type ContactAdapter,
16
16
  export { useUtils, type DownloadFileOptions, type DownloadFileResult, type TapEvent } from './utils';
17
17
  export { useColor } from './color';
18
18
  export { useRouter, type NavigateType, type NavigateOptions } from './navigator';
19
+ export { useUuid } from './algo';
19
20
  export type { FontScale, FontPreset } from './theme';
20
21
  export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars, THEME_CHANGE_EVENT, buildThemeStyle, useThemePageStyle, } from './theme';
21
22
  export type { ThemeColor } from './theme';
package/dist/index.js CHANGED
@@ -1138,6 +1138,18 @@ var __publicField = (obj, key, value) => {
1138
1138
  navigate: doNavigate
1139
1139
  };
1140
1140
  }
1141
+ function useUuid() {
1142
+ function v4() {
1143
+ const bytes = [];
1144
+ for (let i = 0; i < 16; i++) {
1145
+ bytes.push(Math.floor(Math.random() * 256));
1146
+ }
1147
+ bytes[6] = bytes[6] & 15 | 64;
1148
+ bytes[8] = bytes[8] & 63 | 128;
1149
+ return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
1150
+ }
1151
+ return { v4 };
1152
+ }
1141
1153
  const useThemeStore = pinia.defineStore(
1142
1154
  "theme",
1143
1155
  () => {
@@ -1940,6 +1952,7 @@ var __publicField = (obj, key, value) => {
1940
1952
  exports2.useThemeStore = useThemeStore;
1941
1953
  exports2.useUpload = useUpload;
1942
1954
  exports2.useUtils = useUtils;
1955
+ exports2.useUuid = useUuid;
1943
1956
  exports2.useValidate = useValidate;
1944
1957
  exports2.vCopy = vCopy;
1945
1958
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
package/dist/index.mjs CHANGED
@@ -1137,6 +1137,18 @@ function useRouter() {
1137
1137
  navigate: doNavigate
1138
1138
  };
1139
1139
  }
1140
+ function useUuid() {
1141
+ function v4() {
1142
+ const bytes = [];
1143
+ for (let i = 0; i < 16; i++) {
1144
+ bytes.push(Math.floor(Math.random() * 256));
1145
+ }
1146
+ bytes[6] = bytes[6] & 15 | 64;
1147
+ bytes[8] = bytes[8] & 63 | 128;
1148
+ return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
1149
+ }
1150
+ return { v4 };
1151
+ }
1140
1152
  const useThemeStore = defineStore(
1141
1153
  "theme",
1142
1154
  () => {
@@ -1940,6 +1952,7 @@ export {
1940
1952
  useThemeStore,
1941
1953
  useUpload,
1942
1954
  useUtils,
1955
+ useUuid,
1943
1956
  useValidate,
1944
1957
  vCopy
1945
1958
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 算法集:把通用算法包成 useXxx composable,业务侧统一从这里取。
3
+ *
4
+ * 已有:
5
+ * - useUuid RFC 4122 v4,32 字符 hex
6
+ */
7
+ export { useUuid } from "./uuid";
@@ -0,0 +1,27 @@
1
+ /**
2
+ * UUID v4 生成器(RFC 4122 v4 算法),返回 32 字符 hex(无连字符)。
3
+ *
4
+ * 用途:当 nonce、idempotency key、临时唯一标识用。
5
+ *
6
+ * 算法:
7
+ * 1. 生成 16 字节随机源
8
+ * 2. byte 6 高 4 位置成 0100 标版本号 v4
9
+ * 3. byte 8 高 2 位置成 10 标变体(RFC 4122)
10
+ * 4. 16 字节转 hex 拼成 32 字符串
11
+ *
12
+ * 注意:随机源用 Math.random(小程序兼容兜底),加密强度有限,
13
+ * 不能用于密钥派生 / token 签发,只能挡重放。
14
+ */
15
+ export function useUuid() {
16
+ function v4(): string {
17
+ const bytes: number[] = [];
18
+ for (let i = 0; i < 16; i++) {
19
+ bytes.push(Math.floor(Math.random() * 256));
20
+ }
21
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
22
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
23
+ return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
24
+ }
25
+
26
+ return { v4 };
27
+ }
@@ -45,6 +45,7 @@ export {
45
45
  export { useUtils, type DownloadFileOptions, type DownloadFileResult, type TapEvent } from "./utils";
46
46
  export { useColor } from "./color";
47
47
  export { useRouter, type NavigateType, type NavigateOptions } from "./navigator";
48
+ export { useUuid } from "./algo";
48
49
 
49
50
  // Theme(mp-vue 自带)
50
51
  export type { FontScale, FontPreset } from "./theme";