@leafer-in/motion-path 1.8.0 → 1.9.0
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/motion-path.cjs +198 -186
- package/dist/motion-path.esm.js +195 -185
- package/dist/motion-path.esm.min.js +1 -1
- package/dist/motion-path.esm.min.js.map +1 -1
- package/dist/motion-path.js +174 -193
- package/dist/motion-path.min.cjs +1 -1
- package/dist/motion-path.min.cjs.map +1 -1
- package/dist/motion-path.min.js +1 -1
- package/dist/motion-path.min.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +7 -9
package/dist/motion-path.esm.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { BezierHelper, PathCommandMap, OneRadian, UnitConvert, PointHelper, MatrixHelper, decorateLeafAttr, attr, isNull, Plugin, Transition, UI, LeafHelper, BranchHelper } from
|
|
1
|
+
import { BezierHelper, PathCommandMap, OneRadian, UnitConvert, PointHelper, MatrixHelper, decorateLeafAttr, attr, isNull, Plugin, Transition, isObject, UI, LeafHelper, BranchHelper, isNumber } from "@leafer-ui/draw";
|
|
2
|
+
|
|
3
|
+
const gaussNodes = [ .1488743389, .4333953941, .6794095682, .8650633666, .9739065285 ];
|
|
4
|
+
|
|
5
|
+
const gaussWeights = [ .2955242247, .2692667193, .2190863625, .1494513491, .0666713443 ];
|
|
6
|
+
|
|
7
|
+
const {sqrt: sqrt} = Math;
|
|
8
|
+
|
|
9
|
+
const {getDerivative: getDerivative} = BezierHelper;
|
|
2
10
|
|
|
3
|
-
const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285];
|
|
4
|
-
const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
|
|
5
|
-
const { sqrt } = Math;
|
|
6
|
-
const { getDerivative } = BezierHelper;
|
|
7
11
|
const HighBezierHelper = {
|
|
8
12
|
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
|
|
9
13
|
let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
|
|
@@ -25,10 +29,8 @@ const HighBezierHelper = {
|
|
|
25
29
|
},
|
|
26
30
|
getT(distance, totalDistance, fromX, fromY, x1, y1, x2, y2, toX, toY, precision = 1) {
|
|
27
31
|
let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3;
|
|
28
|
-
if (middle >= 1)
|
|
29
|
-
|
|
30
|
-
if (middle <= 0)
|
|
31
|
-
return 0;
|
|
32
|
+
if (middle >= 1) return 1;
|
|
33
|
+
if (middle <= 0) return 0;
|
|
32
34
|
while (high - low > realPrecision) {
|
|
33
35
|
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle;
|
|
34
36
|
middle = (low + high) / 2;
|
|
@@ -46,10 +48,13 @@ const HighBezierHelper = {
|
|
|
46
48
|
data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy);
|
|
47
49
|
}
|
|
48
50
|
};
|
|
49
|
-
const { getDistance } = HighBezierHelper;
|
|
50
51
|
|
|
51
|
-
const {
|
|
52
|
+
const {getDistance: getDistance} = HighBezierHelper;
|
|
53
|
+
|
|
54
|
+
const {M: M, L: L, C: C, Z: Z} = PathCommandMap;
|
|
55
|
+
|
|
52
56
|
const tempPoint = {}, tempFrom = {};
|
|
57
|
+
|
|
53
58
|
const HighCurveHelper = {
|
|
54
59
|
transform(data, matrix) {
|
|
55
60
|
let i = 0, command;
|
|
@@ -57,17 +62,19 @@ const HighCurveHelper = {
|
|
|
57
62
|
while (i < len) {
|
|
58
63
|
command = data[i];
|
|
59
64
|
switch (command) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
case M:
|
|
66
|
+
case L:
|
|
67
|
+
HighCurveHelper.transformPoints(data, matrix, i, 1);
|
|
68
|
+
i += 3;
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case C:
|
|
72
|
+
HighCurveHelper.transformPoints(data, matrix, i, 3);
|
|
73
|
+
i += 7;
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case Z:
|
|
77
|
+
i += 1;
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
},
|
|
@@ -87,35 +94,42 @@ const HighCurveHelper = {
|
|
|
87
94
|
while (i < len) {
|
|
88
95
|
command = data[i];
|
|
89
96
|
switch (command) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
case M:
|
|
98
|
+
case L:
|
|
99
|
+
toX = data[i + 1];
|
|
100
|
+
toY = data[i + 2];
|
|
101
|
+
distance = command === L && i > 0 ? PointHelper.getDistanceFrom(x, y, toX, toY) : 0;
|
|
102
|
+
x = toX;
|
|
103
|
+
y = toY;
|
|
104
|
+
i += 3;
|
|
105
|
+
break;
|
|
106
|
+
|
|
107
|
+
case C:
|
|
108
|
+
toX = data[i + 5];
|
|
109
|
+
toY = data[i + 6];
|
|
110
|
+
distance = HighBezierHelper.getDistance(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY);
|
|
111
|
+
x = toX;
|
|
112
|
+
y = toY;
|
|
113
|
+
i += 7;
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case Z:
|
|
117
|
+
i += 1;
|
|
118
|
+
|
|
119
|
+
default:
|
|
120
|
+
distance = 0;
|
|
111
121
|
}
|
|
112
122
|
segments.push(distance);
|
|
113
123
|
total += distance;
|
|
114
124
|
}
|
|
115
|
-
return {
|
|
125
|
+
return {
|
|
126
|
+
total: total,
|
|
127
|
+
segments: segments,
|
|
128
|
+
data: data
|
|
129
|
+
};
|
|
116
130
|
},
|
|
117
131
|
getDistancePoint(distanceData, motionDistance, motionPrecision) {
|
|
118
|
-
const { segments, data } = distanceData;
|
|
132
|
+
const {segments: segments, data: data} = distanceData;
|
|
119
133
|
motionDistance = UnitConvert.number(motionDistance, distanceData.total);
|
|
120
134
|
let total = 0, distance, to = {};
|
|
121
135
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
@@ -124,45 +138,47 @@ const HighCurveHelper = {
|
|
|
124
138
|
while (i < len) {
|
|
125
139
|
command = data[i];
|
|
126
140
|
switch (command) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
141
|
+
case M:
|
|
142
|
+
case L:
|
|
143
|
+
toX = data[i + 1];
|
|
144
|
+
toY = data[i + 2];
|
|
145
|
+
distance = segments[index];
|
|
146
|
+
if (total + distance >= motionDistance || !distanceData.total) {
|
|
147
|
+
if (!i) x = toX, y = toY;
|
|
148
|
+
tempFrom.x = x;
|
|
149
|
+
tempFrom.y = y;
|
|
150
|
+
to.x = toX;
|
|
151
|
+
to.y = toY;
|
|
152
|
+
PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
|
|
153
|
+
to.rotation = PointHelper.getAngle(tempFrom, to);
|
|
154
|
+
return to;
|
|
155
|
+
}
|
|
156
|
+
x = toX;
|
|
157
|
+
y = toY;
|
|
158
|
+
i += 3;
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
case C:
|
|
162
|
+
toX = data[i + 5];
|
|
163
|
+
toY = data[i + 6];
|
|
164
|
+
distance = segments[index];
|
|
165
|
+
if (total + distance >= motionDistance) {
|
|
166
|
+
x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
|
|
167
|
+
t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
168
|
+
BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
|
|
169
|
+
to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
|
|
170
|
+
return to;
|
|
171
|
+
}
|
|
172
|
+
x = toX;
|
|
173
|
+
y = toY;
|
|
174
|
+
i += 7;
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case Z:
|
|
178
|
+
i += 1;
|
|
179
|
+
|
|
180
|
+
default:
|
|
181
|
+
distance = 0;
|
|
166
182
|
}
|
|
167
183
|
index++;
|
|
168
184
|
total += distance;
|
|
@@ -170,7 +186,7 @@ const HighCurveHelper = {
|
|
|
170
186
|
return to;
|
|
171
187
|
},
|
|
172
188
|
getDistancePath(distanceData, motionDistance, motionPrecision) {
|
|
173
|
-
const { segments, data } = distanceData, path = [];
|
|
189
|
+
const {segments: segments, data: data} = distanceData, path = [];
|
|
174
190
|
motionDistance = UnitConvert.number(motionDistance, distanceData.total);
|
|
175
191
|
let total = 0, distance, to = {};
|
|
176
192
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
@@ -179,47 +195,49 @@ const HighCurveHelper = {
|
|
|
179
195
|
while (i < len) {
|
|
180
196
|
command = data[i];
|
|
181
197
|
switch (command) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
198
|
+
case M:
|
|
199
|
+
case L:
|
|
200
|
+
toX = data[i + 1];
|
|
201
|
+
toY = data[i + 2];
|
|
202
|
+
distance = segments[index];
|
|
203
|
+
if (total + distance >= motionDistance || !distanceData.total) {
|
|
204
|
+
if (!i) x = toX, y = toY;
|
|
205
|
+
tempFrom.x = x;
|
|
206
|
+
tempFrom.y = y;
|
|
207
|
+
to.x = toX;
|
|
208
|
+
to.y = toY;
|
|
209
|
+
PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
|
|
210
|
+
path.push(command, to.x, to.y);
|
|
211
|
+
return path;
|
|
212
|
+
}
|
|
213
|
+
x = toX;
|
|
214
|
+
y = toY;
|
|
215
|
+
i += 3;
|
|
216
|
+
path.push(command, x, y);
|
|
217
|
+
break;
|
|
218
|
+
|
|
219
|
+
case C:
|
|
220
|
+
x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
|
|
221
|
+
toX = data[i + 5];
|
|
222
|
+
toY = data[i + 6];
|
|
223
|
+
distance = segments[index];
|
|
224
|
+
if (total + distance >= motionDistance) {
|
|
225
|
+
t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
226
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
|
|
227
|
+
return path;
|
|
228
|
+
}
|
|
229
|
+
x = toX;
|
|
230
|
+
y = toY;
|
|
231
|
+
i += 7;
|
|
232
|
+
path.push(command, x1, y1, x2, y2, toX, toY);
|
|
233
|
+
break;
|
|
234
|
+
|
|
235
|
+
case Z:
|
|
236
|
+
i += 1;
|
|
237
|
+
path.push(command);
|
|
238
|
+
|
|
239
|
+
default:
|
|
240
|
+
distance = 0;
|
|
223
241
|
}
|
|
224
242
|
index++;
|
|
225
243
|
total += distance;
|
|
@@ -229,7 +247,7 @@ const HighCurveHelper = {
|
|
|
229
247
|
};
|
|
230
248
|
|
|
231
249
|
function motionPathType(defaultValue) {
|
|
232
|
-
return decorateLeafAttr(defaultValue,
|
|
250
|
+
return decorateLeafAttr(defaultValue, key => attr({
|
|
233
251
|
set(value) {
|
|
234
252
|
this.__setAttr(key, value);
|
|
235
253
|
this.__hasMotionPath = this.motionPath || !isNull(this.motion);
|
|
@@ -238,105 +256,97 @@ function motionPathType(defaultValue) {
|
|
|
238
256
|
}));
|
|
239
257
|
}
|
|
240
258
|
|
|
241
|
-
Plugin.add(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (!to)
|
|
248
|
-
to = 0;
|
|
249
|
-
else if (typeof to === 'object')
|
|
250
|
-
to = UnitConvert.number(to, target.getMotionTotal());
|
|
251
|
-
return Transition.number(from, to, t);
|
|
259
|
+
Plugin.add("motion-path");
|
|
260
|
+
|
|
261
|
+
Transition.register("motion", function(from, to, t, target) {
|
|
262
|
+
if (isObject(from)) from = UnitConvert.number(from, target.getMotionTotal());
|
|
263
|
+
if (isObject(to)) to = UnitConvert.number(to, target.getMotionTotal());
|
|
264
|
+
return Transition.number(from || 0, to || 0, t);
|
|
252
265
|
});
|
|
253
|
-
|
|
266
|
+
|
|
267
|
+
Transition.register("motionRotation", function(from, to, t) {
|
|
254
268
|
return Transition.number(from, to, t);
|
|
255
269
|
});
|
|
270
|
+
|
|
256
271
|
const ui = UI.prototype;
|
|
257
|
-
|
|
258
|
-
const {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
UI.addAttr(
|
|
263
|
-
|
|
272
|
+
|
|
273
|
+
const {updateMatrix: updateMatrix, updateAllMatrix: updateAllMatrix} = LeafHelper;
|
|
274
|
+
|
|
275
|
+
const {updateBounds: updateBounds} = BranchHelper;
|
|
276
|
+
|
|
277
|
+
UI.addAttr("motionPath", undefined, motionPathType);
|
|
278
|
+
|
|
279
|
+
UI.addAttr("motionPrecision", 1, motionPathType);
|
|
280
|
+
|
|
281
|
+
UI.addAttr("motion", undefined, motionPathType);
|
|
282
|
+
|
|
283
|
+
UI.addAttr("motionRotation", true, motionPathType);
|
|
284
|
+
|
|
285
|
+
ui.getMotionPathData = function() {
|
|
264
286
|
return getMotionPathData(getMotionPath(this));
|
|
265
287
|
};
|
|
266
|
-
|
|
288
|
+
|
|
289
|
+
ui.getMotionPoint = function(motionDistance) {
|
|
267
290
|
const path = getMotionPath(this);
|
|
268
291
|
const data = getMotionPathData(path);
|
|
269
|
-
if (!data.total)
|
|
270
|
-
return {};
|
|
292
|
+
if (!data.total) return {};
|
|
271
293
|
const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
|
|
272
294
|
MatrixHelper.toOuterPoint(path.localTransform, point);
|
|
273
|
-
const { motionRotation
|
|
274
|
-
if (motionRotation === false)
|
|
275
|
-
delete point.rotation;
|
|
276
|
-
else if (typeof motionRotation === 'number')
|
|
277
|
-
point.rotation += motionRotation;
|
|
295
|
+
const {motionRotation: motionRotation} = this;
|
|
296
|
+
if (motionRotation === false) delete point.rotation; else if (isNumber(motionRotation)) point.rotation += motionRotation;
|
|
278
297
|
return point;
|
|
279
298
|
};
|
|
280
|
-
|
|
299
|
+
|
|
300
|
+
ui.getMotionTotal = function() {
|
|
281
301
|
return this.getMotionPathData().total;
|
|
282
302
|
};
|
|
283
|
-
|
|
303
|
+
|
|
304
|
+
ui.__updateMotionPath = function() {
|
|
284
305
|
const data = this.__;
|
|
285
|
-
if (this.__layout.resized && data.__pathForMotion)
|
|
286
|
-
data.__pathForMotion = undefined;
|
|
306
|
+
if (this.__layout.resized && data.__pathForMotion) data.__pathForMotion = undefined;
|
|
287
307
|
if (this.motionPath) {
|
|
288
308
|
let child;
|
|
289
|
-
const { children
|
|
309
|
+
const {children: children} = this.parent;
|
|
290
310
|
for (let i = 0; i < children.length; i++) {
|
|
291
311
|
child = children[i];
|
|
292
312
|
if (!isNull(child.motion) && !child.__layout.matrixChanged) {
|
|
293
|
-
if (child !== this)
|
|
294
|
-
child.__extraUpdate();
|
|
313
|
+
if (child !== this) child.__extraUpdate();
|
|
295
314
|
updateMotion(child);
|
|
296
315
|
}
|
|
297
316
|
}
|
|
298
|
-
}
|
|
299
|
-
else
|
|
300
|
-
updateMotion(this);
|
|
317
|
+
} else updateMotion(this);
|
|
301
318
|
};
|
|
319
|
+
|
|
302
320
|
function updateMotion(leaf) {
|
|
303
|
-
const { motion, leaferIsCreated } = leaf;
|
|
304
|
-
if (isNull(motion))
|
|
305
|
-
|
|
306
|
-
if (leaferIsCreated)
|
|
307
|
-
leaf.leafer.created = false;
|
|
321
|
+
const {motion: motion, leaferIsCreated: leaferIsCreated} = leaf;
|
|
322
|
+
if (isNull(motion)) return;
|
|
323
|
+
if (leaferIsCreated) leaf.leafer.created = false;
|
|
308
324
|
if (leaf.motionPath) {
|
|
309
325
|
const data = getMotionPathData(leaf);
|
|
310
|
-
if (data.total)
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
326
|
+
if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
|
|
327
|
+
} else {
|
|
314
328
|
leaf.set(leaf.getMotionPoint(motion));
|
|
315
329
|
if (!leaf.__hasAutoLayout) {
|
|
316
|
-
if (leaf.isBranch)
|
|
317
|
-
updateAllMatrix(leaf), updateBounds(leaf, leaf);
|
|
318
|
-
else
|
|
319
|
-
updateMatrix(leaf);
|
|
330
|
+
if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf); else updateMatrix(leaf);
|
|
320
331
|
}
|
|
321
332
|
}
|
|
322
|
-
if (leaferIsCreated)
|
|
323
|
-
leaf.leafer.created = true;
|
|
333
|
+
if (leaferIsCreated) leaf.leafer.created = true;
|
|
324
334
|
}
|
|
335
|
+
|
|
325
336
|
function getMotionPath(leaf) {
|
|
326
|
-
const { parent
|
|
337
|
+
const {parent: parent} = leaf;
|
|
327
338
|
if (!leaf.motionPath && parent) {
|
|
328
|
-
const { children
|
|
339
|
+
const {children: children} = parent;
|
|
329
340
|
for (let i = 0; i < children.length; i++) {
|
|
330
|
-
if (children[i].motionPath)
|
|
331
|
-
return children[i];
|
|
341
|
+
if (children[i].motionPath) return children[i];
|
|
332
342
|
}
|
|
333
343
|
}
|
|
334
344
|
return leaf;
|
|
335
345
|
}
|
|
346
|
+
|
|
336
347
|
function getMotionPathData(leaf) {
|
|
337
348
|
const data = leaf.__;
|
|
338
|
-
if (data.__pathForMotion)
|
|
339
|
-
return data.__pathForMotion;
|
|
349
|
+
if (data.__pathForMotion) return data.__pathForMotion;
|
|
340
350
|
return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
|
|
341
351
|
}
|
|
342
352
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BezierHelper as t,PathCommandMap as o,OneRadian as e,UnitConvert as n,PointHelper as a,MatrixHelper as i,decorateLeafAttr as r,attr as s,isNull as c,Plugin as h,Transition as u,
|
|
1
|
+
import{BezierHelper as t,PathCommandMap as o,OneRadian as e,UnitConvert as n,PointHelper as a,MatrixHelper as i,decorateLeafAttr as r,attr as s,isNull as c,Plugin as h,Transition as u,isObject as l,UI as f,LeafHelper as g,BranchHelper as m,isNumber as d}from"@leafer-ui/draw";const _=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],P=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:p}=Math,{getDerivative:M}=t,D={getDistance(t,o,e,n,a,i,r,s,c=1){let h,u,l,f,g,m,d=0,D=c/2;for(let c=0;c<_.length;c++)h=D*(1+_[c]),u=D*(1-_[c]),l=M(h,t,e,a,r),f=M(h,o,n,i,s),g=M(u,t,e,a,r),m=M(u,o,n,i,s),d+=P[c]*(p(l*l+f*f)+p(g*g+m*m));return d*D},getRotation(t,o,n,a,i,r,s,c,h){const u=M(t,o,a,r,c),l=M(t,n,i,s,h);return Math.atan2(l,u)/e},getT(t,o,e,n,a,i,r,s,c,h,u=1){let l=0,f=1,g=t/o,m=u/o/3;if(g>=1)return 1;if(g<=0)return 0;for(;f-l>m;)b(e,n,a,i,r,s,c,h,g)<t?l=g:f=g,g=(l+f)/2;return g},cut(t,e,n,a,i,r,s,c,h,u){const l=1-e,f=l*n+e*i,g=l*a+e*r,m=l*i+e*s,d=l*r+e*c,_=l*f+e*m,P=l*g+e*d,p=l*_+e*(l*m+e*(l*s+e*h)),M=l*P+e*(l*d+e*(l*c+e*u));t.push(o.C,f,g,_,P,p,M)}},{getDistance:b}=D,{M:x,L:y,C:A,Z:k}=o,F={},T={},C={transform(t,o){let e,n=0;const a=t.length;for(;n<a;)switch(e=t[n],e){case x:case y:C.transformPoints(t,o,n,1),n+=3;break;case A:C.transformPoints(t,o,n,3),n+=7;break;case k:n+=1}},transformPoints(t,o,e,n){for(let a=e+1,r=a+2*n;a<r;a+=2)F.x=t[a],F.y=t[a+1],i.toOuterPoint(o,F),t[a]=F.x,t[a+1]=F.y},getMotionPathData(t){let o,e,n,i,r=0,s=[],c=0,h=0,u=0;const l=t.length;for(;c<l;){switch(i=t[c],i){case x:case y:e=t[c+1],n=t[c+2],o=i===y&&c>0?a.getDistanceFrom(h,u,e,n):0,h=e,u=n,c+=3;break;case A:e=t[c+5],n=t[c+6],o=D.getDistance(h,u,t[c+1],t[c+2],t[c+3],t[c+4],e,n),h=e,u=n,c+=7;break;case k:c+=1;default:o=0}s.push(o),r+=o}return{total:r,segments:s,data:t}},getDistancePoint(o,e,i){const{segments:r,data:s}=o;e=n.number(e,o.total);let c,h,u,l,f,g,m,d,_,P=0,p={},M=0,b=0,F=0,C=0;const R=s.length;for(;M<R;){switch(l=s[M],l){case x:case y:if(h=s[M+1],u=s[M+2],c=r[b],P+c>=e||!o.total)return M||(F=h,C=u),T.x=F,T.y=C,p.x=h,p.y=u,a.getDistancePoint(T,p,e-P,!0),p.rotation=a.getAngle(T,p),p;F=h,C=u,M+=3;break;case A:if(h=s[M+5],u=s[M+6],c=r[b],P+c>=e)return f=s[M+1],g=s[M+2],m=s[M+3],d=s[M+4],_=D.getT(e-P,c,F,C,f,g,m,d,h,u,i),t.getPointAndSet(_,F,C,f,g,m,d,h,u,p),p.rotation=D.getRotation(_,F,C,f,g,m,d,h,u),p;F=h,C=u,M+=7;break;case k:M+=1;default:c=0}b++,P+=c}return p},getDistancePath(t,o,e){const{segments:i,data:r}=t,s=[];o=n.number(o,t.total);let c,h,u,l,f,g,m,d,_,P=0,p={},M=0,b=0,F=0,C=0;const R=r.length;for(;M<R;){switch(l=r[M],l){case x:case y:if(h=r[M+1],u=r[M+2],c=i[b],P+c>=o||!t.total)return M||(F=h,C=u),T.x=F,T.y=C,p.x=h,p.y=u,a.getDistancePoint(T,p,o-P,!0),s.push(l,p.x,p.y),s;F=h,C=u,M+=3,s.push(l,F,C);break;case A:if(f=r[M+1],g=r[M+2],m=r[M+3],d=r[M+4],h=r[M+5],u=r[M+6],c=i[b],P+c>=o)return _=D.getT(o-P,c,F,C,f,g,m,d,h,u,e),D.cut(s,_,F,C,f,g,m,d,h,u),s;F=h,C=u,M+=7,s.push(l,f,g,m,d,h,u);break;case k:M+=1,s.push(l);default:c=0}b++,P+=c}return s}};function R(t){return r(t,t=>s({set(o){this.__setAttr(t,o),this.__hasMotionPath=this.motionPath||!c(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}}))}h.add("motion-path"),u.register("motion",function(t,o,e,a){return l(t)&&(t=n.number(t,a.getMotionTotal())),l(o)&&(o=n.number(o,a.getMotionTotal())),u.number(t||0,o||0,e)}),u.register("motionRotation",function(t,o,e){return u.number(t,o,e)});const v=f.prototype,{updateMatrix:w,updateAllMatrix:B}=g,{updateBounds:L}=m;function O(t){const{motion:o,leaferIsCreated:e}=t;if(!c(o)){if(e&&(t.leafer.created=!1),t.motionPath){const e=z(t);e.total&&(t.__.__pathForRender=C.getDistancePath(e,o,t.motionPrecision))}else t.set(t.getMotionPoint(o)),t.__hasAutoLayout||(t.isBranch?(B(t),L(t,t)):w(t));e&&(t.leafer.created=!0)}}function q(t){const{parent:o}=t;if(!t.motionPath&&o){const{children:t}=o;for(let o=0;o<t.length;o++)if(t[o].motionPath)return t[o]}return t}function z(t){const o=t.__;return o.__pathForMotion?o.__pathForMotion:o.__pathForMotion=C.getMotionPathData(t.getPath(!0,!0))}f.addAttr("motionPath",void 0,R),f.addAttr("motionPrecision",1,R),f.addAttr("motion",void 0,R),f.addAttr("motionRotation",!0,R),v.getMotionPathData=function(){return z(q(this))},v.getMotionPoint=function(t){const o=q(this),e=z(o);if(!e.total)return{};const n=C.getDistancePoint(e,t,o.motionPrecision);i.toOuterPoint(o.localTransform,n);const{motionRotation:a}=this;return!1===a?delete n.rotation:d(a)&&(n.rotation+=a),n},v.getMotionTotal=function(){return this.getMotionPathData().total},v.__updateMotionPath=function(){const t=this.__;if(this.__layout.resized&&t.__pathForMotion&&(t.__pathForMotion=void 0),this.motionPath){let t;const{children:o}=this.parent;for(let e=0;e<o.length;e++)t=o[e],c(t.motion)||t.__layout.matrixChanged||(t!==this&&t.__extraUpdate(),O(t))}else O(this)};export{D as HighBezierHelper,C as HighCurveHelper,R as motionPathType};
|
|
2
2
|
//# sourceMappingURL=motion-path.esm.min.js.map
|