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 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, true);
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, true);
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, true);
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 = 0.5 * (1 + gaussNodes[i]);
342
- t2 = 0.5 * (1 - gaussNodes[i]);
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 * 0.5;
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
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
469
- motionDistance -= total;
470
- draw.BezierHelper.getPointAndSet(motionDistance / distance, x, y, x1, y1, x2, y2, toX, toY, to);
471
- draw.BezierHelper.getPointAndSet(Math.max(0, motionDistance - 0.1) / distance, x, y, x1, y1, x2, y2, toX, toY, tempFrom);
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
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
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.cut(path, (motionDistance - total) / distance, x, y, x1, y1, x2, y2, toX, toY);
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, true);
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, true);
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, true);
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 = 0.5 * (1 + gaussNodes[i]);
340
- t2 = 0.5 * (1 - gaussNodes[i]);
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 * 0.5;
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
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
467
- motionDistance -= total;
468
- BezierHelper.getPointAndSet(motionDistance / distance, x, y, x1, y1, x2, y2, toX, toY, to);
469
- BezierHelper.getPointAndSet(Math.max(0, motionDistance - 0.1) / distance, x, y, x1, y1, x2, y2, toX, toY, tempFrom);
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
- const x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
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.cut(path, (motionDistance - total) / distance, x, y, x1, y1, x2, y2, toX, toY);
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));
@@ -1 +1 @@
1
- export*from"leafer-ui";export*from"@leafer-in/robot";import{decorateLeafAttr as t,attr as e,State as n,PathCommandMap as o,MatrixHelper as i,PointHelper as s,UnitConvert as a,BezierHelper as r,isNull as c,Transition as l,UI as u,LeafHelper as f,BranchHelper as h}from"@leafer-ui/draw";import{MathHelper as d,State as y,isNull as m,PointerEvent as S,UI as g,dataType as p}from"@leafer-ui/core";export*from"@leafer-in/animate";function b(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 _(n){return t(n,(t=>e({set(e){this.__setAttr(t,e),this.__layout.stateStyleChanged=!0}})))}function P(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 v(t,e){"object"!=typeof e&&(e=void 0),x(t,e,"in")}function D(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),x(t,e,"out"))}const M={};function x(t,e,n){const{normalStyle:o}=t;e||(e=M),e.scale&&(d.assignScale(e,e.scale),delete e.scale),e!==M&&y.canAnimate||(n=null);let i=!!n&&function(t,e,n){let o="in"===t?"transition":"transitionOut";"out"===t&&m(n[o])&&m(e[o])&&(o="transition");return m(e[o])?n[o]:e[o]}(n,e,t);const s=i?function(t,e){const n=F(e,t),o=t.animate();o&&F(n,t,o.fromStyle);return n}(t,e):void 0;t.killAnimate("transition"),o&&t.set(o,!0);const a=k(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,!0)}else t.normalStyle=void 0;if(i){const e=A(s,t);t.set(s,!0),t.animate([s,e],i,"transition",!0)}t.__layout.stateStyleChanged=!1}function k(t){let e;const n={},{state:o}=t,i=P(t),s=o&&t.states[o];s&&y.isState(o,t,i)&&(e=w(n,s));const a=n.selectedStyle||t.selectedStyle;if(a&&y.isSelected(t,i)&&(e=w(n,a)),y.isDisabled(t,i)){const o=n.disabledStyle||t.disabledStyle;o&&(e=w(n,o))}else{const o=n.focusStyle||t.focusStyle;o&&y.isFocus(t,i)&&(e=w(n,o));const s=n.hoverStyle||t.hoverStyle;s&&y.isHover(t,i)&&(e=w(n,s));const a=n.pressStyle||t.pressStyle;a&&y.isPress(t,i)&&(e=w(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&&y.animateExcludes[t]||(i[t]=e[t]);return i}function F(t,e,n){return A(t,e,n,!0)}function w(t,e){return Object.assign(t,e),!0}function C(t,e){const n=t[e];n&&v(t,n),t.button&&O(t.children,e)}function E(t,e,n){n||(n=t.states[e]),v(t,n),t.button&&O(t.children,null,e)}function O(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":y.isHover(o)&&(i=!1);break;case"pressStyle":y.isPress(o)&&(i=!1);break;case"focusStyle":y.isFocus(o)&&(i=!1)}i&&C(o,e)}else n&&E(o,n);o.isBranch&&O(o.children,e,n)}}function j(t,e){const n=t[e];n&&D(t,n),t.button&&L(t.children,e)}function R(t,e,n){D(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?j(o,e):n&&R(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=P(e,n);s&&(o=i[t](s))}return o}function T(t,e,n){let o=e[t];if(!o&&n){const i=P(e,n);i&&(o=i[t])}return o}y.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},y.isState=function(t,e,n){return function(t,e,n){let o=e.states[t];if(!o&&n){const i=P(e,n);i&&(o=i.states[t])}return!!o}(t,e,n)},y.isSelected=function(t,e){return T("selected",t,e)},y.isDisabled=function(t,e){return T("disabled",t,e)},y.isFocus=function(t,e){return N("isFocus",t,e)},y.isHover=function(t,e){return N("isHover",t,e)},y.isPress=function(t,e){return N("isPress",t,e)},y.isDrag=function(t,e){return N("isDrag",t,e)},y.setStyleName=function(t,e,n){n?E(t,e,t[e]):R(t,e,t[e])},y.set=function(t,e){const n=t.states[e];n?E(t,e,n):R(t,e,n)},y.getStyle=k,y.updateStyle=x,y.updateEventStyle=function(t,e){switch(e){case S.ENTER:C(t,"hoverStyle");break;case S.LEAVE:j(t,"hoverStyle");break;case S.DOWN:C(t,"pressStyle");break;case S.UP:j(t,"pressStyle")}};const B=g.prototype;b(!1,"selectedStyle")(B,"selected"),b(!1,"disabledStyle")(B,"disabled"),_({})(B,"states"),b("")(B,"state"),p()(B,"normalStyle"),_()(B,"hoverStyle"),_()(B,"pressStyle"),_()(B,"focusStyle"),_()(B,"selectedStyle"),_()(B,"disabledStyle"),p(!1)(B,"button"),B.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?C(this,"focusStyle"):j(this,"focusStyle")}))},B.updateState=function(){y.updateStyle(this,void 0,"in")};const H=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],I=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:U}=Math,q={getDistance(t,e,n,o,i,s,a,r){let c,l,u,f,h,d,y=0;for(let m=0;m<H.length;m++)c=.5*(1+H[m]),l=.5*(1-H[m]),u=z(c,t,n,i,a),f=z(c,e,o,s,r),h=z(l,t,n,i,a),d=z(l,e,o,s,r),y+=I[m]*(U(u*u+f*f)+U(h*h+d*d));return.5*y},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)},cut(t,e,n,i,s,a,r,c,l,u){const f=1-e,h=f*n+e*s,d=f*i+e*a,y=f*s+e*r,m=f*a+e*c,S=f*h+e*y,g=f*d+e*m,p=f*S+e*(f*y+e*(f*r+e*l)),b=f*g+e*(f*m+e*(f*c+e*u));t.push(o.C,h,d,S,g,p,b)}},{getDerivative:z}=q,{M:V,L:W,C:Z,Z:G}=o,J={},K={},Q={transform(t,e){let n,o=0;const i=t.length;for(;o<i;)switch(n=t[o],n){case V:case W:Q.transformPoints(t,e,o,1),o+=3;break;case Z:Q.transformPoints(t,e,o,3),o+=7;break;case G:o+=1}},transformPoints(t,e,n,o){for(let s=n+1,a=s+2*o;s<a;s+=2)J.x=t[s],J.y=t[s+1],i.toOuterPoint(e,J),t[s]=J.x,t[s+1]=J.y},getMotionPathData(t){let e,n,o,i,a=0,r=[],c=0,l=0,u=0;const f=t.length;for(;c<f;){switch(i=t[c],i){case V:case W:n=t[c+1],o=t[c+2],e=i===W&&c>0?s.getDistanceFrom(l,u,n,o):0,l=n,u=o,c+=3;break;case Z:n=t[c+5],o=t[c+6],e=q.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 G:c+=1;default:e=0}r.push(e),a+=e}return{total:a,segments:r,data:t}},getDistancePoint(t,e){const{segments:n,data:o}=t;e=a.number(e,t.total);let i,c,l,u,f=0,h={},d=0,y=0,m=0,S=0;const g=o.length;for(;d<g;){switch(u=o[d],u){case V:case W:if(c=o[d+1],l=o[d+2],i=n[y],f+i>e||!t.total)return d||(m=c,S=l),K.x=m,K.y=S,h.x=c,h.y=l,s.getDistancePoint(K,h,e-f,!0),h.rotation=s.getAngle(K,h),h;m=c,S=l,d+=3;break;case Z:if(c=o[d+5],l=o[d+6],i=n[y],f+i>e){const t=o[d+1],n=o[d+2],a=o[d+3],u=o[d+4];return e-=f,r.getPointAndSet(e/i,m,S,t,n,a,u,c,l,h),r.getPointAndSet(Math.max(0,e-.1)/i,m,S,t,n,a,u,c,l,K),h.rotation=s.getAngle(K,h),h}m=c,S=l,d+=7;break;case G:d+=1;default:i=0}y++,f+=i}return h},getDistancePath(t,e){const{segments:n,data:o}=t,i=[];e=a.number(e,t.total);let r,c,l,u,f=0,h={},d=0,y=0,m=0,S=0;const g=o.length;for(;d<g;){switch(u=o[d],u){case V:case W:if(c=o[d+1],l=o[d+2],r=n[y],f+r>e||!t.total)return d||(m=c,S=l),K.x=m,K.y=S,h.x=c,h.y=l,s.getDistancePoint(K,h,e-f,!0),i.push(u,h.x,h.y),i;m=c,S=l,d+=3,i.push(u,m,S);break;case Z:const a=o[d+1],g=o[d+2],p=o[d+3],b=o[d+4];if(c=o[d+5],l=o[d+6],r=n[y],f+r>e)return q.cut(i,(e-f)/r,m,S,a,g,p,b,c,l),i;m=c,S=l,d+=7,i.push(u,a,g,p,b,c,l);break;case G:d+=1,i.push(u);default:r=0}y++,f+=r}return i}};function X(n){return t(n,(t=>e({set(e){this.__setAttr(t,e),this.__hasMotionPath=this.motionPath||!c(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}})))}l.register("motion",(function(t,e,n,o){return t?"object"==typeof t&&(t=a.number(t,o.getMotionTotal())):t=0,e?"object"==typeof e&&(e=a.number(e,o.getMotionTotal())):e=0,l.number(t,e,n)})),l.register("motionRotation",(function(t,e,n){return l.number(t,e,n)}));const Y=u.prototype,{updateMatrix:$,updateAllMatrix:tt}=f,{updateBounds:et}=h;function nt(t){const{motion:e,leaferIsCreated:n}=t;if(!c(e)){if(n&&(t.leafer.created=!1),t.motionPath){const n=it(t);n.total&&(t.__.__pathForRender=Q.getDistancePath(n,e))}else t.set(t.getMotionPoint(e)),t.__hasAutoLayout||(t.isBranch?(tt(t),et(t,t)):$(t));n&&(t.leafer.created=!0)}}function ot(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 it(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=Q.getMotionPathData(t.getPath(!0,!0))}X()(Y,"motionPath"),X()(Y,"motion"),X(!0)(Y,"motionRotation"),Y.getMotionPathData=function(){return it(ot(this))},Y.getMotionPoint=function(t){const e=ot(this),n=it(e);if(!n.total)return{};const o=Q.getDistancePoint(n,t);i.toOuterPoint(e.localTransform,o);const{motionRotation:s}=this;return!1===s?delete o.rotation:"number"==typeof s&&(o.rotation+=s),o},Y.getMotionTotal=function(){return this.getMotionPathData().total},Y.__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],c(t.motion)||t.__layout.matrixChanged||(n&&t!==this&&this.leafer.layouter.addExtra(t),nt(t))}else nt(this)};export{q as HighBezierHelper,Q as HighCurveHelper,X as motionPathType,_ as stateStyleType,b as stateType};
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};