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