@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.3 → 2.0.0-alpha.30

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.js CHANGED
@@ -3,164 +3,159 @@
3
3
  * Description: Galacean Effects player orientation transformer plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮
6
- * Version: v2.0.0-alpha.3
6
+ * Version: v2.0.0-alpha.30
7
7
  */
8
8
 
9
9
  'use strict';
10
10
 
11
11
  Object.defineProperty(exports, '__esModule', { value: true });
12
12
 
13
- var effects = require('@galacean/effects');
13
+ var EFFECTS = require('@galacean/effects');
14
14
 
15
- /******************************************************************************
16
- Copyright (c) Microsoft Corporation.
17
-
18
- Permission to use, copy, modify, and/or distribute this software for any
19
- purpose with or without fee is hereby granted.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
- PERFORMANCE OF THIS SOFTWARE.
28
- ***************************************************************************** */
29
- /* global Reflect, Promise, SuppressedError, Symbol */
30
-
31
- var extendStatics = function(d, b) {
32
- extendStatics = Object.setPrototypeOf ||
33
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
34
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
35
- return extendStatics(d, b);
36
- };
37
-
38
- function __extends(d, b) {
39
- if (typeof b !== "function" && b !== null)
40
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
41
- extendStatics(d, b);
42
- function __() { this.constructor = d; }
43
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
44
- }
45
-
46
- var __assign = function() {
47
- __assign = Object.assign || function __assign(t) {
48
- for (var s, i = 1, n = arguments.length; i < n; i++) {
49
- s = arguments[i];
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
51
- }
52
- return t;
53
- };
54
- return __assign.apply(this, arguments);
55
- };
56
-
57
- function __read(o, n) {
58
- var m = typeof Symbol === "function" && o[Symbol.iterator];
59
- if (!m) return o;
60
- var i = m.call(o), r, ar = [], e;
61
- try {
62
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
63
- }
64
- catch (error) { e = { error: error }; }
65
- finally {
66
- try {
67
- if (r && !r.done && (m = i["return"])) m.call(i);
68
- }
69
- finally { if (e) throw e.error; }
70
- }
71
- return ar;
72
- }
73
-
74
- function __spreadArray(to, from, pack) {
75
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
76
- if (ar || !(i in from)) {
77
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
78
- ar[i] = from[i];
79
- }
80
- }
81
- return to.concat(ar || Array.prototype.slice.call(from));
82
- }
83
-
84
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
85
- var e = new Error(message);
86
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
- };
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n["default"] = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var EFFECTS__namespace = /*#__PURE__*/_interopNamespace(EFFECTS);
34
+
35
+ function _set_prototype_of(o, p) {
36
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
37
+ o.__proto__ = p;
38
+ return o;
39
+ };
40
+ return _set_prototype_of(o, p);
41
+ }
42
+
43
+ function _inherits(subClass, superClass) {
44
+ if (typeof superClass !== "function" && superClass !== null) {
45
+ throw new TypeError("Super expression must either be null or a function");
46
+ }
47
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
48
+ constructor: {
49
+ value: subClass,
50
+ writable: true,
51
+ configurable: true
52
+ }
53
+ });
54
+ if (superClass) _set_prototype_of(subClass, superClass);
55
+ }
88
56
 
