@chiyou/minigame-framework 1.2.69 → 1.3.1

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.
Files changed (27) hide show
  1. package/package.json +1 -1
  2. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.ts +28 -2
  3. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.ts +8 -1
  4. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.ts +28 -2
  5. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.ts +31 -5
  6. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.ts +34 -1
  7. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.ts +28 -2
  8. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.ts +17 -2
  9. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.ts +31 -5
  10. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.ts +32 -4
  11. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.ts +28 -2
  12. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.ts +31 -5
  13. package/src/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.ts +31 -5
  14. package/src/Framework/Definition/EventDefinition.ts +7 -0
  15. package/src/Framework/Definition/SystemDefinition.ts +12 -1
  16. package/src/Framework/Definition/TimerDefinition.ts +9 -0
  17. package/src/Framework/Definition/UIDefinition.ts +6 -0
  18. package/src/Framework/Manager/AudioMgr.ts +56 -7
  19. package/src/Framework/Manager/EventMgr.ts +31 -0
  20. package/src/Framework/Manager/InputMgr.ts +61 -0
  21. package/src/Framework/Manager/NodePoolMgr.ts +83 -4
  22. package/src/Framework/Manager/ResMgr.ts +41 -2
  23. package/src/Framework/Manager/TimerMgr.ts +53 -3
  24. package/src/Framework/Manager/UIMgr.ts +89 -9
  25. package/src/Framework/Utils/LogUtils.ts +27 -0
  26. package/src/Framework/Utils/ObjectUtils.ts +111 -0
  27. package/src/index.ts +2 -0
@@ -23,4 +23,115 @@ export class ObjectUtils {
23
23
 
24
24
  return keysA.every(key => ObjectUtils.deepEqual(a[key], b[key]));
25
25
  }
26
+
27
+ // ======================== Base64 编解码 ========================
28
+
29
+ private static readonly BASE64_CHARS: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
30
+
31
+ /**
32
+ * 将字符串转为 UTF-8 字节数组
33
+ */
34
+ private static utf8ToBytes(str: string): number[] {
35
+ const bytes: number[] = [];
36
+ for (let i = 0; i < str.length; i++) {
37
+ const code = str.charCodeAt(i);
38
+ if (code < 0x80) {
39
+ bytes.push(code);
40
+ } else if (code < 0x800) {
41
+ bytes.push(0xC0 | (code >> 6));
42
+ bytes.push(0x80 | (code & 0x3F));
43
+ } else if (code >= 0xD800 && code <= 0xDBFF) {
44
+ // 代理对(emoji 等)
45
+ const hi = code;
46
+ const lo = str.charCodeAt(++i);
47
+ const codePoint = ((hi - 0xD800) << 10) + (lo - 0xDC00) + 0x10000;
48
+ bytes.push(0xF0 | (codePoint >> 18));
49
+ bytes.push(0x80 | ((codePoint >> 12) & 0x3F));
50
+ bytes.push(0x80 | ((codePoint >> 6) & 0x3F));
51
+ bytes.push(0x80 | (codePoint & 0x3F));
52
+ } else {
53
+ bytes.push(0xE0 | (code >> 12));
54
+ bytes.push(0x80 | ((code >> 6) & 0x3F));
55
+ bytes.push(0x80 | (code & 0x3F));
56
+ }
57
+ }
58
+ return bytes;
59
+ }
60
+
61
+ /**
62
+ * 将 UTF-8 字节数组转为字符串
63
+ */
64
+ private static utf8FromBytes(bytes: number[]): string {
65
+ let result = "";
66
+ let i = 0;
67
+ while (i < bytes.length) {
68
+ const b1 = bytes[i++];
69
+ if (b1 < 0x80) {
70
+ result += String.fromCharCode(b1);
71
+ } else if (b1 < 0xE0) {
72
+ const b2 = bytes[i++];
73
+ result += String.fromCharCode(((b1 & 0x1F) << 6) | (b2 & 0x3F));
74
+ } else if (b1 < 0xF0) {
75
+ const b2 = bytes[i++];
76
+ const b3 = bytes[i++];
77
+ result += String.fromCharCode(((b1 & 0x0F) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F));
78
+ } else {
79
+ const b2 = bytes[i++];
80
+ const b3 = bytes[i++];
81
+ const b4 = bytes[i++];
82
+ const codePoint = ((b1 & 0x07) << 18) | ((b2 & 0x3F) << 12) | ((b3 & 0x3F) << 6) | (b4 & 0x3F);
83
+ // 转为代理对
84
+ const offset = codePoint - 0x10000;
85
+ result += String.fromCharCode(0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF));
86
+ }
87
+ }
88
+ return result;
89
+ }
90
+
91
+ /**
92
+ * Base64 编码(纯 JS 实现,兼容所有小游戏/快应用平台,支持中文和 emoji)
93
+ * @param str 要编码的字符串
94
+ * @returns Base64 编码后的字符串
95
+ */
96
+ public static base64Encode(str: string): string {
97
+ const bytes = ObjectUtils.utf8ToBytes(str);
98
+ const chars = ObjectUtils.BASE64_CHARS;
99
+ let result = "";
100
+ for (let i = 0; i < bytes.length; i += 3) {
101
+ const a = bytes[i];
102
+ const b = i + 1 < bytes.length ? bytes[i + 1] : 0;
103
+ const c = i + 2 < bytes.length ? bytes[i + 2] : 0;
104
+ result += chars[(a >> 2) & 0x3F];
105
+ result += chars[((a << 4) | (b >> 4)) & 0x3F];
106
+ result += i + 1 < bytes.length ? chars[((b << 2) | (c >> 6)) & 0x3F] : "=";
107
+ result += i + 2 < bytes.length ? chars[c & 0x3F] : "=";
108
+ }
109
+ return result;
110
+ }
111
+
112
+ /**
113
+ * Base64 解码(纯 JS 实现,兼容所有小游戏/快应用平台,支持中文和 emoji)
114
+ * @param str Base64 编码的字符串
115
+ * @returns 解码后的原始字符串
116
+ */
117
+ public static base64Decode(str: string): string {
118
+ const chars = ObjectUtils.BASE64_CHARS;
119
+ const bytes: number[] = [];
120
+ // 去除空白字符
121
+ str = str.replace(/\s/g, "");
122
+ for (let i = 0; i < str.length; i += 4) {
123
+ const a = chars.indexOf(str[i]);
124
+ const b = chars.indexOf(str[i + 1]);
125
+ const c = str[i + 2] === "=" ? 0 : chars.indexOf(str[i + 2]);
126
+ const d = str[i + 3] === "=" ? 0 : chars.indexOf(str[i + 3]);
127
+ bytes.push((a << 2) | (b >> 4));
128
+ if (str[i + 2] !== "=") {
129
+ bytes.push(((b & 0xF) << 4) | (c >> 2));
130
+ }
131
+ if (str[i + 3] !== "=") {
132
+ bytes.push(((c & 0x3) << 6) | d);
133
+ }
134
+ }
135
+ return ObjectUtils.utf8FromBytes(bytes);
136
+ }
26
137
  }
package/src/index.ts CHANGED
@@ -52,4 +52,6 @@ export * from './Framework/Definition/PrivacyDefinition';
52
52
  export * from './Framework/Definition/SocialDefinition';
53
53
  export * from './Framework/Definition/FwkErrorDefinition';
54
54
  export * from './Framework/Definition/UIDefinition';
55
+ export * from './Framework/Definition/EventDefinition';
56
+ export * from './Framework/Definition/TimerDefinition';
55
57
  export * from './Framework/Definition/FrameworkBase';