rspace-online/modules/rphotos/applets.ts

41 lines
1.3 KiB
TypeScript

/**
* rPhotos applet definitions — Album Card.
*/
import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types";
const albumCard: AppletDefinition = {
id: "album-card",
label: "Album Card",
icon: "🖼️",
accentColor: "#be185d",
ports: [
{ name: "album-in", type: "string", direction: "input" },
{ name: "image-out", type: "image-url", direction: "output" },
],
renderCompact(data: AppletLiveData): string {
const { snapshot } = data;
const name = (snapshot.name as string) || "Album";
const count = (snapshot.count as number) || 0;
const thumb = (snapshot.thumbnail as string) || "";
return `
<div style="text-align:center">
${thumb
? `<div style="width:100%;height:80px;border-radius:6px;overflow:hidden;margin-bottom:6px"><img src="${thumb}" style="width:100%;height:100%;object-fit:cover" alt=""></div>`
: `<div style="font-size:32px;margin-bottom:6px">🖼️</div>`
}
<div style="font-size:13px;font-weight:600">${name}</div>
<div style="font-size:10px;color:#94a3b8;margin-top:2px">${count} photos</div>
</div>
`;
},
onInputReceived(portName, value, ctx) {
if (portName === "album-in" && typeof value === "string") {
ctx.emitOutput("image-out", "");
}
},
};
export const photosApplets: AppletDefinition[] = [albumCard];