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