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