@leafer-in/motion-path 1.0.6-rc1

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/src/index.ts ADDED
@@ -0,0 +1,103 @@
1
+ export { HighCurveHelper } from './HighCurveHelper'
2
+ export { HighBezierHelper } from './HighBezierHelper'
3
+ export { motionPathType } from './decorator'
4
+
5
+ import { IMotionPathData, IUI, IUnitData, IRotationPointData } from '@leafer-ui/interface'
6
+ import { isNull, MatrixHelper, Transition, UI, UnitConvert } from '@leafer-ui/draw'
7
+
8
+ import { HighCurveHelper } from './HighCurveHelper'
9
+ import { motionPathType } from './decorator'
10
+
11
+
12
+ Transition.register('motion', function (from: any, to: any, t: number, target: IUI): number {
13
+ if (!from) from = 0
14
+ else if (typeof from === 'object') from = UnitConvert.number(from, target.getMotionTotal())
15
+ if (!to) to = 0
16
+ else if (typeof to === 'object') to = UnitConvert.number(to, target.getMotionTotal())
17
+ return Transition.number(from, to, t)
18
+ })
19
+
20
+
21
+ const ui = UI.prototype
22
+
23
+
24
+ // addAttr
25
+ motionPathType()(ui, 'motionPath')
26
+ motionPathType()(ui, 'motion')
27
+ motionPathType(true)(ui, 'motionRotation')
28
+
29
+
30
+ ui.getMotionPathData = function (): IMotionPathData {
31
+ const { parent } = this
32
+
33
+ if (!this.motionPath && parent) {
34
+ const { children } = parent
35
+ for (let i = 0; i < children.length; i++) {
36
+ if (children[i].motionPath) return children[i].getMotionPathData()
37
+ }
38
+ }
39
+
40
+ const data = this.__
41
+ if (data.__pathForMotion) return data.__pathForMotion
42
+ return data.__pathForMotion = HighCurveHelper.getMotionPathData(this.getPath(true, true))
43
+ }
44
+
45
+ ui.getMotionPoint = function (motionDistance: number | IUnitData): IRotationPointData {
46
+ const data = this.getMotionPathData()
47
+ const point = HighCurveHelper.getDistancePoint(data, motionDistance)
48
+ MatrixHelper.toOuterPoint(this.localTransform, point)
49
+ return point
50
+ }
51
+
52
+ ui.getMotionTotal = function (): number {
53
+ return this.getMotionPathData().total
54
+ }
55
+
56
+ ui.__updateMotionPath = function (): void {
57
+ const data = this.__
58
+ if (this.__layout.resized && data.__pathForMotion) data.__pathForMotion = undefined
59
+
60
+ if (this.motionPath) {
61
+ let child: IUI
62
+ const { children } = this.parent
63
+ for (let i = 0; i < children.length; i++) {
64
+ child = children[i]
65
+ if (!isNull(child.motion)) updateMotion(child)
66
+ }
67
+ } else {
68
+ updateMotion(this)
69
+ }
70
+ }
71
+
72
+ function updateMotion(leaf: IUI): void {
73
+ const { motion, motionRotation } = leaf
74
+ if (isNull(motion)) return
75
+
76
+ if (leaf.motionPath) {
77
+
78
+ const data = leaf.getMotionPathData()
79
+ if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion) // 生长路径
80
+
81
+ } else {
82
+
83
+ let child: IUI
84
+ const { children } = leaf.parent
85
+ for (let i = 0; i < children.length; i++) {
86
+ child = children[i]
87
+ if (child.motionPath) {
88
+ const data = child.getMotionPathData()
89
+ if (!data.total) return
90
+ const point = child.getMotionPoint(motion)
91
+ if (motionRotation === false) delete point.rotation
92
+ else {
93
+ point.rotation += child.rotation
94
+ if (typeof motionRotation === 'number') point.rotation += motionRotation
95
+ }
96
+
97
+ leaf.set(point) // 动画路径
98
+ break
99
+ }
100
+ }
101
+
102
+ }
103
+ }
@@ -0,0 +1,20 @@
1
+ import * as _leafer_ui_interface from '@leafer-ui/interface';
2
+ import { IPathCommandData, IMatrixData, IMotionPathData, IUnitData, IRotationPointData, IValue } from '@leafer-ui/interface';
3
+
4
+ declare const HighCurveHelper: {
5
+ transform(data: IPathCommandData, matrix: IMatrixData): void;
6
+ transformPoints(data: IPathCommandData, matrix: IMatrixData, start: number, pointCount: number): void;
7
+ getMotionPathData(data: IPathCommandData): IMotionPathData;
8
+ getDistancePoint(distanceData: IMotionPathData, motionDistance: number | IUnitData): IRotationPointData;
9
+ getDistancePath(distanceData: IMotionPathData, motionDistance: number | IUnitData): IPathCommandData;
10
+ };
11
+
12
+ declare const HighBezierHelper: {
13
+ getDistance(fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number): number;
14
+ getDerivative(t: number, fromV: number, v1: number, v2: number, toV: number): number;
15
+ cut(data: IPathCommandData, t: number, fromX: number, fromY: number, x1: number, y1: number, x2: number, y2: number, toX: number, toY: number): void;
16
+ };
17
+
18
+ declare function motionPathType(defaultValue?: IValue): (target: _leafer_ui_interface.ILeaf, key: string) => void;
19
+
20
+ export { HighBezierHelper, HighCurveHelper, motionPathType };