card = ({
cellName,
href,
image,
title,
description,
meta,
value,
imageFit,
maxWidth
}) => {
const display = html`<div class="${id}" style="max-width: ${Math.min(
maxWidth || 350,
width
)}px; padding-bottom: 0.5em;">
${style}
${
cellName
? html`<var class="observablehq--inspect">${cellName} =</var>`
: ''
}
<div class=item>
${
image
? !imageFit || imageFit === 'fit'
? html`<a href=${href} target="_blank"><img class=image src="${image}">`
: html`
<a
class=image
style="--src: url('${image}'); --fit: ${imageFit || 'cover'}"
href="${href}"
target="_blank"
></a>`
: ''
}
<div class=body>
<a class=title href="${href}" target="_blank">
${title}
${
description ? html`<div class=description>${description}</div>` : ''
}
</a>
${meta ? html`<div class=meta>${meta}</div>` : ''}
</div>
</div>
`;
requestAnimationFrame(() => {
new DotDotDot(display.querySelector('.description'), { watch: true });
});
if (value && value.then) {
value
.then(value => {
display.value = value;
display.dispatchEvent(new CustomEvent('input'));
})
.catch(err => {
display.outerHTML = `<pre style="color: red"><code>${err.stack}</code></pre>`;
});
} else {
display.value = value;
}
return display;
}