89
- var CompositionTransformerAcceler = /** @class */ (function () {
57
+ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
90
58
  function CompositionTransformerAcceler(composition) {
91
59
  this.composition = composition;
92
60
  this.targets = {};
93
61
  this.records = {};
94
- this.current = {};
95
- this.gammaRange = [-89, 89];
96
- this.betaRange = [-80, 80];
62
+ this.currentPos = {};
63
+ this.currentRot = {};
64
+ this.gammaRange = [
65
+ -89,
66
+ 89
67
+ ];
68
+ this.betaRange = [
69
+ -89,
70
+ 89
71
+ ];
97
72
  }
98
- CompositionTransformerAcceler.prototype.update = function (_a) {
99
- var x = _a.x, y = _a.y;
100
- this.currentEvent = { x: x, y: y };
73
+ var _proto = CompositionTransformerAcceler.prototype;
74
+ _proto.update = function update(param) {
75
+ var x = param.x, y = param.y, beta = param.beta, gamma = param.gamma;
76
+ this.currentEvent = {
77
+ x: x,
78
+ y: y,
79
+ beta: beta,
80
+ gamma: gamma
81
+ };
101
82
  };
102
- CompositionTransformerAcceler.prototype.updateOrientation = function () {
83
+ _proto.updateOrientation = function updateOrientation() {
103
84
  var _this = this;
104
85
  var event = this.currentEvent;
105
86
  if (event) {
106
- Object.getOwnPropertyNames(this.targets).forEach(function (name) {
87
+ Object.getOwnPropertyNames(this.targets).forEach(function(name) {
107
88
  _this.moveLayer(name, event);
108
89
  });
109
90
  }
110
91
  };
111
- CompositionTransformerAcceler.prototype.initComposition = function () {
92
+ _proto.initComposition = function initComposition() {
112
93
  var items = this.composition.items;
113
- for (var i = 0; i < items.length; i++) {
94
+ for(var i = 0; i < items.length; i++){
114
95
  var item = items[i];
115
96
  var target = this.targets[item.name];
116
97
  if (target) {
117
98
  var position = item.transform.position.toArray();
118
- var currentPosition = this.current[item.name];
99
+ var rotation = item.transform.rotation.toArray();
100
+ var currentPosition = this.currentPos[item.name];
101
+ var currentRot = this.currentRot[item.name];
119
102
  this.records[item.name] = {
120
103
  item: item,
121
104
  position: position,
105
+ rotation: rotation
122
106
  };
123
107
  if (currentPosition) {
124
- var _a = __read(currentPosition, 3), x = _a[0], y = _a[1], z = _a[2];
125
- item.transform.setPosition(x, y, z);
108
+ item.transform.setPosition(currentPosition[0], currentPosition[1], currentPosition[2]);
109
+ }
110
+ if (currentRot) {
111
+ item.transform.setRotation(currentRot[0], currentRot[1], currentRot[2]);
126
112
  }
127
113
  }
128
114
  }
129
115
  };
130
- CompositionTransformerAcceler.prototype.addTarget = function (target) {
116
+ _proto.addTarget = function addTarget(target) {
131
117
  this.targets[target.name] = target;
132
118
  };
133
- CompositionTransformerAcceler.prototype.removeTarget = function (name) {
119
+ _proto.removeTarget = function removeTarget(name) {
134
120
  delete this.targets[name];
135
121
  delete this.records[name];
136
122
  };
137
- CompositionTransformerAcceler.prototype.moveLayer = function (name, _a) {
138
- var _b;
139
- var _c;
140
- var x = _a.x, y = _a.y;
141
- var layer = (_c = this.records[name]) === null || _c === void 0 ? void 0 : _c.item;
123
+ _proto.moveLayer = function moveLayer(name, param) {
124
+ var x = param.x, y = param.y, b = param.beta, g = param.gamma;
125
+ var _this_records_name;
126
+ var layer = (_this_records_name = this.records[name]) == null ? void 0 : _this_records_name.item;
142
127
  if (layer) {
143
128
  var initPosition = this.records[name].position;
129
+ var initRotation = this.records[name].rotation;
144
130
  var target = this.targets[name];
145
131
  var beta = clamp(x, this.betaRange), gamma = clamp(y, this.gammaRange);
146
132
  if (target) {
133
+ var _layer_transform, _layer_transform1;
147
134
  var position = [
148
- initPosition[0] + 1.2 * mapRange((beta - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]), target.xMin, target.xMax),
149
- initPosition[1] + 1.2 * mapRange((gamma - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]), target.yMin, target.yMax),
150
- initPosition[2],
135
+ initPosition[0] + 1.2 * mapRange(normalize(beta, this.gammaRange[0], this.gammaRange[1]), target.xMin, target.xMax),
136
+ initPosition[1] + 1.2 * mapRange(normalize(gamma, this.betaRange[0], this.betaRange[1]), target.yMin, target.yMax),
137
+ initPosition[2]
151
138
  ];
152
- (_b = layer.transform).setPosition.apply(_b, __spreadArray([], __read(position), false));
153
- this.current[name] = position.slice();
139
+ var br = normalize(clamp(g * 0.8, this.gammaRange), this.gammaRange[0], this.gammaRange[1]);
140
+ var gr = normalize(clamp(b * 0.8, this.betaRange), this.betaRange[0], this.betaRange[1]);
141
+ var rotation = [
142
+ initRotation[0] + mapRange(gr, target.hMin, target.hMax),
143
+ initRotation[1] + mapRange(br, target.vMin, target.vMax),
144
+ initRotation[2]
145
+ ];
146
+ (_layer_transform = layer.transform).setPosition.apply(_layer_transform, [].concat(position));
147
+ (_layer_transform1 = layer.transform).setRotation.apply(_layer_transform1, [].concat(rotation));
148
+ this.currentPos[name] = position.slice();
149
+ this.currentRot[name] = rotation.slice();
154
150
  }
155
151
  }
156
152
  };
157
153
  return CompositionTransformerAcceler;
158
- }());
154
+ }();
159
155
  function clamp(x, range) {
160
156
  if (x < range[0]) {
161
157
  return range[0];
162
- }
163
- else if (x > range[1]) {
158
+ } else if (x > range[1]) {
164
159
  return range[1];
165
160
  }
166
161
  return x;
@@ -168,9 +163,19 @@ function clamp(x, range) {
168
163
  function mapRange(t, min, max) {
169
164
  return min + (max - min) * t;
170
165
  }
166
+ function normalize(a, min, max) {
167
+ return (a - min) / (max - min);
168
+ }
171
169
 
172
- function getObjectType(obj) {
173
- return Object.prototype.toString.call(obj);
170
+ function _extends() {
171
+ _extends = Object.assign || function assign(target) {
172
+ for(var i = 1; i < arguments.length; i++){
173
+ var source = arguments[i];
174
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
175
+ }
176
+ return target;
177
+ };
178
+ return _extends.apply(this, arguments);
174
179
  }
175
180
 
176
181
  /**
@@ -178,117 +183,59 @@ function getObjectType(obj) {
178
183
  * @internal
179
184
  * @param angleObj 角度数值对象
180
185
  * @param validRange 角度限制值
181
- */
182
- function angleLimit(angleObj, validRange) {
186
+ */ function angleLimit(angleObj, validRange) {
183
187
  var flagAlpha = true;
184
188
  var flagBeta = true;
185
189
  var flagGamma = true;
186
- if (getObjectType(validRange.alpha) === '[object Array]' && validRange.alpha.length >= 2) {
190
+ if (EFFECTS.isArray(validRange.alpha) && validRange.alpha.length >= 2) {
187
191
  var referAlphaA = angleObj.alpha + validRange.alpha[0];
188
192
  var referAlphaB = angleObj.alpha + validRange.alpha[1];
189
193
  referAlphaA = referAlphaA < 0 ? referAlphaA + 360 : referAlphaA;
190
194
  referAlphaB = referAlphaB > 360 ? referAlphaB - 360 : referAlphaB;
191
195
  if (referAlphaA < referAlphaB) {
192
196
  flagAlpha = angleObj.alpha > referAlphaA && angleObj.alpha < referAlphaB;
193
- }
194
- else {
197
+ } else {
195
198
  flagAlpha = angleObj.alpha > referAlphaA || angleObj.alpha < referAlphaB;
196
199
  }
197
200
  }
198
- if (getObjectType(validRange.beta) === '[object Array]' && validRange.beta.length >= 2) {
201
+ if (EFFECTS.isArray(validRange.beta) && validRange.beta.length >= 2) {
199
202
  flagBeta = angleObj.beta >= validRange.beta[0] && angleObj.beta <= validRange.beta[1];
200
203
  }
201
- if (getObjectType(validRange.gamma) === '[object Array]' && validRange.gamma.length >= 2) {
204
+ if (EFFECTS.isArray(validRange.gamma) && validRange.gamma.length >= 2) {
202
205
  flagGamma = angleObj.gamma >= validRange.gamma[0] && angleObj.gamma <= validRange.gamma[1];
203
206
  }
204
207
  return flagAlpha && flagBeta && flagGamma;
205
208
  }
206
209
 
207
- function deepMerge(target, args) {
208
- if (!effects.isObject(target) && !effects.isArray(target)) {
209
- return target;
210
- }
211
- var result = effects.isArray(target) ? __spreadArray([], __read(target), false) : __assign({}, target);
212
- var length = arguments.length;
213
- for (var index = 1; index < length; index++) {
214
- var source = arguments[index] || {};
215
- if (effects.isObject(source)) {
216
- var prop = void 0;
217
- for (prop in source) {
218
- if (source.hasOwnProperty(prop)) {
219
- if (effects.isObject(result[prop]) && effects.isObject(source[prop])) {
220
- result[prop] = deepMerge(result[prop], source[prop]);
221
- }
222
- else if (effects.isObject(source[prop])) {
223
- result[prop] = deepMerge(source[prop]);
224
- }
225
- else if (effects.isArray(source[prop])) {
226
- result[prop] = deepMerge(source[prop]);
227
- }
228
- else {
229
- result[prop] = source[prop];
230
- }
231
- }
232
- }
233
- for (prop in result) {
234
- if (effects.isObject(result[prop]) &&
235
- result.hasOwnProperty(prop) &&
236
- !source.hasOwnProperty(prop)) {
237
- result[prop] = deepMerge(result[prop]);
238
- }
239
- }
240
- }
241
- }
242
- if (length === 1) {
243
- for (var prop in result) {
244
- if (effects.isObject(result[prop]) && result.hasOwnProperty(prop)) {
245
- result[prop] = deepMerge(result[prop]);
246
- }
247
- }
248
- }
249
- return result;
250
- }
251
-
252
- function isIOS() {
253
- var str = navigator.userAgent.toLowerCase();
254
- var ver = str.match(/cpu (iphone )?os (.*?) like mac os/);
255
- return ver ? parseInt(ver[2], 10) : 0;
256
- }
257
-
258
210
  /**
259
211
  * 稳定区间
260
- */
261
- var STABLE_RANGE = 3;
212
+ */ var STABLE_RANGE = 3;
262
213
  /**
263
214
  * 每次增幅的最大值
264
- */
265
- var MAX_CHANGE = 5;
215
+ */ var MAX_CHANGE = 5;
266
216
  /**
267
217
  * 每次增幅的最小值
268
- */
269
- var MIN_CHANGE = 1;
218
+ */ var MIN_CHANGE = 1;
270
219
  /**
271
220
  * 数据缓存队列的长度
272
- */
273
- var VALUE_POOL_LENGTH = 5;
221
+ */ var VALUE_POOL_LENGTH = 5;
274
222
  /**
275
223
  * 滤波方法
276
- */
277
- var Filtering = /** @class */ (function () {
224
+ */ var Filtering = /*#__PURE__*/ function() {
278
225
  function Filtering(options) {
279
- if (options === void 0) { options = {}; }
226
+ if (options === void 0) options = {};
280
227
  this.options = options;
281
228
  this.lastValue = 0;
282
229
  this.valuePool = [];
283
230
  }
231
+ var _proto = Filtering.prototype;
284
232
  /**
285
- * 0deg 左右保持一定的稳定区间 STABLE_RANGE
286
- * - 小于 STABLE_RANGE 的算 0
287
- * - 大于 STABLE_RANGE 的减去 STABLE_RANGE
288
- * @param value - 输入值
289
- * @returns
290
- */
291
- Filtering.prototype.stableFix = function (value) {
233
+ * 0deg 左右保持一定的稳定区间 STABLE_RANGE
234
+ * - 小于 STABLE_RANGE 的算 0
235
+ * - 大于 STABLE_RANGE 的减去 STABLE_RANGE
236
+ * @param value - 输入值
237
+ * @returns
238
+ */ _proto.stableFix = function stableFix(value) {
292
239
  var stableRange = this.options.stableRange || STABLE_RANGE;
293
240
  if (Math.abs(value) < stableRange) {
294
241
  return 0;
@@ -296,13 +243,12 @@ var Filtering = /** @class */ (function () {
296
243
  return value > stableRange ? value - stableRange : value + stableRange;
297
244
  };
298
245
  /**
299
- * 变幅限制
300
- * - 最大变化 MAX_CHANGE
301
- * - 最小变化 MIN_CHANGE
302
- * @param value
303
- * @returns
304
- */
305
- Filtering.prototype.changeLimit = function (value) {
246
+ * 变幅限制
247
+ * - 最大变化 MAX_CHANGE
248
+ * - 最小变化 MIN_CHANGE
249
+ * @param value
250
+ * @returns
251
+ */ _proto.changeLimit = function changeLimit(value) {
306
252
  var lastValue = this.lastValue;
307
253
  var result = value;
308
254
  if (Math.abs(value - lastValue) > MAX_CHANGE) {
@@ -314,21 +260,20 @@ var Filtering = /** @class */ (function () {
314
260
  this.lastValue = result;
315
261
  return result;
316
262
  };
317
- Filtering.prototype.linearRegressionMedian = function (value) {
263
+ _proto.linearRegressionMedian = function linearRegressionMedian(value) {
318
264
  // 在队列中装载数据,达到队列阀值长度时开始计算
319
265
  this.valuePool.push(value);
320
266
  var result;
321
267
  if (this.valuePool.length >= VALUE_POOL_LENGTH) {
322
268
  result = getLinearRegressionFixedVal(this.valuePool);
323
269
  this.valuePool.shift();
324
- }
325
- else {
270
+ } else {
326
271
  result = this.lastValue;
327
272
  }
328
273
  return result;
329
274
  };
330
275
  return Filtering;
331
- }());
276
+ }();
332
277
  // 计算出线性回归参数
333
278
  function linearRegression(x, y) {
334
279
  var result = {};
@@ -338,30 +283,30 @@ function linearRegression(x, y) {
338
283
  var sumXY = 0;
339
284
  var sumXX = 0;
340
285
  var sumYY = 0;
341
- for (var i = 0; i < y.length; i++) {
286
+ for(var i = 0; i < y.length; i++){
342
287
  sumX += x[i];
343
288
  sumY += y[i];
344
- sumXY += (x[i] * y[i]);
345
- sumXX += (x[i] * x[i]);
346
- sumYY += (y[i] * y[i]);
289
+ sumXY += x[i] * y[i];
290
+ sumXX += x[i] * x[i];
291
+ sumYY += y[i] * y[i];
347
292
  }
348
293
  var avgX = sumX / n;
349
294
  var avgY = sumY / n;
350
- result['a'] = (sumXY - n * avgX * avgY) / (sumXX - n * avgX * avgX);
351
- result['b'] = avgY - result.a * avgX;
352
- result['miss'] = Math.pow((n * sumXY - sumX * sumY) / Math.sqrt((n * sumXX - sumX * sumX) * (n * sumYY - sumY * sumY)), 2);
295
+ result["a"] = (sumXY - n * avgX * avgY) / (sumXX - n * avgX * avgX);
296
+ result["b"] = avgY - result.a * avgX;
297
+ result["miss"] = Math.pow((n * sumXY - sumX * sumY) / Math.sqrt((n * sumXX - sumX * sumX) * (n * sumYY - sumY * sumY)), 2);
353
298
  return result;
354
299
  }
355
300
  // 生成线性回归函数 F(x) = ax + b
356
301
  function createLinearRegressionFx(values) {
357
302
  var x = [];
358
303
  var y = [];
359
- values.forEach(function (item, index) {
304
+ values.forEach(function(item, index) {
360
305
  x.push(index); // 数据是连续的,所以直接取数组下标为 x
361
306
  y.push(item);
362
307
  });
363
308
  var key = linearRegression(x, y);
364
- return function (x) {
309
+ return function(x) {
365
310
  return key.a * x + key.b;
366
311
  };
367
312
  }
@@ -369,14 +314,14 @@ function createLinearRegressionFx(values) {
369
314
  function getLinearRegressionFixedVal(valuePool) {
370
315
  var fx = createLinearRegressionFx(valuePool);
371
316
  // 这个迭代修正很重要
372
- valuePool = valuePool.map(function (item, index) {
317
+ valuePool = valuePool.map(function(item, index) {
373
318
  return fx(index);
374
319
  });
375
320
  return fx(valuePool.length / 2);
376
321
  }
377
322
 
378
- var useJSBridge = isIOS() && typeof window.AlipayJSBridge !== 'undefined';
379
- var useWindVane = typeof window.WindVane !== 'undefined';
323
+ var useJSBridge = EFFECTS.isIOSByUA() && typeof window.AlipayJSBridge !== "undefined";
324
+ var useWindVane = typeof window.WindVane !== "undefined";
380
325
  // 默认参数
381
326
  var defaultOptions = {
382
327
  X: true,
@@ -386,31 +331,49 @@ var defaultOptions = {
386
331
  relativeBeta: false,
387
332
  relativeGamma: false,
388
333
  validRange: {
389
- alpha: [-60, 60],
390
- beta: [-60, 180],
391
- gamma: [-89, 89],
334
+ alpha: [
335
+ -60,
336
+ 60
337
+ ],
338
+ beta: [
339
+ -60,
340
+ 180
341
+ ],
342
+ gamma: [
343
+ -89,
344
+ 89
345
+ ]
392
346
  },
393
- stableRange: 3,
347
+ stableRange: 3
394
348
  };
395
- var DeviceOrientation = /** @class */ (function () {
349
+ var DeviceOrientation = /*#__PURE__*/ function() {
396
350
  function DeviceOrientation(options) {
397
- if (options === void 0) { options = {}; }
351
+ if (options === void 0) options = {};
398
352
  this.lastX = 0;
399
353
  this.lastY = 0;
400
354
  this.prevAcceler = {
401
355
  x: 0,
402
356
  y: 0,
403
- z: 0,
357
+ z: 0
404
358
  };
405
359
  this.stoped = false;
406
- this.options = deepMerge(defaultOptions, options);
360
+ // 模拟简单的 deep merge
361
+ var validRange = _extends({}, defaultOptions.validRange, options.validRange);
362
+ var mergeOptions = _extends({}, defaultOptions, options);
363
+ mergeOptions.validRange = validRange;
364
+ this.options = mergeOptions;
407
365
  var stableRange = this.options.stableRange;
408
- this.filterX = new Filtering({ stableRange: stableRange });
409
- this.filterY = new Filtering({ stableRange: stableRange });
366
+ this.filterX = new Filtering({
367
+ stableRange: stableRange
368
+ });
369
+ this.filterY = new Filtering({
370
+ stableRange: stableRange
371
+ });
410
372
  }
411
- DeviceOrientation.prototype.watch = function (callback) {
373
+ var _proto = DeviceOrientation.prototype;
374
+ _proto.watch = function watch(callback) {
412
375
  var _this = this;
413
- if (typeof callback !== 'function') {
376
+ if (typeof callback !== "function") {
414
377
  return;
415
378
  }
416
379
  // 目前只能绑定一个方法,此处可以扩展成一个方法队列
@@ -419,66 +382,67 @@ var DeviceOrientation = /** @class */ (function () {
419
382
  }
420
383
  var timefragment = 0; // 时间片计时
421
384
  var nowts = 0; // 当前时间
422
- var referGamma = 0; // 初始化角度,作为单独一个用户的空间旋转的参照
423
- var referBeta = 0;
385
+ // 初始化角度,作为单独一个用户的空间旋转的参照
386
+ var referGamma = NaN, referBeta = NaN;
424
387
  var alpha;
425
388
  var beta;
426
389
  var gamma;
427
- var gammaFixed;
428
- var betaFixed;
429
390
  var isInValidDegRange;
430
391
  var x; // 最终输出的 x
431
392
  var y; // 最终输出的 y
432
- var handleWatch = function (e) {
393
+ var handleWatch = function(e) {
433
394
  if (_this.stoped) {
434
395
  return;
435
396
  }
436
397
  alpha = e.alpha; // 垂直于屏幕的轴 0 ~ 360
437
398
  beta = e.beta; // 横向 X 轴 -180 ~ 180
438
399
  gamma = e.gamma; // 纵向 Y 轴 -90 ~ 90
439
- if (!referBeta) {
440
- referBeta = beta || 0;
441
- }
442
- if (!referGamma) {
443
- referGamma = gamma || 0;
444
- }
445
- //
446
400
  isInValidDegRange = angleLimit.call(_this, {
447
401
  alpha: alpha,
448
402
  beta: beta,
449
- gamma: gamma,
403
+ gamma: gamma
450
404
  }, _this.options.validRange);
405
+ if (isNaN(referGamma)) {
406
+ referGamma = gamma;
407
+ _this.filterX.lastValue = gamma;
408
+ }
409
+ if (isNaN(referBeta)) {
410
+ referBeta = beta;
411
+ _this.filterY.lastValue = beta;
412
+ }
451
413
  if (isInValidDegRange) {
452
414
  // 最终结果值
453
415
  if (_this.options.X) {
454
- gammaFixed = gamma - referGamma;
455
- x = _this.options.relativeGamma ? gammaFixed : gamma;
416
+ x = _this.options.relativeGamma ? gamma - referGamma : gamma;
456
417
  x = _this.filterX.stableFix(x);
457
418
  x = _this.filterX.changeLimit(x);
458
419
  x = _this.filterX.linearRegressionMedian(+x);
459
- }
460
- else {
420
+ } else {
461
421
  x = 0;
462
422
  }
463
423
  if (_this.options.Y) {
464
- // beta 相对 referBeta 的角度
465
- betaFixed = beta - referBeta;
466
- y = _this.options.relativeBeta ? betaFixed : beta;
424
+ y = _this.options.relativeBeta ? beta - referBeta : beta;
467
425
  y = _this.filterY.stableFix(y);
468
426
  y = _this.filterY.changeLimit(y);
469
427
  y = _this.filterY.linearRegressionMedian(+y);
470
- }
471
- else {
428
+ } else {
472
429
  y = 0;
473
430
  }
474
431
  if (_this.isValid(x, y)) {
475
432
  if (_this.options.useRequestAnimationFrame) {
476
- window.requestAnimationFrame(function () {
477
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
433
+ window.requestAnimationFrame(function() {
434
+ callback(x, y, {
435
+ alpha: alpha,
436
+ beta: y - referBeta,
437
+ gamma: x - referGamma
438
+ });
439
+ });
440
+ } else {
441
+ callback(x, y, {
442
+ alpha: alpha,
443
+ beta: y - referBeta,
444
+ gamma: x - referGamma
478
445
  });
479
- }
480
- else {
481
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
482
446
  }
483
447
  _this.lastX = x;
484
448
  _this.lastY = y;
@@ -489,51 +453,52 @@ var DeviceOrientation = /** @class */ (function () {
489
453
  this.stoped = false;
490
454
  if (useWindVane) {
491
455
  switchWindVane(true, this.options.interval);
492
- this.watchListener = function (e) {
493
- if ('param' in e) {
494
- var _a = e.param, x_1 = _a.x, y_1 = _a.y, z = _a.z;
456
+ this.watchListener = function(e) {
457
+ if ("param" in e) {
458
+ var _e_param = e.param, x = _e_param.x, y = _e_param.y, z = _e_param.z;
495
459
  // 即使手机没动,也会不停触发,所以这里加个判断,值相等则不调用回调
496
- if (x_1 === _this.prevAcceler.x && y_1 === _this.prevAcceler.y && z === _this.prevAcceler.z) {
460
+ if (x === _this.prevAcceler.x && y === _this.prevAcceler.y && z === _this.prevAcceler.z) {
497
461
  return;
498
462
  }
499
- _this.prevAcceler = { x: x_1, y: y_1, z: z };
463
+ _this.prevAcceler = {
464
+ x: x,
465
+ y: y,
466
+ z: z
467
+ };
500
468
  var evt = {
501
469
  alpha: +z * 180,
502
- beta: +y_1 * -90,
503
- gamma: +x_1 * 90,
470
+ beta: +y * -90,
471
+ gamma: +x * 90
504
472
  };
505
473
  handleWatch(evt);
506
474
  }
507
475
  };
508
- document.addEventListener('motion.gyro', this.watchListener, false);
509
- }
510
- else if (useJSBridge) {
476
+ document.addEventListener("motion.gyro", this.watchListener, false);
477
+ } else if (useJSBridge && !EFFECTS.isMiniProgram()) {
511
478
  switchIOSEvent(true, this.options.interval / 1000);
512
- this.watchListener = function (e) {
513
- if (e && 'data' in e) {
479
+ this.watchListener = function(e) {
480
+ if (e && "data" in e) {
514
481
  /*
515
- data:
516
- {
517
- data: {
518
- x: 0.0, // gamma -1 ~ 1
519
- y: 0.0, // beta -1 ~ 1
520
- z: 0.0, // alpha
521
- }
522
- }
523
- */
524
- var _a = e.data, x_2 = _a.x, y_2 = _a.y, z = _a.z;
482
+ data:
483
+ {
484
+ data: {
485
+ x: 0.0, // gamma -1 ~ 1
486
+ y: 0.0, // beta -1 ~ 1
487
+ z: 0.0, // alpha
488
+ }
489
+ }
490
+ */ var _e_data = e.data, x = _e_data.x, y = _e_data.y, z = _e_data.z;
525
491
  var evt = {
526
492
  alpha: z * 180,
527
- beta: y_2 * -90,
528
- gamma: x_2 * 90,
493
+ beta: y * -90,
494
+ gamma: x * 90
529
495
  };
530
496
  handleWatch(evt);
531
497
  }
532
498
  };
533
- document.addEventListener('accelerometerChange', this.watchListener, false);
534
- }
535
- else {
536
- this.watchListener = function (e) {
499
+ document.addEventListener("accelerometerChange", this.watchListener, false);
500
+ } else {
501
+ this.watchListener = function(e) {
537
502
  nowts = new Date().getTime();
538
503
  // 控制时间片
539
504
  if (nowts - timefragment >= _this.options.interval) {
@@ -541,80 +506,87 @@ var DeviceOrientation = /** @class */ (function () {
541
506
  handleWatch(e);
542
507
  }
543
508
  };
544
- window.addEventListener('deviceorientation', this.watchListener, false);
509
+ window.addEventListener("deviceorientation", this.watchListener, false);
545
510
  }
546
511
  };
547
- DeviceOrientation.prototype.unWatch = function () {
548
- effects.assertExist(this.watchListener);
512
+ _proto.unWatch = function unWatch() {
513
+ EFFECTS.assertExist(this.watchListener);
549
514
  if (useWindVane) {
550
515
  switchWindVane(false);
551
- document.removeEventListener('motion.gyro', this.watchListener);
552
- }
553
- else if (useJSBridge) {
516
+ document.removeEventListener("motion.gyro", this.watchListener);
517
+ } else if (useJSBridge) {
554
518
  switchIOSEvent(false);
555
- document.removeEventListener('accelerometerChange', this.watchListener);
556
- }
557
- else {
558
- window.removeEventListener('deviceorientation', this.watchListener);
519
+ document.removeEventListener("accelerometerChange", this.watchListener);
520
+ } else {
521
+ window.removeEventListener("deviceorientation", this.watchListener);
559
522
  }
560
523
  this.stoped = true;
561
524
  this.watchListener = undefined;
562
525
  };
563
- DeviceOrientation.prototype.pause = function () {
526
+ _proto.pause = function pause() {
564
527
  this.stoped = true;
565
528
  if (useJSBridge) {
566
529
  switchIOSEvent(false);
567
530
  }
568
531
  };
569
- DeviceOrientation.prototype.continue = function () {
532
+ _proto.continue = function _continue() {
570
533
  this.stoped = false;
571
534
  if (useJSBridge) {
572
535
  switchIOSEvent(true, this.options.interval / 1000);
573
536
  }
574
537
  };
575
- DeviceOrientation.prototype.isValid = function (x, y) {
538
+ _proto.isValid = function isValid(x, y) {
576
539
  // 判断是否和上次的值一样,检测有没有变
577
540
  return this.lastX !== x || this.lastY !== y;
578
541
  };
579
542
  return DeviceOrientation;
580
- }());
543
+ }();
581
544
  // 开启/关闭 iOS 的陀螺仪监听
582
545
  function switchIOSEvent(open, interval) {
583
- window.AlipayJSBridge.call('watchShake', {
546
+ window.AlipayJSBridge.call("watchShake", {
584
547
  monitorGyroscope: false,
585
548
  monitorAccelerometer: !!open,
586
- interval: !open ? 10 : parseFloat(interval.toFixed(3)),
587
- }, function () { });
549
+ interval: !open ? 10 : parseFloat(interval.toFixed(3))
550
+ }, function() {});
588
551
  }
589
552
  function switchWindVane(open, interval) {
590
553
  var params = {
591
554
  // 是开启还是关闭陀螺仪的监听
592
555
  on: open,
593
556
  // 陀螺仪事件的时间间隔
594
- frequency: interval,
557
+ frequency: interval
595
558
  };
596
- window.WindVane.call('WVMotion', 'listenGyro', params, function (e) {
597
- console.info('call WVMotion success');
598
- }, function (e) {
599
- console.error('call WVMotion failed:' + JSON.stringify(e));
559
+ window.WindVane.call("WVMotion", "listenGyro", params, function(e) {
560
+ console.info("Call WVMotion success.");
561
+ }, function(e) {
562
+ console.error("Call WVMotion failed: " + JSON.stringify(e) + ".");
600
563
  });
601
564
  }
602
565
 
603
566
  /**
604
567
  *
605
- */
606
- var OrientationAdapterAcceler = /** @class */ (function () {
568
+ */ var OrientationAdapterAcceler = /*#__PURE__*/ function() {
607
569
  function OrientationAdapterAcceler() {
608
570
  this.transformers = [];
609
571
  this.connected = false;
610
572
  this.accelerMotion = null;
611
573
  this.validRange = {
612
- alpha: [-60, 60],
613
- beta: [-80, 80],
614
- gamma: [-89, 89], // 左右翻转
574
+ alpha: [
575
+ -60,
576
+ 60
577
+ ],
578
+ beta: [
579
+ -80,
580
+ 80
581
+ ],
582
+ gamma: [
583
+ -89,
584
+ 89
585
+ ]
615
586
  };
616
587
  }
617
- OrientationAdapterAcceler.prototype.connect = function () {
588
+ var _proto = OrientationAdapterAcceler.prototype;
589
+ _proto.connect = function connect() {
618
590
  var _this = this;
619
591
  if (!this.connected) {
620
592
  this.accelerMotion = new DeviceOrientation({
@@ -625,37 +597,41 @@ var OrientationAdapterAcceler = /** @class */ (function () {
625
597
  relativeBeta: false,
626
598
  relativeGamma: false,
627
599
  validRange: this.validRange,
628
- stableRange: 3, // 稳定区间
600
+ stableRange: 3
629
601
  });
630
- this.accelerMotion.watch(function (x, y) {
602
+ this.accelerMotion.watch(function(x, y, param) {
603
+ var beta = param.beta, gamma = param.gamma;
631
604
  var motion = {
632
605
  x: x,
633
606
  y: y,
607
+ beta: beta,
608
+ gamma: gamma
634
609
  };
635
610
  _this.dispatchMotion(motion);
636
611
  });
637
612
  }
638
613
  this.connected = true;
639
614
  };
640
- OrientationAdapterAcceler.prototype.disconnect = function () {
615
+ _proto.disconnect = function disconnect() {
641
616
  if (this.accelerMotion) {
642
617
  this.accelerMotion.unWatch();
643
618
  }
644
619
  this.connected = false;
645
620
  };
646
621
  /**
647
- *
648
- * @param motion
649
- */
650
- OrientationAdapterAcceler.prototype.dispatchMotion = function (motion) {
651
- this.transformers.forEach(function (t) { return t.update(motion); });
652
- };
653
- OrientationAdapterAcceler.prototype.addTransformer = function (transformer) {
622
+ *
623
+ * @param motion
624
+ */ _proto.dispatchMotion = function dispatchMotion(motion) {
625
+ this.transformers.forEach(function(t) {
626
+ return t.update(motion);
627
+ });
628
+ };
629
+ _proto.addTransformer = function addTransformer(transformer) {
654
630
  if (!this.transformers.includes(transformer)) {
655
631
  this.transformers.push(transformer);
656
632
  }
657
633
  };
658
- OrientationAdapterAcceler.prototype.removeTransformer = function (transformer) {
634
+ _proto.removeTransformer = function removeTransformer(transformer) {
659
635
  var index = this.transformers.indexOf(transformer);
660
636
  if (index > -1) {
661
637
  this.transformers.splice(index, 1);
@@ -663,7 +639,7 @@ var OrientationAdapterAcceler = /** @class */ (function () {
663
639
  return this.transformers.length === 0;
664
640
  };
665
641
  return OrientationAdapterAcceler;
666
- }());
642
+ }();
667
643
  var adapter;
668
644
  function getAccelerAdapter() {
669
645
  if (!adapter) {
@@ -672,72 +648,74 @@ function getAccelerAdapter() {
672
648
  return adapter;
673
649
  }
674
650
 
675
- var OrientationPluginLoader = /** @class */ (function (_super) {
676
- __extends(OrientationPluginLoader, _super);
651
+ var OrientationPluginLoader = /*#__PURE__*/ function(AbstractPlugin) {
652
+ _inherits(OrientationPluginLoader, AbstractPlugin);
677
653
  function OrientationPluginLoader() {
678
- var _this = _super !== null && _super.apply(this, arguments) || this;
654
+ var _this;
655
+ _this = AbstractPlugin.apply(this, arguments) || this;
679
656
  _this.order = 90;
680
657
  _this.adapter = null;
681
- _this.handleConnect = function () {
682
- var _a;
658
+ _this.handleConnect = function() {
683
659
  if (!closeManually) {
684
- (_a = _this.adapter) === null || _a === void 0 ? void 0 : _a.connect();
660
+ var _this_adapter;
661
+ (_this_adapter = _this.adapter) == null ? void 0 : _this_adapter.connect();
685
662
  }
686
663
  };
687
- _this.handleDisconnect = function () {
688
- var _a;
689
- (_a = _this.adapter) === null || _a === void 0 ? void 0 : _a.disconnect();
664
+ _this.handleDisconnect = function() {
665
+ var _this_adapter;
666
+ (_this_adapter = _this.adapter) == null ? void 0 : _this_adapter.disconnect();
690
667
  };
691
668
  return _this;
692
669
  }
693
- OrientationPluginLoader.prototype.onCompositionConstructed = function () {
694
- var _a;
670
+ var _proto = OrientationPluginLoader.prototype;
671
+ _proto.onCompositionConstructed = function onCompositionConstructed() {
672
+ var _this_adapter;
695
673
  this.adapter = getAdapter();
696
- (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.connect();
674
+ (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.connect();
697
675
  this.bindAccelerDocumentEvent();
698
676
  };
699
- OrientationPluginLoader.prototype.onCompositionReset = function (composition) {
700
- var _a;
677
+ _proto.onCompositionReset = function onCompositionReset(composition) {
678
+ var _this_adapter;
701
679
  var transformer = composition.loaderData.deviceTransformer = new CompositionTransformerAcceler(composition);
702
- (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.addTransformer(transformer);
680
+ (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.addTransformer(transformer);
703
681
  };
704
- OrientationPluginLoader.prototype.onCompositionUpdate = function (composition) {
682
+ _proto.onCompositionUpdate = function onCompositionUpdate(composition) {
705
683
  var transformer = composition.loaderData.deviceTransformer;
706
684
  if (transformer) {
707
685
  transformer.updateOrientation();
708
686
  }
709
687
  };
710
- OrientationPluginLoader.prototype.onCompositionDestroyed = function (composition) {
711
- var _a, _b;
712
- var empty = (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.removeTransformer(composition.loaderData.deviceTransformer);
688
+ _proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {
689
+ var _this_adapter;
690
+ var empty = (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.removeTransformer(composition.loaderData.deviceTransformer);
713
691
  if (empty) {
714
- (_b = this.adapter) === null || _b === void 0 ? void 0 : _b.disconnect();
692
+ var _this_adapter1;
693
+ (_this_adapter1 = this.adapter) == null ? void 0 : _this_adapter1.disconnect();
715
694
  }
716
695
  };
717
- OrientationPluginLoader.prototype.bindAccelerDocumentEvent = function () {
696
+ _proto.bindAccelerDocumentEvent = function bindAccelerDocumentEvent() {
718
697
  this.unbindAccelerDocumentEvent(); // 保证全局只监听一份
719
- document.addEventListener('resume', this.handleConnect, false);
720
- document.addEventListener('pause', this.handleDisconnect, false);
721
- document.addEventListener('back', this.handleDisconnect, false);
698
+ document.addEventListener("resume", this.handleConnect, false);
699
+ document.addEventListener("pause", this.handleDisconnect, false);
700
+ document.addEventListener("back", this.handleDisconnect, false);
722
701
  };
723
- OrientationPluginLoader.prototype.unbindAccelerDocumentEvent = function () {
724
- document.removeEventListener('resume', this.handleConnect);
725
- document.removeEventListener('pause', this.handleDisconnect);
726
- document.removeEventListener('back', this.handleDisconnect);
702
+ _proto.unbindAccelerDocumentEvent = function unbindAccelerDocumentEvent() {
703
+ document.removeEventListener("resume", this.handleConnect);
704
+ document.removeEventListener("pause", this.handleDisconnect);
705
+ document.removeEventListener("back", this.handleDisconnect);
727
706
  };
728
- OrientationPluginLoader.prototype.dispose = function () {
707
+ _proto.dispose = function dispose() {
729
708
  getAdapter().disconnect();
730
709
  this.unbindAccelerDocumentEvent();
731
710
  };
732
711
  return OrientationPluginLoader;
733
- }(effects.AbstractPlugin));
712
+ }(EFFECTS.AbstractPlugin);
734
713
  // 是否是手动关闭,如果是,那么 resume 时不要恢复
735
714
  var closeManually = false;
736
715
  /**
737
716
  *
738
717
  * @returns
739
- */
740
- function getAdapter() {
718
+ */ function getAdapter() {
741
719
  // 运动感应类型(默认使用加速度,Native 环境使用陀螺仪)
742
720
  return getAccelerAdapter();
743
721
  }
@@ -750,63 +728,83 @@ function openDeviceMotion() {
750
728
  getAdapter().connect();
751
729
  }
752
730
 
753
- var OrientationComponent = /** @class */ (function (_super) {
754
- __extends(OrientationComponent, _super);
731
+ function __decorate(decorators, target, key, desc) {
732
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
733
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
734
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
735
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
736
+ }
737
+ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
738
+ var e = new Error(message);
739
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
740
+ };
741
+
742
+ exports.OrientationComponent = /*#__PURE__*/ function(ItemBehaviour) {
743
+ _inherits(OrientationComponent, ItemBehaviour);
755
744
  function OrientationComponent() {
756
- return _super !== null && _super.apply(this, arguments) || this;
745
+ return ItemBehaviour.apply(this, arguments);
757
746
  }
758
- OrientationComponent.prototype.fromData = function (data) {
759
- _super.prototype.fromData.call(this, data);
760
- var targets = data.content.options.targets;
747
+ var _proto = OrientationComponent.prototype;
748
+ _proto.fromData = function fromData(data) {
749
+ ItemBehaviour.prototype.fromData.call(this, data);
750
+ var targets = data.options.targets;
761
751
  if (targets) {
762
- this.targets = targets.map(function (t) { return ({
763
- name: t.name,
764
- xMin: +t.xMin || 0,
765
- yMin: +t.yMin || 0,
766
- xMax: +t.xMax || 0,
767
- yMax: +t.yMax || 0,
768
- }); });
752
+ this.targets = targets.map(function(t) {
753
+ return {
754
+ name: t.name,
755
+ xMin: +t.xMin || 0,
756
+ yMin: +t.yMin || 0,
757
+ xMax: +t.xMax || 0,
758
+ yMax: +t.yMax || 0,
759
+ vMin: +t.vMin || 0,
760
+ hMin: +t.hMin || 0,
761
+ vMax: +t.vMax || 0,
762
+ hMax: +t.hMax || 0
763
+ };
764
+ });
769
765
  }
770
766
  };
771
- OrientationComponent.prototype.start = function () {
772
- var _a, _b;
773
- var transformer = (_a = this.item.composition) === null || _a === void 0 ? void 0 : _a.loaderData.deviceTransformer;
767
+ _proto.start = function start() {
768
+ var _this_item_composition;
769
+ var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
774
770
  if (transformer) {
775
- (_b = this.targets) === null || _b === void 0 ? void 0 : _b.forEach(function (target) { return transformer.addTarget(target); });
771
+ var _this_targets;
772
+ (_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
773
+ return transformer.addTarget(target);
774
+ });
776
775
  transformer.initComposition();
777
776
  }
778
777
  };
779
- OrientationComponent.prototype.update = function (dt) {
780
- var _a;
781
- var transformer = (_a = this.item.composition) === null || _a === void 0 ? void 0 : _a.loaderData.deviceTransformer;
778
+ _proto.update = function update(dt) {
779
+ var _this_item_composition;
780
+ var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
782
781
  if (transformer) {
783
782
  transformer.updateOrientation();
784
783
  }
785
784
  };
786
- OrientationComponent.prototype.onDestroy = function () {
785
+ _proto.onDestroy = function onDestroy() {
787
786
  var _this = this;
788
- var _a;
789
- (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { var _a, _b; return (_b = (_a = _this.item.composition) === null || _a === void 0 ? void 0 : _a.loaderData.deviceTransformer) === null || _b === void 0 ? void 0 : _b.removeTarget(target.name); });
787
+ var _this_targets;
788
+ (_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
789
+ var _this_item_composition_loaderData_deviceTransformer, _this_item_composition;
790
+ return (_this_item_composition = _this.item.composition) == null ? void 0 : (_this_item_composition_loaderData_deviceTransformer = _this_item_composition.loaderData.deviceTransformer) == null ? void 0 : _this_item_composition_loaderData_deviceTransformer.removeTarget(target.name);
791
+ });
790
792
  };
791
793
  return OrientationComponent;
792
- }(effects.ItemBehaviour));
794
+ }(EFFECTS.ItemBehaviour);
795
+ exports.OrientationComponent = __decorate([
796
+ EFFECTS.effectsClass("OrientationComponent")
797
+ ], exports.OrientationComponent);
793
798
 
794
- var TransformVFXItem = /** @class */ (function (_super) {
795
- __extends(TransformVFXItem, _super);
796
- function TransformVFXItem(engine, props) {
797
- var _this = _super.call(this, engine, props) || this;
798
- var component = _this.addComponent(OrientationComponent);
799
- component.fromData(props);
800
- return _this;
801
- }
802
- return TransformVFXItem;
803
- }(effects.VFXItem));
804
-
805
- effects.registerPlugin('orientation-transformer', OrientationPluginLoader, TransformVFXItem);
806
- var version = "2.0.0-alpha.3";
807
- effects.logger.info('plugin orientation transformer version: ' + version);
799
+ EFFECTS.registerPlugin("orientation-transformer", OrientationPluginLoader, EFFECTS.VFXItem);
800
+ var version = "2.0.0-alpha.30";
801
+ EFFECTS.logger.info("Plugin orientation transformer version: " + version + ".");
802
+ if (version !== EFFECTS__namespace.version) {
803
+ console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
804
+ }
808
805
 
809
806
  exports.OrientationAdapterAcceler = OrientationAdapterAcceler;
807
+ exports.OrientationPluginLoader = OrientationPluginLoader;
810
808
  exports.closeDeviceMotion = closeDeviceMotion;
811
809
  exports.getAdapter = getAdapter;
812
810
  exports.openDeviceMotion = openDeviceMotion;