= { id };
pairs.forEach(pair => {
const [key, value] = pair.split('=').map(s => s.trim());
if (key && value) params[key] = value;
});
return params;
}
function buildStyles(dimensions: { width?: string; height?: string }): string {
return Object.entries(dimensions)
.filter(([, value]) => value)
.map(([prop, value]) => `${prop}: ${value.match(/px|%/) ? value : value + 'px'}`)
.join('; ');
}
function createErrorHtml(type: 'video' | 'image'): string {
const icon = type === 'video' ? VideoIcon : ImageIcon;
return ``;
}
function createPlaceholderBlock(
type: 'image-placeholder' | 'video-placeholder',
query: string,
lineIndex: number
): MediaBlock {
const isVideo = type === 'video-placeholder';
const icon = isVideo ? VideoIcon : ImageIcon;
const mediaType = isVideo ? 'video' : 'image';
const placeholderId = generatePlaceholderId(type, query);
const html = ``;
return {
type,
html,
startLine: lineIndex,
endLine: lineIndex,
};
}
function generatePlaceholderId(type: string, query: string): string {
const prefix = type === 'video-placeholder' ? 'video-placeholder' : 'image-placeholder';
const hash = simpleHash(query);
return `${prefix}-${hash}`;
}
function simpleHash(str: string): string {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = (hash << 5) - hash + char;
hash = hash & hash;
}
return Math.abs(hash).toString(36);
}