');
protected readonly onThisPage = computed(() =>
this.dots().filter((dot) => pageRefsEqual(dot.page, this.page.ref)),
);
protected pixels(dot: Dot) {
return this.page.transform().toPixels(dot.point);
}
}
@Component({
selector: 'demo-dots',
imports: [EpdfStage, EpdfPageTemplate, EpdfRenderLayer, PenCursor, DotLayer],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (penCursor()) {
}
`,
})
export class Dots {
protected readonly colors = COLORS;
protected readonly color = signal(COLORS[0]);
protected readonly penCursor = signal(true);
protected readonly dots = signal([]);
constructor() {
const interaction = inject(EpdfInteraction);
const remove = interaction.registerTool({
id: 'dot',
cursor: 'crosshair',
// The tool reads the color at the moment of the click.
onPointerDown: ({ page, point }) => {
this.dots.update((current) => [
...current,
{ id: current.length + 1, page, point, color: this.color() },
]);
return true;
},
});
interaction.activateTool('dot');
inject(DestroyRef).onDestroy(remove);
}
}
@Component({
selector: 'demo-root',
imports: [EpdfDocumentGate, Dots],
providers: [
provideEmbedPdf(
{ engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] },
withStage(),
withRender(),
withInteraction(),
),
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: './cursor.css',
encapsulation: ViewEncapsulation.None,
template: `
Loading…
`,
})
export class App {}