pindo 5.1.1 → 5.1.3
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.
- checksums.yaml +4 -4
- data/lib/pindo/command/android/autobuild.rb +13 -0
- data/lib/pindo/command/unity/autobuild.rb +200 -0
- data/lib/pindo/command/unity/web.rb +152 -0
- data/lib/pindo/command/unity.rb +1 -1
- data/lib/pindo/command/web/run.rb +18 -178
- data/lib/pindo/module/android/build_helper.rb +325 -0
- data/lib/pindo/module/webserver/brotli_file_handler.rb +57 -0
- data/lib/pindo/module/webserver/preview/preview.css +433 -0
- data/lib/pindo/module/webserver/preview/preview.html +73 -0
- data/lib/pindo/module/webserver/preview/preview.js +595 -0
- data/lib/pindo/module/webserver/responsive_preview_handler.rb +104 -0
- data/lib/pindo/module/webserver/webgl_page_handler.rb +45 -0
- data/lib/pindo/module/webserver/webgl_server_helper.rb +190 -0
- data/lib/pindo/version.rb +1 -1
- metadata +11 -2
@@ -0,0 +1,595 @@
|
|
1
|
+
// 预览页面的JavaScript代码
|
2
|
+
document.addEventListener('DOMContentLoaded', function() {
|
3
|
+
// WebGL目录路径,初始为相对路径,将由后端动态替换
|
4
|
+
const webglDirPath = './';
|
5
|
+
|
6
|
+
// 设备配置
|
7
|
+
const devices = {
|
8
|
+
'iPhone 16 Pro Max': { width: 430, height: 932 },
|
9
|
+
'iPhone 16 Pro Max (横屏)': { width: 932, height: 430 },
|
10
|
+
'iPhone 16': { width: 393, height: 852 },
|
11
|
+
'iPhone 16 (横屏)': { width: 852, height: 393 },
|
12
|
+
'iPhone X': { width: 375, height: 812 },
|
13
|
+
'iPhone X (横屏)': { width: 812, height: 375 },
|
14
|
+
'iPhone 8 Plus': { width: 414, height: 736 },
|
15
|
+
'iPhone 8 Plus (横屏)': { width: 736, height: 414 },
|
16
|
+
'iPhone 8': { width: 375, height: 667 },
|
17
|
+
'iPhone 8 (横屏)': { width: 667, height: 375 },
|
18
|
+
'iPhone 5s': { width: 320, height: 568 },
|
19
|
+
'iPhone 5s (横屏)': { width: 568, height: 320 },
|
20
|
+
'iPad Mini': { width: 768, height: 1024 },
|
21
|
+
'iPad Mini (横屏)': { width: 1024, height: 768 },
|
22
|
+
'iPad Pro 11"': { width: 834, height: 1194 },
|
23
|
+
'iPad Pro 11" (横屏)': { width: 1194, height: 834 },
|
24
|
+
'iPad Pro 12.9"': { width: 1024, height: 1366 },
|
25
|
+
'iPad Pro 12.9" (横屏)': { width: 1366, height: 1024 },
|
26
|
+
'Galaxy Note 8': { width: 360, height: 740 },
|
27
|
+
'Galaxy Note 8 (横屏)': { width: 740, height: 360 },
|
28
|
+
'Galaxy S5': { width: 360, height: 640 },
|
29
|
+
'Galaxy S5 (横屏)': { width: 640, height: 360 },
|
30
|
+
'Nexus 5': { width: 360, height: 640 },
|
31
|
+
'Nexus 5 (横屏)': { width: 640, height: 360 },
|
32
|
+
'Lumia 920': { width: 384, height: 640 },
|
33
|
+
'Lumia 920 (横屏)': { width: 640, height: 384 },
|
34
|
+
'MacBook Pro': { width: 1440, height: 900 },
|
35
|
+
'MacBook Pro (横屏)': { width: 900, height: 1440 },
|
36
|
+
'标准桌面': { width: 1280, height: 720 },
|
37
|
+
'标准桌面 (横屏)': { width: 720, height: 1280 },
|
38
|
+
'宽屏桌面': { width: 1920, height: 1080 },
|
39
|
+
'宽屏桌面 (横屏)': { width: 1080, height: 1920 }
|
40
|
+
};
|
41
|
+
|
42
|
+
// 根据设备尺寸和窗口尺寸动态决定是否允许滚动
|
43
|
+
function updateScrollBehavior() {
|
44
|
+
const deviceFrame = document.getElementById('device-frame');
|
45
|
+
const mainContent = document.querySelector('.main-content');
|
46
|
+
|
47
|
+
// 获取设备框架的尺寸和位置
|
48
|
+
const deviceRect = deviceFrame.getBoundingClientRect();
|
49
|
+
const windowHeight = window.innerHeight;
|
50
|
+
const headerHeight = document.querySelector('.header').offsetHeight;
|
51
|
+
const availableHeight = windowHeight - headerHeight;
|
52
|
+
|
53
|
+
// 判断设备是否完全显示在窗口中
|
54
|
+
const isDeviceFullyVisible = deviceRect.height <= availableHeight;
|
55
|
+
|
56
|
+
return isDeviceFullyVisible;
|
57
|
+
}
|
58
|
+
|
59
|
+
// 智能滚动处理函数
|
60
|
+
function handleScroll(e) {
|
61
|
+
// 如果是设备下拉菜单或自定义尺寸面板内的滚动,始终允许
|
62
|
+
if (e.target.closest('.custom-dimensions') || e.target.closest('.device-select-dropdown')) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
|
66
|
+
// 检查设备是否完全可见
|
67
|
+
if (updateScrollBehavior()) {
|
68
|
+
// 设备完全可见,禁止滚动
|
69
|
+
e.preventDefault();
|
70
|
+
}
|
71
|
+
// 设备不完全可见,允许滚动,不做处理
|
72
|
+
}
|
73
|
+
|
74
|
+
// 设置滚动事件监听
|
75
|
+
document.addEventListener('touchmove', handleScroll, { passive: false });
|
76
|
+
document.addEventListener('wheel', handleScroll, { passive: false });
|
77
|
+
|
78
|
+
// 获取DOM元素
|
79
|
+
const deviceSelectButton = document.getElementById('device-select-button');
|
80
|
+
const deviceSelectDropdown = document.getElementById('device-select-dropdown');
|
81
|
+
const customDimensions = document.getElementById('custom-dimensions');
|
82
|
+
const widthInput = document.getElementById('width-input');
|
83
|
+
const heightInput = document.getElementById('height-input');
|
84
|
+
const applyDimensionsButton = document.getElementById('apply-dimensions');
|
85
|
+
const rotateButton = document.getElementById('rotate-button');
|
86
|
+
const fullscreenButton = document.getElementById('fullscreen-button');
|
87
|
+
const deviceFrame = document.getElementById('device-frame');
|
88
|
+
const previewFrame = document.getElementById('preview-frame');
|
89
|
+
const headerDimensionsDisplay = document.getElementById('header-dimensions-display');
|
90
|
+
const frameDimensionsDisplay = document.getElementById('frame-dimensions-display');
|
91
|
+
const loading = document.getElementById('loading');
|
92
|
+
const currentDeviceName = document.getElementById('current-device-name');
|
93
|
+
const deviceInfo = document.getElementById('device-info');
|
94
|
+
const deviceContainer = document.getElementById('device-container');
|
95
|
+
|
96
|
+
let isLandscape = false;
|
97
|
+
let currentDevice = 'iPhone 8 Plus';
|
98
|
+
let isInitialLoad = true;
|
99
|
+
|
100
|
+
// 生成设备选项
|
101
|
+
function generateDeviceOptions() {
|
102
|
+
let deviceOptionsHTML = '';
|
103
|
+
let deviceGroups = {};
|
104
|
+
|
105
|
+
// 将设备按类型分组
|
106
|
+
for (const [name, dims] of Object.entries(devices)) {
|
107
|
+
// 跳过横屏设备,它们将在后面与对应的竖屏设备一起添加
|
108
|
+
if (name.includes('(横屏)')) continue;
|
109
|
+
|
110
|
+
// 获取设备基本类型(iPhone、iPad等)
|
111
|
+
let deviceType = name.split(' ')[0];
|
112
|
+
if (deviceType === '标准' || deviceType === '宽屏') {
|
113
|
+
deviceType = '桌面';
|
114
|
+
}
|
115
|
+
|
116
|
+
if (!deviceGroups[deviceType]) {
|
117
|
+
deviceGroups[deviceType] = [];
|
118
|
+
}
|
119
|
+
|
120
|
+
// 添加竖屏设备
|
121
|
+
deviceGroups[deviceType].push({
|
122
|
+
name: name,
|
123
|
+
width: dims.width,
|
124
|
+
height: dims.height
|
125
|
+
});
|
126
|
+
|
127
|
+
// 添加对应的横屏设备
|
128
|
+
const landscapeName = `${name} (横屏)`;
|
129
|
+
if (devices[landscapeName]) {
|
130
|
+
deviceGroups[deviceType].push({
|
131
|
+
name: landscapeName,
|
132
|
+
width: devices[landscapeName].width,
|
133
|
+
height: devices[landscapeName].height
|
134
|
+
});
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
// 设备类型的显示顺序
|
139
|
+
const deviceOrder = ['iPhone', 'iPad', 'Galaxy', 'Nexus', 'Lumia', 'MacBook', '桌面'];
|
140
|
+
|
141
|
+
// 按组生成HTML
|
142
|
+
deviceOrder.forEach(groupName => {
|
143
|
+
if (deviceGroups[groupName]) {
|
144
|
+
deviceOptionsHTML += `<div class="device-group-header">${groupName}</div>`;
|
145
|
+
|
146
|
+
deviceGroups[groupName].forEach(device => {
|
147
|
+
deviceOptionsHTML += `<div class='device-option' data-device='${device.name}' data-width='${device.width}' data-height='${device.height}'>
|
148
|
+
${device.name} (${device.width}×${device.height})
|
149
|
+
</div>`;
|
150
|
+
});
|
151
|
+
}
|
152
|
+
});
|
153
|
+
|
154
|
+
// 添加自定义尺寸选项
|
155
|
+
deviceOptionsHTML += `<div class="device-group-header">自定义</div>`;
|
156
|
+
deviceOptionsHTML += `<div class="device-option" data-device="custom">自定义尺寸...</div>`;
|
157
|
+
|
158
|
+
// 更新下拉菜单内容
|
159
|
+
deviceSelectDropdown.innerHTML = deviceOptionsHTML;
|
160
|
+
|
161
|
+
// 为新生成的设备选项添加点击事件
|
162
|
+
attachDeviceOptionEvents();
|
163
|
+
}
|
164
|
+
|
165
|
+
// 为设备选项添加点击事件
|
166
|
+
function attachDeviceOptionEvents() {
|
167
|
+
const deviceOptions = document.querySelectorAll('.device-option');
|
168
|
+
deviceOptions.forEach(option => {
|
169
|
+
option.addEventListener('click', function(e) {
|
170
|
+
e.stopPropagation(); // 阻止事件冒泡
|
171
|
+
const deviceName = this.dataset.device;
|
172
|
+
|
173
|
+
if (deviceName === 'custom') {
|
174
|
+
// 显示自定义尺寸弹窗
|
175
|
+
customDimensions.classList.add('active');
|
176
|
+
deviceSelectDropdown.classList.remove('active');
|
177
|
+
deviceSelectButton.querySelector('.caret-icon').classList.remove('up');
|
178
|
+
|
179
|
+
// 将当前的宽高填入输入框
|
180
|
+
const currentWidth = parseInt(deviceFrame.style.width) || 375;
|
181
|
+
const currentHeight = parseInt(deviceFrame.style.height) || 667;
|
182
|
+
widthInput.value = isLandscape ? currentHeight : currentWidth;
|
183
|
+
heightInput.value = isLandscape ? currentWidth : currentHeight;
|
184
|
+
} else {
|
185
|
+
initDevice(deviceName);
|
186
|
+
deviceSelectDropdown.classList.remove('active');
|
187
|
+
deviceSelectButton.querySelector('.caret-icon').classList.remove('up');
|
188
|
+
currentDevice = deviceName;
|
189
|
+
currentDeviceName.textContent = deviceName;
|
190
|
+
if (deviceInfo) {
|
191
|
+
deviceInfo.textContent = deviceName;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
});
|
195
|
+
});
|
196
|
+
}
|
197
|
+
|
198
|
+
// 初始化设备选项
|
199
|
+
generateDeviceOptions();
|
200
|
+
|
201
|
+
// 初始化默认设备
|
202
|
+
initDevice('iPhone 8 Plus');
|
203
|
+
|
204
|
+
// 恢复默认的iframe加载事件处理
|
205
|
+
function setupDefaultIframeLoadHandler() {
|
206
|
+
previewFrame.onload = function() {
|
207
|
+
// 隐藏加载动画
|
208
|
+
loading.style.display = 'none';
|
209
|
+
|
210
|
+
// 重置滚动位置
|
211
|
+
if (window.scrollY > 0) {
|
212
|
+
window.scrollTo(0, 0);
|
213
|
+
}
|
214
|
+
|
215
|
+
// 尝试访问iframe内容
|
216
|
+
try {
|
217
|
+
const iframeDocument = previewFrame.contentDocument || (previewFrame.contentWindow && previewFrame.contentWindow.document);
|
218
|
+
if (iframeDocument) {
|
219
|
+
const htmlElement = iframeDocument.documentElement;
|
220
|
+
const bodyElement = iframeDocument.body;
|
221
|
+
|
222
|
+
// 获取当前设备的宽高
|
223
|
+
let width, height;
|
224
|
+
if (currentDevice === 'custom') {
|
225
|
+
width = parseInt(deviceFrame.style.width);
|
226
|
+
height = parseInt(deviceFrame.style.height);
|
227
|
+
} else {
|
228
|
+
width = devices[currentDevice].width;
|
229
|
+
height = devices[currentDevice].height;
|
230
|
+
}
|
231
|
+
|
232
|
+
// 根据旋转状态设置内部尺寸
|
233
|
+
if (isLandscape) {
|
234
|
+
// 横屏模式 - 交换宽高
|
235
|
+
htmlElement.style.width = height + 'px';
|
236
|
+
htmlElement.style.height = width + 'px';
|
237
|
+
|
238
|
+
if (bodyElement) {
|
239
|
+
bodyElement.style.width = height + 'px';
|
240
|
+
bodyElement.style.height = width + 'px';
|
241
|
+
}
|
242
|
+
} else {
|
243
|
+
// 竖屏模式 - 正常宽高
|
244
|
+
htmlElement.style.width = width + 'px';
|
245
|
+
htmlElement.style.height = height + 'px';
|
246
|
+
|
247
|
+
if (bodyElement) {
|
248
|
+
bodyElement.style.width = width + 'px';
|
249
|
+
bodyElement.style.height = height + 'px';
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
// 设置CSS,优化展示并禁止滚动
|
254
|
+
if (bodyElement) {
|
255
|
+
bodyElement.style.overflow = 'hidden';
|
256
|
+
bodyElement.style.margin = '0';
|
257
|
+
bodyElement.style.padding = '0';
|
258
|
+
}
|
259
|
+
|
260
|
+
// 添加滚动锁定
|
261
|
+
htmlElement.style.overflow = 'hidden';
|
262
|
+
htmlElement.style.position = 'fixed';
|
263
|
+
htmlElement.style.margin = '0';
|
264
|
+
htmlElement.style.padding = '0';
|
265
|
+
|
266
|
+
// 禁止触摸滚动
|
267
|
+
iframeDocument.addEventListener('touchmove', function(e) {
|
268
|
+
e.preventDefault();
|
269
|
+
}, { passive: false });
|
270
|
+
|
271
|
+
// 尝试修复iframe中相对路径的问题
|
272
|
+
const basePath = './';
|
273
|
+
const baseElement = iframeDocument.createElement('base');
|
274
|
+
baseElement.href = webglDirPath;
|
275
|
+
|
276
|
+
// 将base元素添加到head开始位置
|
277
|
+
const head = iframeDocument.head || iframeDocument.getElementsByTagName('head')[0];
|
278
|
+
if (head && !head.querySelector('base')) {
|
279
|
+
head.insertBefore(baseElement, head.firstChild);
|
280
|
+
}
|
281
|
+
|
282
|
+
// 添加内联样式确保所有元素正确显示
|
283
|
+
const styleEl = iframeDocument.createElement('style');
|
284
|
+
styleEl.textContent = `
|
285
|
+
html, body {
|
286
|
+
width: ${isLandscape ? height : width}px !important;
|
287
|
+
height: ${isLandscape ? width : height}px !important;
|
288
|
+
margin: 0 !important;
|
289
|
+
padding: 0 !important;
|
290
|
+
overflow: hidden !important;
|
291
|
+
}
|
292
|
+
body > * {
|
293
|
+
width: 100% !important;
|
294
|
+
box-sizing: border-box !important;
|
295
|
+
}
|
296
|
+
`;
|
297
|
+
head.appendChild(styleEl);
|
298
|
+
}
|
299
|
+
} catch (e) {
|
300
|
+
// 可能由于同源策略限制,忽略错误
|
301
|
+
console.log("无法访问iframe内容:", e);
|
302
|
+
}
|
303
|
+
|
304
|
+
// 更新滚动行为
|
305
|
+
setTimeout(updateScrollBehavior, 300);
|
306
|
+
};
|
307
|
+
}
|
308
|
+
|
309
|
+
// iframe错误处理,避免无限加载
|
310
|
+
previewFrame.onerror = function() {
|
311
|
+
loading.style.display = 'none';
|
312
|
+
};
|
313
|
+
|
314
|
+
// 初始化设备
|
315
|
+
function initDevice(deviceName) {
|
316
|
+
if (devices[deviceName]) {
|
317
|
+
// 显示加载动画
|
318
|
+
showLoading();
|
319
|
+
|
320
|
+
if (isInitialLoad) {
|
321
|
+
isInitialLoad = false;
|
322
|
+
}
|
323
|
+
|
324
|
+
// 检查是否是横屏设备
|
325
|
+
const isLandscapeDevice = deviceName.includes('(横屏)');
|
326
|
+
|
327
|
+
// 设置方向标志
|
328
|
+
isLandscape = isLandscapeDevice;
|
329
|
+
|
330
|
+
// 根据方向设置类
|
331
|
+
if (isLandscape) {
|
332
|
+
deviceContainer.classList.add('landscape');
|
333
|
+
deviceFrame.classList.add('landscape');
|
334
|
+
} else {
|
335
|
+
deviceContainer.classList.remove('landscape');
|
336
|
+
deviceFrame.classList.remove('landscape');
|
337
|
+
}
|
338
|
+
|
339
|
+
// 重置iframe样式 - 重要:不要设置transform属性,让CSS规则处理旋转
|
340
|
+
previewFrame.style.width = '100%';
|
341
|
+
previewFrame.style.height = '100%';
|
342
|
+
|
343
|
+
// 恢复默认的iframe加载事件处理
|
344
|
+
setupDefaultIframeLoadHandler();
|
345
|
+
|
346
|
+
const { width, height } = devices[deviceName];
|
347
|
+
|
348
|
+
// 更新设备名称显示
|
349
|
+
currentDeviceName.textContent = deviceName;
|
350
|
+
|
351
|
+
// 应用尺寸到设备框架
|
352
|
+
deviceFrame.style.width = width + 'px';
|
353
|
+
deviceFrame.style.height = height + 'px';
|
354
|
+
|
355
|
+
// 设置CSS变量,用于设备旋转时交换宽高
|
356
|
+
document.documentElement.style.setProperty('--device-width', `${width}px`);
|
357
|
+
document.documentElement.style.setProperty('--device-height', `${height}px`);
|
358
|
+
|
359
|
+
// 更新尺寸显示 - 按照显示方向确定尺寸
|
360
|
+
if (isLandscape) {
|
361
|
+
// 在横屏模式下交换宽高显示
|
362
|
+
updateDimensionsDisplay(height, width);
|
363
|
+
} else {
|
364
|
+
updateDimensionsDisplay(width, height);
|
365
|
+
}
|
366
|
+
|
367
|
+
// 更新滚动行为
|
368
|
+
setTimeout(updateScrollBehavior, 100);
|
369
|
+
|
370
|
+
// 强制刷新iframe
|
371
|
+
refreshIframe(true);
|
372
|
+
|
373
|
+
// 更新设备选择按钮显示的文本
|
374
|
+
deviceSelectButton.querySelector('span').textContent = deviceName;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
// 显示加载动画
|
379
|
+
function showLoading() {
|
380
|
+
loading.style.display = 'flex';
|
381
|
+
|
382
|
+
// 设置超时,如果5秒后还在加载,则强制隐藏加载动画
|
383
|
+
setTimeout(() => {
|
384
|
+
loading.style.display = 'none';
|
385
|
+
}, 5000);
|
386
|
+
}
|
387
|
+
|
388
|
+
// 设备选择下拉菜单
|
389
|
+
deviceSelectButton.addEventListener('click', function(e) {
|
390
|
+
e.stopPropagation();
|
391
|
+
deviceSelectDropdown.classList.toggle('active');
|
392
|
+
deviceSelectButton.querySelector('.caret-icon').classList.toggle('up');
|
393
|
+
customDimensions.classList.remove('active');
|
394
|
+
});
|
395
|
+
|
396
|
+
// 点击页面其他区域关闭下拉菜单
|
397
|
+
document.addEventListener('click', function() {
|
398
|
+
deviceSelectDropdown.classList.remove('active');
|
399
|
+
customDimensions.classList.remove('active');
|
400
|
+
deviceSelectButton.querySelector('.caret-icon').classList.remove('up');
|
401
|
+
});
|
402
|
+
|
403
|
+
// 防止自定义尺寸弹窗被点击外部区域关闭
|
404
|
+
customDimensions.addEventListener('click', function(e) {
|
405
|
+
e.stopPropagation();
|
406
|
+
});
|
407
|
+
|
408
|
+
// 应用自定义尺寸
|
409
|
+
applyDimensionsButton.addEventListener('click', function() {
|
410
|
+
// 获取用户输入的宽高值,并确保它们是有效的正整数
|
411
|
+
let width = parseInt(widthInput.value);
|
412
|
+
let height = parseInt(heightInput.value);
|
413
|
+
|
414
|
+
// 设置最小尺寸限制
|
415
|
+
width = (width && width >= 200) ? width : 375;
|
416
|
+
height = (height && height >= 200) ? height : 667;
|
417
|
+
|
418
|
+
// 更新输入框的值,确保显示有效数值
|
419
|
+
widthInput.value = width;
|
420
|
+
heightInput.value = height;
|
421
|
+
|
422
|
+
// 显示加载动画
|
423
|
+
showLoading();
|
424
|
+
|
425
|
+
// 重置滚动位置
|
426
|
+
document.querySelector('.main-content').scrollTop = 0;
|
427
|
+
|
428
|
+
// 更新设备名为"自定义尺寸"
|
429
|
+
currentDevice = 'custom';
|
430
|
+
currentDeviceName.textContent = '自定义尺寸';
|
431
|
+
|
432
|
+
// 设置CSS变量,用于设备旋转时交换宽高
|
433
|
+
document.documentElement.style.setProperty('--device-width', `${width}px`);
|
434
|
+
document.documentElement.style.setProperty('--device-height', `${height}px`);
|
435
|
+
|
436
|
+
// 更新尺寸显示
|
437
|
+
updateDimensionsDisplay(width, height);
|
438
|
+
|
439
|
+
// 应用新尺寸到设备框架
|
440
|
+
setTimeout(() => {
|
441
|
+
deviceFrame.style.width = width + 'px';
|
442
|
+
deviceFrame.style.height = height + 'px';
|
443
|
+
|
444
|
+
// 关闭自定义尺寸面板
|
445
|
+
customDimensions.classList.remove('active');
|
446
|
+
|
447
|
+
// 强制刷新iframe
|
448
|
+
refreshIframe(true);
|
449
|
+
}, 100);
|
450
|
+
});
|
451
|
+
|
452
|
+
// 设置设备容器的尺寸
|
453
|
+
function setDeviceFrameSize(width, height) {
|
454
|
+
if (!deviceFrame) return;
|
455
|
+
|
456
|
+
// 设置设备框架的尺寸
|
457
|
+
deviceFrame.style.width = width + 'px';
|
458
|
+
deviceFrame.style.height = height + 'px';
|
459
|
+
|
460
|
+
// 设置预览框架的尺寸与设备框架相同
|
461
|
+
previewFrame.style.width = width + 'px';
|
462
|
+
previewFrame.style.height = height + 'px';
|
463
|
+
|
464
|
+
// 更新尺寸显示
|
465
|
+
updateDimensionsDisplay(width, height);
|
466
|
+
}
|
467
|
+
|
468
|
+
// 旋转按钮事件处理
|
469
|
+
rotateButton.addEventListener('click', function() {
|
470
|
+
// 显示加载动画
|
471
|
+
showLoading();
|
472
|
+
|
473
|
+
// 切换方向状态
|
474
|
+
isLandscape = !isLandscape;
|
475
|
+
|
476
|
+
// 获取当前设备尺寸
|
477
|
+
let width, height;
|
478
|
+
if (currentDevice === 'custom') {
|
479
|
+
width = parseInt(deviceFrame.style.width) || 375;
|
480
|
+
height = parseInt(deviceFrame.style.height) || 667;
|
481
|
+
} else {
|
482
|
+
width = devices[currentDevice].width;
|
483
|
+
height = devices[currentDevice].height;
|
484
|
+
}
|
485
|
+
|
486
|
+
// 根据当前方向更新容器类
|
487
|
+
if (isLandscape) {
|
488
|
+
deviceContainer.classList.add('landscape');
|
489
|
+
deviceFrame.classList.add('landscape');
|
490
|
+
|
491
|
+
// 在横屏模式下交换宽高
|
492
|
+
updateDimensionsDisplay(height, width);
|
493
|
+
} else {
|
494
|
+
deviceContainer.classList.remove('landscape');
|
495
|
+
deviceFrame.classList.remove('landscape');
|
496
|
+
|
497
|
+
// 在竖屏模式下恢复原始宽高
|
498
|
+
updateDimensionsDisplay(width, height);
|
499
|
+
}
|
500
|
+
|
501
|
+
// 更新滚动行为
|
502
|
+
setTimeout(updateScrollBehavior, 100);
|
503
|
+
|
504
|
+
// 刷新iframe,以确保内容能适应新的方向
|
505
|
+
refreshIframe(true);
|
506
|
+
});
|
507
|
+
|
508
|
+
// 全屏按钮点击事件
|
509
|
+
fullscreenButton.addEventListener('click', function() {
|
510
|
+
if (previewFrame.requestFullscreen) {
|
511
|
+
previewFrame.requestFullscreen();
|
512
|
+
} else if (previewFrame.mozRequestFullScreen) {
|
513
|
+
previewFrame.mozRequestFullScreen();
|
514
|
+
} else if (previewFrame.webkitRequestFullscreen) {
|
515
|
+
previewFrame.webkitRequestFullscreen();
|
516
|
+
} else if (previewFrame.msRequestFullscreen) {
|
517
|
+
previewFrame.msRequestFullscreen();
|
518
|
+
}
|
519
|
+
});
|
520
|
+
|
521
|
+
// 刷新iframe,添加方向参数
|
522
|
+
function refreshIframe(forceRefresh) {
|
523
|
+
// 显示加载动画
|
524
|
+
showLoading();
|
525
|
+
|
526
|
+
const baseUrl = webglDirPath + 'rawindex.html';
|
527
|
+
const currentTime = new Date().getTime();
|
528
|
+
const orientation = isLandscape ? 'landscape' : 'portrait';
|
529
|
+
const freshUrl = `${baseUrl}?t=${currentTime}&orientation=${orientation}`;
|
530
|
+
|
531
|
+
previewFrame.src = freshUrl;
|
532
|
+
}
|
533
|
+
|
534
|
+
// 在文档加载完成时,添加CSS规则到页面样式表,确保框架旋转正确
|
535
|
+
(function() {
|
536
|
+
// 创建新的样式元素
|
537
|
+
const styleElement = document.createElement('style');
|
538
|
+
// 添加CSS规则
|
539
|
+
styleElement.textContent = `
|
540
|
+
/* 横屏模式样式规则 */
|
541
|
+
#device-container.landscape {
|
542
|
+
display: flex;
|
543
|
+
justify-content: center;
|
544
|
+
align-items: center;
|
545
|
+
}
|
546
|
+
|
547
|
+
/* 设备框架旋转样式 - 仅旋转90度,不改变尺寸 */
|
548
|
+
#device-frame.landscape {
|
549
|
+
transform: rotate(-90deg);
|
550
|
+
transform-origin: center center;
|
551
|
+
}
|
552
|
+
|
553
|
+
/* 预览窗口旋转样式 - 在设备框架旋转的基础上旋转回来 */
|
554
|
+
#device-frame.landscape #preview-frame {
|
555
|
+
transform: rotate(90deg);
|
556
|
+
transform-origin: center center;
|
557
|
+
}
|
558
|
+
`;
|
559
|
+
// 添加到文档头部
|
560
|
+
document.head.appendChild(styleElement);
|
561
|
+
})();
|
562
|
+
|
563
|
+
// 更新尺寸显示
|
564
|
+
function updateDimensionsDisplay(width, height) {
|
565
|
+
const dimensionsText = width + ' × ' + height;
|
566
|
+
|
567
|
+
// 更新顶部尺寸显示
|
568
|
+
if (headerDimensionsDisplay) {
|
569
|
+
headerDimensionsDisplay.textContent = dimensionsText;
|
570
|
+
}
|
571
|
+
|
572
|
+
// 更新设备框架下方的尺寸显示
|
573
|
+
if (frameDimensionsDisplay) {
|
574
|
+
frameDimensionsDisplay.textContent = dimensionsText;
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
// 应用尺寸到设备框架
|
579
|
+
function applyDimensions(width, height) {
|
580
|
+
deviceFrame.style.width = width + 'px';
|
581
|
+
deviceFrame.style.height = height + 'px';
|
582
|
+
|
583
|
+
// 更新尺寸显示
|
584
|
+
updateDimensionsDisplay(width, height);
|
585
|
+
|
586
|
+
// 更新滚动行为
|
587
|
+
setTimeout(updateScrollBehavior, 100);
|
588
|
+
}
|
589
|
+
|
590
|
+
// 监听窗口尺寸改变
|
591
|
+
window.addEventListener('resize', function() {
|
592
|
+
// 更新滚动行为
|
593
|
+
updateScrollBehavior();
|
594
|
+
});
|
595
|
+
});
|