@twick/visualizer 0.14.0 → 0.14.3
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/.eslintrc.json +20 -20
- package/README.md +113 -13
- package/package.json +14 -14
- package/package.json.bak +34 -0
- package/src/animations/blur.tsx +96 -60
- package/src/animations/breathe.tsx +95 -60
- package/src/animations/fade.tsx +173 -60
- package/src/animations/index.ts +12 -0
- package/src/animations/photo-rise.tsx +103 -66
- package/src/animations/photo-zoom.tsx +109 -73
- package/src/animations/rise.tsx +157 -118
- package/src/animations/succession.tsx +112 -77
- package/src/components/frame-effects.tsx +188 -188
- package/src/components/track.tsx +237 -232
- package/src/controllers/animation.controller.ts +38 -38
- package/src/controllers/element.controller.ts +42 -42
- package/src/controllers/frame-effect.controller.tsx +29 -29
- package/src/controllers/text-effect.controller.ts +32 -32
- package/src/elements/audio.element.tsx +79 -17
- package/src/elements/caption.element.tsx +169 -87
- package/src/elements/circle.element.tsx +88 -20
- package/src/elements/icon.element.tsx +88 -20
- package/src/elements/image.element.tsx +134 -55
- package/src/elements/index.ts +14 -0
- package/src/elements/rect.element.tsx +92 -22
- package/src/elements/scene.element.tsx +97 -29
- package/src/elements/text.element.tsx +101 -27
- package/src/elements/video.element.tsx +274 -56
- package/src/frame-effects/circle.frame.tsx +168 -103
- package/src/frame-effects/index.ts +7 -0
- package/src/frame-effects/rect.frame.tsx +198 -103
- package/src/global.css +11 -11
- package/src/helpers/caption.utils.ts +29 -29
- package/src/helpers/constants.ts +162 -158
- package/src/helpers/element.utils.ts +331 -239
- package/src/helpers/event.utils.ts +21 -0
- package/src/helpers/filters.ts +127 -127
- package/src/helpers/log.utils.ts +55 -29
- package/src/helpers/timing.utils.ts +109 -109
- package/src/helpers/types.ts +361 -241
- package/src/helpers/utils.ts +36 -19
- package/src/index.ts +196 -6
- package/src/live.tsx +16 -16
- package/src/project.ts +6 -6
- package/src/sample.ts +247 -247
- package/src/text-effects/elastic.tsx +70 -39
- package/src/text-effects/erase.tsx +91 -58
- package/src/text-effects/index.ts +9 -0
- package/src/text-effects/stream-word.tsx +94 -60
- package/src/text-effects/typewriter.tsx +93 -59
- package/src/visualizer-grouped.ts +83 -0
- package/src/visualizer.tsx +182 -78
- package/tsconfig.json +11 -11
- package/typedoc.json +19 -14
- package/vite.config.ts +15 -15
- package/.turbo/turbo-build.log +0 -19
- package/.turbo/turbo-docs.log +0 -7
- package/LICENSE +0 -197
- package/dist/mp4.wasm +0 -0
- package/dist/project.css +0 -1
- package/dist/project.js +0 -145
- package/docs/.nojekyll +0 -1
- package/docs/README.md +0 -13
- package/docs/interfaces/Animation.md +0 -47
- package/docs/interfaces/Element.md +0 -47
- package/docs/interfaces/FrameEffectPlugin.md +0 -47
- package/docs/interfaces/TextEffect.md +0 -47
- package/docs/modules.md +0 -535
package/src/helpers/types.ts
CHANGED
|
@@ -1,241 +1,361 @@
|
|
|
1
|
-
import { View2D } from "@twick/2d";
|
|
2
|
-
import { Reference, ThreadGenerator, Vector2 } from "@twick/core";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export type
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
1
|
+
import { View2D } from "@twick/2d";
|
|
2
|
+
import { Reference, ThreadGenerator, Vector2 } from "@twick/core";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Main input configuration for video visualization.
|
|
6
|
+
* Contains player settings, background color, dimensions, and track definitions
|
|
7
|
+
* for creating complete video visualizations.
|
|
8
|
+
*/
|
|
9
|
+
export type VideoInput = {
|
|
10
|
+
playerId: string,
|
|
11
|
+
backgroundColor: string;
|
|
12
|
+
properties: {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
tracks: VisualizerTrack[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Supported media types for visualizer elements.
|
|
21
|
+
* Defines the types of media content that can be displayed.
|
|
22
|
+
*/
|
|
23
|
+
export type MediaType = "video" | "image";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Object fit options for content scaling within containers.
|
|
27
|
+
* Controls how content is sized and positioned within its container.
|
|
28
|
+
*/
|
|
29
|
+
export type ObjectFit = "contain" | "cover" | "fill" | "none";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Two-dimensional size vector with x and y coordinates.
|
|
33
|
+
* Used for representing width and height dimensions.
|
|
34
|
+
*/
|
|
35
|
+
export type SizeVector = {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Size object with width and height properties.
|
|
42
|
+
* Standard size representation for elements and containers.
|
|
43
|
+
*/
|
|
44
|
+
export type Size = {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Size array with width and height values.
|
|
51
|
+
* Alternative size representation as a tuple.
|
|
52
|
+
*/
|
|
53
|
+
export type SizeArray = [number, number];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Position object with x and y coordinates.
|
|
57
|
+
* Represents 2D positioning for elements in the scene.
|
|
58
|
+
*/
|
|
59
|
+
export type Position = {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Frame effect configuration for visual masking.
|
|
66
|
+
* Defines timing and properties for frame effects like circles and rectangles.
|
|
67
|
+
*/
|
|
68
|
+
export type FrameEffect = {
|
|
69
|
+
name: string;
|
|
70
|
+
s: number;
|
|
71
|
+
e: number;
|
|
72
|
+
props: FrameEffectProps;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Properties for frame effect transformations.
|
|
77
|
+
* Controls frame size, shape, position, and transition behavior.
|
|
78
|
+
*/
|
|
79
|
+
export type FrameEffectProps = {
|
|
80
|
+
frameSize: SizeArray;
|
|
81
|
+
frameShape: "circle" | "rect";
|
|
82
|
+
framePosition: Position;
|
|
83
|
+
radius: number;
|
|
84
|
+
objectFit: ObjectFit;
|
|
85
|
+
transitionDuration: number;
|
|
86
|
+
transitionEasing?: string;
|
|
87
|
+
elementPosition: Position;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Styling configuration for caption elements.
|
|
92
|
+
* Defines visual appearance of captions including layout and text styling.
|
|
93
|
+
*/
|
|
94
|
+
export type CaptionStyle = {
|
|
95
|
+
rect: {
|
|
96
|
+
alignItems?: string;
|
|
97
|
+
gap?: number;
|
|
98
|
+
justifyContent?: string;
|
|
99
|
+
padding?: [number, number];
|
|
100
|
+
radius?: number;
|
|
101
|
+
};
|
|
102
|
+
word: {
|
|
103
|
+
lineWidth: number;
|
|
104
|
+
stroke: string;
|
|
105
|
+
fontWeight: number;
|
|
106
|
+
shadowOffset?: number[];
|
|
107
|
+
shadowColor?: string;
|
|
108
|
+
shadowBlur?: number;
|
|
109
|
+
fill: string;
|
|
110
|
+
fontFamily: string;
|
|
111
|
+
bgColor?: string;
|
|
112
|
+
bgOffsetWidth?: number;
|
|
113
|
+
bgOffsetHeight?: number;
|
|
114
|
+
fontSize: number;
|
|
115
|
+
strokeFirst?: boolean;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Caption element configuration.
|
|
121
|
+
* Defines text content, timing, styling, and display properties for captions.
|
|
122
|
+
*/
|
|
123
|
+
export type Caption = {
|
|
124
|
+
t: string;
|
|
125
|
+
s: number;
|
|
126
|
+
e: number;
|
|
127
|
+
capStyle?: string;
|
|
128
|
+
props?: CaptionProps;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Caption styling properties.
|
|
133
|
+
* Controls colors, fonts, background, and positioning for caption text.
|
|
134
|
+
*/
|
|
135
|
+
export type CaptionProps = {
|
|
136
|
+
colors: CaptionColors;
|
|
137
|
+
font: CaptionFont;
|
|
138
|
+
bgOpacity?: number;
|
|
139
|
+
bgOffsetWidth?: number;
|
|
140
|
+
bgOffsetHeight?: number;
|
|
141
|
+
bgMargin?: [number, number];
|
|
142
|
+
bgRadius?: number;
|
|
143
|
+
bgPadding?: [number, number];
|
|
144
|
+
x?: number;
|
|
145
|
+
y?: number;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Color configuration for caption text and backgrounds.
|
|
150
|
+
* Defines text color, background color, and highlight colors.
|
|
151
|
+
*/
|
|
152
|
+
export type CaptionColors = {
|
|
153
|
+
text?: string;
|
|
154
|
+
background?: string;
|
|
155
|
+
highlight?: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Font configuration for caption text.
|
|
160
|
+
* Controls font family, size, weight, and style.
|
|
161
|
+
*/
|
|
162
|
+
export type CaptionFont = {
|
|
163
|
+
family?: string;
|
|
164
|
+
size?: number;
|
|
165
|
+
weight?: number;
|
|
166
|
+
style?: string;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Visualizer element configuration.
|
|
171
|
+
* Defines the structure and properties for all visual elements in the scene
|
|
172
|
+
* including videos, images, text, and captions with their animations and effects.
|
|
173
|
+
*/
|
|
174
|
+
export type VisualizerElement = {
|
|
175
|
+
id: string;
|
|
176
|
+
trackId?: string;
|
|
177
|
+
frame?: any;
|
|
178
|
+
props?: any;
|
|
179
|
+
objectFit?: "contain" | "cover" | "fill";
|
|
180
|
+
type?: string;
|
|
181
|
+
s: number;
|
|
182
|
+
e: number;
|
|
183
|
+
backgroundColor?: string;
|
|
184
|
+
animation?: AnimationProps;
|
|
185
|
+
textEffect: TextEffectProps;
|
|
186
|
+
frameEffects?: FrameEffect[];
|
|
187
|
+
scale?: number;
|
|
188
|
+
t?: string;
|
|
189
|
+
hWords?: any;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Visualizer track configuration.
|
|
194
|
+
* Contains a collection of elements that share common properties and timing.
|
|
195
|
+
* Tracks organize elements into logical groups for better scene management.
|
|
196
|
+
*/
|
|
197
|
+
export type VisualizerTrack = {
|
|
198
|
+
id: string;
|
|
199
|
+
type: string;
|
|
200
|
+
elements: VisualizerElement[];
|
|
201
|
+
props?: {
|
|
202
|
+
capStyle?: string;
|
|
203
|
+
bgOpacity?: number;
|
|
204
|
+
x?: number;
|
|
205
|
+
y?: number;
|
|
206
|
+
colors?: {
|
|
207
|
+
text?: string;
|
|
208
|
+
background?: string;
|
|
209
|
+
highlight?: string;
|
|
210
|
+
};
|
|
211
|
+
font?: {
|
|
212
|
+
family?: string;
|
|
213
|
+
size?: number;
|
|
214
|
+
weight?: number;
|
|
215
|
+
style?: string;
|
|
216
|
+
};
|
|
217
|
+
captionProps?: CaptionProps;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Parameters for creating elements in the visualizer scene.
|
|
223
|
+
* Contains all necessary references and configuration for element creation.
|
|
224
|
+
*/
|
|
225
|
+
export type ElementParams = {
|
|
226
|
+
view: View2D;
|
|
227
|
+
containerRef: Reference<any>;
|
|
228
|
+
element?: VisualizerElement;
|
|
229
|
+
caption?: Caption;
|
|
230
|
+
waitOnStart?: boolean;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Interface for creating visual elements in the scene.
|
|
235
|
+
* Defines the contract for all element types including video, image, text, and captions.
|
|
236
|
+
*/
|
|
237
|
+
export interface Element<Params = ElementParams> {
|
|
238
|
+
/** The unique name identifier for this element type */
|
|
239
|
+
name: string;
|
|
240
|
+
/** Creates and manages the element in the scene */
|
|
241
|
+
create(params: Params): ThreadGenerator;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Parameters for text effect animations.
|
|
246
|
+
* Controls timing and behavior of text animation effects.
|
|
247
|
+
*/
|
|
248
|
+
export type TextEffectParams = {
|
|
249
|
+
elementRef: Reference<any>;
|
|
250
|
+
interval?: number;
|
|
251
|
+
duration?: number;
|
|
252
|
+
bufferTime?: number;
|
|
253
|
+
delay?: number;
|
|
254
|
+
direction?: "left" | "right" | "center";
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Configuration properties for text effects.
|
|
259
|
+
* Defines how text effects should behave and appear.
|
|
260
|
+
*/
|
|
261
|
+
export type TextEffectProps = {
|
|
262
|
+
name: string;
|
|
263
|
+
interval?: number;
|
|
264
|
+
duration?: number;
|
|
265
|
+
bufferTime?: number;
|
|
266
|
+
delay?: number;
|
|
267
|
+
direction?: "left" | "right" | "center";
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Interface for text effect animations.
|
|
272
|
+
* Defines the contract for text animation effects like typewriter, stream word, etc.
|
|
273
|
+
*/
|
|
274
|
+
export interface TextEffect<Params = TextEffectParams> {
|
|
275
|
+
/** The unique name identifier for this text effect */
|
|
276
|
+
name: string;
|
|
277
|
+
/** Executes the text effect animation */
|
|
278
|
+
run(params: Params): Generator;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Parameters for element animations.
|
|
283
|
+
* Controls timing, direction, and behavior of element animations.
|
|
284
|
+
*/
|
|
285
|
+
export type AnimationParams = {
|
|
286
|
+
elementRef: Reference<any>;
|
|
287
|
+
containerRef?: Reference<any>;
|
|
288
|
+
view: View2D;
|
|
289
|
+
interval?: number;
|
|
290
|
+
duration?: number;
|
|
291
|
+
intensity?: number;
|
|
292
|
+
mode?: "in" | "out";
|
|
293
|
+
animate?: "enter" | "exit" | "both";
|
|
294
|
+
direction?: "left" | "right" | "center" | "up" | "down";
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Configuration properties for animations.
|
|
299
|
+
* Defines how animations should behave and appear.
|
|
300
|
+
*/
|
|
301
|
+
export type AnimationProps = {
|
|
302
|
+
name: string;
|
|
303
|
+
interval?: number;
|
|
304
|
+
duration?: number;
|
|
305
|
+
intensity?: number;
|
|
306
|
+
mode?: "in" | "out";
|
|
307
|
+
animate?: "enter" | "exit" | "both";
|
|
308
|
+
direction?: "left" | "right" | "center" | "up" | "down";
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Interface for element animations.
|
|
313
|
+
* Defines the contract for element animation effects like fade, rise, blur, etc.
|
|
314
|
+
*/
|
|
315
|
+
export interface Animation<Params = AnimationParams> {
|
|
316
|
+
/** The unique name identifier for this animation */
|
|
317
|
+
name: string;
|
|
318
|
+
/** Executes the animation */
|
|
319
|
+
run(params: Params): ThreadGenerator;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Parameters for frame effects.
|
|
324
|
+
* Controls frame transformations and visual masking effects.
|
|
325
|
+
*/
|
|
326
|
+
export type FrameEffectParams = {
|
|
327
|
+
elementRef: Reference<any>;
|
|
328
|
+
containerRef?: Reference<any>;
|
|
329
|
+
initFrameState: FrameState;
|
|
330
|
+
frameEffect: FrameEffect;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Interface for frame effect plugins.
|
|
335
|
+
* Defines the contract for frame effects like circular and rectangular masks.
|
|
336
|
+
*/
|
|
337
|
+
export interface FrameEffectPlugin<Params = FrameEffectParams> {
|
|
338
|
+
/** The unique name identifier for this frame effect */
|
|
339
|
+
name: string;
|
|
340
|
+
/** Executes the frame effect */
|
|
341
|
+
run(params: Params): ThreadGenerator;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* State information for frame and element transformations.
|
|
346
|
+
* Contains size, position, and transformation data for frame effects.
|
|
347
|
+
*/
|
|
348
|
+
export type FrameState = {
|
|
349
|
+
frame: {
|
|
350
|
+
size: Vector2;
|
|
351
|
+
pos: Vector2;
|
|
352
|
+
radius: number;
|
|
353
|
+
scale: Vector2;
|
|
354
|
+
rotation: number;
|
|
355
|
+
};
|
|
356
|
+
element: {
|
|
357
|
+
size: Vector2;
|
|
358
|
+
pos: Vector2;
|
|
359
|
+
scale: Vector2;
|
|
360
|
+
};
|
|
361
|
+
};
|
package/src/helpers/utils.ts
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Converts a hex color string to RGB values.
|
|
3
|
+
* Handles both 3-digit and 6-digit hex color formats
|
|
4
|
+
* and returns an object with red, green, and blue values.
|
|
5
|
+
*
|
|
6
|
+
* @param color - The hex color string to convert
|
|
7
|
+
* @returns Object containing r, g, b values
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* const rgb = hexToRGB("#ff0000");
|
|
12
|
+
* // rgb = { r: 255, g: 0, b: 0 }
|
|
13
|
+
*
|
|
14
|
+
* const rgb = hexToRGB("#f00");
|
|
15
|
+
* // rgb = { r: 255, g: 0, b: 0 }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const hexToRGB = (color: string) => {
|
|
19
|
+
// Remove leading '#' if present
|
|
20
|
+
let hex = color.replace(/^#/, '');
|
|
21
|
+
|
|
22
|
+
// Handle shorthand hex (e.g., #abc)
|
|
23
|
+
if (hex.length === 3) {
|
|
24
|
+
hex = hex.split('').map(c => c + c).join('');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (hex.length !== 6) {
|
|
28
|
+
throw new Error('Invalid hex color');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const num = parseInt(hex, 16);
|
|
32
|
+
const r = (num >> 16) & 255;
|
|
33
|
+
const g = (num >> 8) & 255;
|
|
34
|
+
const b = num & 255;
|
|
35
|
+
|
|
36
|
+
return { r, g, b };
|
|
20
37
|
}
|