@twick/visualizer 0.0.1 → 0.14.2
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 +12 -12
- package/package.json +34 -31
- package/package.json.bak +34 -0
- package/src/animations/blur.tsx +60 -0
- package/src/animations/breathe.tsx +60 -0
- package/src/animations/fade.tsx +60 -0
- package/src/animations/photo-rise.tsx +66 -0
- package/src/animations/photo-zoom.tsx +73 -0
- package/src/animations/rise.tsx +118 -0
- package/src/animations/succession.tsx +77 -0
- package/src/components/frame-effects.tsx +188 -190
- package/src/components/track.tsx +237 -0
- package/src/controllers/animation.controller.ts +39 -0
- package/src/controllers/element.controller.ts +43 -0
- package/src/controllers/frame-effect.controller.tsx +30 -0
- package/src/controllers/text-effect.controller.ts +33 -0
- package/src/elements/audio.element.tsx +17 -0
- package/src/elements/caption.element.tsx +87 -0
- package/src/elements/circle.element.tsx +20 -0
- package/src/elements/icon.element.tsx +20 -0
- package/src/elements/image.element.tsx +53 -0
- package/src/elements/rect.element.tsx +22 -0
- package/src/elements/scene.element.tsx +29 -0
- package/src/elements/text.element.tsx +28 -0
- package/src/elements/video.element.tsx +55 -0
- package/src/frame-effects/circle.frame.tsx +103 -0
- package/src/frame-effects/rect.frame.tsx +103 -0
- package/src/global.css +11 -11
- package/src/helpers/caption.utils.ts +30 -40
- package/src/helpers/constants.ts +162 -158
- package/src/helpers/element.utils.ts +239 -85
- package/src/helpers/event.utils.ts +6 -0
- package/src/helpers/filters.ts +127 -127
- package/src/helpers/log.utils.ts +29 -32
- package/src/helpers/timing.utils.ts +110 -129
- package/src/helpers/types.ts +242 -146
- package/src/helpers/utils.ts +20 -0
- package/src/index.ts +6 -4
- package/src/live.tsx +16 -16
- package/src/project.ts +6 -6
- package/src/sample.ts +247 -449
- package/src/text-effects/elastic.tsx +39 -0
- package/src/text-effects/erase.tsx +58 -0
- package/src/text-effects/stream-word.tsx +60 -0
- package/src/text-effects/typewriter.tsx +59 -0
- package/src/visualizer.tsx +98 -78
- package/tsconfig.json +11 -10
- package/typedoc.json +14 -14
- package/vite.config.ts +15 -15
- package/src/components/animation.tsx +0 -7
- package/src/components/element.tsx +0 -344
- package/src/components/timeline.tsx +0 -225
|
@@ -1,85 +1,239 @@
|
|
|
1
|
-
import { Reference } from "@
|
|
2
|
-
import { ObjectFit, SizeVector } from "./types";
|
|
3
|
-
import { OBJECT_FIT } from "./constants";
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
import { all, Reference, waitFor } from "@twick/core";
|
|
2
|
+
import { FrameState, ObjectFit, SizeVector, VisualizerElement } from "./types";
|
|
3
|
+
import { OBJECT_FIT } from "./constants";
|
|
4
|
+
import textEffectController from "../controllers/text-effect.controller";
|
|
5
|
+
import animationController from "../controllers/animation.controller";
|
|
6
|
+
import { View2D } from "@twick/2d";
|
|
7
|
+
import frameEffectController from "../controllers/frame-effect.controller";
|
|
8
|
+
import { logger } from "./log.utils";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Element utilities for the visualizer package.
|
|
12
|
+
* Provides functions for handling element positioning, sizing, and transformations.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fits an element within specified bounds while maintaining aspect ratio
|
|
17
|
+
* @param {Object} params - Parameters for fitting the element
|
|
18
|
+
* @param {Object} params.containerSize - The container size
|
|
19
|
+
* @param {Object} params.elementSize - The element size
|
|
20
|
+
* @param {Object} params.elementRef - The element reference
|
|
21
|
+
* @param {string} [params.objectFit] - The fit mode (contain, cover, fill)
|
|
22
|
+
* @returns {Object} Updated element dimensions
|
|
23
|
+
*/
|
|
24
|
+
export function* fitElement({
|
|
25
|
+
containerSize,
|
|
26
|
+
elementSize,
|
|
27
|
+
elementRef,
|
|
28
|
+
objectFit,
|
|
29
|
+
}: {
|
|
30
|
+
containerSize: SizeVector;
|
|
31
|
+
elementSize: SizeVector;
|
|
32
|
+
elementRef: Reference<any>;
|
|
33
|
+
objectFit?: ObjectFit;
|
|
34
|
+
}) {
|
|
35
|
+
const containerAspectRatio = containerSize.x / containerSize.y;
|
|
36
|
+
const elementAspectRatio = elementSize.x / elementSize.y;
|
|
37
|
+
switch (objectFit) {
|
|
38
|
+
case OBJECT_FIT.CONTAIN:
|
|
39
|
+
if (elementAspectRatio > containerAspectRatio) {
|
|
40
|
+
yield elementRef().size({
|
|
41
|
+
x: containerSize.x,
|
|
42
|
+
y: containerSize.x / elementAspectRatio,
|
|
43
|
+
});
|
|
44
|
+
yield elementRef().scale(
|
|
45
|
+
containerSize.x / elementSize.x,
|
|
46
|
+
(containerSize.x * elementAspectRatio) / elementSize.y
|
|
47
|
+
);
|
|
48
|
+
} else {
|
|
49
|
+
yield elementRef().size({
|
|
50
|
+
x: containerSize.y * elementAspectRatio,
|
|
51
|
+
y: containerSize.y,
|
|
52
|
+
});
|
|
53
|
+
yield elementRef().scale(
|
|
54
|
+
(containerSize.y * elementAspectRatio) / elementSize.x,
|
|
55
|
+
containerSize.y / elementSize.y
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case OBJECT_FIT.COVER:
|
|
60
|
+
if (elementAspectRatio > containerAspectRatio) {
|
|
61
|
+
yield elementRef().size({
|
|
62
|
+
x: containerSize.y * elementAspectRatio,
|
|
63
|
+
y: containerSize.y,
|
|
64
|
+
});
|
|
65
|
+
yield elementRef().scale(
|
|
66
|
+
(containerSize.y * elementAspectRatio) / elementSize.x,
|
|
67
|
+
containerSize.y / elementSize.y
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
yield elementRef().size({
|
|
71
|
+
x: containerSize.x,
|
|
72
|
+
y: containerSize.x / elementAspectRatio,
|
|
73
|
+
});
|
|
74
|
+
yield elementRef().scale(
|
|
75
|
+
containerSize.x / elementSize.x,
|
|
76
|
+
(containerSize.x * elementAspectRatio) / elementSize.y
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case OBJECT_FIT.FILL:
|
|
81
|
+
yield elementRef().size(containerSize);
|
|
82
|
+
yield elementRef().scale(
|
|
83
|
+
containerSize.x / elementSize.x,
|
|
84
|
+
containerSize.x / elementSize.y
|
|
85
|
+
);
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function* addTextEffect({
|
|
93
|
+
elementRef,
|
|
94
|
+
element,
|
|
95
|
+
}: {
|
|
96
|
+
elementRef: Reference<any>;
|
|
97
|
+
element: VisualizerElement;
|
|
98
|
+
}) {
|
|
99
|
+
yield elementRef();
|
|
100
|
+
if (element.textEffect) {
|
|
101
|
+
const effect = textEffectController.get(element.textEffect.name);
|
|
102
|
+
if (effect) {
|
|
103
|
+
yield* effect.run({
|
|
104
|
+
elementRef,
|
|
105
|
+
duration: element.e - element.s,
|
|
106
|
+
...element.textEffect,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function* addAnimation({
|
|
113
|
+
elementRef,
|
|
114
|
+
containerRef,
|
|
115
|
+
element,
|
|
116
|
+
view,
|
|
117
|
+
}: {
|
|
118
|
+
elementRef: Reference<any>;
|
|
119
|
+
containerRef?: Reference<any>;
|
|
120
|
+
element: VisualizerElement;
|
|
121
|
+
view: View2D;
|
|
122
|
+
}) {
|
|
123
|
+
yield elementRef();
|
|
124
|
+
if (element.animation) {
|
|
125
|
+
const animation = animationController.get(element.animation.name);
|
|
126
|
+
if (animation) {
|
|
127
|
+
yield* animation.run({
|
|
128
|
+
elementRef,
|
|
129
|
+
containerRef,
|
|
130
|
+
view,
|
|
131
|
+
duration: element.e - element.s,
|
|
132
|
+
...element.animation,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
export function* addFrameEffect({
|
|
140
|
+
containerRef,
|
|
141
|
+
elementRef,
|
|
142
|
+
element,
|
|
143
|
+
}: {
|
|
144
|
+
containerRef: Reference<any>;
|
|
145
|
+
elementRef: Reference<any>;
|
|
146
|
+
element: VisualizerElement;
|
|
147
|
+
}) {
|
|
148
|
+
let frameEffects = [];
|
|
149
|
+
const initProps = getFrameState({
|
|
150
|
+
containerRef,
|
|
151
|
+
elementRef,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
for (let i = 0; i < element?.frameEffects?.length; i++) {
|
|
155
|
+
const frameEffect = element.frameEffects[i];
|
|
156
|
+
const restore =
|
|
157
|
+
i === element.frameEffects.length - 1 ||
|
|
158
|
+
element.frameEffects[i + 1].s !== frameEffect.e;
|
|
159
|
+
const frameEffectPlugin = frameEffectController.get(frameEffect.name);
|
|
160
|
+
if (frameEffectPlugin) {
|
|
161
|
+
yield* frameEffectPlugin.run({
|
|
162
|
+
containerRef,
|
|
163
|
+
elementRef,
|
|
164
|
+
initFrameState: initProps,
|
|
165
|
+
frameEffect,
|
|
166
|
+
});
|
|
167
|
+
if (restore) {
|
|
168
|
+
yield* restoreFrameState({
|
|
169
|
+
containerRef,
|
|
170
|
+
elementRef,
|
|
171
|
+
duration: frameEffect.e - frameEffect.s,
|
|
172
|
+
element,
|
|
173
|
+
initProps,
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
// frameEffects.push(...sequence);
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// yield* all(...frameEffects);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getFrameState({
|
|
184
|
+
containerRef,
|
|
185
|
+
elementRef,
|
|
186
|
+
}: {
|
|
187
|
+
containerRef: Reference<any>;
|
|
188
|
+
elementRef: Reference<any>;
|
|
189
|
+
}): FrameState {
|
|
190
|
+
return {
|
|
191
|
+
frame: {
|
|
192
|
+
size: containerRef().size(),
|
|
193
|
+
pos: containerRef().position(),
|
|
194
|
+
radius: containerRef().radius(),
|
|
195
|
+
scale: containerRef().scale(),
|
|
196
|
+
rotation: containerRef().rotation(),
|
|
197
|
+
},
|
|
198
|
+
element: {
|
|
199
|
+
size: containerRef().size(),
|
|
200
|
+
pos: elementRef().position(),
|
|
201
|
+
scale: elementRef().scale(),
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function* restoreFrameState({
|
|
207
|
+
containerRef,
|
|
208
|
+
elementRef,
|
|
209
|
+
duration,
|
|
210
|
+
element,
|
|
211
|
+
initProps,
|
|
212
|
+
}: {
|
|
213
|
+
containerRef: Reference<any>;
|
|
214
|
+
elementRef: Reference<any>;
|
|
215
|
+
duration: number;
|
|
216
|
+
element: VisualizerElement;
|
|
217
|
+
initProps: FrameState;
|
|
218
|
+
}) {
|
|
219
|
+
yield* waitFor(duration);
|
|
220
|
+
logger(`restoreFrameState: ${JSON.stringify(initProps)}`);
|
|
221
|
+
let sequence = [];
|
|
222
|
+
sequence.push(containerRef().size(initProps.frame.size));
|
|
223
|
+
sequence.push(containerRef().position(initProps.frame.pos));
|
|
224
|
+
sequence.push(containerRef().scale(initProps.frame.scale));
|
|
225
|
+
sequence.push(containerRef().rotation(initProps.frame.rotation));
|
|
226
|
+
sequence.push(containerRef().radius(initProps.frame.radius));
|
|
227
|
+
sequence.push(elementRef().size(initProps.element.size));
|
|
228
|
+
sequence.push(elementRef().position(initProps.element.pos));
|
|
229
|
+
sequence.push(elementRef().scale(initProps.element.scale));
|
|
230
|
+
sequence.push(
|
|
231
|
+
fitElement({
|
|
232
|
+
elementRef,
|
|
233
|
+
containerSize: initProps.frame.size,
|
|
234
|
+
elementSize: initProps.element.size,
|
|
235
|
+
objectFit: element.objectFit ?? "none",
|
|
236
|
+
})
|
|
237
|
+
);
|
|
238
|
+
yield* all(...sequence);
|
|
239
|
+
}
|
package/src/helpers/filters.ts
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
import { Reference } from "@
|
|
2
|
-
import { COLOR_FILTERS } from "./constants";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Filter utilities for the visualizer package.
|
|
6
|
-
* Provides functions for applying various visual filters to elements.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Applies a blur filter to an element
|
|
11
|
-
* @param {Object} params - Parameters for the blur filter
|
|
12
|
-
* @param {Reference<any>} params.element - The element to apply the filter to
|
|
13
|
-
* @param {number} params.amount - The blur amount
|
|
14
|
-
* @returns {void}
|
|
15
|
-
*/
|
|
16
|
-
export function applyBlurFilter({ element, amount }: { element: Reference<any>; amount: number }) {
|
|
17
|
-
// ... existing code ...
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Applies a brightness filter to an element
|
|
22
|
-
* @param {Object} params - Parameters for the brightness filter
|
|
23
|
-
* @param {Reference<any>} params.element - The element to apply the filter to
|
|
24
|
-
* @param {number} params.amount - The brightness amount
|
|
25
|
-
* @returns {void}
|
|
26
|
-
*/
|
|
27
|
-
export function applyBrightnessFilter({ element, amount }: { element: Reference<any>; amount: number }) {
|
|
28
|
-
// ... existing code ...
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Applies a contrast filter to an element
|
|
33
|
-
* @param {Object} params - Parameters for the contrast filter
|
|
34
|
-
* @param {Reference<any>} params.element - The element to apply the filter to
|
|
35
|
-
* @param {number} params.amount - The contrast amount
|
|
36
|
-
* @returns {void}
|
|
37
|
-
*/
|
|
38
|
-
export function applyContrastFilter({ element, amount }: { element: Reference<any>; amount: number }) {
|
|
39
|
-
// ... existing code ...
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const applyColorFilter = (ref: Reference<any>, filterType: string) => {
|
|
43
|
-
switch (filterType) {
|
|
44
|
-
case COLOR_FILTERS.SATURATED:
|
|
45
|
-
ref().filters.saturate(1.4);
|
|
46
|
-
ref().filters.contrast(1.1);
|
|
47
|
-
break;
|
|
48
|
-
case COLOR_FILTERS.BRIGHT:
|
|
49
|
-
ref().filters.brightness(1.3);
|
|
50
|
-
ref().filters.contrast(1.05);
|
|
51
|
-
break;
|
|
52
|
-
case COLOR_FILTERS.VIBRANT:
|
|
53
|
-
ref().filters.saturate(1.6);
|
|
54
|
-
ref().filters.brightness(1.15);
|
|
55
|
-
ref().filters.contrast(1.1);
|
|
56
|
-
break;
|
|
57
|
-
case COLOR_FILTERS.RETRO:
|
|
58
|
-
ref().filters.sepia(0.8);
|
|
59
|
-
ref().filters.contrast(1.3);
|
|
60
|
-
ref().filters.brightness(0.85);
|
|
61
|
-
ref().filters.saturate(0.8);
|
|
62
|
-
break;
|
|
63
|
-
case COLOR_FILTERS.BLACK_WHITE:
|
|
64
|
-
ref().filters.grayscale(1);
|
|
65
|
-
ref().filters.contrast(1.25);
|
|
66
|
-
ref().filters.brightness(1.05);
|
|
67
|
-
break;
|
|
68
|
-
case COLOR_FILTERS.COOL:
|
|
69
|
-
ref().filters.hue(15);
|
|
70
|
-
ref().filters.brightness(1.1);
|
|
71
|
-
ref().filters.saturate(1.3);
|
|
72
|
-
ref().filters.contrast(1.05);
|
|
73
|
-
break;
|
|
74
|
-
case COLOR_FILTERS.WARM:
|
|
75
|
-
ref().filters.hue(-15);
|
|
76
|
-
ref().filters.brightness(1.15);
|
|
77
|
-
ref().filters.saturate(1.3);
|
|
78
|
-
ref().filters.contrast(1.05);
|
|
79
|
-
break;
|
|
80
|
-
case COLOR_FILTERS.CINEMATIC:
|
|
81
|
-
ref().filters.contrast(1.4);
|
|
82
|
-
ref().filters.brightness(0.95);
|
|
83
|
-
ref().filters.saturate(0.85);
|
|
84
|
-
ref().filters.sepia(0.2);
|
|
85
|
-
break;
|
|
86
|
-
case COLOR_FILTERS.SOFT_GLOW:
|
|
87
|
-
ref().filters.brightness(1.2);
|
|
88
|
-
ref().filters.contrast(0.95);
|
|
89
|
-
ref().filters.blur(1.2);
|
|
90
|
-
ref().filters.saturate(1.1);
|
|
91
|
-
break;
|
|
92
|
-
case COLOR_FILTERS.MOODY:
|
|
93
|
-
ref().filters.brightness(1.05);
|
|
94
|
-
ref().filters.contrast(1.4);
|
|
95
|
-
ref().filters.saturate(0.65);
|
|
96
|
-
ref().filters.sepia(0.2);
|
|
97
|
-
break;
|
|
98
|
-
case COLOR_FILTERS.DREAMY:
|
|
99
|
-
ref().filters.brightness(1.3);
|
|
100
|
-
ref().filters.blur(2);
|
|
101
|
-
ref().filters.saturate(1.4);
|
|
102
|
-
ref().filters.contrast(0.95);
|
|
103
|
-
break;
|
|
104
|
-
case COLOR_FILTERS.INVERTED:
|
|
105
|
-
ref().filters.invert(1);
|
|
106
|
-
ref().filters.hue(180);
|
|
107
|
-
break;
|
|
108
|
-
case COLOR_FILTERS.VINTAGE:
|
|
109
|
-
ref().filters.sepia(0.4);
|
|
110
|
-
ref().filters.saturate(1.4);
|
|
111
|
-
ref().filters.contrast(1.2);
|
|
112
|
-
ref().filters.brightness(1.1);
|
|
113
|
-
break;
|
|
114
|
-
case COLOR_FILTERS.DRAMATIC:
|
|
115
|
-
ref().filters.contrast(1.5);
|
|
116
|
-
ref().filters.brightness(0.9);
|
|
117
|
-
ref().filters.saturate(1.2);
|
|
118
|
-
break;
|
|
119
|
-
case COLOR_FILTERS.FADED:
|
|
120
|
-
ref().filters.opacity(0.9);
|
|
121
|
-
ref().filters.brightness(1.2);
|
|
122
|
-
ref().filters.saturate(0.8);
|
|
123
|
-
ref().filters.contrast(0.9);
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
1
|
+
import { Reference } from "@twick/core";
|
|
2
|
+
import { COLOR_FILTERS } from "./constants";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Filter utilities for the visualizer package.
|
|
6
|
+
* Provides functions for applying various visual filters to elements.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Applies a blur filter to an element
|
|
11
|
+
* @param {Object} params - Parameters for the blur filter
|
|
12
|
+
* @param {Reference<any>} params.element - The element to apply the filter to
|
|
13
|
+
* @param {number} params.amount - The blur amount
|
|
14
|
+
* @returns {void}
|
|
15
|
+
*/
|
|
16
|
+
export function applyBlurFilter({ element, amount }: { element: Reference<any>; amount: number }) {
|
|
17
|
+
// ... existing code ...
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Applies a brightness filter to an element
|
|
22
|
+
* @param {Object} params - Parameters for the brightness filter
|
|
23
|
+
* @param {Reference<any>} params.element - The element to apply the filter to
|
|
24
|
+
* @param {number} params.amount - The brightness amount
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
export function applyBrightnessFilter({ element, amount }: { element: Reference<any>; amount: number }) {
|
|
28
|
+
// ... existing code ...
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Applies a contrast filter to an element
|
|
33
|
+
* @param {Object} params - Parameters for the contrast filter
|
|
34
|
+
* @param {Reference<any>} params.element - The element to apply the filter to
|
|
35
|
+
* @param {number} params.amount - The contrast amount
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
export function applyContrastFilter({ element, amount }: { element: Reference<any>; amount: number }) {
|
|
39
|
+
// ... existing code ...
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const applyColorFilter = (ref: Reference<any>, filterType: string) => {
|
|
43
|
+
switch (filterType) {
|
|
44
|
+
case COLOR_FILTERS.SATURATED:
|
|
45
|
+
ref().filters.saturate(1.4);
|
|
46
|
+
ref().filters.contrast(1.1);
|
|
47
|
+
break;
|
|
48
|
+
case COLOR_FILTERS.BRIGHT:
|
|
49
|
+
ref().filters.brightness(1.3);
|
|
50
|
+
ref().filters.contrast(1.05);
|
|
51
|
+
break;
|
|
52
|
+
case COLOR_FILTERS.VIBRANT:
|
|
53
|
+
ref().filters.saturate(1.6);
|
|
54
|
+
ref().filters.brightness(1.15);
|
|
55
|
+
ref().filters.contrast(1.1);
|
|
56
|
+
break;
|
|
57
|
+
case COLOR_FILTERS.RETRO:
|
|
58
|
+
ref().filters.sepia(0.8);
|
|
59
|
+
ref().filters.contrast(1.3);
|
|
60
|
+
ref().filters.brightness(0.85);
|
|
61
|
+
ref().filters.saturate(0.8);
|
|
62
|
+
break;
|
|
63
|
+
case COLOR_FILTERS.BLACK_WHITE:
|
|
64
|
+
ref().filters.grayscale(1);
|
|
65
|
+
ref().filters.contrast(1.25);
|
|
66
|
+
ref().filters.brightness(1.05);
|
|
67
|
+
break;
|
|
68
|
+
case COLOR_FILTERS.COOL:
|
|
69
|
+
ref().filters.hue(15);
|
|
70
|
+
ref().filters.brightness(1.1);
|
|
71
|
+
ref().filters.saturate(1.3);
|
|
72
|
+
ref().filters.contrast(1.05);
|
|
73
|
+
break;
|
|
74
|
+
case COLOR_FILTERS.WARM:
|
|
75
|
+
ref().filters.hue(-15);
|
|
76
|
+
ref().filters.brightness(1.15);
|
|
77
|
+
ref().filters.saturate(1.3);
|
|
78
|
+
ref().filters.contrast(1.05);
|
|
79
|
+
break;
|
|
80
|
+
case COLOR_FILTERS.CINEMATIC:
|
|
81
|
+
ref().filters.contrast(1.4);
|
|
82
|
+
ref().filters.brightness(0.95);
|
|
83
|
+
ref().filters.saturate(0.85);
|
|
84
|
+
ref().filters.sepia(0.2);
|
|
85
|
+
break;
|
|
86
|
+
case COLOR_FILTERS.SOFT_GLOW:
|
|
87
|
+
ref().filters.brightness(1.2);
|
|
88
|
+
ref().filters.contrast(0.95);
|
|
89
|
+
ref().filters.blur(1.2);
|
|
90
|
+
ref().filters.saturate(1.1);
|
|
91
|
+
break;
|
|
92
|
+
case COLOR_FILTERS.MOODY:
|
|
93
|
+
ref().filters.brightness(1.05);
|
|
94
|
+
ref().filters.contrast(1.4);
|
|
95
|
+
ref().filters.saturate(0.65);
|
|
96
|
+
ref().filters.sepia(0.2);
|
|
97
|
+
break;
|
|
98
|
+
case COLOR_FILTERS.DREAMY:
|
|
99
|
+
ref().filters.brightness(1.3);
|
|
100
|
+
ref().filters.blur(2);
|
|
101
|
+
ref().filters.saturate(1.4);
|
|
102
|
+
ref().filters.contrast(0.95);
|
|
103
|
+
break;
|
|
104
|
+
case COLOR_FILTERS.INVERTED:
|
|
105
|
+
ref().filters.invert(1);
|
|
106
|
+
ref().filters.hue(180);
|
|
107
|
+
break;
|
|
108
|
+
case COLOR_FILTERS.VINTAGE:
|
|
109
|
+
ref().filters.sepia(0.4);
|
|
110
|
+
ref().filters.saturate(1.4);
|
|
111
|
+
ref().filters.contrast(1.2);
|
|
112
|
+
ref().filters.brightness(1.1);
|
|
113
|
+
break;
|
|
114
|
+
case COLOR_FILTERS.DRAMATIC:
|
|
115
|
+
ref().filters.contrast(1.5);
|
|
116
|
+
ref().filters.brightness(0.9);
|
|
117
|
+
ref().filters.saturate(1.2);
|
|
118
|
+
break;
|
|
119
|
+
case COLOR_FILTERS.FADED:
|
|
120
|
+
ref().filters.opacity(0.9);
|
|
121
|
+
ref().filters.brightness(1.2);
|
|
122
|
+
ref().filters.saturate(0.8);
|
|
123
|
+
ref().filters.contrast(0.9);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
128
|
};
|
package/src/helpers/log.utils.ts
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
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
|
-
|
|
30
|
-
export function errorLogger(message: string, error?: Error) {
|
|
31
|
-
console.error(`[Visualizer Error] ${message}`, error ? error : "");
|
|
32
|
-
}
|
|
1
|
+
import { format } from "date-fns";
|
|
2
|
+
|
|
3
|
+
const getCurrentTime = (dateFormat = "mm:ss:SSS") => {
|
|
4
|
+
const now = new Date();
|
|
5
|
+
return format(now, dateFormat);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Logging utilities for the visualizer package.
|
|
10
|
+
* Provides consistent logging functionality across the application.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Logs a message to the console with a visualizer prefix
|
|
15
|
+
* @param {string} message - The message to log
|
|
16
|
+
* @param {any} [data] - Optional data to log
|
|
17
|
+
*/
|
|
18
|
+
export function logger(message: string, data?: any) {
|
|
19
|
+
console.log(`[Visualizer] ${message}`, data ? data : "");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Logs an error to the console with a visualizer prefix
|
|
24
|
+
* @param {string} message - The error message to log
|
|
25
|
+
* @param {Error} [error] - Optional error object
|
|
26
|
+
*/
|
|
27
|
+
export function errorLogger(message: string, error?: Error) {
|
|
28
|
+
console.error(`[Visualizer Error] ${message}`, error ? error : "");
|
|
29
|
+
}
|