@omnimedia/omnitool 1.1.0-84 → 1.1.0-85

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
@@ -233,7 +233,7 @@ const timeline = omni.timeline(o => {
233
233
  duration: 2000,
234
234
  styles: {fill: "white", fontSize: 36},
235
235
  })
236
- o.set(title.id, {animationId: fadeIn.id})
236
+ o.set(title.id, {animationIds: [fadeIn.id]})
237
237
 
238
238
  return o.stack(
239
239
  o.video(clip, {duration: 4000}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnimedia/omnitool",
3
- "version": "1.1.0-84",
3
+ "version": "1.1.0-85",
4
4
  "description": "open source video processing tools",
5
5
  "license": "MIT",
6
6
  "author": "Przemysław Gałęzki",
@@ -32,7 +32,7 @@ export async function TimelineSchemaTest(driver: Driver, file: File) {
32
32
  )
33
33
 
34
34
  const video = o.video(videoA, {duration: 3000, start: 1000})
35
- o.set<Item.Text>(text.id, {styleId: style.id, spatialId: textSpatial.id, animationId: fade.id})
35
+ o.set<Item.Text>(text.id, {styleId: style.id, spatialId: textSpatial.id, animationIds: [fade.id]})
36
36
  o.set<Item.Video>(video.id, {spatialId: videoSpatial.id})
37
37
 
38
38
  return o.sequence(
@@ -94,7 +94,7 @@ export namespace Item {
94
94
  start: number
95
95
  duration: number
96
96
  spatialId?: Id
97
- animationId?: Id
97
+ animationIds?: Id[]
98
98
  filterIds?: Id[]
99
99
  }
100
100
 
@@ -113,7 +113,7 @@ export namespace Item {
113
113
  content: string
114
114
  duration: number
115
115
  spatialId?: Id
116
- animationId?: Id
116
+ animationIds?: Id[]
117
117
  styleId?: Id
118
118
  filterIds?: Id[]
119
119
  }
@@ -1,4 +1,5 @@
1
1
 
2
+ import {Keyframes} from '../../types.js'
2
3
  import {ms, Ms} from '../../../units/ms.js'
3
4
  import {Id, TimelineFile} from '../../parts/basics.js'
4
5
  import { SampleContext } from './samplers/visual/parts/types.js'
@@ -366,12 +367,30 @@ export function computeOpacity(
366
367
  item: Item.Any,
367
368
  time: Ms,
368
369
  ) {
369
- if (!("animationId" in item) || item.animationId === undefined)
370
+ if (!("animationIds" in item) || item.animationIds === undefined)
370
371
  return 1
371
372
 
372
- const animation = ctx.items.get(item.animationId) as Item.Animation | undefined
373
- return animation?.enabled && animation.anims.opacity
374
- ? resolveScalarAnimation(time, animation.anims.opacity)
375
- : 1
373
+ let opacity = 1
374
+ for (const id of item.animationIds) {
375
+ const animation = ctx.items.get(id) as Item.Animation | undefined
376
+ const anim = animation?.anims.opacity
377
+ if (animation?.enabled && anim && keyframesActiveAt(anim.track, time))
378
+ opacity = resolveScalarAnimation(time, anim)
379
+ }
380
+ return opacity
381
+ }
382
+
383
+ function keyframesActiveAt(keys: Keyframes, time: Ms) {
384
+ if (keys.length === 0)
385
+ return false
386
+
387
+ let start = keys[0][0]
388
+ let end = keys[0][0]
389
+ for (const [keyTime] of keys) {
390
+ start = Math.min(start, keyTime)
391
+ end = Math.max(end, keyTime)
392
+ }
393
+
394
+ return time >= start && time <= end
376
395
  }
377
396
 
@@ -177,7 +177,7 @@ export class O {
177
177
  const animation = make(terp, track)
178
178
  const next = {
179
179
  ...item,
180
- animationId: animation.id
180
+ animationIds: [...(item.animationIds ?? []), animation.id]
181
181
  }
182
182
  this.set<T>(item.id, next as Partial<T>)
183
183
  return next