提交 523a75b3 编写于 作者: Q qiang

style: 重命名部分工具类

上级 55bdf71c
......@@ -7,9 +7,9 @@
<script>
import touchtrack from 'uni-mixins/touchtrack'
import {
N,
I,
O
Decline,
Friction,
STD
} from './utils'
var requesting = false
......@@ -205,10 +205,10 @@ export default {
this._scale = 1
this._oldScale = 1
this._STD = new O(1, 9 * Math.pow(this.dampingNumber, 2) / 40, this.dampingNumber)
this._friction = new I(1, this.frictionNumber)
this._declineX = new N()
this._declineY = new N()
this._STD = new STD(1, 9 * Math.pow(this.dampingNumber, 2) / 40, this.dampingNumber)
this._friction = new Friction(1, this.frictionNumber)
this._declineX = new Decline()
this._declineY = new Decline()
this.__touchInfo = {
historyX: [0, 0],
historyY: [0, 0],
......
......@@ -6,18 +6,18 @@ function t (t, n) {
return e(t, 0, n)
}
export function N () { }
N.prototype.x = function (e) {
export function Decline () { }
Decline.prototype.x = function (e) {
return Math.sqrt(e)
}
export function I (e, t) {
export function Friction (e, t) {
this._m = e
this._f = 1e3 * t
this._startTime = 0
this._v = 0
}
I.prototype.setV = function (x, y) {
Friction.prototype.setV = function (x, y) {
var n = Math.pow(Math.pow(x, 2) + Math.pow(y, 2), 0.5)
this._x_v = x
this._y_v = y
......@@ -27,11 +27,11 @@ I.prototype.setV = function (x, y) {
this._lastDt = null
this._startTime = (new Date()).getTime()
}
I.prototype.setS = function (x, y) {
Friction.prototype.setS = function (x, y) {
this._x_s = x
this._y_s = y
}
I.prototype.s = function (t) {
Friction.prototype.s = function (t) {
if (undefined === t) {
t = ((new Date()).getTime() - this._startTime) / 1e3
}
......@@ -52,7 +52,7 @@ I.prototype.s = function (t) {
y
}
}
I.prototype.ds = function (t) {
Friction.prototype.ds = function (t) {
if (undefined === t) {
t = ((new Date()).getTime() - this._startTime) / 1e3
}
......@@ -64,30 +64,30 @@ I.prototype.ds = function (t) {
dy: this._y_v + this._y_a * t
}
}
I.prototype.delta = function () {
Friction.prototype.delta = function () {
return {
x: -1.5 * Math.pow(this._x_v, 2) / this._x_a || 0,
y: -1.5 * Math.pow(this._y_v, 2) / this._y_a || 0
}
}
I.prototype.dt = function () {
Friction.prototype.dt = function () {
return -this._x_v / this._x_a
}
I.prototype.done = function () {
Friction.prototype.done = function () {
var t = e(this.s().x, this._endPositionX) || e(this.s().y, this._endPositionY) || this._lastDt === this._t
this._lastDt = null
return t
}
I.prototype.setEnd = function (x, y) {
Friction.prototype.setEnd = function (x, y) {
this._endPositionX = x
this._endPositionY = y
}
I.prototype.reconfigure = function (m, f) {
Friction.prototype.reconfigure = function (m, f) {
this._m = m
this._f = 1e3 * f
}
export function R (m, k, c) {
export function Spring (m, k, c) {
this._m = m
this._k = k
this._c = c
......@@ -95,7 +95,7 @@ export function R (m, k, c) {
this._endPosition = 0
this._startTime = 0
}
R.prototype._solve = function (e, t) {
Spring.prototype._solve = function (e, t) {
var n = this._c
var i = this._m
var r = this._k
......@@ -170,19 +170,19 @@ R.prototype._solve = function (e, t) {
}
}
}
R.prototype.x = function (e) {
Spring.prototype.x = function (e) {
if (undefined === e) {
e = ((new Date()).getTime() - this._startTime) / 1e3
}
return this._solution ? this._endPosition + this._solution.x(e) : 0
}
R.prototype.dx = function (e) {
Spring.prototype.dx = function (e) {
if (undefined === e) {
e = ((new Date()).getTime() - this._startTime) / 1e3
}
return this._solution ? this._solution.dx(e) : 0
}
R.prototype.setEnd = function (e, n, i) {
Spring.prototype.setEnd = function (e, n, i) {
if (!i) {
i = (new Date()).getTime()
}
......@@ -209,7 +209,7 @@ R.prototype.setEnd = function (e, n, i) {
}
}
}
R.prototype.snap = function (e) {
Spring.prototype.snap = function (e) {
this._startTime = (new Date()).getTime()
this._endPosition = e
this._solution = {
......@@ -221,13 +221,13 @@ R.prototype.snap = function (e) {
}
}
}
R.prototype.done = function (n) {
Spring.prototype.done = function (n) {
if (!n) {
n = (new Date()).getTime()
}
return e(this.x(), this._endPosition, 0.1) && t(this.dx(), 0.1)
}
R.prototype.reconfigure = function (m, t, c) {
Spring.prototype.reconfigure = function (m, t, c) {
this._m = m
this._k = t
this._c = c
......@@ -236,13 +236,13 @@ R.prototype.reconfigure = function (m, t, c) {
this._startTime = (new Date()).getTime()
}
}
R.prototype.springConstant = function () {
Spring.prototype.springConstant = function () {
return this._k
}
R.prototype.damping = function () {
Spring.prototype.damping = function () {
return this._c
}
R.prototype.configuration = function () {
Spring.prototype.configuration = function () {
function e (e, t) {
e.reconfigure(1, t, e.damping())
}
......@@ -265,20 +265,20 @@ R.prototype.configuration = function () {
}]
}
export function O (e, t, n) {
this._springX = new R(e, t, n)
this._springY = new R(e, t, n)
this._springScale = new R(e, t, n)
export function STD (e, t, n) {
this._springX = new Spring(e, t, n)
this._springY = new Spring(e, t, n)
this._springScale = new Spring(e, t, n)
this._startTime = 0
}
O.prototype.setEnd = function (e, t, n, i) {
STD.prototype.setEnd = function (e, t, n, i) {
var r = (new Date()).getTime()
this._springX.setEnd(e, i, r)
this._springY.setEnd(t, i, r)
this._springScale.setEnd(n, i, r)
this._startTime = r
}
O.prototype.x = function () {
STD.prototype.x = function () {
var e = ((new Date()).getTime() - this._startTime) / 1e3
return {
x: this._springX.x(e),
......@@ -286,11 +286,11 @@ O.prototype.x = function () {
scale: this._springScale.x(e)
}
}
O.prototype.done = function () {
STD.prototype.done = function () {
var e = (new Date()).getTime()
return this._springX.done(e) && this._springY.done(e) && this._springScale.done(e)
}
O.prototype.reconfigure = function (e, t, n) {
STD.prototype.reconfigure = function (e, t, n) {
this._springX.reconfigure(e, t, n)
this._springY.reconfigure(e, t, n)
this._springScale.reconfigure(e, t, n)
......
export function R (e) {
export function Friction (e) {
this._drag = e
this._dragLog = Math.log(e)
this._x = 0
......@@ -6,15 +6,15 @@ export function R (e) {
this._startTime = 0
}
R.prototype.set = function (e, t) {
Friction.prototype.set = function (e, t) {
this._x = e
this._v = t
this._startTime = (new Date()).getTime()
}
R.prototype.setVelocityByEnd = function (e) {
Friction.prototype.setVelocityByEnd = function (e) {
this._v = (e - this._x) * this._dragLog / (Math.pow(this._drag, 100) - 1)
}
R.prototype.x = function (e) {
Friction.prototype.x = function (e) {
if (e === undefined) {
e = ((new Date()).getTime() - this._startTime) / 1e3
}
......@@ -23,7 +23,7 @@ R.prototype.x = function (e) {
this._dt = e
return this._x + this._v * t / this._dragLog - this._v / this._dragLog
}
R.prototype.dx = function (e) {
Friction.prototype.dx = function (e) {
if (e === undefined) {
e = ((new Date()).getTime() - this._startTime) / 1e3
}
......@@ -32,17 +32,17 @@ R.prototype.dx = function (e) {
this._dt = e
return this._v * t
}
R.prototype.done = function () {
Friction.prototype.done = function () {
return Math.abs(this.dx()) < 3
}
R.prototype.reconfigure = function (e) {
Friction.prototype.reconfigure = function (e) {
var t = this.x()
var n = this.dx()
this._drag = e
this._dragLog = Math.log(e)
this.set(t, n)
}
R.prototype.configuration = function () {
Friction.prototype.configuration = function () {
var e = this
return [{
label: 'Friction',
......
import { R } from './R'
import { S } from './S'
import { Friction } from './Friction'
import { Spring } from './Spring'
export function L (extent) {
export function Scroll (extent) {
this._extent = extent
this._friction = new R(0.01)
this._spring = new S(1, 90, 20)
this._friction = new Friction(0.01)
this._spring = new Spring(1, 90, 20)
this._startTime = 0
this._springing = false
this._springOffset = 0
}
L.prototype.snap = function (e, t) {
Scroll.prototype.snap = function (e, t) {
this._springOffset = 0
this._springing = true
this._spring.snap(e)
this._spring.setEnd(t)
}
L.prototype.set = function (e, t) {
Scroll.prototype.set = function (e, t) {
this._friction.set(e, t)
if (e > 0 && t >= 0) {
this._springOffset = 0
......@@ -35,7 +35,7 @@ L.prototype.set = function (e, t) {
}
this._startTime = (new Date()).getTime()
}
L.prototype.x = function (e) {
Scroll.prototype.x = function (e) {
if (!this._startTime) {
return 0
}
......@@ -59,20 +59,20 @@ L.prototype.x = function (e) {
}
return t
}
L.prototype.dx = function (e) {
Scroll.prototype.dx = function (e) {
var t = 0
t = this._lastTime === e ? this._lastDx : this._springing ? this._spring.dx(e) : this._friction.dx(e)
this._lastTime = e
this._lastDx = t
return t
}
L.prototype.done = function () {
Scroll.prototype.done = function () {
return this._springing ? this._spring.done() : this._friction.done()
}
L.prototype.setVelocityByEnd = function (e) {
Scroll.prototype.setVelocityByEnd = function (e) {
this._friction.setVelocityByEnd(e)
}
L.prototype.configuration = function () {
Scroll.prototype.configuration = function () {
var e = this._friction.configuration()
e.push.apply(e, this._spring.configuration())
return e
......
import { L } from './L'
import { Scroll } from './Scroll'
function i (scroll, t, n) {
function i (t, scroll, r, o) {
......@@ -53,7 +53,7 @@ export function Scroller (element, options) {
}
this._position = 0
this._scroll = new L(this._extent)
this._scroll = new Scroll(this._extent)
this._onTransitionEnd = this.onTransitionEnd.bind(this)
this.updatePosition()
}
......
......@@ -6,7 +6,7 @@ function a (e, t) {
return o(e, 0, t)
}
export function S (e, t, n) {
export function Spring (e, t, n) {
this._m = e
this._k = t
this._c = n
......@@ -15,7 +15,7 @@ export function S (e, t, n) {
this._startTime = 0
}
S.prototype._solve = function (e, t) {
Spring.prototype._solve = function (e, t) {
var n = this._c
var i = this._m
var r = this._k
......@@ -95,19 +95,19 @@ S.prototype._solve = function (e, t) {
}
}
}
S.prototype.x = function (e) {
Spring.prototype.x = function (e) {
if (e === undefined) {
e = ((new Date()).getTime() - this._startTime) / 1e3
}
return this._solution ? this._endPosition + this._solution.x(e) : 0
}
S.prototype.dx = function (e) {
Spring.prototype.dx = function (e) {
if (e === undefined) {
e = ((new Date()).getTime() - this._startTime) / 1e3
}
return this._solution ? this._solution.dx(e) : 0
}
S.prototype.setEnd = function (e, t, n) {
Spring.prototype.setEnd = function (e, t, n) {
if (!n) {
n = (new Date()).getTime()
}
......@@ -134,7 +134,7 @@ S.prototype.setEnd = function (e, t, n) {
}
}
}
S.prototype.snap = function (e) {
Spring.prototype.snap = function (e) {
this._startTime = (new Date()).getTime()
this._endPosition = e
this._solution = {
......@@ -146,13 +146,13 @@ S.prototype.snap = function (e) {
}
}
}
S.prototype.done = function (e) {
Spring.prototype.done = function (e) {
if (!e) {
e = (new Date()).getTime()
}
return o(this.x(), this._endPosition, 0.4) && a(this.dx(), 0.4)
}
S.prototype.reconfigure = function (e, t, n) {
Spring.prototype.reconfigure = function (e, t, n) {
this._m = e
this._k = t
this._c = n
......@@ -161,13 +161,13 @@ S.prototype.reconfigure = function (e, t, n) {
this._startTime = (new Date()).getTime()
}
}
S.prototype.springConstant = function () {
Spring.prototype.springConstant = function () {
return this._k
}
S.prototype.damping = function () {
Spring.prototype.damping = function () {
return this._c
}
S.prototype.configuration = function () {
Spring.prototype.configuration = function () {
function e (e, t) {
e.reconfigure(1, t, e.damping())
}
......
import { Scroller } from './C'
import { Scroller } from './Scroller'
export default {
methods: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册