Release v2.2.0
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #111;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#popup-preview-stage {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#popup-preview-canvas {
|
||||
position: relative;
|
||||
left: auto;
|
||||
top: auto;
|
||||
transform-origin: center center;
|
||||
flex: 0 0 auto;
|
||||
box-sizing: border-box;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="slide-preview-popup-stage" id="popup-preview-stage">
|
||||
<div class="slide-preview-popup-canvas" id="popup-preview-canvas"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
function injectFontStylesheet(href) {
|
||||
var normalizedHref = String(href || '').trim();
|
||||
if (!normalizedHref) {
|
||||
return;
|
||||
}
|
||||
|
||||
var existing = document.querySelector('link[data-slide-preview-fonts="true"]');
|
||||
if (existing && existing.getAttribute('href') === normalizedHref) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (existing && existing.parentNode) {
|
||||
existing.parentNode.removeChild(existing);
|
||||
}
|
||||
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = normalizedHref;
|
||||
link.setAttribute('data-slide-preview-fonts', 'true');
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
|
||||
var stage = document.getElementById('popup-preview-stage');
|
||||
var canvas = document.getElementById('popup-preview-canvas');
|
||||
|
||||
function readPayload() {
|
||||
var hash = String(window.location.hash || '').replace(/^#/, '');
|
||||
if (!hash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(decodeURIComponent(hash));
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function applyPayload() {
|
||||
if (!stage || !canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = readPayload();
|
||||
if (!payload) {
|
||||
canvas.innerHTML = '<div class="slide-preview-empty" style="display:flex;align-items:center;justify-content:center;min-height:100%;color:rgba(255,255,255,0.75);">No preview data available.</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
injectFontStylesheet(payload.fontStylesheetHref);
|
||||
|
||||
var backgroundColor = String(payload.backgroundColor || '#111111').trim() || '#111111';
|
||||
var backgroundImagePath = String(payload.backgroundImagePath || '').trim();
|
||||
|
||||
var canvasWidth = Math.max(1, Number(payload.canvasWidth || 1920));
|
||||
var canvasHeight = Math.max(1, Number(payload.canvasHeight || 1080));
|
||||
canvas.style.backgroundColor = backgroundColor;
|
||||
canvas.style.backgroundImage = backgroundImagePath ? 'url("' + encodeURI(backgroundImagePath) + '")' : 'none';
|
||||
canvas.style.backgroundPosition = 'center';
|
||||
canvas.style.backgroundSize = '100% 100%';
|
||||
canvas.style.backgroundRepeat = 'no-repeat';
|
||||
canvas.style.width = canvasWidth + 'px';
|
||||
canvas.style.height = canvasHeight + 'px';
|
||||
canvas.innerHTML = String(payload.html || '');
|
||||
|
||||
var stageRect = stage.getBoundingClientRect();
|
||||
if (!stageRect.width || !stageRect.height) {
|
||||
window.requestAnimationFrame(applyPayload);
|
||||
return;
|
||||
}
|
||||
|
||||
var scale = Math.min(stageRect.width / canvasWidth, stageRect.height / canvasHeight) || 1;
|
||||
canvas.style.transform = 'scale(' + scale + ')';
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', applyPayload);
|
||||
window.addEventListener('resize', applyPayload);
|
||||
applyPayload();
|
||||
}());
|
||||
</script>
|
||||
Reference in New Issue
Block a user