leafer-game 1.1.0 → 1.1.2

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.esm.js CHANGED
@@ -1,674 +1,5 @@
1
1
  export * from 'leafer-ui';
2
2
  export * from '@leafer-in/robot';
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
- import { MathHelper, State as State$1, isNull, PointerEvent, UI, dataType } from '@leafer-ui/core';
3
+ export * from '@leafer-in/state';
5
4
  export * from '@leafer-in/animate';
6
-
7
- function stateType(defaultValue, styleName) {
8
- return decorateLeafAttr(defaultValue, (key) => attr({
9
- set(value) {
10
- this.__setAttr(key, value);
11
- this.waitLeafer(() => styleName ? State.setStyleName(this, styleName, value) : State.set(this, value));
12
- }
13
- }));
14
- }
15
- function stateStyleType(defaultValue) {
16
- return decorateLeafAttr(defaultValue, (key) => attr({
17
- set(value) {
18
- this.__setAttr(key, value);
19
- this.__layout.stateStyleChanged = true;
20
- }
21
- }));
22
- }
23
-
24
- function findParentButton(leaf, button) {
25
- if (button && button !== true)
26
- return button;
27
- if (!leaf.button) {
28
- let { parent } = leaf;
29
- for (let i = 0; i < 2; i++) {
30
- if (parent) {
31
- if (parent.button)
32
- return parent;
33
- parent = parent.parent;
34
- }
35
- }
36
- }
37
- return null;
38
- }
39
-
40
- function setStyle(leaf, style) {
41
- if (typeof style !== 'object')
42
- style = undefined;
43
- updateStyle(leaf, style, 'in');
44
- }
45
- function unsetStyle(leaf, style) {
46
- const { normalStyle } = leaf;
47
- if (typeof style !== 'object')
48
- style = undefined;
49
- if (normalStyle) {
50
- if (!style)
51
- style = normalStyle;
52
- updateStyle(leaf, style, 'out');
53
- }
54
- }
55
- const emprtyStyle = {};
56
- function updateStyle(leaf, style, type) {
57
- const { normalStyle } = leaf;
58
- if (!style)
59
- style = emprtyStyle;
60
- if (style.scale) {
61
- MathHelper.assignScale(style, style.scale);
62
- delete style.scale;
63
- }
64
- if (style === emprtyStyle || !State$1.canAnimate)
65
- type = null;
66
- let transition = type ? getTransition(type, style, leaf) : false;
67
- const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
68
- leaf.killAnimate('transition');
69
- if (normalStyle)
70
- leaf.set(normalStyle, 'temp');
71
- const statesStyle = getStyle(leaf);
72
- if (statesStyle) {
73
- const { animation } = statesStyle;
74
- if (animation) {
75
- const animate = leaf.animate(animation, undefined, 'animation', true);
76
- Object.assign(statesStyle, animate.endingStyle);
77
- if (type !== 'in' || style.animation !== animation)
78
- animate.kill();
79
- else
80
- transition = false;
81
- delete statesStyle.animation;
82
- }
83
- leaf.normalStyle = filterStyle(statesStyle, leaf);
84
- leaf.set(statesStyle, 'temp');
85
- }
86
- else {
87
- leaf.normalStyle = undefined;
88
- }
89
- if (transition) {
90
- const toStyle = filterStyle(fromStyle, leaf);
91
- leaf.set(fromStyle, 'temp');
92
- leaf.animate([fromStyle, toStyle], transition, 'transition', true);
93
- }
94
- leaf.__layout.stateStyleChanged = false;
95
- }
96
- function getStyle(leaf) {
97
- let exist;
98
- const style = {}, { state } = leaf, button = findParentButton(leaf);
99
- const stateStyle = state && leaf.states[state];
100
- if (stateStyle && State$1.isState(state, leaf, button))
101
- exist = assign(style, stateStyle);
102
- const selectedStyle = style.selectedStyle || leaf.selectedStyle;
103
- if (selectedStyle && State$1.isSelected(leaf, button))
104
- exist = assign(style, selectedStyle);
105
- if (State$1.isDisabled(leaf, button)) {
106
- const disabledStyle = style.disabledStyle || leaf.disabledStyle;
107
- if (disabledStyle)
108
- exist = assign(style, disabledStyle);
109
- }
110
- else {
111
- const focusStyle = style.focusStyle || leaf.focusStyle;
112
- if (focusStyle && State$1.isFocus(leaf, button))
113
- exist = assign(style, focusStyle);
114
- const hoverStyle = style.hoverStyle || leaf.hoverStyle;
115
- if (hoverStyle && State$1.isHover(leaf, button))
116
- exist = assign(style, hoverStyle);
117
- const pressStyle = style.pressStyle || leaf.pressStyle;
118
- if (pressStyle && State$1.isPress(leaf, button))
119
- exist = assign(style, pressStyle);
120
- }
121
- return exist ? style : undefined;
122
- }
123
- function filterStyle(style, data, addStyle, useAnimateExcludes) {
124
- const to = addStyle ? style : {}, forStyle = addStyle || style;
125
- for (let key in forStyle) {
126
- if (useAnimateExcludes) {
127
- if (!State$1.animateExcludes[key])
128
- to[key] = data[key];
129
- }
130
- else
131
- to[key] = data[key];
132
- }
133
- return to;
134
- }
135
- function filterAnimateStyle(style, data, addStyle) {
136
- return filterStyle(style, data, addStyle, true);
137
- }
138
- function getFromStyle(leaf, style) {
139
- const fromStyle = filterAnimateStyle(style, leaf), animate = leaf.animate();
140
- if (animate)
141
- filterAnimateStyle(fromStyle, leaf, animate.fromStyle);
142
- return fromStyle;
143
- }
144
- function getTransition(type, style, data) {
145
- let name = type === 'in' ? 'transition' : 'transitionOut';
146
- if (type === 'out' && isNull(data[name]) && isNull(style[name]))
147
- name = 'transition';
148
- return isNull(style[name]) ? data[name] : style[name];
149
- }
150
- function assign(style, stateStyle) {
151
- Object.assign(style, stateStyle);
152
- return true;
153
- }
154
-
155
- function setPointerState(leaf, stateName) {
156
- const style = leaf[stateName];
157
- if (style)
158
- setStyle(leaf, style);
159
- if (leaf.button)
160
- setChildrenState(leaf.children, stateName);
161
- }
162
- function setState(leaf, stateName, stateStyle) {
163
- if (!stateStyle)
164
- stateStyle = leaf.states[stateName];
165
- setStyle(leaf, stateStyle);
166
- if (leaf.button)
167
- setChildrenState(leaf.children, null, stateName);
168
- }
169
- function setChildrenState(children, stateType, state) {
170
- if (!children)
171
- return;
172
- let leaf, update;
173
- for (let i = 0, len = children.length; i < len; i++) {
174
- leaf = children[i];
175
- if (stateType) {
176
- update = true;
177
- switch (stateType) {
178
- case 'hoverStyle':
179
- if (State$1.isHover(leaf))
180
- update = false;
181
- break;
182
- case 'pressStyle':
183
- if (State$1.isPress(leaf))
184
- update = false;
185
- break;
186
- case 'focusStyle':
187
- if (State$1.isFocus(leaf))
188
- update = false;
189
- }
190
- if (update)
191
- setPointerState(leaf, stateType);
192
- }
193
- else if (state)
194
- setState(leaf, state);
195
- if (leaf.isBranch)
196
- setChildrenState(leaf.children, stateType, state);
197
- }
198
- }
199
-
200
- function unsetPointerState(leaf, stateName) {
201
- const style = leaf[stateName];
202
- if (style)
203
- unsetStyle(leaf, style);
204
- if (leaf.button)
205
- unsetChildrenState(leaf.children, stateName);
206
- }
207
- function unsetState(leaf, stateName, stateStyle) {
208
- unsetStyle(leaf, stateStyle);
209
- if (leaf.button)
210
- unsetChildrenState(leaf.children, null, stateName);
211
- }
212
- function unsetChildrenState(children, stateType, state) {
213
- if (!children)
214
- return;
215
- let leaf;
216
- for (let i = 0, len = children.length; i < len; i++) {
217
- leaf = children[i];
218
- if (stateType)
219
- unsetPointerState(leaf, stateType);
220
- else if (state)
221
- unsetState(leaf, state);
222
- if (leaf.isBranch)
223
- unsetChildrenState(leaf.children, stateType, state);
224
- }
225
- }
226
-
227
- function updateEventStyle(leaf, eventType) {
228
- switch (eventType) {
229
- case PointerEvent.ENTER:
230
- setPointerState(leaf, 'hoverStyle');
231
- break;
232
- case PointerEvent.LEAVE:
233
- unsetPointerState(leaf, 'hoverStyle');
234
- break;
235
- case PointerEvent.DOWN:
236
- setPointerState(leaf, 'pressStyle');
237
- break;
238
- case PointerEvent.UP:
239
- unsetPointerState(leaf, 'pressStyle');
240
- break;
241
- }
242
- }
243
-
244
- function checkPointerState(fnName, leaf, button) {
245
- let find;
246
- const interaction = leaf.leafer ? leaf.leafer.interaction : null;
247
- if (interaction) {
248
- find = interaction[fnName](leaf);
249
- if (!find && button) {
250
- const parentButton = findParentButton(leaf, button);
251
- if (parentButton)
252
- find = interaction[fnName](parentButton);
253
- }
254
- }
255
- return find;
256
- }
257
- function checkFixedState(attrName, leaf, button) {
258
- let find = leaf[attrName];
259
- if (!find && button) {
260
- const parentButton = findParentButton(leaf, button);
261
- if (parentButton)
262
- find = parentButton[attrName];
263
- }
264
- return find;
265
- }
266
- function checkState(stateName, leaf, button) {
267
- let find = leaf.states[stateName];
268
- if (!find && button) {
269
- const parentButton = findParentButton(leaf, button);
270
- if (parentButton)
271
- find = parentButton.states[stateName];
272
- }
273
- return !!find;
274
- }
275
-
276
- State$1.animateExcludes = {
277
- animation: 1,
278
- animationOut: 1,
279
- transition: 1,
280
- transitionOut: 1,
281
- states: 1,
282
- state: 1,
283
- normalStyle: 1,
284
- hoverStyle: 1,
285
- pressStyle: 1,
286
- focusStyle: 1,
287
- selectedStyle: 1,
288
- disabledStyle: 1
289
- };
290
- State$1.isState = function (state, leaf, button) { return checkState(state, leaf, button); };
291
- State$1.isSelected = function (leaf, button) { return checkFixedState('selected', leaf, button); };
292
- State$1.isDisabled = function (leaf, button) { return checkFixedState('disabled', leaf, button); };
293
- State$1.isFocus = function (leaf, button) { return checkPointerState('isFocus', leaf, button); };
294
- State$1.isHover = function (leaf, button) { return checkPointerState('isHover', leaf, button); };
295
- State$1.isPress = function (leaf, button) { return checkPointerState('isPress', leaf, button); };
296
- State$1.isDrag = function (leaf, button) { return checkPointerState('isDrag', leaf, button); };
297
- State$1.setStyleName = function (leaf, stateType, value) { value ? setState(leaf, stateType, leaf[stateType]) : unsetState(leaf, stateType, leaf[stateType]); };
298
- State$1.set = function (leaf, stateName) { const style = leaf.states[stateName]; style ? setState(leaf, stateName, style) : unsetState(leaf, stateName, style); };
299
- State$1.getStyle = getStyle;
300
- State$1.updateStyle = updateStyle;
301
- State$1.updateEventStyle = updateEventStyle;
302
- const ui$1 = UI.prototype;
303
- stateType(false, 'selectedStyle')(ui$1, 'selected');
304
- stateType(false, 'disabledStyle')(ui$1, 'disabled');
305
- stateStyleType({})(ui$1, 'states');
306
- stateType('')(ui$1, 'state');
307
- dataType()(ui$1, 'normalStyle');
308
- stateStyleType()(ui$1, 'hoverStyle');
309
- stateStyleType()(ui$1, 'pressStyle');
310
- stateStyleType()(ui$1, 'focusStyle');
311
- stateStyleType()(ui$1, 'selectedStyle');
312
- stateStyleType()(ui$1, 'disabledStyle');
313
- dataType(false)(ui$1, 'button');
314
- ui$1.focus = function (value = true) {
315
- this.waitLeafer(() => {
316
- let { focusData } = this.app.interaction;
317
- if (value) {
318
- if (focusData)
319
- focusData.focus(false);
320
- focusData = this;
321
- }
322
- else
323
- focusData = null;
324
- this.app.interaction.focusData = focusData;
325
- value ? setPointerState(this, 'focusStyle') : unsetPointerState(this, 'focusStyle');
326
- });
327
- };
328
- ui$1.updateState = function () {
329
- State$1.updateStyle(this, undefined, 'in');
330
- };
331
-
332
- const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285];
333
- const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
334
- const { sqrt } = Math;
335
- const HighBezierHelper = {
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
- for (let i = 0; i < gaussNodes.length; i++) {
339
- t1 = half * (1 + gaussNodes[i]);
340
- t2 = half * (1 - gaussNodes[i]);
341
- d1X = getDerivative(t1, fromX, x1, x2, toX);
342
- d1Y = getDerivative(t1, fromY, y1, y2, toY);
343
- d2X = getDerivative(t2, fromX, x1, x2, toX);
344
- d2Y = getDerivative(t2, fromY, y1, y2, toY);
345
- distance += gaussWeights[i] * (sqrt(d1X * d1X + d1Y * d1Y) + sqrt(d2X * d2X + d2Y * d2Y));
346
- }
347
- return distance * half;
348
- },
349
- getDerivative(t, fromV, v1, v2, toV) {
350
- const o = 1 - t;
351
- return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
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
- },
370
- cut(data, t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
371
- const o = 1 - t;
372
- const ax = o * fromX + t * x1, ay = o * fromY + t * y1;
373
- const mbx = o * x1 + t * x2, mby = o * y1 + t * y2;
374
- const mcx = o * x2 + t * toX, mcy = o * y2 + t * toY;
375
- const bx = o * ax + t * mbx, by = o * ay + t * mby;
376
- const mbcx = o * mbx + t * mcx, mbcy = o * mby + t * mcy;
377
- const cx = o * bx + t * mbcx, cy = o * by + t * mbcy;
378
- data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy);
379
- }
380
- };
381
- const { getDerivative, getDistance } = HighBezierHelper;
382
-
383
- const { M, L, C, Z } = PathCommandMap;
384
- const tempPoint = {}, tempFrom = {};
385
- const HighCurveHelper = {
386
- transform(data, matrix) {
387
- let i = 0, command;
388
- const len = data.length;
389
- while (i < len) {
390
- command = data[i];
391
- switch (command) {
392
- case M:
393
- case L:
394
- HighCurveHelper.transformPoints(data, matrix, i, 1);
395
- i += 3;
396
- break;
397
- case C:
398
- HighCurveHelper.transformPoints(data, matrix, i, 3);
399
- i += 7;
400
- break;
401
- case Z:
402
- i += 1;
403
- }
404
- }
405
- },
406
- transformPoints(data, matrix, start, pointCount) {
407
- for (let i = start + 1, end = i + pointCount * 2; i < end; i += 2) {
408
- tempPoint.x = data[i];
409
- tempPoint.y = data[i + 1];
410
- MatrixHelper.toOuterPoint(matrix, tempPoint);
411
- data[i] = tempPoint.x;
412
- data[i + 1] = tempPoint.y;
413
- }
414
- },
415
- getMotionPathData(data) {
416
- let total = 0, distance, segments = [];
417
- let i = 0, x = 0, y = 0, toX, toY, command;
418
- const len = data.length;
419
- while (i < len) {
420
- command = data[i];
421
- switch (command) {
422
- case M:
423
- case L:
424
- toX = data[i + 1];
425
- toY = data[i + 2];
426
- distance = (command === L && i > 0) ? PointHelper.getDistanceFrom(x, y, toX, toY) : 0;
427
- x = toX;
428
- y = toY;
429
- i += 3;
430
- break;
431
- case C:
432
- toX = data[i + 5];
433
- toY = data[i + 6];
434
- distance = HighBezierHelper.getDistance(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY);
435
- x = toX;
436
- y = toY;
437
- i += 7;
438
- break;
439
- case Z:
440
- i += 1;
441
- default:
442
- distance = 0;
443
- }
444
- segments.push(distance);
445
- total += distance;
446
- }
447
- return { total, segments, data };
448
- },
449
- getDistancePoint(distanceData, motionDistance, motionPrecision) {
450
- const { segments, data } = distanceData;
451
- motionDistance = UnitConvert.number(motionDistance, distanceData.total);
452
- let total = 0, distance, to = {};
453
- let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
454
- let x1, y1, x2, y2, t;
455
- const len = data.length;
456
- while (i < len) {
457
- command = data[i];
458
- switch (command) {
459
- case M:
460
- case L:
461
- toX = data[i + 1];
462
- toY = data[i + 2];
463
- distance = segments[index];
464
- if (total + distance > motionDistance || !distanceData.total) {
465
- if (!i)
466
- x = toX, y = toY;
467
- tempFrom.x = x;
468
- tempFrom.y = y;
469
- to.x = toX;
470
- to.y = toY;
471
- PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
472
- to.rotation = PointHelper.getAngle(tempFrom, to);
473
- return to;
474
- }
475
- x = toX;
476
- y = toY;
477
- i += 3;
478
- break;
479
- case C:
480
- toX = data[i + 5];
481
- toY = data[i + 6];
482
- distance = segments[index];
483
- if (total + distance > motionDistance) {
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);
488
- return to;
489
- }
490
- x = toX;
491
- y = toY;
492
- i += 7;
493
- break;
494
- case Z:
495
- i += 1;
496
- default:
497
- distance = 0;
498
- }
499
- index++;
500
- total += distance;
501
- }
502
- return to;
503
- },
504
- getDistancePath(distanceData, motionDistance, motionPrecision) {
505
- const { segments, data } = distanceData, path = [];
506
- motionDistance = UnitConvert.number(motionDistance, distanceData.total);
507
- let total = 0, distance, to = {};
508
- let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
509
- let x1, y1, x2, y2, t;
510
- const len = data.length;
511
- while (i < len) {
512
- command = data[i];
513
- switch (command) {
514
- case M:
515
- case L:
516
- toX = data[i + 1];
517
- toY = data[i + 2];
518
- distance = segments[index];
519
- if (total + distance > motionDistance || !distanceData.total) {
520
- if (!i)
521
- x = toX, y = toY;
522
- tempFrom.x = x;
523
- tempFrom.y = y;
524
- to.x = toX;
525
- to.y = toY;
526
- PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
527
- path.push(command, to.x, to.y);
528
- return path;
529
- }
530
- x = toX;
531
- y = toY;
532
- i += 3;
533
- path.push(command, x, y);
534
- break;
535
- case C:
536
- x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
537
- toX = data[i + 5];
538
- toY = data[i + 6];
539
- distance = segments[index];
540
- if (total + distance > motionDistance) {
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);
543
- return path;
544
- }
545
- x = toX;
546
- y = toY;
547
- i += 7;
548
- path.push(command, x1, y1, x2, y2, toX, toY);
549
- break;
550
- case Z:
551
- i += 1;
552
- path.push(command);
553
- default:
554
- distance = 0;
555
- }
556
- index++;
557
- total += distance;
558
- }
559
- return path;
560
- }
561
- };
562
-
563
- function motionPathType(defaultValue) {
564
- return decorateLeafAttr(defaultValue, (key) => attr({
565
- set(value) {
566
- this.__setAttr(key, value);
567
- this.__hasMotionPath = this.motionPath || !isNull$1(this.motion);
568
- this.__layout.matrixChanged || this.__layout.matrixChange();
569
- }
570
- }));
571
- }
572
-
573
- Transition.register('motion', function (from, to, t, target) {
574
- if (!from)
575
- from = 0;
576
- else if (typeof from === 'object')
577
- from = UnitConvert.number(from, target.getMotionTotal());
578
- if (!to)
579
- to = 0;
580
- else if (typeof to === 'object')
581
- to = UnitConvert.number(to, target.getMotionTotal());
582
- return Transition.number(from, to, t);
583
- });
584
- Transition.register('motionRotation', function (from, to, t) {
585
- return Transition.number(from, to, t);
586
- });
587
- const ui = UI$1.prototype;
588
- const { updateMatrix, updateAllMatrix } = LeafHelper;
589
- const { updateBounds } = BranchHelper;
590
- motionPathType()(ui, 'motionPath');
591
- motionPathType(1)(ui, 'motionPrecision');
592
- motionPathType()(ui, 'motion');
593
- motionPathType(true)(ui, 'motionRotation');
594
- ui.getMotionPathData = function () {
595
- return getMotionPathData(getMotionPath(this));
596
- };
597
- ui.getMotionPoint = function (motionDistance) {
598
- const path = getMotionPath(this);
599
- const data = getMotionPathData(path);
600
- if (!data.total)
601
- return {};
602
- const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
603
- MatrixHelper.toOuterPoint(path.localTransform, point);
604
- const { motionRotation } = this;
605
- if (motionRotation === false)
606
- delete point.rotation;
607
- else if (typeof motionRotation === 'number')
608
- point.rotation += motionRotation;
609
- return point;
610
- };
611
- ui.getMotionTotal = function () {
612
- return this.getMotionPathData().total;
613
- };
614
- ui.__updateMotionPath = function () {
615
- const data = this.__;
616
- if (this.__layout.resized && data.__pathForMotion)
617
- data.__pathForMotion = undefined;
618
- if (this.motionPath) {
619
- let child;
620
- const { children } = this.parent, { leaferIsReady } = this;
621
- for (let i = 0; i < children.length; i++) {
622
- child = children[i];
623
- if (!isNull$1(child.motion) && !child.__layout.matrixChanged) {
624
- if (leaferIsReady && child !== this)
625
- this.leafer.layouter.addExtra(child);
626
- updateMotion(child);
627
- }
628
- }
629
- }
630
- else
631
- updateMotion(this);
632
- };
633
- function updateMotion(leaf) {
634
- const { motion, leaferIsCreated } = leaf;
635
- if (isNull$1(motion))
636
- return;
637
- if (leaferIsCreated)
638
- leaf.leafer.created = false;
639
- if (leaf.motionPath) {
640
- const data = getMotionPathData(leaf);
641
- if (data.total)
642
- leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
643
- }
644
- else {
645
- leaf.set(leaf.getMotionPoint(motion));
646
- if (!leaf.__hasAutoLayout) {
647
- if (leaf.isBranch)
648
- updateAllMatrix(leaf), updateBounds(leaf, leaf);
649
- else
650
- updateMatrix(leaf);
651
- }
652
- }
653
- if (leaferIsCreated)
654
- leaf.leafer.created = true;
655
- }
656
- function getMotionPath(leaf) {
657
- const { parent } = leaf;
658
- if (!leaf.motionPath && parent) {
659
- const { children } = parent;
660
- for (let i = 0; i < children.length; i++) {
661
- if (children[i].motionPath)
662
- return children[i];
663
- }
664
- }
665
- return leaf;
666
- }
667
- function getMotionPathData(leaf) {
668
- const data = leaf.__;
669
- if (data.__pathForMotion)
670
- return data.__pathForMotion;
671
- return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
672
- }
673
-
674
- export { HighBezierHelper, HighCurveHelper, motionPathType, stateStyleType, stateType };
5
+ export * from '@leafer-in/motion-path';
@@ -1 +1 @@
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};
1
+ export*from"leafer-ui";export*from"@leafer-in/robot";export*from"@leafer-in/state";export*from"@leafer-in/animate";export*from"@leafer-in/motion-path";