@galacean/effects-plugin-downgrade 2.0.0-alpha.28

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/dist/weapp.mjs ADDED
@@ -0,0 +1,1085 @@
1
+ import * as EFFECTS from '@galacean/effects/weapp';
2
+ import { spec, getActivePlayers, isAlipayMiniApp, logger, isWechatMiniApp, isIOS, AbstractPlugin, registerPlugin, VFXItem } from '@galacean/effects/weapp';
3
+ import { window } from '@galacean/appx-adapter/weapp';
4
+
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
6
+ try {
7
+ var info = gen[key](arg);
8
+ var value = info.value;
9
+ } catch (error) {
10
+ reject(error);
11
+ return;
12
+ }
13
+ if (info.done) resolve(value);
14
+ else Promise.resolve(value).then(_next, _throw);
15
+ }
16
+ function _async_to_generator(fn) {
17
+ return function() {
18
+ var self = this, args = arguments;
19
+ return new Promise(function(resolve, reject) {
20
+ var gen = fn.apply(self, args);
21
+ function _next(value) {
22
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
+ }
24
+ function _throw(err) {
25
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
+ }
27
+ _next(undefined);
28
+ });
29
+ };
30
+ }
31
+
32
+ function _set_prototype_of(o, p) {
33
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
34
+ o.__proto__ = p;
35
+ return o;
36
+ };
37
+ return _set_prototype_of(o, p);
38
+ }
39
+
40
+ function _inherits(subClass, superClass) {
41
+ if (typeof superClass !== "function" && superClass !== null) {
42
+ throw new TypeError("Super expression must either be null or a function");
43
+ }
44
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
45
+ constructor: {
46
+ value: subClass,
47
+ writable: true,
48
+ configurable: true
49
+ }
50
+ });
51
+ if (superClass) _set_prototype_of(subClass, superClass);
52
+ }
53
+
54
+ function __generator(thisArg, body) {
55
+ var _ = {
56
+ label: 0,
57
+ sent: function sent() {
58
+ if (t[0] & 1) throw t[1];
59
+ return t[1];
60
+ },
61
+ trys: [],
62
+ ops: []
63
+ }, f, y, t, g;
64
+ return g = {
65
+ next: verb(0),
66
+ "throw": verb(1),
67
+ "return": verb(2)
68
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
69
+ return this;
70
+ }), g;
71
+ function verb(n) {
72
+ return function(v) {
73
+ return step([
74
+ n,
75
+ v
76
+ ]);
77
+ };
78
+ }
79
+ function step(op) {
80
+ if (f) throw new TypeError("Generator is already executing.");
81
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
82
+ 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;
83
+ if (y = 0, t) op = [
84
+ op[0] & 2,
85
+ t.value
86
+ ];
87
+ switch(op[0]){
88
+ case 0:
89
+ case 1:
90
+ t = op;
91
+ break;
92
+ case 4:
93
+ _.label++;
94
+ return {
95
+ value: op[1],
96
+ done: false
97
+ };
98
+ case 5:
99
+ _.label++;
100
+ y = op[1];
101
+ op = [
102
+ 0
103
+ ];
104
+ continue;
105
+ case 7:
106
+ op = _.ops.pop();
107
+ _.trys.pop();
108
+ continue;
109
+ default:
110
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
111
+ _ = 0;
112
+ continue;
113
+ }
114
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
115
+ _.label = op[1];
116
+ break;
117
+ }
118
+ if (op[0] === 6 && _.label < t[1]) {
119
+ _.label = t[1];
120
+ t = op;
121
+ break;
122
+ }
123
+ if (t && _.label < t[2]) {
124
+ _.label = t[2];
125
+ _.ops.push(op);
126
+ break;
127
+ }
128
+ if (t[2]) _.ops.pop();
129
+ _.trys.pop();
130
+ continue;
131
+ }
132
+ op = body.call(thisArg, _);
133
+ } catch (e) {
134
+ op = [
135
+ 6,
136
+ e
137
+ ];
138
+ y = 0;
139
+ } finally{
140
+ f = t = 0;
141
+ }
142
+ if (op[0] & 5) throw op[1];
143
+ return {
144
+ value: op[0] ? op[1] : void 0,
145
+ done: true
146
+ };
147
+ }
148
+ }
149
+ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
150
+ var e = new Error(message);
151
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
152
+ };
153
+
154
+ function _extends() {
155
+ _extends = Object.assign || function assign(target) {
156
+ for(var i = 1; i < arguments.length; i++){
157
+ var source = arguments[i];
158
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
159
+ }
160
+ return target;
161
+ };
162
+ return _extends.apply(this, arguments);
163
+ }
164
+
165
+ function _array_like_to_array(arr, len) {
166
+ if (len == null || len > arr.length) len = arr.length;
167
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
168
+ return arr2;
169
+ }
170
+
171
+ function _unsupported_iterable_to_array(o, minLen) {
172
+ if (!o) return;
173
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
174
+ var n = Object.prototype.toString.call(o).slice(8, -1);
175
+ if (n === "Object" && o.constructor) n = o.constructor.name;
176
+ if (n === "Map" || n === "Set") return Array.from(n);
177
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
178
+ }
179
+
180
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
181
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
182
+ if (it) return (it = it.call(o)).next.bind(it);
183
+ // Fallback for engines without symbol support
184
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
185
+ if (it) o = it;
186
+ var i = 0;
187
+ return function() {
188
+ if (i >= o.length) return {
189
+ done: true
190
+ };
191
+ return {
192
+ done: false,
193
+ value: o[i++]
194
+ };
195
+ };
196
+ }
197
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
198
+ }
199
+
200
+ var infoList = {
201
+ vender: [
202
+ "SAMSUNG"
203
+ ],
204
+ iPhone: [
205
+ {
206
+ name: "iPhone 15 Pro Max",
207
+ model: "iPhone16,2",
208
+ width: 1290,
209
+ height: 2796
210
+ },
211
+ {
212
+ name: "iPhone 15 Pro",
213
+ model: "iPhone16,1",
214
+ width: 1179,
215
+ height: 2556
216
+ },
217
+ {
218
+ name: "iPhone 15 Plus",
219
+ model: "iPhone15,5",
220
+ width: 1290,
221
+ height: 2796
222
+ },
223
+ {
224
+ name: "iPhone 15",
225
+ model: "iPhone15,4",
226
+ width: 1179,
227
+ height: 2556
228
+ },
229
+ {
230
+ name: "iPhone 14 Pro Max",
231
+ model: "iPhone15,3",
232
+ width: 1290,
233
+ height: 2796
234
+ },
235
+ {
236
+ name: "iPhone 14 Pro",
237
+ model: "iPhone15,2",
238
+ width: 1179,
239
+ height: 2556
240
+ },
241
+ {
242
+ name: "iPhone 14 Plus",
243
+ model: "iPhone14,8",
244
+ width: 1284,
245
+ height: 2778
246
+ },
247
+ {
248
+ name: "iPhone 14",
249
+ model: "iPhone14,7",
250
+ width: 1170,
251
+ height: 2532
252
+ },
253
+ {
254
+ name: "iPhone 13 Pro Max",
255
+ model: "iPhone14,3",
256
+ width: 1284,
257
+ height: 2778
258
+ },
259
+ {
260
+ name: "iPhone 13 Pro",
261
+ model: "iPhone14,2",
262
+ width: 1170,
263
+ height: 2532
264
+ },
265
+ {
266
+ name: "iPhone 13",
267
+ model: "iPhone14,5",
268
+ width: 1170,
269
+ height: 2532
270
+ },
271
+ {
272
+ name: "iPhone 13 mini",
273
+ model: "iPhone14,4",
274
+ width: 1080,
275
+ height: 2340
276
+ },
277
+ {
278
+ name: "iPhone SE (3rd gen)",
279
+ model: "iPhone14,6",
280
+ width: 750,
281
+ height: 1334
282
+ },
283
+ {
284
+ name: "iPhone 12 Pro Max",
285
+ model: "iPhone13,4",
286
+ width: 1284,
287
+ height: 2778
288
+ },
289
+ {
290
+ name: "iPhone 12 Pro",
291
+ model: "iPhone13,3",
292
+ width: 1170,
293
+ height: 2532
294
+ },
295
+ {
296
+ name: "iPhone 12",
297
+ model: "iPhone13,2",
298
+ width: 1170,
299
+ height: 2532
300
+ },
301
+ {
302
+ name: "iPhone 12 mini",
303
+ model: "iPhone13,1",
304
+ width: 1080,
305
+ height: 2340
306
+ },
307
+ {
308
+ name: "iPhone 11 Pro Max",
309
+ model: "iPhone12,5",
310
+ width: 1242,
311
+ height: 2688
312
+ },
313
+ {
314
+ name: "iPhone 11 Pro",
315
+ model: "iPhone12,3",
316
+ width: 1125,
317
+ height: 2436
318
+ },
319
+ {
320
+ name: "iPhone 11",
321
+ model: "iPhone12,1",
322
+ width: 828,
323
+ height: 1792
324
+ },
325
+ {
326
+ name: "iPhone SE (2nd gen)",
327
+ model: "iPhone12,8",
328
+ width: 750,
329
+ height: 1334
330
+ },
331
+ {
332
+ name: "iPhone XR",
333
+ model: "iPhone11,8",
334
+ width: 828,
335
+ height: 1792
336
+ },
337
+ {
338
+ name: "iPhone XS Max",
339
+ model: "iPhone11,6",
340
+ width: 1242,
341
+ height: 2688
342
+ },
343
+ {
344
+ name: "iPhone XS",
345
+ model: "iPhone11,2",
346
+ width: 1125,
347
+ height: 2436
348
+ },
349
+ {
350
+ name: "iPhone X",
351
+ model: "iPhone10,3",
352
+ width: 1125,
353
+ height: 2436
354
+ },
355
+ {
356
+ name: "iPhone 8 Plus",
357
+ model: "iPhone10,2",
358
+ width: 1080,
359
+ height: 1920
360
+ },
361
+ {
362
+ name: "iPhone 8",
363
+ model: "iPhone10,1",
364
+ width: 750,
365
+ height: 1334
366
+ },
367
+ {
368
+ name: "iPhone 7 Plus",
369
+ model: "iPhone9,2",
370
+ width: 1080,
371
+ height: 1920
372
+ },
373
+ {
374
+ name: "iPhone 7",
375
+ model: "iPhone9,1",
376
+ width: 750,
377
+ height: 1334
378
+ },
379
+ {
380
+ name: "iPhone 6s Plus",
381
+ model: "iPhone8,2",
382
+ width: 1080,
383
+ height: 1920
384
+ },
385
+ {
386
+ name: "iPhone 6s",
387
+ model: "iPhone8,1",
388
+ width: 750,
389
+ height: 1334
390
+ },
391
+ {
392
+ name: "iPhone SE (1st gen)",
393
+ model: "iPhone8,4",
394
+ width: 640,
395
+ height: 1136
396
+ },
397
+ {
398
+ name: "iPhone 6 Plus",
399
+ model: "iPhone7,1",
400
+ width: 1080,
401
+ height: 1920
402
+ },
403
+ {
404
+ name: "iPhone 6",
405
+ model: "iPhone7,2",
406
+ width: 750,
407
+ height: 1334
408
+ },
409
+ {
410
+ name: "iPhone 5C",
411
+ model: "iPhone5,3",
412
+ width: 640,
413
+ height: 1136
414
+ },
415
+ {
416
+ name: "iPhone 5S",
417
+ model: "iPhone6,1",
418
+ width: 640,
419
+ height: 1136
420
+ },
421
+ {
422
+ name: "iPhone 5",
423
+ model: "iPhone5,1",
424
+ width: 640,
425
+ height: 1136
426
+ },
427
+ {
428
+ name: "iPhone 4S",
429
+ model: "iPhone4,1",
430
+ width: 640,
431
+ height: 960
432
+ },
433
+ {
434
+ name: "iPhone 4",
435
+ model: "iPhone3,1",
436
+ width: 640,
437
+ height: 960
438
+ },
439
+ {
440
+ name: "iPhone 3GS",
441
+ model: "iPhone2,1",
442
+ width: 320,
443
+ height: 480
444
+ },
445
+ {
446
+ name: "iPhone 3G",
447
+ model: "iPhone1,2",
448
+ width: 320,
449
+ height: 480
450
+ },
451
+ {
452
+ name: "iPhone 1st gen",
453
+ model: "iPhone1,1",
454
+ width: 320,
455
+ height: 480
456
+ }
457
+ ]
458
+ };
459
+ var downgradeModels = {
460
+ android: [
461
+ "OPPO R9s Plus",
462
+ "GM1910",
463
+ "V1824A",
464
+ "V1916A",
465
+ "SM-G9650",
466
+ "V1936A",
467
+ "MI9 PRO 5G",
468
+ "REDMI K20",
469
+ "V1914A",
470
+ "GM1900",
471
+ "RMX1971",
472
+ "SM-A6060",
473
+ "SM-G9600",
474
+ "V1922A",
475
+ "PBAM00",
476
+ "PCAM10",
477
+ "PACT00",
478
+ "PBBM00",
479
+ "PCEM00",
480
+ "V1818A",
481
+ "vivo X6A",
482
+ "vivo X6Plus A"
483
+ ],
484
+ iPhone: [
485
+ "iPhone8,4",
486
+ "iPhone8,2",
487
+ "iPhone8,1",
488
+ "iPhone7,2",
489
+ "iPhone7,1",
490
+ "iPhone6,2",
491
+ "iPhone6,1",
492
+ "iPhone5,4",
493
+ "iPhone5,3",
494
+ "iPhone5,2",
495
+ "iPhone5,1",
496
+ "iPhone4,3",
497
+ "iPhone4,2",
498
+ "iPhone4,1",
499
+ "iPhone3,3",
500
+ "iPhone3,2",
501
+ "iPhone3,1",
502
+ "iPhone2,1",
503
+ "iPhone1,2",
504
+ "iPhone1,1"
505
+ ]
506
+ };
507
+ var downgradeVersions = {
508
+ android: [],
509
+ iOS: [
510
+ "16.7",
511
+ "16.7.1",
512
+ "16.7.2",
513
+ "16.7.3",
514
+ "16.7.4",
515
+ "16.7.5",
516
+ "16.7.6"
517
+ ]
518
+ };
519
+ var devtoolNameMap = {
520
+ wechat: {
521
+ "iPhone 6/7/8": "iPhone 8",
522
+ "iPhone 6/7/8 Plus": "iPhone 8 Plus",
523
+ "iPhone 12/13 mini": "iPhone 13 mini",
524
+ "iPhone 12/13 (Pro)": "iPhone 13 Pro",
525
+ "iPhone 12/13 Pro Max": "iPhone 13 Pro Max"
526
+ }
527
+ };
528
+
529
+ var DeviceLevel;
530
+ (function(DeviceLevel) {
531
+ DeviceLevel["High"] = "high";
532
+ DeviceLevel["Medium"] = "medium";
533
+ DeviceLevel["Low"] = "low";
534
+ DeviceLevel["Unknown"] = "unknown";
535
+ })(DeviceLevel || (DeviceLevel = {}));
536
+
537
+ var UADecoder = /*#__PURE__*/ function() {
538
+ function UADecoder(userAgent) {
539
+ this.device = {};
540
+ this.parse(userAgent != null ? userAgent : navigator.userAgent);
541
+ }
542
+ var _proto = UADecoder.prototype;
543
+ _proto.getDeviceInfo = function getDeviceInfo() {
544
+ return this.device;
545
+ };
546
+ _proto.isIOS = function isIOS() {
547
+ return this.device.platform === "iOS";
548
+ };
549
+ _proto.isAndroid = function isAndroid() {
550
+ return this.device.platform === "Android";
551
+ };
552
+ _proto.isHarmony = function isHarmony() {
553
+ return this.device.platform === "Harmony";
554
+ };
555
+ _proto.isWindows = function isWindows() {
556
+ return this.device.platform === "Windows";
557
+ };
558
+ _proto.isMacintosh = function isMacintosh() {
559
+ return this.device.platform === "Macintosh";
560
+ };
561
+ _proto.isMobile = function isMobile() {
562
+ return this.isIOS() || this.isAndroid() || this.isHarmony();
563
+ };
564
+ _proto.parse = function parse(ua) {
565
+ var pattern = /(\w+\/[\w.]+)(\s+\([^)]+\))?/g;
566
+ var productInfos = [];
567
+ var match;
568
+ while((match = pattern.exec(ua)) !== null){
569
+ var _match_;
570
+ var name = match[1];
571
+ var comment = (_match_ = match[2]) == null ? void 0 : _match_.trim();
572
+ productInfos.push({
573
+ name: name,
574
+ comment: comment
575
+ });
576
+ }
577
+ for(var _iterator = _create_for_of_iterator_helper_loose(productInfos), _step; !(_step = _iterator()).done;){
578
+ var productInfo = _step.value;
579
+ var name1 = productInfo.name, comment1 = productInfo.comment;
580
+ if (name1 == null ? void 0 : name1.startsWith("Mozilla/")) {
581
+ if (comment1) {
582
+ this.parseData(comment1);
583
+ }
584
+ break;
585
+ }
586
+ }
587
+ this.device.level = this.estimateDeviceLevel();
588
+ this.device.sourceData = ua;
589
+ };
590
+ _proto.parseData = function parseData(data) {
591
+ if (data.length && data[0] === "(") {
592
+ data = data.substring(1);
593
+ }
594
+ if (data.length && data[data.length - 1] == ")") {
595
+ data = data.substring(0, data.length - 1);
596
+ }
597
+ if (this.testIPhone(data)) {
598
+ this.device.platform = "iOS";
599
+ this.device.osVersion = this.parseIOSVersion(data);
600
+ this.device.model = this.getIPhoneModel();
601
+ } else if (this.testIPad(data)) {
602
+ this.device.platform = "iOS";
603
+ this.device.osVersion = this.parseIOSVersion(data);
604
+ this.device.model = "iPad";
605
+ } else if (this.testMacintosh(data)) {
606
+ this.device.platform = "Mac OS";
607
+ this.device.osVersion = this.parseMacOSVersion(data);
608
+ } else if (this.testAndroid(data)) {
609
+ this.device.platform = "Android";
610
+ this.device.osVersion = this.parseAndroidVersion(data);
611
+ this.device.model = this.parseAndroidModel(data);
612
+ } else if (this.testWindows(data)) {
613
+ this.device.platform = "Windows";
614
+ this.device.osVersion = this.parseWindowsVersion(data);
615
+ } else {
616
+ console.error("Unknown info: " + data + ".");
617
+ }
618
+ };
619
+ _proto.estimateDeviceLevel = function estimateDeviceLevel() {
620
+ if (this.isIOS()) {
621
+ if (this.device.osVersion) {
622
+ var osVersion = parseInt(this.device.osVersion.split(".")[0]);
623
+ if (osVersion < 12) {
624
+ return DeviceLevel.Low;
625
+ } else if (osVersion < 16) {
626
+ return DeviceLevel.Medium;
627
+ } else {
628
+ return DeviceLevel.High;
629
+ }
630
+ } else {
631
+ return DeviceLevel.Low;
632
+ }
633
+ }
634
+ if (this.isAndroid()) {
635
+ if (this.device.osVersion) {
636
+ var osVersion1 = parseInt(this.device.osVersion.split(".")[0]);
637
+ if (osVersion1 < 10) {
638
+ return DeviceLevel.Low;
639
+ } else if (osVersion1 < 12) {
640
+ return DeviceLevel.Medium;
641
+ } else {
642
+ return DeviceLevel.High;
643
+ }
644
+ } else {
645
+ return DeviceLevel.Low;
646
+ }
647
+ }
648
+ return DeviceLevel.High;
649
+ };
650
+ _proto.parseIOSVersion = function parseIOSVersion(data) {
651
+ var pattern = /OS (\d+)(?:_(\d+))?_(\d+)/;
652
+ var match = data.match(pattern);
653
+ if (match) {
654
+ var versionList = [];
655
+ for(var i = 1; i <= 3; i++){
656
+ if (match[i]) {
657
+ versionList.push(match[i]);
658
+ }
659
+ }
660
+ return versionList.join(".");
661
+ }
662
+ };
663
+ _proto.getIPhoneModel = function getIPhoneModel() {
664
+ var screenWidth = window.screen.width * window.devicePixelRatio;
665
+ var screenHeight = window.screen.height * window.devicePixelRatio;
666
+ var match = infoList.iPhone.find(function(m) {
667
+ return m.width === screenWidth && m.height === screenHeight;
668
+ });
669
+ var _match_model;
670
+ return (_match_model = match == null ? void 0 : match.model) != null ? _match_model : "iPhone";
671
+ };
672
+ _proto.parseAndroidVersion = function parseAndroidVersion(data) {
673
+ var pattern = /Android ([\d.]+);/;
674
+ var match = data.match(pattern);
675
+ if (match && match.length >= 2) {
676
+ return match[1];
677
+ }
678
+ };
679
+ _proto.parseAndroidModel = function parseAndroidModel(data) {
680
+ var itemList = data.split(";");
681
+ var lastItem;
682
+ for(var _iterator = _create_for_of_iterator_helper_loose(itemList), _step; !(_step = _iterator()).done;){
683
+ var item = _step.value;
684
+ var modelPattern = /(.+?) Build/;
685
+ var modelMatch = item.match(modelPattern);
686
+ if (modelMatch && modelMatch.length >= 2) {
687
+ return modelMatch[1].trim();
688
+ }
689
+ if (item.includes("HMSCore") && lastItem) {
690
+ return lastItem.trim();
691
+ }
692
+ lastItem = item;
693
+ }
694
+ if (itemList.length > 0) {
695
+ var lastItem1 = itemList[itemList.length - 1].trim();
696
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(infoList.vender), _step1; !(_step1 = _iterator1()).done;){
697
+ var vender = _step1.value;
698
+ if (lastItem1.startsWith(vender)) {
699
+ return lastItem1.substring(vender.length).trim();
700
+ }
701
+ }
702
+ }
703
+ if (itemList.length == 3) {
704
+ return itemList[itemList.length - 1].trim();
705
+ } else if (itemList.length === 4) {
706
+ var len = itemList.length;
707
+ if (itemList[len - 1].trim() === "wv") {
708
+ return itemList[len - 2].trim();
709
+ }
710
+ }
711
+ };
712
+ _proto.parseWindowsVersion = function parseWindowsVersion(data) {
713
+ var pattern = /Windows NT ([\d.]+);/;
714
+ var match = data.match(pattern);
715
+ if (match && match.length >= 2) {
716
+ return match[1];
717
+ }
718
+ };
719
+ _proto.parseMacOSVersion = function parseMacOSVersion(data) {
720
+ var pattern = /OS X (\d+)(?:_(\d+))?_(\d+)/;
721
+ var match = data.match(pattern);
722
+ if (match) {
723
+ var versionList = [];
724
+ for(var i = 1; i <= 3; i++){
725
+ if (match[i]) {
726
+ versionList.push(match[i]);
727
+ }
728
+ }
729
+ return versionList.join(".");
730
+ }
731
+ };
732
+ _proto.testIPhone = function testIPhone(data) {
733
+ return data.includes("iPhone");
734
+ };
735
+ _proto.testIPad = function testIPad(data) {
736
+ return data.includes("iPad");
737
+ };
738
+ _proto.testAndroid = function testAndroid(data) {
739
+ return data.includes("Android");
740
+ };
741
+ _proto.testMacintosh = function testMacintosh(data) {
742
+ return data.includes("Macintosh");
743
+ };
744
+ _proto.testWindows = function testWindows(data) {
745
+ return data.includes("Windows");
746
+ };
747
+ return UADecoder;
748
+ }();
749
+
750
+ var AlipayMiniprogramParser = /*#__PURE__*/ function() {
751
+ function AlipayMiniprogramParser(info) {
752
+ this.device = {};
753
+ this.parse(info);
754
+ }
755
+ var _proto = AlipayMiniprogramParser.prototype;
756
+ _proto.getDeviceInfo = function getDeviceInfo() {
757
+ return this.device;
758
+ };
759
+ _proto.parse = function parse(info) {
760
+ this.device.platform = info.platform;
761
+ this.device.osVersion = info.system;
762
+ this.device.originalModel = info.model;
763
+ this.device.model = this.getDeviceModel(info.model);
764
+ this.device.level = this.getDeviceLevel(info.performance);
765
+ this.device.sourceData = info;
766
+ };
767
+ _proto.getDeviceModel = function getDeviceModel(model) {
768
+ if (model) {
769
+ var brandList = [
770
+ "Huawei",
771
+ "Xiaomi",
772
+ "samsung",
773
+ "vivo",
774
+ "OPPO"
775
+ ];
776
+ var brand = brandList.find(function(b) {
777
+ return (model != null ? model : "").toLowerCase().startsWith(b.toLowerCase());
778
+ });
779
+ if (brand) {
780
+ return model == null ? void 0 : model.substring(brand.length).trim();
781
+ }
782
+ }
783
+ return model;
784
+ };
785
+ _proto.getDeviceLevel = function getDeviceLevel(level) {
786
+ if (level === void 0) level = "";
787
+ var levelMap = {
788
+ "high": DeviceLevel.High,
789
+ "medium": DeviceLevel.Medium,
790
+ "middle": DeviceLevel.Medium,
791
+ "low": DeviceLevel.Low
792
+ };
793
+ return levelMap[level] || DeviceLevel.Unknown;
794
+ };
795
+ return AlipayMiniprogramParser;
796
+ }();
797
+
798
+ var WechatMiniprogramParser = /*#__PURE__*/ function() {
799
+ function WechatMiniprogramParser(info) {
800
+ this.device = {};
801
+ this.parse(info);
802
+ }
803
+ var _proto = WechatMiniprogramParser.prototype;
804
+ _proto.getDeviceInfo = function getDeviceInfo() {
805
+ return this.device;
806
+ };
807
+ _proto.parse = function parse(info) {
808
+ var osNameMatch = info.system.match(/\w+/);
809
+ if (osNameMatch) {
810
+ this.device.platform = osNameMatch[0].trim();
811
+ }
812
+ var osVersionMatch = info.system.match(/[\d.]+/);
813
+ if (osVersionMatch) {
814
+ this.device.osVersion = osVersionMatch[0].trim();
815
+ }
816
+ if (info.platform === "devtools") {
817
+ var _devtoolNameMap_wechat_info_model;
818
+ var phoneName = (_devtoolNameMap_wechat_info_model = devtoolNameMap.wechat[info.model]) != null ? _devtoolNameMap_wechat_info_model : info.model;
819
+ for(var _iterator = _create_for_of_iterator_helper_loose(infoList.iPhone), _step; !(_step = _iterator()).done;){
820
+ var data = _step.value;
821
+ if (data.name === phoneName) {
822
+ info.model = data.model;
823
+ break;
824
+ }
825
+ }
826
+ }
827
+ if (this.device.platform === "iOS") {
828
+ var modelMatch = info.model.match(/^(.*?)<(.*?)>$/);
829
+ if (modelMatch) {
830
+ this.device.model = modelMatch[2].trim();
831
+ this.device.originalModel = info.model;
832
+ } else {
833
+ this.device.model = info.model;
834
+ }
835
+ } else {
836
+ this.device.model = info.model;
837
+ }
838
+ if (info.benchmarkLevel <= 0) {
839
+ this.device.level = DeviceLevel.Unknown;
840
+ } else if (info.benchmarkLevel <= 10) {
841
+ this.device.level = DeviceLevel.Low;
842
+ } else if (info.benchmarkLevel <= 20) {
843
+ this.device.level = DeviceLevel.Medium;
844
+ } else {
845
+ this.device.level = DeviceLevel.High;
846
+ }
847
+ this.device.memoryMB = info.memorySize;
848
+ this.device.sourceData = info;
849
+ };
850
+ return WechatMiniprogramParser;
851
+ }();
852
+
853
+ var DowngradeJudge = /*#__PURE__*/ function() {
854
+ function DowngradeJudge(options, device) {
855
+ this.options = options;
856
+ this.device = device;
857
+ this.isIOS = false;
858
+ }
859
+ var _proto = DowngradeJudge.prototype;
860
+ _proto.getDowngradeResult = function getDowngradeResult() {
861
+ var _this = this;
862
+ var downgradeCallback = this.options.downgradeCallback;
863
+ if (downgradeCallback) {
864
+ var result = downgradeCallback(this.device);
865
+ if (result) {
866
+ if (!result.reason) {
867
+ result.reason = "downgradeCallback";
868
+ }
869
+ return result;
870
+ }
871
+ }
872
+ this.isIOS = this.device.platform === "iOS";
873
+ this.level = this.getRenderLevel();
874
+ if (this.device.model) {
875
+ var deviceModel = this.device.model.toLowerCase();
876
+ var modelList = this.isIOS ? downgradeModels.iPhone : downgradeModels.android;
877
+ var findModel = modelList.find(function(m) {
878
+ var testModel = m.toLowerCase();
879
+ if (_this.isIOS) {
880
+ return testModel === deviceModel;
881
+ } else {
882
+ return testModel.includes(deviceModel) || deviceModel.includes(testModel);
883
+ }
884
+ });
885
+ if (findModel !== undefined) {
886
+ return {
887
+ downgrade: true,
888
+ level: this.level,
889
+ reason: "Downgrade by model list",
890
+ deviceInfo: this.device
891
+ };
892
+ }
893
+ }
894
+ var osVersionList = this.isIOS ? downgradeVersions.iOS : downgradeVersions.android;
895
+ var findOS = osVersionList.find(function(v) {
896
+ return v === _this.device.osVersion;
897
+ });
898
+ if (findOS !== undefined) {
899
+ return {
900
+ downgrade: true,
901
+ level: this.level,
902
+ reason: "Downgrade by OS version list",
903
+ deviceInfo: this.device
904
+ };
905
+ }
906
+ return {
907
+ downgrade: false,
908
+ level: this.level,
909
+ reason: "",
910
+ deviceInfo: this.device
911
+ };
912
+ };
913
+ _proto.getRenderLevel = function getRenderLevel() {
914
+ if (this.device.level) {
915
+ if (this.device.level === DeviceLevel.High) {
916
+ return spec.RenderLevel.S;
917
+ } else if (this.device.level === DeviceLevel.Medium) {
918
+ return spec.RenderLevel.A;
919
+ } else if (this.device.level === DeviceLevel.Low) {
920
+ return spec.RenderLevel.B;
921
+ }
922
+ }
923
+ if (this.device.memoryMB) {
924
+ if (this.device.memoryMB < 4000) {
925
+ return spec.RenderLevel.B;
926
+ } else if (this.device.memoryMB < 6000) {
927
+ return spec.RenderLevel.A;
928
+ } else {
929
+ return spec.RenderLevel.S;
930
+ }
931
+ }
932
+ if (this.isIOS && this.device.model) {
933
+ if (/iPhone(\d+),/.test(this.device.model)) {
934
+ var gen = +RegExp.$1;
935
+ if (gen <= 9) {
936
+ return spec.RenderLevel.B;
937
+ } else if (gen < 10) {
938
+ return spec.RenderLevel.A;
939
+ } else {
940
+ return spec.RenderLevel.S;
941
+ }
942
+ }
943
+ }
944
+ return this.isIOS ? spec.RenderLevel.S : spec.RenderLevel.B;
945
+ };
946
+ return DowngradeJudge;
947
+ }();
948
+
949
+ var internalPaused = Symbol("@@_inter_pause");
950
+ var hasRegisterEvent = false;
951
+ function getDowngradeResult(options) {
952
+ if (options === void 0) options = {};
953
+ if (!hasRegisterEvent) {
954
+ registerEvent(options);
955
+ hasRegisterEvent = true;
956
+ }
957
+ var mock = options.mock;
958
+ if (mock) {
959
+ return _extends({}, mock, {
960
+ reason: "mock"
961
+ });
962
+ }
963
+ var device = getDeviceInfo(options);
964
+ var judge = new DowngradeJudge(options, device);
965
+ return judge.getDowngradeResult();
966
+ }
967
+ function registerEvent(options) {
968
+ var autoPause = options.autoPause;
969
+ window.addEventListener("unload", function() {
970
+ getActivePlayers().forEach(function(player) {
971
+ return player.dispose();
972
+ });
973
+ });
974
+ if (autoPause) {
975
+ document.addEventListener("pause", pauseAllActivePlayers);
976
+ document.addEventListener("resume", resumePausedPlayers);
977
+ }
978
+ }
979
+ function getDeviceInfo(options) {
980
+ var queryDeviceInMiniApp = options.queryDeviceInMiniApp, deviceInfo = options.deviceInfo;
981
+ if (deviceInfo) {
982
+ return deviceInfo;
983
+ }
984
+ if (queryDeviceInMiniApp) {
985
+ if (isAlipayMiniApp()) {
986
+ // 支付宝小程序
987
+ if (my.canIUse("getSystemInfo")) {
988
+ // https://opendocs.alipay.com/mini/api/system-info
989
+ var info = my.getSystemInfo();
990
+ var parser = new AlipayMiniprogramParser(info);
991
+ return parser.getDeviceInfo();
992
+ } else {
993
+ logger.error("Can't use getSystemInfo in Alipay MiniProgram.");
994
+ }
995
+ }
996
+ if (isWechatMiniApp()) {
997
+ // 微信小程序
998
+ // @ts-expect-error
999
+ if (wx.canIUse("getDeviceInfo")) {
1000
+ // https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getDeviceInfo.html
1001
+ // @ts-expect-error
1002
+ var info1 = wx.getDeviceInfo();
1003
+ var parser1 = new WechatMiniprogramParser(info1);
1004
+ return parser1.getDeviceInfo();
1005
+ } else {
1006
+ logger.error("Can't use getDeviceInfo in WeChat MiniProgram.");
1007
+ }
1008
+ } else {
1009
+ logger.error("Non-mini program environment and try to get device info from user agent.");
1010
+ }
1011
+ }
1012
+ return new UADecoder().getDeviceInfo();
1013
+ }
1014
+ function getDefaultRenderLevel() {
1015
+ return isIOS() ? spec.RenderLevel.S : spec.RenderLevel.B;
1016
+ }
1017
+ function pauseAllActivePlayers(e) {
1018
+ if (e.target === document) {
1019
+ logger.info("Auto pause all players with data offloaded.");
1020
+ var players = getActivePlayers();
1021
+ players.forEach(function(player) {
1022
+ if (!player.paused) {
1023
+ player.pause({
1024
+ offloadTexture: true
1025
+ });
1026
+ // @ts-expect-error
1027
+ player[internalPaused] = true;
1028
+ }
1029
+ });
1030
+ }
1031
+ }
1032
+ function resumePausedPlayers(e) {
1033
+ if (e.target === document) {
1034
+ logger.info("Auto resume all players.");
1035
+ var players = getActivePlayers();
1036
+ players.forEach(function(player) {
1037
+ // @ts-expect-error
1038
+ if (player[internalPaused]) {
1039
+ void player.resume();
1040
+ // @ts-expect-error
1041
+ player[internalPaused] = false;
1042
+ }
1043
+ });
1044
+ }
1045
+ }
1046
+
1047
+ var DowngradePlugin = /*#__PURE__*/ function(AbstractPlugin) {
1048
+ _inherits(DowngradePlugin, AbstractPlugin);
1049
+ function DowngradePlugin() {
1050
+ return AbstractPlugin.apply(this, arguments);
1051
+ }
1052
+ DowngradePlugin.processRawJSON = function processRawJSON(json, options) {
1053
+ if (options === void 0) options = {};
1054
+ return _async_to_generator(function() {
1055
+ var _options_pluginData, downgradeResult, _downgradeResult_renderLevel;
1056
+ return __generator(this, function(_state) {
1057
+ downgradeResult = (_options_pluginData = options.pluginData) == null ? void 0 : _options_pluginData["downgrade"];
1058
+ if (downgradeResult) {
1059
+ if (downgradeResult.downgrade) {
1060
+ throw new Error("Downgraded, reason: " + downgradeResult.reason + ".");
1061
+ }
1062
+ } else {
1063
+ logger.warn("No downgrade result in pluginData of SceneLoadOptions.");
1064
+ }
1065
+ if (!options.renderLevel) {
1066
+ options.renderLevel = (_downgradeResult_renderLevel = downgradeResult == null ? void 0 : downgradeResult.renderLevel) != null ? _downgradeResult_renderLevel : getDefaultRenderLevel();
1067
+ }
1068
+ return [
1069
+ 2
1070
+ ];
1071
+ });
1072
+ })();
1073
+ };
1074
+ return DowngradePlugin;
1075
+ }(AbstractPlugin);
1076
+
1077
+ var version = "2.0.0-alpha.28";
1078
+ registerPlugin("downgrade", DowngradePlugin, VFXItem, true);
1079
+ logger.info("Plugin downgrade version: " + version + ".");
1080
+ if (version !== EFFECTS.version) {
1081
+ console.error("注意:请统一 Downgrade 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Downgrade plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
1082
+ }
1083
+
1084
+ export { AlipayMiniprogramParser, DeviceLevel, UADecoder, WechatMiniprogramParser, getDefaultRenderLevel, getDowngradeResult, version };
1085
+ //# sourceMappingURL=weapp.mjs.map