@any-touch/compute
Advanced tools
Comparing version 1.0.15 to 2.0.0-alpha.0
@@ -1,2 +0,2 @@ | ||
import type { Input, VS, Point } from '@any-touch/shared'; | ||
import type { Input, Computed } from '@any-touch/shared'; | ||
/** | ||
@@ -6,16 +6,5 @@ * 计算角度 | ||
*/ | ||
declare function ComputeAngle(): (input: Input & { | ||
_vs?: VS; | ||
}) => void | { | ||
export default function ComputeAngle(): (input: Input, computed: Computed) => { | ||
angle: number; | ||
deltaAngle: number; | ||
_vs: { | ||
prevV: Point; | ||
startV: Point; | ||
activeV: Point; | ||
}; | ||
}; | ||
declare namespace ComputeAngle { | ||
var _id: string; | ||
} | ||
export default ComputeAngle; |
import type { Input } from '@any-touch/shared'; | ||
declare function ComputeDeltaXY(): (input: Input) => { | ||
export default function (): (input: Input) => { | ||
deltaX: number; | ||
@@ -7,5 +7,1 @@ deltaY: number; | ||
}; | ||
declare namespace ComputeDeltaXY { | ||
var _id: string; | ||
} | ||
export default ComputeDeltaXY; |
import type { Input, directionString } from '@any-touch/shared'; | ||
declare function ComputeDistance(): (input: Input) => { | ||
export default function (): (input: Input) => { | ||
displacementX: number; | ||
@@ -10,5 +10,1 @@ displacementY: number; | ||
}; | ||
declare namespace ComputeDistance { | ||
var _id: string; | ||
} | ||
export default ComputeDistance; |
@@ -1,8 +0,5 @@ | ||
import type { Input } from '@any-touch/shared'; | ||
import { Input } from '@any-touch/shared'; | ||
declare function ComputeMaxLength(): (input: Input) => { | ||
maxPointLength: number; | ||
}; | ||
declare namespace ComputeMaxLength { | ||
var _id: string; | ||
} | ||
export default ComputeMaxLength; |
@@ -1,16 +0,5 @@ | ||
import type { Input, Point, VS } from '@any-touch/shared'; | ||
declare function ComputeScale(): (input: Input & { | ||
_vs?: VS; | ||
}) => void | { | ||
import type { Input, Computed } from '@any-touch/shared'; | ||
export default function (): (input: Input, computed: Computed) => { | ||
scale: number; | ||
deltaScale: number; | ||
_vs: { | ||
prevV: Point; | ||
startV: Point; | ||
activeV: Point; | ||
}; | ||
}; | ||
declare namespace ComputeScale { | ||
var _id: string; | ||
} | ||
export default ComputeScale; |
import type { Input, directionString } from '@any-touch/shared'; | ||
declare function ComputeVAndDir(): (input: Input) => { | ||
export default function (): (input: Input) => { | ||
velocityX: number; | ||
velocityY: number; | ||
speedX: number; | ||
speedY: number; | ||
velocityX: number; | ||
velocityY: number; | ||
direction?: directionString; | ||
direction: directionString; | ||
}; | ||
declare namespace ComputeVAndDir { | ||
var _id: string; | ||
} | ||
export default ComputeVAndDir; |
export { default as ComputeAngle } from './ComputeAngle'; | ||
export { default as ComputeDeltaXY } from './ComputeDeltaXY'; | ||
export { default as ComputeDistance } from './ComputeDistance'; | ||
export { default as ComputeMaxLength } from './ComputeMaxLength'; | ||
export { default as ComputeScale } from './ComputeScale'; | ||
export { default as ComputeVAndDir } from './ComputeVAndDir'; | ||
export { default as ComputeMaxLength } from './ComputeMaxLength'; | ||
export { default as ComputeVectorForMutli } from './ComputeVectorForMutli'; |
@@ -1,141 +0,1 @@ | ||
import { getAngle, radianToAngle, getVLength, getDirection } from '@any-touch/vector'; | ||
import { CLIENT_X, CLIENT_Y, INPUT_START, INPUT_MOVE, round2, COMPUTE_INTERVAL } from '@any-touch/shared'; | ||
function computeVector(input) { | ||
return { | ||
x: input.points[1][CLIENT_X] - input.points[0][CLIENT_X], | ||
y: input.points[1][CLIENT_Y] - input.points[0][CLIENT_Y] | ||
}; | ||
} | ||
function _computeVectorForMutli (input) { | ||
var prevInput = input.prevInput, startMultiInput = input.startMultiInput; | ||
if (void 0 !== startMultiInput && | ||
void 0 !== prevInput && | ||
input.id !== startMultiInput.id && | ||
1 < prevInput.pointLength && | ||
1 < input.pointLength) { | ||
return { | ||
startV: computeVector(startMultiInput), | ||
prevV: computeVector(prevInput), | ||
activeV: computeVector(input) | ||
}; | ||
} | ||
} | ||
function ComputeAngle() { | ||
return function (input) { | ||
var _vs = (input === null || input === void 0 ? void 0 : input._vs) || _computeVectorForMutli(input); | ||
if (void 0 !== _vs && _vs.activeV) { | ||
var prevV = _vs.prevV, startV = _vs.startV, activeV = _vs.activeV; | ||
var deltaAngle = Math.round(getAngle(activeV, prevV)); | ||
var angle = Math.round(getAngle(activeV, startV)); | ||
return { angle: angle, deltaAngle: deltaAngle, _vs: _vs }; | ||
} | ||
}; | ||
} | ||
ComputeAngle._id = "a"; | ||
function ComputeDeltaXY() { | ||
return function (input) { | ||
var prevInput = input.prevInput; | ||
var deltaX = 0; | ||
var deltaY = 0; | ||
var deltaXYAngle = 0; | ||
if (void 0 !== prevInput) { | ||
deltaX = input.x - prevInput.x; | ||
deltaY = input.y - prevInput.y; | ||
if (0 !== deltaX || 0 !== deltaY) { | ||
var deltaXY = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); | ||
deltaXYAngle = Math.round(radianToAngle(Math.acos(Math.abs(deltaX) / deltaXY))); | ||
} | ||
} | ||
return { deltaX: deltaX, deltaY: deltaY, deltaXYAngle: deltaXYAngle }; | ||
}; | ||
} | ||
ComputeDeltaXY._id = "b"; | ||
function ComputeDistance() { | ||
var displacementX = 0; | ||
var displacementY = 0; | ||
var distanceX = 0; | ||
var distanceY = 0; | ||
var distance = 0; | ||
var overallDirection; | ||
return function (input) { | ||
var stage = input.stage, startInput = input.startInput; | ||
if (INPUT_START === stage) { | ||
displacementX = 0; | ||
displacementY = 0; | ||
distanceX = 0; | ||
distanceY = 0; | ||
distance = 0; | ||
} | ||
else if (INPUT_MOVE === stage) { | ||
displacementX = Math.round(input.points[0][CLIENT_X] - startInput.points[0][CLIENT_X]); | ||
displacementY = Math.round(input.points[0][CLIENT_Y] - startInput.points[0][CLIENT_Y]); | ||
distanceX = Math.abs(displacementX); | ||
distanceY = Math.abs(displacementY); | ||
distance = Math.round(getVLength({ x: distanceX, y: distanceY })); | ||
overallDirection = getDirection(displacementX, displacementY); | ||
} | ||
return { | ||
displacementX: displacementX, displacementY: displacementY, distanceX: distanceX, distanceY: distanceY, distance: distance, overallDirection: overallDirection | ||
}; | ||
}; | ||
} | ||
ComputeDistance._id = "c"; | ||
function ComputeMaxLength() { | ||
var maxPointLength = 0; | ||
return function (input) { | ||
var stage = input.stage; | ||
if (INPUT_START === stage) { | ||
maxPointLength = input.pointLength; | ||
} | ||
return { maxPointLength: maxPointLength }; | ||
}; | ||
} | ||
ComputeMaxLength._id = "d"; | ||
function ComputeScale() { | ||
return function (input) { | ||
var _vs = (input === null || input === void 0 ? void 0 : input._vs) || _computeVectorForMutli(input); | ||
if (void 0 !== _vs && _vs.activeV) { | ||
var prevV = _vs.prevV, startV = _vs.startV, activeV = _vs.activeV; | ||
var deltaScale = round2(getVLength(activeV) / getVLength(prevV)); | ||
var scale = round2(getVLength(activeV) / getVLength(startV)); | ||
return { scale: scale, deltaScale: deltaScale, _vs: _vs }; | ||
} | ||
}; | ||
} | ||
ComputeScale._id = "e"; | ||
function ComputeVAndDir() { | ||
var velocityX = 0; | ||
var velocityY = 0; | ||
var speedX = 0; | ||
var speedY = 0; | ||
var direction; | ||
var _lastValidInput; | ||
return function (input) { | ||
if (void 0 !== input) { | ||
var stage = input.stage; | ||
_lastValidInput = _lastValidInput || input.startInput; | ||
var deltaTime = input.timestamp - _lastValidInput.timestamp; | ||
if (INPUT_MOVE === stage && COMPUTE_INTERVAL < deltaTime) { | ||
var deltaX = input.x - _lastValidInput.x; | ||
var deltaY = input.y - _lastValidInput.y; | ||
speedX = Math.round(deltaX / deltaTime * 100) / 100; | ||
speedY = Math.round(deltaY / deltaTime * 100) / 100; | ||
velocityX = Math.abs(speedX); | ||
velocityY = Math.abs(speedY); | ||
direction = getDirection(deltaX, deltaY) || direction; | ||
_lastValidInput = input; | ||
} | ||
} | ||
return { velocityX: velocityX, velocityY: velocityY, speedX: speedX, speedY: speedY, direction: direction }; | ||
}; | ||
} | ||
ComputeVAndDir._id = "f"; | ||
export { ComputeAngle, ComputeDeltaXY, ComputeDistance, ComputeMaxLength, ComputeScale, ComputeVAndDir }; | ||
import{getAngle as t,radianToAngle as n,getVLength as r,getDirection as a}from"@any-touch/vector";import{TYPE_START as e,TYPE_MOVE as o,CLIENT_X as i,CLIENT_Y as u,round2 as c,COMPUTE_INTERVAL as p}from"@any-touch/shared";function s(){var n=0,r=0;return function(a,e){var o=e.prevVecotr,i=e.startVecotr,u=e.activeVecotr;return u&&(r=Math.round(t(u,o)),n=Math.round(t(u,i))),{angle:n,deltaAngle:r}}}function v(){return function(t){var r=t.prevInput,a=0,e=0,o=0;if(void 0!==r&&(a=t.x-r.x,e=t.y-r.y,0!==a||0!==e)){var i=Math.sqrt(Math.pow(a,2)+Math.pow(e,2));o=Math.round(n(Math.acos(Math.abs(a)/i)))}return{deltaX:a,deltaY:e,deltaXYAngle:o}}}function d(){var t,n=0,c=0,p=0,s=0,v=0;return function(d){var h=d.phase,f=d.startInput;return e===h?(n=0,c=0,p=0,s=0,v=0):o===h&&(n=Math.round(d.points[0][i]-f.points[0][i]),c=Math.round(d.points[0][u]-f.points[0][u]),p=Math.abs(n),s=Math.abs(c),v=Math.round(r({x:p,y:s})),t=a(n,c)),{displacementX:n,displacementY:c,distanceX:p,distanceY:s,distance:v,overallDirection:t}}}function h(){var t=1,n=1;return function(a,e){var o=e.prevVecotr,i=e.startVecotr,u=e.activeVecotr;return u&&(t=c(r(u)/r(o)),n=c(r(u)/r(i))),{scale:n,deltaScale:t}}}function f(){var t,n,r=0,e=0,o=0,i=0;return function(u){if(void 0!==u){n=n||u.startInput;var c=u.timestamp-n.timestamp;if(p<c){var s=u.x-n.x,v=u.y-n.y;o=Math.round(s/c*100)/100,i=Math.round(v/c*100)/100,r=Math.abs(o),e=Math.abs(i),t=a(s,v)||t,n=u}}return{velocityX:r,velocityY:e,speedX:o,speedY:i,direction:t}}}function M(){var t=0;return function(n){var r=n.phase;return e===r&&(t=n.pointLength),{maxPointLength:t}}}function l(t){return{x:t.points[1][i]-t.points[0][i],y:t.points[1][u]-t.points[0][u]}}function m(){var t,n,r;return function(a){var e=a.prevInput,o=a.startMultiInput;return void 0!==o&&void 0!==e&&a.id!==o.id&&1<e.pointLength&&1<a.pointLength&&(t=l(o),n=l(e),r=l(a)),{startVecotr:t,prevVecotr:n,activeVecotr:r}}}export{s as ComputeAngle,v as ComputeDeltaXY,d as ComputeDistance,M as ComputeMaxLength,h as ComputeScale,f as ComputeVAndDir,m as ComputeVectorForMutli}; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@any-touch/vector"),e=require("@any-touch/shared");function n(t){return{x:t.points[1][e.CLIENT_X]-t.points[0][e.CLIENT_X],y:t.points[1][e.CLIENT_Y]-t.points[0][e.CLIENT_Y]}}function r(t){var e=t.prevInput,r=t.startMultiInput;if(void 0!==r&&void 0!==e&&t.id!==r.id&&1<e.pointLength&&1<t.pointLength)return{startV:n(r),prevV:n(e),activeV:n(t)}}function a(){return function(e){var n=(null==e?void 0:e._vs)||r(e);if(void 0!==n&&n.activeV){var a=n.prevV,i=n.startV,o=n.activeV,u=Math.round(t.getAngle(o,a));return{angle:Math.round(t.getAngle(o,i)),deltaAngle:u,_vs:n}}}}function i(){return function(e){var n=e.prevInput,r=0,a=0,i=0;if(void 0!==n&&(r=e.x-n.x,a=e.y-n.y,0!==r||0!==a)){var o=Math.sqrt(Math.pow(r,2)+Math.pow(a,2));i=Math.round(t.radianToAngle(Math.acos(Math.abs(r)/o)))}return{deltaX:r,deltaY:a,deltaXYAngle:i}}}function o(){var n,r=0,a=0,i=0,o=0,u=0;return function(s){var d=s.stage,p=s.startInput;return e.INPUT_START===d?(r=0,a=0,i=0,o=0,u=0):e.INPUT_MOVE===d&&(r=Math.round(s.points[0][e.CLIENT_X]-p.points[0][e.CLIENT_X]),a=Math.round(s.points[0][e.CLIENT_Y]-p.points[0][e.CLIENT_Y]),i=Math.abs(r),o=Math.abs(a),u=Math.round(t.getVLength({x:i,y:o})),n=t.getDirection(r,a)),{displacementX:r,displacementY:a,distanceX:i,distanceY:o,distance:u,overallDirection:n}}}function u(){var t=0;return function(n){var r=n.stage;return e.INPUT_START===r&&(t=n.pointLength),{maxPointLength:t}}}function s(){return function(n){var a=(null==n?void 0:n._vs)||r(n);if(void 0!==a&&a.activeV){var i=a.prevV,o=a.startV,u=a.activeV,s=e.round2(t.getVLength(u)/t.getVLength(i));return{scale:e.round2(t.getVLength(u)/t.getVLength(o)),deltaScale:s,_vs:a}}}}function d(){var n,r,a=0,i=0,o=0,u=0;return function(s){if(void 0!==s){var d=s.stage;r=r||s.startInput;var p=s.timestamp-r.timestamp;if(e.INPUT_MOVE===d&&e.COMPUTE_INTERVAL<p){var v=s.x-r.x,c=s.y-r.y;o=Math.round(v/p*100)/100,u=Math.round(c/p*100)/100,a=Math.abs(o),i=Math.abs(u),n=t.getDirection(v,c)||n,r=s}}return{velocityX:a,velocityY:i,speedX:o,speedY:u,direction:n}}}a._id="a",i._id="b",o._id="c",u._id="d",s._id="e",d._id="f",exports.ComputeAngle=a,exports.ComputeDeltaXY=i,exports.ComputeDistance=o,exports.ComputeMaxLength=u,exports.ComputeScale=s,exports.ComputeVAndDir=d; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@any-touch/vector"),e=require("@any-touch/shared");function n(t){return{x:t.points[1][e.CLIENT_X]-t.points[0][e.CLIENT_X],y:t.points[1][e.CLIENT_Y]-t.points[0][e.CLIENT_Y]}}exports.ComputeAngle=function(){var e=0,n=0;return function(r,o){var a=o.prevVecotr,i=o.startVecotr,u=o.activeVecotr;return u&&(n=Math.round(t.getAngle(u,a)),e=Math.round(t.getAngle(u,i))),{angle:e,deltaAngle:n}}},exports.ComputeDeltaXY=function(){return function(e){var n=e.prevInput,r=0,o=0,a=0;if(void 0!==n&&(r=e.x-n.x,o=e.y-n.y,0!==r||0!==o)){var i=Math.sqrt(Math.pow(r,2)+Math.pow(o,2));a=Math.round(t.radianToAngle(Math.acos(Math.abs(r)/i)))}return{deltaX:r,deltaY:o,deltaXYAngle:a}}},exports.ComputeDistance=function(){var n,r=0,o=0,a=0,i=0,u=0;return function(c){var p=c.phase,s=c.startInput;return e.TYPE_START===p?(r=0,o=0,a=0,i=0,u=0):e.TYPE_MOVE===p&&(r=Math.round(c.points[0][e.CLIENT_X]-s.points[0][e.CLIENT_X]),o=Math.round(c.points[0][e.CLIENT_Y]-s.points[0][e.CLIENT_Y]),a=Math.abs(r),i=Math.abs(o),u=Math.round(t.getVLength({x:a,y:i})),n=t.getDirection(r,o)),{displacementX:r,displacementY:o,distanceX:a,distanceY:i,distance:u,overallDirection:n}}},exports.ComputeMaxLength=function(){var t=0;return function(n){var r=n.phase;return e.TYPE_START===r&&(t=n.pointLength),{maxPointLength:t}}},exports.ComputeScale=function(){var n=1,r=1;return function(o,a){var i=a.prevVecotr,u=a.startVecotr,c=a.activeVecotr;return c&&(n=e.round2(t.getVLength(c)/t.getVLength(i)),r=e.round2(t.getVLength(c)/t.getVLength(u))),{scale:r,deltaScale:n}}},exports.ComputeVAndDir=function(){var n,r,o=0,a=0,i=0,u=0;return function(c){if(void 0!==c){r=r||c.startInput;var p=c.timestamp-r.timestamp;if(e.COMPUTE_INTERVAL<p){var s=c.x-r.x,d=c.y-r.y;i=Math.round(s/p*100)/100,u=Math.round(d/p*100)/100,o=Math.abs(i),a=Math.abs(u),n=t.getDirection(s,d)||n,r=c}}return{velocityX:o,velocityY:a,speedX:i,speedY:u,direction:n}}},exports.ComputeVectorForMutli=function(){var t,e,r;return function(o){var a=o.prevInput,i=o.startMultiInput;return void 0!==i&&void 0!==a&&o.id!==i.id&&1<a.pointLength&&1<o.pointLength&&(t=n(i),e=n(a),r=n(o)),{startVecotr:t,prevVecotr:e,activeVecotr:r}}}; |
{ | ||
"name": "@any-touch/compute", | ||
"version": "1.0.15", | ||
"version": "2.0.0-alpha.0", | ||
"main": "dist/index.js", | ||
@@ -14,5 +14,5 @@ "module": "dist/index.es.js", | ||
"dependencies": { | ||
"@any-touch/shared": "^1.0.15", | ||
"@any-touch/vector": "^1.0.15", | ||
"tslib": "^1.9.3" | ||
"@any-touch/shared": "^2.0.0-alpha.0", | ||
"@any-touch/vector": "^2.0.0-alpha.0", | ||
"tslib": "^2.3.1" | ||
}, | ||
@@ -22,3 +22,3 @@ "author": "any86", | ||
"sideEffects": false, | ||
"gitHead": "20d54f8303eda39f4ef4efdd1f5e2aadde0c713e" | ||
"gitHead": "3fb899bb8ad845ab52fa4a932cc895637e173723" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8045
77
3
1
+ Added@any-touch/shared@2.2.0(transitive)
+ Added@any-touch/vector@2.2.0(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@any-touch/shared@1.0.15(transitive)
- Removed@any-touch/vector@1.0.15(transitive)
- Removedtslib@1.14.1(transitive)
Updatedtslib@^2.3.1