@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.2 → 2.0.0-alpha.21

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.2
6
+ * Version: v2.0.0-alpha.21
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,6 +163,20 @@ 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
+ }
169
+
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);
179
+ }
171
180
 
172
181
  function getObjectType(obj) {
173
182
  return Object.prototype.toString.call(obj);
@@ -178,117 +187,75 @@ function getObjectType(obj) {
178
187
  * @internal
179
188
  * @param angleObj 角度数值对象
180
189
  * @param validRange 角度限制值
181
- */
182
- function angleLimit(angleObj, validRange) {
190
+ */ function angleLimit(angleObj, validRange) {
183
191
  var flagAlpha = true;
184
192
  var flagBeta = true;
185
193
  var flagGamma = true;
186
- if (getObjectType(validRange.alpha) === '[object Array]' && validRange.alpha.length >= 2) {
194
+ if (getObjectType(validRange.alpha) === "[object Array]" && validRange.alpha.length >= 2) {
187
195
  var referAlphaA = angleObj.alpha + validRange.alpha[0];
188
196
  var referAlphaB = angleObj.alpha + validRange.alpha[1];
189
197
  referAlphaA = referAlphaA < 0 ? referAlphaA + 360 : referAlphaA;
190
198
  referAlphaB = referAlphaB > 360 ? referAlphaB - 360 : referAlphaB;
191
199
  if (referAlphaA < referAlphaB) {
192
200
  flagAlpha = angleObj.alpha > referAlphaA && angleObj.alpha < referAlphaB;
193
- }
194
- else {
201
+ } else {
195
202
  flagAlpha = angleObj.alpha > referAlphaA || angleObj.alpha < referAlphaB;
196
203
  }
197
204
  }
198
- if (getObjectType(validRange.beta) === '[object Array]' && validRange.beta.length >= 2) {
205
+ if (getObjectType(validRange.beta) === "[object Array]" && validRange.beta.length >= 2) {
199
206
  flagBeta = angleObj.beta >= validRange.beta[0] && angleObj.beta <= validRange.beta[1];
200
207
  }
201
- if (getObjectType(validRange.gamma) === '[object Array]' && validRange.gamma.length >= 2) {
208
+ if (getObjectType(validRange.gamma) === "[object Array]" && validRange.gamma.length >= 2) {
202
209
  flagGamma = angleObj.gamma >= validRange.gamma[0] && angleObj.gamma <= validRange.gamma[1];
203
210
  }
204
211
  return flagAlpha && flagBeta && flagGamma;
205
212
  }
206
213
 
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
214
  function isIOS() {
253
215
  var str = navigator.userAgent.toLowerCase();
254
216
  var ver = str.match(/cpu (iphone )?os (.*?) like mac os/);
255
217
  return ver ? parseInt(ver[2], 10) : 0;
256
218
  }
219
+ function isMiniProgram() {
220
+ return isAlipayMiniApp() || isWechatMiniApp();
221
+ }
222
+ function isAlipayMiniApp() {
223
+ var _my;
224
+ return typeof my !== "undefined" && ((_my = my) == null ? void 0 : _my.renderTarget) === "web";
225
+ }
226
+ function isWechatMiniApp() {
227
+ return window.__wxjs_environment === "miniprogram";
228
+ }
257
229
 
258
230
  /**
259
231
  * 稳定区间
260
- */
261
- var STABLE_RANGE = 3;
232
+ */ var STABLE_RANGE = 3;
262
233
  /**
263
234
  * 每次增幅的最大值
264
- */
265
- var MAX_CHANGE = 5;
235
+ */ var MAX_CHANGE = 5;
266
236
  /**
267
237
  * 每次增幅的最小值
268
- */
269
- var MIN_CHANGE = 1;
238
+ */ var MIN_CHANGE = 1;
270
239
  /**
271
240
  * 数据缓存队列的长度
272
- */
273
- var VALUE_POOL_LENGTH = 5;
241
+ */ var VALUE_POOL_LENGTH = 5;
274
242
  /**
275
243
  * 滤波方法
276
- */
277
- var Filtering = /** @class */ (function () {
244
+ */ var Filtering = /*#__PURE__*/ function() {
278
245
  function Filtering(options) {
279
- if (options === void 0) { options = {}; }
246
+ if (options === void 0) options = {};
280
247
  this.options = options;
281
248
  this.lastValue = 0;
282
249
  this.valuePool = [];
283
250
  }
251
+ var _proto = Filtering.prototype;
284
252
  /**
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) {
253
+ * 0deg 左右保持一定的稳定区间 STABLE_RANGE
254
+ * - 小于 STABLE_RANGE 的算 0
255
+ * - 大于 STABLE_RANGE 的减去 STABLE_RANGE
256
+ * @param value - 输入值
257
+ * @returns
258
+ */ _proto.stableFix = function stableFix(value) {
292
259
  var stableRange = this.options.stableRange || STABLE_RANGE;
293
260
  if (Math.abs(value) < stableRange) {
294
261
  return 0;
@@ -296,13 +263,12 @@ var Filtering = /** @class */ (function () {
296
263
  return value > stableRange ? value - stableRange : value + stableRange;
297
264
  };
298
265
  /**
299
- * 变幅限制
300
- * - 最大变化 MAX_CHANGE
301
- * - 最小变化 MIN_CHANGE
302
- * @param value
303
- * @returns
304
- */
305
- Filtering.prototype.changeLimit = function (value) {
266
+ * 变幅限制
267
+ * - 最大变化 MAX_CHANGE
268
+ * - 最小变化 MIN_CHANGE
269
+ * @param value
270
+ * @returns
271
+ */ _proto.changeLimit = function changeLimit(value) {
306
272
  var lastValue = this.lastValue;
307
273
  var result = value;
308
274
  if (Math.abs(value - lastValue) > MAX_CHANGE) {
@@ -314,21 +280,20 @@ var Filtering = /** @class */ (function () {
314
280
  this.lastValue = result;
315
281
  return result;
316
282
  };
317
- Filtering.prototype.linearRegressionMedian = function (value) {
283
+ _proto.linearRegressionMedian = function linearRegressionMedian(value) {
318
284
  // 在队列中装载数据,达到队列阀值长度时开始计算
319
285
  this.valuePool.push(value);
320
286
  var result;
321
287
  if (this.valuePool.length >= VALUE_POOL_LENGTH) {
322
288
  result = getLinearRegressionFixedVal(this.valuePool);
323
289
  this.valuePool.shift();
324
- }
325
- else {
290
+ } else {
326
291
  result = this.lastValue;
327
292
  }
328
293
  return result;
329
294
  };
330
295
  return Filtering;
331
- }());
296
+ }();
332
297
  // 计算出线性回归参数
333
298
  function linearRegression(x, y) {
334
299
  var result = {};
@@ -338,30 +303,30 @@ function linearRegression(x, y) {
338
303
  var sumXY = 0;
339
304
  var sumXX = 0;
340
305
  var sumYY = 0;
341
- for (var i = 0; i < y.length; i++) {
306
+ for(var i = 0; i < y.length; i++){
342
307
  sumX += x[i];
343
308
  sumY += y[i];
344
- sumXY += (x[i] * y[i]);
345
- sumXX += (x[i] * x[i]);
346
- sumYY += (y[i] * y[i]);
309
+ sumXY += x[i] * y[i];
310
+ sumXX += x[i] * x[i];
311
+ sumYY += y[i] * y[i];
347
312
  }
348
313
  var avgX = sumX / n;
349
314
  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);
315
+ result["a"] = (sumXY - n * avgX * avgY) / (sumXX - n * avgX * avgX);
316
+ result["b"] = avgY - result.a * avgX;
317
+ result["miss"] = Math.pow((n * sumXY - sumX * sumY) / Math.sqrt((n * sumXX - sumX * sumX) * (n * sumYY - sumY * sumY)), 2);
353
318
  return result;
354
319
  }
355
320
  // 生成线性回归函数 F(x) = ax + b
356
321
  function createLinearRegressionFx(values) {
357
322
  var x = [];
358
323
  var y = [];
359
- values.forEach(function (item, index) {
324
+ values.forEach(function(item, index) {
360
325
  x.push(index); // 数据是连续的,所以直接取数组下标为 x
361
326
  y.push(item);
362
327
  });
363
328
  var key = linearRegression(x, y);
364
- return function (x) {
329
+ return function(x) {
365
330
  return key.a * x + key.b;
366
331
  };
367
332
  }
@@ -369,14 +334,14 @@ function createLinearRegressionFx(values) {
369
334
  function getLinearRegressionFixedVal(valuePool) {
370
335
  var fx = createLinearRegressionFx(valuePool);
371
336
  // 这个迭代修正很重要
372
- valuePool = valuePool.map(function (item, index) {
337
+ valuePool = valuePool.map(function(item, index) {
373
338
  return fx(index);
374
339
  });
375
340
  return fx(valuePool.length / 2);
376
341
  }
377
342
 
378
- var useJSBridge = isIOS() && typeof window.AlipayJSBridge !== 'undefined';
379
- var useWindVane = typeof window.WindVane !== 'undefined';
343
+ var useJSBridge = isIOS() && typeof window.AlipayJSBridge !== "undefined";
344
+ var useWindVane = typeof window.WindVane !== "undefined";
380
345
  // 默认参数
381
346
  var defaultOptions = {
382
347
  X: true,
@@ -386,31 +351,49 @@ var defaultOptions = {
386
351
  relativeBeta: false,
387
352
  relativeGamma: false,
388
353
  validRange: {
389
- alpha: [-60, 60],
390
- beta: [-60, 180],
391
- gamma: [-89, 89],
354
+ alpha: [
355
+ -60,
356
+ 60
357
+ ],
358
+ beta: [
359
+ -60,
360
+ 180
361
+ ],
362
+ gamma: [
363
+ -89,
364
+ 89
365
+ ]
392
366
  },
393
- stableRange: 3,
367
+ stableRange: 3
394
368
  };
395
- var DeviceOrientation = /** @class */ (function () {
369
+ var DeviceOrientation = /*#__PURE__*/ function() {
396
370
  function DeviceOrientation(options) {
397
- if (options === void 0) { options = {}; }
371
+ if (options === void 0) options = {};
398
372
  this.lastX = 0;
399
373
  this.lastY = 0;
400
374
  this.prevAcceler = {
401
375
  x: 0,
402
376
  y: 0,
403
- z: 0,
377
+ z: 0
404
378
  };
405
379
  this.stoped = false;
406
- this.options = deepMerge(defaultOptions, options);
380
+ // 模拟简单的 deep merge
381
+ var validRange = _extends({}, defaultOptions.validRange, options.validRange);
382
+ var mergeOptions = _extends({}, defaultOptions, options);
383
+ mergeOptions.validRange = validRange;
384
+ this.options = mergeOptions;
407
385
  var stableRange = this.options.stableRange;
408
- this.filterX = new Filtering({ stableRange: stableRange });
409
- this.filterY = new Filtering({ stableRange: stableRange });
386
+ this.filterX = new Filtering({
387
+ stableRange: stableRange
388
+ });
389
+ this.filterY = new Filtering({
390
+ stableRange: stableRange
391
+ });
410
392
  }
411
- DeviceOrientation.prototype.watch = function (callback) {
393
+ var _proto = DeviceOrientation.prototype;
394
+ _proto.watch = function watch(callback) {
412
395
  var _this = this;
413
- if (typeof callback !== 'function') {
396
+ if (typeof callback !== "function") {
414
397
  return;
415
398
  }
416
399
  // 目前只能绑定一个方法,此处可以扩展成一个方法队列
@@ -419,66 +402,67 @@ var DeviceOrientation = /** @class */ (function () {
419
402
  }
420
403
  var timefragment = 0; // 时间片计时
421
404
  var nowts = 0; // 当前时间
422
- var referGamma = 0; // 初始化角度,作为单独一个用户的空间旋转的参照
423
- var referBeta = 0;
405
+ // 初始化角度,作为单独一个用户的空间旋转的参照
406
+ var referGamma = NaN, referBeta = NaN;
424
407
  var alpha;
425
408
  var beta;
426
409
  var gamma;
427
- var gammaFixed;
428
- var betaFixed;
429
410
  var isInValidDegRange;
430
411
  var x; // 最终输出的 x
431
412
  var y; // 最终输出的 y
432
- var handleWatch = function (e) {
413
+ var handleWatch = function(e) {
433
414
  if (_this.stoped) {
434
415
  return;
435
416
  }
436
417
  alpha = e.alpha; // 垂直于屏幕的轴 0 ~ 360
437
418
  beta = e.beta; // 横向 X 轴 -180 ~ 180
438
419
  gamma = e.gamma; // 纵向 Y 轴 -90 ~ 90
439
- if (!referBeta) {
440
- referBeta = beta || 0;
441
- }
442
- if (!referGamma) {
443
- referGamma = gamma || 0;
444
- }
445
- //
446
420
  isInValidDegRange = angleLimit.call(_this, {
447
421
  alpha: alpha,
448
422
  beta: beta,
449
- gamma: gamma,
423
+ gamma: gamma
450
424
  }, _this.options.validRange);
425
+ if (isNaN(referGamma)) {
426
+ referGamma = gamma;
427
+ _this.filterX.lastValue = gamma;
428
+ }
429
+ if (isNaN(referBeta)) {
430
+ referBeta = beta;
431
+ _this.filterY.lastValue = beta;
432
+ }
451
433
  if (isInValidDegRange) {
452
434
  // 最终结果值
453
435
  if (_this.options.X) {
454
- gammaFixed = gamma - referGamma;
455
- x = _this.options.relativeGamma ? gammaFixed : gamma;
436
+ x = _this.options.relativeGamma ? gamma - referGamma : gamma;
456
437
  x = _this.filterX.stableFix(x);
457
438
  x = _this.filterX.changeLimit(x);
458
439
  x = _this.filterX.linearRegressionMedian(+x);
459
- }
460
- else {
440
+ } else {
461
441
  x = 0;
462
442
  }
463
443
  if (_this.options.Y) {
464
- // beta 相对 referBeta 的角度
465
- betaFixed = beta - referBeta;
466
- y = _this.options.relativeBeta ? betaFixed : beta;
444
+ y = _this.options.relativeBeta ? beta - referBeta : beta;
467
445
  y = _this.filterY.stableFix(y);
468
446
  y = _this.filterY.changeLimit(y);
469
447
  y = _this.filterY.linearRegressionMedian(+y);
470
- }
471
- else {
448
+ } else {
472
449
  y = 0;
473
450
  }
474
451
  if (_this.isValid(x, y)) {
475
452
  if (_this.options.useRequestAnimationFrame) {
476
- window.requestAnimationFrame(function () {
477
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
453
+ window.requestAnimationFrame(function() {
454
+ callback(x, y, {
455
+ alpha: alpha,
456
+ beta: y - referBeta,
457
+ gamma: x - referGamma
458
+ });
459
+ });
460
+ } else {
461
+ callback(x, y, {
462
+ alpha: alpha,
463
+ beta: y - referBeta,
464
+ gamma: x - referGamma
478
465
  });
479
- }
480
- else {
481
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
482
466
  }
483
467
  _this.lastX = x;
484
468
  _this.lastY = y;
@@ -489,51 +473,52 @@ var DeviceOrientation = /** @class */ (function () {
489
473
  this.stoped = false;
490
474
  if (useWindVane) {
491
475
  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;
476
+ this.watchListener = function(e) {
477
+ if ("param" in e) {
478
+ var _e_param = e.param, x = _e_param.x, y = _e_param.y, z = _e_param.z;
495
479
  // 即使手机没动,也会不停触发,所以这里加个判断,值相等则不调用回调
496
- if (x_1 === _this.prevAcceler.x && y_1 === _this.prevAcceler.y && z === _this.prevAcceler.z) {
480
+ if (x === _this.prevAcceler.x && y === _this.prevAcceler.y && z === _this.prevAcceler.z) {
497
481
  return;
498
482
  }
499
- _this.prevAcceler = { x: x_1, y: y_1, z: z };
483
+ _this.prevAcceler = {
484
+ x: x,
485
+ y: y,
486
+ z: z
487
+ };
500
488
  var evt = {
501
489
  alpha: +z * 180,
502
- beta: +y_1 * -90,
503
- gamma: +x_1 * 90,
490
+ beta: +y * -90,
491
+ gamma: +x * 90
504
492
  };
505
493
  handleWatch(evt);
506
494
  }
507
495
  };
508
- document.addEventListener('motion.gyro', this.watchListener, false);
509
- }
510
- else if (useJSBridge) {
496
+ document.addEventListener("motion.gyro", this.watchListener, false);
497
+ } else if (useJSBridge && !isMiniProgram()) {
511
498
  switchIOSEvent(true, this.options.interval / 1000);
512
- this.watchListener = function (e) {
513
- if (e && 'data' in e) {
499
+ this.watchListener = function(e) {
500
+ if (e && "data" in e) {
514
501
  /*
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;
502
+ data:
503
+ {
504
+ data: {
505
+ x: 0.0, // gamma -1 ~ 1
506
+ y: 0.0, // beta -1 ~ 1
507
+ z: 0.0, // alpha
508
+ }
509
+ }
510
+ */ var _e_data = e.data, x = _e_data.x, y = _e_data.y, z = _e_data.z;
525
511
  var evt = {
526
512
  alpha: z * 180,
527
- beta: y_2 * -90,
528
- gamma: x_2 * 90,
513
+ beta: y * -90,
514
+ gamma: x * 90
529
515
  };
530
516
  handleWatch(evt);
531
517
  }
532
518
  };
533
- document.addEventListener('accelerometerChange', this.watchListener, false);
534
- }
535
- else {
536
- this.watchListener = function (e) {
519
+ document.addEventListener("accelerometerChange", this.watchListener, false);
520
+ } else {
521
+ this.watchListener = function(e) {
537
522
  nowts = new Date().getTime();
538
523
  // 控制时间片
539
524
  if (nowts - timefragment >= _this.options.interval) {
@@ -541,80 +526,87 @@ var DeviceOrientation = /** @class */ (function () {
541
526
  handleWatch(e);
542
527
  }
543
528
  };
544
- window.addEventListener('deviceorientation', this.watchListener, false);
529
+ window.addEventListener("deviceorientation", this.watchListener, false);
545
530
  }
546
531
  };
547
- DeviceOrientation.prototype.unWatch = function () {
548
- effects.assertExist(this.watchListener);
532
+ _proto.unWatch = function unWatch() {
533
+ EFFECTS.assertExist(this.watchListener);
549
534
  if (useWindVane) {
550
535
  switchWindVane(false);
551
- document.removeEventListener('motion.gyro', this.watchListener);
552
- }
553
- else if (useJSBridge) {
536
+ document.removeEventListener("motion.gyro", this.watchListener);
537
+ } else if (useJSBridge) {
554
538
  switchIOSEvent(false);
555
- document.removeEventListener('accelerometerChange', this.watchListener);
556
- }
557
- else {
558
- window.removeEventListener('deviceorientation', this.watchListener);
539
+ document.removeEventListener("accelerometerChange", this.watchListener);
540
+ } else {
541
+ window.removeEventListener("deviceorientation", this.watchListener);
559
542
  }
560
543
  this.stoped = true;
561
544
  this.watchListener = undefined;
562
545
  };
563
- DeviceOrientation.prototype.pause = function () {
546
+ _proto.pause = function pause() {
564
547
  this.stoped = true;
565
548
  if (useJSBridge) {
566
549
  switchIOSEvent(false);
567
550
  }
568
551
  };
569
- DeviceOrientation.prototype.continue = function () {
552
+ _proto.continue = function _continue() {
570
553
  this.stoped = false;
571
554
  if (useJSBridge) {
572
555
  switchIOSEvent(true, this.options.interval / 1000);
573
556
  }
574
557
  };
575
- DeviceOrientation.prototype.isValid = function (x, y) {
558
+ _proto.isValid = function isValid(x, y) {
576
559
  // 判断是否和上次的值一样,检测有没有变
577
560
  return this.lastX !== x || this.lastY !== y;
578
561
  };
579
562
  return DeviceOrientation;
580
- }());
563
+ }();
581
564
  // 开启/关闭 iOS 的陀螺仪监听
582
565
  function switchIOSEvent(open, interval) {
583
- window.AlipayJSBridge.call('watchShake', {
566
+ window.AlipayJSBridge.call("watchShake", {
584
567
  monitorGyroscope: false,
585
568
  monitorAccelerometer: !!open,
586
- interval: !open ? 10 : parseFloat(interval.toFixed(3)),
587
- }, function () { });
569
+ interval: !open ? 10 : parseFloat(interval.toFixed(3))
570
+ }, function() {});
588
571
  }
589
572
  function switchWindVane(open, interval) {
590
573
  var params = {
591
574
  // 是开启还是关闭陀螺仪的监听
592
575
  on: open,
593
576
  // 陀螺仪事件的时间间隔
594
- frequency: interval,
577
+ frequency: interval
595
578
  };
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));
579
+ window.WindVane.call("WVMotion", "listenGyro", params, function(e) {
580
+ console.info("Call WVMotion success.");
581
+ }, function(e) {
582
+ console.error("Call WVMotion failed: " + JSON.stringify(e) + ".");
600
583
  });
601
584
  }
602
585
 
603
586
  /**
604
587
  *
605
- */
606
- var OrientationAdapterAcceler = /** @class */ (function () {
588
+ */ var OrientationAdapterAcceler = /*#__PURE__*/ function() {
607
589
  function OrientationAdapterAcceler() {
608
590
  this.transformers = [];
609
591
  this.connected = false;
610
592
  this.accelerMotion = null;
611
593
  this.validRange = {
612
- alpha: [-60, 60],
613
- beta: [-80, 80],
614
- gamma: [-89, 89], // 左右翻转
594
+ alpha: [
595
+ -60,
596
+ 60
597
+ ],
598
+ beta: [
599
+ -80,
600
+ 80
601
+ ],
602
+ gamma: [
603
+ -89,
604
+ 89
605
+ ]
615
606
  };
616
607
  }
617
- OrientationAdapterAcceler.prototype.connect = function () {
608
+ var _proto = OrientationAdapterAcceler.prototype;
609
+ _proto.connect = function connect() {
618
610
  var _this = this;
619
611
  if (!this.connected) {
620
612
  this.accelerMotion = new DeviceOrientation({
@@ -625,37 +617,41 @@ var OrientationAdapterAcceler = /** @class */ (function () {
625
617
  relativeBeta: false,
626
618
  relativeGamma: false,
627
619
  validRange: this.validRange,
628
- stableRange: 3, // 稳定区间
620
+ stableRange: 3
629
621
  });
630
- this.accelerMotion.watch(function (x, y) {
622
+ this.accelerMotion.watch(function(x, y, param) {
623
+ var beta = param.beta, gamma = param.gamma;
631
624
  var motion = {
632
625
  x: x,
633
626
  y: y,
627
+ beta: beta,
628
+ gamma: gamma
634
629
  };
635
630
  _this.dispatchMotion(motion);
636
631
  });
637
632
  }
638
633
  this.connected = true;
639
634
  };
640
- OrientationAdapterAcceler.prototype.disconnect = function () {
635
+ _proto.disconnect = function disconnect() {
641
636
  if (this.accelerMotion) {
642
637
  this.accelerMotion.unWatch();
643
638
  }
644
639
  this.connected = false;
645
640
  };
646
641
  /**
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) {
642
+ *
643
+ * @param motion
644
+ */ _proto.dispatchMotion = function dispatchMotion(motion) {
645
+ this.transformers.forEach(function(t) {
646
+ return t.update(motion);
647
+ });
648
+ };
649
+ _proto.addTransformer = function addTransformer(transformer) {
654
650
  if (!this.transformers.includes(transformer)) {
655
651
  this.transformers.push(transformer);
656
652
  }
657
653
  };
658
- OrientationAdapterAcceler.prototype.removeTransformer = function (transformer) {
654
+ _proto.removeTransformer = function removeTransformer(transformer) {
659
655
  var index = this.transformers.indexOf(transformer);
660
656
  if (index > -1) {
661
657
  this.transformers.splice(index, 1);
@@ -663,7 +659,7 @@ var OrientationAdapterAcceler = /** @class */ (function () {
663
659
  return this.transformers.length === 0;
664
660
  };
665
661
  return OrientationAdapterAcceler;
666
- }());
662
+ }();
667
663
  var adapter;
668
664
  function getAccelerAdapter() {
669
665
  if (!adapter) {
@@ -672,72 +668,74 @@ function getAccelerAdapter() {
672
668
  return adapter;
673
669
  }
674
670
 
675
- var OrientationPluginLoader = /** @class */ (function (_super) {
676
- __extends(OrientationPluginLoader, _super);
671
+ var OrientationPluginLoader = /*#__PURE__*/ function(AbstractPlugin) {
672
+ _inherits(OrientationPluginLoader, AbstractPlugin);
677
673
  function OrientationPluginLoader() {
678
- var _this = _super !== null && _super.apply(this, arguments) || this;
674
+ var _this;
675
+ _this = AbstractPlugin.apply(this, arguments) || this;
679
676
  _this.order = 90;
680
677
  _this.adapter = null;
681
- _this.handleConnect = function () {
682
- var _a;
678
+ _this.handleConnect = function() {
683
679
  if (!closeManually) {
684
- (_a = _this.adapter) === null || _a === void 0 ? void 0 : _a.connect();
680
+ var _this_adapter;
681
+ (_this_adapter = _this.adapter) == null ? void 0 : _this_adapter.connect();
685
682
  }
686
683
  };
687
- _this.handleDisconnect = function () {
688
- var _a;
689
- (_a = _this.adapter) === null || _a === void 0 ? void 0 : _a.disconnect();
684
+ _this.handleDisconnect = function() {
685
+ var _this_adapter;
686
+ (_this_adapter = _this.adapter) == null ? void 0 : _this_adapter.disconnect();
690
687
  };
691
688
  return _this;
692
689
  }
693
- OrientationPluginLoader.prototype.onCompositionConstructed = function () {
694
- var _a;
690
+ var _proto = OrientationPluginLoader.prototype;
691
+ _proto.onCompositionConstructed = function onCompositionConstructed() {
692
+ var _this_adapter;
695
693
  this.adapter = getAdapter();
696
- (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.connect();
694
+ (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.connect();
697
695
  this.bindAccelerDocumentEvent();
698
696
  };
699
- OrientationPluginLoader.prototype.onCompositionReset = function (composition) {
700
- var _a;
697
+ _proto.onCompositionReset = function onCompositionReset(composition) {
698
+ var _this_adapter;
701
699
  var transformer = composition.loaderData.deviceTransformer = new CompositionTransformerAcceler(composition);
702
- (_a = this.adapter) === null || _a === void 0 ? void 0 : _a.addTransformer(transformer);
700
+ (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.addTransformer(transformer);
703
701
  };
704
- OrientationPluginLoader.prototype.onCompositionUpdate = function (composition) {
702
+ _proto.onCompositionUpdate = function onCompositionUpdate(composition) {
705
703
  var transformer = composition.loaderData.deviceTransformer;
706
704
  if (transformer) {
707
705
  transformer.updateOrientation();
708
706
  }
709
707
  };
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);
708
+ _proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {
709
+ var _this_adapter;
710
+ var empty = (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.removeTransformer(composition.loaderData.deviceTransformer);
713
711
  if (empty) {
714
- (_b = this.adapter) === null || _b === void 0 ? void 0 : _b.disconnect();
712
+ var _this_adapter1;
713
+ (_this_adapter1 = this.adapter) == null ? void 0 : _this_adapter1.disconnect();
715
714
  }
716
715
  };
717
- OrientationPluginLoader.prototype.bindAccelerDocumentEvent = function () {
716
+ _proto.bindAccelerDocumentEvent = function bindAccelerDocumentEvent() {
718
717
  this.unbindAccelerDocumentEvent(); // 保证全局只监听一份
719
- document.addEventListener('resume', this.handleConnect, false);
720
- document.addEventListener('pause', this.handleDisconnect, false);
721
- document.addEventListener('back', this.handleDisconnect, false);
718
+ document.addEventListener("resume", this.handleConnect, false);
719
+ document.addEventListener("pause", this.handleDisconnect, false);
720
+ document.addEventListener("back", this.handleDisconnect, false);
722
721
  };
723
- OrientationPluginLoader.prototype.unbindAccelerDocumentEvent = function () {
724
- document.removeEventListener('resume', this.handleConnect);
725
- document.removeEventListener('pause', this.handleDisconnect);
726
- document.removeEventListener('back', this.handleDisconnect);
722
+ _proto.unbindAccelerDocumentEvent = function unbindAccelerDocumentEvent() {
723
+ document.removeEventListener("resume", this.handleConnect);
724
+ document.removeEventListener("pause", this.handleDisconnect);
725
+ document.removeEventListener("back", this.handleDisconnect);
727
726
  };
728
- OrientationPluginLoader.prototype.dispose = function () {
727
+ _proto.dispose = function dispose() {
729
728
  getAdapter().disconnect();
730
729
  this.unbindAccelerDocumentEvent();
731
730
  };
732
731
  return OrientationPluginLoader;
733
- }(effects.AbstractPlugin));
732
+ }(EFFECTS.AbstractPlugin);
734
733
  // 是否是手动关闭,如果是,那么 resume 时不要恢复
735
734
  var closeManually = false;
736
735
  /**
737
736
  *
738
737
  * @returns
739
- */
740
- function getAdapter() {
738
+ */ function getAdapter() {
741
739
  // 运动感应类型(默认使用加速度,Native 环境使用陀螺仪)
742
740
  return getAccelerAdapter();
743
741
  }
@@ -750,63 +748,83 @@ function openDeviceMotion() {
750
748
  getAdapter().connect();
751
749
  }
752
750
 
753
- var OrientationComponent = /** @class */ (function (_super) {
754
- __extends(OrientationComponent, _super);
751
+ function __decorate(decorators, target, key, desc) {
752
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
753
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
754
+ 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;
755
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
756
+ }
757
+ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
758
+ var e = new Error(message);
759
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
760
+ };
761
+
762
+ exports.OrientationComponent = /*#__PURE__*/ function(ItemBehaviour) {
763
+ _inherits(OrientationComponent, ItemBehaviour);
755
764
  function OrientationComponent() {
756
- return _super !== null && _super.apply(this, arguments) || this;
765
+ return ItemBehaviour.apply(this, arguments);
757
766
  }
758
- OrientationComponent.prototype.fromData = function (data) {
759
- _super.prototype.fromData.call(this, data);
760
- var targets = data.content.options.targets;
767
+ var _proto = OrientationComponent.prototype;
768
+ _proto.fromData = function fromData(data) {
769
+ ItemBehaviour.prototype.fromData.call(this, data);
770
+ var targets = data.options.targets;
761
771
  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
- }); });
772
+ this.targets = targets.map(function(t) {
773
+ return {
774
+ name: t.name,
775
+ xMin: +t.xMin || 0,
776
+ yMin: +t.yMin || 0,
777
+ xMax: +t.xMax || 0,
778
+ yMax: +t.yMax || 0,
779
+ vMin: +t.vMin || 0,
780
+ hMin: +t.hMin || 0,
781
+ vMax: +t.vMax || 0,
782
+ hMax: +t.hMax || 0
783
+ };
784
+ });
769
785
  }
770
786
  };
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;
787
+ _proto.start = function start() {
788
+ var _this_item_composition;
789
+ var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
774
790
  if (transformer) {
775
- (_b = this.targets) === null || _b === void 0 ? void 0 : _b.forEach(function (target) { return transformer.addTarget(target); });
791
+ var _this_targets;
792
+ (_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
793
+ return transformer.addTarget(target);
794
+ });
776
795
  transformer.initComposition();
777
796
  }
778
797
  };
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;
798
+ _proto.update = function update(dt) {
799
+ var _this_item_composition;
800
+ var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
782
801
  if (transformer) {
783
802
  transformer.updateOrientation();
784
803
  }
785
804
  };
786
- OrientationComponent.prototype.onDestroy = function () {
805
+ _proto.onDestroy = function onDestroy() {
787
806
  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); });
807
+ var _this_targets;
808
+ (_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
809
+ var _this_item_composition_loaderData_deviceTransformer, _this_item_composition;
810
+ 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);
811
+ });
790
812
  };
791
813
  return OrientationComponent;
792
- }(effects.ItemBehaviour));
814
+ }(EFFECTS.ItemBehaviour);
815
+ exports.OrientationComponent = __decorate([
816
+ EFFECTS.effectsClass("OrientationComponent")
817
+ ], exports.OrientationComponent);
793
818
 
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.2";
807
- effects.logger.info('plugin orientation transformer version: ' + version);
819
+ EFFECTS.registerPlugin("orientation-transformer", OrientationPluginLoader, EFFECTS.VFXItem);
820
+ var version = "2.0.0-alpha.21";
821
+ EFFECTS.logger.info("Plugin orientation transformer version: " + version + ".");
822
+ if (version !== EFFECTS__namespace.version) {
823
+ 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!");
824
+ }
808
825
 
809
826
  exports.OrientationAdapterAcceler = OrientationAdapterAcceler;
827
+ exports.OrientationPluginLoader = OrientationPluginLoader;
810
828
  exports.closeDeviceMotion = closeDeviceMotion;
811
829
  exports.getAdapter = getAdapter;
812
830
  exports.openDeviceMotion = openDeviceMotion;