@maoyugames/phaser-framework 1.0.0
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/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/BasePlatform-BCOkvvDW.d.ts +47 -0
- package/dist/chunk-H5CUVYCN.js +229 -0
- package/dist/chunk-II3JM4R3.js +9 -0
- package/dist/chunk-PKBMQBKP.js +5 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +1219 -0
- package/dist/index.d.ts +1778 -0
- package/dist/index.js +3790 -0
- package/dist/platform/capacitor.d.ts +34 -0
- package/dist/platform/capacitor.js +145 -0
- package/dist/platform/facebook.d.ts +33 -0
- package/dist/platform/facebook.js +256 -0
- package/dist/platform/tiktok.d.ts +30 -0
- package/dist/platform/tiktok.js +170 -0
- package/dist/platform/web.d.ts +22 -0
- package/dist/platform/web.js +67 -0
- package/dist/platform/wechat.d.ts +37 -0
- package/dist/platform/wechat.js +436 -0
- package/dist/types-DtcRFbM0.d.ts +239 -0
- package/global.d.ts +8 -0
- package/package.json +83 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { BasePlatform } from '../chunk-H5CUVYCN.js';
|
|
2
|
+
import { __publicField } from '../chunk-PKBMQBKP.js';
|
|
3
|
+
|
|
4
|
+
// src/platform/impl/web/WebPlatform.ts
|
|
5
|
+
var WebDevice = class {
|
|
6
|
+
vibrateShort() {
|
|
7
|
+
try {
|
|
8
|
+
navigator.vibrate?.(15);
|
|
9
|
+
} catch {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
vibrateLong() {
|
|
13
|
+
try {
|
|
14
|
+
navigator.vibrate?.(400);
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async setClipboard(text) {
|
|
19
|
+
if (navigator.clipboard?.writeText) {
|
|
20
|
+
await navigator.clipboard.writeText(text);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
fallbackCopy(text);
|
|
24
|
+
}
|
|
25
|
+
async getClipboard() {
|
|
26
|
+
if (navigator.clipboard?.readText) {
|
|
27
|
+
return navigator.clipboard.readText();
|
|
28
|
+
}
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
async share(payload) {
|
|
32
|
+
const navAny = navigator;
|
|
33
|
+
if (navAny.share) {
|
|
34
|
+
const url = typeof location !== "undefined" ? location.href + (payload.query ? `?${payload.query}` : "") : payload.imageUrl;
|
|
35
|
+
await navAny.share({ title: payload.title, url });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function fallbackCopy(text) {
|
|
41
|
+
try {
|
|
42
|
+
const ta = document.createElement("textarea");
|
|
43
|
+
ta.value = text;
|
|
44
|
+
ta.style.position = "fixed";
|
|
45
|
+
ta.style.opacity = "0";
|
|
46
|
+
document.body.appendChild(ta);
|
|
47
|
+
ta.select();
|
|
48
|
+
document.execCommand("copy");
|
|
49
|
+
document.body.removeChild(ta);
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var WebPlatform = class extends BasePlatform {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
__publicField(this, "platformName", "web");
|
|
57
|
+
__publicField(this, "isMiniGame", false);
|
|
58
|
+
// 仅提供设备能力;auth/ads/payment 在浏览器无统一实现,保持 undefined
|
|
59
|
+
__publicField(this, "device", new WebDevice());
|
|
60
|
+
}
|
|
61
|
+
async init() {
|
|
62
|
+
this.readDomSystemInfo();
|
|
63
|
+
this.readDomLaunchOptions();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { WebPlatform };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { d as IPlatform, j as IPlatformNet, m as IPlatformStorage, i as IPlatformLifecycle, g as IPlatformAuth, e as IPlatformAds, k as IPlatformPayment, h as IPlatformDevice, P as PlatformInfo, L as LaunchOptions } from '../types-DtcRFbM0.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 微信小游戏平台适配器。
|
|
5
|
+
*
|
|
6
|
+
* - hasDOM=false(JSCore/V8 运行时,无 window/document/localStorage)
|
|
7
|
+
* - 全程使用 wx.* API,绝不触碰 document / localStorage / 浏览器 WebSocket / fetch
|
|
8
|
+
* - net.request:wx.request(回调包成 Promise;statusCode→status、header→headers)
|
|
9
|
+
* - createSocket:wx.connectSocket 返回 SocketTask,包成 IPlatformSocket
|
|
10
|
+
* - storage:wx.setStorageSync / getStorageSync / removeStorageSync / clearStorageSync
|
|
11
|
+
* - lifecycle:wx.onShow / wx.onHide
|
|
12
|
+
* - systemInfo:wx.getSystemInfoSync + wx.getWindowInfo(安全区 safeArea)
|
|
13
|
+
* - auth:wx.login;ads:激励/插屏;payment:wx.requestMidasPayment;device:震动/剪贴板/分享
|
|
14
|
+
*
|
|
15
|
+
* 所有调用前判断 `typeof wx !== 'undefined'`,缺失抛 PlatformUnsupportedError。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare class WeChatPlatform implements IPlatform {
|
|
19
|
+
private readonly _name;
|
|
20
|
+
private readonly _isMiniGame;
|
|
21
|
+
private readonly _hasDOM;
|
|
22
|
+
private _safeArea;
|
|
23
|
+
private _system;
|
|
24
|
+
private _launchOptions;
|
|
25
|
+
readonly net: IPlatformNet;
|
|
26
|
+
readonly storage: IPlatformStorage;
|
|
27
|
+
readonly lifecycle: IPlatformLifecycle;
|
|
28
|
+
readonly auth: IPlatformAuth;
|
|
29
|
+
readonly ads: IPlatformAds;
|
|
30
|
+
readonly payment: IPlatformPayment;
|
|
31
|
+
readonly device: IPlatformDevice;
|
|
32
|
+
get info(): PlatformInfo;
|
|
33
|
+
init(): Promise<void>;
|
|
34
|
+
getLaunchOptions(): LaunchOptions;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { WeChatPlatform };
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { PlatformUnsupportedError } from '../chunk-II3JM4R3.js';
|
|
2
|
+
import { __publicField } from '../chunk-PKBMQBKP.js';
|
|
3
|
+
|
|
4
|
+
// src/platform/impl/wechat/WeChatPlatform.ts
|
|
5
|
+
function hasWx() {
|
|
6
|
+
return typeof wx !== "undefined";
|
|
7
|
+
}
|
|
8
|
+
function requireWx(capability) {
|
|
9
|
+
if (!hasWx()) throw new PlatformUnsupportedError("wechat", capability);
|
|
10
|
+
}
|
|
11
|
+
var WxSocket = class {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
__publicField(this, "task");
|
|
14
|
+
__publicField(this, "_readyState", 0);
|
|
15
|
+
// 0 connecting,1 open,2 closing,3 closed
|
|
16
|
+
// 各事件的回调集合:外部通过 onXxx 注册,Unsubscribe 从对应集合删除
|
|
17
|
+
__publicField(this, "openHandlers", /* @__PURE__ */ new Set());
|
|
18
|
+
__publicField(this, "messageHandlers", /* @__PURE__ */ new Set());
|
|
19
|
+
__publicField(this, "errorHandlers", /* @__PURE__ */ new Set());
|
|
20
|
+
__publicField(this, "closeHandlers", /* @__PURE__ */ new Set());
|
|
21
|
+
this.task = wx.connectSocket({
|
|
22
|
+
url: options.url,
|
|
23
|
+
protocols: options.protocols,
|
|
24
|
+
header: options.headers
|
|
25
|
+
});
|
|
26
|
+
this.task.onOpen(() => {
|
|
27
|
+
this._readyState = 1;
|
|
28
|
+
for (const cb of Array.from(this.openHandlers)) cb();
|
|
29
|
+
});
|
|
30
|
+
this.task.onMessage((res) => {
|
|
31
|
+
for (const cb of Array.from(this.messageHandlers)) cb(res.data);
|
|
32
|
+
});
|
|
33
|
+
this.task.onError((res) => {
|
|
34
|
+
const err = new Error(res.errMsg ?? "wx socket error");
|
|
35
|
+
for (const cb of Array.from(this.errorHandlers)) cb(err);
|
|
36
|
+
});
|
|
37
|
+
this.task.onClose((res) => {
|
|
38
|
+
this._readyState = 3;
|
|
39
|
+
const info = { code: res.code ?? 1e3, reason: res.reason ?? "" };
|
|
40
|
+
for (const cb of Array.from(this.closeHandlers)) cb(info);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
get readyState() {
|
|
44
|
+
return this.task.readyState ?? this._readyState;
|
|
45
|
+
}
|
|
46
|
+
send(data) {
|
|
47
|
+
this.task.send({ data });
|
|
48
|
+
}
|
|
49
|
+
close(code, reason) {
|
|
50
|
+
this._readyState = 2;
|
|
51
|
+
this.task.close({ code, reason });
|
|
52
|
+
this.openHandlers.clear();
|
|
53
|
+
this.messageHandlers.clear();
|
|
54
|
+
this.errorHandlers.clear();
|
|
55
|
+
this.closeHandlers.clear();
|
|
56
|
+
}
|
|
57
|
+
onOpen(cb) {
|
|
58
|
+
this.openHandlers.add(cb);
|
|
59
|
+
return () => this.openHandlers.delete(cb);
|
|
60
|
+
}
|
|
61
|
+
onMessage(cb) {
|
|
62
|
+
this.messageHandlers.add(cb);
|
|
63
|
+
return () => this.messageHandlers.delete(cb);
|
|
64
|
+
}
|
|
65
|
+
onError(cb) {
|
|
66
|
+
this.errorHandlers.add(cb);
|
|
67
|
+
return () => this.errorHandlers.delete(cb);
|
|
68
|
+
}
|
|
69
|
+
onClose(cb) {
|
|
70
|
+
this.closeHandlers.add(cb);
|
|
71
|
+
return () => this.closeHandlers.delete(cb);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var WxNet = class {
|
|
75
|
+
request(options) {
|
|
76
|
+
requireWx("net.request");
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const responseType = options.responseType ?? "json";
|
|
79
|
+
const wxResponseType = responseType === "arraybuffer" ? "arraybuffer" : "text";
|
|
80
|
+
const wxDataType = responseType === "json" ? "json" : "string";
|
|
81
|
+
let aborted = false;
|
|
82
|
+
const task = wx.request({
|
|
83
|
+
url: options.url,
|
|
84
|
+
method: options.method ?? "GET",
|
|
85
|
+
data: serializeBody(options.body),
|
|
86
|
+
header: options.headers,
|
|
87
|
+
responseType: wxResponseType,
|
|
88
|
+
dataType: wxDataType,
|
|
89
|
+
timeout: options.timeout,
|
|
90
|
+
success: (res) => {
|
|
91
|
+
if (aborted) return;
|
|
92
|
+
const headers = normalizeHeaders(res.header);
|
|
93
|
+
resolve({
|
|
94
|
+
status: res.statusCode,
|
|
95
|
+
ok: res.statusCode >= 200 && res.statusCode < 300,
|
|
96
|
+
headers,
|
|
97
|
+
data: res.data
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
fail: (err) => {
|
|
101
|
+
if (aborted) return;
|
|
102
|
+
reject(new Error(err.errMsg ?? "wx.request \u5931\u8D25"));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (options.signal) {
|
|
106
|
+
if (options.signal.aborted) {
|
|
107
|
+
aborted = true;
|
|
108
|
+
task.abort();
|
|
109
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
options.signal.addEventListener(
|
|
113
|
+
"abort",
|
|
114
|
+
() => {
|
|
115
|
+
aborted = true;
|
|
116
|
+
task.abort();
|
|
117
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
118
|
+
},
|
|
119
|
+
{ once: true }
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
createSocket(options) {
|
|
125
|
+
requireWx("net.createSocket");
|
|
126
|
+
return new WxSocket(options);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function serializeBody(body) {
|
|
130
|
+
return body;
|
|
131
|
+
}
|
|
132
|
+
function normalizeHeaders(header) {
|
|
133
|
+
return header ? { ...header } : {};
|
|
134
|
+
}
|
|
135
|
+
var WxStorage = class {
|
|
136
|
+
getItem(key) {
|
|
137
|
+
try {
|
|
138
|
+
const v = wx.getStorageSync(key);
|
|
139
|
+
return v === "" || v === void 0 || v === null ? null : v;
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
setItem(key, value) {
|
|
145
|
+
try {
|
|
146
|
+
wx.setStorageSync(key, value);
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
removeItem(key) {
|
|
151
|
+
try {
|
|
152
|
+
wx.removeStorageSync(key);
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
clear() {
|
|
157
|
+
try {
|
|
158
|
+
wx.clearStorageSync();
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var WxLifecycle = class {
|
|
164
|
+
onShow(cb) {
|
|
165
|
+
const handler = (res) => {
|
|
166
|
+
cb({ scene: res?.scene, query: res?.query ?? {}, raw: res });
|
|
167
|
+
};
|
|
168
|
+
wx.onShow(handler);
|
|
169
|
+
return () => wx.offShow?.(handler);
|
|
170
|
+
}
|
|
171
|
+
onHide(cb) {
|
|
172
|
+
const handler = () => cb();
|
|
173
|
+
wx.onHide(handler);
|
|
174
|
+
return () => wx.offHide?.(handler);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var WxAuth = class {
|
|
178
|
+
login() {
|
|
179
|
+
requireWx("auth.login");
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
wx.login({
|
|
182
|
+
success: (res) => resolve({ code: res.code, raw: res }),
|
|
183
|
+
fail: (err) => reject(new Error(err.errMsg ?? "wx.login \u5931\u8D25"))
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
getProfile() {
|
|
188
|
+
requireWx("auth.getProfile");
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
const onSuccess = (res) => {
|
|
191
|
+
resolve({
|
|
192
|
+
nickname: res.userInfo?.nickName ?? "",
|
|
193
|
+
avatarUrl: res.userInfo?.avatarUrl ?? ""
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
if (wx.getUserProfile) {
|
|
197
|
+
wx.getUserProfile({
|
|
198
|
+
desc: "\u7528\u4E8E\u5B8C\u5584\u6E38\u620F\u8D44\u6599",
|
|
199
|
+
success: onSuccess,
|
|
200
|
+
fail: () => resolve(null)
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
wx.getUserInfo({
|
|
204
|
+
success: onSuccess,
|
|
205
|
+
fail: () => resolve(null)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var WxAds = class {
|
|
212
|
+
constructor() {
|
|
213
|
+
__publicField(this, "rewarded");
|
|
214
|
+
__publicField(this, "interstitial");
|
|
215
|
+
__publicField(this, "rewardedUnitId");
|
|
216
|
+
__publicField(this, "interstitialUnitId");
|
|
217
|
+
}
|
|
218
|
+
getRewarded(adUnitId) {
|
|
219
|
+
requireWx("ads.rewarded");
|
|
220
|
+
if (!adUnitId) throw new PlatformUnsupportedError("wechat", "ads.rewarded(\u7F3A\u5C11 adUnitId)");
|
|
221
|
+
if (!this.rewarded || this.rewardedUnitId !== adUnitId) {
|
|
222
|
+
this.rewarded = wx.createRewardedVideoAd({ adUnitId });
|
|
223
|
+
this.rewardedUnitId = adUnitId;
|
|
224
|
+
}
|
|
225
|
+
return this.rewarded;
|
|
226
|
+
}
|
|
227
|
+
getInterstitial(adUnitId) {
|
|
228
|
+
requireWx("ads.interstitial");
|
|
229
|
+
if (!adUnitId)
|
|
230
|
+
throw new PlatformUnsupportedError("wechat", "ads.interstitial(\u7F3A\u5C11 adUnitId)");
|
|
231
|
+
if (!this.interstitial || this.interstitialUnitId !== adUnitId) {
|
|
232
|
+
this.interstitial = wx.createInterstitialAd({ adUnitId });
|
|
233
|
+
this.interstitialUnitId = adUnitId;
|
|
234
|
+
}
|
|
235
|
+
return this.interstitial;
|
|
236
|
+
}
|
|
237
|
+
async preloadRewarded(adUnitId) {
|
|
238
|
+
const ad = this.getRewarded(adUnitId);
|
|
239
|
+
await ad.load().catch(() => {
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
showRewarded(adUnitId) {
|
|
243
|
+
const ad = this.getRewarded(adUnitId);
|
|
244
|
+
return new Promise((resolve) => {
|
|
245
|
+
let settled = false;
|
|
246
|
+
const onClose = (res) => {
|
|
247
|
+
if (settled) return;
|
|
248
|
+
settled = true;
|
|
249
|
+
ad.offClose?.(onClose);
|
|
250
|
+
resolve(res && res.isEnded ? "completed" : "skipped");
|
|
251
|
+
};
|
|
252
|
+
const onError = () => {
|
|
253
|
+
if (settled) return;
|
|
254
|
+
settled = true;
|
|
255
|
+
ad.offError?.(onError);
|
|
256
|
+
resolve("failed");
|
|
257
|
+
};
|
|
258
|
+
ad.onClose(onClose);
|
|
259
|
+
ad.onError(onError);
|
|
260
|
+
ad.show().catch(() => {
|
|
261
|
+
ad.load().then(() => ad.show()).catch(onError);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
showInterstitial(adUnitId) {
|
|
266
|
+
const ad = this.getInterstitial(adUnitId);
|
|
267
|
+
return new Promise((resolve) => {
|
|
268
|
+
let settled = false;
|
|
269
|
+
const onClose = () => {
|
|
270
|
+
if (settled) return;
|
|
271
|
+
settled = true;
|
|
272
|
+
ad.offClose?.(onClose);
|
|
273
|
+
resolve("closed");
|
|
274
|
+
};
|
|
275
|
+
ad.onClose(onClose);
|
|
276
|
+
ad.onError(() => {
|
|
277
|
+
if (settled) return;
|
|
278
|
+
settled = true;
|
|
279
|
+
resolve("failed");
|
|
280
|
+
});
|
|
281
|
+
ad.show().catch(() => {
|
|
282
|
+
ad.load().then(() => ad.show()).catch(() => {
|
|
283
|
+
if (settled) return;
|
|
284
|
+
settled = true;
|
|
285
|
+
resolve("failed");
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
var WxPayment = class {
|
|
292
|
+
purchase(productId, extra) {
|
|
293
|
+
requireWx("payment.purchase");
|
|
294
|
+
return new Promise((resolve, reject) => {
|
|
295
|
+
wx.requestMidasPayment({
|
|
296
|
+
mode: "game",
|
|
297
|
+
env: 0,
|
|
298
|
+
currencyType: "CNY",
|
|
299
|
+
platform: "android",
|
|
300
|
+
productId,
|
|
301
|
+
...extra ?? {},
|
|
302
|
+
success: (res) => {
|
|
303
|
+
resolve({
|
|
304
|
+
productId,
|
|
305
|
+
transactionId: "",
|
|
306
|
+
// 米大师不直接返回回执,业务后端通过虚拟支付回调对账;raw 透传平台原始结果
|
|
307
|
+
receipt: "",
|
|
308
|
+
raw: res
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
fail: (err) => reject(new Error(err.errMsg ?? "wx.requestMidasPayment \u5931\u8D25"))
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
// 米大师没有标准 restore;掉单恢复由业务后端发货补偿,这里不提供 restore
|
|
316
|
+
};
|
|
317
|
+
var WxDevice = class {
|
|
318
|
+
vibrateShort() {
|
|
319
|
+
if (!hasWx()) return;
|
|
320
|
+
wx.vibrateShort({ type: "medium" });
|
|
321
|
+
}
|
|
322
|
+
vibrateLong() {
|
|
323
|
+
if (!hasWx()) return;
|
|
324
|
+
wx.vibrateLong();
|
|
325
|
+
}
|
|
326
|
+
setClipboard(text) {
|
|
327
|
+
requireWx("device.setClipboard");
|
|
328
|
+
return new Promise((resolve, reject) => {
|
|
329
|
+
wx.setClipboardData({
|
|
330
|
+
data: text,
|
|
331
|
+
success: () => resolve(),
|
|
332
|
+
fail: () => reject(new Error("wx.setClipboardData \u5931\u8D25"))
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
getClipboard() {
|
|
337
|
+
requireWx("device.getClipboard");
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
wx.getClipboardData({
|
|
340
|
+
success: (res) => resolve(res.data ?? ""),
|
|
341
|
+
fail: () => reject(new Error("wx.getClipboardData \u5931\u8D25"))
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async share(payload) {
|
|
346
|
+
requireWx("device.share");
|
|
347
|
+
wx.shareAppMessage({
|
|
348
|
+
title: payload.title,
|
|
349
|
+
imageUrl: payload.imageUrl,
|
|
350
|
+
query: payload.query
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
var WeChatPlatform = class {
|
|
355
|
+
constructor() {
|
|
356
|
+
__publicField(this, "_name", "wechat");
|
|
357
|
+
__publicField(this, "_isMiniGame", true);
|
|
358
|
+
__publicField(this, "_hasDOM", false);
|
|
359
|
+
// 微信小游戏无 DOM
|
|
360
|
+
__publicField(this, "_safeArea", { top: 0, bottom: 0, left: 0, right: 0 });
|
|
361
|
+
__publicField(this, "_system", {
|
|
362
|
+
screenWidth: 0,
|
|
363
|
+
screenHeight: 0,
|
|
364
|
+
pixelRatio: 1,
|
|
365
|
+
os: "unknown",
|
|
366
|
+
language: "zh-CN"
|
|
367
|
+
});
|
|
368
|
+
__publicField(this, "_launchOptions", { query: {} });
|
|
369
|
+
__publicField(this, "net", new WxNet());
|
|
370
|
+
__publicField(this, "storage", new WxStorage());
|
|
371
|
+
__publicField(this, "lifecycle", new WxLifecycle());
|
|
372
|
+
__publicField(this, "auth", new WxAuth());
|
|
373
|
+
__publicField(this, "ads", new WxAds());
|
|
374
|
+
__publicField(this, "payment", new WxPayment());
|
|
375
|
+
__publicField(this, "device", new WxDevice());
|
|
376
|
+
}
|
|
377
|
+
// 微信原生埋点能力较弱,业务统一走 AnalyticsManager + 自有后端,这里不提供 analytics
|
|
378
|
+
get info() {
|
|
379
|
+
return {
|
|
380
|
+
name: this._name,
|
|
381
|
+
isMiniGame: this._isMiniGame,
|
|
382
|
+
hasDOM: this._hasDOM,
|
|
383
|
+
safeArea: this._safeArea,
|
|
384
|
+
system: this._system
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
async init() {
|
|
388
|
+
requireWx("init");
|
|
389
|
+
const sys = wx.getSystemInfoSync();
|
|
390
|
+
const win = wx.getWindowInfo?.();
|
|
391
|
+
this._system = {
|
|
392
|
+
screenWidth: win?.screenWidth ?? sys.screenWidth,
|
|
393
|
+
screenHeight: win?.screenHeight ?? sys.screenHeight,
|
|
394
|
+
pixelRatio: win?.pixelRatio ?? sys.pixelRatio ?? 1,
|
|
395
|
+
os: mapWxPlatform(sys.platform),
|
|
396
|
+
language: sys.language ?? "zh-CN",
|
|
397
|
+
hostVersion: sys.version
|
|
398
|
+
};
|
|
399
|
+
const safe = win?.safeArea ?? sys.safeArea;
|
|
400
|
+
if (safe) {
|
|
401
|
+
const sh = this._system.screenHeight;
|
|
402
|
+
const sw = this._system.screenWidth;
|
|
403
|
+
this._safeArea = {
|
|
404
|
+
top: safe.top,
|
|
405
|
+
left: safe.left,
|
|
406
|
+
right: Math.max(0, sw - safe.right),
|
|
407
|
+
bottom: Math.max(0, sh - safe.bottom)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const lo = wx.getLaunchOptionsSync?.();
|
|
411
|
+
if (lo) {
|
|
412
|
+
this._launchOptions = { scene: lo.scene, query: lo.query ?? {}, raw: lo };
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
getLaunchOptions() {
|
|
416
|
+
return this._launchOptions;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
function mapWxPlatform(p) {
|
|
420
|
+
switch (p) {
|
|
421
|
+
case "ios":
|
|
422
|
+
return "ios";
|
|
423
|
+
case "android":
|
|
424
|
+
return "android";
|
|
425
|
+
case "windows":
|
|
426
|
+
return "windows";
|
|
427
|
+
case "mac":
|
|
428
|
+
return "mac";
|
|
429
|
+
case "devtools":
|
|
430
|
+
return "devtools";
|
|
431
|
+
default:
|
|
432
|
+
return p || "unknown";
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export { WeChatPlatform };
|