@twick/canvas 0.15.7 → 0.15.8
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/index.js +13 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -287,19 +287,21 @@ class VideoFrameExtractor {
|
|
|
287
287
|
/**
|
|
288
288
|
* Get a frame thumbnail from a video at a specific time.
|
|
289
289
|
* Uses caching and reuses video elements for optimal performance.
|
|
290
|
-
*
|
|
290
|
+
* Uses 0.1s instead of 0 when seekTime is 0, since frames at t=0 are often blank.
|
|
291
|
+
*
|
|
291
292
|
* @param videoUrl - The URL of the video
|
|
292
|
-
* @param seekTime - The time in seconds to extract the frame
|
|
293
|
+
* @param seekTime - The time in seconds to extract the frame (0 is treated as 0.1)
|
|
293
294
|
* @returns Promise resolving to a thumbnail image URL (data URL or blob URL)
|
|
294
295
|
*/
|
|
295
296
|
async getFrame(videoUrl, seekTime = 0.1) {
|
|
296
|
-
const
|
|
297
|
+
const effectiveSeekTime = seekTime === 0 ? 0.1 : seekTime;
|
|
298
|
+
const cacheKey = this.getCacheKey(videoUrl, effectiveSeekTime);
|
|
297
299
|
const cached = this.frameCache.get(cacheKey);
|
|
298
300
|
if (cached) {
|
|
299
301
|
return cached;
|
|
300
302
|
}
|
|
301
303
|
const videoState = await this.getVideoElement(videoUrl);
|
|
302
|
-
const thumbnail = await this.extractFrame(videoState.video,
|
|
304
|
+
const thumbnail = await this.extractFrame(videoState.video, effectiveSeekTime);
|
|
303
305
|
this.frameCache.set(cacheKey, thumbnail);
|
|
304
306
|
return thumbnail;
|
|
305
307
|
}
|
|
@@ -663,7 +665,6 @@ const setImageProps = ({
|
|
|
663
665
|
((_d = element.props) == null ? void 0 : _d.y) || 0,
|
|
664
666
|
canvasMetadata
|
|
665
667
|
);
|
|
666
|
-
console.log(width, height, x, y);
|
|
667
668
|
img.set("id", element.id);
|
|
668
669
|
img.set("zIndex", index);
|
|
669
670
|
img.set("width", width);
|
|
@@ -750,8 +751,7 @@ const addVideoElement = async ({
|
|
|
750
751
|
canvasMetadata,
|
|
751
752
|
currentFrameEffect
|
|
752
753
|
});
|
|
753
|
-
} catch
|
|
754
|
-
console.error("Error loading image:", error);
|
|
754
|
+
} catch {
|
|
755
755
|
}
|
|
756
756
|
};
|
|
757
757
|
const addImageElement = async ({
|
|
@@ -787,8 +787,7 @@ const addImageElement = async ({
|
|
|
787
787
|
canvas.add(img);
|
|
788
788
|
return img;
|
|
789
789
|
}
|
|
790
|
-
} catch
|
|
791
|
-
console.error("Error loading image:", error);
|
|
790
|
+
} catch {
|
|
792
791
|
}
|
|
793
792
|
};
|
|
794
793
|
const addMediaGroup = ({
|
|
@@ -1042,7 +1041,6 @@ const useTwickCanvas = ({
|
|
|
1042
1041
|
return;
|
|
1043
1042
|
}
|
|
1044
1043
|
if (twickCanvasRef.current) {
|
|
1045
|
-
console.log("Destroying twickCanvas");
|
|
1046
1044
|
twickCanvasRef.current.off("mouse:up", handleMouseUp);
|
|
1047
1045
|
twickCanvasRef.current.off("text:editing:exited", onTextEdit);
|
|
1048
1046
|
twickCanvasRef.current.dispose();
|
|
@@ -1245,10 +1243,7 @@ const useTwickCanvas = ({
|
|
|
1245
1243
|
captionProps,
|
|
1246
1244
|
cleanAndAdd = false
|
|
1247
1245
|
}) => {
|
|
1248
|
-
if (!twickCanvas || !getCanvasContext(twickCanvas))
|
|
1249
|
-
console.warn("Canvas not properly initialized");
|
|
1250
|
-
return;
|
|
1251
|
-
}
|
|
1246
|
+
if (!twickCanvas || !getCanvasContext(twickCanvas)) return;
|
|
1252
1247
|
try {
|
|
1253
1248
|
if (cleanAndAdd && getCanvasContext(twickCanvas)) {
|
|
1254
1249
|
const backgroundColor = twickCanvas.backgroundColor;
|
|
@@ -1262,10 +1257,7 @@ const useTwickCanvas = ({
|
|
|
1262
1257
|
await Promise.all(
|
|
1263
1258
|
elements.map(async (element, index) => {
|
|
1264
1259
|
try {
|
|
1265
|
-
if (!element)
|
|
1266
|
-
console.warn("Element not found");
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1260
|
+
if (!element) return;
|
|
1269
1261
|
await addElementToCanvas({
|
|
1270
1262
|
element,
|
|
1271
1263
|
index,
|
|
@@ -1273,14 +1265,12 @@ const useTwickCanvas = ({
|
|
|
1273
1265
|
seekTime,
|
|
1274
1266
|
captionProps
|
|
1275
1267
|
});
|
|
1276
|
-
} catch
|
|
1277
|
-
console.error(`Error adding element ${element.id}:`, error);
|
|
1268
|
+
} catch {
|
|
1278
1269
|
}
|
|
1279
1270
|
})
|
|
1280
1271
|
);
|
|
1281
1272
|
reorderElementsByZIndex(twickCanvas);
|
|
1282
|
-
} catch
|
|
1283
|
-
console.error("Error in setCanvasElements:", error);
|
|
1273
|
+
} catch {
|
|
1284
1274
|
}
|
|
1285
1275
|
};
|
|
1286
1276
|
const addElementToCanvas = async ({
|
|
@@ -1291,10 +1281,7 @@ const useTwickCanvas = ({
|
|
|
1291
1281
|
captionProps
|
|
1292
1282
|
}) => {
|
|
1293
1283
|
var _a, _b;
|
|
1294
|
-
if (!twickCanvas)
|
|
1295
|
-
console.warn("Canvas not initialized");
|
|
1296
|
-
return;
|
|
1297
|
-
}
|
|
1284
|
+
if (!twickCanvas) return;
|
|
1298
1285
|
switch (element.type) {
|
|
1299
1286
|
case ELEMENT_TYPES.VIDEO:
|
|
1300
1287
|
const currentFrameEffect = getCurrentFrameEffect(
|