@taole/giftstage 0.1.14 → 0.1.15

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 CHANGED
@@ -164,6 +164,32 @@ await stage.addGift({
164
164
  Promise<GiftHandle>;
165
165
  ```
166
166
 
167
+ ### `GiftHandle` API
168
+
169
+ `addGift()` 返回的句柄可用于控制单个礼物:
170
+
171
+ - `gift.id`
172
+ - `gift.type`
173
+ - `gift.pause()`
174
+ - `gift.resume()`
175
+ - `gift.destroy()`
176
+ - 立即移除当前礼物
177
+ - `gift.animate(stepOrSteps?)`
178
+ - 创建链式动画并返回 `GiftAnimationChain`
179
+
180
+ `GiftAnimationChain` 支持:
181
+
182
+ - `.to(step)` / `.then(step)`
183
+ - 追加动画步骤(两者等价)
184
+ - `.onComplete((gift) => void)`
185
+ - 整条链执行完成后的回调
186
+ - `.start(mode?)`
187
+ - `mode: 'immediate' | 'afterGiftComplete'`
188
+ - `immediate`:立即开始(默认)
189
+ - `afterGiftComplete`:等待礼物主播放结束后再执行链
190
+ - `.cancel()`
191
+ - 取消当前礼物正在执行的链式动画
192
+
167
193
  ### `stage.removeGift(id)`
168
194
 
169
195
  按 ID 移除礼物。
@@ -199,17 +225,12 @@ Promise<GiftHandle>;
199
225
  - `objectFit?: 'contain' | 'cover' | 'fill'`
200
226
  - `loop?: number`
201
227
  - `0` 表示无限循环
228
+ - `clearsAfterStop?: boolean`
229
+ - 播放结束后,是否自动移除礼物
230
+ - 默认 `true`,传 `false` 时会停留最后一帧,方便后续继续调用 `gift.animate(...).start()`
202
231
  - `mute?: boolean`
203
232
  - `onComplete?: (gift) => void`
204
233
 
205
- 飞行动画相关:
206
-
207
- - `flyTo?: { x: number; y: number }`
208
- - `scaleTo?: number`
209
- - `flyDuration?: number`
210
- - `easing?: (t: number) => number`
211
- - `onFlyComplete?: (gift) => void`
212
-
213
234
  层级规则:
214
235
 
215
236
  - `zIndex` 在 `SVGA / VAP / AlphaVideo` 三种礼物间通用
@@ -347,6 +368,54 @@ await stage.addGift({
347
368
  });
348
369
  ```
349
370
 
371
+ ## 动画控制
372
+
373
+ ### 链式动画
374
+
375
+ `addGift()` 返回的 `GiftHandle` 支持 `animate()`。一次 `to()` 是组合动画,同一步里可以同时移动和缩放;多个 `to()` / `then()` 会按顺序播放:
376
+
377
+ ```ts
378
+ const gift = await stage.addGift({
379
+ type: 'svga',
380
+ source: 'https://example.com/demo.svga',
381
+ x: '50%',
382
+ y: '50%',
383
+ width: 300,
384
+ height: 300,
385
+ loop: 0,
386
+ });
387
+
388
+ await gift
389
+ .animate()
390
+ .to({
391
+ flyTo: { x: 200, y: 240 },
392
+ scaleTo: 0.8,
393
+ duration: 500,
394
+ })
395
+ .then({
396
+ flyTo: { x: 600, y: 320 },
397
+ scaleTo: 1.1,
398
+ duration: 700,
399
+ })
400
+ .onComplete((g) => {
401
+ console.log('chain complete', g.id);
402
+ })
403
+ .start();
404
+ ```
405
+
406
+ 也可以传入单步或数组:
407
+
408
+ ```ts
409
+ gift.animate({ flyTo: { x: 300, y: 300 }, scaleTo: 0.5 }).start();
410
+
411
+ gift
412
+ .animate([
413
+ { flyTo: { x: 300, y: 300 }, duration: 400 },
414
+ { scaleTo: 1, duration: 300 },
415
+ ])
416
+ .start();
417
+ ```
418
+
350
419
  ## Slot 替换
351
420
 
352
421
  ### SVGA