@galacean/effects-plugin-orientation-transformer 2.8.5 → 2.8.6
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 -1
- package/dist/alipay.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/dist/alipay.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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 r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(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&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,n){return s=o()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var i=new(Function.bind.apply(t,a));return n&&r(i,n.prototype),i},s.apply(null,arguments)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function u(t){var e="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a)}function a(){return s(t,arguments,c(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,t)},u(t)}var l=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,r=t.gamma;this.currentEvent={x:e,y:n,beta:a,gamma:r}},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(),r=n.transform.rotation.toArray(),i=this.currentPos[n.name],o=this.currentRot[n.name];this.records[n.name]={item:n,position:a,rotation:r},i&&n.transform.setPosition(i[0],i[1],i[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,r=e.y,i=e.beta,o=e.gamma,s=null==(n=this.records[t])?void 0:n.item;if(s){var c=this.records[t].position,u=this.records[t].rotation,l=this.targets[t],m=h(a,this.betaRange),v=h(r,this.gammaRange);if(l){var d,g,y=[c[0]+1.2*f(p(m,this.gammaRange[0],this.gammaRange[1]),l.xMin,l.xMax),c[1]+1.2*f(p(v,this.betaRange[0],this.betaRange[1]),l.yMin,l.yMax),c[2]],b=p(h(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),M=p(h(.8*i,this.betaRange),this.betaRange[0],this.betaRange[1]),w=[u[0]+f(M,l.hMin,l.hMax),u[1]+f(b,l.vMin,l.vMax),u[2]];(d=s.transform).setPosition.apply(d,[].concat(y)),(g=s.transform).setRotation.apply(g,[].concat(w)),this.currentPos[t]=y.slice(),this.currentRot[t]=w.slice()}}},t}();function h(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function f(t,e,n){return e+(n-e)*t}function p(t,e,n){return(t-e)/(n-e)}function m(){return m=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},m.apply(this,arguments)}function v(e,n){var a=!0,r=!0,i=!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&&(r=e.beta>=n.beta[0]&&e.beta<=n.beta[1]),t.isArray(n.gamma)&&n.gamma.length>=2&&(i=e.gamma>=n.gamma[0]&&e.gamma<=n.gamma[1]),a&&r&&i}var d=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,r=0,i=0,o=0,s=0,c=0,u=0;u<e.length;u++)r+=t[u],i+=e[u],o+=t[u]*e[u],s+=t[u]*t[u],c+=e[u]*e[u];var l=r/a,h=i/a;return n.a=(o-a*l*h)/(s-a*l*l),n.b=h-n.a*l,n.miss=Math.pow((a*o-r*i)/Math.sqrt((a*s-r*r)*(a*c-i*i)),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 g=t.isIOSByUA()&&void 0!==e.window.AlipayJSBridge,y=void 0!==e.window.WindVane,b={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},M=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=m({},b.validRange,t.validRange),n=m({},b,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new d({stableRange:a}),this.filterY=new d({stableRange:a})}var a=n.prototype;return a.watch=function(n){var a=this;if("function"==typeof n&&!this.watchListener){var r,i,o,s,c,u,l=0,h=0,f=NaN,p=NaN,m=function(t){a.stoped||(r=t.alpha||0,i=t.beta||0,o=t.gamma||0,s=v.call(a,{alpha:r,beta:i,gamma:o},a.options.validRange),isNaN(f)&&(f=o,a.filterX.lastValue=o),isNaN(p)&&(p=i,a.filterY.lastValue=i),s&&(a.options.X?(c=a.options.relativeGamma?o-f:o,c=a.filterX.stableFix(c),c=a.filterX.changeLimit(c),c=a.filterX.linearRegressionMedian(+c)):c=0,a.options.Y?(u=a.options.relativeBeta?i-p:i,u=a.filterY.stableFix(u),u=a.filterY.changeLimit(u),u=a.filterY.linearRegressionMedian(+u)):u=0,a.isValid(c,u)&&(a.options.useRequestAnimationFrame?e.window.requestAnimationFrame((function(){n(c,u,{alpha:r,beta:u-p,gamma:c-f})})):n(c,u,{alpha:r,beta:u-p,gamma:c-f}),a.lastX=c,a.lastY=u)))};this.stoped=!1,y?(x(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,r=e.y,i=e.z;if(n===a.prevAcceler.x&&r===a.prevAcceler.y&&i===a.prevAcceler.z)return;a.prevAcceler={x:n,y:r,z:i},m({alpha:180*+i,beta:-90*+r,gamma:90*+n})}},e.document.addEventListener("motion.gyro",this.watchListener,!1)):g&&!t.isMiniProgram()?(w(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y,r=e.z;m({alpha:180*r,beta:-90*a,gamma:90*n})}},e.document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(h=(new Date).getTime())-l>=a.options.interval&&(l=h,m(t))},e.window.addEventListener("deviceorientation",this.watchListener,!1))}},a.unWatch=function(){t.assertExist(this.watchListener),y?(x(!1),e.document.removeEventListener("motion.gyro",this.watchListener)):g?(w(!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,g&&w(!1)},a.continue=function(){this.stoped=!1,g&&w(!0,this.options.interval/1e3)},a.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},n}();function w(t,n){e.window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(n.toFixed(3)):10},(function(){}))}function x(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 R,O=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 M({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 r={x:e,y:n,beta:a.beta,gamma:a.gamma};t.dispatchMotion(r)}))),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 E=function(t){function n(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;L||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}i(n,t);var a=n.prototype;return a.onCompositionCreated=function(t){var e,n;this.adapter=P(),null==(e=this.adapter)||e.connect(),this.bindAccelerDocumentEvent();var a=t.loaderData.deviceTransformer=new l(t);null==(n=this.adapter)||n.addTransformer(a)},a.onCompositionDestroy=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(){P().disconnect(),this.unbindAccelerDocumentEvent()},n}(u(t.Plugin)),L=!1;function P(){return R||(R=new O),R}"function"==typeof SuppressedError&&SuppressedError,exports.OrientationComponent=function(t){function e(){return t.apply(this,arguments)}i(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 r,i=arguments.length,o=i<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--)(r=t[s])&&(o=(i<3?r(o):i>3?r(e,n,o):r(e,n))||o);return i>3&&o&&Object.defineProperty(e,n,o),o}([t.effectsClass("OrientationComponent")],exports.OrientationComponent),t.registerPlugin("orientation-transformer",E);var A="2.8.5";t.logger.info("Plugin orientation transformer version: 2.8.5."),A!==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=O,exports.OrientationPluginLoader=E,exports.closeDeviceMotion=function(){L=!0,P().disconnect()},exports.getAdapter=P,exports.openDeviceMotion=function(){L=!1,P().connect()},exports.version=A;
|
|
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 r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(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&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,n){return s=o()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var i=new(Function.bind.apply(t,a));return n&&r(i,n.prototype),i},s.apply(null,arguments)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function u(t){var e="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a)}function a(){return s(t,arguments,c(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,t)},u(t)}var l=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,r=t.gamma;this.currentEvent={x:e,y:n,beta:a,gamma:r}},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(),r=n.transform.rotation.toArray(),i=this.currentPos[n.name],o=this.currentRot[n.name];this.records[n.name]={item:n,position:a,rotation:r},i&&n.transform.setPosition(i[0],i[1],i[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,r=e.y,i=e.beta,o=e.gamma,s=null==(n=this.records[t])?void 0:n.item;if(s){var c=this.records[t].position,u=this.records[t].rotation,l=this.targets[t],m=h(a,this.betaRange),v=h(r,this.gammaRange);if(l){var d,g,y=[c[0]+1.2*f(p(m,this.gammaRange[0],this.gammaRange[1]),l.xMin,l.xMax),c[1]+1.2*f(p(v,this.betaRange[0],this.betaRange[1]),l.yMin,l.yMax),c[2]],b=p(h(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),M=p(h(.8*i,this.betaRange),this.betaRange[0],this.betaRange[1]),w=[u[0]+f(M,l.hMin,l.hMax),u[1]+f(b,l.vMin,l.vMax),u[2]];(d=s.transform).setPosition.apply(d,[].concat(y)),(g=s.transform).setRotation.apply(g,[].concat(w)),this.currentPos[t]=y.slice(),this.currentRot[t]=w.slice()}}},t}();function h(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function f(t,e,n){return e+(n-e)*t}function p(t,e,n){return(t-e)/(n-e)}function m(){return m=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},m.apply(this,arguments)}function v(e,n){var a=!0,r=!0,i=!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&&(r=e.beta>=n.beta[0]&&e.beta<=n.beta[1]),t.isArray(n.gamma)&&n.gamma.length>=2&&(i=e.gamma>=n.gamma[0]&&e.gamma<=n.gamma[1]),a&&r&&i}var d=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,r=0,i=0,o=0,s=0,c=0,u=0;u<e.length;u++)r+=t[u],i+=e[u],o+=t[u]*e[u],s+=t[u]*t[u],c+=e[u]*e[u];var l=r/a,h=i/a;return n.a=(o-a*l*h)/(s-a*l*l),n.b=h-n.a*l,n.miss=Math.pow((a*o-r*i)/Math.sqrt((a*s-r*r)*(a*c-i*i)),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 g=t.isIOSByUA()&&void 0!==e.window.AlipayJSBridge,y=void 0!==e.window.WindVane,b={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},M=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=m({},b.validRange,t.validRange),n=m({},b,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new d({stableRange:a}),this.filterY=new d({stableRange:a})}var a=n.prototype;return a.watch=function(n){var a=this;if("function"==typeof n&&!this.watchListener){var r,i,o,s,c,u,l=0,h=0,f=NaN,p=NaN,m=function(t){a.stoped||(r=t.alpha||0,i=t.beta||0,o=t.gamma||0,s=v.call(a,{alpha:r,beta:i,gamma:o},a.options.validRange),isNaN(f)&&(f=o,a.filterX.lastValue=o),isNaN(p)&&(p=i,a.filterY.lastValue=i),s&&(a.options.X?(c=a.options.relativeGamma?o-f:o,c=a.filterX.stableFix(c),c=a.filterX.changeLimit(c),c=a.filterX.linearRegressionMedian(+c)):c=0,a.options.Y?(u=a.options.relativeBeta?i-p:i,u=a.filterY.stableFix(u),u=a.filterY.changeLimit(u),u=a.filterY.linearRegressionMedian(+u)):u=0,a.isValid(c,u)&&(a.options.useRequestAnimationFrame?e.window.requestAnimationFrame((function(){n(c,u,{alpha:r,beta:u-p,gamma:c-f})})):n(c,u,{alpha:r,beta:u-p,gamma:c-f}),a.lastX=c,a.lastY=u)))};this.stoped=!1,y?(x(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,r=e.y,i=e.z;if(n===a.prevAcceler.x&&r===a.prevAcceler.y&&i===a.prevAcceler.z)return;a.prevAcceler={x:n,y:r,z:i},m({alpha:180*+i,beta:-90*+r,gamma:90*+n})}},e.document.addEventListener("motion.gyro",this.watchListener,!1)):g&&!t.isMiniProgram()?(w(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y,r=e.z;m({alpha:180*r,beta:-90*a,gamma:90*n})}},e.document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(h=(new Date).getTime())-l>=a.options.interval&&(l=h,m(t))},e.window.addEventListener("deviceorientation",this.watchListener,!1))}},a.unWatch=function(){t.assertExist(this.watchListener),y?(x(!1),e.document.removeEventListener("motion.gyro",this.watchListener)):g?(w(!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,g&&w(!1)},a.continue=function(){this.stoped=!1,g&&w(!0,this.options.interval/1e3)},a.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},n}();function w(t,n){e.window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(n.toFixed(3)):10},(function(){}))}function x(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 R,O=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 M({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 r={x:e,y:n,beta:a.beta,gamma:a.gamma};t.dispatchMotion(r)}))),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 E=function(t){function n(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;L||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}i(n,t);var a=n.prototype;return a.onCompositionCreated=function(t){var e,n;this.adapter=P(),null==(e=this.adapter)||e.connect(),this.bindAccelerDocumentEvent();var a=t.loaderData.deviceTransformer=new l(t);null==(n=this.adapter)||n.addTransformer(a)},a.onCompositionDestroy=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(){P().disconnect(),this.unbindAccelerDocumentEvent()},n}(u(t.Plugin)),L=!1;function P(){return R||(R=new O),R}"function"==typeof SuppressedError&&SuppressedError,exports.OrientationComponent=function(t){function e(){return t.apply(this,arguments)}i(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 r,i=arguments.length,o=i<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--)(r=t[s])&&(o=(i<3?r(o):i>3?r(e,n,o):r(e,n))||o);return i>3&&o&&Object.defineProperty(e,n,o),o}([t.effectsClass("OrientationComponent")],exports.OrientationComponent),t.registerPlugin("orientation-transformer",E);var A="2.8.6";t.logger.info("Plugin orientation transformer version: 2.8.6."),A!==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=O,exports.OrientationPluginLoader=E,exports.closeDeviceMotion=function(){L=!0,P().disconnect()},exports.getAdapter=P,exports.openDeviceMotion=function(){L=!1,P().connect()},exports.version=A;
|
|
2
2
|
//# sourceMappingURL=alipay.js.map
|
package/dist/alipay.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"@galacean/effects/alipay";import{isArray as e,isIOSByUA as n,isMiniProgram as a,assertExist as i,Plugin as r,effectsClass as o,Behaviour as s,registerPlugin as c,logger as l}from"@galacean/effects/alipay";import{window as u,document as h}from"@galacean/appx-adapter/alipay";function f(t,e){return f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},f(t,e)}function p(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&&f(t,e)}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(m=function(){return!!t})()}function v(t,e,n){return v=m()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var i=new(Function.bind.apply(t,a));return n&&f(i,n.prototype),i},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function g(t){var e="function"==typeof Map?new Map:void 0;return g=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a)}function a(){return v(t,arguments,d(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),f(a,t)},g(t)}var y=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,s=null==(n=this.records[t])?void 0:n.item;if(s){var c=this.records[t].position,l=this.records[t].rotation,u=this.targets[t],h=b(a,this.betaRange),f=b(i,this.gammaRange);if(u){var p,m,v=[c[0]+1.2*M(R(h,this.gammaRange[0],this.gammaRange[1]),u.xMin,u.xMax),c[1]+1.2*M(R(f,this.betaRange[0],this.betaRange[1]),u.yMin,u.yMax),c[2]],d=R(b(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),g=R(b(.8*r,this.betaRange),this.betaRange[0],this.betaRange[1]),y=[l[0]+M(g,u.hMin,u.hMax),l[1]+M(d,u.vMin,u.vMax),l[2]];(p=s.transform).setPosition.apply(p,[].concat(v)),(m=s.transform).setRotation.apply(m,[].concat(y)),this.currentPos[t]=v.slice(),this.currentRot[t]=y.slice()}}},t}();function b(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function M(t,e,n){return e+(n-e)*t}function R(t,e,n){return(t-e)/(n-e)}function x(){return x=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},x.apply(this,arguments)}function w(t,n){var a=!0,i=!0,r=!0;if(e(n.alpha)&&n.alpha.length>=2){var o=t.alpha+n.alpha[0],s=t.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?t.alpha>o&&t.alpha<s:t.alpha>o||t.alpha<s}return e(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var L=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 E=n()&&void 0!==u.AlipayJSBridge,O=void 0!==u.WindVane,P={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},D=function(){function t(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=x({},P.validRange,t.validRange),n=x({},P,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new L({stableRange:a}),this.filterY=new L({stableRange:a})}var e=t.prototype;return e.watch=function(t){var e=this;if("function"==typeof t&&!this.watchListener){var n,i,r,o,s,c,l=0,f=0,p=NaN,m=NaN,v=function(a){e.stoped||(n=a.alpha||0,i=a.beta||0,r=a.gamma||0,o=w.call(e,{alpha:n,beta:i,gamma:r},e.options.validRange),isNaN(p)&&(p=r,e.filterX.lastValue=r),isNaN(m)&&(m=i,e.filterY.lastValue=i),o&&(e.options.X?(s=e.options.relativeGamma?r-p:r,s=e.filterX.stableFix(s),s=e.filterX.changeLimit(s),s=e.filterX.linearRegressionMedian(+s)):s=0,e.options.Y?(c=e.options.relativeBeta?i-m:i,c=e.filterY.stableFix(c),c=e.filterY.changeLimit(c),c=e.filterY.linearRegressionMedian(+c)):c=0,e.isValid(s,c)&&(e.options.useRequestAnimationFrame?u.requestAnimationFrame((function(){t(s,c,{alpha:n,beta:c-m,gamma:s-p})})):t(s,c,{alpha:n,beta:c-m,gamma:s-p}),e.lastX=s,e.lastY=c)))};this.stoped=!1,O?(T(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var n=t.param,a=n.x,i=n.y,r=n.z;if(a===e.prevAcceler.x&&i===e.prevAcceler.y&&r===e.prevAcceler.z)return;e.prevAcceler={x:a,y:i,z:r},v({alpha:180*+r,beta:-90*+i,gamma:90*+a})}},h.addEventListener("motion.gyro",this.watchListener,!1)):E&&!a()?(A(!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;v({alpha:180*i,beta:-90*a,gamma:90*n})}},h.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(f=(new Date).getTime())-l>=e.options.interval&&(l=f,v(t))},u.addEventListener("deviceorientation",this.watchListener,!1))}},e.unWatch=function(){i(this.watchListener),O?(T(!1),h.removeEventListener("motion.gyro",this.watchListener)):E?(A(!1),h.removeEventListener("accelerometerChange",this.watchListener)):u.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},e.pause=function(){this.stoped=!0,E&&A(!1)},e.continue=function(){this.stoped=!1,E&&A(!0,this.options.interval/1e3)},e.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function A(t,e){u.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},(function(){}))}function T(t,e){var n={on:t,frequency:e};u.WindVane.call("WVMotion","listenGyro",n,(function(t){console.info("Call WVMotion success.")}),(function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")}))}var C,V=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 D({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 j=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;F||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}p(e,t);var n=e.prototype;return n.onCompositionCreated=function(t){var e,n;this.adapter=X(),null==(e=this.adapter)||e.connect(),this.bindAccelerDocumentEvent();var a=t.loaderData.deviceTransformer=new y(t);null==(n=this.adapter)||n.addTransformer(a)},n.onCompositionDestroy=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},n.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),h.addEventListener("resume",this.handleConnect,!1),h.addEventListener("pause",this.handleDisconnect,!1),h.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){h.removeEventListener("resume",this.handleConnect),h.removeEventListener("pause",this.handleDisconnect),h.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){X().disconnect(),this.unbindAccelerDocumentEvent()},e}(g(r)),F=!1;function X(){return C||(C=new V),C}function Y(){F=!0,X().disconnect()}function N(){F=!1,X().connect()}"function"==typeof SuppressedError&&SuppressedError;var S=function(t){function e(){return t.apply(this,arguments)}p(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}(s);S=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}([o("OrientationComponent")],S),c("orientation-transformer",j);var _="2.8.5";l.info("Plugin orientation transformer version: 2.8.5."),_!==t.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!");export{V as OrientationAdapterAcceler,S as OrientationComponent,j as OrientationPluginLoader,Y as closeDeviceMotion,X as getAdapter,N as openDeviceMotion,_ as version};
|
|
1
|
+
import*as t from"@galacean/effects/alipay";import{isArray as e,isIOSByUA as n,isMiniProgram as a,assertExist as i,Plugin as r,effectsClass as o,Behaviour as s,registerPlugin as c,logger as l}from"@galacean/effects/alipay";import{window as u,document as h}from"@galacean/appx-adapter/alipay";function f(t,e){return f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},f(t,e)}function p(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&&f(t,e)}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(m=function(){return!!t})()}function v(t,e,n){return v=m()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var i=new(Function.bind.apply(t,a));return n&&f(i,n.prototype),i},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function g(t){var e="function"==typeof Map?new Map:void 0;return g=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a)}function a(){return v(t,arguments,d(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),f(a,t)},g(t)}var y=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,s=null==(n=this.records[t])?void 0:n.item;if(s){var c=this.records[t].position,l=this.records[t].rotation,u=this.targets[t],h=b(a,this.betaRange),f=b(i,this.gammaRange);if(u){var p,m,v=[c[0]+1.2*M(R(h,this.gammaRange[0],this.gammaRange[1]),u.xMin,u.xMax),c[1]+1.2*M(R(f,this.betaRange[0],this.betaRange[1]),u.yMin,u.yMax),c[2]],d=R(b(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),g=R(b(.8*r,this.betaRange),this.betaRange[0],this.betaRange[1]),y=[l[0]+M(g,u.hMin,u.hMax),l[1]+M(d,u.vMin,u.vMax),l[2]];(p=s.transform).setPosition.apply(p,[].concat(v)),(m=s.transform).setRotation.apply(m,[].concat(y)),this.currentPos[t]=v.slice(),this.currentRot[t]=y.slice()}}},t}();function b(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function M(t,e,n){return e+(n-e)*t}function R(t,e,n){return(t-e)/(n-e)}function x(){return x=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},x.apply(this,arguments)}function w(t,n){var a=!0,i=!0,r=!0;if(e(n.alpha)&&n.alpha.length>=2){var o=t.alpha+n.alpha[0],s=t.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?t.alpha>o&&t.alpha<s:t.alpha>o||t.alpha<s}return e(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var L=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 E=n()&&void 0!==u.AlipayJSBridge,O=void 0!==u.WindVane,P={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},D=function(){function t(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=x({},P.validRange,t.validRange),n=x({},P,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new L({stableRange:a}),this.filterY=new L({stableRange:a})}var e=t.prototype;return e.watch=function(t){var e=this;if("function"==typeof t&&!this.watchListener){var n,i,r,o,s,c,l=0,f=0,p=NaN,m=NaN,v=function(a){e.stoped||(n=a.alpha||0,i=a.beta||0,r=a.gamma||0,o=w.call(e,{alpha:n,beta:i,gamma:r},e.options.validRange),isNaN(p)&&(p=r,e.filterX.lastValue=r),isNaN(m)&&(m=i,e.filterY.lastValue=i),o&&(e.options.X?(s=e.options.relativeGamma?r-p:r,s=e.filterX.stableFix(s),s=e.filterX.changeLimit(s),s=e.filterX.linearRegressionMedian(+s)):s=0,e.options.Y?(c=e.options.relativeBeta?i-m:i,c=e.filterY.stableFix(c),c=e.filterY.changeLimit(c),c=e.filterY.linearRegressionMedian(+c)):c=0,e.isValid(s,c)&&(e.options.useRequestAnimationFrame?u.requestAnimationFrame((function(){t(s,c,{alpha:n,beta:c-m,gamma:s-p})})):t(s,c,{alpha:n,beta:c-m,gamma:s-p}),e.lastX=s,e.lastY=c)))};this.stoped=!1,O?(T(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var n=t.param,a=n.x,i=n.y,r=n.z;if(a===e.prevAcceler.x&&i===e.prevAcceler.y&&r===e.prevAcceler.z)return;e.prevAcceler={x:a,y:i,z:r},v({alpha:180*+r,beta:-90*+i,gamma:90*+a})}},h.addEventListener("motion.gyro",this.watchListener,!1)):E&&!a()?(A(!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;v({alpha:180*i,beta:-90*a,gamma:90*n})}},h.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(f=(new Date).getTime())-l>=e.options.interval&&(l=f,v(t))},u.addEventListener("deviceorientation",this.watchListener,!1))}},e.unWatch=function(){i(this.watchListener),O?(T(!1),h.removeEventListener("motion.gyro",this.watchListener)):E?(A(!1),h.removeEventListener("accelerometerChange",this.watchListener)):u.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},e.pause=function(){this.stoped=!0,E&&A(!1)},e.continue=function(){this.stoped=!1,E&&A(!0,this.options.interval/1e3)},e.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function A(t,e){u.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},(function(){}))}function T(t,e){var n={on:t,frequency:e};u.WindVane.call("WVMotion","listenGyro",n,(function(t){console.info("Call WVMotion success.")}),(function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")}))}var C,V=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 D({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 j=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;F||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}p(e,t);var n=e.prototype;return n.onCompositionCreated=function(t){var e,n;this.adapter=X(),null==(e=this.adapter)||e.connect(),this.bindAccelerDocumentEvent();var a=t.loaderData.deviceTransformer=new y(t);null==(n=this.adapter)||n.addTransformer(a)},n.onCompositionDestroy=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},n.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),h.addEventListener("resume",this.handleConnect,!1),h.addEventListener("pause",this.handleDisconnect,!1),h.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){h.removeEventListener("resume",this.handleConnect),h.removeEventListener("pause",this.handleDisconnect),h.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){X().disconnect(),this.unbindAccelerDocumentEvent()},e}(g(r)),F=!1;function X(){return C||(C=new V),C}function Y(){F=!0,X().disconnect()}function N(){F=!1,X().connect()}"function"==typeof SuppressedError&&SuppressedError;var S=function(t){function e(){return t.apply(this,arguments)}p(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}(s);S=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}([o("OrientationComponent")],S),c("orientation-transformer",j);var _="2.8.6";l.info("Plugin orientation transformer version: 2.8.6."),_!==t.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!");export{V as OrientationAdapterAcceler,S as OrientationComponent,j as OrientationPluginLoader,Y as closeDeviceMotion,X as getAdapter,N as openDeviceMotion,_ as version};
|
|
2
2
|
//# sourceMappingURL=alipay.mjs.map
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects player orientation transformer plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 燃然,意绮
|
|
6
|
-
* Version: v2.8.
|
|
6
|
+
* Version: v2.8.6
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -858,7 +858,7 @@ exports.OrientationComponent = __decorate([
|
|
|
858
858
|
EFFECTS.registerPlugin("orientation-transformer", OrientationPluginLoader);
|
|
859
859
|
/**
|
|
860
860
|
* 插件版本号
|
|
861
|
-
*/ var version = "2.8.
|
|
861
|
+
*/ var version = "2.8.6";
|
|
862
862
|
EFFECTS.logger.info("Plugin orientation transformer version: " + version + ".");
|
|
863
863
|
if (version !== EFFECTS__namespace.version) {
|
|
864
864
|
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!");
|
package/dist/index.min.js
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Description: Galacean Effects player orientation transformer plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 燃然,意绮
|
|
6
|
-
* Version: v2.8.
|
|
7
|
-
*/function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.orientationTransformerPlugin={}),t.ge)}(this,function(t,e){"use strict";var n,a=function(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)}(e);function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw 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)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(o=function(){return!!t})()}function s(t,e,n){return(s=o()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var r=new(Function.bind.apply(t,a));return n&&i(r,n.prototype),r}).apply(null,arguments)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),i(n,t)})(t)}var l=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=e.x,a=e.y,i=e.beta,r=e.gamma,o=null==(E=this.records[t])?void 0:E.item;if(o){var s=this.records[t].position,c=this.records[t].rotation,u=this.targets[t],l=h(n,this.betaRange),f=h(a,this.gammaRange);if(u){var p,m,d,v,g,y,b,M,w,R,x,O,E,L,P,A=[s[0]+1.2*(m=(l-(p=this.gammaRange[0]))/(this.gammaRange[1]-p),(d=u.xMin)+(u.xMax-d)*m),s[1]+1.2*(g=(f-(v=this.betaRange[0]))/(this.betaRange[1]-v),(y=u.yMin)+(u.yMax-y)*g),s[2]],D=(b=h(.8*r,this.gammaRange),(b-(M=this.gammaRange[0]))/(this.gammaRange[1]-M)),T=(w=h(.8*i,this.betaRange),(w-(R=this.betaRange[0]))/(this.betaRange[1]-R)),j=[c[0]+((x=u.hMin)+(u.hMax-x)*T),c[1]+((O=u.vMin)+(u.vMax-O)*D),c[2]];(L=o.transform).setPosition.apply(L,[].concat(A)),(P=o.transform).setRotation.apply(P,[].concat(j)),this.currentPos[t]=A.slice(),this.currentRot[t]=j.slice()}}},t}();function h(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function f(){return(f=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}).apply(this,arguments)}function p(t,n){var a=!0,i=!0,r=!0;if(e.isArray(n.alpha)&&n.alpha.length>=2){var o=t.alpha+n.alpha[0],s=t.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?t.alpha>o&&t.alpha<s:t.alpha>o||t.alpha<s}return e.isArray(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e.isArray(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var m=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),1>Math.abs(t-e)&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(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,u=0;u<e.length;u++)i+=t[u],r+=e[u],o+=t[u]*e[u],s+=t[u]*t[u],c+=e[u]*e[u];var l=i/a,h=r/a;return n.a=(o-a*l*h)/(s-a*l*l),n.b=h-n.a*l,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=this.valuePool),n=n.map(function(t,e){return a(e)}),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}(),d=e.isIOSByUA()&&void 0!==window.AlipayJSBridge,v=void 0!==window.WindVane,g={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},y=function(){function t(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=f({},g.validRange,t.validRange),n=f({},g,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new m({stableRange:a}),this.filterY=new m({stableRange:a})}var n=t.prototype;return n.watch=function(t){var n,a,i,r,o,s,c=this;if("function"==typeof t&&!this.watchListener){var u=0,l=0,h=NaN,f=NaN,m=function(e){!c.stoped&&(n=e.alpha||0,a=e.beta||0,i=e.gamma||0,r=p.call(c,{alpha:n,beta:a,gamma:i},c.options.validRange),isNaN(h)&&(h=i,c.filterX.lastValue=i),isNaN(f)&&(f=a,c.filterY.lastValue=a),r&&(c.options.X?(o=c.options.relativeGamma?i-h:i,o=c.filterX.stableFix(o),o=c.filterX.changeLimit(o),o=c.filterX.linearRegressionMedian(+o)):o=0,c.options.Y?(s=c.options.relativeBeta?a-f:a,s=c.filterY.stableFix(s),s=c.filterY.changeLimit(s),s=c.filterY.linearRegressionMedian(+s)):s=0,c.isValid(o,s)&&(c.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(o,s,{alpha:n,beta:s-f,gamma:o-h})}):t(o,s,{alpha:n,beta:s-f,gamma:o-h}),c.lastX=o,c.lastY=s)))};this.stoped=!1,v?(M(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,a=e.y,i=e.z;(n!==c.prevAcceler.x||a!==c.prevAcceler.y||i!==c.prevAcceler.z)&&(c.prevAcceler={x:n,y:a,z:i},m({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):d&&!e.isMiniProgram()?(b(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;m({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(l=new Date().getTime())-u>=c.options.interval&&(u=l,m(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),v?(M(!1),document.removeEventListener("motion.gyro",this.watchListener)):d?(b(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,d&&b(!1)},n.continue=function(){this.stoped=!1,d&&b(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function b(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function M(t,e){window.WindVane.call("WVMotion","listenGyro",{on:t,frequency:e},function(t){console.info("Call WVMotion success.")},function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")})}var w=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 y({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=a.beta,r=a.gamma;t.dispatchMotion({x:e,y:n,beta:i,gamma:r})})),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}(),R=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.order=90,e.adapter=null,e.handleConnect=function(){if(!x){var t;null==(t=e.adapter)||t.connect()}},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}r(e,t);var n=e.prototype;return n.onCompositionCreated=function(t){this.adapter=O(),null==(e=this.adapter)||e.connect(),this.bindAccelerDocumentEvent();var e,n,a=t.loaderData.deviceTransformer=new l(t);null==(n=this.adapter)||n.addTransformer(a)},n.onCompositionDestroy=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},n.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),document.addEventListener("resume",this.handleConnect,!1),document.addEventListener("pause",this.handleDisconnect,!1),document.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){document.removeEventListener("resume",this.handleConnect),document.removeEventListener("pause",this.handleDisconnect),document.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){O().disconnect(),this.unbindAccelerDocumentEvent()},e}(u(e.Plugin)),x=!1;function O(){return n||(n=new w),n}"function"==typeof SuppressedError&&SuppressedError,t.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)?void 0:null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)})},e}(e.Behaviour),t.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}([e.effectsClass("OrientationComponent")],t.OrientationComponent),e.registerPlugin("orientation-transformer",R);var E="2.8.5";e.logger.info("Plugin orientation transformer version: "+E+"."),E!==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!"),t.OrientationAdapterAcceler=w,t.OrientationPluginLoader=R,t.closeDeviceMotion=function(){x=!0,O().disconnect()},t.getAdapter=O,t.openDeviceMotion=function(){x=!1,O().connect()},t.version=E,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
6
|
+
* Version: v2.8.6
|
|
7
|
+
*/function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.orientationTransformerPlugin={}),t.ge)}(this,function(t,e){"use strict";var n,a=function(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)}(e);function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw 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)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(o=function(){return!!t})()}function s(t,e,n){return(s=o()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var r=new(Function.bind.apply(t,a));return n&&i(r,n.prototype),r}).apply(null,arguments)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),i(n,t)})(t)}var l=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=e.x,a=e.y,i=e.beta,r=e.gamma,o=null==(E=this.records[t])?void 0:E.item;if(o){var s=this.records[t].position,c=this.records[t].rotation,u=this.targets[t],l=h(n,this.betaRange),f=h(a,this.gammaRange);if(u){var p,m,d,v,g,y,b,M,w,R,x,O,E,L,P,A=[s[0]+1.2*(m=(l-(p=this.gammaRange[0]))/(this.gammaRange[1]-p),(d=u.xMin)+(u.xMax-d)*m),s[1]+1.2*(g=(f-(v=this.betaRange[0]))/(this.betaRange[1]-v),(y=u.yMin)+(u.yMax-y)*g),s[2]],D=(b=h(.8*r,this.gammaRange),(b-(M=this.gammaRange[0]))/(this.gammaRange[1]-M)),T=(w=h(.8*i,this.betaRange),(w-(R=this.betaRange[0]))/(this.betaRange[1]-R)),j=[c[0]+((x=u.hMin)+(u.hMax-x)*T),c[1]+((O=u.vMin)+(u.vMax-O)*D),c[2]];(L=o.transform).setPosition.apply(L,[].concat(A)),(P=o.transform).setRotation.apply(P,[].concat(j)),this.currentPos[t]=A.slice(),this.currentRot[t]=j.slice()}}},t}();function h(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function f(){return(f=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}).apply(this,arguments)}function p(t,n){var a=!0,i=!0,r=!0;if(e.isArray(n.alpha)&&n.alpha.length>=2){var o=t.alpha+n.alpha[0],s=t.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?t.alpha>o&&t.alpha<s:t.alpha>o||t.alpha<s}return e.isArray(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e.isArray(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var m=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),1>Math.abs(t-e)&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(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,u=0;u<e.length;u++)i+=t[u],r+=e[u],o+=t[u]*e[u],s+=t[u]*t[u],c+=e[u]*e[u];var l=i/a,h=r/a;return n.a=(o-a*l*h)/(s-a*l*l),n.b=h-n.a*l,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=this.valuePool),n=n.map(function(t,e){return a(e)}),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}(),d=e.isIOSByUA()&&void 0!==window.AlipayJSBridge,v=void 0!==window.WindVane,g={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},y=function(){function t(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=f({},g.validRange,t.validRange),n=f({},g,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new m({stableRange:a}),this.filterY=new m({stableRange:a})}var n=t.prototype;return n.watch=function(t){var n,a,i,r,o,s,c=this;if("function"==typeof t&&!this.watchListener){var u=0,l=0,h=NaN,f=NaN,m=function(e){!c.stoped&&(n=e.alpha||0,a=e.beta||0,i=e.gamma||0,r=p.call(c,{alpha:n,beta:a,gamma:i},c.options.validRange),isNaN(h)&&(h=i,c.filterX.lastValue=i),isNaN(f)&&(f=a,c.filterY.lastValue=a),r&&(c.options.X?(o=c.options.relativeGamma?i-h:i,o=c.filterX.stableFix(o),o=c.filterX.changeLimit(o),o=c.filterX.linearRegressionMedian(+o)):o=0,c.options.Y?(s=c.options.relativeBeta?a-f:a,s=c.filterY.stableFix(s),s=c.filterY.changeLimit(s),s=c.filterY.linearRegressionMedian(+s)):s=0,c.isValid(o,s)&&(c.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(o,s,{alpha:n,beta:s-f,gamma:o-h})}):t(o,s,{alpha:n,beta:s-f,gamma:o-h}),c.lastX=o,c.lastY=s)))};this.stoped=!1,v?(M(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,a=e.y,i=e.z;(n!==c.prevAcceler.x||a!==c.prevAcceler.y||i!==c.prevAcceler.z)&&(c.prevAcceler={x:n,y:a,z:i},m({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):d&&!e.isMiniProgram()?(b(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;m({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(l=new Date().getTime())-u>=c.options.interval&&(u=l,m(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),v?(M(!1),document.removeEventListener("motion.gyro",this.watchListener)):d?(b(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,d&&b(!1)},n.continue=function(){this.stoped=!1,d&&b(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function b(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function M(t,e){window.WindVane.call("WVMotion","listenGyro",{on:t,frequency:e},function(t){console.info("Call WVMotion success.")},function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")})}var w=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 y({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=a.beta,r=a.gamma;t.dispatchMotion({x:e,y:n,beta:i,gamma:r})})),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}(),R=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.order=90,e.adapter=null,e.handleConnect=function(){if(!x){var t;null==(t=e.adapter)||t.connect()}},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}r(e,t);var n=e.prototype;return n.onCompositionCreated=function(t){this.adapter=O(),null==(e=this.adapter)||e.connect(),this.bindAccelerDocumentEvent();var e,n,a=t.loaderData.deviceTransformer=new l(t);null==(n=this.adapter)||n.addTransformer(a)},n.onCompositionDestroy=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},n.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),document.addEventListener("resume",this.handleConnect,!1),document.addEventListener("pause",this.handleDisconnect,!1),document.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){document.removeEventListener("resume",this.handleConnect),document.removeEventListener("pause",this.handleDisconnect),document.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){O().disconnect(),this.unbindAccelerDocumentEvent()},e}(u(e.Plugin)),x=!1;function O(){return n||(n=new w),n}"function"==typeof SuppressedError&&SuppressedError,t.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)?void 0:null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)})},e}(e.Behaviour),t.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}([e.effectsClass("OrientationComponent")],t.OrientationComponent),e.registerPlugin("orientation-transformer",R);var E="2.8.6";e.logger.info("Plugin orientation transformer version: "+E+"."),E!==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!"),t.OrientationAdapterAcceler=w,t.OrientationPluginLoader=R,t.closeDeviceMotion=function(){x=!0,O().disconnect()},t.getAdapter=O,t.openDeviceMotion=function(){x=!1,O().connect()},t.version=E,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
8
8
|
//# sourceMappingURL=index.min.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects player orientation transformer plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 燃然,意绮
|
|
6
|
-
* Version: v2.8.
|
|
6
|
+
* Version: v2.8.6
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
@@ -835,7 +835,7 @@ OrientationComponent = __decorate([
|
|
|
835
835
|
registerPlugin("orientation-transformer", OrientationPluginLoader);
|
|
836
836
|
/**
|
|
837
837
|
* 插件版本号
|
|
838
|
-
*/ var version = "2.8.
|
|
838
|
+
*/ var version = "2.8.6";
|
|
839
839
|
logger.info("Plugin orientation transformer version: " + version + ".");
|
|
840
840
|
if (version !== EFFECTS.version) {
|
|
841
841
|
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!");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galacean/effects-plugin-orientation-transformer",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.6",
|
|
4
4
|
"description": "Galacean Effects player orientation transformer plugin",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@galacean/effects": "2.8.
|
|
46
|
+
"@galacean/effects": "2.8.6"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"dev": "vite",
|