42 lines
1011 B
TypeScript
42 lines
1011 B
TypeScript
import type { ImageWidgetNode } from '../schema';
|
|
|
|
/**
|
|
* goView Image option shape varies across versions. We keep this intentionally
|
|
* permissive and normalize the common fields.
|
|
*/
|
|
export interface GoViewImageOption {
|
|
/**
|
|
* Common in existing legacy widgets (same as iframe/video).
|
|
*/
|
|
dataset?: string;
|
|
|
|
/**
|
|
* Other variants seen in the wild.
|
|
*/
|
|
src?: string;
|
|
url?: string;
|
|
|
|
/**
|
|
* Styling.
|
|
*/
|
|
fit?: ImageWidgetNode['props']['fit'];
|
|
objectFit?: ImageWidgetNode['props']['fit'];
|
|
borderRadius?: number;
|
|
}
|
|
|
|
function pickSrc(option: GoViewImageOption): string {
|
|
return option.dataset ?? option.src ?? option.url ?? '';
|
|
}
|
|
|
|
function pickFit(option: GoViewImageOption): ImageWidgetNode['props']['fit'] | undefined {
|
|
return option.fit ?? option.objectFit;
|
|
}
|
|
|
|
export function convertGoViewImageOptionToNodeProps(option: GoViewImageOption): ImageWidgetNode['props'] {
|
|
return {
|
|
src: pickSrc(option),
|
|
fit: pickFit(option),
|
|
borderRadius: option.borderRadius,
|
|
};
|
|
}
|