@itwin/core-backend 5.2.0-dev.31 → 5.2.0-dev.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  2. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +3 -5
  3. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  4. package/lib/cjs/annotations/LeaderGeometry.js +1 -1
  5. package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
  6. package/lib/cjs/annotations/TextAnnotationGeometry.d.ts.map +1 -1
  7. package/lib/cjs/annotations/TextAnnotationGeometry.js +24 -17
  8. package/lib/cjs/annotations/TextAnnotationGeometry.js.map +1 -1
  9. package/lib/cjs/annotations/TextBlockGeometry.d.ts.map +1 -1
  10. package/lib/cjs/annotations/TextBlockGeometry.js +8 -0
  11. package/lib/cjs/annotations/TextBlockGeometry.js.map +1 -1
  12. package/lib/cjs/annotations/TextBlockLayout.d.ts +46 -27
  13. package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
  14. package/lib/cjs/annotations/TextBlockLayout.js +201 -113
  15. package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
  16. package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
  17. package/lib/cjs/internal/annotations/fields.js +3 -5
  18. package/lib/cjs/internal/annotations/fields.js.map +1 -1
  19. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  20. package/lib/esm/annotations/ElementDrivesTextAnnotation.js +4 -6
  21. package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  22. package/lib/esm/annotations/LeaderGeometry.js +1 -1
  23. package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
  24. package/lib/esm/annotations/TextAnnotationGeometry.d.ts.map +1 -1
  25. package/lib/esm/annotations/TextAnnotationGeometry.js +24 -17
  26. package/lib/esm/annotations/TextAnnotationGeometry.js.map +1 -1
  27. package/lib/esm/annotations/TextBlockGeometry.d.ts.map +1 -1
  28. package/lib/esm/annotations/TextBlockGeometry.js +8 -0
  29. package/lib/esm/annotations/TextBlockGeometry.js.map +1 -1
  30. package/lib/esm/annotations/TextBlockLayout.d.ts +46 -27
  31. package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
  32. package/lib/esm/annotations/TextBlockLayout.js +202 -114
  33. package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
  34. package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
  35. package/lib/esm/internal/annotations/fields.js +4 -6
  36. package/lib/esm/internal/annotations/fields.js.map +1 -1
  37. package/lib/esm/test/annotations/Fields.test.js +5 -3
  38. package/lib/esm/test/annotations/Fields.test.js.map +1 -1
  39. package/lib/esm/test/annotations/TextAnnotation.test.js +1 -1
  40. package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
  41. package/lib/esm/test/annotations/TextBlock.test.js +417 -54
  42. package/lib/esm/test/annotations/TextBlock.test.js.map +1 -1
  43. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"TextBlockLayout.js","sourceRoot":"","sources":["../../../src/annotations/TextBlockLayout.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAiFH,0CAKC;AAQD,oEAGC;AAsBD,wDAoBC;AAzID,oDAAqR;AACrR,wDAAyD;AAEzD,sDAAkF;AAClF,yCAAyC;AACzC,mEAA8D;AAoC9D,gBAAgB;AAChB,SAAS,uBAAuB,CAAC,MAAgB;IAC/C,OAAO,SAAS,iBAAiB,CAAC,EAAc;QAC9C,MAAM,mBAAmB,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAsB,EAAE,CAAC,CAAC;QACnF,IAAI,mBAAmB,IAAI,mBAAmB,YAAY,2CAAmB,EAAE,CAAC;YAC9E,OAAO,mBAAmB,CAAC,QAAQ,CAAC;QACtC,CAAC;QAED,OAAO,+BAAiB,CAA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\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module ElementGeometry\n */\n\nimport { BaselineShift, FieldRun, FontId, FontType, FractionRun, LineLayoutResult, Paragraph, Run, RunLayoutResult, TabRun, TextAnnotationLeader, TextBlock, TextBlockLayoutResult, TextBlockMargins, TextRun, TextStyleSettings, TextStyleSettingsProps } from \"@itwin/core-common\";\nimport { Geometry, Range2d } from \"@itwin/core-geometry\";\nimport { IModelDb } from \"../IModelDb\";\nimport { assert, Id64String, NonFunctionPropertiesOf } from \"@itwin/core-bentley\";\nimport * as LineBreaker from \"linebreak\";\nimport { AnnotationTextStyle } from \"./TextAnnotationElement\";\n\n\n/** @internal */\nexport interface TextLayoutRanges {\n layout: Range2d;\n justification: Range2d;\n}\n\n/** Arguments to [[ComputeRangesForTextLayout]].\n * @internal\n */\nexport interface ComputeRangesForTextLayoutArgs {\n chars: string;\n bold: boolean;\n italic: boolean;\n baselineShift: BaselineShift;\n fontId: FontId;\n widthFactor: number;\n lineHeight: number;\n}\n\n/** A function that uses a font to compute the layout and justification ranges of a string of text.\n * @internal\n */\nexport type ComputeRangesForTextLayout = (args: ComputeRangesForTextLayoutArgs) => TextLayoutRanges;\n\n/** A function that looks up the font Id corresponding to a [FontFamilyDescriptor]($common).\n * If no type is provided, the function can return a font of any type matching `name` (there may be more than one, of different types).\n * @internal\n */\nexport type FindFontId = (name: string, type?: FontType) => FontId;\n\n/** @internal chiefly for tests. */\nexport type FindTextStyle = (id: Id64String) => TextStyleSettings;\n\n/** @internal */\nfunction createFindTextStyleImpl(iModel: IModelDb): FindTextStyle {\n return function findTextStyleImpl(id: Id64String): TextStyleSettings {\n const annotationTextStyle = iModel.elements.tryGetElement<AnnotationTextStyle>(id);\n if (annotationTextStyle && annotationTextStyle instanceof AnnotationTextStyle) {\n return annotationTextStyle.settings;\n }\n\n return TextStyleSettings.fromJSON();\n };\n}\n\n/**\n * Arguments supplied to [[computeLayoutTextBlockResult]].\n * @beta\n */\nexport interface LayoutTextBlockArgs {\n /** The text block whose extents are to be computed. */\n textBlock: TextBlock;\n /** The iModel from which to obtain fonts and [[AnnotationTextStyle]]s when laying out glyphs. */\n iModel: IModelDb;\n /** The text style resolver used to resolve effective text styles during layout. */\n textStyleResolver: TextStyleResolver;\n /** @internal chiefly for tests, by default uses IModelJsNative.DgnDb.computeRangesForText. */\n computeTextRange?: ComputeRangesForTextLayout;\n /** @internal chiefly for tests, by default uses IModelDb.fontMap. */\n findFontId?: FindFontId;\n}\n\n/**\n * Lays out the contents of a TextBlock into a series of lines containing runs.\n * Each paragraph is decomposed into a series of lines.\n * Each series of consecutive non-linebreak runs within a paragraph is concatenated into one line.\n * If the document specifies a width > 0, individual lines are split to try to avoid exceeding that width.\n * Individual TextRuns can be split onto multiple lines at word boundaries if necessary. Individual FractionRuns are never split.\n * @see [[computeLayoutTextBlockResult]]\n * @beta\n */\nexport function layoutTextBlock(args: LayoutTextBlockArgs): TextBlockLayout {\n const findFontId = args.findFontId ?? ((name, type) => args.iModel.fonts.findId({ name, type }) ?? 0);\n const computeTextRange = args.computeTextRange ?? ((x) => args.iModel.computeRangesForText(x));\n\n return new TextBlockLayout(args.textBlock, new LayoutContext(args.textStyleResolver, computeTextRange, findFontId));\n}\n\n/**\n * Gets the result of laying out the the contents of a TextBlock into a series of lines containing runs.\n * The visual layout accounts for the [[AnnotationTextStyle]]s, fonts, and [TextBlock.width]($common). It applies word-wrapping if needed.\n * The layout returned matches the visual layout of the geometry produced by [[appendTextAnnotationGeometry]].\n * @beta\n */\nexport function computeLayoutTextBlockResult(args: LayoutTextBlockArgs): TextBlockLayoutResult {\n const layout = layoutTextBlock(args);\n return layout.toResult();\n}\n\n/**\n * Arguments supplied to [[computeGraphemeOffsets]].\n * @beta\n */\nexport interface ComputeGraphemeOffsetsArgs extends LayoutTextBlockArgs {\n /** The index of the [Paragraph]($common) in the text block that contains the run layout result text. */\n paragraphIndex: number;\n /** The run layout result for which grapheme ranges will be computed. */\n runLayoutResult: RunLayoutResult;\n /** An array of starting character indexes for each grapheme. Each entry represents the index of the first character in a grapheme. */\n graphemeCharIndexes: number[];\n};\n\n/**\n * Computes the range from the start of a [RunLayoutResult]($common) to the trailing edge of each grapheme.\n * It is the responsibility of the caller to determine the number and character indexes of the graphemes.\n * @returns If the [RunLayoutResult]($common)'s source is a [TextRun]($common), it returns an array containing the range of each grapheme.\n * Otherwise, it returns and empty array.\n * @beta\n */\nexport function computeGraphemeOffsets(args: ComputeGraphemeOffsetsArgs): Range2d[] {\n const { textBlock, paragraphIndex, runLayoutResult, graphemeCharIndexes, iModel } = args;\n const findFontId = args.findFontId ?? ((name, type) => iModel.fonts.findId({ name, type }) ?? 0);\n const computeTextRange = args.computeTextRange ?? ((x) => iModel.computeRangesForText(x));\n const source = textBlock.paragraphs[paragraphIndex].runs[runLayoutResult.sourceRunIndex];\n\n if (source.type !== \"text\" || runLayoutResult.characterCount === 0) {\n return [];\n }\n\n const style = TextStyleSettings.fromJSON(runLayoutResult.textStyle);\n\n const layoutContext = new LayoutContext(args.textStyleResolver, computeTextRange, findFontId);\n const graphemeRanges: Range2d[] = [];\n\n graphemeCharIndexes.forEach((_, index) => {\n const nextGraphemeCharIndex = graphemeCharIndexes[index + 1] ?? runLayoutResult.characterCount;\n graphemeRanges.push(layoutContext.computeRangeForTextRun(style, source, runLayoutResult.characterOffset, nextGraphemeCharIndex).layout);\n });\n return graphemeRanges;\n}\n\nfunction scaleRange(range: Range2d, scale: number): void {\n range.low.scaleInPlace(scale);\n range.high.scaleInPlace(scale);\n}\n\n/**\n * Applies block level settings (lineSpacingFactor, lineHeight, widthFactor, frame, and leader) to a [TextStyleSettings]($common).\n * These must be set on the block, as they are meaningless on individual paragraphs/runs.\n * However, leaders are a special case and can override the block's leader settings.\n * Setting `isLeader` to `true` makes the [TextBlock]($common) settings not override the leader's settings.\n * @internal\n */\nfunction applyBlockSettings(target: TextStyleSettings, source: TextStyleSettings | TextStyleSettingsProps, isLeader: boolean = false): TextStyleSettings {\n if (source === target) {\n return target;\n }\n\n const lineSpacingFactor = source.lineSpacingFactor ?? target.lineSpacingFactor;\n const lineHeight = source.lineHeight ?? target.lineHeight;\n const widthFactor = source.widthFactor ?? target.widthFactor;\n const frame = source.frame ?? target.frame;\n const leader = source.leader ?? target.leader;\n\n const leaderShouldChange = !isLeader && !target.leaderEquals(leader);\n\n if (lineSpacingFactor !== target.lineSpacingFactor ||\n lineHeight !== target.lineHeight ||\n widthFactor !== target.widthFactor ||\n !target.frameEquals(frame) ||\n leaderShouldChange\n ) {\n const cloneProps: TextStyleSettingsProps = {\n lineSpacingFactor,\n lineHeight,\n widthFactor,\n frame,\n };\n\n if (leaderShouldChange) {\n cloneProps.leader = leader;\n }\n\n target = target.clone(cloneProps);\n }\n\n return target;\n}\n\n/**\n * Arguments used when constructing a [[TextStyleResolver]].\n * @beta\n */\nexport interface TextStyleResolverArgs {\n /** The text block whose styles are being resolved. */\n textBlock: TextBlock;\n /** The ID of the [[AnnotationTextStyle]] to apply. */\n textStyleId: Id64String;\n /** The iModel from which to obtain [[AnnotationTextStyle]]s when resolving styles. */\n iModel: IModelDb;\n /** @internal chiefly for tests, by default looks up an [[AnnotationTextStyle]] in the iModel by ID. */\n findTextStyle?: FindTextStyle;\n}\n\n/**\n * Resolves the effective style of TextBlockComponents and Leaders, taking into account overrides of the instance and its parent(s).\n * @beta\n */\nexport class TextStyleResolver {\n /** The resolved style of the TextBlock. */\n public readonly blockSettings: TextStyleSettings;\n\n public constructor(args: TextStyleResolverArgs) {\n const findTextStyle = args.findTextStyle ?? createFindTextStyleImpl(args.iModel);\n this.blockSettings = findTextStyle(args.textStyleId);\n\n if (args.textBlock.styleOverrides)\n this.blockSettings = this.blockSettings.clone(args.textBlock.styleOverrides);\n }\n\n private resolveParagraphSettingsImpl(paragraph: Paragraph): TextStyleSettings {\n let settings = this.blockSettings;\n\n if (paragraph.overridesStyle)\n settings = settings.clone(paragraph.styleOverrides);\n\n return settings;\n }\n\n /** Resolves the effective style for a [TextAnnotationLeader]($common). The TextAnnotationLeader should be a sibling of the provided TextBlock. */\n public resolveTextAnnotationLeaderSettings(leader: TextAnnotationLeader): TextStyleSettings {\n let settings = this.blockSettings;\n\n if (leader.styleOverrides)\n settings = settings.clone(leader.styleOverrides);\n\n return applyBlockSettings(settings, this.blockSettings, true);\n }\n\n /** Resolves the effective style for a [Paragraph]($common). Paragraph should be child of provided TextBlock. */\n public resolveParagraphSettings(paragraph: Paragraph): TextStyleSettings {\n return applyBlockSettings(this.resolveParagraphSettingsImpl(paragraph), this.blockSettings);\n }\n\n /** Resolves the effective style for a [Run]($common). Run should be child of provided Paragraph and TextBlock. */\n public resolveRunSettings(paragraph: Paragraph, run: Run): TextStyleSettings {\n let settings = this.resolveParagraphSettingsImpl(paragraph);\n\n if (run.overridesStyle)\n settings = settings.clone(run.styleOverrides);\n\n return applyBlockSettings(settings, this.blockSettings);\n }\n}\n\nclass LayoutContext {\n private readonly _fontIds = new Map<string, FontId>();\n\n public constructor(public readonly textStyleResolver: TextStyleResolver, private readonly _computeTextRange: ComputeRangesForTextLayout, private readonly _findFontId: FindFontId) {}\n\n public findFontId(name: string): FontId {\n let fontId = this._fontIds.get(name);\n if (undefined === fontId) {\n this._fontIds.set(name, fontId = this._findFontId(name));\n }\n\n return fontId;\n }\n\n public computeRangeForText(chars: string, style: TextStyleSettings, baselineShift: BaselineShift): TextLayoutRanges {\n if (chars.length === 0) {\n return {\n layout: new Range2d(0, 0, 0, style.lineHeight),\n justification: new Range2d(),\n };\n }\n\n const fontId = this.findFontId(style.fontName);\n const { layout, justification } = this._computeTextRange({\n chars,\n fontId,\n baselineShift,\n bold: style.isBold,\n italic: style.isItalic,\n lineHeight: this.textStyleResolver.blockSettings.lineHeight,\n widthFactor: this.textStyleResolver.blockSettings.widthFactor,\n });\n\n if (\"none\" !== baselineShift) {\n const isSub = \"subscript\" === baselineShift;\n const scale = isSub ? style.subScriptScale : style.superScriptScale;\n const offsetFactor = isSub ? style.subScriptOffsetFactor : style.superScriptOffsetFactor;\n const offset = { x: 0, y: style.lineHeight * offsetFactor };\n\n scaleRange(layout, scale);\n layout.cloneTranslated(offset, layout);\n\n scaleRange(justification, scale);\n justification.cloneTranslated(offset, justification);\n }\n\n return { layout, justification };\n }\n\n public computeRangeForTextRun(style: TextStyleSettings, run: TextRun | FieldRun, charOffset: number, numChars: number): TextLayoutRanges {\n let content: string;\n let baselineShift: BaselineShift;\n\n if (run.type === \"text\") {\n content = run.content;\n baselineShift = run.baselineShift;\n } else {\n content = run.cachedContent;\n baselineShift = \"none\";\n }\n\n return this.computeRangeForText(content.substring(charOffset, charOffset + numChars), style, baselineShift);\n }\n\n public computeRangeForFractionRun(style: TextStyleSettings, source: FractionRun): { layout: Range2d, numerator: Range2d, denominator: Range2d } {\n const numerator = this.computeRangeForText(source.numerator, style, \"none\").layout;\n scaleRange(numerator, style.stackedFractionScale);\n\n const denominator = this.computeRangeForText(source.denominator, style, \"none\").layout;\n scaleRange(denominator, style.stackedFractionScale);\n\n const numLen = numerator.xLength();\n const denomLen = denominator.xLength();\n switch (style.stackedFractionType) {\n case \"horizontal\": {\n if (numLen > denomLen) {\n denominator.cloneTranslated({ x: (numLen - denomLen) / 2, y: 0 }, denominator);\n } else {\n numerator.cloneTranslated({ x: (denomLen - numLen) / 2, y: 0 }, numerator);\n }\n\n numerator.cloneTranslated({ x: 0, y: 1.5 * denominator.yLength() }, numerator);\n break;\n }\n case \"diagonal\": {\n numerator.cloneTranslated({ x: 0, y: denominator.yLength() }, numerator);\n denominator.cloneTranslated({ x: numLen, y: 0 }, denominator);\n break;\n }\n }\n\n const layout = numerator.clone();\n layout.extendRange(denominator);\n return { layout, numerator, denominator };\n }\n\n public computeRangeForTabRun(style: TextStyleSettings, source: TabRun, length: number): Range2d {\n const interval = source.styleOverrides.tabInterval ?? style.tabInterval;\n const tabEndX = interval - length % interval;\n\n const range = new Range2d(0, 0, 0, style.lineHeight);\n range.extendXY(tabEndX, range.low.y);\n\n return range;\n }\n}\n\ninterface Segment {\n segment: string;\n index: number;\n}\n\nfunction split(source: string): Segment[] {\n if (source.length === 0) {\n return [];\n }\n\n let index = 0;\n const segments: Segment[] = [];\n const breaker = new LineBreaker(source);\n for (let brk = breaker.nextBreak(); brk; brk = breaker.nextBreak()) {\n segments.push({\n segment: source.slice(index, brk.position),\n index,\n });\n\n index = brk.position;\n }\n\n return segments;\n}\n\nfunction applyTabShift(run: RunLayout, parent: LineLayout, context: LayoutContext): void {\n if (run.source.type === \"tab\") {\n run.range.setFrom(context.computeRangeForTabRun(run.style, run.source, parent.lengthFromLastTab));\n }\n}\n\n/**\n * Represents the layout of a single run (text, fraction, or line break) within a line of text.\n * Stores information about the run's position, style, and font within the line.\n * Provides utilities for splitting text runs for word wrapping and converting to result objects.\n * @beta\n */\nexport class RunLayout {\n public source: Run;\n public charOffset: number;\n public numChars: number;\n public range: Range2d;\n public justificationRange?: Range2d;\n public denominatorRange?: Range2d;\n public numeratorRange?: Range2d;\n public offsetFromLine: { x: number, y: number };\n public style: TextStyleSettings;\n public fontId: FontId;\n\n private constructor(props: NonFunctionPropertiesOf<RunLayout>) {\n this.source = props.source;\n this.charOffset = props.charOffset;\n this.numChars = props.numChars;\n this.range = props.range;\n this.justificationRange = props.justificationRange;\n this.denominatorRange = props.denominatorRange;\n this.numeratorRange = props.numeratorRange;\n this.offsetFromLine = props.offsetFromLine;\n this.style = props.style;\n this.fontId = props.fontId;\n }\n\n public static create(source: Run, parentParagraph: Paragraph, context: LayoutContext): RunLayout {\n const style = context.textStyleResolver.resolveRunSettings(parentParagraph, source);\n const fontId = context.findFontId(style.fontName);\n const charOffset = 0;\n const offsetFromLine = { x: 0, y: 0 };\n let numChars = 0;\n\n let range, justificationRange, numeratorRange, denominatorRange;\n\n switch (source.type) {\n case \"field\":\n case \"text\": {\n const content = source.type === \"text\" ? source.content : source.cachedContent;\n numChars = content.length;\n const ranges = context.computeRangeForTextRun(style, source, charOffset, numChars);\n range = ranges.layout;\n justificationRange = ranges.justification;\n break;\n }\n case \"fraction\": {\n numChars = 1;\n const ranges = context.computeRangeForFractionRun(style, source);\n range = ranges.layout;\n numeratorRange = ranges.numerator;\n denominatorRange = ranges.denominator;\n break;\n }\n default: { // \"linebreak\" or \"tab\"\n // \"tab\": Tabs rely on the context they are in, so we compute its range later.\n // lineBreak: We do this so that blank lines space correctly without special casing later.\n range = new Range2d(0, 0, 0, style.lineHeight);\n break;\n }\n }\n\n return new RunLayout({ source, charOffset, numChars, range, justificationRange, denominatorRange, numeratorRange, offsetFromLine, style, fontId });\n }\n\n /** Compute a string representation, primarily for debugging purposes. */\n public stringify(): string {\n return this.source.type === \"text\" ? this.source.content.substring(this.charOffset, this.charOffset + this.numChars) : this.source.stringify();\n }\n\n public canWrap(): this is { source: TextRun } {\n return this.source.type === \"text\";\n }\n\n private cloneForWrap(args: { ranges: TextLayoutRanges, charOffset: number, numChars: number }): RunLayout {\n assert(this.canWrap());\n\n return new RunLayout({\n ...this,\n charOffset: args.charOffset,\n numChars: args.numChars,\n range: args.ranges.layout,\n justificationRange: args.ranges.justification,\n offsetFromLine: { ...this.offsetFromLine },\n });\n }\n\n public split(context: LayoutContext): RunLayout[] {\n assert(this.charOffset === 0, \"cannot re-split a run\");\n if (!this.canWrap() || this.charOffset > 0) {\n return [this];\n }\n\n const myText = this.source.content.substring(this.charOffset, this.charOffset + this.numChars);\n const segments = split(myText);\n\n if (segments.length <= 1) {\n return [this];\n }\n\n return segments.map((segment: any) => {\n return this.cloneForWrap({\n ranges: context.computeRangeForText(segment.segment, this.style, this.source.baselineShift),\n charOffset: segment.index,\n numChars: segment.segment.length,\n });\n });\n }\n\n public toResult(paragraph: Paragraph): RunLayoutResult {\n const result: RunLayoutResult = {\n sourceRunIndex: paragraph.runs.indexOf(this.source),\n fontId: this.fontId,\n characterOffset: this.charOffset,\n characterCount: this.numChars,\n range: this.range.toJSON(),\n offsetFromLine: this.offsetFromLine,\n textStyle: this.style.toJSON(),\n };\n\n if (this.justificationRange) {\n result.justificationRange = this.justificationRange.toJSON();\n }\n\n if (this.numeratorRange) {\n result.numeratorRange = this.numeratorRange.toJSON();\n }\n\n if (this.denominatorRange) {\n result.denominatorRange = this.denominatorRange.toJSON();\n }\n\n return result;\n }\n}\n\n/**\n * Represents the layout of a single line within a paragraph of a text block.\n * Contains a sequence of RunLayout objects, the computed range of the line, and its offset from the document origin.\n * Provides utilities for appending runs, computing ranges, and converting to result objects.\n * @beta\n */\nexport class LineLayout {\n public source: Paragraph;\n public range = new Range2d(0, 0, 0, 0);\n public justificationRange = new Range2d(0, 0, 0, 0);\n public offsetFromDocument = { x: 0, y: 0 };\n public lengthFromLastTab = 0; // Used to track the length from the last tab for tab runs.\n private _runs: RunLayout[] = [];\n\n public constructor(source: Paragraph) {\n this.source = source;\n }\n\n /** Compute a string representation, primarily for debugging purposes. */\n public stringify(): string {\n const runs = this._runs.map((run) => run.stringify());\n return `${runs.join(\"\")}`;\n }\n\n public get runs(): ReadonlyArray<RunLayout> { return this._runs; }\n public get isEmpty() { return this._runs.length === 0; }\n public get back(): RunLayout {\n assert(!this.isEmpty);\n return this._runs[this._runs.length - 1];\n }\n\n public append(run: RunLayout): void {\n this._runs.push(run);\n this.computeRanges();\n }\n\n /** Invoked every time a run is appended,. */\n private computeRanges(): void {\n this.range.low.setZero();\n this.range.high.setZero();\n\n // Some runs (fractions) are taller than others.\n // We want to center each run vertically inside the line.\n let lineHeight = 0;\n for (const run of this._runs) {\n lineHeight = Math.max(lineHeight, run.range.yLength());\n }\n\n for (const run of this._runs) {\n const runHeight = run.range.yLength();\n const runOffset = { x: this.range.high.x, y: (lineHeight - runHeight) / 2 };\n run.offsetFromLine = runOffset;\n\n const runLayoutRange = run.range.cloneTranslated(runOffset);\n this.range.extendRange(runLayoutRange);\n\n if (\"linebreak\" !== run.source.type) {\n const runJustificationRange = run.justificationRange?.cloneTranslated(runOffset);\n this.justificationRange.extendRange(runJustificationRange ?? runLayoutRange);\n }\n\n if (run.source.type === \"tab\") {\n this.lengthFromLastTab = 0;\n } else {\n this.lengthFromLastTab += run.range.xLength();\n }\n }\n }\n\n public toResult(textBlock: TextBlock): LineLayoutResult {\n return {\n sourceParagraphIndex: textBlock.paragraphs.indexOf(this.source),\n runs: this.runs.map((x) => x.toResult(this.source)),\n range: this.range.toJSON(),\n justificationRange: this.justificationRange.toJSON(),\n offsetFromDocument: this.offsetFromDocument,\n };\n }\n}\n\n/**\n * Describes the layout of a text block as a collection of lines containing runs.\n * Computes the visual layout of the text block, including word wrapping, justification, and margins.\n * Provides access to the computed lines, ranges, and utilities for converting to result objects.\n * @beta\n */\nexport class TextBlockLayout {\n public source: TextBlock;\n\n /** @internal: This is primarily for debugging purposes. This is the range of text geometry */\n public textRange = new Range2d();\n\n /** The range including margins of the [[TextBlock]]. */\n public range = new Range2d();\n public lines: LineLayout[] = [];\n private _context: LayoutContext;\n\n public constructor(source: TextBlock, context: LayoutContext) {\n this._context = context;\n this.source = source;\n\n if (source.width > 0) {\n this.textRange.low.x = 0;\n this.textRange.high.x = source.width;\n }\n\n this.populateLines(context);\n this.justifyLines();\n this.applyMargins(source.margins);\n }\n\n public toResult(): TextBlockLayoutResult {\n return {\n lines: this.lines.map((x) => x.toResult(this.source)),\n range: this.range.toJSON(),\n };\n }\n\n /** Compute a string representation, primarily for debugging purposes. */\n public stringify(): string {\n return this.lines.map((line) => line.stringify()).join(\"\\n\");\n }\n\n private get _back(): LineLayout {\n assert(this.lines.length > 0);\n return this.lines[this.lines.length - 1];\n }\n\n private populateLines(context: LayoutContext): void {\n const doc = this.source;\n if (doc.paragraphs.length === 0) {\n return;\n }\n\n const doWrap = doc.width > 0;\n let curLine = new LineLayout(doc.paragraphs[0]);\n for (let i = 0; i < doc.paragraphs.length; i++) {\n const paragraph = doc.paragraphs[i];\n if (i > 0) {\n curLine = this.flushLine(context, curLine, paragraph);\n }\n\n let runs = paragraph.runs.map((run) => RunLayout.create(run, paragraph, context));\n if (doWrap) {\n runs = runs.map((run) => run.split(context)).flat();\n }\n\n for (const run of runs) {\n if (\"linebreak\" === run.source.type) {\n curLine.append(run);\n curLine = this.flushLine(context, curLine);\n continue;\n }\n\n // If this is a tab, we need to apply the tab shift first, and then we can treat it like a text run.\n applyTabShift(run, curLine, context);\n\n // If our width is not set (doWrap is false), then we don't have to compute word wrapping, so just append the run, and continue.\n if (!doWrap) {\n curLine.append(run);\n continue;\n }\n\n // Next, determine if we can append this run to the current line without exceeding the document width\n const runWidth = run.range.xLength();\n const lineWidth = curLine.range.xLength();\n\n // If true, then no word wrapping is required, so we can append to the current line.\n if (runWidth + lineWidth < doc.width || Geometry.isAlmostEqualNumber(runWidth + lineWidth, doc.width, Geometry.smallMetricDistance)) {\n curLine.append(run);\n continue;\n }\n\n // Do word wrapping\n if (curLine.runs.length === 0) {\n curLine.append(run);\n\n // Lastly, flush line\n curLine = this.flushLine(context, curLine);\n } else {\n // First, flush line\n curLine = this.flushLine(context, curLine);\n\n // Recompute tab shift if applicable\n applyTabShift(run, curLine, context);\n\n curLine.append(run);\n }\n }\n }\n\n if (curLine.runs.length > 0) {\n this.flushLine(context, curLine);\n }\n }\n\n private justifyLines(): void {\n // We don't want to justify empty text, or a single line of text whose width is 0. By default text is already left justified.\n if (this.lines.length < 1 || (this.lines.length === 1 && this.source.width === 0) || \"left\" === this.source.justification) {\n return;\n }\n\n // This is the minimum width of the document's bounding box.\n const docWidth = this.source.width;\n\n let minOffset = Number.MAX_VALUE;\n for (const line of this.lines) {\n const lineWidth = line.justificationRange.xLength();\n\n let offset = docWidth - lineWidth;\n if (\"center\" === this.source.justification) {\n offset = offset / 2;\n }\n\n line.offsetFromDocument.x += offset;\n minOffset = Math.min(offset, minOffset);\n }\n\n if (minOffset < 0) {\n // Shift left to accommodate lines that exceeded the document's minimum width.\n this.textRange.low.x += minOffset;\n this.textRange.high.x += minOffset;\n }\n }\n\n private flushLine(context: LayoutContext, line: LineLayout, nextParagraph?: Paragraph): LineLayout {\n nextParagraph = nextParagraph ?? line.source;\n\n // We want to guarantee that each layout line has at least one run.\n if (line.runs.length === 0) {\n // If we're empty, there should always be a preceding run, and it should be a line break.\n if (this.lines.length === 0 || this._back.runs.length === 0) {\n return new LineLayout(nextParagraph);\n }\n\n const prevRun = this._back.back.source;\n assert(prevRun.type === \"linebreak\");\n if (prevRun.type !== \"linebreak\") {\n return new LineLayout(nextParagraph);\n }\n\n line.append(RunLayout.create(prevRun.clone(), line.source, context));\n }\n\n // Line origin is its baseline.\n const lineOffset = { x: 0, y: -line.range.yLength() };\n\n // Place it below any existing lines\n if (this.lines.length > 0) {\n lineOffset.y += this._back.offsetFromDocument.y;\n lineOffset.y -= context.textStyleResolver.blockSettings.lineSpacingFactor * context.textStyleResolver.blockSettings.lineHeight;\n }\n\n line.offsetFromDocument = lineOffset;\n\n // Update document range from computed line range and position\n this.textRange.extendRange(line.range.cloneTranslated(lineOffset));\n\n this.lines.push(line);\n return new LineLayout(nextParagraph);\n }\n\n private applyMargins(margins: TextBlockMargins) {\n this.range = this.textRange.clone();\n\n if (this.range.isNull)\n return;\n\n // Disregard negative margins.\n const right = margins.right >= 0 ? margins.right : 0;\n const left = margins.left >= 0 ? margins.left : 0;\n const top = margins.top >= 0 ? margins.top : 0;\n const bottom = margins.bottom >= 0 ? margins.bottom : 0;\n\n const xHigh = this.textRange.high.x + right;\n const yHigh = this.textRange.high.y + top;\n const xLow = this.textRange.low.x - left;\n const yLow = this.textRange.low.y - bottom;\n\n this.range.extendXY(xHigh, yHigh);\n this.range.extendXY(xLow, yLow);\n }\n}\n"]}
1
+ {"version":3,"file":"TextBlockLayout.js","sourceRoot":"","sources":["../../../src/annotations/TextBlockLayout.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAwFH,0CAKC;AAQD,oEAGC;AAsBD,wDAmBC;AA/ID,oDAAsU;AACtU,wDAAwE;AAExE,sDAAkF;AAClF,yCAAyC;AACz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GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;QAE3C,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAjRD,0CAiRC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module ElementGeometry\n */\n\nimport { BaselineShift, FieldRun, FontId, FontType, FractionRun, getMarkerText, LineLayoutResult, List, Paragraph, Run, RunLayoutResult, StructuralTextBlockComponent, TabRun, TextBlock, TextBlockComponent, TextBlockLayoutResult, TextBlockMargins, TextRun, TextStyleSettings, TextStyleSettingsProps } from \"@itwin/core-common\";\nimport { Geometry, Range2d, WritableXAndY } from \"@itwin/core-geometry\";\nimport { IModelDb } from \"../IModelDb\";\nimport { assert, Id64String, NonFunctionPropertiesOf } from \"@itwin/core-bentley\";\nimport * as LineBreaker from \"linebreak\";\nimport { AnnotationTextStyle } from \"./TextAnnotationElement\";\n\n\n/** @internal */\nexport interface TextLayoutRanges {\n layout: Range2d;\n justification: Range2d;\n}\n\n/** Arguments to [[ComputeRangesForTextLayout]].\n * @internal\n */\nexport interface ComputeRangesForTextLayoutArgs {\n chars: string;\n bold: boolean;\n italic: boolean;\n baselineShift: BaselineShift;\n fontId: FontId;\n widthFactor: number;\n lineHeight: number;\n}\n\n/** A function that uses a font to compute the layout and justification ranges of a string of text.\n * @internal\n */\nexport type ComputeRangesForTextLayout = (args: ComputeRangesForTextLayoutArgs) => TextLayoutRanges;\n\n/** A function that looks up the font Id corresponding to a [FontFamilyDescriptor]($common).\n * If no type is provided, the function can return a font of any type matching `name` (there may be more than one, of different types).\n * @internal\n */\nexport type FindFontId = (name: string, type?: FontType) => FontId;\n\n/** @internal chiefly for tests. */\nexport type FindTextStyle = (id: Id64String) => TextStyleSettings;\n\n/** @internal */\nfunction createFindTextStyleImpl(iModel: IModelDb): FindTextStyle {\n return function findTextStyleImpl(id: Id64String): TextStyleSettings {\n const annotationTextStyle = iModel.elements.tryGetElement<AnnotationTextStyle>(id);\n if (annotationTextStyle && annotationTextStyle instanceof AnnotationTextStyle) {\n return annotationTextStyle.settings;\n }\n\n return TextStyleSettings.fromJSON();\n };\n}\n\n/**\n * Base interface for arguments supplied to [[computeLayoutTextBlockResult]] and [[computeGraphemeOffsets]].\n * @beta\n */\nexport interface LayoutTextArgs {\n /** The iModel from which to obtain fonts and [[AnnotationTextStyle]]s when laying out glyphs. */\n iModel: IModelDb;\n /** The text style resolver used to resolve effective text styles during layout. */\n textStyleResolver: TextStyleResolver;\n /** @internal chiefly for tests, by default uses IModelJsNative.DgnDb.computeRangesForText. */\n computeTextRange?: ComputeRangesForTextLayout;\n /** @internal chiefly for tests, by default uses IModelDb.fontMap. */\n findFontId?: FindFontId;\n}\n\n/**\n * Arguments supplied to [[computeLayoutTextBlockResult]].\n * @beta\n */\nexport interface LayoutTextBlockArgs extends LayoutTextArgs {\n /** The text block whose extents are to be computed. */\n textBlock: TextBlock;\n}\n\n/**\n * Lays out the contents of a TextBlock into a series of lines containing runs.\n * Each paragraph is decomposed into a series of lines.\n * Each series of consecutive non-linebreak runs within a paragraph is concatenated into one line.\n * If the document specifies a width > 0, individual lines are split to try to avoid exceeding that width.\n * Individual TextRuns can be split onto multiple lines at word boundaries if necessary. Individual FractionRuns are never split.\n * @see [[computeLayoutTextBlockResult]]\n * @beta\n */\nexport function layoutTextBlock(args: LayoutTextBlockArgs): TextBlockLayout {\n const findFontId = args.findFontId ?? ((name, type) => args.iModel.fonts.findId({ name, type }) ?? 0);\n const computeTextRange = args.computeTextRange ?? ((x) => args.iModel.computeRangesForText(x));\n\n return new TextBlockLayout(args.textBlock, new LayoutContext(args.textStyleResolver, computeTextRange, findFontId));\n}\n\n/**\n * Gets the result of laying out the the contents of a TextBlock into a series of lines containing runs.\n * The visual layout accounts for the [[AnnotationTextStyle]]s, fonts, and [TextBlock.width]($common). It applies word-wrapping if needed.\n * The layout returned matches the visual layout of the geometry produced by [[appendTextAnnotationGeometry]].\n * @beta\n */\nexport function computeLayoutTextBlockResult(args: LayoutTextBlockArgs): TextBlockLayoutResult {\n const layout = layoutTextBlock(args);\n return layout.toResult();\n}\n\n/**\n * Arguments supplied to [[computeGraphemeOffsets]].\n * @beta\n */\nexport interface ComputeGraphemeOffsetsArgs extends LayoutTextArgs {\n /** The TextBlockComponent for which to compute grapheme offsets. */\n source: TextBlockComponent;\n /** The run layout result for which grapheme ranges will be computed. */\n runLayoutResult: RunLayoutResult;\n /** An array of starting character indexes for each grapheme. Each entry represents the index of the first character in a grapheme. */\n graphemeCharIndexes: number[];\n};\n\n/**\n * Computes the range from the start of a [RunLayoutResult]($common) to the trailing edge of each grapheme.\n * It is the responsibility of the caller to determine the number and character indexes of the graphemes.\n * @returns If the [RunLayoutResult]($common)'s source is a [TextRun]($common), it returns an array containing the range of each grapheme.\n * Otherwise, it returns and empty array.\n * @beta\n */\nexport function computeGraphemeOffsets(args: ComputeGraphemeOffsetsArgs): Range2d[] {\n const { source, runLayoutResult, graphemeCharIndexes, iModel } = args;\n const findFontId = args.findFontId ?? ((name, type) => iModel.fonts.findId({ name, type }) ?? 0);\n const computeTextRange = args.computeTextRange ?? ((x) => iModel.computeRangesForText(x));\n\n if (!(source instanceof TextRun) || runLayoutResult.characterCount === 0) {\n return [];\n }\n\n const style = TextStyleSettings.fromJSON(runLayoutResult.textStyle);\n\n const layoutContext = new LayoutContext(args.textStyleResolver, computeTextRange, findFontId);\n const graphemeRanges: Range2d[] = [];\n\n graphemeCharIndexes.forEach((_, index) => {\n const nextGraphemeCharIndex = graphemeCharIndexes[index + 1] ?? runLayoutResult.characterCount;\n graphemeRanges.push(layoutContext.computeRangeForTextRun(style, source, runLayoutResult.characterOffset, nextGraphemeCharIndex).layout);\n });\n return graphemeRanges;\n}\n\nfunction scaleRange(range: Range2d, scale: number): void {\n range.low.scaleInPlace(scale);\n range.high.scaleInPlace(scale);\n}\n\n/**\n * Applies block level settings (lineSpacingFactor, lineHeight, widthFactor, frame, and leader) to a [TextStyleSettings]($common).\n * These must be set on the block, as they are meaningless on individual paragraphs/runs.\n * However, leaders are a special case and can override the block's leader settings.\n * Setting `isLeader` to `true` makes the [TextBlock]($common) settings not override the leader's settings.\n * @internal\n */\nfunction applyBlockSettings(target: TextStyleSettings, source: TextStyleSettings | TextStyleSettingsProps, isLeader: boolean = false): TextStyleSettings {\n if (source === target) {\n return target;\n }\n\n const lineSpacingFactor = source.lineSpacingFactor ?? target.lineSpacingFactor;\n const lineHeight = source.lineHeight ?? target.lineHeight;\n const widthFactor = source.widthFactor ?? target.widthFactor;\n const frame = source.frame ?? target.frame;\n const leader = source.leader ?? target.leader;\n\n const leaderShouldChange = !isLeader && !target.leaderEquals(leader);\n\n if (lineSpacingFactor !== target.lineSpacingFactor ||\n lineHeight !== target.lineHeight ||\n widthFactor !== target.widthFactor ||\n !target.frameEquals(frame) ||\n leaderShouldChange\n ) {\n const cloneProps: TextStyleSettingsProps = {\n lineSpacingFactor,\n lineHeight,\n widthFactor,\n frame,\n };\n\n if (leaderShouldChange) {\n cloneProps.leader = leader;\n }\n\n target = target.clone(cloneProps);\n }\n\n return target;\n}\n\n/**\n * Arguments used when constructing a [[TextStyleResolver]].\n * @beta\n */\nexport interface TextStyleResolverArgs {\n /** The text block whose styles are being resolved. */\n textBlock: TextBlock;\n /** The ID of the [[AnnotationTextStyle]] to apply. */\n textStyleId: Id64String;\n /** The iModel from which to obtain [[AnnotationTextStyle]]s when resolving styles. */\n iModel: IModelDb;\n /** @internal chiefly for tests, by default looks up an [[AnnotationTextStyle]] in the iModel by ID. */\n findTextStyle?: FindTextStyle;\n}\n\n/**\n * Resolves the effective style of TextBlockComponents and Leaders, taking into account overrides of the instance and its parent(s).\n * @beta\n */\nexport class TextStyleResolver {\n /** The resolved style of the TextBlock. */\n public readonly blockSettings: TextStyleSettings;\n\n public constructor(args: TextStyleResolverArgs) {\n const findTextStyle = args.findTextStyle ?? createFindTextStyleImpl(args.iModel);\n this.blockSettings = findTextStyle(args.textStyleId);\n\n if (args.textBlock.styleOverrides)\n this.blockSettings = this.blockSettings.clone(args.textBlock.styleOverrides);\n }\n\n /**\n * Resolves the effective text style settings for a given TextBlockComponent, applying block-level overrides.\n */\n public resolveSettings(overrides: TextStyleSettingsProps, isLeader: boolean = false): TextStyleSettings {\n let settings = this.blockSettings;\n\n if (overrides)\n settings = settings.clone(overrides);\n\n return applyBlockSettings(settings, this.blockSettings, isLeader);\n }\n\n public resolveMarkerText(overrides: TextStyleSettingsProps, index: number): string {\n const markerSettings = overrides.listMarker ?? this.blockSettings.listMarker;\n return getMarkerText(markerSettings, index);\n }\n\n /**\n * Computes the indentation based on its style and nesting depth.\n */\n public resolveIndentation(styleOverrides: TextStyleSettingsProps, depth: number): number {\n const overrides = this.resolveSettings(styleOverrides);\n const indentation = overrides.indentation;\n const tabInterval = overrides.tabInterval;\n return indentation + tabInterval * depth;\n }\n}\n\nclass LayoutContext {\n private readonly _fontIds = new Map<string, FontId>();\n\n public constructor(public readonly textStyleResolver: TextStyleResolver, private readonly _computeTextRange: ComputeRangesForTextLayout, private readonly _findFontId: FindFontId) { }\n\n public findFontId(name: string): FontId {\n let fontId = this._fontIds.get(name);\n if (undefined === fontId) {\n this._fontIds.set(name, fontId = this._findFontId(name));\n }\n\n return fontId;\n }\n\n public computeRangeForText(chars: string, style: TextStyleSettings, baselineShift: BaselineShift): TextLayoutRanges {\n if (chars.length === 0) {\n return {\n layout: new Range2d(0, 0, 0, style.lineHeight),\n justification: new Range2d(),\n };\n }\n\n const fontId = this.findFontId(style.fontName);\n const { layout, justification } = this._computeTextRange({\n chars,\n fontId,\n baselineShift,\n bold: style.isBold,\n italic: style.isItalic,\n lineHeight: this.textStyleResolver.blockSettings.lineHeight,\n widthFactor: this.textStyleResolver.blockSettings.widthFactor,\n });\n\n if (\"none\" !== baselineShift) {\n const isSub = \"subscript\" === baselineShift;\n const scale = isSub ? style.subScriptScale : style.superScriptScale;\n const offsetFactor = isSub ? style.subScriptOffsetFactor : style.superScriptOffsetFactor;\n const offset = { x: 0, y: style.lineHeight * offsetFactor };\n\n scaleRange(layout, scale);\n layout.cloneTranslated(offset, layout);\n\n scaleRange(justification, scale);\n justification.cloneTranslated(offset, justification);\n }\n\n return { layout, justification };\n }\n\n public computeRangeForTextRun(style: TextStyleSettings, run: TextRun | FieldRun, charOffset: number, numChars: number): TextLayoutRanges {\n let content: string;\n let baselineShift: BaselineShift;\n\n if (run.type === \"text\") {\n content = run.content;\n baselineShift = run.baselineShift;\n } else {\n content = run.cachedContent;\n baselineShift = \"none\";\n }\n\n return this.computeRangeForText(content.substring(charOffset, charOffset + numChars), style, baselineShift);\n }\n\n public computeRangeForFractionRun(style: TextStyleSettings, source: FractionRun): { layout: Range2d, numerator: Range2d, denominator: Range2d } {\n const numerator = this.computeRangeForText(source.numerator, style, \"none\").layout;\n scaleRange(numerator, style.stackedFractionScale);\n\n const denominator = this.computeRangeForText(source.denominator, style, \"none\").layout;\n scaleRange(denominator, style.stackedFractionScale);\n\n const numLen = numerator.xLength();\n const denomLen = denominator.xLength();\n switch (style.stackedFractionType) {\n case \"horizontal\": {\n if (numLen > denomLen) {\n denominator.cloneTranslated({ x: (numLen - denomLen) / 2, y: 0 }, denominator);\n } else {\n numerator.cloneTranslated({ x: (denomLen - numLen) / 2, y: 0 }, numerator);\n }\n\n numerator.cloneTranslated({ x: 0, y: 1.5 * denominator.yLength() }, numerator);\n break;\n }\n case \"diagonal\": {\n numerator.cloneTranslated({ x: 0, y: denominator.yLength() }, numerator);\n denominator.cloneTranslated({ x: numLen, y: 0 }, denominator);\n break;\n }\n }\n\n const layout = numerator.clone();\n layout.extendRange(denominator);\n return { layout, numerator, denominator };\n }\n\n public computeRangeForTabRun(style: TextStyleSettings, source: TabRun, lengthFromLastTab: number): Range2d {\n const interval = source.styleOverrides.tabInterval ?? style.tabInterval;\n const tabEndX = interval - lengthFromLastTab % interval;\n\n const range = new Range2d(0, 0, 0, style.lineHeight);\n range.extendXY(tabEndX, range.low.y);\n\n return range;\n }\n}\n\ninterface Segment {\n segment: string;\n index: number;\n}\n\nfunction split(source: string): Segment[] {\n if (source.length === 0) {\n return [];\n }\n\n let index = 0;\n const segments: Segment[] = [];\n const breaker = new LineBreaker(source);\n for (let brk = breaker.nextBreak(); brk; brk = breaker.nextBreak()) {\n segments.push({\n segment: source.slice(index, brk.position),\n index,\n });\n\n index = brk.position;\n }\n\n return segments;\n}\n\nfunction applyTabShift(run: RunLayout, parent: LineLayout, context: LayoutContext): void {\n if (run.source.type === \"tab\") {\n run.range.setFrom(context.computeRangeForTabRun(run.style, run.source, parent.lengthFromLastTab));\n }\n}\n\n/**\n * Represents the layout of a single run (text, fraction, or line break) within a line of text.\n * Stores information about the run's position, style, and font within the line.\n * Provides utilities for splitting text runs for word wrapping and converting to result objects.\n * @beta\n */\nexport class RunLayout {\n public source: Run;\n public charOffset: number;\n public numChars: number;\n public range: Range2d;\n public justificationRange?: Range2d;\n public denominatorRange?: Range2d;\n public numeratorRange?: Range2d;\n public offsetFromLine: { x: number, y: number };\n public style: TextStyleSettings;\n public fontId: FontId;\n\n private constructor(props: NonFunctionPropertiesOf<RunLayout>) {\n this.source = props.source;\n this.charOffset = props.charOffset;\n this.numChars = props.numChars;\n this.range = props.range;\n this.justificationRange = props.justificationRange;\n this.denominatorRange = props.denominatorRange;\n this.numeratorRange = props.numeratorRange;\n this.offsetFromLine = props.offsetFromLine;\n this.style = props.style;\n this.fontId = props.fontId;\n }\n\n public static create(source: Run, context: LayoutContext, cumulativeOverrides: TextStyleSettingsProps): RunLayout {\n const style = context.textStyleResolver.resolveSettings(cumulativeOverrides);\n const fontId = context.findFontId(style.fontName);\n const charOffset = 0;\n const offsetFromLine = { x: 0, y: 0 };\n let numChars = 0;\n\n let range, justificationRange, numeratorRange, denominatorRange;\n\n switch (source.type) {\n case \"field\":\n case \"text\": {\n const content = source.type === \"text\" ? source.content : source.cachedContent;\n numChars = content.length;\n const ranges = context.computeRangeForTextRun(style, source, charOffset, numChars);\n range = ranges.layout;\n justificationRange = ranges.justification;\n break;\n }\n case \"fraction\": {\n numChars = 1;\n const ranges = context.computeRangeForFractionRun(style, source);\n range = ranges.layout;\n numeratorRange = ranges.numerator;\n denominatorRange = ranges.denominator;\n break;\n }\n default: { // \"linebreak\" or \"tab\"\n // \"tab\": Tabs rely on the context they are in, so we compute its range later.\n // lineBreak: We do this so that blank lines space correctly without special casing later.\n range = new Range2d(0, 0, 0, style.lineHeight);\n break;\n }\n }\n\n return new RunLayout({ source, charOffset, numChars, range, justificationRange, denominatorRange, numeratorRange, offsetFromLine, style, fontId });\n }\n\n /** Compute a string representation, primarily for debugging purposes. */\n public stringify(): string {\n return this.source.type === \"text\" ? this.source.content.substring(this.charOffset, this.charOffset + this.numChars) : this.source.stringify();\n }\n\n public canWrap(): this is { source: TextRun } {\n return this.source.type === \"text\";\n }\n\n private cloneForWrap(args: { ranges: TextLayoutRanges, charOffset: number, numChars: number }): RunLayout {\n assert(this.canWrap());\n\n return new RunLayout({\n ...this,\n charOffset: args.charOffset,\n numChars: args.numChars,\n range: args.ranges.layout,\n justificationRange: args.ranges.justification,\n offsetFromLine: { ...this.offsetFromLine },\n });\n }\n\n public split(context: LayoutContext): RunLayout[] {\n assert(this.charOffset === 0, \"cannot re-split a run\");\n if (!this.canWrap() || this.charOffset > 0) {\n return [this];\n }\n\n const myText = this.source.content.substring(this.charOffset, this.charOffset + this.numChars);\n const segments = split(myText);\n\n if (segments.length <= 1) {\n return [this];\n }\n\n return segments.map((segment: any) => {\n return this.cloneForWrap({\n ranges: context.computeRangeForText(segment.segment, this.style, this.source.baselineShift),\n charOffset: segment.index,\n numChars: segment.segment.length,\n });\n });\n }\n\n public toResult(): RunLayoutResult {\n const result: RunLayoutResult = {\n fontId: this.fontId,\n characterOffset: this.charOffset,\n characterCount: this.numChars,\n range: this.range.toJSON(),\n offsetFromLine: this.offsetFromLine,\n textStyle: this.style.toJSON(),\n };\n\n if (this.justificationRange) {\n result.justificationRange = this.justificationRange.toJSON();\n }\n\n if (this.numeratorRange) {\n result.numeratorRange = this.numeratorRange.toJSON();\n }\n\n if (this.denominatorRange) {\n result.denominatorRange = this.denominatorRange.toJSON();\n }\n\n return result;\n }\n}\n\n/**\n * Represents the layout of a single line within a paragraph of a text block.\n * Contains a sequence of RunLayout objects, the computed range of the line, and its offset from the document origin.\n * Provides utilities for appending runs, computing ranges, and converting to result objects.\n * @beta\n */\nexport class LineLayout {\n public source: List | Run | Paragraph;\n public range = new Range2d(0, 0, 0, 0);\n public runRange = new Range2d(0, 0, 0, 0); // Range of all runs excluding marker.\n public justificationRange = new Range2d(0, 0, 0, 0);\n public offsetFromDocument: WritableXAndY;\n public depth: number;\n public lengthFromLastTab = 0; // Used to track the length from the last tab for tab runs.\n private _runs: RunLayout[] = [];\n private _marker?: RunLayout;\n\n public constructor(source: List | Run | Paragraph, style: TextStyleSettingsProps, context?: LayoutContext, depth: number = 0) {\n this.source = source;\n this.depth = depth;\n this.offsetFromDocument = { x: context?.textStyleResolver.resolveIndentation(style, depth) ?? 0, y: 0 };\n }\n\n /** Compute a string representation, primarily for debugging purposes. */\n public stringify(): string {\n const runs = this._runs.map((run) => run.stringify());\n return `${runs.join(\"\")}`;\n }\n\n /** Gets the array of RunLayout objects contained in this line. */\n public get runs(): ReadonlyArray<RunLayout> { return this._runs; }\n /** Indicates whether this line contains any runs. */\n public get isEmpty() { return this._runs.length === 0; }\n /** Gets the last RunLayout in this line. */\n public get back(): RunLayout {\n assert(!this.isEmpty);\n return this._runs[this._runs.length - 1];\n }\n\n /**\n * Gets or sets the marker RunLayout for this line, used for lists.\n * A marker is the symbol or character that appears before each list item in a list, bullets, numbers, etc.\n * */\n public get marker(): RunLayout | undefined { return this._marker; }\n public set marker(value: RunLayout | undefined) { this._marker = value; }\n\n public append(run: RunLayout): void {\n this._runs.push(run);\n this.computeRanges();\n }\n\n /** Invoked every time a run is appended,. */\n private computeRanges(): void {\n this.runRange.low.setZero();\n this.runRange.high.setZero();\n this.lengthFromLastTab = 0;\n\n // Some runs (fractions) are taller than others.\n // We want to center each run vertically inside the line.\n let lineHeight = 0;\n for (const run of this._runs) {\n lineHeight = Math.max(lineHeight, run.range.yLength());\n }\n\n for (const run of this._runs) {\n const runHeight = run.range.yLength();\n const runOffset = { x: this.runRange.high.x, y: (lineHeight - runHeight) / 2 };\n run.offsetFromLine = runOffset;\n\n const runLayoutRange = run.range.cloneTranslated(runOffset);\n this.runRange.extendRange(runLayoutRange);\n\n if (\"linebreak\" !== run.source.type) {\n const runJustificationRange = run.justificationRange?.cloneTranslated(runOffset);\n this.justificationRange.extendRange(runJustificationRange ?? runLayoutRange);\n }\n\n if (\"tab\" === run.source.type) {\n this.lengthFromLastTab = 0;\n } else {\n this.lengthFromLastTab += run.range.xLength();\n }\n }\n\n this.range.setFrom(this.runRange);\n\n if (this._marker) {\n const indentation = this.range.low.x;\n const x = indentation - (this._marker.style.tabInterval / 2) - this._marker.range.xLength();\n const runHeight = this._marker.range.yLength();\n const runOffset = {\n x,\n y: (lineHeight - runHeight) / 2 // Center the marker vertically in the line.\n };\n\n this._marker.offsetFromLine = runOffset;\n\n const markerRange = this._marker.range.cloneTranslated(this._marker.offsetFromLine);\n this.range.extendRange(markerRange);\n }\n }\n\n public toResult(): LineLayoutResult {\n return {\n runs: this.runs.map((x) => x.toResult()),\n marker: this.marker?.toResult(),\n range: this.range.toJSON(),\n justificationRange: this.justificationRange.toJSON(),\n offsetFromDocument: this.offsetFromDocument,\n };\n }\n}\n\n/**\n * Describes the layout of a text block as a collection of lines containing runs.\n * Computes the visual layout of the text block, including word wrapping, justification, and margins.\n * Provides access to the computed lines, ranges, and utilities for converting to result objects.\n * @beta\n */\nexport class TextBlockLayout {\n public source: TextBlock;\n\n /** @internal: This is primarily for debugging purposes. This is the range of text geometry */\n public textRange = new Range2d();\n\n /** The range including margins of the [[TextBlock]]. */\n public range = new Range2d();\n public lines: LineLayout[] = [];\n private _context: LayoutContext;\n\n public constructor(source: TextBlock, context: LayoutContext) {\n this._context = context;\n this.source = source;\n\n if (source.width > 0) {\n this.textRange.low.x = 0;\n this.textRange.high.x = source.width;\n }\n\n this.populateLines(context);\n this.justifyLines();\n this.applyMargins(source.margins);\n }\n\n public toResult(): TextBlockLayoutResult {\n return {\n lines: this.lines.map((x) => x.toResult()),\n range: this.range.toJSON(),\n };\n }\n\n /** Compute a string representation, primarily for debugging purposes. */\n public stringify(): string {\n return this.lines.map((line) => line.stringify()).join(\"\\n\");\n }\n\n private get _back(): LineLayout {\n assert(this.lines.length > 0);\n return this.lines[this.lines.length - 1];\n }\n\n private populateLines(context: LayoutContext): void {\n const doc = this.source;\n if (!doc.children || doc.children.length === 0) {\n return;\n }\n\n let curLine = new LineLayout(doc.children[0], doc.children[0].styleOverrides, context);\n let childIndex = 0;\n for (const child of doc.children) {\n curLine = this.populateComponent(child, childIndex++, context, doc.width, curLine, doc, doc.styleOverrides);\n }\n\n if (curLine.runs.length > 0) {\n this.flushLine(context, curLine, doc.styleOverrides);\n }\n }\n\n private populateComponent(\n component: Run | Paragraph | List,\n componentIndex: number,\n context: LayoutContext,\n docWidth: number,\n curLine: LineLayout,\n parent: StructuralTextBlockComponent,\n cumulativeOverrides: TextStyleSettingsProps,\n depth: number = 0\n ): LineLayout {\n cumulativeOverrides = { ...cumulativeOverrides, ...component.styleOverrides };\n\n switch (component.type) {\n case \"list\": {\n // If we have any runs in the current line, flush it before starting the list.\n if (curLine.runs.length > 0) {\n curLine = this.flushLine(context, curLine, cumulativeOverrides, component.children[0], true, depth + 1);\n } else {\n // If not, we need to apply the indentation for the list to the first line.\n curLine.offsetFromDocument.x = context.textStyleResolver.resolveIndentation(cumulativeOverrides, depth + 1);\n curLine.depth = depth + 1;\n }\n\n // Iterate through each list item, setting the marker and populating its contents.\n component.children.forEach((child, index) => {\n const markerContent = context.textStyleResolver.resolveMarkerText(cumulativeOverrides, index + 1);\n const markerRun = TextRun.create({ content: markerContent });\n curLine.marker = RunLayout.create(markerRun, context, cumulativeOverrides);\n\n curLine = this.populateComponent(child, index, context, docWidth, curLine, component, cumulativeOverrides, depth + 1);\n });\n\n // Lastly flush the line.\n const nextSibling = parent?.children[componentIndex + 1];\n if (curLine && nextSibling) {\n curLine = this.flushLine(context, curLine, cumulativeOverrides, nextSibling, true, depth);\n }\n break;\n }\n case \"paragraph\": {\n // Iterate through each paragraph child (either a list or a run), populating its contents.\n component.children.forEach((child, index) => {\n curLine = this.populateComponent(child, index, context, docWidth, curLine, component, cumulativeOverrides, depth);\n });\n\n // Lastly flush the line.\n const nextSibling = parent?.children[componentIndex + 1];\n if (curLine && nextSibling) {\n curLine = this.flushLine(context, curLine, cumulativeOverrides, nextSibling, true, depth);\n }\n break;\n }\n case \"text\": {\n const layout = RunLayout.create(component, context, cumulativeOverrides);\n\n // Text can be word-wrapped, so we need to split it into multiple runs if necessary.\n if (docWidth > 0) {\n layout.split(context).forEach(r => { curLine = this.populateRun(curLine, r, context, cumulativeOverrides, docWidth) });\n } else {\n curLine = this.populateRun(curLine, layout, context, cumulativeOverrides, docWidth);\n }\n break;\n }\n case \"fraction\":\n case \"tab\": {\n const layout = RunLayout.create(component, context, cumulativeOverrides);\n curLine = this.populateRun(curLine, layout, context, cumulativeOverrides, docWidth);\n break;\n }\n case \"linebreak\": {\n const layout = RunLayout.create(component, context, cumulativeOverrides);\n\n curLine.append(layout);\n curLine = this.flushLine(context, curLine, cumulativeOverrides, undefined, undefined, depth);\n break;\n }\n default: break;\n }\n\n return curLine;\n };\n\n private populateRun(curLine: LineLayout, run: RunLayout, context: LayoutContext, cumulativeOverrides: TextStyleSettingsProps, docWidth: number): LineLayout {\n // If this is a tab, we need to apply the tab shift first, and then we can treat it like a text run.\n applyTabShift(run, curLine, context);\n\n // If our width is not set, then we don't have to compute word wrapping, so just append the run, and continue.\n if (docWidth <= 0) {\n curLine.append(run);\n return curLine;\n }\n\n // If not, we need to determine if we can append this run to the current line without exceeding the document width or if we need to word wrap.\n const runWidth = run.justificationRange?.xLength() ?? run.range.xLength();\n const lineWidth = curLine.runRange.xLength();\n const newWidth = runWidth + lineWidth + curLine.offsetFromDocument.x;\n\n // If true, then no word wrapping is required, so we can append to the current line.\n if (newWidth < docWidth || Geometry.isAlmostEqualNumber(newWidth, docWidth, Geometry.smallMetricDistance)) {\n curLine.append(run);\n return curLine;\n }\n\n // If not, do word wrapping\n if (curLine.runs.length === 0) {\n curLine.append(run);\n\n // Lastly, flush line\n curLine = this.flushLine(context, curLine, cumulativeOverrides, undefined, undefined, curLine.depth);\n } else {\n // First, flush line\n curLine = this.flushLine(context, curLine, cumulativeOverrides, undefined, undefined, curLine.depth);\n\n // Recompute tab shift if applicable\n applyTabShift(run, curLine, context);\n\n curLine.append(run);\n }\n\n return curLine;\n };\n\n private flushLine(context: LayoutContext, curLine: LineLayout, cumulativeOverrides: TextStyleSettingsProps, next?: List | Run | Paragraph, newParagraph: boolean = false, depth: number = 0): LineLayout {\n next = next ?? curLine.source;\n\n // We want to guarantee that each layout line has at least one run.\n if (curLine.runs.length === 0) {\n if (this.lines.length === 0 || this._back.runs.length === 0) {\n return new LineLayout(next, cumulativeOverrides, context, depth);\n }\n\n if (curLine.source.type !== \"linebreak\") {\n const newLine = new LineLayout(next, cumulativeOverrides, context, depth);\n newLine.offsetFromDocument.y -= context.textStyleResolver.blockSettings.paragraphSpacingFactor * context.textStyleResolver.blockSettings.lineHeight;\n return newLine;\n }\n\n const run = curLine.source.clone();\n curLine.append(RunLayout.create(run, context, cumulativeOverrides));\n }\n\n // Line origin is its baseline.\n const lineOffset = { ...curLine.offsetFromDocument }; // Start with the line's original offset, which includes indentation.\n lineOffset.y -= curLine.range.yLength(); // Shift down the baseline\n\n // Place it below any existing lines\n if (this.lines.length > 0) {\n lineOffset.y += this._back.offsetFromDocument.y;\n lineOffset.y -= context.textStyleResolver.blockSettings.lineSpacingFactor * context.textStyleResolver.blockSettings.lineHeight;\n }\n\n curLine.offsetFromDocument = lineOffset;\n\n // Update document range from computed line range and position\n this.textRange.extendRange(curLine.range.cloneTranslated(lineOffset));\n\n this.lines.push(curLine);\n if (newParagraph) {\n const newLine = new LineLayout(next, cumulativeOverrides, context, depth);\n newLine.offsetFromDocument.y -= context.textStyleResolver.blockSettings.paragraphSpacingFactor * context.textStyleResolver.blockSettings.lineHeight;\n return newLine;\n }\n return new LineLayout(next, cumulativeOverrides, context, depth);\n }\n\n private justifyLines(): void {\n // We don't want to justify empty text, or a single line of text whose width is 0. By default text is already left justified.\n if (this.lines.length < 1 || (this.lines.length === 1 && this.source.width === 0) || \"left\" === this.source.justification) {\n return;\n }\n\n // This is the minimum width of the document's bounding box.\n const docWidth = this.source.width;\n\n let minOffset = Number.MAX_VALUE;\n for (const line of this.lines) {\n const lineWidth = line.justificationRange.xLength() + line.offsetFromDocument.x;\n\n let offset = docWidth - lineWidth;\n if (\"center\" === this.source.justification) {\n offset = offset / 2;\n }\n\n line.offsetFromDocument.x += offset;\n minOffset = Math.min(offset, minOffset);\n }\n\n if (minOffset < 0) {\n // Shift left to accommodate lines that exceeded the document's minimum width.\n this.textRange.low.x += minOffset;\n this.textRange.high.x += minOffset;\n }\n }\n\n private applyMargins(margins: TextBlockMargins) {\n this.range = this.textRange.clone();\n\n if (this.range.isNull)\n return;\n\n // Disregard negative margins.\n const right = margins.right >= 0 ? margins.right : 0;\n const left = margins.left >= 0 ? margins.left : 0;\n const top = margins.top >= 0 ? margins.top : 0;\n const bottom = margins.bottom >= 0 ? margins.bottom : 0;\n\n const xHigh = this.textRange.high.x + right;\n const yHigh = this.textRange.high.y + top;\n const xLow = this.textRange.low.x - left;\n const yLow = this.textRange.low.y - bottom;\n\n this.range.extendXY(xHigh, yHigh);\n this.range.extendXY(xLow, yLow);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":"AAKA,OAAO,EAA0D,QAAQ,EAAE,UAAU,EAAoB,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAClK,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAmC,UAAU,EAAU,MAAM,qBAAqB,CAAC;AA8B1F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IAEnC,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAA;CACrD;AAsLD,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAKlH;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAsBlF;AAID,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAWvF;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAmBtG"}
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":"AAKA,OAAO,EAA0D,QAAQ,EAAE,UAAU,EAAoB,iBAAiB,EAAE,SAAS,EAA8B,MAAM,oBAAoB,CAAC;AAC9L,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAmC,UAAU,EAAU,MAAM,qBAAqB,CAAC;AA8B1F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IAEnC,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAA;CACrD;AAsLD,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAKlH;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAsBlF;AAID,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CASvF;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAmBtG"}
@@ -211,11 +211,9 @@ function updateField(field, context) {
211
211
  // of fields whose display strings changed as a result.
212
212
  function updateFields(textBlock, context) {
213
213
  let numUpdated = 0;
214
- for (const paragraph of textBlock.paragraphs) {
215
- for (const run of paragraph.runs) {
216
- if (run.type === "field" && updateField(run, context)) {
217
- ++numUpdated;
218
- }
214
+ for (const { child } of (0, core_common_1.traverseTextBlockComponent)(textBlock)) {
215
+ if (child.type === "field" && updateField(child, context)) {
216
+ ++numUpdated;
219
217
  }
220
218
  }
221
219
  return numUpdated;
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;AA4N/F,kDAKC;AAGD,kCAsBC;AAID,oCAWC;AAGD,kDAmBC;AA7RD,oDAAkK;AAElK,sDAA0F;AAC1F,uEAAoE;AACpE,+FAAkF;AAClF,gEAA6H;AAiC7H,0EAA0E;AAC1E,SAAS,qBAAqB,CAAC,KAAe,EAAE,MAAgB;IAC9D,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC;IAChC,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,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QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { ECSqlValueType, FieldPrimitiveValue, FieldPropertyType, FieldRun, FieldValue, formatFieldValue, RelationshipProps, TextBlock } from \"@itwin/core-common\";\nimport { IModelDb } from \"../../IModelDb\";\nimport { assert, DbResult, expectDefined, Id64String, Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"../../BackendLoggerCategory\";\nimport { isITextAnnotation } from \"../../annotations/ElementDrivesTextAnnotation\";\nimport { AnyClass, EntityClass, PrimitiveType, Property, PropertyType, StructArrayProperty } from \"@itwin/ecschema-metadata\";\n\ninterface FieldStructValue { [key: string]: any }\n\n// An intermediate value obtained while evaluating a FieldPropertyPath.\ntype FieldValueType = {\n primitive: FieldPrimitiveValue;\n struct?: never;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct: FieldStructValue;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray: FieldPrimitiveValue[];\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray?: never;\n structArray: FieldStructValue[];\n}\n\nexport interface UpdateFieldsContext {\n readonly hostElementId: Id64String;\n\n getProperty(field: FieldRun): FieldValue | undefined\n}\n\n// Resolve the raw primitive value of the property that a field points to.\nfunction getFieldPropertyValue(field: FieldRun, iModel: IModelDb): FieldValue | undefined {\n const host = field.propertyHost;\n const schemaItem = iModel.schemaContext.getSchemaItemSync(host.schemaName, host.className);\n if (!EntityClass.isEntityClass(schemaItem)) {\n return undefined;\n }\n\n let ecClass: AnyClass = schemaItem;\n const { propertyName, accessors } = field.propertyPath;\n let ecProp = ecClass.getPropertySync(propertyName);\n if (!ecProp) {\n return undefined;\n }\n\n const isAspect = ecClass.isSync(\"ElementAspect\", \"BisCore\");\n const where = ` WHERE ${isAspect ? \"Element.Id\" : \"ECInstanceId\"}=${host.elementId}`;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n let curValue: FieldValueType | undefined = iModel.withPreparedStatement(`SELECT ${propertyName} FROM ${host.schemaName}.${host.className} ${where}`, (stmt) => {\n if (stmt.step() !== DbResult.BE_SQLITE_ROW) {\n return undefined;\n }\n\n const rootValue = stmt.getValue(0);\n if (undefined === rootValue || rootValue.isNull) {\n return undefined;\n }\n\n switch (rootValue.columnInfo.getType()) {\n case ECSqlValueType.Blob:\n return { primitive: rootValue.getBlob() };\n case ECSqlValueType.Boolean:\n return { primitive: rootValue.getBoolean() };\n case ECSqlValueType.DateTime:\n return { primitive: new Date(rootValue.getDateTime()) };\n case ECSqlValueType.Double:\n return { primitive: rootValue.getDouble() };\n case ECSqlValueType.Guid:\n return { primitive: rootValue.getGuid() };\n case ECSqlValueType.Int:\n case ECSqlValueType.Int64:\n return { primitive: rootValue.getInteger() };\n case ECSqlValueType.Point2d:\n return { primitive: rootValue.getXAndY() };\n case ECSqlValueType.Point3d:\n return { primitive: rootValue.getXYAndZ() };\n case ECSqlValueType.String:\n return { primitive: rootValue.getString() };\n case ECSqlValueType.Struct: {\n ecProp = expectDefined(ecProp);\n assert(ecProp.isStruct());\n ecClass = ecProp.structClass;\n return { struct: rootValue.getStruct() };\n }\n case ECSqlValueType.PrimitiveArray: {\n return { primitiveArray: rootValue.getArray() };\n }\n case ECSqlValueType.StructArray: {\n return { structArray: rootValue.getArray() };\n }\n // Unsupported:\n // case ECSqlValueType.Geometry:\n // case ECSqlValueType.Navigation:\n // case ECSqlValueType.Id:\n }\n\n return undefined;\n });\n\n if (undefined === curValue) {\n return undefined;\n }\n\n if (accessors) {\n for (const accessor of accessors) {\n if (undefined !== curValue.primitive) {\n // Can't index into a primitive.\n return undefined;\n }\n\n if (typeof accessor === \"number\") {\n const array: FieldPrimitiveValue[] | FieldStructValue[] | undefined = curValue.primitiveArray ?? curValue.structArray;\n if (!array) {\n return undefined;\n }\n\n const index: number = accessor < 0 ? (array.length + accessor) : accessor;\n const item: FieldPrimitiveValue | FieldStructValue = array[index];\n if (undefined === item) {\n return undefined;\n } else if (curValue.primitiveArray) {\n curValue = { primitive: curValue.primitiveArray[index] };\n } else {\n assert(undefined !== curValue.structArray);\n assert(ecProp instanceof StructArrayProperty);\n\n ecClass = ecProp.structClass;\n curValue = { struct: curValue.structArray[index] };\n }\n } else {\n if (undefined === curValue.struct) {\n return undefined;\n }\n\n const item: any = curValue.struct[accessor];\n if (undefined === item) {\n return undefined;\n }\n\n ecProp = ecClass.getPropertySync(accessor);\n if (!ecProp) {\n return undefined;\n }\n\n if (ecProp.isArray()) {\n curValue = ecProp.isStruct() ? { structArray: item } : { primitiveArray: item };\n } else if (ecProp.isStruct()) {\n ecClass = ecProp.structClass;\n curValue = { struct: item };\n } else if (ecProp.isPrimitive()) {\n curValue = { primitive: item };\n } else {\n return undefined;\n }\n }\n }\n }\n\n const propertyType = determineFieldPropertyType(ecProp);\n if(!propertyType) {\n return undefined;\n }\n\n // The ultimate result must be a primitive value.\n if (undefined === curValue.primitive) {\n return undefined;\n }\n\n return { value: curValue.primitive, type: propertyType };\n}\n\nfunction determineFieldPropertyType(prop: Property): FieldPropertyType | undefined {\n if (prop.isEnumeration()) {\n switch (prop.propertyType) {\n case PropertyType.Integer_Enumeration:\n return \"int-enum\";\n case PropertyType.String_Enumeration:\n return \"string-enum\";\n default:\n return undefined;\n }\n }\n\n if (prop.isPrimitive()) {\n switch (prop.primitiveType) {\n case PrimitiveType.Boolean:\n return \"boolean\";\n case PrimitiveType.String:\n return prop.extendedTypeName === \"DateTime\" ? \"datetime\" : \"string\";\n case PrimitiveType.DateTime:\n return \"datetime\";\n case PrimitiveType.Double:\n case PrimitiveType.Long:\n return \"quantity\";\n case PrimitiveType.Point2d:\n case PrimitiveType.Point3d:\n return \"coordinate\";\n case PrimitiveType.Binary:\n return prop.extendedTypeName === \"BeGuid\" ? \"string\" : undefined;\n case PrimitiveType.Integer:\n case PrimitiveType.Long:\n return \"string\";\n default:\n return undefined;\n }\n }\n\n return undefined;\n}\n\nexport function createUpdateContext(hostElementId: string, iModel: IModelDb, deleted: boolean): UpdateFieldsContext {\n return {\n hostElementId,\n getProperty: deleted ? () => undefined : (field) => getFieldPropertyValue(field, iModel),\n };\n}\n\n// Recompute the display value of a single field, return false if it couldn't be evaluated.\nexport function updateField(field: FieldRun, context: UpdateFieldsContext): boolean {\n if (context.hostElementId !== field.propertyHost.elementId) {\n return false;\n }\n\n let newContent: string | undefined;\n try {\n const propValue = context.getProperty(field);\n if (undefined !== propValue) {\n newContent = formatFieldValue(propValue, field.formatOptions);\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n\n newContent = newContent ?? FieldRun.invalidContentIndicator;\n if (newContent === field.cachedContent) {\n return false;\n }\n\n field.setCachedContent(newContent);\n return true;\n}\n\n// Re-evaluates the display strings for all fields that target the element specified by `context` and returns the number\n// of fields whose display strings changed as a result.\nexport function updateFields(textBlock: TextBlock, context: UpdateFieldsContext): number {\n let numUpdated = 0;\n for (const paragraph of textBlock.paragraphs) {\n for (const run of paragraph.runs) {\n if (run.type === \"field\" && updateField(run, context)) {\n ++numUpdated;\n }\n }\n }\n\n return numUpdated;\n}\n\n// Invoked by ElementDrivesTextAnnotation to update fields in target element when source element changes or is deleted.\nexport function updateElementFields(props: RelationshipProps, iModel: IModelDb, deleted: boolean): void {\n try {\n const target = iModel.elements.getElement(props.targetId);\n if (isITextAnnotation(target)) {\n const context = createUpdateContext(props.sourceId, iModel, deleted);\n const updatedBlocks = [];\n for (const block of target.getTextBlocks()) {\n if (updateFields(block.textBlock, context)) {\n updatedBlocks.push(block);\n }\n }\n\n if (updatedBlocks.length > 0) {\n target.updateTextBlocks(updatedBlocks);\n }\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n}\n\n"]}
1
+ {"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a,EAAE,EAAE,CAAC;gBAC3C,IAAI,YAAY,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;oBAC3C,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;YAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7B,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,qBAAM,CAAC,YAAY,CAAC,6CAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { ECSqlValueType, FieldPrimitiveValue, FieldPropertyType, FieldRun, FieldValue, formatFieldValue, RelationshipProps, TextBlock, traverseTextBlockComponent } from \"@itwin/core-common\";\nimport { IModelDb } from \"../../IModelDb\";\nimport { assert, DbResult, expectDefined, Id64String, Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"../../BackendLoggerCategory\";\nimport { isITextAnnotation } from \"../../annotations/ElementDrivesTextAnnotation\";\nimport { AnyClass, EntityClass, PrimitiveType, Property, PropertyType, StructArrayProperty } from \"@itwin/ecschema-metadata\";\n\ninterface FieldStructValue { [key: string]: any }\n\n// An intermediate value obtained while evaluating a FieldPropertyPath.\ntype FieldValueType = {\n primitive: FieldPrimitiveValue;\n struct?: never;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct: FieldStructValue;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray: FieldPrimitiveValue[];\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray?: never;\n structArray: FieldStructValue[];\n}\n\nexport interface UpdateFieldsContext {\n readonly hostElementId: Id64String;\n\n getProperty(field: FieldRun): FieldValue | undefined\n}\n\n// Resolve the raw primitive value of the property that a field points to.\nfunction getFieldPropertyValue(field: FieldRun, iModel: IModelDb): FieldValue | undefined {\n const host = field.propertyHost;\n const schemaItem = iModel.schemaContext.getSchemaItemSync(host.schemaName, host.className);\n if (!EntityClass.isEntityClass(schemaItem)) {\n return undefined;\n }\n\n let ecClass: AnyClass = schemaItem;\n const { propertyName, accessors } = field.propertyPath;\n let ecProp = ecClass.getPropertySync(propertyName);\n if (!ecProp) {\n return undefined;\n }\n\n const isAspect = ecClass.isSync(\"ElementAspect\", \"BisCore\");\n const where = ` WHERE ${isAspect ? \"Element.Id\" : \"ECInstanceId\"}=${host.elementId}`;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n let curValue: FieldValueType | undefined = iModel.withPreparedStatement(`SELECT ${propertyName} FROM ${host.schemaName}.${host.className} ${where}`, (stmt) => {\n if (stmt.step() !== DbResult.BE_SQLITE_ROW) {\n return undefined;\n }\n\n const rootValue = stmt.getValue(0);\n if (undefined === rootValue || rootValue.isNull) {\n return undefined;\n }\n\n switch (rootValue.columnInfo.getType()) {\n case ECSqlValueType.Blob:\n return { primitive: rootValue.getBlob() };\n case ECSqlValueType.Boolean:\n return { primitive: rootValue.getBoolean() };\n case ECSqlValueType.DateTime:\n return { primitive: new Date(rootValue.getDateTime()) };\n case ECSqlValueType.Double:\n return { primitive: rootValue.getDouble() };\n case ECSqlValueType.Guid:\n return { primitive: rootValue.getGuid() };\n case ECSqlValueType.Int:\n case ECSqlValueType.Int64:\n return { primitive: rootValue.getInteger() };\n case ECSqlValueType.Point2d:\n return { primitive: rootValue.getXAndY() };\n case ECSqlValueType.Point3d:\n return { primitive: rootValue.getXYAndZ() };\n case ECSqlValueType.String:\n return { primitive: rootValue.getString() };\n case ECSqlValueType.Struct: {\n ecProp = expectDefined(ecProp);\n assert(ecProp.isStruct());\n ecClass = ecProp.structClass;\n return { struct: rootValue.getStruct() };\n }\n case ECSqlValueType.PrimitiveArray: {\n return { primitiveArray: rootValue.getArray() };\n }\n case ECSqlValueType.StructArray: {\n return { structArray: rootValue.getArray() };\n }\n // Unsupported:\n // case ECSqlValueType.Geometry:\n // case ECSqlValueType.Navigation:\n // case ECSqlValueType.Id:\n }\n\n return undefined;\n });\n\n if (undefined === curValue) {\n return undefined;\n }\n\n if (accessors) {\n for (const accessor of accessors) {\n if (undefined !== curValue.primitive) {\n // Can't index into a primitive.\n return undefined;\n }\n\n if (typeof accessor === \"number\") {\n const array: FieldPrimitiveValue[] | FieldStructValue[] | undefined = curValue.primitiveArray ?? curValue.structArray;\n if (!array) {\n return undefined;\n }\n\n const index: number = accessor < 0 ? (array.length + accessor) : accessor;\n const item: FieldPrimitiveValue | FieldStructValue = array[index];\n if (undefined === item) {\n return undefined;\n } else if (curValue.primitiveArray) {\n curValue = { primitive: curValue.primitiveArray[index] };\n } else {\n assert(undefined !== curValue.structArray);\n assert(ecProp instanceof StructArrayProperty);\n\n ecClass = ecProp.structClass;\n curValue = { struct: curValue.structArray[index] };\n }\n } else {\n if (undefined === curValue.struct) {\n return undefined;\n }\n\n const item: any = curValue.struct[accessor];\n if (undefined === item) {\n return undefined;\n }\n\n ecProp = ecClass.getPropertySync(accessor);\n if (!ecProp) {\n return undefined;\n }\n\n if (ecProp.isArray()) {\n curValue = ecProp.isStruct() ? { structArray: item } : { primitiveArray: item };\n } else if (ecProp.isStruct()) {\n ecClass = ecProp.structClass;\n curValue = { struct: item };\n } else if (ecProp.isPrimitive()) {\n curValue = { primitive: item };\n } else {\n return undefined;\n }\n }\n }\n }\n\n const propertyType = determineFieldPropertyType(ecProp);\n if(!propertyType) {\n return undefined;\n }\n\n // The ultimate result must be a primitive value.\n if (undefined === curValue.primitive) {\n return undefined;\n }\n\n return { value: curValue.primitive, type: propertyType };\n}\n\nfunction determineFieldPropertyType(prop: Property): FieldPropertyType | undefined {\n if (prop.isEnumeration()) {\n switch (prop.propertyType) {\n case PropertyType.Integer_Enumeration:\n return \"int-enum\";\n case PropertyType.String_Enumeration:\n return \"string-enum\";\n default:\n return undefined;\n }\n }\n\n if (prop.isPrimitive()) {\n switch (prop.primitiveType) {\n case PrimitiveType.Boolean:\n return \"boolean\";\n case PrimitiveType.String:\n return prop.extendedTypeName === \"DateTime\" ? \"datetime\" : \"string\";\n case PrimitiveType.DateTime:\n return \"datetime\";\n case PrimitiveType.Double:\n case PrimitiveType.Long:\n return \"quantity\";\n case PrimitiveType.Point2d:\n case PrimitiveType.Point3d:\n return \"coordinate\";\n case PrimitiveType.Binary:\n return prop.extendedTypeName === \"BeGuid\" ? \"string\" : undefined;\n case PrimitiveType.Integer:\n case PrimitiveType.Long:\n return \"string\";\n default:\n return undefined;\n }\n }\n\n return undefined;\n}\n\nexport function createUpdateContext(hostElementId: string, iModel: IModelDb, deleted: boolean): UpdateFieldsContext {\n return {\n hostElementId,\n getProperty: deleted ? () => undefined : (field) => getFieldPropertyValue(field, iModel),\n };\n}\n\n// Recompute the display value of a single field, return false if it couldn't be evaluated.\nexport function updateField(field: FieldRun, context: UpdateFieldsContext): boolean {\n if (context.hostElementId !== field.propertyHost.elementId) {\n return false;\n }\n\n let newContent: string | undefined;\n try {\n const propValue = context.getProperty(field);\n if (undefined !== propValue) {\n newContent = formatFieldValue(propValue, field.formatOptions);\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n\n newContent = newContent ?? FieldRun.invalidContentIndicator;\n if (newContent === field.cachedContent) {\n return false;\n }\n\n field.setCachedContent(newContent);\n return true;\n}\n\n// Re-evaluates the display strings for all fields that target the element specified by `context` and returns the number\n// of fields whose display strings changed as a result.\nexport function updateFields(textBlock: TextBlock, context: UpdateFieldsContext): number {\n let numUpdated = 0;\n for (const { child } of traverseTextBlockComponent(textBlock)) {\n if (child.type === \"field\" && updateField(child, context)) {\n ++numUpdated;\n }\n }\n\n return numUpdated;\n}\n\n// Invoked by ElementDrivesTextAnnotation to update fields in target element when source element changes or is deleted.\nexport function updateElementFields(props: RelationshipProps, iModel: IModelDb, deleted: boolean): void {\n try {\n const target = iModel.elements.getElement(props.targetId);\n if (isITextAnnotation(target)) {\n const context = createUpdateContext(props.sourceId, iModel, deleted);\n const updatedBlocks = [];\n for (const block of target.getTextBlocks()) {\n if (updateFields(block.textBlock, context)) {\n updatedBlocks.push(block);\n }\n }\n\n if (updatedBlocks.length > 0) {\n target.updateTextBlocks(updatedBlocks);\n }\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n}\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ElementDrivesTextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotations/ElementDrivesTextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjE;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,sBAAsB;IACtB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,gIAAgI;IAChI,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;CACtB;AAKD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,oCAAoC,CAAC;IACxD,sFAAsF;IACtF,aAAa,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC1C,yFAAyF;IACzF,gBAAgB,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;CACtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC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eAAe;IAC9B,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,oCAAoC,CAAC;IACxD,sFAAsF;IACtF,aAAa,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC1C,yFAAyF;IACzF,gBAAgB,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;CACtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,eAAe,GAAG,OAAO,CAExF;AAED;;;;;;;GAOG;AACH,qBAAa,2BAA4B,SAAQ,oBAAoB;IACnE,WAA2B,SAAS,IAAI,MAAM,CAA0C;IAExF,gBAAgB;WACO,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI;IAItF,gBAAgB;WACO,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI;IAI5F;;;OAGG;WACW,oBAAoB,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO;IAK7D;;;OAGG;WACW,uBAAuB,CAAC,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI;CA2D/F;AAED;;GAEG;AACH,qBAAa,oCAAqC,SAAQ,cAAc;IACtE,OAAc,aAAa,SAAkD;gBAC1D,qBAAqB,EAAE,UAAU,EAAE,YAAY,GAAE,MAA2D;CAGhI"}
@@ -5,7 +5,7 @@
5
5
  /** @packageDocumentation
6
6
  * @module Elements
7
7
  */
8
- import { RelatedElement } from "@itwin/core-common";
8
+ import { RelatedElement, traverseTextBlockComponent } from "@itwin/core-common";
9
9
  import { ElementDrivesElement } from "../Relationship";
10
10
  import { updateElementFields } from "../internal/annotations/fields";
11
11
  import { DbResult, Id64 } from "@itwin/core-bentley";
@@ -70,11 +70,9 @@ export class ElementDrivesTextAnnotation extends ElementDrivesElement {
70
70
  const sourceToRelationship = new Map();
71
71
  const blocks = annotationElement.getTextBlocks();
72
72
  for (const block of blocks) {
73
- for (const paragraph of block.textBlock.paragraphs) {
74
- for (const run of paragraph.runs) {
75
- if (run.type === "field" && isValidSourceId(run.propertyHost.elementId)) {
76
- sourceToRelationship.set(run.propertyHost.elementId, null);
77
- }
73
+ for (const { child } of traverseTextBlockComponent(block.textBlock)) {
74
+ if (child.type === "field" && isValidSourceId(child.propertyHost.elementId)) {
75
+ sourceToRelationship.set(child.propertyHost.elementId, null);
78
76
  }
79
77
  }
80
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ElementDrivesTextAnnotation.js","sourceRoot":"","sources":["../../../src/annotations/ElementDrivesTextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAgC,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAerD,2IAA2I;AAC3I,MAAM,iBAAiB,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAgBlD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,OAAO,IAAI,OAAQ,OAAe,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC;AACvH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA4B,SAAQ,oBAAoB;IAC5D,MAAM,KAAc,SAAS,KAAa,OAAO,6BAA6B,CAAC,CAAC,CAAC;IAExF,gBAAgB;IACT,MAAM,CAAU,aAAa,CAAC,KAAwB,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Ac,CAAC,IAAI,oBAAoB,EAAE,CAAC;YAC9D,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;gBAC5B,2BAA2B,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;YACxG,CAAC;QACH,CAAC;QAED,KAAK,MAAM,cAAc,IAAI,kBAAkB,EAAE,CAAC;YAChD,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,qCAAqC,EAAE,cAAc,CAAC,CAAC;YAC7H,iBAAiB,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,oCAAqC,SAAQ,cAAc;IAC/D,MAAM,CAAC,aAAa,GAAG,8CAA8C,CAAC;IAC7E,YAAmB,qBAAiC,EAAE,eAAuB,oCAAoC,CAAC,aAAa;QAC7H,KAAK,CAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAC,CAAC;IACrD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Elements\n */\n\nimport { RelatedElement, RelationshipProps, TextBlock } from \"@itwin/core-common\";\nimport { ElementDrivesElement } from \"../Relationship\";\nimport { IModelDb } from \"../IModelDb\";\nimport { Element } from \"../Element\";\nimport { updateElementFields } from \"../internal/annotations/fields\";\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { ECVersion } from \"@itwin/ecschema-metadata\";\n\n/** Describes one of potentially many [TextBlock]($common)s hosted by an [[ITextAnnotation]].\n * For example, a [[TextAnnotation2d]] hosts only a single text block, but an element representing a table may\n * host one text block for each cell in the table, in which case it might use the combination of row and column\n * as the [[id]] for each text block.\n * @beta\n */\nexport interface TextBlockAndId {\n /** The text block. */\n readonly textBlock: TextBlock;\n /** An opaque identifier that allows the [[ITextAnnotation]] to discern which of its hosted text blocks is being referred to. */\n readonly id: unknown;\n}\n\n// ElementDrivesTextAnnotation was introduced in this version of BisCore - iModels with earlier versions cannot support field dependencies.\nconst minBisCoreVersion = new ECVersion(1, 0, 22);\n\n/** Interface implemented by [[GeometricElement]] subclasses whose schemas declare them to implement the mix-in `BisCore:ITextAnnotation`.\n * Such elements may host any number of [TextBlock]($common)s. `ITextAnnotation` provides a uniform way to interact with text regardless of\n * the type of element to which it belongs.\n * @beta\n */\nexport interface ITextAnnotation {\n /** The default [[AnnotationTextStyle]] used by the text annotation. */\n defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** Obtain a collection of all of the [TextBlock]($common)s hosted by this element. */\n getTextBlocks(): Iterable<TextBlockAndId>;\n /** Update the element to replace the contents of the specified [TextBlock]($common)s. */\n updateTextBlocks(textBlocks: TextBlockAndId[]): void;\n}\n\n/** Returns `true` if the specified `element` implements [[ITextAnnotation]].\n * @beta\n */\nexport function isITextAnnotation(element: Element): element is ITextAnnotation & Element {\n return [\"getTextBlocks\", \"updateTextBlocks\"].every((x) => x in element && typeof (element as any)[x] === \"function\");\n}\n\n/** A relationship in which the source element hosts one or more properties that are displayed by a target [[ITextAnnotation]] element.\n * This relationship is used to automatically update the [FieldRun]($common)s contained in the target element when the source element is modified.\n * An [[ITextAnnotation]] element should invoke [[updateFieldDependencies]] from its [[Element.onInserted]] and [[Element.onUpdated]] functions to\n * establish or update the relationships required for the [FieldRun]($common)s it contains.\n * @note This relationship was introduced in version 01.00.22 of the BisCore schema. [FieldRun]($common)s created in iModels that have not been upgraded to\n * that version or newer will not automatically update. Use [[isSupportedForIModel]] to check.\n * @beta\n */\nexport class ElementDrivesTextAnnotation extends ElementDrivesElement {\n public static override get className(): string { return \"ElementDrivesTextAnnotation\"; }\n\n /** @internal */\n public static override onRootChanged(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, false);\n }\n\n /** @internal */\n public static override onDeletedDependency(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, true);\n }\n\n /** Returns true if `iModel` contains a version of the BisCore schema new enough to support this relationship.\n * If not, the schema should be updated before inserting any [FieldRun]($common)s, or those runs will not\n * update when the source element changes.\n */\n public static isSupportedForIModel(iModel: IModelDb): boolean {\n const bisCoreVersion = iModel.querySchemaVersionNumbers(\"BisCore\");\n return undefined !== bisCoreVersion && bisCoreVersion.compare(minBisCoreVersion) >= 0;\n }\n\n /** Examines all of the [FieldRun]($common)s within the specified [[ITextAnnotation]] and ensures that the appropriate\n * `ElementDrivesTextAnnotation` relationships exist between the fields' source elements and this target element.\n * It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.\n */\n public static updateFieldDependencies(annotationElementId: Id64String, iModel: IModelDb): void {\n if (!ElementDrivesTextAnnotation.isSupportedForIModel(iModel)) {\n return;\n }\n\n const annotationElement = iModel.elements.tryGetElement<Element>(annotationElementId);\n if (!annotationElement || !isITextAnnotation(annotationElement)) {\n return;\n }\n\n // The native layer will allow us to insert relationships to invalid or non-existent source elements...errors will arise later. Prevent it.\n function isValidSourceId(id: Id64String): boolean {\n if (!Id64.isValidId64(id)) {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return iModel.withPreparedStatement(\"SELECT CodeValue FROM BisCore.Element WHERE ECInstanceId=?\", (stmt) => {\n stmt.bindId(1, id);\n return DbResult.BE_SQLITE_ROW === stmt.step();\n });\n }\n\n const sourceToRelationship = new Map<Id64String, Id64String | null>();\n const blocks = annotationElement.getTextBlocks();\n for (const block of blocks) {\n for (const paragraph of block.textBlock.paragraphs) {\n for (const run of paragraph.runs) {\n if (run.type === \"field\" && isValidSourceId(run.propertyHost.elementId)) {\n sourceToRelationship.set(run.propertyHost.elementId, null);\n }\n }\n }\n }\n\n const staleRelationships = new Set<Id64String>();\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n annotationElement.iModel.withPreparedStatement(`SELECT ECInstanceId, SourceECInstanceId FROM BisCore.ElementDrivesTextAnnotation WHERE TargetECInstanceId=${annotationElement.id}`, (stmt) => {\n while (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const relationshipId = stmt.getValue(0).getId();\n const sourceId = stmt.getValue(1).getId();\n if (sourceToRelationship.has(sourceId)) {\n sourceToRelationship.set(sourceId, relationshipId);\n } else {\n staleRelationships.add(relationshipId);\n }\n }\n });\n\n for (const [sourceId, relationshipId] of sourceToRelationship) {\n if (relationshipId === null) {\n ElementDrivesTextAnnotation.create(annotationElement.iModel, sourceId, annotationElement.id).insert();\n }\n }\n\n for (const relationshipId of staleRelationships) {\n const props = annotationElement.iModel.relationships.getInstanceProps(\"BisCore.ElementDrivesTextAnnotation\", relationshipId);\n annotationElement.iModel.relationships.deleteInstance(props);\n }\n }\n}\n\n/** Relationship indicating that the [[AnnotationTextStyle]] is being used as the default style for the [[ITextAnnotation]].\n * @beta\n */\nexport class TextAnnotationUsesTextStyleByDefault extends RelatedElement {\n public static classFullName = \"BisCore:TextAnnotationUsesTextStyleByDefault\";\n public constructor(annotationTextStyleId: Id64String, relClassName: string = TextAnnotationUsesTextStyleByDefault.classFullName) {\n super({ id: annotationTextStyleId, relClassName });\n }\n}"]}
1
+ {"version":3,"file":"ElementDrivesTextAnnotation.js","sourceRoot":"","sources":["../../../src/annotations/ElementDrivesTextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAgC,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACjE,OAAO,EA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ourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Elements\n */\n\nimport { RelatedElement, RelationshipProps, TextBlock, traverseTextBlockComponent } from \"@itwin/core-common\";\nimport { ElementDrivesElement } from \"../Relationship\";\nimport { IModelDb } from \"../IModelDb\";\nimport { Element } from \"../Element\";\nimport { updateElementFields } from \"../internal/annotations/fields\";\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { ECVersion } from \"@itwin/ecschema-metadata\";\n\n/** Describes one of potentially many [TextBlock]($common)s hosted by an [[ITextAnnotation]].\n * For example, a [[TextAnnotation2d]] hosts only a single text block, but an element representing a table may\n * host one text block for each cell in the table, in which case it might use the combination of row and column\n * as the [[id]] for each text block.\n * @beta\n */\nexport interface TextBlockAndId {\n /** The text block. */\n readonly textBlock: TextBlock;\n /** An opaque identifier that allows the [[ITextAnnotation]] to discern which of its hosted text blocks is being referred to. */\n readonly id: unknown;\n}\n\n// ElementDrivesTextAnnotation was introduced in this version of BisCore - iModels with earlier versions cannot support field dependencies.\nconst minBisCoreVersion = new ECVersion(1, 0, 22);\n\n/** Interface implemented by [[GeometricElement]] subclasses whose schemas declare them to implement the mix-in `BisCore:ITextAnnotation`.\n * Such elements may host any number of [TextBlock]($common)s. `ITextAnnotation` provides a uniform way to interact with text regardless of\n * the type of element to which it belongs.\n * @beta\n */\nexport interface ITextAnnotation {\n /** The default [[AnnotationTextStyle]] used by the text annotation. */\n defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** Obtain a collection of all of the [TextBlock]($common)s hosted by this element. */\n getTextBlocks(): Iterable<TextBlockAndId>;\n /** Update the element to replace the contents of the specified [TextBlock]($common)s. */\n updateTextBlocks(textBlocks: TextBlockAndId[]): void;\n}\n\n/** Returns `true` if the specified `element` implements [[ITextAnnotation]].\n * @beta\n */\nexport function isITextAnnotation(element: Element): element is ITextAnnotation & Element {\n return [\"getTextBlocks\", \"updateTextBlocks\"].every((x) => x in element && typeof (element as any)[x] === \"function\");\n}\n\n/** A relationship in which the source element hosts one or more properties that are displayed by a target [[ITextAnnotation]] element.\n * This relationship is used to automatically update the [FieldRun]($common)s contained in the target element when the source element is modified.\n * An [[ITextAnnotation]] element should invoke [[updateFieldDependencies]] from its [[Element.onInserted]] and [[Element.onUpdated]] functions to\n * establish or update the relationships required for the [FieldRun]($common)s it contains.\n * @note This relationship was introduced in version 01.00.22 of the BisCore schema. [FieldRun]($common)s created in iModels that have not been upgraded to\n * that version or newer will not automatically update. Use [[isSupportedForIModel]] to check.\n * @beta\n */\nexport class ElementDrivesTextAnnotation extends ElementDrivesElement {\n public static override get className(): string { return \"ElementDrivesTextAnnotation\"; }\n\n /** @internal */\n public static override onRootChanged(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, false);\n }\n\n /** @internal */\n public static override onDeletedDependency(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, true);\n }\n\n /** Returns true if `iModel` contains a version of the BisCore schema new enough to support this relationship.\n * If not, the schema should be updated before inserting any [FieldRun]($common)s, or those runs will not\n * update when the source element changes.\n */\n public static isSupportedForIModel(iModel: IModelDb): boolean {\n const bisCoreVersion = iModel.querySchemaVersionNumbers(\"BisCore\");\n return undefined !== bisCoreVersion && bisCoreVersion.compare(minBisCoreVersion) >= 0;\n }\n\n /** Examines all of the [FieldRun]($common)s within the specified [[ITextAnnotation]] and ensures that the appropriate\n * `ElementDrivesTextAnnotation` relationships exist between the fields' source elements and this target element.\n * It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.\n */\n public static updateFieldDependencies(annotationElementId: Id64String, iModel: IModelDb): void {\n if (!ElementDrivesTextAnnotation.isSupportedForIModel(iModel)) {\n return;\n }\n\n const annotationElement = iModel.elements.tryGetElement<Element>(annotationElementId);\n if (!annotationElement || !isITextAnnotation(annotationElement)) {\n return;\n }\n\n // The native layer will allow us to insert relationships to invalid or non-existent source elements...errors will arise later. Prevent it.\n function isValidSourceId(id: Id64String): boolean {\n if (!Id64.isValidId64(id)) {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return iModel.withPreparedStatement(\"SELECT CodeValue FROM BisCore.Element WHERE ECInstanceId=?\", (stmt) => {\n stmt.bindId(1, id);\n return DbResult.BE_SQLITE_ROW === stmt.step();\n });\n }\n\n const sourceToRelationship = new Map<Id64String, Id64String | null>();\n const blocks = annotationElement.getTextBlocks();\n\n for (const block of blocks) {\n for (const { child } of traverseTextBlockComponent(block.textBlock)) {\n if (child.type === \"field\" && isValidSourceId(child.propertyHost.elementId)) {\n sourceToRelationship.set(child.propertyHost.elementId, null);\n }\n }\n }\n\n const staleRelationships = new Set<Id64String>();\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n annotationElement.iModel.withPreparedStatement(`SELECT ECInstanceId, SourceECInstanceId FROM BisCore.ElementDrivesTextAnnotation WHERE TargetECInstanceId=${annotationElement.id}`, (stmt) => {\n while (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const relationshipId = stmt.getValue(0).getId();\n const sourceId = stmt.getValue(1).getId();\n if (sourceToRelationship.has(sourceId)) {\n sourceToRelationship.set(sourceId, relationshipId);\n } else {\n staleRelationships.add(relationshipId);\n }\n }\n });\n\n for (const [sourceId, relationshipId] of sourceToRelationship) {\n if (relationshipId === null) {\n ElementDrivesTextAnnotation.create(annotationElement.iModel, sourceId, annotationElement.id).insert();\n }\n }\n\n for (const relationshipId of staleRelationships) {\n const props = annotationElement.iModel.relationships.getInstanceProps(\"BisCore.ElementDrivesTextAnnotation\", relationshipId);\n annotationElement.iModel.relationships.deleteInstance(props);\n }\n }\n}\n\n/** Relationship indicating that the [[AnnotationTextStyle]] is being used as the default style for the [[ITextAnnotation]].\n * @beta\n */\nexport class TextAnnotationUsesTextStyleByDefault extends RelatedElement {\n public static classFullName = \"BisCore:TextAnnotationUsesTextStyleByDefault\";\n public constructor(annotationTextStyleId: Id64String, relClassName: string = TextAnnotationUsesTextStyleByDefault.classFullName) {\n super({ id: annotationTextStyleId, relClassName });\n }\n}"]}
@@ -38,7 +38,7 @@ export function appendLeadersToBuilder(builder, leaders, layout, transform, para
38
38
  return false;
39
39
  const frameCurve = computeFrame({ frame: frame.shape, range: layout.range, transform });
40
40
  for (const leader of leaders) {
41
- const leaderStyle = textStyleResolver.resolveTextAnnotationLeaderSettings(leader);
41
+ const leaderStyle = textStyleResolver.resolveSettings(leader.styleOverrides ?? {}, true);
42
42
  let effectiveColor = "subcategory";
43
43
  if (leaderStyle.leader.color === "inherit") {
44
44
  effectiveColor = leaderStyle.color;
@@ -1 +1 @@
1
- {"version":3,"file":"LeaderGeometry.js","sourceRoot":"","sources":["../../../src/annotations/LeaderGeometry.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAA8F,MAAM,oBAAoB,CAAC;AAC1I,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAc,OAAO,EAAa,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAE,OAA+B,EAAE,MAAuB,EAAE,SAAoB,EAAE,MAAsB,EAAE,iBAAoC,EAAE,WAAmB;IACxO,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,CAAC,UAAU,GAAG,WAAW,CAAC;IAClF,IAAI,KAAK,GAAoC,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC;IAEnF,6FAA6F;IAC7F,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;QAClD,KAAK,GAAG,EAAE,KAAK,EAAE,WA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AAC,CAAC;YAC7G,cAAc,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;QAC3C,CAAC;QACD,uFAAuF;QACvF,+EAA+E;QAC/E,MAAM,WAAW,GAAG,qBAAqB,CAAC,UAAU,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC,8CAA8C;QACzH,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;QAClF,MAAM,kBAAkB,GAAG,UAAU,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QACvG,eAAe,GAAG,kBAAkB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;IACzD,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module ElementGeometry\n */\n\nimport { ColorDef, ElementGeometry, GeometryParams, TextAnnotationLeader, TextFrameStyleProps, TextStyleColor } from \"@itwin/core-common\";\nimport { CurveCurve, LineSegment3d, LineString3d, Loop, Path, Point3d, Transform, Vector3d } from \"@itwin/core-geometry\";\nimport { computeFrame } from \"./FrameGeometry\";\nimport { TextBlockLayout, TextStyleResolver } from \"./TextBlockLayout\";\n\n/**\n * Constructs and appends leader lines and their terminators to the provided geometry builder for a text annotation.\n *\n * This function processes an array of `TextAnnotationLeader` objects, computes their attachment points\n * relative to a text frame (or a default rectangular frame if none is provided), and appends the leader\n * line and terminator geometry to the builder. It also applies color overrides if specified\n * in the leader's style overrides.\n *\n * @param builder - The geometry builder to which the leader geometries will be appended.\n * @param leaders - An array of leader properties.\n * @param layout - The layout information for the text block, including its range.\n * @param transform - The transform to apply to the frame and leader geometry.\n * @param params - The geometry parameters, such as color, to use for the leader lines.\n * @param textStyleResolver - Resolver for text styles, used to obtain leader styles.\n * @param scaleFactor - The scale factor to apply to leader dimensions, usually comes from the `scaleFactor` of a [[Drawing]] element.\n * @returns `true` if at least one leader with a terminator was successfully appended; otherwise, `false`.\n * @beta\n */\nexport function appendLeadersToBuilder(builder: ElementGeometry.Builder, leaders: TextAnnotationLeader[], layout: TextBlockLayout, transform: Transform, params: GeometryParams, textStyleResolver: TextStyleResolver, scaleFactor: number): boolean {\n let result = true;\n const scaledLineHeight = textStyleResolver.blockSettings.lineHeight * scaleFactor;\n let frame: TextFrameStyleProps | undefined = textStyleResolver.blockSettings.frame;\n\n // If there is no frame, use a rectangular frame to compute the attachmentPoints for leaders.\n if (frame === undefined || frame.shape === \"none\") {\n frame = { shape: \"rectangle\" }\n }\n if (frame.shape === undefined || frame.shape === \"none\") return false;\n const frameCurve = computeFrame({ frame: frame.shape, range: layout.range, transform });\n\n for (const leader of leaders) {\n const leaderStyle = textStyleResolver.resolveTextAnnotationLeaderSettings(leader);\n\n let effectiveColor: TextStyleColor = \"subcategory\";\n\n if (leaderStyle.leader.color === \"inherit\") {\n effectiveColor = leaderStyle.color;\n } else if (leaderStyle.leader.color !== \"subcategory\") {\n effectiveColor = leaderStyle.leader.color;\n }\n\n if (effectiveColor !== \"subcategory\") {\n params.lineColor = ColorDef.fromJSON(effectiveColor);\n result = result && builder.appendGeometryParamsChange(params);\n }\n\n const attachmentPoint = computeLeaderAttachmentPoint(leader, frameCurve, layout, transform);\n if (!attachmentPoint) return false;\n\n // Leader line geometry\n const leaderLinePoints: Point3d[] = [];\n\n leaderLinePoints.push(leader.startPoint)\n\n leader.intermediatePoints?.forEach((point) => {\n leaderLinePoints.push(point);\n });\n\n if (leaderStyle.leader.wantElbow) {\n const elbowLength = leaderStyle.leader.elbowLength * scaledLineHeight;\n const elbowDirection = computeElbowDirection(attachmentPoint, frameCurve, elbowLength);\n if (elbowDirection)\n leaderLinePoints.push(attachmentPoint.plusScaled(elbowDirection, elbowLength))\n }\n\n leaderLinePoints.push(attachmentPoint)\n\n result = result && builder.appendGeometryQuery(LineString3d.create(leaderLinePoints));\n\n // Terminator geometry\n const terminatorDirection = Vector3d.createStartEnd(\n leaderLinePoints[0], leaderLinePoints[1]\n ).normalize();\n\n const termY = terminatorDirection?.unitCrossProduct(Vector3d.unitZ());\n if (!termY || !terminatorDirection) continue; // Assuming leaders without terminators is a valid case.\n const terminatorHeight = leaderStyle.leader.terminatorHeightFactor * scaledLineHeight;\n const terminatorWidth = leaderStyle.leader.terminatorWidthFactor * scaledLineHeight;\n const basePoint = leader.startPoint.plusScaled(terminatorDirection, terminatorWidth);\n const termPointA = basePoint.plusScaled(termY, terminatorHeight);\n const termPointB = basePoint.plusScaled(termY.negate(), terminatorHeight);\n result = result && builder.appendGeometryQuery(LineString3d.create([termPointA, leader.startPoint, termPointB]));\n\n }\n return result;\n}\n\n\n/**\n * Computes the direction vector for an \"elbow\" for leader based on the attachment point and a frame curve.\n * The elbow direction is determined by whether the attachment point is closer to the left or right side of the frame.\n * If the computed elbow would be tangent to the frame at the intersection, no elbow direction is returned.\n *\n * @param attachmentPoint - The point where the leader attaches.\n * @param frameCurve - The frame curve (either a Loop or Path) to which the leader is attached.\n * @param elbowLength - The length of the elbow segment to be created.\n * @returns The direction vector for the elbow, or `undefined` if the elbow would be tangent to the frame.\n * @beta\n */\nexport function computeElbowDirection(attachmentPoint: Point3d, frameCurve: Loop | Path, elbowLength: number): Vector3d | undefined {\n\n let elbowDirection: Vector3d | undefined;\n // Determine the direction based on the closest point's position relative to the frame\n const isCloserToLeft = Math.abs(attachmentPoint.x - frameCurve.range().low.x) < Math.abs(attachmentPoint.x - frameCurve.range().high.x);\n\n // Decide the direction: left (-X) or right (+X)\n elbowDirection = isCloserToLeft ? Vector3d.unitX().negate() : Vector3d.unitX();\n\n // Verify if the elbow is a tangent to the frame, if yes, do not create an elbow\n const elbowPoint = attachmentPoint.plusScaled(elbowDirection, elbowLength);\n const elbowLine = LineSegment3d.create(attachmentPoint, elbowPoint);\n // Find intersection points between the elbow and the frame\n const intersections = CurveCurve.intersectionXYZPairs(elbowLine, false, frameCurve, false);\n // As the elbow will intersect the frame only at one point, we can safely use the first intersection\n const intersection = intersections[0];\n const curveFraction = intersection.detailB.fraction;\n const derivative = intersection.detailB.curve?.fractionToPointAndDerivative(curveFraction);\n const tangent = derivative?.direction.normalize();\n const lineDirection = Vector3d.createStartEnd(elbowLine.point0Ref, elbowLine.point1Ref).normalize();\n if (tangent && lineDirection) {\n const dot = tangent.dotProduct(lineDirection);\n // If the tangent and line direction are aligned (dot product close to 1 or -1), it's tangent\n if (Math.abs(dot) > 0.999) {\n elbowDirection = undefined;\n }\n }\n return elbowDirection;\n}\n\n/**\n * Computes the attachment point for a leader line on a text annotation frame.\n *\n * The attachment point is determined based on the leader's attachment mode:\n * - `\"Nearest\"`: Finds the closest point on the frame curve to the leader's start point.\n * - `\"KeyPoint\"`: Uses a specific curve segment and fraction along that segment to determine the point.\n * - `\"TextPoint\"`: Calculates a point on the text layout (top/bottom, left/right) and projects it onto the frame curve.\n *\n * @param leader - The leader props.\n * @param frameCurve - The curve (Loop or Path) representing the annotation frame.\n * @param textLayout - The layout information for the text block.\n * @param transform - The transform applied to the text layout.\n * @returns The computed attachment point as a `Point3d`, or `undefined` if it cannot be determined.\n * @beta\n */\nexport function computeLeaderAttachmentPoint(\n leader: TextAnnotationLeader,\n frameCurve: Loop | Path,\n textLayout: TextBlockLayout,\n transform: Transform\n): Point3d | undefined {\n let attachmentPoint: Point3d | undefined;\n\n if (leader.attachment.mode === \"Nearest\") {\n attachmentPoint = frameCurve.closestPoint(leader.startPoint)?.point;\n } else if (leader.attachment.mode === \"KeyPoint\") {\n const curves = frameCurve.collectCurvePrimitives(undefined, false, true);\n const curveIndex = leader.attachment.curveIndex;\n const fraction = leader.attachment.fraction;\n if (curveIndex >= curves.length) {\n // If the curveIndex is invalid, use the last curve\n // This is a fallback to avoid out-of-bounds access\n attachmentPoint = curves[curves.length - 1].fractionToPoint(fraction);\n } else {\n attachmentPoint = curves[curveIndex].fractionToPoint(fraction);\n }\n } else { // attachment.mode=\"TextPoint\"\n let scaleDirection = transform.matrix.getColumn(0).negate(); // direction to draw a scaled line from text attachment point to find intersection point on frame\n let lineIndex: number;\n if (leader.attachment.position.includes(\"Top\")) {\n lineIndex = 0\n } else {\n lineIndex = textLayout.lines.length - 1\n }\n const lineRange = textLayout.lines[lineIndex].range;\n const lineOffset = textLayout.lines[lineIndex].offsetFromDocument;\n const origin = transform.multiplyPoint3d(Point3d.fromJSON(lineOffset));\n let attachmentPointOnText = origin.plusScaled(transform.matrix.getColumn(1), ((lineRange.yLength()) / 2));\n\n if (leader.attachment.position.includes(\"Right\")) {\n attachmentPointOnText = attachmentPointOnText.plusScaled(transform.matrix.getColumn(0), lineRange.xLength());\n scaleDirection = scaleDirection.negate();\n }\n // Find the nearest intersection point on the frame to get the correct attachment point\n // Extend the direction vector to create a target point far along the direction\n const targetPoint = attachmentPointOnText.plusScaled(scaleDirection, 1e6); // Scale the direction vector to a large value\n const intersectionLine = LineSegment3d.create(attachmentPointOnText, targetPoint);\n const closestPointDetail = CurveCurve.intersectionXYZPairs(intersectionLine, false, frameCurve, false);\n attachmentPoint = closestPointDetail[0]?.detailA.point;\n }\n return attachmentPoint;\n}"]}
1
+ {"version":3,"file":"LeaderGeometry.js","sourceRoot":"","sources":["../../../src/annotations/LeaderGeometry.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAA8F,MAAM,oBAAoB,CAAC;AAC1I,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAc,OAAO,EAAa,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAE,OAA+B,EAAE,MAAuB,EAAE,S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;QACvE,IAAI,qBAAqB,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAE1G,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACjD,qBAAqB,GAAG,qBAAqB,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7G,cAAc,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;QAC3C,CAAC;QACD,uFAAuF;QACvF,+EAA+E;QAC/E,MAAM,WAAW,GAAG,qBAAqB,CAAC,UAAU,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC,8CAA8C;QACzH,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;QAClF,MAAM,kBAAkB,GAAG,UAAU,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QACvG,eAAe,GAAG,kBAAkB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;IACzD,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module ElementGeometry\n */\n\nimport { ColorDef, ElementGeometry, GeometryParams, TextAnnotationLeader, TextFrameStyleProps, TextStyleColor } from \"@itwin/core-common\";\nimport { CurveCurve, LineSegment3d, LineString3d, Loop, Path, Point3d, Transform, Vector3d } from \"@itwin/core-geometry\";\nimport { computeFrame } from \"./FrameGeometry\";\nimport { TextBlockLayout, TextStyleResolver } from \"./TextBlockLayout\";\n\n/**\n * Constructs and appends leader lines and their terminators to the provided geometry builder for a text annotation.\n *\n * This function processes an array of `TextAnnotationLeader` objects, computes their attachment points\n * relative to a text frame (or a default rectangular frame if none is provided), and appends the leader\n * line and terminator geometry to the builder. It also applies color overrides if specified\n * in the leader's style overrides.\n *\n * @param builder - The geometry builder to which the leader geometries will be appended.\n * @param leaders - An array of leader properties.\n * @param layout - The layout information for the text block, including its range.\n * @param transform - The transform to apply to the frame and leader geometry.\n * @param params - The geometry parameters, such as color, to use for the leader lines.\n * @param textStyleResolver - Resolver for text styles, used to obtain leader styles.\n * @param scaleFactor - The scale factor to apply to leader dimensions, usually comes from the `scaleFactor` of a [[Drawing]] element.\n * @returns `true` if at least one leader with a terminator was successfully appended; otherwise, `false`.\n * @beta\n */\nexport function appendLeadersToBuilder(builder: ElementGeometry.Builder, leaders: TextAnnotationLeader[], layout: TextBlockLayout, transform: Transform, params: GeometryParams, textStyleResolver: TextStyleResolver, scaleFactor: number): boolean {\n let result = true;\n const scaledLineHeight = textStyleResolver.blockSettings.lineHeight * scaleFactor;\n let frame: TextFrameStyleProps | undefined = textStyleResolver.blockSettings.frame;\n\n // If there is no frame, use a rectangular frame to compute the attachmentPoints for leaders.\n if (frame === undefined || frame.shape === \"none\") {\n frame = { shape: \"rectangle\" }\n }\n if (frame.shape === undefined || frame.shape === \"none\") return false;\n const frameCurve = computeFrame({ frame: frame.shape, range: layout.range, transform });\n\n for (const leader of leaders) {\n const leaderStyle = textStyleResolver.resolveSettings(leader.styleOverrides ?? {}, true);\n\n let effectiveColor: TextStyleColor = \"subcategory\";\n\n if (leaderStyle.leader.color === \"inherit\") {\n effectiveColor = leaderStyle.color;\n } else if (leaderStyle.leader.color !== \"subcategory\") {\n effectiveColor = leaderStyle.leader.color;\n }\n\n if (effectiveColor !== \"subcategory\") {\n params.lineColor = ColorDef.fromJSON(effectiveColor);\n result = result && builder.appendGeometryParamsChange(params);\n }\n\n const attachmentPoint = computeLeaderAttachmentPoint(leader, frameCurve, layout, transform);\n if (!attachmentPoint) return false;\n\n // Leader line geometry\n const leaderLinePoints: Point3d[] = [];\n\n leaderLinePoints.push(leader.startPoint)\n\n leader.intermediatePoints?.forEach((point) => {\n leaderLinePoints.push(point);\n });\n\n if (leaderStyle.leader.wantElbow) {\n const elbowLength = leaderStyle.leader.elbowLength * scaledLineHeight;\n const elbowDirection = computeElbowDirection(attachmentPoint, frameCurve, elbowLength);\n if (elbowDirection)\n leaderLinePoints.push(attachmentPoint.plusScaled(elbowDirection, elbowLength))\n }\n\n leaderLinePoints.push(attachmentPoint)\n\n result = result && builder.appendGeometryQuery(LineString3d.create(leaderLinePoints));\n\n // Terminator geometry\n const terminatorDirection = Vector3d.createStartEnd(\n leaderLinePoints[0], leaderLinePoints[1]\n ).normalize();\n\n const termY = terminatorDirection?.unitCrossProduct(Vector3d.unitZ());\n if (!termY || !terminatorDirection) continue; // Assuming leaders without terminators is a valid case.\n const terminatorHeight = leaderStyle.leader.terminatorHeightFactor * scaledLineHeight;\n const terminatorWidth = leaderStyle.leader.terminatorWidthFactor * scaledLineHeight;\n const basePoint = leader.startPoint.plusScaled(terminatorDirection, terminatorWidth);\n const termPointA = basePoint.plusScaled(termY, terminatorHeight);\n const termPointB = basePoint.plusScaled(termY.negate(), terminatorHeight);\n result = result && builder.appendGeometryQuery(LineString3d.create([termPointA, leader.startPoint, termPointB]));\n\n }\n return result;\n}\n\n\n/**\n * Computes the direction vector for an \"elbow\" for leader based on the attachment point and a frame curve.\n * The elbow direction is determined by whether the attachment point is closer to the left or right side of the frame.\n * If the computed elbow would be tangent to the frame at the intersection, no elbow direction is returned.\n *\n * @param attachmentPoint - The point where the leader attaches.\n * @param frameCurve - The frame curve (either a Loop or Path) to which the leader is attached.\n * @param elbowLength - The length of the elbow segment to be created.\n * @returns The direction vector for the elbow, or `undefined` if the elbow would be tangent to the frame.\n * @beta\n */\nexport function computeElbowDirection(attachmentPoint: Point3d, frameCurve: Loop | Path, elbowLength: number): Vector3d | undefined {\n\n let elbowDirection: Vector3d | undefined;\n // Determine the direction based on the closest point's position relative to the frame\n const isCloserToLeft = Math.abs(attachmentPoint.x - frameCurve.range().low.x) < Math.abs(attachmentPoint.x - frameCurve.range().high.x);\n\n // Decide the direction: left (-X) or right (+X)\n elbowDirection = isCloserToLeft ? Vector3d.unitX().negate() : Vector3d.unitX();\n\n // Verify if the elbow is a tangent to the frame, if yes, do not create an elbow\n const elbowPoint = attachmentPoint.plusScaled(elbowDirection, elbowLength);\n const elbowLine = LineSegment3d.create(attachmentPoint, elbowPoint);\n // Find intersection points between the elbow and the frame\n const intersections = CurveCurve.intersectionXYZPairs(elbowLine, false, frameCurve, false);\n // As the elbow will intersect the frame only at one point, we can safely use the first intersection\n const intersection = intersections[0];\n const curveFraction = intersection.detailB.fraction;\n const derivative = intersection.detailB.curve?.fractionToPointAndDerivative(curveFraction);\n const tangent = derivative?.direction.normalize();\n const lineDirection = Vector3d.createStartEnd(elbowLine.point0Ref, elbowLine.point1Ref).normalize();\n if (tangent && lineDirection) {\n const dot = tangent.dotProduct(lineDirection);\n // If the tangent and line direction are aligned (dot product close to 1 or -1), it's tangent\n if (Math.abs(dot) > 0.999) {\n elbowDirection = undefined;\n }\n }\n return elbowDirection;\n}\n\n/**\n * Computes the attachment point for a leader line on a text annotation frame.\n *\n * The attachment point is determined based on the leader's attachment mode:\n * - `\"Nearest\"`: Finds the closest point on the frame curve to the leader's start point.\n * - `\"KeyPoint\"`: Uses a specific curve segment and fraction along that segment to determine the point.\n * - `\"TextPoint\"`: Calculates a point on the text layout (top/bottom, left/right) and projects it onto the frame curve.\n *\n * @param leader - The leader props.\n * @param frameCurve - The curve (Loop or Path) representing the annotation frame.\n * @param textLayout - The layout information for the text block.\n * @param transform - The transform applied to the text layout.\n * @returns The computed attachment point as a `Point3d`, or `undefined` if it cannot be determined.\n * @beta\n */\nexport function computeLeaderAttachmentPoint(\n leader: TextAnnotationLeader,\n frameCurve: Loop | Path,\n textLayout: TextBlockLayout,\n transform: Transform\n): Point3d | undefined {\n let attachmentPoint: Point3d | undefined;\n\n if (leader.attachment.mode === \"Nearest\") {\n attachmentPoint = frameCurve.closestPoint(leader.startPoint)?.point;\n } else if (leader.attachment.mode === \"KeyPoint\") {\n const curves = frameCurve.collectCurvePrimitives(undefined, false, true);\n const curveIndex = leader.attachment.curveIndex;\n const fraction = leader.attachment.fraction;\n if (curveIndex >= curves.length) {\n // If the curveIndex is invalid, use the last curve\n // This is a fallback to avoid out-of-bounds access\n attachmentPoint = curves[curves.length - 1].fractionToPoint(fraction);\n } else {\n attachmentPoint = curves[curveIndex].fractionToPoint(fraction);\n }\n } else { // attachment.mode=\"TextPoint\"\n let scaleDirection = transform.matrix.getColumn(0).negate(); // direction to draw a scaled line from text attachment point to find intersection point on frame\n let lineIndex: number;\n if (leader.attachment.position.includes(\"Top\")) {\n lineIndex = 0\n } else {\n lineIndex = textLayout.lines.length - 1\n }\n const lineRange = textLayout.lines[lineIndex].range;\n const lineOffset = textLayout.lines[lineIndex].offsetFromDocument;\n const origin = transform.multiplyPoint3d(Point3d.fromJSON(lineOffset));\n let attachmentPointOnText = origin.plusScaled(transform.matrix.getColumn(1), ((lineRange.yLength()) / 2));\n\n if (leader.attachment.position.includes(\"Right\")) {\n attachmentPointOnText = attachmentPointOnText.plusScaled(transform.matrix.getColumn(0), lineRange.xLength());\n scaleDirection = scaleDirection.negate();\n }\n // Find the nearest intersection point on the frame to get the correct attachment point\n // Extend the direction vector to create a target point far along the direction\n const targetPoint = attachmentPointOnText.plusScaled(scaleDirection, 1e6); // Scale the direction vector to a large value\n const intersectionLine = LineSegment3d.create(attachmentPointOnText, targetPoint);\n const closestPointDetail = CurveCurve.intersectionXYZPairs(intersectionLine, false, frameCurve, false);\n attachmentPoint = closestPointDetail[0]?.detailA.point;\n }\n return attachmentPoint;\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TextAnnotationGeometry.d.ts","sourceRoot":"","sources":["../../../src/annotations/TextAnnotationGeometry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAY,eAAe,EAA+C,mBAAmB,EAAqB,MAAM,oBAAoB,CAAC;AACpJ,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAQ,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKvD;;;;GAIG;AACH,MAAM,WAAW,gCAAgC;IAC/C,4GAA4G;IAC5G,eAAe,EAAE,mBAAmB,CAAC;IACrC,qDAAqD;IACrD,MAAM,EAAE,eAAe,CAAC;IACxB,6FAA6F;IAC7F,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,kHAAkH;IAClH,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC;IACjC,4FAA4F;IAC5F,UAAU,EAAE,UAAU,CAAA;IACtB,yGAAyG;IACzG,aAAa,CAAC,EAAE,UAAU,CAAA;IAC1B,+FAA+F;IAC/F,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,gCAAgC,GAAG,OAAO,CA8B7F"}
1
+ {"version":3,"file":"TextAnnotationGeometry.d.ts","sourceRoot":"","sources":["../../../src/annotations/TextAnnotationGeometry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAY,eAAe,EAA+C,mBAAmB,EAAqB,MAAM,oBAAoB,CAAC;AACpJ,OAAO,EAAa,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAElF,OAAO,EAAQ,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKvD;;;;GAIG;AACH,MAAM,WAAW,gCAAgC;IAC/C,4GAA4G;IAC5G,eAAe,EAAE,mBAAmB,CAAC;IACrC,qDAAqD;IACrD,MAAM,EAAE,eAA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