@leafer-game/miniapp 1.0.10 → 1.1.1

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