function escapeHtml(value = "") {
return String(value)
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function commonHead({ title = "oEmbed Graphics", htmlClass = "" } = {}) {
return `
${escapeHtml(title)}
`;
}
function slugify(value = "") {
return String(value)
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-|-$/g, "") || "unknown";
}
function numericPixelValue(value) {
const number = Number(value);
return Number.isFinite(number) && number > 0 ? `${number}px` : "";
}
function cappedPixelValue(value, cap) {
const number = Number(value);
if (!Number.isFinite(number) || number <= 0) {
return `${cap}px`;
}
return `${Math.min(number, cap)}px`;
}
function collageCardWidth({ width, spacing, columns }) {
const availableWidth = width - (spacing * 2) - (spacing * Math.max(columns - 1, 0));
const columnWidth = Math.floor(availableWidth / columns);
return Math.max(Math.min(columnWidth, 500), 120);
}
function shuffleItems(items) {
const shuffled = [...items];
for (let index = shuffled.length - 1; index > 0; index -= 1) {
const randomIndex = Math.floor(Math.random() * (index + 1));
[shuffled[index], shuffled[randomIndex]] = [shuffled[randomIndex], shuffled[index]];
}
return shuffled;
}
function addIframePermissions(tag) {
const autoplayPermission = "autoplay";
if (/allow=/i.test(tag)) {
return tag.replace(/\sallow=(["'])(.*?)\1/i, (_match, quote, value) => {
const permissions = value
.split(";")
.map((permission) => permission.trim())
.filter(Boolean);
if (!permissions.includes(autoplayPermission)) {
permissions.push(autoplayPermission);
}
return ` allow=${quote}${permissions.join("; ")}${quote}`;
});
}
return tag.replace(/