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

style: 重命名部分工具类

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