@yqg/aminofx-css-kit 1.0.8 → 1.0.10
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/README.md +117 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +247 -67
- package/dist/esm/type.d.ts +8 -1
- package/dist/umd/aminofx-css-kit.min.js +1 -1
- package/package.json +4 -1
- package/src/index.ts +149 -0
- package/src/type.ts +15 -1
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
## 🚀 功能特性
|
|
6
6
|
|
|
7
7
|
- **CSS 动画渲染**: 基于纯 CSS 实现的高性能动画播放
|
|
8
|
+
- **Lottie 动画支持**: 集成 lottie-web,支持 Lottie 动画叠加播放
|
|
8
9
|
- **资源预加载**: 智能的图片预加载机制,避免动画卡顿
|
|
9
10
|
- **多种加载方式**: 支持 JSON Schema 直接传入或通过 URL 动态加载
|
|
10
11
|
- **动态数据替换**: 支持模板变量替换,实现数据驱动的动画
|
|
@@ -34,6 +35,26 @@ interface IJsonSchema {
|
|
|
34
35
|
}
|
|
35
36
|
```
|
|
36
37
|
|
|
38
|
+
### ILottieConfig
|
|
39
|
+
|
|
40
|
+
Lottie 动画配置接口,定义 Lottie 动画的播放参数。
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
interface ILottieConfig {
|
|
44
|
+
/** Lottie 动画 JSON 文件 URL */
|
|
45
|
+
url: string;
|
|
46
|
+
|
|
47
|
+
/** Lottie 容器的 DOM id */
|
|
48
|
+
containerId: string;
|
|
49
|
+
|
|
50
|
+
/** 延迟播放时间(毫秒) */
|
|
51
|
+
timeout: number;
|
|
52
|
+
|
|
53
|
+
/** 播放完成后是否清空容器内容,默认 true */
|
|
54
|
+
removeOnComplete?: boolean;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
37
58
|
### IPlayerOptions
|
|
38
59
|
|
|
39
60
|
播放器配置接口,定义创建播放器时的所有可选参数。
|
|
@@ -57,6 +78,9 @@ interface IPlayerOptions {
|
|
|
57
78
|
|
|
58
79
|
/** 动态数据,用于替换模板变量 */
|
|
59
80
|
dynamicData?: Record<string, string | number | boolean>;
|
|
81
|
+
|
|
82
|
+
/** Lottie 动画配置 */
|
|
83
|
+
lottie?: ILottieConfig;
|
|
60
84
|
}
|
|
61
85
|
```
|
|
62
86
|
|
|
@@ -201,6 +225,41 @@ const player = createCssAnimationPlayer('demo-container', {
|
|
|
201
225
|
player.play();
|
|
202
226
|
```
|
|
203
227
|
|
|
228
|
+
### Lottie 动画叠加示例
|
|
229
|
+
|
|
230
|
+
```html
|
|
231
|
+
<!-- HTML 结构 -->
|
|
232
|
+
<div id="demo-container"></div>
|
|
233
|
+
<!-- Lottie 容器 -->
|
|
234
|
+
<div id="lottie-container"></div>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// 基础配置示例
|
|
239
|
+
const player = createCssAnimationPlayer('demo-container', {
|
|
240
|
+
jsonUrl: 'https://example.com/css-animation.json',
|
|
241
|
+
alignItems: 'flex-start',
|
|
242
|
+
lottie: {
|
|
243
|
+
url: 'https://example.com/lottie-animation.json',
|
|
244
|
+
containerId: 'lottie-container', // 传入动效平台设置的lottie容器id,lottie尺寸默认375*812,位置、层级、展示区域等需在动效平台调整
|
|
245
|
+
timeout: 1000, // 延迟 1 秒后播放
|
|
246
|
+
removeOnComplete: true, // 播放完成后清空容器(默认 true,可省略)
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
player.play();
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**功能说明:**
|
|
254
|
+
|
|
255
|
+
- Lottie 动画渲染在用户指定的容器中
|
|
256
|
+
- 需要在 HTML 中预先创建 Lottie 容器元素
|
|
257
|
+
- 通过 `containerId` 参数指定容器的 DOM id
|
|
258
|
+
- `timeout` 参数控制延迟播放时间(毫秒)
|
|
259
|
+
- `removeOnComplete` 控制播放完成后是否清空容器内容(默认 true)
|
|
260
|
+
- Lottie 容器的样式(位置、尺寸、层级等)由用户自行控制
|
|
261
|
+
- Lottie 动画与 CSS 动画独立播放,互不影响
|
|
262
|
+
|
|
204
263
|
## 🎪 高级用法
|
|
205
264
|
|
|
206
265
|
### 生命周期管理
|
|
@@ -413,6 +472,7 @@ const player = createCssAnimationPlayer('container', {
|
|
|
413
472
|
4. **循环播放**:启用 `autoLoop` 时,确保提供了 `duration` 属性
|
|
414
473
|
5. **内存管理**:使用完毕后务必调用 `destroy()` 方法清理资源
|
|
415
474
|
6. **CORS**:通过 URL 加载的资源需要正确配置 CORS 策略
|
|
475
|
+
7. **Lottie 依赖**:使用 Lottie 功能需要确保 `lottie-web` 已正确安装或通过 CDN 引入
|
|
416
476
|
|
|
417
477
|
## 🐛 常见问题
|
|
418
478
|
|
|
@@ -453,3 +513,60 @@ player.updateSchema({
|
|
|
453
513
|
});
|
|
454
514
|
player.play();
|
|
455
515
|
```
|
|
516
|
+
|
|
517
|
+
### Q: Lottie 动画不显示?
|
|
518
|
+
|
|
519
|
+
**A:** 检查以下几点:
|
|
520
|
+
|
|
521
|
+
- 确认 `lottie-web` 库已正确加载(通过 npm 安装或 CDN 引入)
|
|
522
|
+
- 检查 Lottie JSON 文件 URL 是否可访问
|
|
523
|
+
- 确认 `containerId` 对应的容器元素已存在于 DOM 中
|
|
524
|
+
- 检查容器元素的样式(display、visibility、尺寸等)
|
|
525
|
+
- 查看浏览器控制台是否有 Lottie 加载错误
|
|
526
|
+
- 确保 Lottie JSON 文件格式正确
|
|
527
|
+
|
|
528
|
+
### Q: 如何调整 Lottie 动画的位置、大小和层级?
|
|
529
|
+
|
|
530
|
+
**A:** Lottie 容器由用户自行创建和控制,可以通过 CSS 自由设置:
|
|
531
|
+
|
|
532
|
+
```html
|
|
533
|
+
<div id="lottie-container" style="
|
|
534
|
+
position: absolute;
|
|
535
|
+
left: 50px;
|
|
536
|
+
top: 100px;
|
|
537
|
+
width: 500px;
|
|
538
|
+
height: 600px;
|
|
539
|
+
z-index: 999;
|
|
540
|
+
"></div>
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
或使用 CSS 类:
|
|
544
|
+
|
|
545
|
+
```css
|
|
546
|
+
#lottie-container {
|
|
547
|
+
position: absolute;
|
|
548
|
+
left: 50px;
|
|
549
|
+
top: 100px;
|
|
550
|
+
width: 500px;
|
|
551
|
+
height: 600px;
|
|
552
|
+
z-index: 999;
|
|
553
|
+
}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Q: 如何让 Lottie 动画播放完成后保留在页面上?
|
|
557
|
+
|
|
558
|
+
**A:** 设置 `removeOnComplete: false`:
|
|
559
|
+
|
|
560
|
+
```typescript
|
|
561
|
+
const player = createCssAnimationPlayer('container', {
|
|
562
|
+
jsonUrl: 'https://example.com/css-animation.json',
|
|
563
|
+
lottie: {
|
|
564
|
+
url: 'https://example.com/lottie-animation.json',
|
|
565
|
+
containerId: 'lottie-container',
|
|
566
|
+
timeout: 1000,
|
|
567
|
+
removeOnComplete: false, // 播放完成后不清空容器
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
player.play();
|
|
572
|
+
```
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ declare class AnimationPlayer {
|
|
|
11
11
|
private readyPromise;
|
|
12
12
|
private loopTimerId;
|
|
13
13
|
private slotObservers;
|
|
14
|
+
private lottieInstance;
|
|
15
|
+
private lottieTimerId;
|
|
14
16
|
constructor(container: HTMLElement, options: IPlayerOptions);
|
|
15
17
|
private init;
|
|
16
18
|
private replacePlaceholders;
|
|
@@ -19,6 +21,10 @@ declare class AnimationPlayer {
|
|
|
19
21
|
private performMove;
|
|
20
22
|
private observeElementMount;
|
|
21
23
|
private cleanupSlotObservers;
|
|
24
|
+
private initLottie;
|
|
25
|
+
private playLottie;
|
|
26
|
+
private removeLottieContent;
|
|
27
|
+
private cleanupLottie;
|
|
22
28
|
private handleLoop;
|
|
23
29
|
ready(): Promise<void>;
|
|
24
30
|
play(): Promise<void>;
|
package/dist/esm/index.js
CHANGED
|
@@ -4,6 +4,8 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
4
4
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
5
5
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
6
6
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
+
import lottie from 'lottie-web/build/player/lottie_light';
|
|
8
|
+
|
|
7
9
|
// 扩展全局 Window 接口
|
|
8
10
|
|
|
9
11
|
var isBrowser = typeof window !== 'undefined';
|
|
@@ -102,7 +104,7 @@ var ResourceLoader = /*#__PURE__*/function () {
|
|
|
102
104
|
_defineProperty(ResourceLoader, "imageCache", new Map());
|
|
103
105
|
_defineProperty(ResourceLoader, "loadingQueue", new Map());
|
|
104
106
|
var AnimationPlayer = /*#__PURE__*/function () {
|
|
105
|
-
// 保存
|
|
107
|
+
// 保存 lottie 延迟播放定时器
|
|
106
108
|
|
|
107
109
|
function AnimationPlayer(container, options) {
|
|
108
110
|
_classCallCheck(this, AnimationPlayer);
|
|
@@ -113,6 +115,10 @@ var AnimationPlayer = /*#__PURE__*/function () {
|
|
|
113
115
|
_defineProperty(this, "loopTimerId", null);
|
|
114
116
|
// 保存定时器ID,用于清理
|
|
115
117
|
_defineProperty(this, "slotObservers", []);
|
|
118
|
+
// 保存 MutationObserver 实例,用于清理
|
|
119
|
+
_defineProperty(this, "lottieInstance", null);
|
|
120
|
+
// 保存 lottie 实例
|
|
121
|
+
_defineProperty(this, "lottieTimerId", null);
|
|
116
122
|
this.container = container;
|
|
117
123
|
this.options = options;
|
|
118
124
|
this.init();
|
|
@@ -292,11 +298,172 @@ var AnimationPlayer = /*#__PURE__*/function () {
|
|
|
292
298
|
this.slotObservers = [];
|
|
293
299
|
console.log('aminofx: 🧹 清理所有插槽观察器');
|
|
294
300
|
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 初始化 lottie 动画
|
|
304
|
+
*/
|
|
305
|
+
}, {
|
|
306
|
+
key: "initLottie",
|
|
307
|
+
value: (function () {
|
|
308
|
+
var _initLottie = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
309
|
+
var _this5 = this;
|
|
310
|
+
var _this$options$lottie, url, containerId, lottieContainer;
|
|
311
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
312
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
313
|
+
case 0:
|
|
314
|
+
if (this.options.lottie) {
|
|
315
|
+
_context3.next = 2;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
return _context3.abrupt("return");
|
|
319
|
+
case 2:
|
|
320
|
+
_context3.prev = 2;
|
|
321
|
+
_this$options$lottie = this.options.lottie, url = _this$options$lottie.url, containerId = _this$options$lottie.containerId; // 获取用户指定的容器
|
|
322
|
+
lottieContainer = document.getElementById(containerId);
|
|
323
|
+
if (lottieContainer) {
|
|
324
|
+
_context3.next = 8;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
console.error("aminofx: \u274C \u627E\u4E0D\u5230 Lottie \u5BB9\u5668\uFF0Cid: ".concat(containerId));
|
|
328
|
+
return _context3.abrupt("return");
|
|
329
|
+
case 8:
|
|
330
|
+
console.log("aminofx: \uD83C\uDFAC \u5F00\u59CB\u52A0\u8F7D Lottie \u52A8\u753B: ".concat(url));
|
|
331
|
+
console.log("aminofx: \uD83D\uDCE6 Lottie \u5BB9\u5668 ID: ".concat(containerId));
|
|
332
|
+
|
|
333
|
+
// 使用 lottie-web 加载动画
|
|
334
|
+
this.lottieInstance = lottie.loadAnimation({
|
|
335
|
+
container: lottieContainer,
|
|
336
|
+
renderer: 'svg',
|
|
337
|
+
loop: false,
|
|
338
|
+
autoplay: false,
|
|
339
|
+
// 不自动播放,等待延迟后手动播放
|
|
340
|
+
path: url
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// 等待动画加载完成
|
|
344
|
+
_context3.next = 13;
|
|
345
|
+
return new Promise(function (resolve, reject) {
|
|
346
|
+
if (!_this5.lottieInstance) {
|
|
347
|
+
reject(new Error('Lottie 实例创建失败'));
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
_this5.lottieInstance.addEventListener('DOMLoaded', function () {
|
|
351
|
+
console.log('aminofx: ✅ Lottie 动画加载完成');
|
|
352
|
+
resolve();
|
|
353
|
+
});
|
|
354
|
+
_this5.lottieInstance.addEventListener('data_failed', function () {
|
|
355
|
+
console.error('aminofx: ❌ Lottie 动画加载失败');
|
|
356
|
+
reject(new Error('Lottie 动画加载失败'));
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
case 13:
|
|
360
|
+
_context3.next = 18;
|
|
361
|
+
break;
|
|
362
|
+
case 15:
|
|
363
|
+
_context3.prev = 15;
|
|
364
|
+
_context3.t0 = _context3["catch"](2);
|
|
365
|
+
console.error('aminofx: ❌ 初始化 Lottie 失败:', _context3.t0);
|
|
366
|
+
case 18:
|
|
367
|
+
case "end":
|
|
368
|
+
return _context3.stop();
|
|
369
|
+
}
|
|
370
|
+
}, _callee3, this, [[2, 15]]);
|
|
371
|
+
}));
|
|
372
|
+
function initLottie() {
|
|
373
|
+
return _initLottie.apply(this, arguments);
|
|
374
|
+
}
|
|
375
|
+
return initLottie;
|
|
376
|
+
}()
|
|
377
|
+
/**
|
|
378
|
+
* 播放 lottie 动画(支持延迟)
|
|
379
|
+
*/
|
|
380
|
+
)
|
|
381
|
+
}, {
|
|
382
|
+
key: "playLottie",
|
|
383
|
+
value: function playLottie() {
|
|
384
|
+
var _this6 = this;
|
|
385
|
+
if (!this.options.lottie || !this.lottieInstance) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
var _this$options$lottie2 = this.options.lottie,
|
|
389
|
+
timeout = _this$options$lottie2.timeout,
|
|
390
|
+
_this$options$lottie3 = _this$options$lottie2.removeOnComplete,
|
|
391
|
+
removeOnComplete = _this$options$lottie3 === void 0 ? true : _this$options$lottie3;
|
|
392
|
+
|
|
393
|
+
// 清理旧的延迟定时器
|
|
394
|
+
if (this.lottieTimerId !== null) {
|
|
395
|
+
clearTimeout(this.lottieTimerId);
|
|
396
|
+
this.lottieTimerId = null;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// 监听播放完成事件
|
|
400
|
+
if (removeOnComplete) {
|
|
401
|
+
this.lottieInstance.addEventListener('complete', function () {
|
|
402
|
+
console.log('aminofx: ✅ Lottie 动画播放完成,正在清空内容...');
|
|
403
|
+
_this6.removeLottieContent();
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (timeout > 0) {
|
|
407
|
+
console.log("aminofx: \u23F0 Lottie \u52A8\u753B\u5C06\u5728 ".concat(timeout, "ms \u540E\u64AD\u653E"));
|
|
408
|
+
this.lottieTimerId = window.setTimeout(function () {
|
|
409
|
+
var _this6$lottieInstance;
|
|
410
|
+
(_this6$lottieInstance = _this6.lottieInstance) === null || _this6$lottieInstance === void 0 || _this6$lottieInstance.play();
|
|
411
|
+
console.log('aminofx: ▶️ Lottie 动画开始播放');
|
|
412
|
+
_this6.lottieTimerId = null;
|
|
413
|
+
}, timeout);
|
|
414
|
+
} else {
|
|
415
|
+
this.lottieInstance.play();
|
|
416
|
+
console.log('aminofx: ▶️ Lottie 动画立即播放');
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 移除 lottie 内容(播放完成后调用)
|
|
422
|
+
*/
|
|
423
|
+
}, {
|
|
424
|
+
key: "removeLottieContent",
|
|
425
|
+
value: function removeLottieContent() {
|
|
426
|
+
if (!this.options.lottie) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
var containerId = this.options.lottie.containerId;
|
|
430
|
+
var lottieContainer = document.getElementById(containerId);
|
|
431
|
+
if (!lottieContainer) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
try {
|
|
435
|
+
lottieContainer.innerHTML = '';
|
|
436
|
+
console.log('aminofx: 🗑️ Lottie 内容已清空');
|
|
437
|
+
} catch (error) {
|
|
438
|
+
console.error('aminofx: ❌ 清空 Lottie 内容失败:', error);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* 清理 lottie 相关资源
|
|
444
|
+
*/
|
|
445
|
+
}, {
|
|
446
|
+
key: "cleanupLottie",
|
|
447
|
+
value: function cleanupLottie() {
|
|
448
|
+
// 清理延迟定时器
|
|
449
|
+
if (this.lottieTimerId !== null) {
|
|
450
|
+
clearTimeout(this.lottieTimerId);
|
|
451
|
+
this.lottieTimerId = null;
|
|
452
|
+
console.log('aminofx: 🧹 清理 Lottie 延迟定时器');
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// 销毁 lottie 实例
|
|
456
|
+
if (this.lottieInstance) {
|
|
457
|
+
this.lottieInstance.destroy();
|
|
458
|
+
this.lottieInstance = null;
|
|
459
|
+
console.log('aminofx: 🗑️ 销毁 Lottie 实例');
|
|
460
|
+
}
|
|
461
|
+
}
|
|
295
462
|
}, {
|
|
296
463
|
key: "handleLoop",
|
|
297
464
|
value: function handleLoop() {
|
|
298
465
|
var _this$options$jsonSch,
|
|
299
|
-
|
|
466
|
+
_this7 = this,
|
|
300
467
|
_this$options$jsonSch2,
|
|
301
468
|
_this$options$jsonSch3;
|
|
302
469
|
if (!this.options.autoLoop || !Number((_this$options$jsonSch = this.options.jsonSchema) === null || _this$options$jsonSch === void 0 ? void 0 : _this$options$jsonSch.duration)) {
|
|
@@ -312,10 +479,10 @@ var AnimationPlayer = /*#__PURE__*/function () {
|
|
|
312
479
|
|
|
313
480
|
// 后续根据使用情况看是否调整为监听css动画结束事件
|
|
314
481
|
this.loopTimerId = window.setTimeout(function () {
|
|
315
|
-
|
|
482
|
+
_this7.container.style.display = 'none';
|
|
316
483
|
window.setTimeout(function () {
|
|
317
|
-
|
|
318
|
-
|
|
484
|
+
_this7.loopTimerId = null;
|
|
485
|
+
_this7.play();
|
|
319
486
|
}, 100);
|
|
320
487
|
}, Number((_this$options$jsonSch2 = this.options.jsonSchema) === null || _this$options$jsonSch2 === void 0 ? void 0 : _this$options$jsonSch2.duration));
|
|
321
488
|
console.log("aminofx: \uD83D\uDD04 \u542F\u52A8\u5FAA\u73AF\u5B9A\u65F6\u5668\uFF0C\u65F6\u957F: ".concat((_this$options$jsonSch3 = this.options.jsonSchema) === null || _this$options$jsonSch3 === void 0 ? void 0 : _this$options$jsonSch3.duration, "ms"));
|
|
@@ -323,118 +490,125 @@ var AnimationPlayer = /*#__PURE__*/function () {
|
|
|
323
490
|
}, {
|
|
324
491
|
key: "ready",
|
|
325
492
|
value: function () {
|
|
326
|
-
var _ready = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
327
|
-
var
|
|
328
|
-
return _regeneratorRuntime().wrap(function
|
|
329
|
-
while (1) switch (
|
|
493
|
+
var _ready = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
494
|
+
var _this8 = this;
|
|
495
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
496
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
330
497
|
case 0:
|
|
331
498
|
if (!this.isReady) {
|
|
332
|
-
|
|
499
|
+
_context6.next = 3;
|
|
333
500
|
break;
|
|
334
501
|
}
|
|
335
502
|
console.log('aminofx: ✅ 动画已准备就绪,直接返回');
|
|
336
|
-
return
|
|
503
|
+
return _context6.abrupt("return", Promise.resolve());
|
|
337
504
|
case 3:
|
|
338
505
|
if (!this.readyPromise) {
|
|
339
|
-
|
|
506
|
+
_context6.next = 6;
|
|
340
507
|
break;
|
|
341
508
|
}
|
|
342
509
|
console.log('aminofx: ⏳ 正在准备中,等待现有Promise...');
|
|
343
|
-
return
|
|
510
|
+
return _context6.abrupt("return", this.readyPromise);
|
|
344
511
|
case 6:
|
|
345
512
|
this.readyPromise = new Promise( /*#__PURE__*/function () {
|
|
346
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
513
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(resolve, reject) {
|
|
347
514
|
var jsonPromise, imgPromise;
|
|
348
|
-
return _regeneratorRuntime().wrap(function
|
|
349
|
-
while (1) switch (
|
|
515
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
516
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
350
517
|
case 0:
|
|
351
|
-
|
|
518
|
+
_context5.prev = 0;
|
|
352
519
|
jsonPromise = new Promise( /*#__PURE__*/function () {
|
|
353
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
354
|
-
var
|
|
355
|
-
var
|
|
356
|
-
return _regeneratorRuntime().wrap(function
|
|
357
|
-
while (1) switch (
|
|
520
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(resolve, reject) {
|
|
521
|
+
var _this8$options;
|
|
522
|
+
var _this8$options2, _this8$options$jsonSc, response, data;
|
|
523
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
524
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
358
525
|
case 0:
|
|
359
|
-
if (!
|
|
360
|
-
|
|
526
|
+
if (!_this8.options.jsonSchema) {
|
|
527
|
+
_context4.next = 5;
|
|
361
528
|
break;
|
|
362
529
|
}
|
|
363
|
-
|
|
530
|
+
_this8.container.innerHTML = _this8.replacePlaceholders(_this8.options.jsonSchema.content);
|
|
364
531
|
resolve();
|
|
365
|
-
|
|
532
|
+
_context4.next = 24;
|
|
366
533
|
break;
|
|
367
534
|
case 5:
|
|
368
|
-
if (!((
|
|
369
|
-
|
|
535
|
+
if (!((_this8$options = _this8.options) !== null && _this8$options !== void 0 && _this8$options.jsonUrl)) {
|
|
536
|
+
_context4.next = 23;
|
|
370
537
|
break;
|
|
371
538
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return fetch((
|
|
539
|
+
_context4.prev = 6;
|
|
540
|
+
_context4.next = 9;
|
|
541
|
+
return fetch((_this8$options2 = _this8.options) === null || _this8$options2 === void 0 ? void 0 : _this8$options2.jsonUrl);
|
|
375
542
|
case 9:
|
|
376
|
-
response =
|
|
377
|
-
|
|
543
|
+
response = _context4.sent;
|
|
544
|
+
_context4.next = 12;
|
|
378
545
|
return response.json();
|
|
379
546
|
case 12:
|
|
380
|
-
data =
|
|
381
|
-
|
|
382
|
-
|
|
547
|
+
data = _context4.sent;
|
|
548
|
+
_this8.options.jsonSchema = data;
|
|
549
|
+
_this8.container.innerHTML = _this8.replacePlaceholders(((_this8$options$jsonSc = _this8.options.jsonSchema) === null || _this8$options$jsonSc === void 0 ? void 0 : _this8$options$jsonSc.content) || '');
|
|
383
550
|
resolve();
|
|
384
|
-
|
|
551
|
+
_context4.next = 21;
|
|
385
552
|
break;
|
|
386
553
|
case 18:
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
reject(
|
|
554
|
+
_context4.prev = 18;
|
|
555
|
+
_context4.t0 = _context4["catch"](6);
|
|
556
|
+
reject(_context4.t0);
|
|
390
557
|
case 21:
|
|
391
|
-
|
|
558
|
+
_context4.next = 24;
|
|
392
559
|
break;
|
|
393
560
|
case 23:
|
|
394
561
|
throw new Error('没有提供jsonSchema或jsonUrl');
|
|
395
562
|
case 24:
|
|
396
563
|
case "end":
|
|
397
|
-
return
|
|
564
|
+
return _context4.stop();
|
|
398
565
|
}
|
|
399
|
-
},
|
|
566
|
+
}, _callee4, null, [[6, 18]]);
|
|
400
567
|
}));
|
|
401
568
|
return function (_x4, _x5) {
|
|
402
569
|
return _ref2.apply(this, arguments);
|
|
403
570
|
};
|
|
404
571
|
}());
|
|
405
|
-
imgPromise = ResourceLoader.loadImages(
|
|
406
|
-
|
|
572
|
+
imgPromise = ResourceLoader.loadImages(_this8.options.preloadImgList || []);
|
|
573
|
+
_context5.next = 5;
|
|
407
574
|
return Promise.all([jsonPromise, imgPromise]);
|
|
408
575
|
case 5:
|
|
409
|
-
|
|
576
|
+
if (!_this8.options.lottie) {
|
|
577
|
+
_context5.next = 8;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
_context5.next = 8;
|
|
581
|
+
return _this8.initLottie();
|
|
582
|
+
case 8:
|
|
583
|
+
_this8.isReady = true; // 设置准备完成状态
|
|
410
584
|
|
|
411
585
|
// 处理插槽列表(此时弹窗内容已渲染,slotId 存在)
|
|
412
|
-
|
|
586
|
+
_this8.handleSlotList();
|
|
413
587
|
resolve();
|
|
414
588
|
console.log('aminofx: 🎉 动画准备完成,可以开始播放');
|
|
415
|
-
|
|
589
|
+
_context5.next = 18;
|
|
416
590
|
break;
|
|
417
|
-
case
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
reject(
|
|
421
|
-
console.error('aminofx: ❌ 动画准备失败:',
|
|
422
|
-
case
|
|
591
|
+
case 14:
|
|
592
|
+
_context5.prev = 14;
|
|
593
|
+
_context5.t0 = _context5["catch"](0);
|
|
594
|
+
reject(_context5.t0);
|
|
595
|
+
console.error('aminofx: ❌ 动画准备失败:', _context5.t0);
|
|
596
|
+
case 18:
|
|
423
597
|
case "end":
|
|
424
|
-
return
|
|
598
|
+
return _context5.stop();
|
|
425
599
|
}
|
|
426
|
-
},
|
|
600
|
+
}, _callee5, null, [[0, 14]]);
|
|
427
601
|
}));
|
|
428
602
|
return function (_x2, _x3) {
|
|
429
603
|
return _ref.apply(this, arguments);
|
|
430
604
|
};
|
|
431
605
|
}());
|
|
432
|
-
return
|
|
606
|
+
return _context6.abrupt("return", this.readyPromise);
|
|
433
607
|
case 8:
|
|
434
608
|
case "end":
|
|
435
|
-
return
|
|
609
|
+
return _context6.stop();
|
|
436
610
|
}
|
|
437
|
-
},
|
|
611
|
+
}, _callee6, this);
|
|
438
612
|
}));
|
|
439
613
|
function ready() {
|
|
440
614
|
return _ready.apply(this, arguments);
|
|
@@ -444,29 +618,32 @@ var AnimationPlayer = /*#__PURE__*/function () {
|
|
|
444
618
|
}, {
|
|
445
619
|
key: "play",
|
|
446
620
|
value: function () {
|
|
447
|
-
var _play = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
448
|
-
return _regeneratorRuntime().wrap(function
|
|
449
|
-
while (1) switch (
|
|
621
|
+
var _play = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
622
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
623
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
450
624
|
case 0:
|
|
451
625
|
if (this.isReady) {
|
|
452
|
-
|
|
626
|
+
_context7.next = 4;
|
|
453
627
|
break;
|
|
454
628
|
}
|
|
455
629
|
console.warn('aminofx: ⚠️ 动画尚未准备就绪,自动调用ready()...');
|
|
456
|
-
|
|
630
|
+
_context7.next = 4;
|
|
457
631
|
return this.ready();
|
|
458
632
|
case 4:
|
|
459
633
|
this.container.style.display = 'flex';
|
|
460
634
|
|
|
635
|
+
// 播放 lottie 动画(如果配置了 lottie)
|
|
636
|
+
this.playLottie();
|
|
637
|
+
|
|
461
638
|
// 只在循环未启动时才启动循环,防止重复调用
|
|
462
639
|
if (this.options.autoLoop && this.loopTimerId === null) {
|
|
463
640
|
this.handleLoop();
|
|
464
641
|
}
|
|
465
|
-
case
|
|
642
|
+
case 7:
|
|
466
643
|
case "end":
|
|
467
|
-
return
|
|
644
|
+
return _context7.stop();
|
|
468
645
|
}
|
|
469
|
-
},
|
|
646
|
+
}, _callee7, this);
|
|
470
647
|
}));
|
|
471
648
|
function play() {
|
|
472
649
|
return _play.apply(this, arguments);
|
|
@@ -486,6 +663,9 @@ var AnimationPlayer = /*#__PURE__*/function () {
|
|
|
486
663
|
// 清理插槽观察器
|
|
487
664
|
this.cleanupSlotObservers();
|
|
488
665
|
|
|
666
|
+
// 清理 lottie 相关资源
|
|
667
|
+
this.cleanupLottie();
|
|
668
|
+
|
|
489
669
|
// 重置状态
|
|
490
670
|
this.container.innerHTML = '';
|
|
491
671
|
this.isReady = false;
|
package/dist/esm/type.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ type IJsonSchema = {
|
|
|
2
2
|
duration: number;
|
|
3
3
|
content: string;
|
|
4
4
|
};
|
|
5
|
+
interface ILottieConfig {
|
|
6
|
+
url: string;
|
|
7
|
+
containerId: string;
|
|
8
|
+
timeout: number;
|
|
9
|
+
removeOnComplete?: boolean;
|
|
10
|
+
}
|
|
5
11
|
interface IPlayerOptions {
|
|
6
12
|
alignItems?: 'center' | 'flex-start' | 'flex-end';
|
|
7
13
|
jsonSchema?: IJsonSchema;
|
|
@@ -20,5 +26,6 @@ interface IPlayerOptions {
|
|
|
20
26
|
};
|
|
21
27
|
}[];
|
|
22
28
|
containerStyle?: Record<string, string>;
|
|
29
|
+
lottie?: ILottieConfig;
|
|
23
30
|
}
|
|
24
|
-
export type { IPlayerOptions, IJsonSchema };
|
|
31
|
+
export type { IPlayerOptions, IJsonSchema, ILottieConfig };
|