import { ChangeDetectionStrategy, Component, computed, effect, inject, signal, untracked, viewChild, ViewEncapsulation, } from '@angular/core'; import { EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime'; import type { OpenInput } from '@embedpdf/angular/runtime'; import { EpdfPageTemplate, EpdfStage, withStage } from '@embedpdf/angular/stage'; import { EpdfRenderLayer, withRender } from '@embedpdf/angular/render'; import { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { EpdfMeasurement, withMeasurement, type AreaUnit, type LengthUnit, } from '@embedpdf/angular/measurement'; import { localEngine } from '@embedpdf/engine'; const sketch = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/sketch.pdf'); return { kind: 'bytes', id: 'sketch', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // Precision is steps per unit: 100 shows two decimals. const PRECISIONS = [1, 10, 100, 1000]; // The floor plan's lower half, where the measurements go. const LOWER_HALF = { x: 50, y: 500, width: 512, height: 240 }; @Component({ selector: 'demo-scale-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ ratio() }}
`, }) export class ScaleToolbar { protected readonly measurement = inject(EpdfMeasurement); protected readonly presets = this.measurement.listPresets(); protected readonly units = this.measurement.listUnits(); protected readonly areaUnits = this.measurement.listAreaUnits(); protected readonly precisions = PRECISIONS; protected readonly preset = signal('metric-100'); protected readonly unit = signal('m'); protected readonly areaUnit = signal('m2'); protected readonly precision = signal(100); private readonly scale = this.measurement.scaleOf(0); protected readonly ratio = computed(() => { const measure = this.scale().measure; return measure?.subtype === 'rectilinear' ? measure.ratio : '…'; }); // Every change recalculates the measurements already on the page. protected setPreset(preset: string) { this.preset.set(preset); void this.measurement.setPreset(0, preset); } // A