Upload public.js
Browse files- backend/src/routes/public.js +299 -122
backend/src/routes/public.js
CHANGED
|
@@ -19,11 +19,34 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
|
|
| 19 |
const slide = pptData.slides[slideIndex];
|
| 20 |
const theme = pptData.theme || {};
|
| 21 |
|
| 22 |
-
//
|
| 23 |
const calculatePptDimensions = (slide) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if (!slide.elements || slide.elements.length === 0) {
|
| 25 |
-
// 如果没有元素,使用标准PPT
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
let maxRight = 0;
|
|
@@ -31,13 +54,13 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
|
|
| 31 |
let minLeft = Infinity;
|
| 32 |
let minTop = Infinity;
|
| 33 |
|
|
|
|
| 34 |
slide.elements.forEach(element => {
|
| 35 |
const left = element.left || 0;
|
| 36 |
const top = element.top || 0;
|
| 37 |
const width = element.width || 0;
|
| 38 |
const height = element.height || 0;
|
| 39 |
|
| 40 |
-
// 计算元素的边界
|
| 41 |
const elementRight = left + width;
|
| 42 |
const elementBottom = top + height;
|
| 43 |
|
|
@@ -47,34 +70,28 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
|
|
| 47 |
minTop = Math.min(minTop, top);
|
| 48 |
});
|
| 49 |
|
| 50 |
-
//
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
const contentHeight = maxBottom - Math.max(0, minTop);
|
| 54 |
|
| 55 |
-
//
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
//
|
| 60 |
-
const
|
| 61 |
-
const
|
| 62 |
-
const maxRatio = 16/9; // 1.78
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
} else if (aspectRatio > maxRatio) {
|
| 68 |
-
// 太宽了,调整高度
|
| 69 |
-
finalHeight = finalWidth / maxRatio;
|
| 70 |
-
}
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
};
|
| 76 |
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
return result;
|
| 80 |
};
|
|
@@ -138,165 +155,325 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
|
|
| 138 |
<html lang="zh-CN">
|
| 139 |
<head>
|
| 140 |
<meta charset="UTF-8">
|
| 141 |
-
<meta name="viewport" content="width=${pptDimensions.width}, height=${pptDimensions.height}, initial-scale=1.0, user-scalable=no">
|
| 142 |
<title>${title} - 第${slideIndex + 1}页</title>
|
| 143 |
<style>
|
|
|
|
| 144 |
* {
|
| 145 |
margin: 0 !important;
|
| 146 |
padding: 0 !important;
|
| 147 |
box-sizing: border-box !important;
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
|
|
|
|
| 150 |
html {
|
| 151 |
-
width:
|
| 152 |
-
height:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
overflow: hidden !important;
|
| 154 |
-
background
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
}
|
| 156 |
|
|
|
|
| 157 |
body {
|
| 158 |
-
width:
|
| 159 |
-
height:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
overflow: hidden !important;
|
| 161 |
font-family: 'Microsoft YaHei', Arial, sans-serif !important;
|
| 162 |
-
background
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
}
|
| 167 |
|
|
|
|
| 168 |
.slide-container {
|
| 169 |
width: ${pptDimensions.width}px !important;
|
| 170 |
height: ${pptDimensions.height}px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
background-color: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
|
| 172 |
-
position:
|
|
|
|
|
|
|
| 173 |
overflow: hidden !important;
|
| 174 |
-
|
| 175 |
-
transform-origin:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
}
|
| 177 |
|
|
|
|
| 178 |
${slide.background?.type === 'image' ? `
|
| 179 |
.slide-container::before {
|
| 180 |
content: '';
|
| 181 |
-
position: absolute;
|
| 182 |
-
top: 0;
|
| 183 |
-
left: 0;
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
background-image: url('${slide.background.image}');
|
| 187 |
-
background-size: ${slide.background.imageSize || 'cover'};
|
| 188 |
-
background-position: center;
|
| 189 |
-
background-repeat: no-repeat;
|
| 190 |
-
z-index: 0;
|
| 191 |
}
|
| 192 |
` : ''}
|
| 193 |
|
| 194 |
-
/*
|
| 195 |
-
::-webkit-scrollbar
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
}
|
| 198 |
|
| 199 |
-
/*
|
| 200 |
-
|
| 201 |
-
|
| 202 |
}
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
}
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
box-shadow: none !important;
|
| 217 |
}
|
| 218 |
</style>
|
| 219 |
<script>
|
| 220 |
-
//
|
| 221 |
window.PPT_DIMENSIONS = {
|
| 222 |
width: ${pptDimensions.width},
|
| 223 |
height: ${pptDimensions.height}
|
| 224 |
};
|
| 225 |
|
| 226 |
-
//
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
</script>
|
| 229 |
</head>
|
| 230 |
-
<body
|
| 231 |
<div class="slide-container" id="slideContainer">
|
| 232 |
${renderElements(slide.elements)}
|
| 233 |
</div>
|
| 234 |
|
| 235 |
<script>
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
console.log('截图模式:', window.SCREENSHOT_MODE);
|
| 239 |
-
|
| 240 |
-
// 根据模式应用不同的样式和行为
|
| 241 |
-
if (window.SCREENSHOT_MODE) {
|
| 242 |
-
// 截图模式:固定尺寸,无缩放
|
| 243 |
-
document.documentElement.classList.add('screenshot-mode');
|
| 244 |
-
document.body.style.cssText = \`
|
| 245 |
-
width: ${pptDimensions.width}px !important;
|
| 246 |
-
height: ${pptDimensions.height}px !important;
|
| 247 |
-
background: transparent !important;
|
| 248 |
-
overflow: hidden !important;
|
| 249 |
-
margin: 0 !important;
|
| 250 |
-
padding: 0 !important;
|
| 251 |
-
display: block !important;
|
| 252 |
-
\`;
|
| 253 |
-
|
| 254 |
const container = document.getElementById('slideContainer');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
if (container) {
|
| 256 |
container.style.cssText = \`
|
| 257 |
-
width:
|
| 258 |
-
height:
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
top: 0 !important;
|
| 261 |
left: 0 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
transform: none !important;
|
| 263 |
box-shadow: none !important;
|
| 264 |
-
|
|
|
|
| 265 |
\`;
|
| 266 |
}
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
const slideHeight = window.PPT_DIMENSIONS.height;
|
| 275 |
-
|
| 276 |
-
// 窗口尺寸
|
| 277 |
-
const windowWidth = window.innerWidth;
|
| 278 |
-
const windowHeight = window.innerHeight;
|
| 279 |
-
|
| 280 |
-
// 计算缩放比例,保持宽高比
|
| 281 |
-
const scaleX = (windowWidth - 40) / slideWidth; // 留20px边距
|
| 282 |
-
const scaleY = (windowHeight - 40) / slideHeight;
|
| 283 |
-
const scale = Math.min(scaleX, scaleY, 1); // 最大不超过1倍
|
| 284 |
-
|
| 285 |
-
// 应用缩放
|
| 286 |
-
container.style.transform = \`scale(\${scale})\`;
|
| 287 |
-
|
| 288 |
-
console.log(\`响应式缩放应用: \${scale.toFixed(3)}x (窗口: \${windowWidth}x\${windowHeight}, PPT: \${slideWidth}x\${slideHeight})\`);
|
| 289 |
-
}
|
| 290 |
|
| 291 |
-
//
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
-
//
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
-
//
|
| 298 |
-
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
</script>
|
| 301 |
</body>
|
| 302 |
</html>
|
|
|
|
| 19 |
const slide = pptData.slides[slideIndex];
|
| 20 |
const theme = pptData.theme || {};
|
| 21 |
|
| 22 |
+
// 精确计算PPT内容的真实尺寸 - 优先使用预设尺寸,然后基于元素计算
|
| 23 |
const calculatePptDimensions = (slide) => {
|
| 24 |
+
// 1. 优先使用PPT数据中的预设尺寸
|
| 25 |
+
if (pptData.slideSize && pptData.slideSize.width && pptData.slideSize.height) {
|
| 26 |
+
const result = {
|
| 27 |
+
width: Math.ceil(pptData.slideSize.width),
|
| 28 |
+
height: Math.ceil(pptData.slideSize.height)
|
| 29 |
+
};
|
| 30 |
+
console.log(`使用PPT预设尺寸: ${result.width}x${result.height}`);
|
| 31 |
+
return result;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// 2. 使用slide级别的尺寸设置
|
| 35 |
+
if (slide.width && slide.height) {
|
| 36 |
+
const result = {
|
| 37 |
+
width: Math.ceil(slide.width),
|
| 38 |
+
height: Math.ceil(slide.height)
|
| 39 |
+
};
|
| 40 |
+
console.log(`使用slide尺寸: ${result.width}x${result.height}`);
|
| 41 |
+
return result;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// 3. 根据元素分布计算合适的尺寸
|
| 45 |
if (!slide.elements || slide.elements.length === 0) {
|
| 46 |
+
// 如果没有元素,使用标准PPT尺寸
|
| 47 |
+
const result = { width: 960, height: 720 }; // 4:3标准比例
|
| 48 |
+
console.log(`使用默认尺寸: ${result.width}x${result.height}`);
|
| 49 |
+
return result;
|
| 50 |
}
|
| 51 |
|
| 52 |
let maxRight = 0;
|
|
|
|
| 54 |
let minLeft = Infinity;
|
| 55 |
let minTop = Infinity;
|
| 56 |
|
| 57 |
+
// 计算所有元素的实际边界
|
| 58 |
slide.elements.forEach(element => {
|
| 59 |
const left = element.left || 0;
|
| 60 |
const top = element.top || 0;
|
| 61 |
const width = element.width || 0;
|
| 62 |
const height = element.height || 0;
|
| 63 |
|
|
|
|
| 64 |
const elementRight = left + width;
|
| 65 |
const elementBottom = top + height;
|
| 66 |
|
|
|
|
| 70 |
minTop = Math.min(minTop, top);
|
| 71 |
});
|
| 72 |
|
| 73 |
+
// 重置无限值
|
| 74 |
+
if (minLeft === Infinity) minLeft = 0;
|
| 75 |
+
if (minTop === Infinity) minTop = 0;
|
|
|
|
| 76 |
|
| 77 |
+
// 计算内容区域的实际尺寸
|
| 78 |
+
const contentWidth = maxRight - minLeft;
|
| 79 |
+
const contentHeight = maxBottom - minTop;
|
| 80 |
|
| 81 |
+
// 添加适当的边距,确保内容不被裁切
|
| 82 |
+
const paddingX = Math.max(40, Math.abs(minLeft));
|
| 83 |
+
const paddingY = Math.max(40, Math.abs(minTop));
|
|
|
|
| 84 |
|
| 85 |
+
// 计算最终的PPT尺寸
|
| 86 |
+
let finalWidth = Math.max(contentWidth + paddingX * 2, 800);
|
| 87 |
+
let finalHeight = Math.max(contentHeight + paddingY * 2, 600);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
// 确保尺寸为偶数(避免半像素问题)
|
| 90 |
+
finalWidth = Math.ceil(finalWidth / 2) * 2;
|
| 91 |
+
finalHeight = Math.ceil(finalHeight / 2) * 2;
|
|
|
|
| 92 |
|
| 93 |
+
const result = { width: finalWidth, height: finalHeight };
|
| 94 |
+
console.log(`根据元素计算尺寸: ${result.width}x${result.height}`);
|
| 95 |
|
| 96 |
return result;
|
| 97 |
};
|
|
|
|
| 155 |
<html lang="zh-CN">
|
| 156 |
<head>
|
| 157 |
<meta charset="UTF-8">
|
| 158 |
+
<meta name="viewport" content="width=${pptDimensions.width}, height=${pptDimensions.height}, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
| 159 |
<title>${title} - 第${slideIndex + 1}页</title>
|
| 160 |
<style>
|
| 161 |
+
/* 全局重置 - 完全消除所有边距和填充 */
|
| 162 |
* {
|
| 163 |
margin: 0 !important;
|
| 164 |
padding: 0 !important;
|
| 165 |
box-sizing: border-box !important;
|
| 166 |
+
border: none !important;
|
| 167 |
+
outline: none !important;
|
| 168 |
}
|
| 169 |
|
| 170 |
+
/* HTML根元素 - 严格设置为PPT精确尺寸 */
|
| 171 |
html {
|
| 172 |
+
width: ${pptDimensions.width}px !important;
|
| 173 |
+
height: ${pptDimensions.height}px !important;
|
| 174 |
+
min-width: ${pptDimensions.width}px !important;
|
| 175 |
+
min-height: ${pptDimensions.height}px !important;
|
| 176 |
+
max-width: ${pptDimensions.width}px !important;
|
| 177 |
+
max-height: ${pptDimensions.height}px !important;
|
| 178 |
overflow: hidden !important;
|
| 179 |
+
background: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
|
| 180 |
+
position: fixed !important;
|
| 181 |
+
top: 0 !important;
|
| 182 |
+
left: 0 !important;
|
| 183 |
+
margin: 0 !important;
|
| 184 |
+
padding: 0 !important;
|
| 185 |
+
border: none !important;
|
| 186 |
+
outline: none !important;
|
| 187 |
}
|
| 188 |
|
| 189 |
+
/* Body元素 - 严格设置为PPT精确尺寸 */
|
| 190 |
body {
|
| 191 |
+
width: ${pptDimensions.width}px !important;
|
| 192 |
+
height: ${pptDimensions.height}px !important;
|
| 193 |
+
min-width: ${pptDimensions.width}px !important;
|
| 194 |
+
min-height: ${pptDimensions.height}px !important;
|
| 195 |
+
max-width: ${pptDimensions.width}px !important;
|
| 196 |
+
max-height: ${pptDimensions.height}px !important;
|
| 197 |
overflow: hidden !important;
|
| 198 |
font-family: 'Microsoft YaHei', Arial, sans-serif !important;
|
| 199 |
+
background: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
|
| 200 |
+
position: fixed !important;
|
| 201 |
+
top: 0 !important;
|
| 202 |
+
left: 0 !important;
|
| 203 |
+
margin: 0 !important;
|
| 204 |
+
padding: 0 !important;
|
| 205 |
+
border: none !important;
|
| 206 |
+
outline: none !important;
|
| 207 |
}
|
| 208 |
|
| 209 |
+
/* PPT容器 - 严格设置为PPT精确尺寸,完全填充 */
|
| 210 |
.slide-container {
|
| 211 |
width: ${pptDimensions.width}px !important;
|
| 212 |
height: ${pptDimensions.height}px !important;
|
| 213 |
+
min-width: ${pptDimensions.width}px !important;
|
| 214 |
+
min-height: ${pptDimensions.height}px !important;
|
| 215 |
+
max-width: ${pptDimensions.width}px !important;
|
| 216 |
+
max-height: ${pptDimensions.height}px !important;
|
| 217 |
background-color: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
|
| 218 |
+
position: fixed !important;
|
| 219 |
+
top: 0 !important;
|
| 220 |
+
left: 0 !important;
|
| 221 |
overflow: hidden !important;
|
| 222 |
+
transform: none !important;
|
| 223 |
+
transform-origin: top left !important;
|
| 224 |
+
margin: 0 !important;
|
| 225 |
+
padding: 0 !important;
|
| 226 |
+
border: none !important;
|
| 227 |
+
outline: none !important;
|
| 228 |
+
z-index: 1 !important;
|
| 229 |
}
|
| 230 |
|
| 231 |
+
/* 背景图片处理 */
|
| 232 |
${slide.background?.type === 'image' ? `
|
| 233 |
.slide-container::before {
|
| 234 |
content: '';
|
| 235 |
+
position: absolute !important;
|
| 236 |
+
top: 0 !important;
|
| 237 |
+
left: 0 !important;
|
| 238 |
+
width: ${pptDimensions.width}px !important;
|
| 239 |
+
height: ${pptDimensions.height}px !important;
|
| 240 |
+
background-image: url('${slide.background.image}') !important;
|
| 241 |
+
background-size: ${slide.background.imageSize || 'cover'} !important;
|
| 242 |
+
background-position: center !important;
|
| 243 |
+
background-repeat: no-repeat !important;
|
| 244 |
+
z-index: 0 !important;
|
| 245 |
}
|
| 246 |
` : ''}
|
| 247 |
|
| 248 |
+
/* 隐藏所有滚动条 */
|
| 249 |
+
html::-webkit-scrollbar,
|
| 250 |
+
body::-webkit-scrollbar,
|
| 251 |
+
*::-webkit-scrollbar {
|
| 252 |
+
display: none !important;
|
| 253 |
+
width: 0 !important;
|
| 254 |
+
height: 0 !important;
|
| 255 |
}
|
| 256 |
|
| 257 |
+
/* Firefox滚动条隐藏 */
|
| 258 |
+
html {
|
| 259 |
+
scrollbar-width: none !important;
|
| 260 |
}
|
| 261 |
|
| 262 |
+
/* 禁用文本选择和拖拽 */
|
| 263 |
+
* {
|
| 264 |
+
-webkit-user-select: none !important;
|
| 265 |
+
-moz-user-select: none !important;
|
| 266 |
+
-ms-user-select: none !important;
|
| 267 |
+
user-select: none !important;
|
| 268 |
+
-webkit-user-drag: none !important;
|
| 269 |
+
-khtml-user-drag: none !important;
|
| 270 |
+
-moz-user-drag: none !important;
|
| 271 |
+
-o-user-drag: none !important;
|
| 272 |
+
user-drag: none !important;
|
| 273 |
}
|
| 274 |
|
| 275 |
+
/* 禁用所有可能的缩放和调整 */
|
| 276 |
+
body {
|
| 277 |
+
zoom: 1 !important;
|
| 278 |
+
-webkit-text-size-adjust: 100% !important;
|
| 279 |
+
-ms-text-size-adjust: 100% !important;
|
|
|
|
| 280 |
}
|
| 281 |
</style>
|
| 282 |
<script>
|
| 283 |
+
// PPT尺寸信息 - 用于截图服务和JavaScript处理
|
| 284 |
window.PPT_DIMENSIONS = {
|
| 285 |
width: ${pptDimensions.width},
|
| 286 |
height: ${pptDimensions.height}
|
| 287 |
};
|
| 288 |
|
| 289 |
+
// 强制设置viewport尺寸
|
| 290 |
+
const viewportMeta = document.querySelector('meta[name="viewport"]');
|
| 291 |
+
if (viewportMeta) {
|
| 292 |
+
viewportMeta.setAttribute('content', \`width=\${window.PPT_DIMENSIONS.width}, height=\${window.PPT_DIMENSIONS.height}, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover\`);
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
console.log('PPT页面初始化 - 固定尺寸模式:', {
|
| 296 |
+
dimensions: window.PPT_DIMENSIONS,
|
| 297 |
+
userAgent: navigator.userAgent
|
| 298 |
+
});
|
| 299 |
</script>
|
| 300 |
</head>
|
| 301 |
+
<body>
|
| 302 |
<div class="slide-container" id="slideContainer">
|
| 303 |
${renderElements(slide.elements)}
|
| 304 |
</div>
|
| 305 |
|
| 306 |
<script>
|
| 307 |
+
// 页面加载完成后的初始化 - 确保完全精确的尺寸
|
| 308 |
+
window.addEventListener('load', function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
const container = document.getElementById('slideContainer');
|
| 310 |
+
const html = document.documentElement;
|
| 311 |
+
const body = document.body;
|
| 312 |
+
|
| 313 |
+
// 强制设置精确尺寸
|
| 314 |
+
const exactWidth = ${pptDimensions.width};
|
| 315 |
+
const exactHeight = ${pptDimensions.height};
|
| 316 |
+
const backgroundColor = '${slide.background?.color || theme.backgroundColor || '#ffffff'}';
|
| 317 |
+
|
| 318 |
+
console.log('强制设置页面精确尺寸:', exactWidth + 'x' + exactHeight);
|
| 319 |
+
|
| 320 |
+
// 应用固定尺寸样式 - 完全消除白边
|
| 321 |
+
const applyExactSize = (element, width, height) => {
|
| 322 |
+
if (!element) return;
|
| 323 |
+
|
| 324 |
+
element.style.cssText = \`
|
| 325 |
+
width: \${width}px !important;
|
| 326 |
+
height: \${height}px !important;
|
| 327 |
+
min-width: \${width}px !important;
|
| 328 |
+
min-height: \${height}px !important;
|
| 329 |
+
max-width: \${width}px !important;
|
| 330 |
+
max-height: \${height}px !important;
|
| 331 |
+
overflow: hidden !important;
|
| 332 |
+
margin: 0 !important;
|
| 333 |
+
padding: 0 !important;
|
| 334 |
+
border: none !important;
|
| 335 |
+
outline: none !important;
|
| 336 |
+
position: fixed !important;
|
| 337 |
+
top: 0 !important;
|
| 338 |
+
left: 0 !important;
|
| 339 |
+
transform: none !important;
|
| 340 |
+
transform-origin: top left !important;
|
| 341 |
+
background: \${backgroundColor} !important;
|
| 342 |
+
box-sizing: border-box !important;
|
| 343 |
+
\`;
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
// 设置HTML和Body元素
|
| 347 |
+
applyExactSize(html, exactWidth, exactHeight);
|
| 348 |
+
applyExactSize(body, exactWidth, exactHeight);
|
| 349 |
+
|
| 350 |
+
// 设置容器元素
|
| 351 |
if (container) {
|
| 352 |
container.style.cssText = \`
|
| 353 |
+
width: \${exactWidth}px !important;
|
| 354 |
+
height: \${exactHeight}px !important;
|
| 355 |
+
min-width: \${exactWidth}px !important;
|
| 356 |
+
min-height: \${exactHeight}px !important;
|
| 357 |
+
max-width: \${exactWidth}px !important;
|
| 358 |
+
max-height: \${exactHeight}px !important;
|
| 359 |
+
position: fixed !important;
|
| 360 |
top: 0 !important;
|
| 361 |
left: 0 !important;
|
| 362 |
+
overflow: hidden !important;
|
| 363 |
+
margin: 0 !important;
|
| 364 |
+
padding: 0 !important;
|
| 365 |
+
border: none !important;
|
| 366 |
+
outline: none !important;
|
| 367 |
transform: none !important;
|
| 368 |
box-shadow: none !important;
|
| 369 |
+
z-index: 1 !important;
|
| 370 |
+
background-color: \${backgroundColor} !important;
|
| 371 |
\`;
|
| 372 |
}
|
| 373 |
|
| 374 |
+
// 禁用所有可能的缩放和调整
|
| 375 |
+
document.addEventListener('wheel', function(e) {
|
| 376 |
+
if (e.ctrlKey) {
|
| 377 |
+
e.preventDefault();
|
| 378 |
+
}
|
| 379 |
+
}, { passive: false });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
+
// 禁用触摸缩放
|
| 382 |
+
document.addEventListener('touchstart', function(e) {
|
| 383 |
+
if (e.touches.length > 1) {
|
| 384 |
+
e.preventDefault();
|
| 385 |
+
}
|
| 386 |
+
}, { passive: false });
|
| 387 |
|
| 388 |
+
// 禁用双击缩放
|
| 389 |
+
let lastTouchEnd = 0;
|
| 390 |
+
document.addEventListener('touchend', function(e) {
|
| 391 |
+
const now = new Date().getTime();
|
| 392 |
+
if (now - lastTouchEnd <= 300) {
|
| 393 |
+
e.preventDefault();
|
| 394 |
+
}
|
| 395 |
+
lastTouchEnd = now;
|
| 396 |
+
}, false);
|
| 397 |
|
| 398 |
+
// 禁用右键菜单
|
| 399 |
+
document.addEventListener('contextmenu', function(e) {
|
| 400 |
+
e.preventDefault();
|
| 401 |
+
}, false);
|
| 402 |
+
|
| 403 |
+
// 禁用F11全屏
|
| 404 |
+
document.addEventListener('keydown', function(e) {
|
| 405 |
+
if (e.key === 'F11') {
|
| 406 |
+
e.preventDefault();
|
| 407 |
+
}
|
| 408 |
+
}, false);
|
| 409 |
+
|
| 410 |
+
console.log('固定尺寸模式样式应用完成,精确尺寸:', exactWidth + 'x' + exactHeight);
|
| 411 |
+
|
| 412 |
+
// 最终验证尺寸 - 确保网页分辨率与PPT分辨率完全一致
|
| 413 |
+
setTimeout(() => {
|
| 414 |
+
const actualDimensions = {
|
| 415 |
+
html: {
|
| 416 |
+
width: html.offsetWidth,
|
| 417 |
+
height: html.offsetHeight,
|
| 418 |
+
clientWidth: html.clientWidth,
|
| 419 |
+
clientHeight: html.clientHeight
|
| 420 |
+
},
|
| 421 |
+
body: {
|
| 422 |
+
width: body.offsetWidth,
|
| 423 |
+
height: body.offsetHeight,
|
| 424 |
+
clientWidth: body.clientWidth,
|
| 425 |
+
clientHeight: body.clientHeight
|
| 426 |
+
},
|
| 427 |
+
container: {
|
| 428 |
+
width: container ? container.offsetWidth : 0,
|
| 429 |
+
height: container ? container.offsetHeight : 0,
|
| 430 |
+
clientWidth: container ? container.clientWidth : 0,
|
| 431 |
+
clientHeight: container ? container.clientHeight : 0
|
| 432 |
+
},
|
| 433 |
+
viewport: {
|
| 434 |
+
width: window.innerWidth,
|
| 435 |
+
height: window.innerHeight
|
| 436 |
+
}
|
| 437 |
+
};
|
| 438 |
+
|
| 439 |
+
console.log('最终页面尺寸验证:', actualDimensions);
|
| 440 |
+
console.log('PPT目标尺寸:', window.PPT_DIMENSIONS);
|
| 441 |
+
|
| 442 |
+
// 检查是否存在尺寸不一致的情况
|
| 443 |
+
const htmlSizeMatch = actualDimensions.html.width === window.PPT_DIMENSIONS.width &&
|
| 444 |
+
actualDimensions.html.height === window.PPT_DIMENSIONS.height;
|
| 445 |
+
const bodySizeMatch = actualDimensions.body.width === window.PPT_DIMENSIONS.width &&
|
| 446 |
+
actualDimensions.body.height === window.PPT_DIMENSIONS.height;
|
| 447 |
+
const containerSizeMatch = container ?
|
| 448 |
+
(actualDimensions.container.width === window.PPT_DIMENSIONS.width &&
|
| 449 |
+
actualDimensions.container.height === window.PPT_DIMENSIONS.height) : true;
|
| 450 |
+
|
| 451 |
+
if (!htmlSizeMatch || !bodySizeMatch || !containerSizeMatch) {
|
| 452 |
+
console.warn('检测到尺寸不一致,可能出现白边问题');
|
| 453 |
+
console.warn('HTML尺寸匹配:', htmlSizeMatch);
|
| 454 |
+
console.warn('Body尺寸匹配:', bodySizeMatch);
|
| 455 |
+
console.warn('容器尺寸匹配:', containerSizeMatch);
|
| 456 |
+
|
| 457 |
+
// 尝试强制修正
|
| 458 |
+
if (!htmlSizeMatch) {
|
| 459 |
+
html.style.width = window.PPT_DIMENSIONS.width + 'px';
|
| 460 |
+
html.style.height = window.PPT_DIMENSIONS.height + 'px';
|
| 461 |
+
}
|
| 462 |
+
if (!bodySizeMatch) {
|
| 463 |
+
body.style.width = window.PPT_DIMENSIONS.width + 'px';
|
| 464 |
+
body.style.height = window.PPT_DIMENSIONS.height + 'px';
|
| 465 |
+
}
|
| 466 |
+
if (container && !containerSizeMatch) {
|
| 467 |
+
container.style.width = window.PPT_DIMENSIONS.width + 'px';
|
| 468 |
+
container.style.height = window.PPT_DIMENSIONS.height + 'px';
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
console.log('已尝试强制修正尺寸不一致问题');
|
| 472 |
+
} else {
|
| 473 |
+
console.log('✅ 页面尺寸验证通过,网页分辨率与PPT分辨率完全一致,无白边');
|
| 474 |
+
}
|
| 475 |
+
}, 100);
|
| 476 |
+
});
|
| 477 |
</script>
|
| 478 |
</body>
|
| 479 |
</html>
|