# @embedpdf/core-annotation — . AnchorMode [InterfaceDeclaration] (from packages/core/annotation/src/anchor.ts): export interface AnchorMode{ zoom: boolean; upright: boolean; } AnnotationFlags [InterfaceDeclaration] (from packages/engine/core/src/annotation/primitives.ts): export interface AnnotationFlags{ invisible: boolean; hidden: boolean; print: boolean; noZoom: boolean; noRotate: boolean; noView: boolean; readOnly: boolean; locked: boolean; toggleNoView: boolean; lockedContents: boolean; } AnnotationKind [InterfaceDeclaration] (from packages/core/annotation/src/kinds/define.ts): export interface AnnotationKind{ readonly name: string; readonly family: ShapeFamily; readonly style: (annotation: Annotation) => Style; readonly text?: (annotation: Annotation) => TextStyle; readonly caps: KindCaps; readonly properties: readonly AnnotationProperty[]; } AnnotationOption [InterfaceDeclaration] (from packages/core/annotation/src/kinds/define.ts): export interface AnnotationOption{ readonly value: string; readonly label: string; readonly labelKey: string; } AnnotationProperty [TypeAliasDeclaration] (from packages/core/annotation/src/kinds/define.ts): export type AnnotationProperty = |{ readonly key: 'color' | 'interiorColor' | 'fontColor'; readonly control: 'color'; readonly label: string; readonly labelKey: string; readonly allowsNone?: boolean; } |{ readonly key: 'opacity' | 'strokeWidth' | 'fontSize'; readonly control: 'number'; readonly label: string; readonly labelKey: string; readonly min: number; readonly max: number; readonly step: number; } |{ readonly key: 'borderStyle'; readonly control: 'choice'; readonly label: string; readonly labelKey: string; readonly options: readonly AnnotationOption[]; readonly cloudy: boolean; } |{ readonly key: 'lineEndings' | 'fontFamily' | 'textAlign' | 'blendMode' | 'icon' | 'subtype'; readonly control: 'choice'; readonly label: string; readonly labelKey: string; readonly options: readonly AnnotationOption[]; } |{ readonly key: 'orientation'; readonly control: 'choice'; readonly label: string; readonly labelKey: string; readonly options: readonly AnnotationOption[]; } |{ readonly key: FlagKey; readonly control: 'flag'; readonly label: string; readonly labelKey: string; } |{ readonly key: 'overlayText'; readonly control: 'text'; readonly label: string; readonly labelKey: string; } |{ readonly key: 'bold' | 'italic' | 'underline'; readonly control: 'textFormat'; readonly label: string; readonly labelKey: string; readonly format: 'bold' | 'italic' | 'underline'; } |{ readonly key: 'link'; readonly control: 'link'; readonly label: string; readonly labelKey: string; } ; AnnotationView [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface AnnotationView{ byId: Record; order: Id[]; } BlendMode [TypeAliasDeclaration] (from packages/engine/core/src/annotation/primitives.ts): export type BlendMode = | 'normal' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity'; BoxShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/box.ts): export interface BoxShape extends TurnedBox{ kind: 'box'; ellipse: boolean; } CalloutLine [TypeAliasDeclaration] (from packages/core/annotation/src/shapes/text-box.ts): export type CalloutLine = NonNullable; CaretShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/caret.ts): export interface CaretShape extends TurnedBox{ kind: 'caret'; } ChangeSet [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface ChangeSet{ readonly put: readonly ModelAnnotation[]; readonly drop: readonly Id[]; readonly patches: Readonly>; } ChromeGeometry [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface ChromeGeometry{ handleTol: number; knobTol: number; knobOffset: number; rotationHandle?: boolean; } ChromeNode [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type ChromeNode = |{ kind: 'outline'; rect: Rect} |{ kind: 'obb'; corners: [Point, Point, Point, Point]; angle: number} |{ kind: 'handle'; at: Point; cursor: Cursor; rot?: number; role: HandleRole; active: boolean; } |{ kind: 'rotate-knob'; at: Point; from: Point} |{ kind: 'guide'; axis: 'x' | 'y'; at: number; lo: number; hi: number} |{ kind: 'rotate-guides'; center: Point; angle: number; lines: Array<{ a: Point; b: Point; role: 'axis' | 'indicator'} >; } |{ kind: 'marquee'; rect: Rect} ; ClickCreate [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type ClickCreate = |{ width: number; height: number; anchor?: 'center' | 'top-left'} |{ length: number; rotation?: number; anchor?: 'center' | 'start' | 'end'} ; Corners [TypeAliasDeclaration] (from packages/core/annotation/src/shapes/family.ts): export type Corners = [Point, Point, Point, Point]; CreationDraftAnchor [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface CreationDraftAnchor{ kind: 'poly'; subtype: PolySubtype; page: PageRef; bounds: Rect; pointCount: number; minPoints: number; canFinish: boolean; } Cursor [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Cursor = string; DEFAULT_CHROME_GEOMETRY [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): DEFAULT_CHROME_GEOMETRY ={ handleTol: 6, knobTol: 6, knobOffset: ROTATE_KNOB_OFFSET, } as const DRAWN_FLAGS [VariableDeclaration] (from packages/core/annotation/src/flags.ts): DRAWN_FLAGS: AnnotationFlags ={ ...NO_ANNOTATION_FLAGS, print: true} DistanceAppearance [TypeAliasDeclaration] (from packages/core/annotation/src/measurement.ts): export type DistanceAppearance ={ intent: 'line-dimension'} & Pick< LineAnnotation, 'measure' | 'captionEnabled' | 'captionPosition' | 'captionOffset' | 'leader' | 'contents' >; DistanceCaptionLayout [InterfaceDeclaration] (from packages/core/annotation/src/measurement.ts): export interface DistanceCaptionLayout{ text: string; center: Point; along: Point; normal: Point; width: number; height: number; bounds: QuadRing; } DistanceLayout [InterfaceDeclaration] (from packages/core/annotation/src/measurement.ts): export interface DistanceLayout{ along: Point; normal: Point; length: number; measuredStart: Point; measuredEnd: Point; dimensionStart: Point; dimensionEnd: Point; dimensionSegments: DistanceSegment[]; leaderSegments: DistanceSegment[]; captionConnector: DistanceSegment[]; caption: DistanceCaptionLayout | null; arrowPlacement: 'inside' | 'outside'; endings: RenderNode[]; selectionPoints: Point[]; visualBounds: Rect; } DistanceSegment [InterfaceDeclaration] (from packages/core/annotation/src/measurement.ts): export interface DistanceSegment{ from: Point; to: Point; } Draft [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Draft = |{ kind: 'create-rect'; subtype: KindName; preset?: string; page: PageRef; from: Point; to: Point; displayRotation?: Rotation; upright?: boolean; clickCreate?: ClickCreate | false; flags?: Partial; } |{ kind: 'create-distance'; step: 'endpoints' | 'offset'; subtype: 'line'; preset: string; page: PageRef; from: Point; to: Point; measure: DistanceAppearance; flags?: Partial; } |{ kind: 'create-line'; measure?: MeasurementAppearance; capture?: string; subtype: KindName; preset?: string; page: PageRef; from: Point; to: Point; displayRotation?: Rotation; upright?: boolean; clickCreate?: ClickCreate | false; flags?: Partial; } |{ kind: 'create-poly'; measure?: ShapeMeasurementAppearance; subtype: KindName; preset?: string; page: PageRef; points: Point[]; current: Point; closed: boolean; flags?: Partial; } |{ kind: 'create-ink'; subtype: KindName; preset?: string; page: PageRef; strokes: Point[][]; drawing?: boolean; intent?: InkIntent; flags?: Partial; } |{ kind: 'create-callout'; subtype: KindName; preset?: string; page: PageRef; step: 'knee' | 'box'; tip: Point; knee?: Point; current: Point; boxFrom?: Point; boxTo?: Point; pageBox?: Rect; displayRotation?: Rotation; upright?: boolean; flags?: Partial; } |{ kind: 'move'; ids: Id[]; start: Point; delta: Point; guides: Guide[]} |{ kind: 'handle'; id: Id; handle: string; base: Shape; current: Shape; view?: ViewEnv; } |{ kind: 'rotate'; ids: Id[]; pivot: Point; start: Point; current: Point; free?: boolean; view?: ViewEnv; } |{ kind: 'group'; op: 'resize'; ids: Id[]; handle: string; anchor: Point; base: Rect; current: Rect; view?: ViewEnv; } |{ kind: 'caption'; id: Id; start: Point; delta: Point} |{ kind: 'leader'; id: Id; start: Point; delta: number} |{ kind: 'marquee'; page: PageRef; from: Point; to: Point} ; DrawState [TypeAliasDeclaration] (from packages/core/annotation/src/appearance.ts): export type DrawState = Pick; EMPTY_CHANGE [VariableDeclaration] (from packages/core/annotation/src/update/index.ts): EMPTY_CHANGE: ChangeSet ={ put: [], drop: [], patches:{ } } EditableKind [TypeAliasDeclaration] (from packages/core/annotation/src/editable.ts): export type EditableKind = AnnotationSubtype | MeasurementIntent; EditableKinds [TypeAliasDeclaration] (from packages/core/annotation/src/editable.ts): export type EditableKinds = boolean | readonly EditableKind[]; Effect [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Effect = |{ type: 'captured'; tool: string; page: PageRef; geometry: Shape} |{ type: 'create'; id: Id; draft: AnnotationDraft} |{ type: 'patch'; id: Id; patch: AnnotationPatch} |{ type: 'text'; id: Id} |{ type: 'syncLink'; id: Id; target: PdfLinkTarget | null} |{ type: 'delete'; id: Id} ; FLAG_KEYS [VariableDeclaration] (from packages/core/annotation/src/flags.ts): FLAG_KEYS = Object.keys(NO_ANNOTATION_FLAGS) as ReadonlyArray FLAG_PROPERTIES [VariableDeclaration] (from packages/core/annotation/src/kinds/fields.ts): FLAG_PROPERTIES: readonly AnnotationProperty[] = [{ key: 'print', control: 'flag', label: 'Print', labelKey: 'annotation.flags.print'} , { key: 'hidden', control: 'flag', label: 'Hidden', labelKey: 'annotation.flags.hidden'} , { key: 'noView', control: 'flag', label: 'No view', labelKey: 'annotation.flags.noView'} , { key: 'toggleNoView', control: 'flag', label: 'Toggle no view', labelKey: 'annotation.flags.toggleNoView', } , { key: 'readOnly', control: 'flag', label: 'Read only', labelKey: 'annotation.flags.readOnly'} , { key: 'locked', control: 'flag', label: 'Locked', labelKey: 'annotation.flags.locked'} , { key: 'lockedContents', control: 'flag', label: 'Locked contents', labelKey: 'annotation.flags.lockedContents', } , { key: 'noZoom', control: 'flag', label: 'No zoom', labelKey: 'annotation.flags.noZoom'} , { key: 'noRotate', control: 'flag', label: 'No rotate', labelKey: 'annotation.flags.noRotate'} , { key: 'invisible', control: 'flag', label: 'Invisible', labelKey: 'annotation.flags.invisible'} , ] FieldValues [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type FieldValues = Readonly>; FlagBearer [InterfaceDeclaration] (from packages/core/annotation/src/flags.ts): export interface FlagBearer{ annotation: Annotation; authority?:{ update: boolean; delete: boolean} ; } FlagKey [TypeAliasDeclaration] (from packages/core/annotation/src/kinds/define.ts): export type FlagKey = | 'invisible' | 'hidden' | 'print' | 'noZoom' | 'noRotate' | 'noView' | 'readOnly' | 'locked' | 'toggleNoView' | 'lockedContents'; FontLookup [TypeAliasDeclaration] (from packages/core/annotation/src/richtext.ts): export type FontLookup = () => readonly NamedFont[]; GestureForm [TypeAliasDeclaration] (from packages/core/annotation/src/placement.ts): export type GestureForm = 'box' | 'segment'; GroupCaps [InterfaceDeclaration] (from packages/core/annotation/src/group.ts): export interface GroupCaps{ movable: boolean; resizable: boolean; rotatable: boolean; } Guide [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface Guide{ axis: 'x' | 'y'; at: number; lo: number; hi: number; } Handle [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface Handle{ id: string; at: Point; cursor: Cursor; } HandleRole [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type HandleRole = 'corner' | 'side' | 'point'; Id [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Id = string; InkShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/points.ts): export interface InkShape{ kind: 'ink'; inkList: Point[][]; rotation: number; drawing?: boolean; } InkStraightenOptions [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface InkStraightenOptions{ deviationThreshold: number; axisSnapDegrees: number; } KINDS [VariableDeclaration] (from packages/core/annotation/src/kinds/index.ts): KINDS: Readonly> ={ [square.name]: square, [circle.name]: circle, [line.name]: line, [polygon.name]: polygon, [polyline.name]: polyline, [ink.name]: ink, [freeText.name]: freeText, [freeTextCallout.name]: freeTextCallout, [highlight.name]: highlight, [underline.name]: underline, [squiggly.name]: squiggly, [strikeout.name]: strikeout, [caret.name]: caret, [redact.name]: redact, [textNote.name]: textNote, [fileAttachment.name]: fileAttachment, [stamp.name]: stamp, [link.name]: link, [widgetText.name]: widgetText, [widgetChoice.name]: widgetChoice, [widgetButton.name]: widgetButton, [widgetToggle.name]: widgetToggle, [widgetRadio.name]: widgetRadio, [widgetBox.name]: widgetBox, [widgetMark.name]: widgetMark, } KindCaps [InterfaceDeclaration] (from packages/core/annotation/src/kinds/define.ts): export interface KindCaps{ selectable: boolean; movable: boolean; resizable: boolean; vertexEditable: boolean; rotatable: boolean; quarterTurns: boolean; groupMovable: boolean; groupResizable: boolean; groupRotatable: boolean; textEditable: boolean; commentable: boolean; hasPopup: boolean; anchored: boolean; paintsBeneath: boolean; hasFill: boolean; hasEndings: boolean; hasCloudy: boolean; opaqueBody: boolean; rasterOnly: boolean; ignoresReadOnly: boolean; noZoom: boolean; noRotate: boolean; } KindName [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type KindName = | 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'square' | 'circle' | 'line' | 'polygon' | 'polyline' | 'caret' | 'ink' | 'stamp' | 'text' | 'file-attachment' | 'redact' | 'link' | (string &{ } ); LINE_ENDING_NAMES [VariableDeclaration] (from packages/core/annotation/src/kinds/fields.ts): LINE_ENDING_NAMES = [ 'none', 'square', 'circle', 'diamond', 'open-arrow', 'closed-arrow', 'butt', 'r-open-arrow', 'r-closed-arrow', 'slash', ] as const LineEnding [TypeAliasDeclaration] (from packages/engine/core/src/annotation/primitives.ts): export type LineEnding = | 'none' | 'square' | 'circle' | 'diamond' | 'open-arrow' | 'closed-arrow' | 'butt' | 'r-open-arrow' | 'r-closed-arrow' | 'slash'; LineEndings [InterfaceDeclaration] (from packages/engine/core/src/annotation/primitives.ts): export interface LineEndings{ start: LineEnding; end: LineEnding; } LineShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/points.ts): export interface LineShape{ kind: 'line'; linePoints:{ start: Point; end: Point} ; lineEndings?: LineEndings; rotation: number; } MIN_DRAG [VariableDeclaration] (from packages/core/annotation/src/placement.ts): MIN_DRAG = 3 MITER_LIMIT [VariableDeclaration] (from packages/core/annotation/src/shapes/points.ts): MITER_LIMIT = 10 MeasurementAppearance [TypeAliasDeclaration] (from packages/core/annotation/src/measurement.ts): export type MeasurementAppearance = DistanceAppearance | ShapeMeasurementAppearance; MeasurementIntent [TypeAliasDeclaration] (from packages/core/annotation/src/editable.ts): export type MeasurementIntent = 'line-dimension' | 'polyline-dimension' | 'polygon-dimension'; Message [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Message = |{ type: 'editPointer'; phase: 'down' | 'move' | 'up'; in: PointerInput} |{ type: 'marqueePointer'; phase: 'down' | 'move' | 'up'; in: PointerInput} |{ type: 'createPointer'; measure?: MeasurementAppearance; capture?: string; phase: 'down' | 'move' | 'up'; subtype: KindName; preset?: string; intent?: InkIntent; clickCreate?: ClickCreate | false; flags?: Partial; deferInkCommit?: boolean; straightenInk?: InkStraightenOptions; in: PointerInput; } |{ type: 'finishInkDraft'} |{ type: 'finishCreationDraft'} |{ type: 'createCaret'; page: PageRef; anchor: TextEndAnchor; flags?: Partial; } |{ type: 'createReplaceText'; page: PageRef; quads: Quad[]; anchor: TextEndAnchor; preset?: string; } |{ type: 'createMarkup'; subtype: KindName; page: PageRef; quads: Quad[]; preset?: string; flags?: Partial; } |{ type: 'setMarkupPreview'; subtype: KindName; quadsByPage: Record; preset?: string; } |{ type: 'clearMarkupPreview'} |{ type: 'deselect'; ids?: Id[]} |{ type: 'hover'; id: Id | null} |{ type: 'select'; ids: Id[]; add?: boolean} |{ type: 'setFields'; patches: Readonly>} |{ type: 'setTextFormat'; format: 'bold' | 'italic' | 'underline'; on: boolean} |{ type: 'setLink'; target: PdfLinkTarget | null} |{ type: 'setFlags'; patch: Partial; ids?: Id[]} |{ type: 'setDefaults'; preset: string; patch: FieldValues} |{ type: 'replaceDefaults'; preset: string; defaults: FieldValues} |{ type: 'setSnap'; patch: Partial} |{ type: 'rotateSelection'; degrees: 90 | -90; pageBoxes?: PageBoxes} |{ type: 'resetRotation'; pageBoxes?: PageBoxes} |{ type: 'delete'} |{ type: 'cancel'} |{ type: 'forget'; ids: Id[]} |{ type: 'beginTextEdit'; id: Id} |{ type: 'setText'; id: Id; text: string} |{ type: 'setRichText'; id: Id; doc: RichTextDocumentInput} |{ type: 'endTextEdit'} ; Model [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Model = Session & AnnotationView; ModelAnnotation [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface ModelAnnotation{ id: Id; unconfirmed?: true; source: 'baked' | 'vector'; apBox?: Rect; apRot?: number; pictureVersion?: number; painter?: (box: Rect) => readonly SceneNode[]; authority?:{ update: boolean; delete: boolean} ; annotation: Annotation; } NO_ANNOTATION_FLAGS [VariableDeclaration] (from packages/engine/core/src/annotation/primitives.ts): NO_ANNOTATION_FLAGS: AnnotationFlags ={ invisible: false, hidden: false, print: false, noZoom: false, noRotate: false, noView: false, readOnly: false, locked: false, toggleNoView: false, lockedContents: false, } NO_CAPS [VariableDeclaration] (from packages/core/annotation/src/kinds/define.ts): NO_CAPS: KindCaps ={ selectable: false, movable: false, resizable: false, vertexEditable: false, rotatable: false, quarterTurns: false, groupMovable: false, groupResizable: false, groupRotatable: false, textEditable: false, commentable: false, hasPopup: false, anchored: false, paintsBeneath: false, hasFill: false, hasEndings: false, hasCloudy: false, opaqueBody: false, rasterOnly: false, ignoresReadOnly: false, noZoom: false, noRotate: false, } NamedFont [InterfaceDeclaration] (from packages/core/annotation/src/richtext.ts): export interface NamedFont{ readonly key: string; readonly familyName: string; readonly weight: number; readonly italic: boolean; } PageBoxes [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type PageBoxes = Readonly>; Paint [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface Paint{ fill?: string; stroke?: string; width?: number; opacity?: number; dash?: number[]; blend?: Exclude; lineCap?: 'round'; join?: 'round'; fillRule?: 'evenodd'; hairline?: true; } PaintedPiece [TypeAliasDeclaration] (from packages/core/annotation/src/painted.ts): export type PaintedPiece = |{ readonly kind: 'stroke'; readonly points: readonly Point[]; readonly closed: boolean; readonly halfWidth: number; } |{ readonly kind: 'area'; readonly ring: readonly Point[]} |{ readonly kind: 'oval'; readonly center: Point; readonly rx: number; readonly ry: number; readonly rotation: number; readonly halfWidth: number; readonly filled: boolean; } ; Placement [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Placement = |{ kind: 'box'; rect: Rect; rot: number} |{ kind: 'segment'; a: Point; b: Point} ; PlacementFrame [InterfaceDeclaration] (from packages/core/annotation/src/placement.ts): export interface PlacementFrame{ pageBox?: Rect; upright?: boolean; displayRotation?: Rotation; } Point [InterfaceDeclaration] (from packages/core/geometry/src/index.ts): export interface Point{ x: number; y: number; } PointerInput [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface PointerInput{ page: PageRef; point: Point; shift: boolean; finish?: boolean; pageBox?: Rect; chrome?: ChromeGeometry; displayRotation?: Rotation; scale?: number; zoom?: number; upright?: boolean; inert?: ReadonlySet; } PointsShape [TypeAliasDeclaration] (from packages/core/annotation/src/shapes/points.ts): export type PointsShape = LineShape | PolyShape | InkShape; PolyShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/points.ts): export interface PolyShape{ kind: 'poly'; vertices: Point[]; closed: boolean; lineEndings?: LineEndings; captionCenter?: Point | null; rotation: number; } Quad [InterfaceDeclaration] (from packages/core/geometry/src/index.ts): export interface Quad{ upperLeft: Point; upperRight: Point; lowerLeft: Point; lowerRight: Point; } QuadRing [TypeAliasDeclaration] (from packages/core/geometry/src/index.ts): export type QuadRing = [Point, Point, Point, Point]; QuadsShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/quads.ts): export interface QuadsShape{ kind: 'quads'; quadPoints: Quad[]; } RECT_HANDLES [VariableDeclaration] (from packages/core/annotation/src/rect.ts): RECT_HANDLES: RectHandle[] = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'] ROTATE_KNOB_OFFSET [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): ROTATE_KNOB_OFFSET = 24 Rect [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Rect = GeometryRect; RectHandle [TypeAliasDeclaration] (from packages/core/annotation/src/rect.ts): export type RectHandle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w'; RenderItem [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface RenderItem{ id: Id; ref: AnnotationRef | null; annotation?: Annotation; subtype: KindName; geometry: Shape; box: Rect; apBox?: Rect; apRot?: number; style: Style; text?: TextStyle; source: 'baked' | 'vector' | 'draft' | 'ghost'; pictureVersion?: number; lentScene?: () => readonly SceneNode[]; ghostOpacity?: number; selected: boolean; hovered?: boolean; label?:{ text: string; repeat: boolean; fonts?: PaintFonts} ; frame:{ box: Rect; rotation: number; scale: number} ; raster:{ box: Rect; rotation: number} | null; icon?: NoteIcon | FileAttachmentIcon; measure?: MeasurementAppearance; rot?: number; blend?: Exclude; } RenderNode [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type RenderNode = |{ kind: 'rect'; rect: Rect} |{ kind: 'ellipse'; rect: Rect} |{ kind: 'line'; a: Point; b: Point} |{ kind: 'poly'; points: Point[]; closed: boolean} |{ kind: 'path'; d: string} ; RichTextRange [InterfaceDeclaration] (from packages/core/annotation/src/richtext.ts): export interface RichTextRange{ start: number; end: number; } RichTextStyleDelta [TypeAliasDeclaration] (from packages/core/annotation/src/richtext.ts): export type RichTextStyleDelta = Partial; RotationAnchor [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface RotationAnchor{ page: PageRef; at: Point; angle: number; } SceneFontProgram [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface SceneFontProgram{ readonly family: string; readonly weight: number; readonly style: 'normal' | 'italic'; load(): Promise; } SceneNode [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type SceneNode = ( |{ kind: 'rect'; rect: Rect; paint: Paint} |{ kind: 'ellipse'; rect: Rect; paint: Paint} |{ kind: 'line'; a: Point; b: Point; paint: Paint} |{ kind: 'poly'; points: Point[]; closed: boolean; paint: Paint} |{ kind: 'path'; d: string; paint: Paint} |{ kind: 'text'; at: Point; text: string; fontSize: number; fontFamily?: string; rotation?: number; program?: SceneFontProgram; paint: Paint; } |{ kind: 'textRun'; at: Point; text: string; rtl: boolean; plain: boolean; joinsPrevious?: boolean; joinsNext?: boolean; fontSize: number; fontFamily: string; fontWeight?: number; fontStyle?: 'normal' | 'italic'; rotation?: number; program?: SceneFontProgram; paint: Paint; } ) &{ clip?: Rect; } ; SelectionFrame [InterfaceDeclaration] (from packages/core/annotation/src/selection.ts): export interface SelectionFrame{ corners: QuadRing; center: Point; angle: number; } Session [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface Session{ selected: Id[]; hovered: Id | null; draft: Draft | null; preview: MarkupPreview | null; objectNumbers: readonly number[]; defaults: Record; hitMargin: number; editing: Id | null; snap: SnapSettings; editable: EditableKinds; } Shape [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type Shape = | BoxShape | PointsShape | QuadsShape | CaretShape | TextBoxShape; ShapeFamily [InterfaceDeclaration] (from packages/core/annotation/src/shapes/family.ts): export interface ShapeFamily{ read(annotation: Annotation): S; write(shape: S, subtype: string): FieldValues; placed(placement: Placement, annotation: Annotation): S | null; bounds(shape: S): Rect; drawnBounds(shape: S, stroke: Stroke): Rect; rect(shape: S, stroke: Stroke): Rect; selectionBounds(shape: S, stroke: Stroke): Rect; oriented(shape: S): boolean; turnedCorners(shape: S, stroke: Stroke): Corners | null; pivot(shape: S): Point; translate(shape: S, delta: Point): S; rotateAbout(shape: S, pivot: Point, degrees: number): S; scaleAbout(shape: S, anchor: Point, sx: number, sy: number, minSize?: number): S; upright(shape: S, pivot?: Point): S; handles(shape: S): Handle[]; drag(shape: S, handle: string, to: Point): S; painted(shape: S, stroke: Stroke, filled: boolean): PaintedPiece[]; scene(shape: S, stroke: Stroke): RenderNode[]; } ShapeMeasurementAppearance [TypeAliasDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export type ShapeMeasurementAppearance ={ intent: 'polyline-dimension' | 'polygon-dimension'; } & Pick; ShapeMeasurementLayout [InterfaceDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export interface ShapeMeasurementLayout{ caption: DistanceCaptionLayout | null; visualBounds: Rect; selectionPoints: Point[]; } SnapResult [InterfaceDeclaration] (from packages/core/annotation/src/snap.ts): export interface SnapResult{ delta: Point; guides: Guide[]; } SnapSettings [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface SnapSettings{ readonly alignment: boolean; readonly alignmentThresholdPx: number; readonly rotation: boolean; readonly rotationAngles: readonly number[]; readonly rotationThresholdDeg: number; } Stroke [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface Stroke{ strokeWidth: number; cloudyIntensity?: number | null; } Style [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface Style{ color: Color | null; interiorColor: Color | null; strokeWidth: number; opacity: number; blendMode: BlendMode; borderStyle: AnnotationBorderStyle; dashArray: number[] | null; cloudyIntensity: number | null; } Target [TypeAliasDeclaration] (from packages/core/annotation/src/hit.ts): export type Target = |{ kind: 'handle'; id: Id; handle: string; cursor: Cursor} |{ kind: 'rotate'; ids: Id[]; pivot: Point} |{ kind: 'group-handle'; ids: Id[]; handle: string; cursor: Cursor; box: Rect} |{ kind: 'annot'; id: Id} |{ kind: 'empty'} ; TextAlign [TypeAliasDeclaration] (from packages/core/annotation/src/types.ts): export type TextAlign = 'left' | 'center' | 'right'; TextBox [InterfaceDeclaration] (from packages/core/annotation/src/view.ts): export interface TextBox{ id: Id; box: Rect; editing: boolean; rot?: number; } TextBoxShape [InterfaceDeclaration] (from packages/core/annotation/src/shapes/text-box.ts): export interface TextBoxShape extends TurnedBox{ kind: 'text-box'; calloutLine: CalloutLine | null; lineEnding: LineEnding | null; } TextEndAnchor [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface TextEndAnchor{ glyphQuad: Quad; advance: 1 | -1; } TextStyle [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface TextStyle{ fontFamily: string; fontSize: number; fontColor: Color; textAlign: TextAlign; bold?: boolean; italic?: boolean; underline?: boolean; } TurnedBox [InterfaceDeclaration] (from packages/core/annotation/src/shapes/box.ts): export interface TurnedBox{ box: Rect; rotation: number; } UpdateResult [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface UpdateResult{ readonly session: Session; readonly change: ChangeSet; readonly effects: readonly Effect[]; } ViewEnv [InterfaceDeclaration] (from packages/core/annotation/src/types.ts): export interface ViewEnv{ zoom: number; rotation: Rotation; } anchorModeOf [FunctionDeclaration] (from packages/core/annotation/src/anchor.ts): export function anchorModeOf(record: FlagBearer): AnchorMode | null{ const caps = kindOf(record.annotation).caps; const zoom = !!record.annotation.noZoom || caps.noZoom; const upright = !!record.annotation.noRotate || caps.noRotate; return zoom || upright ?{ zoom, upright} : null; } anchorOf [VariableDeclaration] (from packages/core/annotation/src/anchor.ts): anchorOf = (geometry: Shape): Point =>{ const rect = geomBounds(geometry); return{ x: rect.x, y: rect.y} ; } anchoredBox [FunctionDeclaration] (from packages/core/annotation/src/anchor.ts): export function anchoredBox( box:{ x: number; y: number; width: number; height: number} , anchor: Point, mode: AnchorMode | null, view: ViewEnv | undefined, ):{ box:{ x: number; y: number; width: number; height: number} ; rot: number} | null{ const projection = factors(mode, view); if (!projection) return null; const center ={ x: box.x + box.width / 2, y: box.y + box.height / 2} ; const scaled ={ x: anchor.x + (center.x - anchor.x) / projection.s, y: anchor.y + (center.y - anchor.y) / projection.s, } ; const pc = projection.r !== 0 ? rotatePoint(scaled, anchor, normalizeDeg(-projection.r)) : scaled; const width = box.width / projection.s; const height = box.height / projection.s; return{ box:{ x: pc.x - width / 2, y: pc.y - height / 2, width, height} , rot: normalizeDeg(-projection.r), } ; } anchoredGeometry [FunctionDeclaration] (from packages/core/annotation/src/anchor.ts): export function anchoredGeometry( geometry: Shape, mode: AnchorMode | null, view: ViewEnv | undefined, ): Shape{ const projection = factors(mode, view); if (!projection || !projectable(geometry)) return geometry; const point = anchorOf(geometry); let out: Shape = geometry; if (projection.s !== 1) out = geomScaleAbout(out, point, 1 / projection.s, 1 / projection.s); if (projection.r !== 0) out = geomRotateAbout(out, point, normalizeDeg(-projection.r)); return out; } anchoredStrokeWidth [VariableDeclaration] (from packages/core/annotation/src/anchor.ts): anchoredStrokeWidth = ( width: number, mode: AnchorMode | null, view: ViewEnv | undefined, ): number =>{ const projection = factors(mode, view); return projection ? width / projection.s : width; } annotContentsEditable [VariableDeclaration] (from packages/core/annotation/src/flags.ts): annotContentsEditable = (record: FlagBearer): boolean => annotInteractive(record) && !record.annotation.lockedContents && (record.authority?.update ?? true) annotDeletable [VariableDeclaration] (from packages/core/annotation/src/flags.ts): annotDeletable = (record: FlagBearer): boolean => annotInteractive(record) && !record.annotation.locked && (record.authority?.delete ?? true) annotInteractive [VariableDeclaration] (from packages/core/annotation/src/flags.ts): annotInteractive = (record: FlagBearer): boolean => kindOf(record.annotation).caps.ignoresReadOnly ? !record.annotation.hidden && !record.annotation.noView : interactive(record.annotation) annotTransformable [VariableDeclaration] (from packages/core/annotation/src/flags.ts): annotTransformable = (record: FlagBearer): boolean => annotInteractive(record) && !record.annotation.locked && (record.authority?.update ?? true) annotationAfter [FunctionDeclaration] (from packages/core/annotation/src/record/written.ts): export function annotationAfter(annotation: Annotation, patch: AnnotationPatch): Annotation{ const after = applyAnnotationPatch(annotation, patch); const change = appearanceChangeOf(annotation, resolveAnnotationPatch(annotation, patch)); switch (change.impact){ case 'inert': return after; case 'translation':{ if (!rectFollowsDrawing(after)) return after; const{ rect} = annotation; return{ ...after, rect:{ ...rect, x: rect.x + change.by.x, y: rect.y + change.by.y} } ; } case 'regenerate': return{ ...after, ...(UNBAKED_KINDS.has(after.subtype) ?{ } :{ hasAppearance: true} ), ...(rectFollowsDrawing(after) ?{ rect: drawnBoundsOf(after)} :{ } ), } ; } } annotationAnchor [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function annotationAnchor( model: Model, id: Id, view?: ViewEnv, ):{ page: PageRef; bounds: Rect} | null{ const record = model.byId[id]; if (!record) return null; const frame = effectiveSelectionFrame(model, id, effectiveGeometry(model, id, view), view); return{ page: record.annotation.page, bounds: unionRect(frame.corners)} ; } annotationOfNew [FunctionDeclaration] (from packages/core/annotation/src/record/written.ts): export function annotationOfNew( draft: AnnotationDraft, at:{ readonly ref: AnnotationRef} , ): Annotation{ const annotation = annotationOfDraft(draft, at); return rectFollowsDrawing(annotation) ?{ ...annotation, rect: drawnBoundsOf(annotation)} : annotation; } annotationSelectionFrame [FunctionDeclaration] (from packages/core/annotation/src/selection.ts): export function annotationSelectionFrame( record: ModelAnnotation, view?: ViewEnv, live?:{ geometry?: Shape; style?: Style; measure?: MeasurementAppearance} , ): SelectionFrame{ const style = live?.style ?? styleOf(record.annotation); const measure = live?.measure ?? measurementOf(record.annotation); const mode = anchorModeOf(record); const geometry = anchoredGeometry(live?.geometry ?? shapeOf(record.annotation), mode, view); const strokeWidth = anchoredStrokeWidth(style.strokeWidth, mode, view); const corners = measure ? measurementSelectionQuad(geometry, measure, { ...style, strokeWidth} ) : selectionQuad(geometry, { ...style, strokeWidth: strokeWidth} ); return{ corners, center:{ x: (corners[0].x + corners[1].x + corners[2].x + corners[3].x) / 4, y: (corners[0].y + corners[1].y + corners[2].y + corners[3].y) / 4, } , angle: isRotatableGeometry(geometry) ? geomRotation(geometry) : 0, } ; } applyStyleToRange [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function applyStyleToRange( doc: T, range: RichTextRange, delta: RichTextStyleDelta, clear: readonly (keyof RichTextRunStyle)[] = [], ): T{ const start = Math.max(0, Math.min(range.start, range.end)); const end = Math.max(range.start, range.end); if (end <= start) return doc; const from = locateOffset(doc, start); const to = locateOffset(doc, end); const paragraphs = doc.paragraphs.map((paragraph, index) =>{ if (index < from.paragraph || index > to.paragraph) return paragraph; const localStart = index === from.paragraph ? from.offset : 0; const localEnd = index === to.paragraph ? to.offset : paragraph.runs.reduce((sum, run) => sum + run.text.length, 0); if (localEnd <= localStart) return paragraph; const split = splitRunsAt(splitRunsAt(paragraph, localStart), localEnd); let pos = 0; const runs = split.runs.map((run) =>{ const runStart = pos; pos += run.text.length; if (runStart < localStart || runStart >= localEnd || run.text.length === 0) return run; const style: RichTextStyleDelta ={ ...(run.style ??{ } ), ...delta} ; for (const key of clear) delete (style as Record)[key]; return{ ...run, style} ; } ); return{ ...split, runs} ; } ); return normalizeRuns({ ...doc, paragraphs} ); } automaticShapeCaptionCenter [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function automaticShapeCaptionCenter(points: readonly Point[], closed: boolean): Point{ if (!points.length) return ORIGIN; if (!closed){ const lengths = points .slice(1) .map((point, i) => Math.hypot(point.x - points[i].x, point.y - points[i].y)); let remaining = lengths.reduce((sum, length) => sum + length, 0) / 2; for (let i = 0; i < lengths.length; i++){ const length = lengths[i]; if (length > 0 && remaining <= length){ const fraction = remaining / length; return{ x: points[i].x + fraction * (points[i + 1].x - points[i].x), y: points[i].y + fraction * (points[i + 1].y - points[i].y) - DISTANCE_CAPTION_SIZE / 2 - 2, } ; } remaining -= length; } return points[0]; } const origin = points[0]; let area = 0; let momentX = 0; let momentY = 0; for (let i = 0; i < points.length; i++){ const start ={ x: points[i].x - origin.x, y: points[i].y - origin.y} ; const next = points[(i + 1) % points.length]; const end ={ x: next.x - origin.x, y: next.y - origin.y} ; const cross = start.x * end.y - end.x * start.y; area += cross; momentX += (start.x + end.x) * cross; momentY += (start.y + end.y) * cross; } if (Math.abs(area) > 1e-8){ const center ={ x: origin.x + momentX / (3 * area), y: origin.y + momentY / (3 * area)} ; if (pointInPoly(center, points)) return center; } const bounds = unionRect([...points]); const fallback ={ x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2} ; const intersections: number[] = []; for (let i = 0; i < points.length; i++){ const start = points[i]; const end = points[(i + 1) % points.length]; if (start.y > fallback.y !== end.y > fallback.y){ intersections.push( start.x + ((fallback.y - start.y) * (end.x - start.x)) / (end.y - start.y), ); } } intersections.sort((left, right) => left - right); let widest = -1; for (let i = 1; i < intersections.length; i += 2){ const width = intersections[i] - intersections[i - 1]; if (width > widest){ widest = width; fallback.x = (intersections[i] + intersections[i - 1]) / 2; } } return fallback; } bodyFromTextStyle [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function bodyFromTextStyle(style: TextStyle, fonts?: FontLookup): RichTextBody{ const face = faceForFont(style.fontFamily, fonts); return{ family: face.family, weight: style.bold ? 700 : (face.weight ?? 400), italic: style.italic ?? face.italic ?? false, size: style.fontSize, color: hex(style.fontColor), decoration: style.underline ? ['underline'] : [], script: 'normal', letterSpacing: 0, horizontalScale: 1, align: style.textAlign, dir: 'ltr', } ; } bodyPieces [VariableDeclaration] (from packages/core/annotation/src/painted.ts): bodyPieces = (ring: readonly Point[]): PaintedPiece[] => [{ kind: 'area', ring} , { kind: 'stroke', points: ring, closed: true, halfWidth: 0} , ] boxFamily [VariableDeclaration] (from packages/core/annotation/src/shapes/box.ts): boxFamily: ShapeFamily ={ read: readBox, write: writeBox, placed: placeBox, bounds: (shape) => shape.box, drawnBounds: boxDrawnBounds, rect: boxRect, selectionBounds: (shape) => shape.box, oriented: () => true, turnedCorners: boxCorners, pivot: (shape) => rectCenter(shape.box), translate: boxTranslate, rotateAbout: boxRotateAbout, scaleAbout: boxScaleAbout, upright: (shape) => ({ ...shape, rotation: 0} ), handles: boxHandles, drag: boxResize, painted: boxPainted, scene: boxScene, } calloutEnd [FunctionDeclaration] (from packages/core/annotation/src/shapes/text-box.ts): export function calloutEnd(box: Rect, toward: Point, rotation = 0): Point{ const middle = rectCenter(box); const local = rotation ? rotatePoint(toward, middle, -rotation) : toward; const dx = local.x - middle.x; const dy = local.y - middle.y; const end = Math.abs(dx) >= Math.abs(dy) ?{ x: dx >= 0 ? box.x + box.width : box.x, y: middle.y} :{ x: middle.x, y: dy >= 0 ? box.y + box.height : box.y} ; return rotation ? rotatePoint(end, middle, rotation) : end; } canMove [VariableDeclaration] (from packages/core/annotation/src/hit.ts): canMove = (model: Model, id: Id): boolean =>{ const record = model.byId[id]; return !!record && isTransformableByHand(model, record) && isMovable(record); } captionPainted [VariableDeclaration] (from packages/core/annotation/src/measurement.ts): captionPainted = (caption: DistanceCaptionLayout | null): PaintedPiece[] => caption ? bodyPieces(caption.bounds) : [] caretFamily [VariableDeclaration] (from packages/core/annotation/src/shapes/caret.ts): caretFamily: ShapeFamily ={ read: readCaret, write: writeCaret, placed: () => null, bounds: (shape) => shape.box, drawnBounds: caretDrawnBounds, rect: (shape) => rotatedAabb(caretDrawnBounds(shape), shape.rotation, rectCenter(shape.box)), selectionBounds: (shape) => shape.box, oriented: () => true, turnedCorners: boxCorners, pivot: (shape) => rectCenter(shape.box), translate: boxTranslate, rotateAbout: (shape) => shape, scaleAbout: boxScaleAbout, upright: (shape) => ({ ...shape, rotation: 0} ), handles: () => [], drag: (shape) => shape, painted: (shape) => bodyPieces(boxCorners(shape)), scene: caretScene, } caretFromAnchor [FunctionDeclaration] (from packages/core/annotation/src/shapes/caret.ts): export function caretFromAnchor(anchor: TextEndAnchor): CaretShape{ const quad = anchor.glyphQuad; const ink = Math.hypot(quad.lowerLeft.x - quad.upperLeft.x, quad.lowerLeft.y - quad.upperLeft.y); const size = Math.max(ink / 2, 1); const corner = anchor.advance > 0 ? quad.lowerRight : quad.lowerLeft; const bx = quad.lowerRight.x - quad.lowerLeft.x; const by = quad.lowerRight.y - quad.lowerLeft.y; const rotation = Math.hypot(bx, by) > 0 ? normalizeDeg((Math.atan2(by, bx) * 180) / Math.PI) : 0; if (rotation < UPRIGHT_EPSILON || rotation > 360 - UPRIGHT_EPSILON){ return{ kind: 'caret', box: caretRectFromAnchor(anchor), rotation: 0} ; } const ux = (quad.upperLeft.x - quad.lowerLeft.x) / ink; const uy = (quad.upperLeft.y - quad.lowerLeft.y) / ink; const cx = corner.x + (ux * size) / 2; const cy = corner.y + (uy * size) / 2; return{ kind: 'caret', box:{ x: cx - size / 2, y: cy - size / 2, width: size, height: size} , rotation, } ; } caretRectFromAnchor [FunctionDeclaration] (from packages/core/annotation/src/shapes/caret.ts): export function caretRectFromAnchor(anchor: TextEndAnchor): Rect{ const quad = anchor.glyphQuad; const ink = Math.hypot(quad.lowerLeft.x - quad.upperLeft.x, quad.lowerLeft.y - quad.upperLeft.y); const size = Math.max(ink / 2, 1); const corner = anchor.advance > 0 ? quad.lowerRight : quad.lowerLeft; return{ x: corner.x - size / 2, y: corner.y - size, width: size, height: size} ; } chrome [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function chrome( model: Model, page: PageRef, pageBox?: Rect, knobOffset: number = ROTATE_KNOB_OFFSET, view?: ViewEnv, ): ChromeNode[]{ const pageObjectNumber = page.objectNumber; const nodes: ChromeNode[] = []; if (model.draft?.kind === 'marquee' && model.draft.page.objectNumber === pageObjectNumber){ nodes.push({ kind: 'marquee', rect: rectFromPoints(model.draft.from, model.draft.to)} ); } if ( model.draft?.kind === 'create-rect' && model.draft.subtype === 'link' && model.draft.page.objectNumber === pageObjectNumber ){ nodes.push({ kind: 'marquee', rect: rectFromPoints(model.draft.from, model.draft.to)} ); } if ( model.draft?.kind === 'move' && model.draft.guides.length && model.byId[model.draft.ids[0]]?.annotation.page.objectNumber === pageObjectNumber ){ for (const guide of model.draft.guides) nodes.push({ kind: 'guide', axis: guide.axis, at: guide.at, lo: guide.lo, hi: guide.hi} ); } const rd = model.draft?.kind === 'rotate' && model.byId[model.draft.ids[0]]?.annotation.page.objectNumber === pageObjectNumber ? model.draft : null; if (rd){ const{ angle} = rotateDraftDelta(model, rd); const span = pageBox ??{ x: rd.pivot.x - 300, y: rd.pivot.y - 300, width: 600, height: 600} ; const lines: Array<{ a: Point; b: Point; role: 'axis' | 'indicator'} > = []; for (const [deg, role] of [ [0, 'axis'], [90, 'axis'], [angle, 'indicator'], ] as const){ const chord = chordThrough(span, rd.pivot, deg); if (chord) lines.push({ ...chord, role} ); } nodes.push({ kind: 'rotate-guides', center: rd.pivot, angle, lines} ); } const selection = model.selected.filter( (id) => isSelectable(model, id) && model.byId[id].annotation.page.objectNumber === pageObjectNumber, ); if (selection.length === 1){ const record = model.byId[selection[0]]; const geometry = effectiveGeometry(model, selection[0], view); const style = effStyle(record.annotation, view); const caps = kindOf(record.annotation).caps; const rot = geomRotation(geometry); const measure = effMeasure(model, record.id); const distance = measure?.intent === 'line-dimension' && distanceLayout(geometry, measure, style.strokeWidth); const frame = effectiveSelectionFrame(model, record.id, geometry, view); if (frame.angle !== 0){ nodes.push({ kind: 'obb', corners: frame.corners, angle: frame.angle} ); } else{ nodes.push({ kind: 'outline', rect: unionRect(frame.corners)} ); } if (!rd && isTransformableByHand(model, record) && (caps.resizable || caps.vertexEditable)){ const handles = distance ? distanceHandles(distance) : geomHandles(geometry); const dragged = model.draft?.kind === 'handle' && model.draft.id === record.id ? model.draft.handle : null; for (const handle of handles){ nodes.push({ kind: 'handle', at: handle.at, cursor: cursorOnScreen(handle.cursor, view?.rotation ?? 0), ...(rot ?{ rot} :{ } ), role: handleRole(handle.id), active: handle.id === dragged, } ); } } } else if (selection.length > 1 && !rd){ const union = unionBoundsOf(model, page, (id) => effectiveGeometry(model, id, view), view); if (union){ nodes.push({ kind: 'outline', rect: union} ); const gc = groupCaps(model, selection); if (gc.resizable){ const dragged = model.draft?.kind === 'group' && model.draft.op === 'resize' ? model.draft.handle : null; for (const handle of rectHandlesFor(union)) nodes.push({ kind: 'handle', at: handle.at, cursor: cursorOnScreen(handle.cursor, view?.rotation ?? 0), role: handleRole(handle.id), active: handle.id === dragged, } ); } } } if (!rd){ const knob = selectionKnob(model, page, pageBox, knobOffset, view); if (knob) nodes.push({ kind: 'rotate-knob', at: knob.at, from: knob.from} ); } return nodes; } clampRectToBox [VariableDeclaration] (from packages/core/annotation/src/placement.ts): clampRectToBox = (rect: Rect, box: Rect | undefined): Rect =>{ if (!box) return rect; return{ ...rect, x: Math.min(Math.max(rect.x, box.x), Math.max(box.x, box.x + box.width - rect.width)), y: Math.min(Math.max(rect.y, box.y), Math.max(box.y, box.y + box.height - rect.height)), } ; } cloudyPath [FunctionDeclaration] (from packages/core/annotation/src/cloudy.ts): export function cloudyPath( box: Rect, ellipse: boolean, intensity: number, strokeWidth: number, ): string{ const out = new PathBuilder(box.x, box.y); boxCloud(box, ellipse, intensity, strokeWidth, out); out.close(); return out.build(); } computeMoveSnap [FunctionDeclaration] (from packages/core/annotation/src/snap.ts): export function computeMoveSnap( model: Model, ids: Id[], page: PageRef, raw: Point, threshold: number, pageBox: Rect | undefined, ): SnapResult{ const pageObjectNumber = page.objectNumber; const moving = new Set(ids); if (ids.some((id) => model.byId[id] && anchorModeOf(model.byId[id]))){ return{ delta: raw, guides: []} ; } const base = toBounds(unionRect(ids.flatMap((id) => annotQuad(model, id)))); const movingBox = shift(base, raw); const targets: Bounds[] = [ ...(pageBox ? [toBounds(pageBox)] : []), ...model.order .filter( (id) => !moving.has(id) && model.byId[id].annotation.page.objectNumber === pageObjectNumber && isSelectable(model, id) && !anchorModeOf(model.byId[id]), ) .map((id) => toBounds(unionRect(annotQuad(model, id)))), ]; let bx:{ adjust: number; at: number; tb: Bounds} | null = null; let by:{ adjust: number; at: number; tb: Bounds} | null = null; for (const tb of targets){ for (const tk of keysX(tb)) for (const mk of keysX(movingBox)){ const diff = tk - mk; if (Math.abs(diff) < threshold && (!bx || Math.abs(diff) < Math.abs(bx.adjust))) bx ={ adjust: diff, at: tk, tb} ; } for (const tk of keysY(tb)) for (const mk of keysY(movingBox)){ const diff = tk - mk; if (Math.abs(diff) < threshold && (!by || Math.abs(diff) < Math.abs(by.adjust))) by ={ adjust: diff, at: tk, tb} ; } } const delta ={ x: raw.x + (bx?.adjust ?? 0), y: raw.y + (by?.adjust ?? 0)} ; const snapped = shift(base, delta); const guides: Guide[] = []; if (bx) guides.push({ axis: 'x', at: bx.at, lo: Math.min(snapped.min.y, bx.tb.min.y) - GUIDE_PAD, hi: Math.max(snapped.max.y, bx.tb.max.y) + GUIDE_PAD, } ); if (by) guides.push({ axis: 'y', at: by.at, lo: Math.min(snapped.min.x, by.tb.min.x) - GUIDE_PAD, hi: Math.max(snapped.max.x, by.tb.max.x) + GUIDE_PAD, } ); return{ delta, guides} ; } creationDraftAnchor [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function creationDraftAnchor(model: Model): CreationDraftAnchor | null{ const draft = model.draft; if (draft?.kind !== 'create-poly') return null; if (!draft.points.length) return null; const minPoints = draft.closed ? 3 : 2; return{ kind: 'poly', subtype: draft.closed ? 'polygon' : 'polyline', page: draft.page, bounds: unionRect(draft.points), pointCount: draft.points.length, minPoints, canFinish: draft.points.length >= minPoints && (!draft.measure || !( 'unavailable' in shapeMeasurementReadout({ kind: 'poly', vertices: draft.points, closed: draft.closed, rotation: 0} , draft.measure, ) )), } ; } cursorAt [FunctionDeclaration] (from packages/core/annotation/src/hit.ts): export function cursorAt( model: Model, page: PageRef, point: Point, geometry: ChromeGeometry, strokeMargin: number, pageBox?: Rect, inert?: ReadonlySet, view?: ViewEnv, ): Cursor | null{ const target = hitTest(model, page, point, geometry, strokeMargin, pageBox, inert, view); if (target.kind === 'handle') return target.cursor; if (target.kind === 'group-handle') return target.cursor; if (target.kind === 'rotate') return 'grab'; if (target.kind === 'annot') return model.selected.includes(target.id) && canMove(model, target.id) ? 'move' : 'pointer'; return null; } defaultsFor [VariableDeclaration] (from packages/core/annotation/src/update/session.ts): defaultsFor = (model: Model, preset: string): FieldValues => model.defaults[preset] ?? NO_DEFAULTS defineKind [VariableDeclaration] (from packages/core/annotation/src/kinds/define.ts): defineKind = (kind: Kind): Kind => kind distanceCaptionAt [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceCaptionAt( geometry: Shape, appearance: DistanceAppearance, width: number, ): Point | null{ return distanceLayout(geometry, appearance, width)?.caption?.center ?? null; } distanceCaptionHit [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceCaptionHit( layout:{ caption: DistanceCaptionLayout | null} , point: Point, margin = 0, ): boolean{ const caption = layout.caption; if (!caption){ return false; } const along = projectDelta(caption.center, point, caption.along); const perpendicular = projectDelta(caption.center, point, caption.normal); return ( Math.abs(along) <= caption.width / 2 + margin && Math.abs(perpendicular) <= caption.height / 2 + margin ); } distanceDrawnBounds [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceDrawnBounds(layout: DistanceLayout, strokeWidth: number): Rect{ const lines = [ ...layout.dimensionSegments, ...layout.leaderSegments, ...layout.captionConnector, ].map((segment): RenderNode => ({ kind: 'line', a: segment.from, b: segment.to} )); return unionRect([ ...strokedOutlineOf([...lines, ...layout.endings], strokeWidth), ...(layout.caption?.bounds ?? []), ]); } distanceHandles [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceHandles(layout: DistanceLayout): Handle[]{ return [{ id: 'v0', at: layout.measuredStart, cursor: 'crosshair'} , { id: 'v1', at: layout.measuredEnd, cursor: 'crosshair'} , { id: 'leader-start', at: layout.dimensionStart, cursor: 'move'} , { id: 'leader-end', at: layout.dimensionEnd, cursor: 'move'} , ]; } distanceLabel [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceLabel(geometry: Shape, appearance: DistanceAppearance): string{ if (geometry.kind !== 'line'){ return appearance.contents ?? ''; } const readout = measurementReadout({ subtype: 'line', intent: appearance.intent, measure: appearance.measure, linePoints: geometry.linePoints, } ); return isReadout(readout) ? readout.label : (appearance.contents ?? ''); } distanceLayout [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceLayout( geometry: Shape, appearance: DistanceAppearance, strokeWidth: number, ): DistanceLayout | null{ if (geometry.kind !== 'line'){ return null; } const{ start: a, end: b} = drawnLineOf(geometry); const{ along, normal, length} = lineAxes(a, b); const leaderLength = appearance.leader?.length ?? 0; const dimensionStart = offsetPoint(a, normal, leaderLength); const dimensionEnd = offsetPoint(b, normal, leaderLength); const midpoint = offsetPoint(dimensionStart, along, length / 2); const text = distanceLabel(geometry, appearance); const width = distanceCaptionWidth(text); const hasCaption = !!appearance.captionEnabled && text.length > 0; const outside = hasCaption && width + 2 * CAPTION_PADDING + ARROW_RESERVE * strokeWidth > length; let caption: DistanceCaptionLayout | null = null; if (hasCaption){ const reversed = along.x < 0 || (along.x === 0 && along.y > 0); const textAlong = reversed ?{ x: -along.x, y: -along.y} : along; const textNormal ={ x: textAlong.y, y: -textAlong.x} ; const offset = appearance.captionOffset; let center = offsetPoint(midpoint, along, offset?.along ?? 0); center = offsetPoint(center, normal, offset?.perpendicular ?? 0); if (appearance.captionPosition === 'top' || outside){ const side = outside && leaderLength < 0 ? -1 : 1; const padding = outside ? OUTSIDE_CAPTION_PADDING : CAPTION_PADDING; center = offsetPoint(center, normal, side * (CAPTION_SIZE / 2 + padding)); } caption ={ text, center, along: textAlong, normal: textNormal, width, height: CAPTION_SIZE, bounds: captionQuad(center, textAlong, textNormal, width, CAPTION_SIZE), } ; } const leaderSegments: DistanceSegment[] = []; if (leaderLength !== 0){ const side = Math.sign(leaderLength); const leaderOffset = side * (appearance.leader?.offset ?? 0); const leaderEnd = leaderLength + side * (appearance.leader?.extension ?? 0); for (const endpoint of [a, b]){ leaderSegments.push({ from: offsetPoint(endpoint, normal, leaderOffset), to: offsetPoint(endpoint, normal, leaderEnd), } ); } } const segments = dimensionSegments( dimensionStart, dimensionEnd, along, normal, length, caption, appearance.captionPosition, outside, strokeWidth, ); const connector = caption ? captionConnector(midpoint, caption, along, normal, appearance.captionOffset) : []; const angle = Math.atan2(along.y, along.x); const startAngle = outside ? angle : angle + Math.PI; const endAngle = outside ? angle + Math.PI : angle; const endings = [ ...endingNodes(dimensionStart, startAngle, geometry.lineEndings?.start, strokeWidth), ...endingNodes(dimensionEnd, endAngle, geometry.lineEndings?.end, strokeWidth), ]; const boundsPoints = [ a, b, ...segments.flatMap((segment) => [segment.from, segment.to]), ...leaderSegments.flatMap((segment) => [segment.from, segment.to]), ...connector.flatMap((segment) => [segment.from, segment.to]), ...endingPoints(dimensionStart, startAngle, geometry.lineEndings?.start, strokeWidth), ...endingPoints(dimensionEnd, endAngle, geometry.lineEndings?.end, strokeWidth), ...(caption?.bounds ?? []), ]; return{ along, normal, length, measuredStart: a, measuredEnd: b, dimensionStart, dimensionEnd, dimensionSegments: segments, leaderSegments, captionConnector: connector, caption, arrowPlacement: outside ? 'outside' : 'inside', endings, selectionPoints: boundsPoints, visualBounds: expandDistanceBounds(unionRect(boundsPoints), strokeWidth / 2 + 1), } ; } distanceLeaderLength [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceLeaderLength(geometry: Shape, point: Point): number{ if (geometry.kind !== 'line'){ return 0; } const{ start, end} = drawnLineOf(geometry); const{ normal} = lineAxes(start, end); return projectDelta(start, point, normal); } distancePainted [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distancePainted(layout: DistanceLayout, strokeWidth: number): PaintedPiece[]{ const halfWidth = strokeWidth / 2; const segments = [ ...layout.dimensionSegments, ...layout.leaderSegments, ...layout.captionConnector, ]; return [ ...captionPainted(layout.caption), ...segments.map( ({ from, to} ): PaintedPiece => ({ kind: 'stroke', points: [from, to], closed: false, halfWidth, } ), ), ...endingPieces(layout.endings, strokeWidth), ]; } distanceScene [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceScene( geometry: Shape, appearance: DistanceAppearance, style: Style, ): SceneNode[]{ const layout = distanceLayout(geometry, appearance, style.strokeWidth); if (!layout){ return []; } const paint: Paint ={ stroke: style.color ?? undefined, width: style.strokeWidth, opacity: style.opacity, dash: dashOf(style), } ; const segments = [ ...layout.dimensionSegments, ...layout.leaderSegments, ...layout.captionConnector, ]; const nodes: SceneNode[] = segments.map((segment) => ({ kind: 'line', a: segment.from, b: segment.to, paint, } )); for (const ending of layout.endings){ const filled = ending.kind === 'ellipse' || (ending.kind === 'poly' && ending.closed); nodes.push({ ...ending, paint:{ ...paint, fill: filled ? (style.interiorColor ?? undefined) : undefined, } , } as SceneNode); } nodes.push(...measurementCaptionScene(layout.caption, style)); return nodes; } distanceSelectionQuad [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function distanceSelectionQuad( geometry: Shape, appearance: DistanceAppearance, strokeWidth: number, ): QuadRing{ const layout = distanceLayout(geometry, appearance, strokeWidth); if (!layout || geometry.kind !== 'line'){ return selectionQuad(geometry, { strokeWidth: strokeWidth} ); } const angle = geomRotation(geometry); const origin = drawnLineOf(geometry).start; const points = layout.selectionPoints.map((point) => rotatePoint(point, origin, -angle)); const bounds = expandDistanceBounds(unionRect(points), strokeWidth / 2 + 1); const corner = (x: number, y: number) => rotatePoint({ x, y} , origin, angle); return [ corner(bounds.x, bounds.y), corner(bounds.x + bounds.width, bounds.y), corner(bounds.x + bounds.width, bounds.y + bounds.height), corner(bounds.x, bounds.y + bounds.height), ]; } drawnAfter [FunctionDeclaration] (from packages/core/annotation/src/appearance.ts): export function drawnAfter(record: ModelAnnotation, patch: AnnotationPatch): Partial{ if (!drawsLive(record)) return{ } ; const change = appearanceChangeOf( record.annotation, resolveAnnotationPatch(record.annotation, patch), ); switch (change.impact){ case 'inert': return{ } ; case 'translation':{ const box = record.apBox; return box ?{ apBox:{ ...box, x: box.x + change.by.x, y: box.y + change.by.y} } :{ } ; } case 'regenerate': return record.source === 'vector' ?{ } :{ source: 'vector'} ; } } drawnStrokesOf [FunctionDeclaration] (from packages/core/annotation/src/shapes/points.ts): export function drawnStrokesOf(shape: PointsShape): Point[][]{ const cached = drawn.get(shape); if (cached) return cached; const turn = turnOf(shape); const strokes = uprightStrokesOf(shape); const out = turn ? strokes.map((stroke) => stroke.map((point) => pagePointTurned(point, turn))) : strokes; drawn.set(shape, out); return out; } drawsLive [VariableDeclaration] (from packages/core/annotation/src/appearance.ts): drawsLive = (record: Pick): boolean => record.painter !== undefined || !kindOf(record.annotation).caps.rasterOnly dropsWaitingInk [FunctionDeclaration] (from packages/core/annotation/src/update/draw.ts): export function dropsWaitingInk(before: Session, after: Session, message: Message): boolean{ const waiting = before.draft; if (waiting?.kind !== 'create-ink' || waiting.drawing) return false; if (message.type === 'cancel' || message.type === 'finishInkDraft') return false; const next = after.draft; return !(next?.kind === 'create-ink' && next.strokes[0] === waiting.strokes[0]); } editableKindOf [FunctionDeclaration] (from packages/core/annotation/src/editable.ts): export function editableKindOf(annotation: Annotation): EditableKind{ const{ intent} = annotation as{ readonly intent?: string | null} ; return isDimension(annotation) ? (intent as MeasurementIntent) : annotation.subtype; } engineSubtypeOf [VariableDeclaration] (from packages/core/annotation/src/record/defaults.ts): engineSubtypeOf = (kind: string): AnnotationSubtype => kind === 'free-text-callout' ? 'free-text' : kind.startsWith('widget') ? 'widget' : (kind as AnnotationSubtype) expandDistanceBounds [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function expandDistanceBounds(bounds: Rect, padding: number): Rect{ return{ x: bounds.x - padding, y: bounds.y - padding, width: bounds.width + 2 * padding, height: bounds.height + 2 * padding, } ; } expandGroups [FunctionDeclaration] (from packages/core/annotation/src/group.ts): export function expandGroups(model: Model, ids: Id[]): Id[]{ const out: Id[] = []; const seen = new Set(); for (const id of ids){ for (const member of groupMembers(model, id)){ if (!seen.has(member)){ seen.add(member); out.push(member); } } } return out; } faceForFont [VariableDeclaration] (from packages/core/annotation/src/richtext.ts): faceForFont = (font: string, fonts?: FontLookup): FaceRequest => faceForFontName(font, fonts && ((key) => fonts().find((handle) => handle.key === key))) familyChosenBy [FunctionDeclaration] (from packages/core/annotation/src/shapes/index.ts): export function familyChosenBy(pick: (annotation: Annotation) => ShapeFamily): ShapeFamily{ return{ read: (annotation) => pick(annotation).read(annotation), write: (shape, subtype) => familyOf(shape).write(shape, subtype), placed: (placement, annotation) => pick(annotation).placed(placement, annotation), bounds: (shape) => familyOf(shape).bounds(shape), drawnBounds: (shape, stroke) => familyOf(shape).drawnBounds(shape, stroke), rect: (shape, stroke) => familyOf(shape).rect(shape, stroke), selectionBounds: (shape, stroke) => familyOf(shape).selectionBounds(shape, stroke), oriented: (shape) => familyOf(shape).oriented(shape), turnedCorners: (shape, stroke) => familyOf(shape).turnedCorners(shape, stroke), pivot: (shape) => familyOf(shape).pivot(shape), translate: (shape, delta) => familyOf(shape).translate(shape, delta), rotateAbout: (shape, pivot, degrees) => familyOf(shape).rotateAbout(shape, pivot, degrees), scaleAbout: (shape, anchor, sx, sy, minSize) => familyOf(shape).scaleAbout(shape, anchor, sx, sy, minSize), upright: (shape, pivot) => familyOf(shape).upright(shape, pivot), handles: (shape) => familyOf(shape).handles(shape), drag: (shape, handle, to) => familyOf(shape).drag(shape, handle, to), painted: (shape, stroke, filled) => familyOf(shape).painted(shape, stroke, filled), scene: (shape, stroke) => familyOf(shape).scene(shape, stroke), } ; } familyOf [VariableDeclaration] (from packages/core/annotation/src/shapes/index.ts): familyOf = (shape: Shape): ShapeFamily => FAMILY_OF[shape.kind] fitStampBox [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function fitStampBox(center: Point, desired: Size, page: Size, rotCW: number): Rect{ const quarter = isQuarterTurn((normalizeDeg(rotCW) as Rotation) ?? 0); const fw0 = quarter ? desired.height : desired.width; const fh0 = quarter ? desired.width : desired.height; const fitScale = Math.min(1, fw0 > 0 ? page.width / fw0 : 1, fh0 > 0 ? page.height / fh0 : 1); const width = desired.width * fitScale; const height = desired.height * fitScale; const fw = quarter ? height : width; const fh = quarter ? width : height; const cx = clampScalar(center.x, fw / 2, page.width - fw / 2); const cy = clampScalar(center.y, fh / 2, page.height - fh / 2); return{ x: cx - width / 2, y: cy - height / 2, width, height} ; } flagsEqual [VariableDeclaration] (from packages/core/annotation/src/flags.ts): flagsEqual = (left: AnnotationFlags, right: AnnotationFlags): boolean => FLAG_KEYS.every((flag) => left[flag] === right[flag]) fromDTO [FunctionDeclaration] (from packages/core/annotation/src/record/index.ts): export function fromDTO(dto: Annotation): ModelAnnotation{ const strippedRect = 'box' in dto && appearanceTurnOf(dto) !== null ? dto.box : undefined; return{ id: annotationKey(dto.ref), source: 'baked', annotation: dto, apBox: strippedRect ?? dto.rect, ...(strippedRect ?{ apRot: geomRotation(shapeOf(dto))} :{ } ), } ; } geomBounds [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): geomBounds = (geometry: Shape): Rect => familyOf(geometry).bounds(geometry) geomDragHandle [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): geomDragHandle = (geometry: Shape, handle: string, to: Point): Shape => familyOf(geometry).drag(geometry, handle, to) geomHandles [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): geomHandles = (geometry: Shape): Handle[] => familyOf(geometry).handles(geometry) geomHit [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function geomHit( geometry: Shape, point: Point, margin: number, filled: boolean, stroke: Stroke, ): boolean{ return paintedNear(geomPainted(geometry, stroke, filled), point, margin); } geomPainted [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function geomPainted( geometry: Shape, stroke: Stroke, filled: boolean, ): readonly PaintedPiece[]{ const asked ={ strokeWidth: stroke.strokeWidth, cloudyIntensity: stroke.cloudyIntensity ?? null, } ; const cached = paintedCache.get(geometry); if ( cached?.filled === filled && cached.stroke.strokeWidth === asked.strokeWidth && cached.stroke.cloudyIntensity === asked.cloudyIntensity ) return cached.pieces; const pieces = familyOf(geometry).painted(geometry, asked, filled); paintedCache.set(geometry, { stroke: asked, filled, pieces} ); return pieces; } geomResetRotation [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function geomResetRotation(geometry: Shape, pivot?: Point): Shape{ return geomRotation(geometry) ? familyOf(geometry).upright(geometry, pivot) : geometry; } geomRotateAbout [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function geomRotateAbout(geometry: Shape, pivot: Point, deltaDeg: number): Shape{ return deltaDeg === 0 ? geometry : familyOf(geometry).rotateAbout(geometry, pivot, deltaDeg); } geomRotation [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function geomRotation(geometry: Shape): number{ return geometry.kind === 'quads' ? 0 : geometry.rotation; } geomScaleAbout [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function geomScaleAbout( geometry: Shape, anchor: Point, sx: number, sy: number, minSize?: number, ): Shape{ return familyOf(geometry).scaleAbout(geometry, anchor, sx, sy, minSize); } geomScene [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): geomScene = (geometry: Shape, stroke: Stroke): RenderNode[] => familyOf(geometry).scene(geometry, stroke) geomTranslate [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): geomTranslate = (geometry: Shape, delta: Point): Shape => familyOf(geometry).translate(geometry, delta) geomVisualBounds [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): geomVisualBounds = (geometry: Shape, stroke: Stroke): Rect => familyOf(geometry).drawnBounds(geometry, stroke) gesturePlacement [FunctionDeclaration] (from packages/core/annotation/src/placement.ts): export function gesturePlacement( form: GestureForm, from: Point, to: Point, clickCreate: ClickCreate | false | undefined, frame: PlacementFrame ={ } , ): Placement | null{ if (!isDrag(form, from, to)){ return clickCreate ? resolveClickPlacement(from, clickCreate, frame) : null; } const a = frame.pageBox ? clampPointToBox(from, frame.pageBox) : from; const b = frame.pageBox ? clampPointToBox(to, frame.pageBox) : to; if (form === 'segment') return{ kind: 'segment', a, b} ; const rot = uprightTurn(frame); const dragged = rectFromPoints(a, b); return{ kind: 'box', rect: rot % 180 ? transposedAboutCenter(dragged) : dragged, rot} ; } groupCaps [FunctionDeclaration] (from packages/core/annotation/src/group.ts): export function groupCaps(model: Model, ids: Id[]): GroupCaps{ const members = ids .map((id) => model.byId[id]) .filter((record): record is NonNullable => !!record); if (members.length === 0) return{ movable: false, resizable: false, rotatable: false} ; const ok = (pick: (caps: KindCaps) => boolean): boolean => members.every( (record) => isTransformableByHand(model, record) && pick(kindOf(record.annotation).caps), ); return{ movable: ok((caps) => caps.groupMovable), resizable: ok((caps) => caps.groupResizable), rotatable: ok((caps) => caps.groupRotatable), } ; } groupKeyOf [FunctionDeclaration] (from packages/core/annotation/src/group.ts): export function groupKeyOf(model: Model, id: Id): Id | null{ const record = model.byId[id]; if (!record) return null; const group = groupOf(record.annotation); if (group) return isAttachedLink(record) ? null : group; for (const other of model.order){ const sub = model.byId[other]; if (sub && groupOf(sub.annotation) === id && visualMember(sub)) return id; } return null; } groupMembers [FunctionDeclaration] (from packages/core/annotation/src/group.ts): export function groupMembers(model: Model, id: Id): Id[]{ const key = groupKeyOf(model, id); if (key == null) return [id]; const members: Id[] = []; if (model.byId[key]) members.push(key); for (const other of model.order){ const sub = model.byId[other]; if (other !== key && sub && groupOf(sub.annotation) === key && visualMember(sub)) members.push(other); } return members; } groupOf [VariableDeclaration] (from packages/core/annotation/src/record/identity.ts): groupOf = (annotation: Annotation): Id | undefined => annotation.reply?.type === 'group' ? annotationKey(annotation.reply.to) : undefined groupResizeAnchor [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function groupResizeAnchor(base: Rect, handle: string): Point{ return rectHandlePoint(base, OPPOSITE_HANDLE[handle as RectHandle] ?? 'nw'); } groupResizeBox [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function groupResizeBox(base: Rect, handle: string, to: Point, isotropic: boolean): Rect{ const raw = resizeRect(base, handle as RectHandle, to); if (!isotropic) return raw; const sx = base.width > 0 ? raw.width / base.width : 1; const sy = base.height > 0 ? raw.height / base.height : 1; const scale = Math.max(MIN_SIZE / Math.max(base.width, base.height, 1), Math.max(sx, sy)); const anchor = groupResizeAnchor(base, handle); return{ x: anchor.x + (base.x - anchor.x) * scale, y: anchor.y + (base.y - anchor.y) * scale, width: base.width * scale, height: base.height * scale, } ; } groupResizeFactors [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function groupResizeFactors(base: Rect, current: Rect):{ sx: number; sy: number} { return{ sx: base.width > 0 ? current.width / base.width : 1, sy: base.height > 0 ? current.height / base.height : 1, } ; } hasLiveDrawing [VariableDeclaration] (from packages/core/annotation/src/scene.ts): hasLiveDrawing = (item: RenderItem): boolean => item.source !== 'baked' || item.lentScene !== undefined || (item.annotation !== undefined && drawsLive({ annotation: item.annotation} )) hitTest [FunctionDeclaration] (from packages/core/annotation/src/hit.ts): export function hitTest( model: Model, page: PageRef, point: Point, chromeGeometry: ChromeGeometry, strokeMargin: number, pageBox?: Rect, inert?: ReadonlySet, view?: ViewEnv, ): Target{ const pageObjectNumber = page.objectNumber; if (model.selected.length === 1 && isSelectable(model, model.selected[0])){ const record = model.byId[model.selected[0]]; if (record.annotation.page.objectNumber === pageObjectNumber){ if (kindOf(record.annotation).caps.rotatable && isTransformableByHand(model, record)){ const frame = annotationSelectionFrame(record, view); const knob = placeRotateKnob(frame.corners, chromeGeometry.knobOffset, pageBox); if ( chromeGeometry.rotationHandle !== false && Math.abs(knob.at.x - point.x) <= chromeGeometry.knobTol && Math.abs(knob.at.y - point.y) <= chromeGeometry.knobTol ){ return{ kind: 'rotate', ids: [record.id], pivot: annotationTurnPivot(record, view), } ; } } if (hasHandles(model, record)){ const style = styleOf(record.annotation); const measure = measurementOf(record.annotation); const geometry = hitGeomOf(record, view); const distance = measure?.intent === 'line-dimension' && distanceLayout(geometry, measure, hitStrokeOf(record, view)); const handles = distance ? distanceHandles(distance) : geomHandles(geometry); if (distance){ const distanceToPointer = (handle: (typeof handles)[number]) => Math.hypot(handle.at.x - point.x, handle.at.y - point.y); handles.sort((left, right) => distanceToPointer(left) - distanceToPointer(right)); } const layout = measure && measurementLayout(geometry, measure, { ...style, strokeWidth: hitStrokeOf(record, view), } ); if ( layout && distanceCaptionHit(layout, point, Math.min(2, chromeGeometry.handleTol / 3)) ){ return{ kind: 'handle', id: record.id, handle: 'caption', cursor: 'move'} ; } for (const handle of handles){ if ( Math.abs(handle.at.x - point.x) <= chromeGeometry.handleTol && Math.abs(handle.at.y - point.y) <= chromeGeometry.handleTol ){ return{ kind: 'handle', id: record.id, handle: handle.id, cursor: cursorOnScreen(handle.cursor, view?.rotation ?? 0), } ; } } } } } else if (model.selected.length > 1){ const gc = groupCaps(model, model.selected); if (gc.rotatable){ const union = groupUnionBounds(model, page, view); if (union){ const corners: [Point, Point, Point, Point] = [{ x: union.x, y: union.y} , { x: union.x + union.width, y: union.y} , { x: union.x + union.width, y: union.y + union.height} , { x: union.x, y: union.y + union.height} , ]; const knob = placeRotateKnob(corners, chromeGeometry.knobOffset, pageBox); if ( chromeGeometry.rotationHandle !== false && Math.abs(knob.at.x - point.x) <= chromeGeometry.knobTol && Math.abs(knob.at.y - point.y) <= chromeGeometry.knobTol ){ const pivot ={ x: union.x + union.width / 2, y: union.y + union.height / 2} ; return{ kind: 'rotate', ids: model.selected.filter( (id) => model.byId[id]?.annotation.page.objectNumber === pageObjectNumber, ), pivot, } ; } } } if (gc.resizable){ const union = groupUnionBounds(model, page, view); if (union){ for (const handle of rectHandlesFor(union)){ if ( Math.abs(handle.at.x - point.x) <= chromeGeometry.handleTol && Math.abs(handle.at.y - point.y) <= chromeGeometry.handleTol ){ return{ kind: 'group-handle', ids: model.selected.filter( (id) => model.byId[id]?.annotation.page.objectNumber === pageObjectNumber, ), handle: handle.id, cursor: cursorOnScreen(handle.cursor, view?.rotation ?? 0), box: union, } ; } } } } } const order = paintOrder(model, page); for (let i = order.length - 1; i >= 0; i--){ const id = order[i]; const record = model.byId[id]; if (!record || inert?.has(id) || !isSelectable(model, id)) continue; if (model.selected.includes(id) && canMove(model, id) && inFrame(record, point, view)){ return{ kind: 'annot', id} ; } if (paintedNear(paintedOf(record, view), point, strokeMargin)){ return{ kind: 'annot', id} ; } } const union = selectionUnionBounds(model, page, view); if (union && inRect(union, point)){ for (let i = order.length - 1; i >= 0; i--){ if (model.selected.includes(order[i]) && canMove(model, order[i])) return{ kind: 'annot', id: order[i]} ; } } return{ kind: 'empty'} ; } iconOf [VariableDeclaration] (from packages/core/annotation/src/view.ts): iconOf = (annotation: Annotation): Pick => (annotation.subtype === 'text' || annotation.subtype === 'file-attachment') && annotation.icon ?{ icon: annotation.icon} :{ } initialModel [VariableDeclaration] (from packages/core/annotation/src/update/index.ts): initialModel: Model ={ ...initialSession, byId:{ } , order: []} initialSession [VariableDeclaration] (from packages/core/annotation/src/update/session.ts): initialSession: Session ={ selected: [], hovered: null, draft: null, preview: null, objectNumbers: [], defaults:{ } , hitMargin: 6, editing: null, snap:{ alignment: true, alignmentThresholdPx: 6, rotation: true, rotationAngles: [0, 90, 180, 270], rotationThresholdDeg: 4, } , editable: true, } initialTextStyle [VariableDeclaration] (from packages/core/annotation/src/props.ts): initialTextStyle: TextStyle ={ fontFamily: 'helvetica', fontSize: 14, fontColor: '#000000', textAlign: 'left', } interactive [VariableDeclaration] (from packages/core/annotation/src/flags.ts): interactive = (flags: AnnotationFlags): boolean => !flags.hidden && !flags.noView && !flags.readOnly irtOf [VariableDeclaration] (from packages/core/annotation/src/record/identity.ts): irtOf = (annotation: Annotation): Id | undefined => annotation.reply ? annotationKey(annotation.reply.to) : undefined isAttachedLink [FunctionDeclaration] (from packages/core/annotation/src/plane.ts): export function isAttachedLink(record: Pick): boolean{ return record.annotation.subtype === 'link' && record.annotation.reply?.type === 'group'; } isContentsEditableByHand [VariableDeclaration] (from packages/core/annotation/src/editable.ts): isContentsEditableByHand = ( model: Pick, record: ModelAnnotation, ): boolean => annotContentsEditable(record) && isEditableByHand(model, record.annotation) isConversationOnly [FunctionDeclaration] (from packages/core/annotation/src/plane.ts): export function isConversationOnly(record: Pick): boolean{ const annotation = record.annotation; if (annotation.reply && annotation.reply.type !== 'group') return true; if (annotation.subtype === 'text'){ if (nonEmpty(annotation.state) || nonEmpty(annotation.stateModel)) return true; } return annotation.subtype === 'popup'; } isDeletableByHand [VariableDeclaration] (from packages/core/annotation/src/editable.ts): isDeletableByHand = ( model: Pick, record: ModelAnnotation, ): boolean => annotDeletable(record) && isEditableByHand(model, record.annotation) isDrag [FunctionDeclaration] (from packages/core/annotation/src/placement.ts): export function isDrag(form: GestureForm, from: Point, to: Point): boolean{ if (form === 'segment') return Math.hypot(to.x - from.x, to.y - from.y) >= MIN_DRAG; return Math.abs(to.x - from.x) >= MIN_DRAG || Math.abs(to.y - from.y) >= MIN_DRAG; } isEditableByHand [FunctionDeclaration] (from packages/core/annotation/src/editable.ts): export function isEditableByHand( model: Pick, annotation: Annotation, ): boolean{ const{ editable} = model; return typeof editable === 'boolean' ? editable : editable.includes(editableKindOf(annotation)); } isMovable [VariableDeclaration] (from packages/core/annotation/src/hit.ts): isMovable = (record: ModelAnnotation): boolean => kindOf(record.annotation).caps.movable && !textBound(record) isOnTextBox [FunctionDeclaration] (from packages/core/annotation/src/hit.ts): export function isOnTextBox( record: ModelAnnotation, point: Point, margin: number, view?: ViewEnv, ): boolean{ const geometry = hitGeomOf(record, view); return geometry.kind === 'text-box' && isInTurnedBox(geometry, point, margin); } isPlainRichText [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function isPlainRichText(doc: RichTextDocumentInput): boolean{ if (doc.body && Object.keys(doc.body).length > 0) return false; return doc.paragraphs.every( (paragraph) => paragraph.align === undefined && paragraph.dir === undefined && paragraph.lineHeight === undefined && paragraph.margins === undefined && paragraph.textIndent === undefined && paragraph.unknown === undefined && paragraph.runs.every((run) => cleanDelta(run.style) === undefined), ); } isRotatableGeometry [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): isRotatableGeometry = (geometry: Shape): boolean => familyOf(geometry).oriented(geometry) isSelectable [VariableDeclaration] (from packages/core/annotation/src/hit.ts): isSelectable = (model: Model, id: Id): boolean =>{ const record = model.byId[id]; return !!record && annotInteractive(record) && kindOf(record.annotation).caps.selectable; } isSubstrateOnly [FunctionDeclaration] (from packages/core/annotation/src/plane.ts): export function isSubstrateOnly(record: Pick): boolean{ return isConversationOnly(record) || isAttachedLink(record); } isTransformableByHand [VariableDeclaration] (from packages/core/annotation/src/editable.ts): isTransformableByHand = ( model: Pick, record: ModelAnnotation, ): boolean => annotTransformable(record) && isEditableByHand(model, record.annotation) kindNamed [FunctionDeclaration] (from packages/core/annotation/src/kinds/index.ts): export function kindNamed(name: string): AnnotationKind{ const kind = KINDS[name]; if (kind) return kind; let shown = shownOnly.get(name); if (!shown){ shown ={ name, family: boxFamily, style: plainStyle, caps:{ ...NO_CAPS, rasterOnly: true} , properties: [], } ; shownOnly.set(name, shown); } return shown; } kindOf [FunctionDeclaration] (from packages/core/annotation/src/record/identity.ts): export function kindOf(annotation: Annotation): AnnotationKind{ switch (annotation.subtype){ case 'widget': return kindNamed(widgetKindOf(annotation)); case 'free-text': return kindNamed( annotation.intent === 'free-text-callout' ? 'free-text-callout' : 'free-text', ); default: return kindNamed(annotation.subtype); } } kindTakesLink [VariableDeclaration] (from packages/core/annotation/src/props.ts): kindTakesLink = (kind: AnnotationKind): boolean => kind.properties.some((property) => property.key === 'link') lineEndingsOf [VariableDeclaration] (from packages/core/annotation/src/shapes/points.ts): lineEndingsOf = (annotation: Annotation): LineEndings => ('lineEndings' in annotation && annotation.lineEndings) || NO_ENDINGS linkChildRects [FunctionDeclaration] (from packages/core/annotation/src/record/links.ts): export function linkChildRects(shape: Shape, style: Style): Rect[]{ if (shape.kind === 'quads') return shape.quadPoints.map(quadBounds); if (shape.kind === 'text-box') return [rotatedAabb(shape.box, shape.rotation)]; return [unionRect(selectionQuad(shape, style))]; } linkChildrenOf [FunctionDeclaration] (from packages/core/annotation/src/links.ts): export function linkChildrenOf(model: Model, parentId: Id): ModelAnnotation[]{ const out: ModelAnnotation[] = []; for (const id of model.order){ const record = model.byId[id]; if (record && isAttachedLink(record) && groupOf(record.annotation) === parentId) out.push(record); } return out; } linkOf [FunctionDeclaration] (from packages/core/annotation/src/links.ts): export function linkOf(model: Model, parentId: Id): PdfLinkTarget | null{ const child = linkChildrenOf(model, parentId)[0]?.annotation; return child?.subtype === 'link' ? (child.target ?? null) : null; } locateOffset [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function locateOffset( doc:{ paragraphs: readonly RichTextParagraph[]} , offset: number, ):{ paragraph: number; offset: number} { let pos = 0; for (let i = 0; i < doc.paragraphs.length; i++){ const length = doc.paragraphs[i]!.runs.reduce((sum, run) => sum + run.text.length, 0); if (offset <= pos + length || i === doc.paragraphs.length - 1){ return{ paragraph: i, offset: Math.max(0, Math.min(length, offset - pos))} ; } pos += length + 1; } return{ paragraph: 0, offset: 0} ; } measurementCaptionScene [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function measurementCaptionScene( caption: DistanceCaptionLayout | null, style: Style, ): SceneNode[]{ if (caption){ const helvetica = standardPaintFont('helvetica'); const baseline = offsetPoint(caption.center, caption.normal, -CAPTION_SIZE * 0.33); const at = offsetPoint(baseline, caption.along, -caption.width / 2); return [{ kind: 'text', at, text: caption.text, fontSize: CAPTION_SIZE, fontFamily: helvetica.fontFamily, program: helvetica.program, rotation: (Math.atan2(caption.along.y, caption.along.x) * 180) / Math.PI, paint:{ fill: '#000000', opacity: style.opacity} , } , ]; } return []; } measurementDraftFields [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function measurementDraftFields(appearance: MeasurementAppearance): FieldValues{ const caption = appearance.intent === 'line-dimension' ?{ captionEnabled: appearance.captionEnabled, captionPosition: appearance.captionPosition, captionOffset: appearance.captionOffset, leader: appearance.leader, } :{ captionEnabled: appearance.captionEnabled} ; return{ intent: appearance.intent, measure: appearance.measure?.subtype === 'rectilinear' ? appearance.measure : null, ...Object.fromEntries(Object.entries(caption).filter(([, value]) => value !== undefined)), subject: SUBJECT[appearance.intent], } ; } measurementLayout [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function measurementLayout( geometry: Shape, appearance: MeasurementAppearance, style: Style, ){ return appearance.intent === 'line-dimension' ? distanceLayout(geometry, appearance, style.strokeWidth) : shapeMeasurementLayout(geometry, appearance, style); } measurementOf [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function measurementOf(annotation: Annotation): MeasurementAppearance | undefined{ if (annotation.subtype === 'line' && annotation.intent === 'line-dimension'){ return{ intent: annotation.intent, measure: annotation.measure, captionEnabled: annotation.captionEnabled, captionPosition: annotation.captionPosition, captionOffset: annotation.captionOffset, leader: annotation.leader, contents: annotation.contents, } ; } if ( (annotation.subtype === 'polyline' || annotation.subtype === 'polygon') && (annotation.intent === 'polyline-dimension' || annotation.intent === 'polygon-dimension') ){ return{ intent: annotation.intent, measure: annotation.measure, captionEnabled: annotation.captionEnabled, contents: annotation.contents, } ; } return undefined; } measurementSelectionQuad [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function measurementSelectionQuad( geometry: Shape, appearance: MeasurementAppearance, style: Style, ): QuadRing{ if (appearance.intent === 'line-dimension'){ return distanceSelectionQuad(geometry, appearance, style.strokeWidth); } const layout = shapeMeasurementLayout(geometry, appearance, style); if (!layout) return selectionQuad(geometry, style); const angle = geomRotation(geometry); const bounds = unionRect( layout.selectionPoints.map((point) => rotatePoint(point, ORIGIN, -angle)), ); return [{ x: bounds.x, y: bounds.y} , { x: bounds.x + bounds.width, y: bounds.y} , { x: bounds.x + bounds.width, y: bounds.y + bounds.height} , { x: bounds.x, y: bounds.y + bounds.height} , ].map((point) => rotatePoint(point, ORIGIN, angle)) as QuadRing; } mergeFlags [VariableDeclaration] (from packages/core/annotation/src/flags.ts): mergeFlags = ( base: AnnotationFlags, patch: Partial, ): AnnotationFlags => ({ ...base, ...patch, } ) moveDistanceCaption [FunctionDeclaration] (from packages/core/annotation/src/measurement.ts): export function moveDistanceCaption( geometry: Shape, appearance: DistanceAppearance, delta: Point, ): DistanceAppearance{ if (geometry.kind !== 'line'){ return appearance; } const{ start, end} = drawnLineOf(geometry); const{ along, normal} = lineAxes(start, end); const previous = appearance.captionOffset; return{ ...appearance, captionOffset:{ along: (previous?.along ?? 0) + delta.x * along.x + delta.y * along.y, perpendicular: (previous?.perpendicular ?? 0) + delta.x * normal.x + delta.y * normal.y, } , } ; } moveMeasurementCaption [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function moveMeasurementCaption( geometry: Shape, appearance: MeasurementAppearance, delta: Point, style: Style, ):{ geometry: Shape; measure: MeasurementAppearance} { if (appearance.intent === 'line-dimension') return{ geometry, measure: moveDistanceCaption(geometry, appearance, delta)} ; const center = shapeMeasurementLayout(geometry, appearance, style)?.caption?.center; if (!center || geometry.kind !== 'poly') return{ geometry, measure: appearance} ; const moved ={ x: center.x + delta.x, y: center.y + delta.y} ; return{ geometry:{ ...geometry, captionCenter: uprightPointOf(geometry, moved)} , measure: appearance, } ; } newRecordsAtMost [FunctionDeclaration] (from packages/core/annotation/src/update/index.ts): export function newRecordsAtMost(message: Message): number{ switch (message.type){ case 'createReplaceText': return 2; case 'createPointer': return message.phase === 'move' ? 0 : 1; case 'finishInkDraft': case 'finishCreationDraft': case 'createCaret': case 'createMarkup': return 1; default: return 0; } } normalizeDeg [VariableDeclaration] (from packages/core/annotation/src/rect.ts): normalizeDeg = (degrees: number): number => ((degrees % 360) + 360) % 360 normalizeRuns [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function normalizeRuns(doc: T): T{ const paragraphs = doc.paragraphs.map((paragraph) =>{ const runs: RichTextRun[] = []; for (const run of paragraph.runs){ if (run.text.length === 0) continue; const style = cleanDelta(run.style); const last = runs[runs.length - 1]; if (last && sameStyleDelta(last.style, style)){ runs[runs.length - 1] ={ ...last, text: last.text + run.text} ; } else{ runs.push(style ?{ text: run.text, style} :{ text: run.text} ); } } if (runs.length === 0) runs.push({ text: ''} ); return{ ...paragraph, runs} ; } ); return{ ...doc, paragraphs} ; } obbFromGeometry [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function obbFromGeometry( geometry: Shape, stroke: Stroke, ):{ corners: [Point, Point, Point, Point]; angle: number} | null{ const corners = familyOf(geometry).turnedCorners(geometry, stroke); return corners ?{ corners, angle: geomRotation(geometry)} : null; } orientationPatch [FunctionDeclaration] (from packages/core/annotation/src/record/shape.ts): export function orientationPatch( annotation: Annotation, rotation: Rotation, ):{ box: Rect; rotation: Rotation | null} | Record{ if (!kindOf(annotation).caps.quarterTurns) return{ } ; const shape = shapeOf(annotation); if (shape.kind !== 'box') return{ } ; const stands = standingRect(shape.box, shape.rotation); return{ box: standingRect(stands, rotation), rotation: rotation || null} ; } pageItems [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function pageItems(model: Model, page: PageRef, view?: ViewEnv): RenderItem[]{ const pageObjectNumber = page.objectNumber; const items: RenderItem[] = []; for (const id of paintOrder(model, page)){ const record = model.byId[id]; const text = textOf(record.annotation); const geometry = effectiveGeometry(model, id, view); const style = effStyle(record.annotation, view); const ap = rasterPlacement(model, id, view, geometry); const measure = effMeasure(model, id); const distance = measure && measurementLayout(geometry, measure, style); const box = distance?.visualBounds ?? geomVisualBounds(geometry, style); items.push( placed({ id, ref: refOf(record), annotation: record.annotation, subtype: kindOf(record.annotation).name, geometry, box, apBox: ap.box, style, ...(text ?{ text} :{ } ), ...iconOf(record.annotation), ...redactionLabelOf(record.annotation), measure, source: sourceDuring(model, id), pictureVersion: record.pictureVersion ?? 0, ...(record.painter ?{ lentScene: once(record.painter, box)} :{ } ), selected: model.selected.includes(id), ...(model.hovered === id ?{ hovered: true} :{ } ), rot: geomRotation(geometry), ...(ap.rot ?{ apRot: ap.rot} :{ } ), blend: blendFor(style), } , anchoredScale(anchorModeOf(record), view), ), ); } const draft = model.draft; if ( (draft?.kind === 'create-rect' || draft?.kind === 'create-line') && draft.page.objectNumber === pageObjectNumber && isDrag(draft.kind === 'create-line' ? 'segment' : 'box', draft.from, draft.to) ){ const placement = draftPlacement(draft); const tool ={ ...toolAnnotation(model, draft.subtype, draft.preset), ...draft.flags} ; const shape = placement && placedShape(tool, placement); if (shape){ const measure = draft.kind === 'create-line' ? draft.measure : undefined; items.push(unmadeItem(DRAFT_ID, tool, shape, 'draft', view, measure)); } } if ( (draft?.kind === 'create-distance' || draft?.kind === 'create-poly' || draft?.kind === 'create-ink') && draft.page.objectNumber === pageObjectNumber ){ const tool = toolAnnotation(model, draft.subtype, draft.preset); const style ={ ...styleOf(tool)} ; if (draft.kind === 'create-distance' && style.interiorColor == null){ style.interiorColor = style.color; } const geometry: Shape = draft.kind === 'create-distance' ?{ kind: 'line', linePoints:{ start: draft.from, end: draft.to} , lineEndings: lineEndingsOf(tool), rotation: 0, } : draft.kind === 'create-poly' ?{ kind: 'poly', vertices: polyPreviewPoints(draft.points, draft.current), closed: draft.closed, lineEndings: draft.closed ? undefined : lineEndingsOf(tool), rotation: 0, } :{ kind: 'ink', inkList: draft.strokes, rotation: 0, ...(draft.drawing ?{ drawing: true} :{ } ), } ; const measure = draft.kind === 'create-distance' || draft.kind === 'create-poly' ? draft.measure : undefined; const distance = measure && measurementLayout(geometry, measure, style); items.push( placed({ id: DRAFT_ID, ref: null, measure, subtype: draft.subtype, geometry, box: distance?.visualBounds ?? geomVisualBounds(geometry, style), style, source: 'draft', selected: false, } ), ); } if (draft?.kind === 'create-callout' && draft.page.objectNumber === pageObjectNumber){ const tool = toolAnnotation(model, draft.subtype, draft.preset); const style = styleOf(tool); const toolEnding = tool.subtype === 'free-text' ? tool.lineEnding : null; const ending = toolEnding && toolEnding !== 'none' ? toolEnding : 'open-arrow'; const rot = calloutUprightRot(draft); const geometry: Shape = draft.step === 'knee' ?{ kind: 'line', linePoints:{ start: draft.tip, end: draft.current} , lineEndings:{ start: ending, end: 'none'} , rotation: 0, } : calloutShape(calloutBox(draft), rot, draft.tip, draft.knee, ending); items.push( placed({ id: DRAFT_ID, ref: null, subtype: draft.subtype, geometry, box: geomVisualBounds(geometry, style), style, source: 'draft', selected: false, } ), ); } const quads = model.preview?.byPage[pageObjectNumber]; if (model.preview && quads?.length){ const geometry: Shape ={ kind: 'quads', quadPoints: quads} ; items.push( placed({ id: PREVIEW_ID, ref: null, subtype: model.preview.subtype, geometry, box: geomVisualBounds(geometry, { strokeWidth: 0} ), style: styleOf(toolAnnotation(model, model.preview.subtype, model.preview.preset)), source: 'draft', selected: false, } ), ); } return items; } paintedNear [VariableDeclaration] (from packages/core/annotation/src/painted.ts): paintedNear = ( pieces: readonly PaintedPiece[], point: Point, margin: number, ): boolean => pieces.some((piece) => pieceNear(piece, point, margin)) paintedOf [FunctionDeclaration] (from packages/core/annotation/src/hit.ts): export function paintedOf(record: ModelAnnotation, view?: ViewEnv): readonly PaintedPiece[]{ const style = styleOf(record.annotation); const measure = measurementOf(record.annotation); const geometry = hitGeomOf(record, view); const stroke ={ ...style, strokeWidth: hitStrokeOf(record, view)} ; if (measure?.intent === 'line-dimension'){ const distance = distanceLayout(geometry, measure, stroke.strokeWidth); if (distance) return distancePainted(distance, stroke.strokeWidth); } const caption = measure ? measurementLayout(geometry, measure, stroke)?.caption : null; const shape = geomPainted(geometry, stroke, isFilled(record)); return caption ? [...captionPainted(caption), ...shape] : shape; } paintedTouches [VariableDeclaration] (from packages/core/annotation/src/painted.ts): paintedTouches = (pieces: readonly PaintedPiece[], rect: Rect): boolean => pieces.some((piece) => pieceTouches(piece, rect)) paragraphsFromPlainText [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function paragraphsFromPlainText(text: string): RichTextParagraph[]{ return text.split(/\r\n|\r|\n/).map((line) => ({ runs: [{ text: line} ]} )); } placeRotateKnob [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function placeRotateKnob( corners: [Point, Point, Point, Point], offset: number, pageBox?: Rect, ):{ at: Point; from: Point} { const top = rotateKnob(corners, offset); if (!pageBox || insideRect(pageBox, top.at)) return top; const [nw, , se, sw] = corners; const from ={ x: (sw.x + se.x) / 2, y: (sw.y + se.y) / 2} ; const down ={ x: sw.x - nw.x, y: sw.y - nw.y} ; const len = Math.hypot(down.x, down.y) || 1; const at ={ x: from.x + (down.x / len) * offset, y: from.y + (down.y / len) * offset, } ; if (insideRect(pageBox, at)) return{ at, from} ; return{ at:{ x: Math.min(Math.max(top.at.x, pageBox.x), pageBox.x + pageBox.width), y: Math.min(Math.max(top.at.y, pageBox.y), pageBox.y + pageBox.height), } , from: top.from, } ; } placedBoxFields [FunctionDeclaration] (from packages/core/annotation/src/placement.ts): export function placedBoxFields(placement: Extract):{ box: Rect; rotation: number | null; } { return{ box: placement.rect, rotation: placement.rot || null} ; } placedShape [FunctionDeclaration] (from packages/core/annotation/src/placement.ts): export function placedShape(annotation: Annotation, placement: Placement): Shape | null{ return kindOf(annotation).family.placed(placement, annotation); } plainTextOf [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function plainTextOf(doc:{ paragraphs: readonly RichTextParagraph[]} ): string{ return doc.paragraphs .map((paragraph) => paragraph.runs.map((run) => run.text).join('')) .join('\n'); } pointInQuad [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): pointInQuad = (point: Point, quad: [Point, Point, Point, Point]): boolean => pointInPoly(point, quad) pointsFamily [VariableDeclaration] (from packages/core/annotation/src/shapes/points.ts): pointsFamily: ShapeFamily ={ read: readPoints, write: writePoints, placed: placePoints, bounds: pointsBounds, drawnBounds: pointsDrawnBounds, rect: pointsDrawnBounds, selectionBounds: pointsDrawnBounds, oriented: () => true, turnedCorners: pointsCorners, pivot: pointsMiddleOf, translate: pointsTranslate, rotateAbout: pointsRotateAbout, scaleAbout: pointsScaleAbout, upright: pointsUpright, handles: pointsHandles, drag: pointsDrag, painted: pointsPainted, scene: pointsScene, } propertiesOf [FunctionDeclaration] (from packages/core/annotation/src/props.ts): export function propertiesOf(kind: AnnotationKind): readonly AnnotationProperty[]{ let properties = withFlags.get(kind); if (!properties){ properties = [...kind.properties, ...FLAG_PROPERTIES]; withFlags.set(kind, properties); } return properties; } quadsFamily [VariableDeclaration] (from packages/core/annotation/src/shapes/quads.ts): quadsFamily: ShapeFamily ={ read: readQuads, write: (shape) => ({ quadPoints: shape.quadPoints} ), placed: () => null, bounds: quadsBounds, drawnBounds: quadsDrawnBounds, rect: quadsDrawnBounds, selectionBounds: quadsBounds, oriented: () => false, turnedCorners: () => null, pivot: quadsCentroid, translate: quadsTranslate, rotateAbout: (shape) => shape, scaleAbout: (shape) => shape, upright: (shape) => shape, handles: () => [], drag: (shape) => shape, painted: (shape) => shape.quadPoints.map((quad) => ({ kind: 'area', ring: quadRing(quad)} )), scene: quadsScene, } rangeHasStyle [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function rangeHasStyle( doc:{ paragraphs: readonly RichTextParagraph[]} , range: RichTextRange, predicate: (delta: RichTextStyleDelta) => boolean, ): boolean{ const start = Math.min(range.start, range.end); const end = Math.max(range.start, range.end); if (end <= start) return predicate(styleAt(doc, start) ??{ } ); const from = locateOffset(doc, start); const to = locateOffset(doc, end); let any = false; for (let index = from.paragraph; index <= to.paragraph; index++){ const paragraph = doc.paragraphs[index]!; const localStart = index === from.paragraph ? from.offset : 0; const localEnd = index === to.paragraph ? to.offset : paragraph.runs.reduce((sum, run) => sum + run.text.length, 0); let pos = 0; for (const run of paragraph.runs){ const runEnd = pos + run.text.length; if (runEnd > localStart && pos < localEnd && run.text.length > 0){ any = true; if (!predicate(run.style ??{ } )) return false; } pos = runEnd; } } return any; } readOfDefaults [FunctionDeclaration] (from packages/core/annotation/src/record/defaults.ts): export function readOfDefaults(kind: string, defaults: FieldValues): Annotation{ const subtype = engineSubtypeOf(kind); const fieldKind = subtype === 'widget' ? fieldKindOf(kind) : undefined; return{ subtype, ...annotationDefaultsOf(subtype), ...(fieldKind ?{ fieldKind} :{ } ), ...defaults, } as unknown as Annotation; } rectFromPoints [VariableDeclaration] (from packages/core/annotation/src/rect.ts): rectFromPoints = (from: Point, to: Point): Rect => ({ x: Math.min(from.x, to.x), y: Math.min(from.y, to.y), width: Math.abs(to.x - from.x), height: Math.abs(to.y - from.y), } ) refOf [VariableDeclaration] (from packages/core/annotation/src/record/identity.ts): refOf = (record: ModelAnnotation | undefined): AnnotationRef | null => record?.annotation.ref ?? null resolveClickPlacement [FunctionDeclaration] (from packages/core/annotation/src/placement.ts): export function resolveClickPlacement( point: Point, policy: ClickCreate, frame: PlacementFrame ={ } , ): Placement{ const seen = frame.upright ? (frame.displayRotation ?? 0) : 0; if ('length' in policy){ const turn = ((policy.rotation ?? 0) * Math.PI) / 180; const span = rotatePoint({ x: Math.cos(turn) * policy.length, y: Math.sin(turn) * policy.length} , { x: 0, y: 0} , -seen, ); const before = policy.anchor === 'start' ? 0 : policy.anchor === 'end' ? 1 : 0.5; const a ={ x: point.x - span.x * before, y: point.y - span.y * before} ; const b ={ x: a.x + span.x, y: a.y + span.y} ; const bounds = rectFromPoints(a, b); const placed = clampRectToBox(bounds, frame.pageBox); const dx = placed.x - bounds.x; const dy = placed.y - bounds.y; return{ kind: 'segment', a:{ x: a.x + dx, y: a.y + dy} , b:{ x: b.x + dx, y: b.y + dy} } ; } const{ width, height} = policy; const rot = uprightTurn(frame); const rect = policy.anchor === 'top-left' ? uprightAnchoredRect(point, width, height, seen) :{ x: point.x - width / 2, y: point.y - height / 2, width, height} ; const shown = rot % 180 ? transposedAboutCenter(rect) : rect; const placed = clampRectToBox(shown, frame.pageBox); return{ kind: 'box', rect:{ ...rect, x: rect.x + placed.x - shown.x, y: rect.y + placed.y - shown.y} , rot, } ; } restyleRuns [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function restyleRuns( doc: T, change: (style: RichTextStyleDelta) => RichTextStyleDelta, ): T{ let changed = false; const paragraphs = doc.paragraphs.map((paragraph) => ({ ...paragraph, runs: paragraph.runs.map((run) =>{ const own = run.style ?? NO_STYLE; const style = change(own); if (style === own) return run; changed = true; return{ ...run, style} ; } ), } )); return changed ? normalizeRuns({ ...doc, paragraphs} ) : doc; } richDocOf [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function richDocOf(annotation: Annotation, fonts?: FontLookup): RichTextDocument{ if (annotation.subtype === 'free-text' && annotation.richText) return annotation.richText; const style: TextStyle = textOf(annotation) ??{ fontFamily: 'helvetica', fontSize: 12, fontColor: '#000000', textAlign: 'left', } ; return{ body: bodyFromTextStyle(style, fonts), paragraphs: paragraphsFromPlainText(annotation.contents ?? ''), } ; } richTextLength [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function richTextLength(doc:{ paragraphs: readonly RichTextParagraph[]} ): number{ let length = 0; doc.paragraphs.forEach((paragraph, i) =>{ if (i > 0) length += 1; for (const run of paragraph.runs) length += run.text.length; } ); return length; } rotateDraftDelta [FunctionDeclaration] (from packages/core/annotation/src/update/edit.ts): export function rotateDraftDelta( model: Model, draft: Extract, ):{ delta: number; angle: number; snapped: boolean} { const raw = angleAt(draft.pivot, draft.current) - angleAt(draft.pivot, draft.start); const one = draft.ids.length === 1 ? model.byId[draft.ids[0]] : null; const base = one ? geomRotation(anchoredGeometry(shapeOf(one.annotation), anchorModeOf(one), draft.view)) : 0; const angle = normalizeDeg(base + raw); if (!model.snap.rotation || draft.free) return{ delta: raw, angle, snapped: false} ; for (const target of model.snap.rotationAngles){ const adjust = arcTo(angle, normalizeDeg(target)); if (Math.abs(adjust) <= model.snap.rotationThresholdDeg) return{ delta: raw + adjust, angle: normalizeDeg(target), snapped: true} ; } return{ delta: raw, angle, snapped: false} ; } rotateKnob [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function rotateKnob( corners: [Point, Point, Point, Point], offset: number, ):{ at: Point; from: Point} { const [nw, ne, , sw] = corners; const from ={ x: (nw.x + ne.x) / 2, y: (nw.y + ne.y) / 2} ; const down ={ x: sw.x - nw.x, y: sw.y - nw.y} ; const len = Math.hypot(down.x, down.y) || 1; const up ={ x: -down.x / len, y: -down.y / len} ; return{ at:{ x: from.x + up.x * offset, y: from.y + up.y * offset} , from} ; } rotatedAabb [FunctionDeclaration] (from packages/core/annotation/src/rect.ts): export function rotatedAabb(rect: Rect, deg: number, pivot: Point = rectCenter(rect)): Rect{ if (!deg) return rect; return unionRect(rectCornerPoints(rect).map((corner) => rotatePoint(corner, pivot, deg))); } rotatedHandleCursor [VariableDeclaration] (from packages/core/annotation/src/rect.ts): rotatedHandleCursor = (handle: RectHandle, rot: number): Cursor => SECTOR_CURSORS[Math.round(normalizeDeg(HANDLE_BASE_ANGLE[handle] + rot) / 45) % 8] rotationAnchor [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function rotationAnchor(model: Model): RotationAnchor | null{ const draft = model.draft; if (draft?.kind !== 'rotate') return null; const page = model.byId[draft.ids[0]]?.annotation.page; if (!page) return null; return{ page, at: draft.current, angle: Math.round(rotateDraftDelta(model, draft).angle), } ; } sameSession [VariableDeclaration] (from packages/core/annotation/src/update/index.ts): sameSession = (left: Session, right: Session): boolean => SESSION_KEYS.every((key) => Object.is(left[key], right[key])) sameStyleDelta [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function sameStyleDelta( left: RichTextStyleDelta | undefined, right: RichTextStyleDelta | undefined, ): boolean{ const da = left ??{ } ; const db = right ??{ } ; for (const key of DELTA_KEYS){ if (key === 'decoration'){ if (!sameDecoration(da.decoration, db.decoration)) return false; } else if (da[key] !== db[key]){ return false; } } return true; } scene [FunctionDeclaration] (from packages/core/annotation/src/scene.ts): export function scene(item: RenderItem): SceneNode[]{ if (item.lentScene) return [...item.lentScene()]; if (item.subtype === 'link') return []; if (item.geometry.kind === 'box' && item.subtype === 'text') return noteIconScene(item.icon, item.geometry.box, item.style); if (item.geometry.kind === 'box' && item.subtype === 'file-attachment') return fileAttachmentIconScene(item.icon, item.geometry.box, item.style); if (item.measure?.intent === 'line-dimension') return distanceScene(item.geometry, item.measure, item.style); if (item.subtype === 'redact') return redactScene(item); if (item.geometry.kind === 'quads') return markupScene(item.subtype, item.geometry.quadPoints, item.style); if (item.geometry.kind === 'caret'){ return geomScene(item.geometry, item.style).map((node) => ({ ...node, paint:{ fill: item.style.color ?? undefined, stroke: item.style.color ?? undefined, width: CARET_STROKE_WIDTH, opacity: item.style.opacity, } , } )) as SceneNode[]; } const ink = item.geometry.kind === 'ink'; const hairline = item.style.strokeWidth === 0 && HAIRLINE_KINDS.has(item.subtype); const nodes = geomScene(item.geometry, item.style).map((node) =>{ const closed = node.kind === 'rect' || node.kind === 'ellipse' || (node.kind === 'path' && !ink) || (node.kind === 'poly' && node.closed); const paint ={ ...shapePaint(item.style, closed), blend: blendFor(item.style), ...(hairline ?{ hairline: true as const} :{ } ), } ; return{ ...node, paint: ink ?{ ...paint, fill: closed ? (item.style.color ?? undefined) : undefined, lineCap: 'round', ...(node.kind === 'poly' ?{ join: 'round'} :{ } ), } : paint, } as SceneNode; } ); if (item.measure){ const layout = shapeMeasurementLayout(item.geometry, item.measure, item.style); nodes.push(...measurementCaptionScene(layout?.caption ?? null, item.style)); } return nodes; } selectedItems [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function selectedItems(model: Model, view?: ViewEnv): RenderItem[]{ const items: RenderItem[] = []; for (const id of model.selected){ const record = model.byId[id]; if (!record) continue; const geometry = effectiveGeometry(model, id, view); const style = effStyle(record.annotation, view); items.push( placed({ id, ref: refOf(record), annotation: record.annotation, subtype: kindOf(record.annotation).name, geometry, box: geomVisualBounds(geometry, style), style, source: record.source, selected: true, rot: geomRotation(geometry), } , anchoredScale(anchorModeOf(record), view), ), ); } return items; } selectionAnchor [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function selectionAnchor( model: Model, pageBoxOf?: (page: PageRef) => Rect | undefined, knobOffsetOf?: (page: PageRef) => number | undefined, viewOf?: (page: PageRef) => ViewEnv | undefined, ):{ page: PageRef; bounds: Rect; knob?: Point} | null{ if (model.draft && !model.draft.kind.startsWith('create-')) return null; const id = model.selected.find((selectedId) => isSelectable(model, selectedId)); if (id == null) return null; const page = model.byId[id].annotation.page; const view = viewOf?.(page); const bounds = selectionBoundsOnPage(model, page, view); if (!bounds) return null; const knob = selectionKnob( model, page, pageBoxOf?.(page), knobOffsetOf?.(page) ?? ROTATE_KNOB_OFFSET, view, ); return knob ?{ page, bounds, knob: knob.at} :{ page, bounds} ; } selectionBounds [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): selectionBounds = (geometry: Shape, stroke: Stroke): Rect => familyOf(geometry).selectionBounds(geometry, stroke) selectionBoundsOnPage [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function selectionBoundsOnPage(model: Model, page: PageRef, view?: ViewEnv): Rect | null{ const pageObjectNumber = page.objectNumber; const selection = model.selected.filter( (id) => isSelectable(model, id) && model.byId[id].annotation.page.objectNumber === pageObjectNumber, ); if (selection.length === 0) return null; const corners = selection.flatMap( (id) => effectiveSelectionFrame(model, id, effectiveGeometry(model, id, view), view).corners, ); return unionRect(corners); } selectionInBox [FunctionDeclaration] (from packages/core/annotation/src/update/marquee.ts): export function selectionInBox( model: Model, page: PageRef, box: Rect, inert?: ReadonlySet, view?: ViewEnv, ): Id[]{ return expandGroups(model, annotsInBox(model, page, box, inert, view)); } selectionKnob [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function selectionKnob( model: Model, page: PageRef, pageBox?: Rect, knobOffset: number = ROTATE_KNOB_OFFSET, view?: ViewEnv, ):{ at: Point; from: Point} | null{ const draft = model.draft; if ( draft?.kind === 'rotate' && model.byId[draft.ids[0]]?.annotation.page.objectNumber === page.objectNumber ){ const rest = placeSelectionKnob( model, page, pageBox, knobOffset, (id) => anchoredGeometry(shapeOf(model.byId[id].annotation), anchorModeOf(model.byId[id]), view), view, ); if (!rest) return null; const{ delta} = rotateDraftDelta(model, draft); return{ at: rotatePoint(rest.at, draft.pivot, delta), from: rotatePoint(rest.from, draft.pivot, delta), } ; } return placeSelectionKnob( model, page, pageBox, knobOffset, (id) => effectiveGeometry(model, id, view), view, ); } selectionProperties [FunctionDeclaration] (from packages/core/annotation/src/props.ts): export function selectionProperties( model: Pick, annotations: readonly Annotation[], ): readonly AnnotationProperty[]{ const kinds = annotations.map((annotation) => kindOf(annotation)); const shared = withOrientation(sharedProperties(kinds), kinds); const choice = kindChoiceOf(model, annotations); return choice ? [choice, ...shared] : shared; } selectionQuad [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function selectionQuad(geometry: Shape, stroke: Stroke): [Point, Point, Point, Point]{ const obb = obbFromGeometry(geometry, stroke); if (obb) return obb.corners; return rectCornerPoints(selectionBounds(geometry, stroke)) as [Point, Point, Point, Point]; } shapeMeasurementLabel [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function shapeMeasurementLabel( geometry: Shape, appearance: ShapeMeasurementAppearance, ): string{ const readout = shapeMeasurementReadout(geometry, appearance); if (isReadout(readout)) return readout.label; return readout.unavailable === 'invalid-geometry' ? '—' : (appearance.contents ?? ''); } shapeMeasurementLayout [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function shapeMeasurementLayout( geometry: Shape, appearance: ShapeMeasurementAppearance, style: Style, ): ShapeMeasurementLayout | null{ if (geometry.kind !== 'poly' || !geometry.vertices.length) return null; const angle = geomRotation(geometry); const localPoints = drawnVerticesOf(geometry).map((point) => rotatePoint(point, ORIGIN, -angle)); const center = geometry.captionCenter ? drawnPointOf(geometry, geometry.captionCenter) : rotatePoint(automaticShapeCaptionCenter(localPoints, geometry.closed), ORIGIN, angle); const text = shapeMeasurementLabel(geometry, appearance); const width = distanceCaptionWidth(text); const height = DISTANCE_CAPTION_SIZE; const along = rotatePoint({ x: 1, y: 0} , ORIGIN, angle); const normal ={ x: along.y, y: -along.x} ; const corner = (x: number, y: number): Point => ({ x: center.x + x * along.x + y * normal.x, y: center.y + x * along.y + y * normal.y, } ); const caption: DistanceCaptionLayout | null = appearance.captionEnabled && text ?{ text, center, along, normal, width, height, bounds: [ corner(-width / 2, -height / 2), corner(width / 2, -height / 2), corner(width / 2, height / 2), corner(-width / 2, height / 2), ], } : null; const selectionPoints = [...selectionQuad(geometry, style), ...(caption?.bounds ?? [])]; return{ caption, selectionPoints, visualBounds: unionRect(selectionPoints)} ; } shapeMeasurementReadout [FunctionDeclaration] (from packages/core/annotation/src/measurement-shape.ts): export function shapeMeasurementReadout(geometry: Shape, appearance: ShapeMeasurementAppearance){ return measurementReadout({ subtype: appearance.intent === 'polygon-dimension' ? 'polygon' : 'polyline', intent: appearance.intent, measure: appearance.measure, vertices: geometry.kind === 'poly' ? geometry.vertices : [], } ); } shapeOf [FunctionDeclaration] (from packages/core/annotation/src/record/shape.ts): export function shapeOf(annotation: Annotation): Shape{ let shape = shapes.get(annotation); if (!shape){ shape = kindOf(annotation).family.read(annotation); shapes.set(annotation, shape); } return shape; } sharedProperties [FunctionDeclaration] (from packages/core/annotation/src/props.ts): export function sharedProperties(kinds: readonly AnnotationKind[]): readonly AnnotationProperty[]{ const unique = [...new Set(kinds)]; if (!unique.length) return []; const first = propertiesOf(unique[0]!); if (unique.length === 1) return first; const rest = unique .slice(1) .map((kind) => new Set(propertiesOf(kind).map((property) => property.key))); return first.filter((property) => rest.every((keys) => keys.has(property.key))); } sourceOfConfirmed [VariableDeclaration] (from packages/core/annotation/src/appearance.ts): sourceOfConfirmed = ( annotation: Annotation, vector: boolean, ): ModelAnnotation['source'] => drawsLive({ annotation} ) && (vector || !annotation.hasAppearance) ? 'vector' : 'baked' sourceOfNew [VariableDeclaration] (from packages/core/annotation/src/appearance.ts): sourceOfNew = (annotation: Annotation): ModelAnnotation['source'] => drawsLive({ annotation} ) ? 'vector' : 'baked' splitRunsAt [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function splitRunsAt(paragraph: RichTextParagraph, offset: number): RichTextParagraph{ const runs: RichTextRun[] = []; let pos = 0; for (const run of paragraph.runs){ const end = pos + run.text.length; if (offset > pos && offset < end){ const cut = offset - pos; runs.push({ ...run, text: run.text.slice(0, cut)} ); runs.push({ ...run, text: run.text.slice(cut)} ); } else{ runs.push(run); } pos = end; } return{ ...paragraph, runs} ; } standingRect [FunctionDeclaration] (from packages/core/annotation/src/rect.ts): export function standingRect(box: Rect, deg: number): Rect{ const turn = normalizeDeg(deg); if (turn % 90 !== 0) return rotatedAabb(box, turn); return turn % 180 === 0 ? box : transposedAboutCenter(box); } straightenInkStroke [FunctionDeclaration] (from packages/core/annotation/src/ink.ts): export function straightenInkStroke( points: readonly Point[], options: InkStraightenOptions, ): Point[]{ if (points.length < 3) return [...points]; const first = points[0]; const last = points[points.length - 1]; const dx = last.x - first.x; const dy = last.y - first.y; const length = Math.hypot(dx, dy); if (length < 3) return [...points]; const maxDeviation = points.reduce((max, point) =>{ const distance = Math.abs(dx * (first.y - point.y) - (first.x - point.x) * dy) / length; return Math.max(max, distance); } , 0); if (maxDeviation / length >= options.deviationThreshold) return [...points]; const angle = Math.atan2(Math.abs(dy), Math.abs(dx)) * (180 / Math.PI); if (angle <= options.axisSnapDegrees){ const y = points.reduce((sum, point) => sum + point.y, 0) / points.length; return [{ x: first.x, y} , { x: last.x, y} , ]; } if (angle >= 90 - options.axisSnapDegrees){ const x = points.reduce((sum, point) => sum + point.x, 0) / points.length; return [{ x, y: first.y} , { x, y: last.y} , ]; } return [...points]; } styleAt [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function styleAt( doc:{ paragraphs: readonly RichTextParagraph[]} , offset: number, ): RichTextStyleDelta | undefined{ const at = locateOffset(doc, offset); const paragraph = doc.paragraphs[at.paragraph]; if (!paragraph) return undefined; let pos = 0; let previous: RichTextRun | undefined; for (const run of paragraph.runs){ const end = pos + run.text.length; if (at.offset > pos && at.offset <= end) return run.style ??{ } ; if (at.offset === pos && pos === 0) return run.style ??{ } ; previous = run; pos = end; } return previous?.style ??{ } ; } styleOf [FunctionDeclaration] (from packages/core/annotation/src/record/style.ts): export function styleOf(annotation: Annotation): Style{ let style = styles.get(annotation); if (!style){ style = kindOf(annotation).style(annotation); styles.set(annotation, style); } return style; } textBoxFamily [VariableDeclaration] (from packages/core/annotation/src/shapes/text-box.ts): textBoxFamily: ShapeFamily ={ read: readTextBox, write: writeTextBox, placed: placeTextBox, bounds: (shape) => shape.box, drawnBounds: textBoxDrawnBounds, rect: textBoxRect, selectionBounds: textBoxSelectionBounds, oriented: (shape) => !shape.calloutLine, turnedCorners: (shape) => (shape.calloutLine ? null : boxCorners(shape)), pivot: (shape) => rectCenter(shape.box), translate: textBoxTranslate, rotateAbout: textBoxRotateAbout, scaleAbout: textBoxScaleAbout, upright: textBoxUpright, handles: textBoxHandles, drag: textBoxDrag, painted: (shape, stroke) => textBoxPainted(shape, stroke), scene: textBoxScene, } textBoxOf [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function textBoxOf(model: Model, id: Id, view?: ViewEnv): TextBox | null{ const record = model.byId[id]; if (!record || shapeOf(record.annotation).kind !== 'text-box') return null; const geometry = effectiveGeometry(model, id, view); if (geometry.kind !== 'text-box') return null; return{ id, box: geometry.box, editing: model.editing === id, rot: geomRotation(geometry), } ; } textBoxes [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function textBoxes(model: Model, page: PageRef, view?: ViewEnv): TextBox[]{ const pageObjectNumber = page.objectNumber; const out: TextBox[] = []; for (const id of model.order){ const record = model.byId[id]; if (record.annotation.page.objectNumber !== pageObjectNumber) continue; if (!viewable(record.annotation, model.selected.includes(id))) continue; if (!textIsLive(model, id)) continue; const box = textBoxOf(model, id, view); if (box) out.push(box); } return out; } textOf [FunctionDeclaration] (from packages/core/annotation/src/record/text.ts): export function textOf(annotation: Annotation): TextStyle | undefined{ if (texts.has(annotation)) return texts.get(annotation); const text = kindOf(annotation).text?.(annotation); texts.set(annotation, text); return text; } textPlateInset [FunctionDeclaration] (from packages/core/annotation/src/shapes/text-box.ts): export function textPlateInset(strokeWidth: number): number{ return 2 * Math.max(0, strokeWidth); } toolAnnotation [VariableDeclaration] (from packages/core/annotation/src/update/session.ts): toolAnnotation = (model: Model, kind: string, preset: string = kind): Annotation => readOfDefaults(kind, defaultsFor(model, preset)) transposedAboutCenter [FunctionDeclaration] (from packages/core/annotation/src/rect.ts): export function transposedAboutCenter(rect: Rect): Rect{ const point = rectCenter(rect); return{ x: point.x - rect.height / 2, y: point.y - rect.width / 2, width: rect.height, height: rect.width, } ; } turnPivotOf [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): turnPivotOf = (geometry: Shape): Point => familyOf(geometry).pivot(geometry) typeWithStyle [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function typeWithStyle( before:{ paragraphs: readonly RichTextParagraph[]} , after: T, at: number, style: RichTextStyleDelta, ):{ doc: T; caret: number; style?: RichTextStyleDelta} | null{ const inserted = insertedAt(before, after, at); if (inserted === null) return null; const caret = at + inserted.length; if (/^\n+$/.test(inserted)) return{ doc: after, caret, style} ; return{ doc: applyStyleToRange(after, { start: at, end: caret} , style), caret} ; } unanchoredGeometry [FunctionDeclaration] (from packages/core/annotation/src/anchor.ts): export function unanchoredGeometry( target: Shape, mode: AnchorMode | null, view: ViewEnv | undefined, ): Shape{ const projection = factors(mode, view); if (!projection || !projectable(target)) return target; let lin: Shape = target; if (projection.s !== 1) lin = geomScaleAbout(lin, ORIGIN, projection.s, projection.s); if (projection.r !== 0) lin = geomRotateAbout(lin, ORIGIN, projection.r); const point = anchorOf(lin); const unrotatedAnchor = rotatePoint(point, ORIGIN, -projection.r); return geomTranslate(lin, { x: unrotatedAnchor.x / projection.s - point.x, y: unrotatedAnchor.y / projection.s - point.y, } ); } unionRect [FunctionDeclaration] (from packages/core/annotation/src/rect.ts): export function unionRect(points: Point[]): Rect{ let x0 = Infinity; let y0 = Infinity; let x1 = -Infinity; let y1 = -Infinity; for (const point of points){ x0 = Math.min(x0, point.x); y0 = Math.min(y0, point.y); x1 = Math.max(x1, point.x); y1 = Math.max(y1, point.y); } return{ x: x0, y: y0, width: x1 - x0, height: y1 - y0} ; } unmadeItem [FunctionDeclaration] (from packages/core/annotation/src/view.ts): export function unmadeItem( id: Id, annotation: Annotation, shape: Shape, source: 'draft' | 'ghost', view?: ViewEnv, measure?: MeasurementAppearance, ): RenderItem{ const geometry = anchoredGeometry(shape, anchorModeOf({ annotation} ), view); const style = effStyle(annotation, view); const distance = measure && measurementLayout(geometry, measure, style); const text = textOf(annotation); return placed({ id, ref: null, subtype: kindOf(annotation).name, geometry, box: distance?.visualBounds ?? geomVisualBounds(geometry, style), style, ...(text ?{ text} :{ } ), ...iconOf(annotation), ...redactionLabelOf(annotation), ...(measure ?{ measure} :{ } ), source, selected: false, rot: geomRotation(geometry), blend: blendFor(style), } , anchoredScale(anchorModeOf({ annotation} ), view), ); } update [FunctionDeclaration] (from packages/core/annotation/src/update/index.ts): export function update(model: Model, message: Message): UpdateResult{ const [next, effects] = transition(model, message); const change = changeBetween(model, next); return{ session: sessionOf(next), change, effects: [...effects, ...writesOf(change, effects)]} ; } uprightAnchoredRect [FunctionDeclaration] (from packages/core/annotation/src/geometry.ts): export function uprightAnchoredRect( anchor: Point, width: number, height: number, displayRotation: number, ): Rect{ const rotation = normalizeDeg(displayRotation); const point: Point = rotation === 90 ?{ x: anchor.x + height / 2, y: anchor.y - width / 2} : rotation === 180 ?{ x: anchor.x - width / 2, y: anchor.y - height / 2} : rotation === 270 ?{ x: anchor.x - height / 2, y: anchor.y + width / 2} :{ x: anchor.x + width / 2, y: anchor.y + height / 2} ; return{ x: point.x - width / 2, y: point.y - height / 2, width, height} ; } uprightRotation [VariableDeclaration] (from packages/core/annotation/src/geometry.ts): uprightRotation = (displayRotation: number): number => normalizeDeg(-displayRotation) viewable [VariableDeclaration] (from packages/core/annotation/src/flags.ts): viewable = (annotation: Annotation, engaged = false): boolean => !annotation.hidden && !hiddenByInvisibleFlag(annotation) && (!annotation.noView || (annotation.toggleNoView && engaged)) widgetAppearanceOf [FunctionDeclaration] (from packages/core/annotation/src/record/defaults.ts): export function widgetAppearanceOf(defaults: FieldValues): WidgetAppearance{ return Object.fromEntries( WIDGET_APPEARANCE_FIELDS.filter((name) => defaults[name] !== undefined).map((name) => [ name, defaults[name], ]), ) as WidgetAppearance; } withShape [VariableDeclaration] (from packages/core/annotation/src/record/shape.ts): withShape = (record: ModelAnnotation, shape: Shape): ModelAnnotation => withValues(record, familyOf(shape).write(shape, record.annotation.subtype)) withValues [FunctionDeclaration] (from packages/core/annotation/src/record/values.ts): export function withValues(record: ModelAnnotation, values: FieldValues): ModelAnnotation{ const subtype = kindAfter(record, values); const declared = ANNOTATION_FIELD_NAMES[subtype]; const taken: Record = subtype === record.annotation.subtype ?{ } :{ subtype} ; for (const [field, value] of Object.entries(values)){ if (value === undefined || field === 'subtype' || !declared.includes(field)) continue; if (mayWrite(record, field)) taken[field] = value; } if (!Object.keys(taken).length) return record; const stated = resolveRectCommand(record.annotation, { ...taken, subtype, } as AnnotationPatch); const annotation = mergeAnnotationPatch(record.annotation, stated); return Object.keys(annotationPatchBetween(record.annotation, annotation)).length ?{ ...record, annotation} : record; } withoutStyle [FunctionDeclaration] (from packages/core/annotation/src/richtext.ts): export function withoutStyle( style: RichTextStyleDelta, keys: readonly (keyof RichTextRunStyle)[], ): RichTextStyleDelta{ if (!keys.some((key) => style[key] !== undefined)) return style; const out ={ ...style} ; for (const key of keys) delete out[key]; return out; } writableTarget [FunctionDeclaration] (from packages/core/annotation/src/record/links.ts): export function writableTarget(target: PdfLinkTarget | null): PdfLinkTargetWritable | null{ return target && (target.kind === 'goto' || target.kind === 'uri') ? target : null; }