@starrykit/slides-editor 0.1.28 → 0.1.30
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 +47 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11010,7 +11010,7 @@ async function renderSlideThumbnail(slide) {
|
|
|
11010
11010
|
if (!root) {
|
|
11011
11011
|
throw new Error("Slide root not found while rendering thumbnail.");
|
|
11012
11012
|
}
|
|
11013
|
-
const renderTarget = doc.body ?? root;
|
|
11013
|
+
const renderTarget = createThumbnailRenderTarget(doc, doc.body ?? root, slide);
|
|
11014
11014
|
return await renderThumbnailPng(doc, renderTarget, slide);
|
|
11015
11015
|
} finally {
|
|
11016
11016
|
iframe.remove();
|
|
@@ -11034,11 +11034,14 @@ async function waitForImages(doc) {
|
|
|
11034
11034
|
]);
|
|
11035
11035
|
}
|
|
11036
11036
|
async function renderThumbnailPng(doc, renderTarget, slide) {
|
|
11037
|
+
const thumbnailSize = getThumbnailSize(slide);
|
|
11037
11038
|
const options = {
|
|
11038
11039
|
cacheBust: true,
|
|
11039
11040
|
pixelRatio: THUMBNAIL_PIXEL_RATIO,
|
|
11040
|
-
|
|
11041
|
-
|
|
11041
|
+
width: thumbnailSize.width,
|
|
11042
|
+
height: thumbnailSize.height,
|
|
11043
|
+
canvasWidth: thumbnailSize.width,
|
|
11044
|
+
canvasHeight: thumbnailSize.height,
|
|
11042
11045
|
skipFonts: false
|
|
11043
11046
|
};
|
|
11044
11047
|
try {
|
|
@@ -11048,6 +11051,47 @@ async function renderThumbnailPng(doc, renderTarget, slide) {
|
|
|
11048
11051
|
return await toPng(renderTarget, options);
|
|
11049
11052
|
}
|
|
11050
11053
|
}
|
|
11054
|
+
function getThumbnailSize(slide) {
|
|
11055
|
+
return {
|
|
11056
|
+
width: THUMBNAIL_DISPLAY_WIDTH,
|
|
11057
|
+
height: Math.round(slide.height / slide.width * THUMBNAIL_DISPLAY_WIDTH)
|
|
11058
|
+
};
|
|
11059
|
+
}
|
|
11060
|
+
function createThumbnailRenderTarget(doc, root, slide) {
|
|
11061
|
+
const thumbnailSize = getThumbnailSize(slide);
|
|
11062
|
+
const scale = Math.min(thumbnailSize.width / slide.width, thumbnailSize.height / slide.height);
|
|
11063
|
+
const scaledRoot = cloneSlideRoot(root);
|
|
11064
|
+
const frame = doc.createElement("div");
|
|
11065
|
+
const rootStyle = doc.defaultView?.getComputedStyle(root);
|
|
11066
|
+
const rootBackground = rootStyle?.background;
|
|
11067
|
+
frame.style.width = `${thumbnailSize.width}px`;
|
|
11068
|
+
frame.style.height = `${thumbnailSize.height}px`;
|
|
11069
|
+
frame.style.position = "relative";
|
|
11070
|
+
frame.style.overflow = "hidden";
|
|
11071
|
+
frame.style.margin = "0";
|
|
11072
|
+
frame.style.padding = "0";
|
|
11073
|
+
frame.style.boxSizing = "border-box";
|
|
11074
|
+
if (rootBackground && rootBackground !== "rgba(0, 0, 0, 0)" && rootBackground !== "transparent") {
|
|
11075
|
+
frame.style.background = rootBackground;
|
|
11076
|
+
}
|
|
11077
|
+
scaledRoot.style.width = `${slide.width}px`;
|
|
11078
|
+
scaledRoot.style.height = `${slide.height}px`;
|
|
11079
|
+
scaledRoot.style.position = "absolute";
|
|
11080
|
+
scaledRoot.style.left = "0";
|
|
11081
|
+
scaledRoot.style.top = "0";
|
|
11082
|
+
scaledRoot.style.margin = "0";
|
|
11083
|
+
scaledRoot.style.maxWidth = "none";
|
|
11084
|
+
scaledRoot.style.maxHeight = "none";
|
|
11085
|
+
scaledRoot.style.boxSizing = "border-box";
|
|
11086
|
+
scaledRoot.style.transform = `scale(${scale})`;
|
|
11087
|
+
scaledRoot.style.transformOrigin = "top left";
|
|
11088
|
+
frame.appendChild(scaledRoot);
|
|
11089
|
+
doc.body.appendChild(frame);
|
|
11090
|
+
return frame;
|
|
11091
|
+
}
|
|
11092
|
+
function cloneSlideRoot(root) {
|
|
11093
|
+
return root.cloneNode(true);
|
|
11094
|
+
}
|
|
11051
11095
|
function removeBrokenImages(doc) {
|
|
11052
11096
|
for (const image of Array.from(doc.images)) {
|
|
11053
11097
|
if (image.complete && image.naturalWidth > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starrykit/slides-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "Embeddable React editor UI for Starry Slides — host-driven through props and callbacks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/StarryKit/starry-slides#readme",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"build": "tsc -p tsconfig.json && tsup src/index.tsx --format esm --external react --external react-dom"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@starrykit/slides-core": "0.1.
|
|
33
|
+
"@starrykit/slides-core": "0.1.30",
|
|
34
34
|
"class-variance-authority": "^0.7.1",
|
|
35
35
|
"clsx": "^2.1.1",
|
|
36
36
|
"html-to-image": "^1.11.11",
|