@taole/giftstage 0.1.13 → 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
@@ -161,9 +161,35 @@ await stage.addGift({
161
161
  插入一个礼物,返回:
162
162
 
163
163
  ```ts
164
- Promise<GiftHandle>
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 移除礼物。
@@ -196,20 +222,15 @@ Promise<GiftHandle>
196
222
  - `width?: number`
197
223
  - `height?: number`
198
224
  - `useOriginalSize?: boolean`
199
- - `objectFit?: 'contain' | 'fill'`
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` 三种礼物间通用
@@ -223,7 +244,8 @@ Promise<GiftHandle>
223
244
  - 两个都传:按传入值显示
224
245
  - 只传 `width`:`height` 按礼物原始宽高比自动补全
225
246
  - 只传 `height`:`width` 按礼物原始宽高比自动补全
226
- - 两个都不传:按当前画布尺寸做等比 `contain`
247
+ - 两个都不传:默认按当前画布尺寸做等比 `contain`
248
+ - 如果 `objectFit: 'cover'` 且两个都不传:按整个画布作为显示区域做等比 `cover`
227
249
  - 也就是会在画布内尽可能放大或缩小,并保持礼物原始宽高比
228
250
  - 如果 `useOriginalSize: true`,且礼物原始尺寸本身小于画布,则优先使用礼物原始尺寸
229
251
  - 如果 `useOriginalSize: true`,但礼物原始尺寸超出画布,则仍会按画布尺寸等比缩小
@@ -242,6 +264,21 @@ await stage.addGift({
242
264
 
243
265
  这时会按舞台尺寸做等比适配,并保持礼物原始宽高比。
244
266
 
267
+ 如果希望礼物铺满整个画布,并按中心裁剪超出的部分,可以使用 `cover`:
268
+
269
+ ```ts
270
+ await stage.addGift({
271
+ type: 'svga',
272
+ source: 'https://example.com/demo.svga',
273
+ x: '50%',
274
+ y: '50%',
275
+ objectFit: 'cover',
276
+ loop: 0,
277
+ });
278
+ ```
279
+
280
+ 当 `x: '50%'`、`y: '50%'` 且未传 `width / height` 时,显示区域会居中放在整个画布上;`cover` 会保持礼物原始宽高比铺满该区域,并从中心裁剪溢出的部分。
281
+
245
282
  如果你希望“小礼物保持原始尺寸,大礼物再缩小”,可以这样:
246
283
 
247
284
  ```ts
@@ -331,6 +368,54 @@ await stage.addGift({
331
368
  });
332
369
  ```
333
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
+
334
419
  ## Slot 替换
335
420
 
336
421
  ### SVGA
@@ -448,7 +533,7 @@ await stage.addGift({
448
533
 
449
534
  入口文件:
450
535
 
451
- - [src/index.ts](</D:/MyDocuments/UnityProjects/SVGAPlayer-Unity/gift-stage/src/index.ts>)
536
+ - [src/index.ts](/D:/MyDocuments/UnityProjects/SVGAPlayer-Unity/gift-stage/src/index.ts)
452
537
 
453
538
  主要导出:
454
539
 
@@ -466,7 +551,7 @@ await stage.addGift({
466
551
 
467
552
  Demo 入口:
468
553
 
469
- - [index.html](</D:/MyDocuments/UnityProjects/SVGAPlayer-Unity/gift-stage/index.html>)
554
+ - [index.html](/D:/MyDocuments/UnityProjects/SVGAPlayer-Unity/gift-stage/index.html)
470
555
 
471
556
  可用于验证:
472
557
 
@@ -478,4 +563,4 @@ Demo 入口:
478
563
  ## 相关文档
479
564
 
480
565
  - 优化汇总:
481
- [docs/giftstage-optimization-summary.md](</D:/MyDocuments/UnityProjects/SVGAPlayer-Unity/gift-stage/docs/giftstage-optimization-summary.md>)
566
+ [docs/giftstage-optimization-summary.md](/D:/MyDocuments/UnityProjects/SVGAPlayer-Unity/gift-stage/docs/giftstage-optimization-summary.md)