@omnimedia/omnitool 1.1.0-20 → 1.1.0-22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnimedia/omnitool",
3
- "version": "1.1.0-20",
3
+ "version": "1.1.0-22",
4
4
  "description": "open source video processing tools",
5
5
  "license": "MIT",
6
6
  "author": "Przemysław Gałęzki",
@@ -12,6 +12,7 @@ export enum Kind {
12
12
  Gap,
13
13
  Spatial,
14
14
  Transition,
15
+ TextStyle
15
16
  }
16
17
 
17
18
  export enum Effect {
@@ -19,6 +20,12 @@ export enum Effect {
19
20
  }
20
21
 
21
22
  export namespace Item {
23
+ export type TextStyle = {
24
+ id: Id
25
+ kind: Kind.TextStyle
26
+ style: TextStyleOptions
27
+ }
28
+
22
29
  export type Spatial = {
23
30
  id: Id
24
31
  kind: Kind.Spatial
@@ -68,7 +75,7 @@ export namespace Item {
68
75
  content: string
69
76
  duration: number
70
77
  spatialId?: Id
71
- style: TextStyleOptions
78
+ styleId?: Id
72
79
  }
73
80
 
74
81
  export type Transition = {
@@ -87,6 +94,7 @@ export namespace Item {
87
94
  | Gap
88
95
  | Transition
89
96
  | Spatial
97
+ | TextStyle
90
98
  )
91
99
  }
92
100
 
@@ -1,3 +1,4 @@
1
+ import {TextStyleOptions} from "pixi.js"
1
2
 
2
3
  import {Media} from "../parts/media.js"
3
4
  import {Id, TimelineFile} from "../parts/basics.js"
@@ -9,10 +10,12 @@ export class O {
9
10
 
10
11
  constructor(public state: {project: TimelineFile}) {}
11
12
 
12
- require<T extends Item.Any>(id: Id): T {
13
+ require<T extends Item.Any>(id: Id | undefined) {
14
+ if (id === undefined)
15
+ return undefined
13
16
  const item = this.state.project.items.find(item => item.id === id)
14
- return item as T
15
- }
17
+ return item as T | undefined
18
+ }
16
19
 
17
20
  #getId() {
18
21
  return this.#nextId++
@@ -22,6 +25,12 @@ export class O {
22
25
  this.state.project = fn(this.state.project)
23
26
  }
24
27
 
28
+ textStyle = (style: TextStyleOptions): Item.TextStyle => ({
29
+ id: this.#getId(),
30
+ kind: Kind.TextStyle,
31
+ style
32
+ })
33
+
25
34
  spatial = (transform: Transform): Item.Spatial => {
26
35
  const item: Item.Spatial = {
27
36
  id: this.#getId(),
@@ -107,8 +116,7 @@ export class O {
107
116
  id: this.#getId(),
108
117
  content,
109
118
  kind: Kind.Text,
110
- duration: 2000,
111
- style: {}
119
+ duration: 2000
112
120
  })
113
121
 
114
122
  gap = (duration: number): Item.Gap => ({
@@ -147,5 +155,20 @@ export class O {
147
155
  return state
148
156
  })
149
157
  }
158
+
159
+ update = <K extends keyof Item.Any>(itemId: Id, key: K, value: Item.Any[K]) => {
160
+ this.#mutate(project => {
161
+ const newItems = project.items.map(item => {
162
+ if (item.id === itemId) {
163
+ return {
164
+ ...item,
165
+ [key]: value,
166
+ }
167
+ }
168
+ return item
169
+ })
170
+ return {...project, items: newItems}
171
+ })
172
+ }
150
173
  }
151
174