@galacean/effects-plugin-alipay-downgrade 0.0.0-experimental-downgrade624-20240904

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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2019-present Ant Group Co., Ltd. https://www.antgroup.com/
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # 支付宝降级插件
2
+
3
+ ## 本地开发
4
+
5
+ ### 开始开发
6
+
7
+ ``` bash
8
+ # demo
9
+ pnpm --filter @galacean/effects-plugin-alipay-downgrade dev
10
+ ```
11
+
12
+ > 浏览器打开:http://localhost:8081/demo/
13
+
14
+ ### 单测
15
+
16
+ ``` bash
17
+ # 同上
18
+ ```
19
+
20
+ > 浏览器打开:http://localhost:8081/test/
@@ -0,0 +1,7 @@
1
+ import type { Player, SceneLoadOptions, spec } from '@galacean/effects';
2
+ import { AbstractPlugin } from '@galacean/effects';
3
+ export declare class AlipayDowngradePlugin extends AbstractPlugin {
4
+ static glLostOccurred: boolean;
5
+ static onPlayerCreated(player: Player): Promise<void>;
6
+ static processRawJSON(json: spec.JSONScene, options?: SceneLoadOptions): Promise<undefined>;
7
+ }
package/dist/alipay.js ADDED
@@ -0,0 +1,590 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var effects = require('@galacean/effects/alipay');
6
+ var alipay = require('@galacean/appx-adapter/alipay');
7
+
8
+ /******************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+ /* global Reflect, Promise, SuppressedError, Symbol */
23
+
24
+ var extendStatics = function(d, b) {
25
+ extendStatics = Object.setPrototypeOf ||
26
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
27
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28
+ return extendStatics(d, b);
29
+ };
30
+
31
+ function __extends(d, b) {
32
+ if (typeof b !== "function" && b !== null)
33
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
34
+ extendStatics(d, b);
35
+ function __() { this.constructor = d; }
36
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37
+ }
38
+
39
+ var __assign = function() {
40
+ __assign = Object.assign || function __assign(t) {
41
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
42
+ s = arguments[i];
43
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
+ }
45
+ return t;
46
+ };
47
+ return __assign.apply(this, arguments);
48
+ };
49
+
50
+ function __awaiter(thisArg, _arguments, P, generator) {
51
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
52
+ return new (P || (P = Promise))(function (resolve, reject) {
53
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
54
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
55
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
56
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
57
+ });
58
+ }
59
+
60
+ function __generator(thisArg, body) {
61
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
62
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
+ function verb(n) { return function (v) { return step([n, v]); }; }
64
+ function step(op) {
65
+ if (f) throw new TypeError("Generator is already executing.");
66
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
+ if (y = 0, t) op = [op[0] & 2, t.value];
69
+ switch (op[0]) {
70
+ case 0: case 1: t = op; break;
71
+ case 4: _.label++; return { value: op[1], done: false };
72
+ case 5: _.label++; y = op[1]; op = [0]; continue;
73
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
+ default:
75
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
+ if (t[2]) _.ops.pop();
80
+ _.trys.pop(); continue;
81
+ }
82
+ op = body.call(thisArg, _);
83
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
+ }
86
+ }
87
+
88
+ function __read(o, n) {
89
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
90
+ if (!m) return o;
91
+ var i = m.call(o), r, ar = [], e;
92
+ try {
93
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
94
+ }
95
+ catch (error) { e = { error: error }; }
96
+ finally {
97
+ try {
98
+ if (r && !r.done && (m = i["return"])) m.call(i);
99
+ }
100
+ finally { if (e) throw e.error; }
101
+ }
102
+ return ar;
103
+ }
104
+
105
+ function __spreadArray(to, from, pack) {
106
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
107
+ if (ar || !(i in from)) {
108
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
109
+ ar[i] = from[i];
110
+ }
111
+ }
112
+ return to.concat(ar || Array.prototype.slice.call(from));
113
+ }
114
+
115
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
116
+ var e = new Error(message);
117
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
118
+ };
119
+
120
+ /**
121
+ * 设备等级,分为高、中、低和未知。
122
+ */
123
+ exports.DeviceLevel = void 0;
124
+ (function (DeviceLevel) {
125
+ DeviceLevel["High"] = "high";
126
+ DeviceLevel["Medium"] = "medium";
127
+ DeviceLevel["Low"] = "low";
128
+ DeviceLevel["Unknown"] = "unknown";
129
+ })(exports.DeviceLevel || (exports.DeviceLevel = {}));
130
+
131
+ var deviceModelList = ['12,8', '13,1', '13,2', '13,3', '13,4'];
132
+ /**
133
+ * 设备代理类
134
+ *
135
+ * 负责将 JSAPI 返回的 SystemInfo 和 DowngradeResult 数据
136
+ * 转成设备相关的数据,在后面的降级判断中使用
137
+ */
138
+ var DeviceProxy = /** @class */ (function () {
139
+ function DeviceProxy() {
140
+ /**
141
+ * 是否 iOS 系统
142
+ */
143
+ this.isIOS = false;
144
+ /**
145
+ * 硬件机型
146
+ */
147
+ this.model = 'DESKTOP_DEBUG';
148
+ /**
149
+ * 系统版本
150
+ */
151
+ this.system = 'Unknown';
152
+ /**
153
+ * 设备等级
154
+ */
155
+ this.level = exports.DeviceLevel.Unknown;
156
+ /**
157
+ * 是否降级
158
+ */
159
+ this.isDowngrade = false;
160
+ }
161
+ /**
162
+ * 设置 JSAPI 返回的系统信息
163
+ * @param systemInfo - JSAPI 返回的系统信息
164
+ */
165
+ DeviceProxy.prototype.setSystemInfo = function (systemInfo) {
166
+ var performance = systemInfo.performance, platform = systemInfo.platform, _a = systemInfo.model, model = _a === void 0 ? 'UNKNOWN_DEVICE' : _a, _b = systemInfo.system, system = _b === void 0 ? 'Unknown' : _b;
167
+ this.isIOS = platform === 'iOS';
168
+ this.model = model;
169
+ this.system = system;
170
+ this.setLevel(performance);
171
+ };
172
+ /**
173
+ * 根据传入的 JSAPI 降级结果,返回设备的降级决定
174
+ *
175
+ * @param result - JSAPI 返回的降级结果
176
+ * @returns 设备降级决定
177
+ */
178
+ DeviceProxy.prototype.getDowngradeDecision = function (result) {
179
+ var resultType = undefined;
180
+ var resultReason = undefined;
181
+ if (result.error) {
182
+ // 无权调用的情况下不降级
183
+ return {
184
+ downgrade: result.error !== 4,
185
+ level: this.getRenderLevel(),
186
+ reason: 'api error: ' + result.error,
187
+ };
188
+ }
189
+ try {
190
+ var ret = effects.isString(result) ? JSON.parse(result) : result;
191
+ if ('downgradeResultType' in ret) {
192
+ resultType = ret.downgradeResultType;
193
+ }
194
+ else if ('resultType' in ret) {
195
+ resultType = ret.resultType;
196
+ resultReason = ret.resultReason;
197
+ }
198
+ if (result.context) {
199
+ var deviceInfo = result.context.deviceInfo;
200
+ if (deviceInfo) {
201
+ var deviceLevel = deviceInfo.deviceLevel;
202
+ var newLevel = getDeviceLevel(deviceLevel);
203
+ if (newLevel !== exports.DeviceLevel.Unknown) {
204
+ this.level = newLevel;
205
+ }
206
+ }
207
+ }
208
+ }
209
+ catch (ex) {
210
+ effects.logger.error(ex);
211
+ }
212
+ if (resultType === undefined) {
213
+ return {
214
+ downgrade: true,
215
+ level: this.getRenderLevel(),
216
+ reason: 'call downgrade fail',
217
+ };
218
+ }
219
+ if (resultType === 1) {
220
+ return {
221
+ downgrade: true,
222
+ level: this.getRenderLevel(),
223
+ reason: getDowngradeReason(resultReason),
224
+ };
225
+ }
226
+ if (effects.isAlipayMiniApp() && this.downgradeForMiniprogram()) {
227
+ return {
228
+ downgrade: true,
229
+ level: this.getRenderLevel(),
230
+ reason: 'Force downgrade by downgrade plugin',
231
+ };
232
+ }
233
+ return {
234
+ downgrade: false,
235
+ level: this.getRenderLevel(),
236
+ reason: "".concat(resultType),
237
+ };
238
+ };
239
+ /**
240
+ * 获取设备渲染等级
241
+ * @returns 设备渲染等级
242
+ */
243
+ DeviceProxy.prototype.getRenderLevel = function () {
244
+ if (this.level === exports.DeviceLevel.High) {
245
+ return effects.spec.RenderLevel.S;
246
+ }
247
+ else if (this.level === exports.DeviceLevel.Medium) {
248
+ return effects.spec.RenderLevel.A;
249
+ }
250
+ else if (this.level === exports.DeviceLevel.Low) {
251
+ return effects.spec.RenderLevel.B;
252
+ }
253
+ else {
254
+ return this.isIOS ? effects.spec.RenderLevel.S : effects.spec.RenderLevel.B;
255
+ }
256
+ };
257
+ DeviceProxy.prototype.setLevel = function (level) {
258
+ this.level = getDeviceLevel(level);
259
+ if (this.level === exports.DeviceLevel.Unknown) {
260
+ if (/iPhone(\d+),/.test(this.model)) {
261
+ var gen = +RegExp.$1;
262
+ if (gen <= 9) {
263
+ this.level = exports.DeviceLevel.Low;
264
+ }
265
+ else if (gen < 10) {
266
+ this.level = exports.DeviceLevel.Medium;
267
+ }
268
+ else {
269
+ this.level = exports.DeviceLevel.High;
270
+ }
271
+ }
272
+ }
273
+ };
274
+ DeviceProxy.prototype.downgradeForMiniprogram = function () {
275
+ var _this = this;
276
+ if (this.isIOS) {
277
+ if (deviceModelList.find(function (v) { return v === _this.model; })) {
278
+ var versionList = this.system.split('.');
279
+ if (versionList.length > 0 && versionList[0] === '16') {
280
+ return true;
281
+ }
282
+ }
283
+ }
284
+ return false;
285
+ };
286
+ return DeviceProxy;
287
+ }());
288
+ function getDowngradeReason(reason) {
289
+ if (reason === -1) {
290
+ return "".concat(reason, ", unable to pull configuration");
291
+ }
292
+ else if (reason === 0) {
293
+ return "".concat(reason, ", no downgrade");
294
+ }
295
+ else if (reason === 1) {
296
+ return "".concat(reason, ", memory downgrade");
297
+ }
298
+ else if (reason === 2) {
299
+ return "".concat(reason, ", crash downgrade");
300
+ }
301
+ else if (reason === 3) {
302
+ return "".concat(reason, ", basic dimension downgrade");
303
+ }
304
+ else if (reason === 4) {
305
+ return "".concat(reason, ", technical point downgrade");
306
+ }
307
+ else if (reason === 5) {
308
+ return "".concat(reason, ", GPU downgrade");
309
+ }
310
+ else if (reason === 6) {
311
+ return "".concat(reason, ", self-healing downgrade");
312
+ }
313
+ else if (reason === 7) {
314
+ return "".concat(reason, ", 32-bit CPU downgrade");
315
+ }
316
+ else {
317
+ return "".concat(reason);
318
+ }
319
+ }
320
+ function getDeviceLevel(level) {
321
+ if (level === 'high') {
322
+ return exports.DeviceLevel.High;
323
+ }
324
+ else if (level === 'medium' || level === 'middle') {
325
+ return exports.DeviceLevel.Medium;
326
+ }
327
+ else if (level === 'low') {
328
+ return exports.DeviceLevel.Low;
329
+ }
330
+ else {
331
+ return exports.DeviceLevel.Unknown;
332
+ }
333
+ }
334
+
335
+ var internalPaused = Symbol('@@_inter_pause');
336
+ var mockIdPass = 'mock-pass';
337
+ var mockIdFail = 'mock-fail';
338
+ var hasRegisterEvent = false;
339
+ /**
340
+ * 获取 GE 降级结果,在有 JSAPI 环境下调用,不需要创建 Canvas 和 WebGL 环境。
341
+ *
342
+ * @param bizId - 业务 bizId
343
+ * @param options - 降级选项
344
+ * @returns 降级结果
345
+ */
346
+ function getDowngradeResult(bizId, options) {
347
+ var _a, _b;
348
+ if (options === void 0) { options = {}; }
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ var ap, systemStartTime;
351
+ return __generator(this, function (_c) {
352
+ if (!hasRegisterEvent) {
353
+ hasRegisterEvent = true;
354
+ registerEvent(options);
355
+ }
356
+ if (bizId === mockIdFail || bizId === mockIdPass) {
357
+ return [2 /*return*/, Promise.resolve({
358
+ bizId: bizId,
359
+ downgrade: bizId === mockIdFail,
360
+ level: (_a = options.level) !== null && _a !== void 0 ? _a : effects.spec.RenderLevel.S,
361
+ reason: 'mock',
362
+ })];
363
+ }
364
+ ap = effects.isAlipayMiniApp() ? my : alipay.window.AlipayJSBridge;
365
+ // 当需要通过 ap 获取降级信息时,才进行降级环境的检查
366
+ if (!ap && (!options.systemInfo || !options.downgradeResult)) {
367
+ return [2 /*return*/, {
368
+ bizId: bizId,
369
+ downgrade: false,
370
+ level: (_b = options.level) !== null && _b !== void 0 ? _b : effects.spec.RenderLevel.S,
371
+ reason: 'Non-Alipay environment',
372
+ }];
373
+ }
374
+ systemStartTime = performance.now();
375
+ return [2 /*return*/, getSystemInfoJSAPI(options, ap)
376
+ .then(function (systemInfo) {
377
+ var systemEndTime = performance.now();
378
+ return getDowngradeResultJSAPI(bizId, options, ap)
379
+ .then(function (downgradeResult) {
380
+ var downgradeEndTime = performance.now();
381
+ effects.logger.info("Downgrade time: ".concat(downgradeEndTime - systemStartTime, "ms."));
382
+ var device = new DeviceProxy();
383
+ device.setSystemInfo(systemInfo);
384
+ var decision = device.getDowngradeDecision(downgradeResult);
385
+ if (options.level) {
386
+ decision.level = options.level;
387
+ }
388
+ var result = __assign(__assign({}, decision), { bizId: bizId, systemInfo: systemInfo, systemTime: systemEndTime - systemStartTime, downgradeResult: downgradeResult, downgradeTime: downgradeEndTime - systemEndTime });
389
+ return result;
390
+ });
391
+ })];
392
+ });
393
+ });
394
+ }
395
+ function registerEvent(options) {
396
+ var ignoreGLLost = options.ignoreGLLost, autoPause = options.autoPause, _a = options.disableGLLostEvent, disableGLLostEvent = _a === void 0 ? false : _a;
397
+ var downgradeWhenGLLost = ignoreGLLost !== true;
398
+ alipay.window.addEventListener('unload', function () {
399
+ effects.getActivePlayers().forEach(function (player) { return player.dispose(); });
400
+ });
401
+ if (!disableGLLostEvent) {
402
+ alipay.window.addEventListener('webglcontextlost', function (e) {
403
+ if (effects.isCanvasUsedByPlayer(e.target)) {
404
+ AlipayDowngradePlugin.glLostOccurred = true;
405
+ console.error('webgl lost occur');
406
+ if (downgradeWhenGLLost) {
407
+ console.warn('webgl lost occur, all players will be downgraded from now on');
408
+ effects.disableAllPlayer(true);
409
+ effects.getActivePlayers().forEach(function (player) { return player.dispose(); });
410
+ }
411
+ }
412
+ }, true);
413
+ }
414
+ if (autoPause) {
415
+ document.addEventListener('pause', pauseAllActivePlayers);
416
+ document.addEventListener('resume', resumePausedPlayers);
417
+ }
418
+ }
419
+ function getSystemInfoJSAPI(options, ap) {
420
+ return __awaiter(this, void 0, void 0, function () {
421
+ return __generator(this, function (_a) {
422
+ if (options.systemInfo) {
423
+ return [2 /*return*/, Promise.resolve(options.systemInfo)];
424
+ }
425
+ else {
426
+ return [2 /*return*/, new Promise(function (resolve, reject) {
427
+ ap.call('getSystemInfo', function (e) {
428
+ if (e.error) {
429
+ reject(e);
430
+ }
431
+ else {
432
+ resolve(e);
433
+ }
434
+ });
435
+ })];
436
+ }
437
+ });
438
+ });
439
+ }
440
+ function getDowngradeResultJSAPI(bizId, options, ap) {
441
+ return __awaiter(this, void 0, void 0, function () {
442
+ return __generator(this, function (_a) {
443
+ if (options.downgradeResult) {
444
+ return [2 /*return*/, Promise.resolve(options.downgradeResult)];
445
+ }
446
+ else {
447
+ return [2 /*return*/, new Promise(function (resolve, reject) {
448
+ var _a;
449
+ var techPoint = ['mars'];
450
+ var tc = options.techPoint;
451
+ if (tc) {
452
+ techPoint.push.apply(techPoint, __spreadArray([], __read(tc), false));
453
+ }
454
+ var downgradeOptions = {
455
+ bizId: bizId,
456
+ scene: 0,
457
+ ext: {
458
+ techPoint: techPoint,
459
+ },
460
+ };
461
+ var callBridge = (_a = options.callBridge) !== null && _a !== void 0 ? _a : ap.call;
462
+ callBridge('getDowngradeResult', downgradeOptions, function (result) {
463
+ resolve(result);
464
+ });
465
+ })];
466
+ }
467
+ });
468
+ });
469
+ }
470
+ /**
471
+ * 获取默认渲染等级
472
+ *
473
+ * @returns 渲染等级
474
+ */
475
+ function getDefaultRenderLevel() {
476
+ return effects.isIOS() ? effects.spec.RenderLevel.S : effects.spec.RenderLevel.B;
477
+ }
478
+ function pauseAllActivePlayers(e) {
479
+ if (e.target === document) {
480
+ effects.logger.info('Auto pause all players with data offloaded.');
481
+ var players = effects.getActivePlayers();
482
+ players.forEach(function (player) {
483
+ if (!player.paused) {
484
+ player.pause({ offloadTexture: true });
485
+ // @ts-expect-error
486
+ player[internalPaused] = true;
487
+ }
488
+ });
489
+ }
490
+ }
491
+ function resumePausedPlayers(e) {
492
+ if (e.target === document) {
493
+ effects.logger.info('Auto resume all players.');
494
+ var players = effects.getActivePlayers();
495
+ players.forEach(function (player) {
496
+ // @ts-expect-error
497
+ if (player[internalPaused]) {
498
+ void player.resume();
499
+ // @ts-expect-error
500
+ player[internalPaused] = false;
501
+ }
502
+ });
503
+ }
504
+ }
505
+
506
+ var AlipayDowngradePlugin = /** @class */ (function (_super) {
507
+ __extends(AlipayDowngradePlugin, _super);
508
+ function AlipayDowngradePlugin() {
509
+ return _super !== null && _super.apply(this, arguments) || this;
510
+ }
511
+ AlipayDowngradePlugin.onPlayerCreated = function (player) {
512
+ return __awaiter(this, void 0, void 0, function () {
513
+ return __generator(this, function (_a) {
514
+ if (AlipayDowngradePlugin.glLostOccurred) {
515
+ console.warn('gl lost happened, new player will be destroyed.');
516
+ player.dispose();
517
+ }
518
+ return [2 /*return*/];
519
+ });
520
+ });
521
+ };
522
+ AlipayDowngradePlugin.processRawJSON = function (json, options) {
523
+ var _a, _b;
524
+ if (options === void 0) { options = {}; }
525
+ return __awaiter(this, void 0, void 0, function () {
526
+ var downgradeResult;
527
+ return __generator(this, function (_c) {
528
+ if (AlipayDowngradePlugin.glLostOccurred) {
529
+ return [2 /*return*/, Promise.reject('gl lost happened')];
530
+ }
531
+ downgradeResult = (_a = options.pluginData) === null || _a === void 0 ? void 0 : _a['downgrade'];
532
+ if (downgradeResult) {
533
+ if (downgradeResult.downgrade) {
534
+ throw new Error("Downgraded, reason: ".concat(downgradeResult.reason));
535
+ }
536
+ }
537
+ else {
538
+ effects.logger.warn('No downgrade result in pluginData of SceneLoadOptions.');
539
+ }
540
+ if (!options.renderLevel) {
541
+ options.renderLevel = (_b = downgradeResult === null || downgradeResult === void 0 ? void 0 : downgradeResult.level) !== null && _b !== void 0 ? _b : getDefaultRenderLevel();
542
+ }
543
+ return [2 /*return*/];
544
+ });
545
+ });
546
+ };
547
+ AlipayDowngradePlugin.glLostOccurred = false;
548
+ return AlipayDowngradePlugin;
549
+ }(effects.AbstractPlugin));
550
+
551
+ var DowngradeVFXItem = /** @class */ (function (_super) {
552
+ __extends(DowngradeVFXItem, _super);
553
+ function DowngradeVFXItem() {
554
+ return _super !== null && _super.apply(this, arguments) || this;
555
+ }
556
+ return DowngradeVFXItem;
557
+ }(effects.VFXItem));
558
+
559
+ var prefix = '[Galacean Effects]';
560
+ //@ts-expect-error
561
+ var ap = effects.isAlipayMiniApp() ? my : alipay.window.AlipayJSBridge;
562
+ effects.logger.register(nativeLogger);
563
+ function nativeLogger(type, msg) {
564
+ var args = [];
565
+ for (var _i = 2; _i < arguments.length; _i++) {
566
+ args[_i - 2] = arguments[_i];
567
+ }
568
+ var content = {
569
+ 'message': "".concat(prefix, " ").concat(msg, " ").concat(args.join('')),
570
+ 'level': type,
571
+ };
572
+ if (effects.isAndroid()) {
573
+ content['anr_info'] = 'mars';
574
+ }
575
+ try {
576
+ ap === null || ap === void 0 ? void 0 : ap.call('localLog', content);
577
+ }
578
+ catch (e) {
579
+ console.error(e);
580
+ }
581
+ }
582
+
583
+ var version = "0.0.0-experimental-downgrade624-20240904";
584
+ effects.registerPlugin('alipay-downgrade', AlipayDowngradePlugin, DowngradeVFXItem, true);
585
+ effects.logger.info('plugin alipay downgrade version: ' + version);
586
+
587
+ exports.getDefaultRenderLevel = getDefaultRenderLevel;
588
+ exports.getDowngradeResult = getDowngradeResult;
589
+ exports.version = version;
590
+ //# sourceMappingURL=alipay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alipay.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}