leafer-game 1.0.10 → 1.1.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/web.cjs +40 -20
- package/dist/web.esm.js +41 -21
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +119 -71
- package/dist/web.min.cjs +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +119 -71
- package/dist/web.module.min.js +1 -1
- package/package.json +7 -7
package/dist/web.cjs
CHANGED
|
@@ -69,7 +69,7 @@ function updateStyle(leaf, style, type) {
|
|
|
69
69
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
|
|
70
70
|
leaf.killAnimate('transition');
|
|
71
71
|
if (normalStyle)
|
|
72
|
-
leaf.set(normalStyle,
|
|
72
|
+
leaf.set(normalStyle, 'temp');
|
|
73
73
|
const statesStyle = getStyle(leaf);
|
|
74
74
|
if (statesStyle) {
|
|
75
75
|
const { animation } = statesStyle;
|
|
@@ -83,14 +83,14 @@ function updateStyle(leaf, style, type) {
|
|
|
83
83
|
delete statesStyle.animation;
|
|
84
84
|
}
|
|
85
85
|
leaf.normalStyle = filterStyle(statesStyle, leaf);
|
|
86
|
-
leaf.set(statesStyle,
|
|
86
|
+
leaf.set(statesStyle, 'temp');
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
leaf.normalStyle = undefined;
|
|
90
90
|
}
|
|
91
91
|
if (transition) {
|
|
92
92
|
const toStyle = filterStyle(fromStyle, leaf);
|
|
93
|
-
leaf.set(fromStyle,
|
|
93
|
+
leaf.set(fromStyle, 'temp');
|
|
94
94
|
leaf.animate([fromStyle, toStyle], transition, 'transition', true);
|
|
95
95
|
}
|
|
96
96
|
leaf.__layout.stateStyleChanged = false;
|
|
@@ -335,23 +335,40 @@ const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.97
|
|
|
335
335
|
const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
|
|
336
336
|
const { sqrt } = Math;
|
|
337
337
|
const HighBezierHelper = {
|
|
338
|
-
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY) {
|
|
339
|
-
let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y;
|
|
338
|
+
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
|
|
339
|
+
let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
|
|
340
340
|
for (let i = 0; i < gaussNodes.length; i++) {
|
|
341
|
-
t1 =
|
|
342
|
-
t2 =
|
|
341
|
+
t1 = half * (1 + gaussNodes[i]);
|
|
342
|
+
t2 = half * (1 - gaussNodes[i]);
|
|
343
343
|
d1X = getDerivative(t1, fromX, x1, x2, toX);
|
|
344
344
|
d1Y = getDerivative(t1, fromY, y1, y2, toY);
|
|
345
345
|
d2X = getDerivative(t2, fromX, x1, x2, toX);
|
|
346
346
|
d2Y = getDerivative(t2, fromY, y1, y2, toY);
|
|
347
347
|
distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y));
|
|
348
348
|
}
|
|
349
|
-
return distance *
|
|
349
|
+
return distance * half;
|
|
350
350
|
},
|
|
351
351
|
getDerivative(t, fromV, v1, v2, toV) {
|
|
352
352
|
const o = 1 - t;
|
|
353
353
|
return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
|
|
354
354
|
},
|
|
355
|
+
getRotation(t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
|
|
356
|
+
const dx = getDerivative(t, fromX, x1, x2, toX);
|
|
357
|
+
const dy = getDerivative(t, fromY, y1, y2, toY);
|
|
358
|
+
return Math.atan2(dy, dx) / draw.OneRadian;
|
|
359
|
+
},
|
|
360
|
+
getT(distance, totalDistance, fromX, fromY, x1, y1, x2, y2, toX, toY, precision = 1) {
|
|
361
|
+
let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3;
|
|
362
|
+
if (middle >= 1)
|
|
363
|
+
return 1;
|
|
364
|
+
if (middle <= 0)
|
|
365
|
+
return 0;
|
|
366
|
+
while (high - low > realPrecision) {
|
|
367
|
+
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle;
|
|
368
|
+
middle = (low + high) / 2;
|
|
369
|
+
}
|
|
370
|
+
return middle;
|
|
371
|
+
},
|
|
355
372
|
cut(data, t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
|
|
356
373
|
const o = 1 - t;
|
|
357
374
|
const ax = o * fromX + t * x1, ay = o * fromY + t * y1;
|
|
@@ -363,7 +380,7 @@ const HighBezierHelper = {
|
|
|
363
380
|
data.push(draw.PathCommandMap.C, ax, ay, bx, by, cx, cy);
|
|
364
381
|
}
|
|
365
382
|
};
|
|
366
|
-
const { getDerivative } = HighBezierHelper;
|
|
383
|
+
const { getDerivative, getDistance } = HighBezierHelper;
|
|
367
384
|
|
|
368
385
|
const { M, L, C, Z } = draw.PathCommandMap;
|
|
369
386
|
const tempPoint = {}, tempFrom = {};
|
|
@@ -431,11 +448,12 @@ const HighCurveHelper = {
|
|
|
431
448
|
}
|
|
432
449
|
return { total, segments, data };
|
|
433
450
|
},
|
|
434
|
-
getDistancePoint(distanceData, motionDistance) {
|
|
451
|
+
getDistancePoint(distanceData, motionDistance, motionPrecision) {
|
|
435
452
|
const { segments, data } = distanceData;
|
|
436
453
|
motionDistance = draw.UnitConvert.number(motionDistance, distanceData.total);
|
|
437
454
|
let total = 0, distance, to = {};
|
|
438
455
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
456
|
+
let x1, y1, x2, y2, t;
|
|
439
457
|
const len = data.length;
|
|
440
458
|
while (i < len) {
|
|
441
459
|
command = data[i];
|
|
@@ -465,11 +483,10 @@ const HighCurveHelper = {
|
|
|
465
483
|
toY = data[i + 6];
|
|
466
484
|
distance = segments[index];
|
|
467
485
|
if (total + distance > motionDistance) {
|
|
468
|
-
|
|
469
|
-
motionDistance
|
|
470
|
-
draw.BezierHelper.getPointAndSet(
|
|
471
|
-
|
|
472
|
-
to.rotation = draw.PointHelper.getAngle(tempFrom, to);
|
|
486
|
+
x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
|
|
487
|
+
t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
488
|
+
draw.BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
|
|
489
|
+
to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
|
|
473
490
|
return to;
|
|
474
491
|
}
|
|
475
492
|
x = toX;
|
|
@@ -486,11 +503,12 @@ const HighCurveHelper = {
|
|
|
486
503
|
}
|
|
487
504
|
return to;
|
|
488
505
|
},
|
|
489
|
-
getDistancePath(distanceData, motionDistance) {
|
|
506
|
+
getDistancePath(distanceData, motionDistance, motionPrecision) {
|
|
490
507
|
const { segments, data } = distanceData, path = [];
|
|
491
508
|
motionDistance = draw.UnitConvert.number(motionDistance, distanceData.total);
|
|
492
509
|
let total = 0, distance, to = {};
|
|
493
510
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
511
|
+
let x1, y1, x2, y2, t;
|
|
494
512
|
const len = data.length;
|
|
495
513
|
while (i < len) {
|
|
496
514
|
command = data[i];
|
|
@@ -517,12 +535,13 @@ const HighCurveHelper = {
|
|
|
517
535
|
path.push(command, x, y);
|
|
518
536
|
break;
|
|
519
537
|
case C:
|
|
520
|
-
|
|
538
|
+
x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
|
|
521
539
|
toX = data[i + 5];
|
|
522
540
|
toY = data[i + 6];
|
|
523
541
|
distance = segments[index];
|
|
524
542
|
if (total + distance > motionDistance) {
|
|
525
|
-
HighBezierHelper.
|
|
543
|
+
t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
544
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
|
|
526
545
|
return path;
|
|
527
546
|
}
|
|
528
547
|
x = toX;
|
|
@@ -571,6 +590,7 @@ const ui = draw.UI.prototype;
|
|
|
571
590
|
const { updateMatrix, updateAllMatrix } = draw.LeafHelper;
|
|
572
591
|
const { updateBounds } = draw.BranchHelper;
|
|
573
592
|
motionPathType()(ui, 'motionPath');
|
|
593
|
+
motionPathType(1)(ui, 'motionPrecision');
|
|
574
594
|
motionPathType()(ui, 'motion');
|
|
575
595
|
motionPathType(true)(ui, 'motionRotation');
|
|
576
596
|
ui.getMotionPathData = function () {
|
|
@@ -581,7 +601,7 @@ ui.getMotionPoint = function (motionDistance) {
|
|
|
581
601
|
const data = getMotionPathData(path);
|
|
582
602
|
if (!data.total)
|
|
583
603
|
return {};
|
|
584
|
-
const point = HighCurveHelper.getDistancePoint(data, motionDistance);
|
|
604
|
+
const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
|
|
585
605
|
draw.MatrixHelper.toOuterPoint(path.localTransform, point);
|
|
586
606
|
const { motionRotation } = this;
|
|
587
607
|
if (motionRotation === false)
|
|
@@ -621,7 +641,7 @@ function updateMotion(leaf) {
|
|
|
621
641
|
if (leaf.motionPath) {
|
|
622
642
|
const data = getMotionPathData(leaf);
|
|
623
643
|
if (data.total)
|
|
624
|
-
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
|
|
644
|
+
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
|
|
625
645
|
}
|
|
626
646
|
else {
|
|
627
647
|
leaf.set(leaf.getMotionPoint(motion));
|
package/dist/web.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from 'leafer-ui';
|
|
2
2
|
export * from '@leafer-in/robot';
|
|
3
|
-
import { decorateLeafAttr, attr, State, PathCommandMap, MatrixHelper, PointHelper, UnitConvert, BezierHelper, isNull as isNull$1, Transition, UI as UI$1, LeafHelper, BranchHelper } from '@leafer-ui/draw';
|
|
3
|
+
import { decorateLeafAttr, attr, State, OneRadian, PathCommandMap, MatrixHelper, PointHelper, UnitConvert, BezierHelper, isNull as isNull$1, Transition, UI as UI$1, LeafHelper, BranchHelper } from '@leafer-ui/draw';
|
|
4
4
|
import { MathHelper, State as State$1, isNull, PointerEvent, UI, dataType } from '@leafer-ui/core';
|
|
5
5
|
export * from '@leafer-in/animate';
|
|
6
6
|
|
|
@@ -67,7 +67,7 @@ function updateStyle(leaf, style, type) {
|
|
|
67
67
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
|
|
68
68
|
leaf.killAnimate('transition');
|
|
69
69
|
if (normalStyle)
|
|
70
|
-
leaf.set(normalStyle,
|
|
70
|
+
leaf.set(normalStyle, 'temp');
|
|
71
71
|
const statesStyle = getStyle(leaf);
|
|
72
72
|
if (statesStyle) {
|
|
73
73
|
const { animation } = statesStyle;
|
|
@@ -81,14 +81,14 @@ function updateStyle(leaf, style, type) {
|
|
|
81
81
|
delete statesStyle.animation;
|
|
82
82
|
}
|
|
83
83
|
leaf.normalStyle = filterStyle(statesStyle, leaf);
|
|
84
|
-
leaf.set(statesStyle,
|
|
84
|
+
leaf.set(statesStyle, 'temp');
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
leaf.normalStyle = undefined;
|
|
88
88
|
}
|
|
89
89
|
if (transition) {
|
|
90
90
|
const toStyle = filterStyle(fromStyle, leaf);
|
|
91
|
-
leaf.set(fromStyle,
|
|
91
|
+
leaf.set(fromStyle, 'temp');
|
|
92
92
|
leaf.animate([fromStyle, toStyle], transition, 'transition', true);
|
|
93
93
|
}
|
|
94
94
|
leaf.__layout.stateStyleChanged = false;
|
|
@@ -333,23 +333,40 @@ const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.97
|
|
|
333
333
|
const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
|
|
334
334
|
const { sqrt } = Math;
|
|
335
335
|
const HighBezierHelper = {
|
|
336
|
-
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY) {
|
|
337
|
-
let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y;
|
|
336
|
+
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
|
|
337
|
+
let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
|
|
338
338
|
for (let i = 0; i < gaussNodes.length; i++) {
|
|
339
|
-
t1 =
|
|
340
|
-
t2 =
|
|
339
|
+
t1 = half * (1 + gaussNodes[i]);
|
|
340
|
+
t2 = half * (1 - gaussNodes[i]);
|
|
341
341
|
d1X = getDerivative(t1, fromX, x1, x2, toX);
|
|
342
342
|
d1Y = getDerivative(t1, fromY, y1, y2, toY);
|
|
343
343
|
d2X = getDerivative(t2, fromX, x1, x2, toX);
|
|
344
344
|
d2Y = getDerivative(t2, fromY, y1, y2, toY);
|
|
345
345
|
distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y));
|
|
346
346
|
}
|
|
347
|
-
return distance *
|
|
347
|
+
return distance * half;
|
|
348
348
|
},
|
|
349
349
|
getDerivative(t, fromV, v1, v2, toV) {
|
|
350
350
|
const o = 1 - t;
|
|
351
351
|
return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
|
|
352
352
|
},
|
|
353
|
+
getRotation(t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
|
|
354
|
+
const dx = getDerivative(t, fromX, x1, x2, toX);
|
|
355
|
+
const dy = getDerivative(t, fromY, y1, y2, toY);
|
|
356
|
+
return Math.atan2(dy, dx) / OneRadian;
|
|
357
|
+
},
|
|
358
|
+
getT(distance, totalDistance, fromX, fromY, x1, y1, x2, y2, toX, toY, precision = 1) {
|
|
359
|
+
let low = 0, high = 1, middle = distance / totalDistance, realPrecision = precision / totalDistance / 3;
|
|
360
|
+
if (middle >= 1)
|
|
361
|
+
return 1;
|
|
362
|
+
if (middle <= 0)
|
|
363
|
+
return 0;
|
|
364
|
+
while (high - low > realPrecision) {
|
|
365
|
+
getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, middle) < distance ? low = middle : high = middle;
|
|
366
|
+
middle = (low + high) / 2;
|
|
367
|
+
}
|
|
368
|
+
return middle;
|
|
369
|
+
},
|
|
353
370
|
cut(data, t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
|
|
354
371
|
const o = 1 - t;
|
|
355
372
|
const ax = o * fromX + t * x1, ay = o * fromY + t * y1;
|
|
@@ -361,7 +378,7 @@ const HighBezierHelper = {
|
|
|
361
378
|
data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy);
|
|
362
379
|
}
|
|
363
380
|
};
|
|
364
|
-
const { getDerivative } = HighBezierHelper;
|
|
381
|
+
const { getDerivative, getDistance } = HighBezierHelper;
|
|
365
382
|
|
|
366
383
|
const { M, L, C, Z } = PathCommandMap;
|
|
367
384
|
const tempPoint = {}, tempFrom = {};
|
|
@@ -429,11 +446,12 @@ const HighCurveHelper = {
|
|
|
429
446
|
}
|
|
430
447
|
return { total, segments, data };
|
|
431
448
|
},
|
|
432
|
-
getDistancePoint(distanceData, motionDistance) {
|
|
449
|
+
getDistancePoint(distanceData, motionDistance, motionPrecision) {
|
|
433
450
|
const { segments, data } = distanceData;
|
|
434
451
|
motionDistance = UnitConvert.number(motionDistance, distanceData.total);
|
|
435
452
|
let total = 0, distance, to = {};
|
|
436
453
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
454
|
+
let x1, y1, x2, y2, t;
|
|
437
455
|
const len = data.length;
|
|
438
456
|
while (i < len) {
|
|
439
457
|
command = data[i];
|
|
@@ -463,11 +481,10 @@ const HighCurveHelper = {
|
|
|
463
481
|
toY = data[i + 6];
|
|
464
482
|
distance = segments[index];
|
|
465
483
|
if (total + distance > motionDistance) {
|
|
466
|
-
|
|
467
|
-
motionDistance
|
|
468
|
-
BezierHelper.getPointAndSet(
|
|
469
|
-
|
|
470
|
-
to.rotation = PointHelper.getAngle(tempFrom, to);
|
|
484
|
+
x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
|
|
485
|
+
t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
486
|
+
BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
|
|
487
|
+
to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
|
|
471
488
|
return to;
|
|
472
489
|
}
|
|
473
490
|
x = toX;
|
|
@@ -484,11 +501,12 @@ const HighCurveHelper = {
|
|
|
484
501
|
}
|
|
485
502
|
return to;
|
|
486
503
|
},
|
|
487
|
-
getDistancePath(distanceData, motionDistance) {
|
|
504
|
+
getDistancePath(distanceData, motionDistance, motionPrecision) {
|
|
488
505
|
const { segments, data } = distanceData, path = [];
|
|
489
506
|
motionDistance = UnitConvert.number(motionDistance, distanceData.total);
|
|
490
507
|
let total = 0, distance, to = {};
|
|
491
508
|
let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
|
|
509
|
+
let x1, y1, x2, y2, t;
|
|
492
510
|
const len = data.length;
|
|
493
511
|
while (i < len) {
|
|
494
512
|
command = data[i];
|
|
@@ -515,12 +533,13 @@ const HighCurveHelper = {
|
|
|
515
533
|
path.push(command, x, y);
|
|
516
534
|
break;
|
|
517
535
|
case C:
|
|
518
|
-
|
|
536
|
+
x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
|
|
519
537
|
toX = data[i + 5];
|
|
520
538
|
toY = data[i + 6];
|
|
521
539
|
distance = segments[index];
|
|
522
540
|
if (total + distance > motionDistance) {
|
|
523
|
-
HighBezierHelper.
|
|
541
|
+
t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
|
|
542
|
+
HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
|
|
524
543
|
return path;
|
|
525
544
|
}
|
|
526
545
|
x = toX;
|
|
@@ -569,6 +588,7 @@ const ui = UI$1.prototype;
|
|
|
569
588
|
const { updateMatrix, updateAllMatrix } = LeafHelper;
|
|
570
589
|
const { updateBounds } = BranchHelper;
|
|
571
590
|
motionPathType()(ui, 'motionPath');
|
|
591
|
+
motionPathType(1)(ui, 'motionPrecision');
|
|
572
592
|
motionPathType()(ui, 'motion');
|
|
573
593
|
motionPathType(true)(ui, 'motionRotation');
|
|
574
594
|
ui.getMotionPathData = function () {
|
|
@@ -579,7 +599,7 @@ ui.getMotionPoint = function (motionDistance) {
|
|
|
579
599
|
const data = getMotionPathData(path);
|
|
580
600
|
if (!data.total)
|
|
581
601
|
return {};
|
|
582
|
-
const point = HighCurveHelper.getDistancePoint(data, motionDistance);
|
|
602
|
+
const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
|
|
583
603
|
MatrixHelper.toOuterPoint(path.localTransform, point);
|
|
584
604
|
const { motionRotation } = this;
|
|
585
605
|
if (motionRotation === false)
|
|
@@ -619,7 +639,7 @@ function updateMotion(leaf) {
|
|
|
619
639
|
if (leaf.motionPath) {
|
|
620
640
|
const data = getMotionPathData(leaf);
|
|
621
641
|
if (data.total)
|
|
622
|
-
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion);
|
|
642
|
+
leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
|
|
623
643
|
}
|
|
624
644
|
else {
|
|
625
645
|
leaf.set(leaf.getMotionPoint(motion));
|
package/dist/web.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"leafer-ui";export*from"@leafer-in/robot";import{decorateLeafAttr as t,attr as e,State as n,
|
|
1
|
+
export*from"leafer-ui";export*from"@leafer-in/robot";import{decorateLeafAttr as t,attr as e,State as n,OneRadian as o,PathCommandMap as i,MatrixHelper as s,PointHelper as a,UnitConvert as r,BezierHelper as c,isNull as l,Transition as u,UI as f,LeafHelper as h,BranchHelper as d}from"@leafer-ui/draw";import{MathHelper as y,State as m,isNull as g,PointerEvent as S,UI as p,dataType as b}from"@leafer-ui/core";export*from"@leafer-in/animate";function _(o,i){return t(o,(t=>e({set(e){this.__setAttr(t,e),this.waitLeafer((()=>i?n.setStyleName(this,i,e):n.set(this,e)))}})))}function P(n){return t(n,(t=>e({set(e){this.__setAttr(t,e),this.__layout.stateStyleChanged=!0}})))}function v(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function D(t,e){"object"!=typeof e&&(e=void 0),k(t,e,"in")}function M(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),k(t,e,"out"))}const x={};function k(t,e,n){const{normalStyle:o}=t;e||(e=x),e.scale&&(y.assignScale(e,e.scale),delete e.scale),e!==x&&m.canAnimate||(n=null);let i=!!n&&function(t,e,n){let o="in"===t?"transition":"transitionOut";"out"===t&&g(n[o])&&g(e[o])&&(o="transition");return g(e[o])?n[o]:e[o]}(n,e,t);const s=i?function(t,e){const n=w(e,t),o=t.animate();o&&w(n,t,o.fromStyle);return n}(t,e):void 0;t.killAnimate("transition"),o&&t.set(o,"temp");const a=F(t);if(a){const{animation:o}=a;if(o){const s=t.animate(o,void 0,"animation",!0);Object.assign(a,s.endingStyle),"in"!==n||e.animation!==o?s.kill():i=!1,delete a.animation}t.normalStyle=A(a,t),t.set(a,"temp")}else t.normalStyle=void 0;if(i){const e=A(s,t);t.set(s,"temp"),t.animate([s,e],i,"transition",!0)}t.__layout.stateStyleChanged=!1}function F(t){let e;const n={},{state:o}=t,i=v(t),s=o&&t.states[o];s&&m.isState(o,t,i)&&(e=C(n,s));const a=n.selectedStyle||t.selectedStyle;if(a&&m.isSelected(t,i)&&(e=C(n,a)),m.isDisabled(t,i)){const o=n.disabledStyle||t.disabledStyle;o&&(e=C(n,o))}else{const o=n.focusStyle||t.focusStyle;o&&m.isFocus(t,i)&&(e=C(n,o));const s=n.hoverStyle||t.hoverStyle;s&&m.isHover(t,i)&&(e=C(n,s));const a=n.pressStyle||t.pressStyle;a&&m.isPress(t,i)&&(e=C(n,a))}return e?n:void 0}function A(t,e,n,o){const i=n?t:{},s=n||t;for(let t in s)o&&m.animateExcludes[t]||(i[t]=e[t]);return i}function w(t,e,n){return A(t,e,n,!0)}function C(t,e){return Object.assign(t,e),!0}function E(t,e){const n=t[e];n&&D(t,n),t.button&&R(t.children,e)}function O(t,e,n){n||(n=t.states[e]),D(t,n),t.button&&R(t.children,null,e)}function R(t,e,n){if(!t)return;let o,i;for(let s=0,a=t.length;s<a;s++){if(o=t[s],e){switch(i=!0,e){case"hoverStyle":m.isHover(o)&&(i=!1);break;case"pressStyle":m.isPress(o)&&(i=!1);break;case"focusStyle":m.isFocus(o)&&(i=!1)}i&&E(o,e)}else n&&O(o,n);o.isBranch&&R(o.children,e,n)}}function T(t,e){const n=t[e];n&&M(t,n),t.button&&L(t.children,e)}function j(t,e,n){M(t,n),t.button&&L(t.children,null,e)}function L(t,e,n){if(!t)return;let o;for(let i=0,s=t.length;i<s;i++)o=t[i],e?T(o,e):n&&j(o,n),o.isBranch&&L(o.children,e,n)}function N(t,e,n){let o;const i=e.leafer?e.leafer.interaction:null;if(i&&(o=i[t](e),!o&&n)){const s=v(e,n);s&&(o=i[t](s))}return o}function B(t,e,n){let o=e[t];if(!o&&n){const i=v(e,n);i&&(o=i[t])}return o}m.animateExcludes={animation:1,animationOut:1,transition:1,transitionOut:1,states:1,state:1,normalStyle:1,hoverStyle:1,pressStyle:1,focusStyle:1,selectedStyle:1,disabledStyle:1},m.isState=function(t,e,n){return function(t,e,n){let o=e.states[t];if(!o&&n){const i=v(e,n);i&&(o=i.states[t])}return!!o}(t,e,n)},m.isSelected=function(t,e){return B("selected",t,e)},m.isDisabled=function(t,e){return B("disabled",t,e)},m.isFocus=function(t,e){return N("isFocus",t,e)},m.isHover=function(t,e){return N("isHover",t,e)},m.isPress=function(t,e){return N("isPress",t,e)},m.isDrag=function(t,e){return N("isDrag",t,e)},m.setStyleName=function(t,e,n){n?O(t,e,t[e]):j(t,e,t[e])},m.set=function(t,e){const n=t.states[e];n?O(t,e,n):j(t,e,n)},m.getStyle=F,m.updateStyle=k,m.updateEventStyle=function(t,e){switch(e){case S.ENTER:E(t,"hoverStyle");break;case S.LEAVE:T(t,"hoverStyle");break;case S.DOWN:E(t,"pressStyle");break;case S.UP:T(t,"pressStyle")}};const H=p.prototype;_(!1,"selectedStyle")(H,"selected"),_(!1,"disabledStyle")(H,"disabled"),P({})(H,"states"),_("")(H,"state"),b()(H,"normalStyle"),P()(H,"hoverStyle"),P()(H,"pressStyle"),P()(H,"focusStyle"),P()(H,"selectedStyle"),P()(H,"disabledStyle"),b(!1)(H,"button"),H.focus=function(t=!0){this.waitLeafer((()=>{let{focusData:e}=this.app.interaction;t?(e&&e.focus(!1),e=this):e=null,this.app.interaction.focusData=e,t?E(this,"focusStyle"):T(this,"focusStyle")}))},H.updateState=function(){m.updateStyle(this,void 0,"in")};const I=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],U=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:q}=Math,z={getDistance(t,e,n,o,i,s,a,r,c=1){let l,u,f,h,d,y,m=0,g=c/2;for(let c=0;c<I.length;c++)l=g*(1+I[c]),u=g*(1-I[c]),f=V(l,t,n,i,a),h=V(l,e,o,s,r),d=V(u,t,n,i,a),y=V(u,e,o,s,r),m+=U[c]*(q(f*f+h*h)+q(d*d+y*y));return m*g},getDerivative(t,e,n,o,i){const s=1-t;return 3*s*s*(n-e)+6*s*t*(o-n)+3*t*t*(i-o)},getRotation(t,e,n,i,s,a,r,c,l){const u=V(t,e,i,a,c),f=V(t,n,s,r,l);return Math.atan2(f,u)/o},getT(t,e,n,o,i,s,a,r,c,l,u=1){let f=0,h=1,d=t/e,y=u/e/3;if(d>=1)return 1;if(d<=0)return 0;for(;h-f>y;)W(n,o,i,s,a,r,c,l,d)<t?f=d:h=d,d=(f+h)/2;return d},cut(t,e,n,o,s,a,r,c,l,u){const f=1-e,h=f*n+e*s,d=f*o+e*a,y=f*s+e*r,m=f*a+e*c,g=f*h+e*y,S=f*d+e*m,p=f*g+e*(f*y+e*(f*r+e*l)),b=f*S+e*(f*m+e*(f*c+e*u));t.push(i.C,h,d,g,S,p,b)}},{getDerivative:V,getDistance:W}=z,{M:Z,L:G,C:J,Z:K}=i,Q={},X={},Y={transform(t,e){let n,o=0;const i=t.length;for(;o<i;)switch(n=t[o],n){case Z:case G:Y.transformPoints(t,e,o,1),o+=3;break;case J:Y.transformPoints(t,e,o,3),o+=7;break;case K:o+=1}},transformPoints(t,e,n,o){for(let i=n+1,a=i+2*o;i<a;i+=2)Q.x=t[i],Q.y=t[i+1],s.toOuterPoint(e,Q),t[i]=Q.x,t[i+1]=Q.y},getMotionPathData(t){let e,n,o,i,s=0,r=[],c=0,l=0,u=0;const f=t.length;for(;c<f;){switch(i=t[c],i){case Z:case G:n=t[c+1],o=t[c+2],e=i===G&&c>0?a.getDistanceFrom(l,u,n,o):0,l=n,u=o,c+=3;break;case J:n=t[c+5],o=t[c+6],e=z.getDistance(l,u,t[c+1],t[c+2],t[c+3],t[c+4],n,o),l=n,u=o,c+=7;break;case K:c+=1;default:e=0}r.push(e),s+=e}return{total:s,segments:r,data:t}},getDistancePoint(t,e,n){const{segments:o,data:i}=t;e=r.number(e,t.total);let s,l,u,f,h,d,y,m,g,S=0,p={},b=0,_=0,P=0,v=0;const D=i.length;for(;b<D;){switch(f=i[b],f){case Z:case G:if(l=i[b+1],u=i[b+2],s=o[_],S+s>e||!t.total)return b||(P=l,v=u),X.x=P,X.y=v,p.x=l,p.y=u,a.getDistancePoint(X,p,e-S,!0),p.rotation=a.getAngle(X,p),p;P=l,v=u,b+=3;break;case J:if(l=i[b+5],u=i[b+6],s=o[_],S+s>e)return h=i[b+1],d=i[b+2],y=i[b+3],m=i[b+4],g=z.getT(e-S,s,P,v,h,d,y,m,l,u,n),c.getPointAndSet(g,P,v,h,d,y,m,l,u,p),p.rotation=z.getRotation(g,P,v,h,d,y,m,l,u),p;P=l,v=u,b+=7;break;case K:b+=1;default:s=0}_++,S+=s}return p},getDistancePath(t,e,n){const{segments:o,data:i}=t,s=[];e=r.number(e,t.total);let c,l,u,f,h,d,y,m,g,S=0,p={},b=0,_=0,P=0,v=0;const D=i.length;for(;b<D;){switch(f=i[b],f){case Z:case G:if(l=i[b+1],u=i[b+2],c=o[_],S+c>e||!t.total)return b||(P=l,v=u),X.x=P,X.y=v,p.x=l,p.y=u,a.getDistancePoint(X,p,e-S,!0),s.push(f,p.x,p.y),s;P=l,v=u,b+=3,s.push(f,P,v);break;case J:if(h=i[b+1],d=i[b+2],y=i[b+3],m=i[b+4],l=i[b+5],u=i[b+6],c=o[_],S+c>e)return g=z.getT(e-S,c,P,v,h,d,y,m,l,u,n),z.cut(s,g,P,v,h,d,y,m,l,u),s;P=l,v=u,b+=7,s.push(f,h,d,y,m,l,u);break;case K:b+=1,s.push(f);default:c=0}_++,S+=c}return s}};function $(n){return t(n,(t=>e({set(e){this.__setAttr(t,e),this.__hasMotionPath=this.motionPath||!l(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}})))}u.register("motion",(function(t,e,n,o){return t?"object"==typeof t&&(t=r.number(t,o.getMotionTotal())):t=0,e?"object"==typeof e&&(e=r.number(e,o.getMotionTotal())):e=0,u.number(t,e,n)})),u.register("motionRotation",(function(t,e,n){return u.number(t,e,n)}));const tt=f.prototype,{updateMatrix:et,updateAllMatrix:nt}=h,{updateBounds:ot}=d;function it(t){const{motion:e,leaferIsCreated:n}=t;if(!l(e)){if(n&&(t.leafer.created=!1),t.motionPath){const n=at(t);n.total&&(t.__.__pathForRender=Y.getDistancePath(n,e,t.motionPrecision))}else t.set(t.getMotionPoint(e)),t.__hasAutoLayout||(t.isBranch?(nt(t),ot(t,t)):et(t));n&&(t.leafer.created=!0)}}function st(t){const{parent:e}=t;if(!t.motionPath&&e){const{children:t}=e;for(let e=0;e<t.length;e++)if(t[e].motionPath)return t[e]}return t}function at(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=Y.getMotionPathData(t.getPath(!0,!0))}$()(tt,"motionPath"),$(1)(tt,"motionPrecision"),$()(tt,"motion"),$(!0)(tt,"motionRotation"),tt.getMotionPathData=function(){return at(st(this))},tt.getMotionPoint=function(t){const e=st(this),n=at(e);if(!n.total)return{};const o=Y.getDistancePoint(n,t,e.motionPrecision);s.toOuterPoint(e.localTransform,o);const{motionRotation:i}=this;return!1===i?delete o.rotation:"number"==typeof i&&(o.rotation+=i),o},tt.getMotionTotal=function(){return this.getMotionPathData().total},tt.__updateMotionPath=function(){const t=this.__;if(this.__layout.resized&&t.__pathForMotion&&(t.__pathForMotion=void 0),this.motionPath){let t;const{children:e}=this.parent,{leaferIsReady:n}=this;for(let o=0;o<e.length;o++)t=e[o],l(t.motion)||t.__layout.matrixChanged||(n&&t!==this&&this.leafer.layouter.addExtra(t),it(t))}else it(this)};export{z as HighBezierHelper,Y as HighCurveHelper,$ as motionPathType,P as stateStyleType,_ as stateType};
|