23 lines
841 B
TypeScript
23 lines
841 B
TypeScript
import type { Annotation } from "./canvas/types.js";
|
|
|
|
/** Several views of one cached semantic item. These are authored presentation
|
|
* choices, not separate computations or independently generated annotations. */
|
|
export type AnnotationRender = {
|
|
style: Annotation["style"];
|
|
underlinePattern?: Annotation["underlinePattern"];
|
|
placement?: Annotation["placement"];
|
|
reveal: "always" | "click" | "hover";
|
|
content?: "result" | "source";
|
|
};
|
|
export function renderAnnotations(item: Annotation, source: string, renders: readonly AnnotationRender[] | undefined) {
|
|
if (!renders?.length) return [item];
|
|
return renders.map(
|
|
(render, index): Annotation => ({
|
|
...item,
|
|
id: `${item.id}:render:${index}`,
|
|
...render,
|
|
text: render.content === "source" ? source.slice(item.start, item.end) : item.text,
|
|
}),
|
|
);
|
|
}
|