# @embedpdf/plugin-selection — ./internal GlyphPointer [InterfaceDeclaration] (from packages/plugin/selection/src/model.ts): export interface GlyphPointer{ page: PageRef; glyph: number; } SelectionAction [TypeAliasDeclaration] (from packages/plugin/selection/src/model.ts): export type SelectionAction = |{ type: 'pageLoaded'; page: PageRef} |{ type: 'set'; selection: SelectionRange; segments: Record; } |{ type: 'clear'} |{ type: 'setHighlightHidden'; hidden: boolean} |{ type: 'setGestureActive'; active: boolean} ; SelectionAnchor [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionAnchor{ page: PageRef; bounds: Rect; } SelectionCapability [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionCapability{ canSelect(): boolean; canCopy(): boolean; select(range: SelectionRangeInput): void; selectAll(): void; selectPage(page: PageRef): void; selectWordAt(page: PageRef, point: Point): boolean; selectLineAt(page: PageRef, point: Point): boolean; extendTo(page: PageRef, point: Point): void; clear(): void; hasSelection(): boolean; getSnapshot(): SelectionSnapshot; getRange(): TextRange | null; listSelectedPages(): readonly PageRef[]; listSegments(page: PageRef): readonly SelectionSegment[]; listRects(page: PageRef): readonly Rect[]; getAnchor(): SelectionAnchor | null; readText(options?: OperationOptions): Promise; readTextInRange(range: TextRange, options?: OperationOptions): Promise; readonly onChanged: EventHook; readonly onCommitted: EventHook; readonly onCleared: EventHook; } SelectionChangedEvent [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionChangedEvent{ readonly range: TextRange | null; readonly pages: readonly PageRef[]; readonly origin: ChangeOrigin; } SelectionClearedEvent [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionClearedEvent{ readonly origin: ChangeOrigin; } SelectionCommittedEvent [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionCommittedEvent{ readonly range: TextRange; } SelectionConfig [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionConfig{ dragThreshold?: number; } SelectionEndpoint [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionEndpoint{ page: PageRef; glyphQuad: TextQuad; advance: 1 | -1; rect: Rect; } SelectionHostCapability [InterfaceDeclaration] (from packages/plugin/selection/src/host-contract.ts): export interface SelectionHostCapability extends SelectionCapability{ ensureLoaded(page: PageRef): Promise; isLoaded(page: PageRef): boolean; isOverText(page: PageRef, point: Point): boolean; beginGesture(): void; beginGestureAt(page: PageRef, point: Point): boolean; endGesture(): void; isGestureActive(): boolean; setHighlightVisible(visible: boolean): void; isHighlightVisible(): boolean; } SelectionPageGeometry [InterfaceDeclaration] (from packages/plugin/selection/src/geometry.ts): export interface SelectionPageGeometry{ layout: PageTextLayout; toContent: Mat2D<'pdf', 'content'>; fromContent: Mat2D<'content', 'pdf'>; } SelectionRange [InterfaceDeclaration] (from packages/plugin/selection/src/model.ts): export interface SelectionRange{ anchor: GlyphPointer; focus: GlyphPointer; } SelectionRangeInput [TypeAliasDeclaration] (from packages/plugin/selection/src/contract.ts): export type SelectionRangeInput = TextRange |{ page: PageRef; start: number; count: number} ; SelectionSegment [InterfaceDeclaration] (from packages/plugin/selection/src/geometry.ts): export interface SelectionSegment{ quad: TextQuad; rect: Rect; advance: 1 | -1; } SelectionSnapshot [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface SelectionSnapshot{ readonly pages: readonly{ page: PageRef; segments: readonly SelectionSegment[]} []; readonly start: SelectionEndpoint | null; readonly end: SelectionEndpoint | null; readonly direction: 'forward' | 'backward'; readonly range: TextRange | null; } SelectionState [InterfaceDeclaration] (from packages/plugin/selection/src/model.ts): export interface SelectionState{ selection: SelectionRange | null; segments: Record; loaded: Record; highlightHidden: boolean; gestureActive: boolean; } SelectionToken [VariableDeclaration] (from packages/plugin/selection/src/host-contract.ts): SelectionToken = PublicSelectionToken as unknown as CapabilityToken TextPosition [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface TextPosition{ page: PageRef; index: number; } TextRange [InterfaceDeclaration] (from packages/plugin/selection/src/contract.ts): export interface TextRange{ start: TextPosition; end: TextPosition; } buildSelectionPageGeometry [FunctionDeclaration] (from packages/plugin/selection/src/geometry.ts): export function buildSelectionPageGeometry( snapshot: PageGeometrySnapshot, crop: PdfRect, rotation: 0 | 90 | 180 | 270, userUnit: number, ): SelectionPageGeometry{ const{ pdfToContent} = pageGeometry({ crop, rotation, userUnit} , 1); return{ layout: buildPageTextLayout(snapshot), toContent: pdfToContent, fromContent: invert(pdfToContent), } ; } contentPointToPdf [FunctionDeclaration] (from packages/plugin/selection/src/geometry.ts): export function contentPointToPdf(geom: SelectionPageGeometry, p: Point): PdfPoint{ return applyPoint(geom.fromContent, p as PointIn<'content'>); } createSelectionController [FunctionDeclaration] (from packages/plugin/selection/src/controller.ts): export function createSelectionController(ctx: ControllerContext){ const rawGeometry = new Map(); const derived = new Map(); const loads = new Map>(); const textSnapshots = new Map>(); let epoch = 0; const changed = ctx.events.source(); const committed = ctx.events.source(); const cleared = ctx.events.source(); const state = () => ctx.getState(); const canSelect = (): boolean => ctx.doc.security.allows(SELECT_SCOPE); const canCopy = (): boolean => ctx.doc.security.allows(COPY_SCOPE); const assertScope = (scope: DocCapability, operation: string): void =>{ if (!ctx.doc.security.allows(scope)){ throw new PluginError('permission-denied', 'selection', `${ operation} requires ${ scope} `, { details:{ required: scope} , } ); } } ; const layoutOf = (pon: PageObjectNumber) => ctx.getPage(toPageRef(pon)); const pageIndexOf = (pon: PageObjectNumber): number => layoutOf(pon)?.index ?? -1; const ponAtIndex = (i: number): PageObjectNumber | undefined => ctx.document()?.pages[i]?.ref.pageObjectNumber; function geometryFor(pon: PageObjectNumber): SelectionPageGeometry | null{ const raw = rawGeometry.get(pon); const layout = layoutOf(pon); if (!raw || !layout) return null; const crop = layout.boxes.crop; const key = `${ layout.rotation} |${ layout.userUnit} |${ crop.left} , ${ crop.bottom} , ${ crop.right} , ${ crop.top} `; const hit = derived.get(pon); if (hit && hit.key === key) return hit.geom; const geom = buildSelectionPageGeometry(raw, crop, layout.rotation, layout.userUnit); derived.set(pon, { key, geom} ); return geom; } const glyphAt = (geom: SelectionPageGeometry, point: Point): number | null => textGlyphAt(geom.layout, contentPointToPdf(geom, point)); function ensureLoaded(page: PageRef): Promise{ const pon = page.pageObjectNumber; if (rawGeometry.has(pon)) return Promise.resolve(); const inFlight = loads.get(pon); if (inFlight) return inFlight; if (!canSelect() || !layoutOf(pon)) return Promise.resolve(); const at = epoch; const load = ctx.doc .page(page) .geometry.read() .then( (snapshot) =>{ loads.delete(pon); if (at !== epoch) return; rawGeometry.set(pon, snapshot); ctx.dispatch({ type: 'pageLoaded', page} ); const current = state().selection; if (current) recompute(current, 'system'); } , () =>{ loads.delete(pon); } , ); loads.set(pon, load); return load; } function orderedEnds(sel: SelectionRange):{ start: GlyphPointer; end: GlyphPointer; direction: 'forward' | 'backward'; } { const ai = pageIndexOf(sel.anchor.page.pageObjectNumber); const fi = pageIndexOf(sel.focus.page.pageObjectNumber); const anchorFirst = ai < fi || (ai === fi && sel.anchor.glyph <= sel.focus.glyph); return anchorFirst ?{ start: sel.anchor, end: sel.focus, direction: 'forward'} :{ start: sel.focus, end: sel.anchor, direction: 'backward'} ; } function clampPointer(ptr: GlyphPointer): GlyphPointer{ const geom = geometryFor(ptr.page.pageObjectNumber); if (!geom) return ptr; const max = Math.max(geom.layout.glyphs.length - 1, 0); const glyph = Math.max(0, Math.min(ptr.glyph, max)); return glyph === ptr.glyph ? ptr :{ page: ptr.page, glyph} ; } function publish( selection: SelectionRange | null, segments: Record, trigger: ChangeOrigin['trigger'], ): void{ const before = state(); if (selection) ctx.dispatch({ type: 'set', selection, segments} ); else ctx.dispatch({ type: 'clear'} ); if (state() === before) return; const origin = localOrigin(trigger); const model = readModel(); changed.emit({ range: model.snapshot.range, pages: model.pages, origin} ); if (!selection) cleared.emit({ origin} ); } function recompute(sel: SelectionRange, trigger: ChangeOrigin['trigger']): void{ const clamped: SelectionRange ={ anchor: clampPointer(sel.anchor), focus: clampPointer(sel.focus), } ; const{ start, end} = orderedEnds(clamped); const si = pageIndexOf(start.page.pageObjectNumber); const ei = pageIndexOf(end.page.pageObjectNumber); if (si < 0 || ei < 0){ publish(null, { } , trigger); return; } const segments: Record ={ } ; for (let i = si; i <= ei; i++){ const pon = ponAtIndex(i); if (pon == null) continue; const geom = geometryFor(pon); if (!geom){ void ensureLoaded(toPageRef(pon)); continue; } const from = i === si ? start.glyph : 0; const to = i === ei ? end.glyph : geom.layout.glyphs.length - 1; segments[pon] = textSegmentsForRange(geom.layout, from, to - from + 1).map((s) => toContentSegment(geom, s), ); } publish(clamped, segments, trigger); } const setGesture = (active: boolean): void => ctx.dispatch({ type: 'setGestureActive', active} ); const writeTrigger = (): ChangeOrigin['trigger'] => (state().gestureActive ? 'user' : 'api'); let model: ReadModel | null = null; function readModel(): ReadModel{ const s = state(); if (model?.state === s) return model; const pagesWithSegments = Object.keys(s.segments) .map(Number) .filter((pon) => (s.segments[pon]?.length ?? 0) > 0) .sort((a, b) => pageIndexOf(a) - pageIndexOf(b)); const pages = pagesWithSegments.map((pon) => toPageRef(pon)); const snapshotPages = pagesWithSegments.map((pon) => ({ page: toPageRef(pon), segments: s.segments[pon], } )); let snapshot: SelectionSnapshot; let anchor: SelectionAnchor | null = null; if (!s.selection){ snapshot ={ pages: snapshotPages, start: null, end: null, direction: 'forward', range: null, } ; } else{ const{ start, end, direction} = orderedEnds(s.selection); snapshot ={ pages: snapshotPages, start: endpointFor(s, start, 'start'), end: endpointFor(s, end, 'end'), direction, range:{ start:{ page: start.page, index: start.glyph} , end:{ page: end.page, index: end.glyph + 1} , } , } ; const endBounds = unionOf(s.segments[end.page.pageObjectNumber]); if (endBounds) anchor ={ page: end.page, bounds: endBounds} ; else{ const last = pagesWithSegments[pagesWithSegments.length - 1]; if (last != null) anchor ={ page: toPageRef(last), bounds: unionOf(s.segments[last])!} ; } } model ={ state: s, snapshot, pages: pages.length ? pages : EMPTY_PAGES, anchor, rects: new Map(), } ; return model; } function endpointFor( s: SelectionState, ptr: GlyphPointer, which: 'start' | 'end', ): SelectionEndpoint | null{ const segments = s.segments[ptr.page.pageObjectNumber] ?? EMPTY_SEGMENTS; if (!segments.length) return null; const segment = which === 'start' ? segments[0] : segments[segments.length - 1]; const geom = geometryFor(ptr.page.pageObjectNumber); const cell = geom ? textGlyphQuad(geom.layout, ptr.glyph) : null; if (geom && cell){ const glyphQuad = toContentTextQuad(geom, cell); return{ page: ptr.page, glyphQuad, advance: segment.advance, rect: textQuadBounds(glyphQuad), } ; } return{ page: ptr.page, glyphQuad: segment.quad, advance: segment.advance, rect: segment.rect, } ; } function unionOf(segments: readonly SelectionSegment[] | undefined): Rect | null{ if (!segments || segments.length === 0) return null; let x1 = Infinity; let y1 = Infinity; let x2 = -Infinity; let y2 = -Infinity; for (const s of segments){ x1 = Math.min(x1, s.rect.x); y1 = Math.min(y1, s.rect.y); x2 = Math.max(x2, s.rect.x + s.rect.width); y2 = Math.max(y2, s.rect.y + s.rect.height); } return{ x: x1, y: y1, width: x2 - x1, height: y2 - y1} ; } function select(input: SelectionRangeInput): void{ assertScope(SELECT_SCOPE, 'selection.select'); const range: TextRange = 'page' in input ?{ start:{ page: input.page, index: input.start} , end:{ page: input.page, index: input.start + input.count} , } : input; ctx.assertPageRef(range.start.page); ctx.assertPageRef(range.end.page); const si = pageIndexOf(range.start.page.pageObjectNumber); let ei = pageIndexOf(range.end.page.pageObjectNumber); let endIndex = range.end.index; if (ei < si || (ei === si && endIndex <= range.start.index)){ publish(null, { } , writeTrigger()); return; } if (endIndex === 0){ ei -= 1; if (ei < si){ publish(null, { } , writeTrigger()); return; } endIndex = OPEN_END; } const focusPon = ponAtIndex(ei); if (focusPon == null) return; recompute({ anchor:{ page: range.start.page, glyph: Math.max(0, range.start.index)} , focus:{ page: toPageRef(focusPon), glyph: endIndex - 1} , } , writeTrigger(), ); } function selectAll(): void{ assertScope(SELECT_SCOPE, 'selection.selectAll'); const pages = ctx.document()?.pages ?? []; if (pages.length === 0) return; recompute({ anchor:{ page: pages[0].ref, glyph: 0} , focus:{ page: pages[pages.length - 1].ref, glyph: OPEN_END} , } , writeTrigger(), ); } function selectPage(page: PageRef): void{ assertScope(SELECT_SCOPE, 'selection.selectPage'); ctx.assertPageRef(page); recompute({ anchor:{ page, glyph: 0} , focus:{ page, glyph: OPEN_END} } , writeTrigger()); } function selectSpanAt(page: PageRef, point: Point, expand: 'word' | 'line'): boolean{ assertScope(SELECT_SCOPE, `selection.select${ expand === 'word' ? 'WordAt' : 'LineAt'} `); const geom = geometryFor(page.pageObjectNumber); if (!geom) return false; const i = glyphAt(geom, point); if (i == null) return false; const [from, to] = expand === 'word' ? expandTextRangeToWord(geom.layout, i) : expandTextRangeToLine(geom.layout, i); recompute({ anchor:{ page, glyph: from} , focus:{ page, glyph: to} } , writeTrigger()); return true; } function extendTo(page: PageRef, point: Point): void{ assertScope(SELECT_SCOPE, 'selection.extendTo'); const current = state().selection; if (!current) return; const geom = geometryFor(page.pageObjectNumber); if (!geom){ void ensureLoaded(page); return; } const i = glyphAt(geom, point); if (i == null) return; recompute({ anchor: current.anchor, focus:{ page, glyph: i} } , writeTrigger()); } function clear(): void{ publish(null, { } , writeTrigger()); } function pageText(pon: PageObjectNumber): Promise{ let p = textSnapshots.get(pon); if (!p){ p = Promise.resolve(ctx.doc.page(toPageRef(pon)).text.read()); p.catch(() => textSnapshots.delete(pon)); textSnapshots.set(pon, p); } return p; } async function readTextInRange(range: TextRange, options?: OperationOptions): Promise{ assertScope(COPY_SCOPE, 'selection.readText'); ctx.assertPageRef(range.start.page); ctx.assertPageRef(range.end.page); const si = pageIndexOf(range.start.page.pageObjectNumber); let ei = pageIndexOf(range.end.page.pageObjectNumber); let endIndex = range.end.index; if (ei < si || (ei === si && endIndex <= range.start.index)) return ''; if (endIndex === 0){ ei -= 1; endIndex = OPEN_END; } const spans: Array<{ pon: PageObjectNumber; from: number; to: number} > = []; for (let i = si; i <= ei; i++){ const pon = ponAtIndex(i); if (pon == null) continue; spans.push({ pon, from: i === si ? Math.max(0, range.start.index) : 0, to: i === ei ? endIndex : OPEN_END, } ); } const parts: string[] = new Array(spans.length); for (let base = 0; base < spans.length; base += TEXT_READ_CONCURRENCY){ throwIfAborted(options?.signal); const batch = spans.slice(base, base + TEXT_READ_CONCURRENCY); const snapshots = await Promise.all(batch.map((s) => pageText(s.pon))); snapshots.forEach((snap, j) =>{ parts[base + j] = sliceTextByChars(snap, batch[j].from, batch[j].to); } ); } throwIfAborted(options?.signal); return parts.join('\n'); } function throwIfAborted(signal: AbortSignal | undefined): void{ if (signal?.aborted){ throw new PluginError('operation-cancelled', 'selection', 'selection.readText was cancelled'); } } function onPagesUpdated(): void{ const alive = new Set((ctx.document()?.pages ?? []).map((p) => p.ref.pageObjectNumber)); for (const pon of [...rawGeometry.keys()]){ if (!alive.has(pon)){ rawGeometry.delete(pon); derived.delete(pon); textSnapshots.delete(pon); } } const current = state().selection; if (current) recompute(current, 'system'); } function invalidateContent(): void{ epoch++; rawGeometry.clear(); derived.clear(); loads.clear(); textSnapshots.clear(); publish(null, { } , 'system'); } const api: SelectionHostCapability ={ canSelect, canCopy, select, selectAll, selectPage, selectWordAt: (page, point) => selectSpanAt(page, point, 'word'), selectLineAt: (page, point) => selectSpanAt(page, point, 'line'), extendTo, clear, hasSelection: () => state().selection != null, getSnapshot: () => readModel().snapshot, getRange: () => readModel().snapshot.range, listSelectedPages: () => readModel().pages, listSegments: (page) => state().segments[page.pageObjectNumber] ?? EMPTY_SEGMENTS, listRects: (page) =>{ const{ rects} = readModel(); const pon = page.pageObjectNumber; let hit = rects.get(pon); if (!hit){ hit = (state().segments[pon] ?? EMPTY_SEGMENTS).map((s) => s.rect); rects.set(pon, hit); } return hit; } , getAnchor: () => readModel().anchor, readText: (options) =>{ const range = readModel().snapshot.range; return range ? readTextInRange(range, options) : Promise.resolve(''); } , readTextInRange, onChanged: changed.on, onCommitted: committed.on, onCleared: cleared.on, ensureLoaded, isLoaded: (page) => !!state().loaded[page.pageObjectNumber], isOverText: (page, point) =>{ const geom = geometryFor(page.pageObjectNumber); return geom ? glyphAt(geom, point) != null : false; } , beginGesture: () => setGesture(true), beginGestureAt: (page, point) =>{ if (!canSelect()) return false; const geom = geometryFor(page.pageObjectNumber); if (!geom) return false; const i = glyphAt(geom, point); if (i == null) return false; setGesture(true); recompute({ anchor:{ page, glyph: i} , focus:{ page, glyph: i} } , 'user'); return true; } , endGesture: () =>{ setGesture(false); const range = readModel().snapshot.range; if (range) committed.emit({ range} ); } , isGestureActive: () => state().gestureActive, setHighlightVisible: (visible) => ctx.dispatch({ type: 'setHighlightHidden', hidden: !visible} ), isHighlightVisible: () => !state().highlightHidden, } ; return{ api, connect(){ let lastRevision = ctx.document()?.revision ?? -1; ctx.cleanup( ctx.subscribe(() =>{ const revision = ctx.document()?.revision; if (revision === undefined || revision === lastRevision) return; lastRevision = revision; onPagesUpdated(); } ), ); ctx.listen(ctx.doc.events, (event) =>{ if (event.type === 'redaction.applied' || event.type === 'pages.flattened'){ invalidateContent(); } } ); } , } ; } createTextSelectHandler [FunctionDeclaration] (from packages/plugin/selection/src/handler.ts): export function createTextSelectHandler( selection: SelectionHostCapability, interaction: InteractionHostCapability, feedback?: PlatformFeedback, options: TextSelectHandlerOptions ={ } , ): InteractionHandler{ const dragThreshold = options.dragThreshold ?? DEFAULT_DRAG_THRESHOLD; let anchor:{ page: PageRef; point:{ x: number; y: number} ; vx: number; vy: number} | null = null; let dragging = false; return{ id: 'text-select', priority: 60, enabledFor: (tool) => tool.enables.has('text-select'), onDown: (s) =>{ anchor = null; dragging = false; if (!s.page) return false; if (!selection.canSelect()) return false; const{ ref: page, point} = s.page; const clicks = s.clickCount ?? 1; selection.beginGesture(); if (clicks >= 3){ selection.selectLineAt(page, point); return true; } if (clicks === 2){ const selected = selection.selectWordAt(page, point); if (selected && s.gesture === 'long-press') feedback?.selection(); return true; } selection.clear(); if (!selection.isOverText(page, point)){ selection.endGesture(); return false; } anchor ={ page, point, vx: s.viewport.x, vy: s.viewport.y} ; return true; } , onMove: (s) =>{ if (!s.page || !anchor) return; if (!dragging){ if (Math.hypot(s.viewport.x - anchor.vx, s.viewport.y - anchor.vy) < dragThreshold){ return; } dragging = true; selection.beginGestureAt(anchor.page, anchor.point); } selection.extendTo(s.page.ref, s.page.point); } , onUp: () =>{ anchor = null; dragging = false; selection.endGesture(); } , onCancel: () =>{ anchor = null; dragging = false; selection.clear(); selection.endGesture(); } , onHover: (s) =>{ if (!s.page){ interaction.claimCursor(CURSOR_TOKEN, null); return; } void selection.ensureLoaded(s.page.ref); const overText = selection.isOverText(s.page.ref, s.page.point); interaction.claimCursor(CURSOR_TOKEN, overText ? 'text' : null, 10); } , } ; } initialSelectionState [VariableDeclaration] (from packages/plugin/selection/src/model.ts): initialSelectionState = (): SelectionState => ({ selection: null, segments:{ } , loaded:{ } , highlightHidden: false, gestureActive: false, } ) reduceSelection [FunctionDeclaration] (from packages/plugin/selection/src/model.ts): export function reduceSelection(state: SelectionState, action: SelectionAction): SelectionState{ switch (action.type){ case 'pageLoaded':{ const pon = action.page.pageObjectNumber; return state.loaded[pon] ? state :{ ...state, loaded:{ ...state.loaded, [pon]: true} } ; } case 'set': return{ ...state, selection: action.selection, segments: action.segments} ; case 'clear': return state.selection === null && Object.keys(state.segments).length === 0 ? state :{ ...state, selection: null, segments:{ } } ; case 'setHighlightHidden': return state.highlightHidden === action.hidden ? state :{ ...state, highlightHidden: action.hidden} ; case 'setGestureActive': return state.gestureActive === action.active ? state :{ ...state, gestureActive: action.active} ; default: return state; } } toContentSegment [FunctionDeclaration] (from packages/plugin/selection/src/geometry.ts): export function toContentSegment( geom: SelectionPageGeometry, segment: PdfTextSegment, ): SelectionSegment{ const quad = toContentTextQuad(geom, segment.quad); return{ quad, rect: textQuadBounds(quad), advance: segment.advance} ; } toContentTextQuad [FunctionDeclaration] (from packages/plugin/selection/src/geometry.ts): export function toContentTextQuad(geom: SelectionPageGeometry, quad: PdfQuad): TextQuad{ const pt = (p: PdfPoint): Point => applyPoint(geom.toContent, p as PointIn<'pdf'>); return{ upperStart: pt(quad.p1), upperEnd: pt(quad.p2), lowerStart: pt(quad.p3), lowerEnd: pt(quad.p4), } ; }