@taole/giftstage 0.1.14 → 0.1.16

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,14 @@ Promise<GiftHandle>;
199
225
  - `objectFit?: 'contain' | 'cover' | 'fill'`
200
226
  - `loop?: number`
201
227
  - `0` 表示无限循环
228
+ - `opacity?: number`
229
+ - 全局透明度,范围 `0 ~ 1`,默认 `1`
230
+ - `clearsAfterStop?: boolean`
231
+ - 播放结束后,是否自动移除礼物
232
+ - 默认 `true`,传 `false` 时会停留最后一帧,方便后续继续调用 `gift.animate(...).start()`
202
233
  - `mute?: boolean`
203
234
  - `onComplete?: (gift) => void`
204
235
 
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
236
  层级规则:
214
237
 
215
238
  - `zIndex` 在 `SVGA / VAP / AlphaVideo` 三种礼物间通用
@@ -347,6 +370,56 @@ await stage.addGift({
347
370
  });
348
371
  ```
349
372
 
373
+ ## 动画控制
374
+
375
+ ### 链式动画
376
+
377
+ `addGift()` 返回的 `GiftHandle` 支持 `animate()`。一次 `to()` 是组合动画,同一步里可以同时移动、缩放和改变透明度;多个 `to()` / `then()` 会按顺序播放:
378
+
379
+ ```ts
380
+ const gift = await stage.addGift({
381
+ type: 'svga',
382
+ source: 'https://example.com/demo.svga',
383
+ x: '50%',
384
+ y: '50%',
385
+ width: 300,
386
+ height: 300,
387
+ loop: 0,
388
+ });
389
+
390
+ await gift
391
+ .animate()
392
+ .to({
393
+ flyTo: { x: 200, y: 240 },
394
+ scaleTo: 0.8,
395
+ opacity: 0.6,
396
+ duration: 500,
397
+ })
398
+ .then({
399
+ flyTo: { x: 600, y: 320 },
400
+ scaleTo: 1.1,
401
+ opacity: 1,
402
+ duration: 700,
403
+ })
404
+ .onComplete((g) => {
405
+ console.log('chain complete', g.id);
406
+ })
407
+ .start();
408
+ ```
409
+
410
+ 也可以传入单步或数组:
411
+
412
+ ```ts
413
+ gift.animate({ flyTo: { x: 300, y: 300 }, scaleTo: 0.5, opacity: 0.3 }).start();
414
+
415
+ gift
416
+ .animate([
417
+ { flyTo: { x: 300, y: 300 }, duration: 400 },
418
+ { scaleTo: 1, opacity: 1, duration: 300 },
419
+ ])
420
+ .start();
421
+ ```
422
+
350
423
  ## Slot 替换
351
424
 
352
425
  ### SVGA
@@ -366,6 +439,7 @@ await stage.addGift({
366
439
  title: {
367
440
  text: 'Hello',
368
441
  color: '#ff0000',
442
+ fontSize: 28,
369
443
  mode: 'dynamic',
370
444
  },
371
445
  },
@@ -378,6 +452,15 @@ await stage.addGift({
378
452
  - 文本配置
379
453
  - 图片配置
380
454
 
455
+ SVGA 文本配置会按目标 frame 自动适配字号,避免文字超出槽位:
456
+
457
+ - `mode: 'dynamic'`:默认行为。生成文字自身尺寸的纹理,渲染时按自身逻辑尺寸居中到 frame 内,不会被拉伸。
458
+ - `mode: 'replace'`:生成和 frame 一样大的纹理,按替换图逻辑铺满 frame。
459
+ - `fontSize?: number`:期望字号;如果文字放不下,会自动缩小。
460
+ - `minFontSize?: number` / `maxFontSize?: number`:限制自适应字号范围。
461
+ - `padding?: number`:文字纹理内边距,默认 `2`。
462
+ - `scale?: number`:文字纹理栅格倍率,SVGA 默认 `3`,用于保持清晰度。
463
+
381
464
  ### VAP / VAPX
382
465
 
383
466
  使用 `vapSlots`: