@remotion/timeline-utils 4.0.530 → 4.0.532
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/dist/audio-waveform/draw-peaks.js +4 -1
- package/dist/esm/index.mjs +4 -1
- package/dist/image-thumbnail/draw-repeating-image-thumbnail.d.ts +10 -0
- package/dist/image-thumbnail/draw-repeating-image-thumbnail.js +48 -0
- package/dist/image-thumbnail/get-scaled-image-thumbnail-dimensions.d.ts +8 -0
- package/dist/image-thumbnail/get-scaled-image-thumbnail-dimensions.js +17 -0
- package/package.json +3 -3
|
@@ -4,6 +4,7 @@ exports.drawBars = void 0;
|
|
|
4
4
|
const parse_color_1 = require("./parse-color");
|
|
5
5
|
const CLIPPING_COLOR = '#FF7F50';
|
|
6
6
|
const WAVEFORM_HEIGHT_SCALE = 0.8;
|
|
7
|
+
const MIN_VISIBLE_DECIBELS = -37;
|
|
7
8
|
const getVolumeAtBar = ({ barIndex, numBars, volume, }) => {
|
|
8
9
|
var _a;
|
|
9
10
|
if (typeof volume === 'number') {
|
|
@@ -47,7 +48,9 @@ const drawBars = ({ canvas, color, peaks, volume, width, horizontalOffset, }) =>
|
|
|
47
48
|
const peak = peaks[peakIndex] || 0;
|
|
48
49
|
const barVolume = getVolumeAtBar({ barIndex, numBars, volume });
|
|
49
50
|
const scaledPeak = peak * barVolume;
|
|
50
|
-
const
|
|
51
|
+
const decibelPeak = scaledPeak <= 0 ? MIN_VISIBLE_DECIBELS : 20 * Math.log10(scaledPeak);
|
|
52
|
+
const visualPeak = Math.max(0, (decibelPeak - MIN_VISIBLE_DECIBELS) / -MIN_VISIBLE_DECIBELS);
|
|
53
|
+
const halfBar = Math.max(0, Math.min(height / 2, visualPeak * fullScaleHalfBar));
|
|
51
54
|
if (halfBar === 0)
|
|
52
55
|
continue;
|
|
53
56
|
const mid = height / 2;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -18,6 +18,7 @@ var parseColor = (color) => {
|
|
|
18
18
|
// src/audio-waveform/draw-peaks.ts
|
|
19
19
|
var CLIPPING_COLOR = "#FF7F50";
|
|
20
20
|
var WAVEFORM_HEIGHT_SCALE = 0.8;
|
|
21
|
+
var MIN_VISIBLE_DECIBELS = -37;
|
|
21
22
|
var getVolumeAtBar = ({
|
|
22
23
|
barIndex,
|
|
23
24
|
numBars,
|
|
@@ -65,7 +66,9 @@ var drawBars = ({
|
|
|
65
66
|
const peak = peaks[peakIndex] || 0;
|
|
66
67
|
const barVolume = getVolumeAtBar({ barIndex, numBars, volume });
|
|
67
68
|
const scaledPeak = peak * barVolume;
|
|
68
|
-
const
|
|
69
|
+
const decibelPeak = scaledPeak <= 0 ? MIN_VISIBLE_DECIBELS : 20 * Math.log10(scaledPeak);
|
|
70
|
+
const visualPeak = Math.max(0, (decibelPeak - MIN_VISIBLE_DECIBELS) / -MIN_VISIBLE_DECIBELS);
|
|
71
|
+
const halfBar = Math.max(0, Math.min(height / 2, visualPeak * fullScaleHalfBar));
|
|
69
72
|
if (halfBar === 0)
|
|
70
73
|
continue;
|
|
71
74
|
const mid = height / 2;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type ImageWithNaturalDimensions = CanvasImageSource & {
|
|
2
|
+
readonly naturalWidth: number;
|
|
3
|
+
readonly naturalHeight: number;
|
|
4
|
+
};
|
|
5
|
+
export declare const drawRepeatingImageThumbnail: ({ canvas, image, offsetInPixels, }: {
|
|
6
|
+
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
7
|
+
readonly image: ImageWithNaturalDimensions;
|
|
8
|
+
readonly offsetInPixels?: number | undefined;
|
|
9
|
+
}) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.drawRepeatingImageThumbnail = void 0;
|
|
4
|
+
const get_scaled_image_thumbnail_dimensions_1 = require("./get-scaled-image-thumbnail-dimensions");
|
|
5
|
+
const createOffscreenCanvas = (width, height) => {
|
|
6
|
+
if (typeof document !== 'undefined') {
|
|
7
|
+
const canvas = document.createElement('canvas');
|
|
8
|
+
canvas.width = width;
|
|
9
|
+
canvas.height = height;
|
|
10
|
+
return canvas;
|
|
11
|
+
}
|
|
12
|
+
if (typeof OffscreenCanvas !== 'undefined') {
|
|
13
|
+
return new OffscreenCanvas(width, height);
|
|
14
|
+
}
|
|
15
|
+
throw new Error('No canvas implementation available');
|
|
16
|
+
};
|
|
17
|
+
const drawRepeatingImageThumbnail = ({ canvas, image, offsetInPixels = 0, }) => {
|
|
18
|
+
const ctx = canvas.getContext('2d');
|
|
19
|
+
if (!ctx) {
|
|
20
|
+
throw new Error('Failed to get canvas context');
|
|
21
|
+
}
|
|
22
|
+
const { width, height } = canvas;
|
|
23
|
+
if (width === 0 || height === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { scaledWidth, scaledHeight } = (0, get_scaled_image_thumbnail_dimensions_1.getScaledImageThumbnailDimensions)({
|
|
27
|
+
naturalWidth: image.naturalWidth,
|
|
28
|
+
naturalHeight: image.naturalHeight,
|
|
29
|
+
canvasHeight: height,
|
|
30
|
+
});
|
|
31
|
+
if (scaledWidth === 0 || scaledHeight === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const offscreen = createOffscreenCanvas(scaledWidth, scaledHeight);
|
|
35
|
+
const offCtx = offscreen.getContext('2d');
|
|
36
|
+
if (!offCtx) {
|
|
37
|
+
throw new Error('Failed to get offscreen canvas context');
|
|
38
|
+
}
|
|
39
|
+
offCtx.drawImage(image, 0, 0, scaledWidth, scaledHeight);
|
|
40
|
+
const pattern = ctx.createPattern(offscreen, 'repeat-x');
|
|
41
|
+
if (!pattern) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
pattern.setTransform(new DOMMatrix().translate(-offsetInPixels, 0));
|
|
45
|
+
ctx.fillStyle = pattern;
|
|
46
|
+
ctx.fillRect(0, 0, width, height);
|
|
47
|
+
};
|
|
48
|
+
exports.drawRepeatingImageThumbnail = drawRepeatingImageThumbnail;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const getScaledImageThumbnailDimensions: ({ naturalWidth, naturalHeight, canvasHeight, }: {
|
|
2
|
+
readonly naturalWidth: number;
|
|
3
|
+
readonly naturalHeight: number;
|
|
4
|
+
readonly canvasHeight: number;
|
|
5
|
+
}) => {
|
|
6
|
+
scaledWidth: number;
|
|
7
|
+
scaledHeight: number;
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScaledImageThumbnailDimensions = void 0;
|
|
4
|
+
const getScaledImageThumbnailDimensions = ({ naturalWidth, naturalHeight, canvasHeight, }) => {
|
|
5
|
+
if (naturalWidth === 0 || naturalHeight === 0 || canvasHeight === 0) {
|
|
6
|
+
return {
|
|
7
|
+
scaledWidth: 0,
|
|
8
|
+
scaledHeight: 0,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const scale = canvasHeight / naturalHeight;
|
|
12
|
+
return {
|
|
13
|
+
scaledWidth: naturalWidth * scale,
|
|
14
|
+
scaledHeight: canvasHeight,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.getScaledImageThumbnailDimensions = getScaledImageThumbnailDimensions;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/timeline-utils"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/timeline-utils",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.532",
|
|
7
7
|
"description": "Internal utilities for rendering Remotion timelines",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"scripts": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"mediabunny": "1.56.1",
|
|
25
|
-
"remotion": "4.0.
|
|
25
|
+
"remotion": "4.0.532"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@mediabunny/server": "1.56.1",
|
|
29
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
29
|
+
"@remotion/eslint-config-internal": "4.0.532",
|
|
30
30
|
"eslint": "9.19.0",
|
|
31
31
|
"@typescript/native-preview": "7.0.0-dev.20260217.1"
|
|
32
32
|
},
|