@itwin/core-quantity 5.12.0-dev.8 → 5.12.0-dev.9

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 (94) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/cjs/BasicUnitsProvider.js.map +1 -1
  3. package/lib/cjs/CompositeUnitsProvider.js.map +1 -1
  4. package/lib/cjs/Constants.js.map +1 -1
  5. package/lib/cjs/Exception.js.map +1 -1
  6. package/lib/cjs/FormatSpecHandle.js.map +1 -1
  7. package/lib/cjs/Formatter/Format.d.ts +8 -0
  8. package/lib/cjs/Formatter/Format.d.ts.map +1 -1
  9. package/lib/cjs/Formatter/Format.js +8 -0
  10. package/lib/cjs/Formatter/Format.js.map +1 -1
  11. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  12. package/lib/cjs/Formatter/Formatter.d.ts +7 -0
  13. package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
  14. package/lib/cjs/Formatter/Formatter.js +13 -1
  15. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  16. package/lib/cjs/Formatter/FormatterSpec.d.ts +3 -0
  17. package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
  18. package/lib/cjs/Formatter/FormatterSpec.js +3 -0
  19. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  20. package/lib/cjs/Formatter/FormattingReadyCollector.js.map +1 -1
  21. package/lib/cjs/Formatter/Interfaces.d.ts +10 -2
  22. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  23. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  24. package/lib/cjs/Interfaces.js.map +1 -1
  25. package/lib/cjs/Parser.d.ts +6 -1
  26. package/lib/cjs/Parser.d.ts.map +1 -1
  27. package/lib/cjs/Parser.js +20 -3
  28. package/lib/cjs/Parser.js.map +1 -1
  29. package/lib/cjs/ParserSpec.d.ts +3 -0
  30. package/lib/cjs/ParserSpec.d.ts.map +1 -1
  31. package/lib/cjs/ParserSpec.js +3 -0
  32. package/lib/cjs/ParserSpec.js.map +1 -1
  33. package/lib/cjs/Quantity.js.map +1 -1
  34. package/lib/cjs/QuantityLoggerCategory.js.map +1 -1
  35. package/lib/cjs/SerializedUnitSchema.js.map +1 -1
  36. package/lib/cjs/Unit.js.map +1 -1
  37. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  38. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  39. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  40. package/lib/cjs/UnitConversion/UnitDefinitionResolver.js.map +1 -1
  41. package/lib/cjs/UnitConversion/nameUtils.js.map +1 -1
  42. package/lib/cjs/UnitConversions.js.map +1 -1
  43. package/lib/cjs/core-quantity.js.map +1 -1
  44. package/lib/cjs/internal/BasicUnitConversionData.js.map +1 -1
  45. package/lib/cjs/internal/BasicUnitsResolvedStateCache.js.map +1 -1
  46. package/lib/cjs/internal/UnitConversionMath.js.map +1 -1
  47. package/lib/cjs/internal/cross-package.js.map +1 -1
  48. package/lib/esm/BasicUnitsProvider.js.map +1 -1
  49. package/lib/esm/CompositeUnitsProvider.js.map +1 -1
  50. package/lib/esm/Constants.js.map +1 -1
  51. package/lib/esm/Exception.js.map +1 -1
  52. package/lib/esm/FormatSpecHandle.js.map +1 -1
  53. package/lib/esm/Formatter/Format.d.ts +8 -0
  54. package/lib/esm/Formatter/Format.d.ts.map +1 -1
  55. package/lib/esm/Formatter/Format.js +8 -0
  56. package/lib/esm/Formatter/Format.js.map +1 -1
  57. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  58. package/lib/esm/Formatter/Formatter.d.ts +7 -0
  59. package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
  60. package/lib/esm/Formatter/Formatter.js +13 -1
  61. package/lib/esm/Formatter/Formatter.js.map +1 -1
  62. package/lib/esm/Formatter/FormatterSpec.d.ts +3 -0
  63. package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
  64. package/lib/esm/Formatter/FormatterSpec.js +3 -0
  65. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  66. package/lib/esm/Formatter/FormattingReadyCollector.js.map +1 -1
  67. package/lib/esm/Formatter/Interfaces.d.ts +10 -2
  68. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  69. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  70. package/lib/esm/Interfaces.js.map +1 -1
  71. package/lib/esm/Parser.d.ts +6 -1
  72. package/lib/esm/Parser.d.ts.map +1 -1
  73. package/lib/esm/Parser.js +20 -3
  74. package/lib/esm/Parser.js.map +1 -1
  75. package/lib/esm/ParserSpec.d.ts +3 -0
  76. package/lib/esm/ParserSpec.d.ts.map +1 -1
  77. package/lib/esm/ParserSpec.js +3 -0
  78. package/lib/esm/ParserSpec.js.map +1 -1
  79. package/lib/esm/Quantity.js.map +1 -1
  80. package/lib/esm/QuantityLoggerCategory.js.map +1 -1
  81. package/lib/esm/SerializedUnitSchema.js.map +1 -1
  82. package/lib/esm/Unit.js.map +1 -1
  83. package/lib/esm/UnitConversion/Graph.js.map +1 -1
  84. package/lib/esm/UnitConversion/Parser.js.map +1 -1
  85. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -1
  86. package/lib/esm/UnitConversion/UnitDefinitionResolver.js.map +1 -1
  87. package/lib/esm/UnitConversion/nameUtils.js.map +1 -1
  88. package/lib/esm/UnitConversions.js.map +1 -1
  89. package/lib/esm/core-quantity.js.map +1 -1
  90. package/lib/esm/internal/BasicUnitConversionData.js.map +1 -1
  91. package/lib/esm/internal/BasicUnitsResolvedStateCache.js.map +1 -1
  92. package/lib/esm/internal/UnitConversionMath.js.map +1 -1
  93. package/lib/esm/internal/cross-package.js.map +1 -1
  94. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"FormattingReadyCollector.js","sourceRoot":"","sources":["../../../src/Formatter/FormattingReadyCollector.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,uBAAuB;;;AAEvB,sDA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A9BD,4DA8BC","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/** @module Quantity */\n\nimport { Logger } from \"@itwin/core-bentley\";\nimport { QuantityLoggerCategory } from \"../QuantityLoggerCategory\";\n\n/** Collects async work from formatting providers during the pre-ready phase.\n * Providers call [[addPendingWork]] to register promises that the formatter\n * will await before signaling [[QuantityFormatter.onFormattingReady]].\n * @beta\n */\nexport class FormattingReadyCollector {\n private _promises: Promise<void>[] = [];\n\n /** Register async work that must complete before the formatter signals ready.\n * Call this from an `onBeforeFormattingReady` listener.\n */\n public addPendingWork(work: Promise<void>): void {\n this._promises.push(work);\n }\n\n /** @internal Await all registered work with a timeout. Logs warnings for rejections and timeouts. */\n public async awaitAll(timeoutMs: number = 20_000): Promise<void> {\n if (this._promises.length === 0)\n return;\n\n const timeout = new Promise<\"timeout\">((resolve) => setTimeout(() => resolve(\"timeout\"), timeoutMs));\n const work = Promise.allSettled(this._promises).then((results) => {\n for (const result of results) {\n if (result.status === \"rejected\") {\n Logger.logWarning(QuantityLoggerCategory.Formatting, \"FormattingReadyCollector: a provider's async work rejected\", () => ({ reason: result.reason }));\n }\n }\n return \"done\" as const;\n });\n\n const outcome = await Promise.race([work, timeout]);\n if (outcome === \"timeout\") {\n Logger.logWarning(QuantityLoggerCategory.Formatting, `FormattingReadyCollector: timed out after ${timeoutMs}ms waiting for ${this._promises.length} provider(s). Proceeding with ready signal.`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"FormattingReadyCollector.js","sourceRoot":"","sources":["../../../src/Formatter/FormattingReadyCollector.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,uBAAuB;;;AAEvB,sDAA6C;AAC7C,sEAAmE;AAEnE;;;;GAIG;AACH,MAAa,wBAAwB;IAC3B,SAAS,GAAoB,EAAE,CAAC;IAExC;;OAEG;IACI,cAAc,CAAC,IAAmB;QACvC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,qGAAqG;IAC9F,KAAK,CAAC,QAAQ,CAAC,YAAoB,MAAM;QAC9C,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YAC7B,OAAO;QAET,MAAM,OAAO,GAAG,IAAI,OAAO,CAAY,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;QACrG,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YAC/D,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;oBACjC,qBAAM,CAAC,UAAU,CAAC,+CAAsB,CAAC,UAAU,EAAE,4DAA4D,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACxJ,CAAC;YACH,CAAC;YACD,OAAO,MAAe,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACpD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,qBAAM,CAAC,UAAU,CAAC,+CAAsB,CAAC,UAAU,EAAE,6CAA6C,SAAS,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,6CAA6C,CAAC,CAAC;QACnM,CAAC;IACH,CAAC;CACF;AA9BD,4DA8BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @module Quantity */\r\n\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport { QuantityLoggerCategory } from \"../QuantityLoggerCategory\";\r\n\r\n/** Collects async work from formatting providers during the pre-ready phase.\r\n * Providers call [[addPendingWork]] to register promises that the formatter\r\n * will await before signaling [[QuantityFormatter.onFormattingReady]].\r\n * @beta\r\n */\r\nexport class FormattingReadyCollector {\r\n private _promises: Promise<void>[] = [];\r\n\r\n /** Register async work that must complete before the formatter signals ready.\r\n * Call this from an `onBeforeFormattingReady` listener.\r\n */\r\n public addPendingWork(work: Promise<void>): void {\r\n this._promises.push(work);\r\n }\r\n\r\n /** @internal Await all registered work with a timeout. Logs warnings for rejections and timeouts. */\r\n public async awaitAll(timeoutMs: number = 20_000): Promise<void> {\r\n if (this._promises.length === 0)\r\n return;\r\n\r\n const timeout = new Promise<\"timeout\">((resolve) => setTimeout(() => resolve(\"timeout\"), timeoutMs));\r\n const work = Promise.allSettled(this._promises).then((results) => {\r\n for (const result of results) {\r\n if (result.status === \"rejected\") {\r\n Logger.logWarning(QuantityLoggerCategory.Formatting, \"FormattingReadyCollector: a provider's async work rejected\", () => ({ reason: result.reason }));\r\n }\r\n }\r\n return \"done\" as const;\r\n });\r\n\r\n const outcome = await Promise.race([work, timeout]);\r\n if (outcome === \"timeout\") {\r\n Logger.logWarning(QuantityLoggerCategory.Formatting, `FormattingReadyCollector: timed out after ${timeoutMs}ms waiting for ${this._promises.length} provider(s). Proceeding with ready signal.`);\r\n }\r\n }\r\n}\r\n"]}
@@ -77,11 +77,19 @@ export interface FormatProps {
77
77
  readonly stationBaseFactor?: number;
78
78
  /** The base value for azimuth, specified from east counter-clockwise. */
79
79
  readonly azimuthBase?: number;
80
- /** The name of the unit for the azimuth base value. Required if azimuthBase is set. */
80
+ /** The name of the unit for the azimuth base value. Required if azimuthBase is set.
81
+ * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. a `Units.HORIZONTAL_DIRECTION`
82
+ * unit for a `Units.HORIZONTAL_DIRECTION` persistence unit, or a `Units.ANGLE` unit for a `Units.ANGLE` persistence unit) - the units provider
83
+ * cannot convert between different phenomena, so a mismatch will fail to resolve.
84
+ */
81
85
  readonly azimuthBaseUnit?: string;
82
86
  /** If set to true, azimuth values are returned counter-clockwise from the base. */
83
87
  readonly azimuthCounterClockwise?: boolean;
84
- /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */
88
+ /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types.
89
+ * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. `Units.HORIZONTAL_DIR_REVOLUTION`
90
+ * for a `Units.HORIZONTAL_DIRECTION` persistence unit, or `Units.REVOLUTION` for a `Units.ANGLE` persistence unit) - the units provider cannot
91
+ * convert between different phenomena, so a mismatch will fail to resolve.
92
+ */
85
93
  readonly revolutionUnit?: string;
86
94
  /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */
87
95
  readonly allowMathematicOperations?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yGAAyG;IACzG,QAA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ACtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAwHH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","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 Quantity\n */\n\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\nimport type { FormatterSpec } from \"./FormatterSpec\";\nimport type { ParserSpec } from \"../ParserSpec\";\n\n/** Defines a unit specification with a name and optional label override.\n * Used in composite formats and ratio unit specifications.\n * @beta\n */\nexport interface FormatUnitSpec {\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\n readonly name: string;\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\n readonly label?: string;\n}\n\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\n * @beta\n */\nexport interface ResolvedFormatUnitSpec {\n /** The resolved unit */\n readonly unit: UnitProps;\n /** Optional custom label that overrides the unit's default label */\n readonly label?: string;\n}\n\n/** Defines the units that make up a composite format and their display properties.\n * A composite format allows displaying a single quantity value across multiple units,\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\n * @beta\n */\nexport interface FormatCompositeProps {\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\n readonly spacer?: string;\n /** Whether to include unit segments with zero magnitude in the formatted output. */\n readonly includeZero?: boolean;\n /** Array of units this format is comprised of. Each unit specifies the unit name and\n * an optional custom label that will override the unit's default label when displaying values. */\n readonly units: FormatUnitSpec[];\n}\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n /** The format type. See [[FormatType]] */\n readonly type: string;\n\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\n readonly precision?: number;\n\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\n readonly roundFactor?: number;\n\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\n readonly minWidth?: number;\n\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\n readonly showSignOption?: string;\n\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\n readonly formatTraits?: string | string[];\n\n /** Character separating integer from fractional part. Must be empty or a single character. */\n readonly decimalSeparator?: string;\n\n /** Character separating thousands in the integer part. Must be empty or a single character. */\n readonly thousandSeparator?: string;\n\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\n readonly uomSeparator?: string;\n\n /** Required when type is Scientific. See [[ScientificType]] */\n readonly scientificType?: string;\n\n /** Required when type is Ratio. See [[RatioType]]*/\n readonly ratioType?: string;\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\n readonly ratioSeparator?: string;\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\n readonly ratioFormatType?: string;\n\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\n readonly stationOffsetSize?: number;\n\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\n readonly allowMathematicOperations?: boolean;\n\n /** Composite format specification for multi-unit display. */\n readonly composite?: FormatCompositeProps;\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\n readonly units: ResolvedFormatUnitSpec[];\n};\n\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\n readonly azimuthBaseUnit?: UnitProps;\n readonly revolutionUnit?: UnitProps;\n readonly composite?: ResolvedFormatCompositeProps;\n readonly custom?: any;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n /** If set, indicates that the format set implies a particular unit system. The consumer\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\n * If `undefined`, the format change does not imply a unit system switch — the active\n * unit system remains unchanged.\n * @beta\n */\n impliedUnitSystem?: UnitSystemKey;\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\n\n /**\n * Fired when formats are added, removed, or changed.\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\n */\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n /**\n * Adds a new format or updates an existing format associated with the specified name.\n */\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n /**\n * Removes the format associated with the specified name.\n * @param name The name of the format to remove.\n */\n removeFormat(name: string): Promise<void>;\n}\n\n/** Entries returned when looking up specs from the format registry.\n * @beta\n */\nexport interface FormattingSpecEntry {\n formatterSpec: FormatterSpec;\n parserSpec: ParserSpec;\n}\n\n/** Arguments for looking up a formatting spec entry.\n * @beta\n */\nexport interface FormattingSpecArgs {\n /** The KoQ name to look up. */\n name: string;\n /** The persistence unit name (e.g., `\"Units.M\"`). */\n persistenceUnitName: string;\n /** Optional unit system override. When omitted, the active system is used. */\n system?: UnitSystemKey;\n}\n\n/** Arguments for registering a formatting spec entry.\n * @beta\n */\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\n formatProps?: FormatProps;\n}\n\n/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\n * @beta\n */\nexport interface FormattingSpecProvider {\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\n /** Format a numeric value using the given formatter spec. */\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\n /** Event raised after the provider has finished reloading its caches.\n * Uses Set-backed event for safe concurrent add/remove during emit.\n */\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\n}\n\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAgIH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\r\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\nimport type { FormatterSpec } from \"./FormatterSpec\";\r\nimport type { ParserSpec } from \"../ParserSpec\";\r\n\r\n/** Defines a unit specification with a name and optional label override.\r\n * Used in composite formats and ratio unit specifications.\r\n * @beta\r\n */\r\nexport interface FormatUnitSpec {\r\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\r\n readonly name: string;\r\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\r\n readonly label?: string;\r\n}\r\n\r\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\r\n * @beta\r\n */\r\nexport interface ResolvedFormatUnitSpec {\r\n /** The resolved unit */\r\n readonly unit: UnitProps;\r\n /** Optional custom label that overrides the unit's default label */\r\n readonly label?: string;\r\n}\r\n\r\n/** Defines the units that make up a composite format and their display properties.\r\n * A composite format allows displaying a single quantity value across multiple units,\r\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\r\n * @beta\r\n */\r\nexport interface FormatCompositeProps {\r\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\r\n readonly spacer?: string;\r\n /** Whether to include unit segments with zero magnitude in the formatted output. */\r\n readonly includeZero?: boolean;\r\n /** Array of units this format is comprised of. Each unit specifies the unit name and\r\n * an optional custom label that will override the unit's default label when displaying values. */\r\n readonly units: FormatUnitSpec[];\r\n}\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n /** The format type. See [[FormatType]] */\r\n readonly type: string;\r\n\r\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\r\n readonly precision?: number;\r\n\r\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\r\n readonly roundFactor?: number;\r\n\r\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\r\n readonly minWidth?: number;\r\n\r\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\r\n readonly showSignOption?: string;\r\n\r\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\r\n readonly formatTraits?: string | string[];\r\n\r\n /** Character separating integer from fractional part. Must be empty or a single character. */\r\n readonly decimalSeparator?: string;\r\n\r\n /** Character separating thousands in the integer part. Must be empty or a single character. */\r\n readonly thousandSeparator?: string;\r\n\r\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\r\n readonly uomSeparator?: string;\r\n\r\n /** Required when type is Scientific. See [[ScientificType]] */\r\n readonly scientificType?: string;\r\n\r\n /** Required when type is Ratio. See [[RatioType]]*/\r\n readonly ratioType?: string;\r\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\r\n readonly ratioSeparator?: string;\r\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\r\n readonly ratioFormatType?: string;\r\n\r\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\r\n readonly stationOffsetSize?: number;\r\n\r\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\r\n readonly stationSeparator?: string;\r\n\r\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\r\n readonly stationBaseFactor?: number;\r\n\r\n /** The base value for azimuth, specified from east counter-clockwise. */\r\n readonly azimuthBase?: number;\r\n\r\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set.\r\n * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. a `Units.HORIZONTAL_DIRECTION`\r\n * unit for a `Units.HORIZONTAL_DIRECTION` persistence unit, or a `Units.ANGLE` unit for a `Units.ANGLE` persistence unit) - the units provider\r\n * cannot convert between different phenomena, so a mismatch will fail to resolve.\r\n */\r\n readonly azimuthBaseUnit?: string;\r\n\r\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\r\n readonly azimuthCounterClockwise?: boolean;\r\n\r\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types.\r\n * @note Must share the same phenomenon as the persistence unit the Format/FormatterSpec/ParserSpec is used with (e.g. `Units.HORIZONTAL_DIR_REVOLUTION`\r\n * for a `Units.HORIZONTAL_DIRECTION` persistence unit, or `Units.REVOLUTION` for a `Units.ANGLE` persistence unit) - the units provider cannot\r\n * convert between different phenomena, so a mismatch will fail to resolve.\r\n */\r\n readonly revolutionUnit?: string;\r\n\r\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\r\n readonly allowMathematicOperations?: boolean;\r\n\r\n /** Composite format specification for multi-unit display. */\r\n readonly composite?: FormatCompositeProps;\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\r\n * @beta\r\n */\r\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\r\n readonly units: ResolvedFormatUnitSpec[];\r\n};\r\n\r\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\r\n * @beta\r\n */\r\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\r\n readonly azimuthBaseUnit?: UnitProps;\r\n readonly revolutionUnit?: UnitProps;\r\n readonly composite?: ResolvedFormatCompositeProps;\r\n readonly custom?: any;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n\r\n/** An extension of FormatProps to help identify formats.\r\n * @beta\r\n */\r\nexport interface FormatDefinition extends FormatProps {\r\n readonly name?: string;\r\n readonly label?: string;\r\n readonly description?: string;\r\n}\r\n\r\n/** Argument for [[FormatsProvider.onFormatsChanged]]\r\n * @beta\r\n */\r\nexport interface FormatsChangedArgs {\r\n /**\r\n * If `all` - all formats within the `FormatsProvider` have changed.\r\n * If array, the array items list the names of formats that were changed or removed.\r\n */\r\n formatsChanged: \"all\" | string[];\r\n /** If set, indicates that the format set implies a particular unit system. The consumer\r\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\r\n * If `undefined`, the format change does not imply a unit system switch — the active\r\n * unit system remains unchanged.\r\n * @beta\r\n */\r\n impliedUnitSystem?: UnitSystemKey;\r\n}\r\n\r\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\r\n * @beta\r\n */\r\nexport interface FormatsProvider {\r\n /**\r\n * @param name The full name of the Format or KindOfQuantity.\r\n */\r\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\r\n\r\n /**\r\n * Fired when formats are added, removed, or changed.\r\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\r\n */\r\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\r\n}\r\n\r\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\r\n * @beta\r\n */\r\nexport interface MutableFormatsProvider extends FormatsProvider {\r\n /**\r\n * Adds a new format or updates an existing format associated with the specified name.\r\n */\r\n addFormat(name: string, format: FormatDefinition): Promise<void>;\r\n /**\r\n * Removes the format associated with the specified name.\r\n * @param name The name of the format to remove.\r\n */\r\n removeFormat(name: string): Promise<void>;\r\n}\r\n\r\n/** Entries returned when looking up specs from the format registry.\r\n * @beta\r\n */\r\nexport interface FormattingSpecEntry {\r\n formatterSpec: FormatterSpec;\r\n parserSpec: ParserSpec;\r\n}\r\n\r\n/** Arguments for looking up a formatting spec entry.\r\n * @beta\r\n */\r\nexport interface FormattingSpecArgs {\r\n /** The KoQ name to look up. */\r\n name: string;\r\n /** The persistence unit name (e.g., `\"Units.M\"`). */\r\n persistenceUnitName: string;\r\n /** Optional unit system override. When omitted, the active system is used. */\r\n system?: UnitSystemKey;\r\n}\r\n\r\n/** Arguments for registering a formatting spec entry.\r\n * @beta\r\n */\r\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\r\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\r\n formatProps?: FormatProps;\r\n}\r\n\r\n/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.\r\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\r\n * @beta\r\n */\r\nexport interface FormattingSpecProvider {\r\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\r\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\r\n /** Format a numeric value using the given formatter spec. */\r\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\r\n /** Event raised after the provider has finished reloading its caches.\r\n * Uses Set-backed event for safe concurrent add/remove during emit.\r\n */\r\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\r\n}\r\n\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAmDH;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","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 Quantity\n */\n\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\n * @beta\n */\nexport interface AlternateUnitLabelsProvider {\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\n}\n\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\n * uniquely identifies a unit by its name.\n * @beta\n */\nexport interface UnitProps {\n /** Unique name for unit. */\n readonly name: string;\n /** Default label for unit. */\n readonly label: string;\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\n readonly phenomenon: string;\n /** This is set to true if the Unit is known by the UnitsProvider. */\n readonly isValid: boolean;\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\n readonly system: string;\n}\n\n/** This interface defines the required properties of a Quantity.\n * @beta\n */\nexport interface QuantityProps {\n readonly magnitude: number;\n readonly unit: UnitProps;\n readonly isValid: boolean;\n}\n\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\n * @beta\n */\nexport interface UnitConversionSpec {\n /** Unit name that was used to locate the unit by the Unit Provider */\n name: string;\n /** The default label that is used to display unit */\n label: string;\n /** Unit system name, used to when finding preferred parse unit */\n system: string;\n /** the information necessary to convert the unit to a specific display unit */\n conversion: UnitConversionProps;\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\n parseLabels?: string[];\n}\n\n/** Indicates the way in which unit values are inverted during conversion\n * @beta\n */\nexport enum UnitConversionInvert {\n /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */\n InvertPreConversion = \"InvertPreConversion\",\n /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */\n InvertPostConversion = \"InvertPostConversion\"\n}\n\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\n * or from Celsius to Fahrenheit.\n * @beta\n */\nexport interface UnitConversionProps {\n /** The factor to multiply the input value by to convert to the output value. */\n factor: number;\n /** The offset to add to the input value to convert to the output value. */\n offset: number;\n /** If set, inverts the unit value (1/x) before or after conversion. */\n inversion?: UnitConversionInvert;\n /**\n * If `true`, the conversion could not be resolved (e.g. unknown unit, incompatible phenomena).\n * When `error` is `true`, `factor` MUST be `1.0` and `offset` MUST be `0.0` (identity).\n * Callers must check this flag before applying the conversion — applying an identity conversion\n * silently produces wrong output.\n */\n error?: boolean;\n}\n\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\n * @beta\n */\nexport interface PotentialParseUnit {\n unitName: string;\n altLabels?: string[];\n}\n\n/**\n * This interface defines extra properties to be associated with Units from Units Schema by name\n * @alpha\n */\nexport interface UnitExtraData {\n readonly name: string;\n readonly altDisplayLabels: string[];\n}\n\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\n * @beta\n */\nexport interface UnitsProvider {\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\n findUnitByName(unitName: string): Promise<UnitProps>;\n /**\n * Compute the conversion factors from `fromUnit` to `toUnit`.\n * On failure (unknown unit, incompatible phenomena), implementations MUST return\n * `{ factor: 1.0, offset: 0.0, error: true }`. Throwing is also permitted;\n * composite providers treat a throw as equivalent to `error: true`.\n * Callers MUST check `result.error` before applying the conversion.\n */\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\n}\n\n/**\n * Identifies a user-facing unit system preference group.\n *\n * A `UnitSystemKey` does **not** map one-to-one to an EC `UnitSystem` element. Instead, each key\n * represents a *preference group* that matches against one or more EC `UnitSystem` names in\n * priority order when resolving formats from a `KindOfQuantity`:\n *\n * | Key | EC UnitSystems matched (highest priority first) |\n * | -------------- | ------------------------------------------------------- |\n * | `\"metric\"` | SI / METRIC, INTERNATIONAL, FINANCE |\n * | `\"imperial\"` | IMPERIAL, USCUSTOM, INTERNATIONAL, FINANCE |\n * | `\"usCustomary\"`| USCUSTOM, INTERNATIONAL, FINANCE |\n * | `\"usSurvey\"` | USSURVEY, USCUSTOM, INTERNATIONAL, FINANCE |\n *\n * EC `UnitSystem` elements not listed above (e.g. CGS, MARITIME, INDUSTRIAL) are not covered by\n * any preference group and will only appear if a `KindOfQuantity` explicitly references them.\n *\n * @see [SchemaFormatsProvider]($ecschema-metadata) for how preference groups resolve formats.\n * @beta\n */\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAmDH;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\r\n * @beta\r\n */\r\nexport interface AlternateUnitLabelsProvider {\r\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\r\n}\r\n\r\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\r\n * uniquely identifies a unit by its name.\r\n * @beta\r\n */\r\nexport interface UnitProps {\r\n /** Unique name for unit. */\r\n readonly name: string;\r\n /** Default label for unit. */\r\n readonly label: string;\r\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\r\n readonly phenomenon: string;\r\n /** This is set to true if the Unit is known by the UnitsProvider. */\r\n readonly isValid: boolean;\r\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\r\n readonly system: string;\r\n}\r\n\r\n/** This interface defines the required properties of a Quantity.\r\n * @beta\r\n */\r\nexport interface QuantityProps {\r\n readonly magnitude: number;\r\n readonly unit: UnitProps;\r\n readonly isValid: boolean;\r\n}\r\n\r\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\r\n * @beta\r\n */\r\nexport interface UnitConversionSpec {\r\n /** Unit name that was used to locate the unit by the Unit Provider */\r\n name: string;\r\n /** The default label that is used to display unit */\r\n label: string;\r\n /** Unit system name, used to when finding preferred parse unit */\r\n system: string;\r\n /** the information necessary to convert the unit to a specific display unit */\r\n conversion: UnitConversionProps;\r\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\r\n parseLabels?: string[];\r\n}\r\n\r\n/** Indicates the way in which unit values are inverted during conversion\r\n * @beta\r\n */\r\nexport enum UnitConversionInvert {\r\n /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */\r\n InvertPreConversion = \"InvertPreConversion\",\r\n /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */\r\n InvertPostConversion = \"InvertPostConversion\"\r\n}\r\n\r\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\r\n * or from Celsius to Fahrenheit.\r\n * @beta\r\n */\r\nexport interface UnitConversionProps {\r\n /** The factor to multiply the input value by to convert to the output value. */\r\n factor: number;\r\n /** The offset to add to the input value to convert to the output value. */\r\n offset: number;\r\n /** If set, inverts the unit value (1/x) before or after conversion. */\r\n inversion?: UnitConversionInvert;\r\n /**\r\n * If `true`, the conversion could not be resolved (e.g. unknown unit, incompatible phenomena).\r\n * When `error` is `true`, `factor` MUST be `1.0` and `offset` MUST be `0.0` (identity).\r\n * Callers must check this flag before applying the conversion — applying an identity conversion\r\n * silently produces wrong output.\r\n */\r\n error?: boolean;\r\n}\r\n\r\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\r\n * @beta\r\n */\r\nexport interface PotentialParseUnit {\r\n unitName: string;\r\n altLabels?: string[];\r\n}\r\n\r\n/**\r\n * This interface defines extra properties to be associated with Units from Units Schema by name\r\n * @alpha\r\n */\r\nexport interface UnitExtraData {\r\n readonly name: string;\r\n readonly altDisplayLabels: string[];\r\n}\r\n\r\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\r\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\r\n * @beta\r\n */\r\nexport interface UnitsProvider {\r\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\r\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\r\n findUnitByName(unitName: string): Promise<UnitProps>;\r\n /**\r\n * Compute the conversion factors from `fromUnit` to `toUnit`.\r\n * On failure (unknown unit, incompatible phenomena), implementations MUST return\r\n * `{ factor: 1.0, offset: 0.0, error: true }`. Throwing is also permitted;\r\n * composite providers treat a throw as equivalent to `error: true`.\r\n * Callers MUST check `result.error` before applying the conversion.\r\n */\r\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\r\n}\r\n\r\n/**\r\n * Identifies a user-facing unit system preference group.\r\n *\r\n * A `UnitSystemKey` does **not** map one-to-one to an EC `UnitSystem` element. Instead, each key\r\n * represents a *preference group* that matches against one or more EC `UnitSystem` names in\r\n * priority order when resolving formats from a `KindOfQuantity`:\r\n *\r\n * | Key | EC UnitSystems matched (highest priority first) |\r\n * | -------------- | ------------------------------------------------------- |\r\n * | `\"metric\"` | SI / METRIC, INTERNATIONAL, FINANCE |\r\n * | `\"imperial\"` | IMPERIAL, USCUSTOM, INTERNATIONAL, FINANCE |\r\n * | `\"usCustomary\"`| USCUSTOM, INTERNATIONAL, FINANCE |\r\n * | `\"usSurvey\"` | USSURVEY, USCUSTOM, INTERNATIONAL, FINANCE |\r\n *\r\n * EC `UnitSystem` elements not listed above (e.g. CGS, MARITIME, INDUSTRIAL) are not covered by\r\n * any preference group and will only appear if a `KindOfQuantity` explicitly references them.\r\n *\r\n * @see [SchemaFormatsProvider]($ecschema-metadata) for how preference groups resolve formats.\r\n * @beta\r\n */\r\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\r\n"]}
@@ -113,7 +113,8 @@ export declare class Parser {
113
113
  * @deprecated in 4.10 - might be removed in next major version. Check [[Parser.parseQuantityString]] for replacements.
114
114
  */
115
115
  static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
116
- /** The value of special direction is always in degrees, try to find the unit conversion for that. */
116
+ /** The value of special direction is always in degrees; resolve "degrees" relative to
117
+ * `spec.outUnit`'s phenomenon, since `Units.ARC_DEG` only exists in the `Units.ANGLE` family. */
117
118
  private static processSpecialBearingDirection;
118
119
  private static parseBearingFormat;
119
120
  private static parseAzimuthFormat;
@@ -134,6 +135,10 @@ export declare class Parser {
134
135
  private static parseRatioFormat;
135
136
  private static normalizeAngle;
136
137
  private static getRevolution;
138
+ /** Converts an azimuth-convention magnitude back to a raw math angle when `spec.outUnit` is
139
+ * `ANGLE`-phenomenon (mirrors the transform in `Formatter.processBearingAndAzimuth`). No-op for
140
+ * `HORIZONTAL_DIRECTION`, which is already a true azimuth. */
141
+ private static convertAzimuthToPersistenceConvention;
137
142
  private static parseAndProcessTokens;
138
143
  /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
139
144
  static createUnitConversionSpecsForUnit(unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../src/Parser.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,aAAa,EAAuB,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,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@@ -14,6 +14,7 @@ const Exception_1 = require("./Exception");
14
14
  const FormatEnums_1 = require("./Formatter/FormatEnums");
15
15
  const QuantityLoggerCategory_1 = require("./QuantityLoggerCategory");
16
16
  const Quantity_1 = require("./Quantity");
17
+ const Units_generated_1 = require("./generated/Units.generated");
17
18
  /** Possible parser errors
18
19
  * @beta
19
20
  */
@@ -677,16 +678,19 @@ class Parser {
677
678
  }
678
679
  return this.parseAndProcessTokens(inString, format, unitsConversions);
679
680
  }
680
- /** The value of special direction is always in degrees, try to find the unit conversion for that. */
681
+ /** The value of special direction is always in degrees; resolve "degrees" relative to
682
+ * `spec.outUnit`'s phenomenon, since `Units.ARC_DEG` only exists in the `Units.ANGLE` family. */
681
683
  static processSpecialBearingDirection(mag, spec) {
682
- const specialDirUnit = spec.unitConversions.find((unitConversion) => unitConversion.name === "Units.ARC_DEG");
684
+ const degreeUnitName = spec.outUnit.phenomenon === Units_generated_1.Phenomena.HORIZONTAL_DIRECTION ? "Units.HORIZONTAL_DIR_ARC_DEG" : "Units.ARC_DEG";
685
+ const specialDirUnit = spec.unitConversions.find((unitConversion) => unitConversion.name === degreeUnitName);
683
686
  if (!specialDirUnit)
684
687
  return { ok: false, error: ParseError.UnknownUnit };
685
688
  const preferredUnit = spec.outUnit;
686
689
  const conversion = this.tryFindUnitConversion(specialDirUnit.label, spec.unitConversions, preferredUnit);
687
690
  if (!conversion)
688
691
  return { ok: true, value: mag };
689
- return { ok: true, value: (0, Quantity_1.applyConversion)(mag, conversion) };
692
+ const revolution = this.getRevolution(spec);
693
+ return { ok: true, value: this.convertAzimuthToPersistenceConvention((0, Quantity_1.applyConversion)(mag, conversion), spec, revolution) };
690
694
  }
691
695
  static parseBearingFormat(inString, spec) {
692
696
  const specialDirections = {
@@ -763,6 +767,7 @@ class Parser {
763
767
  }
764
768
  }
765
769
  magnitude = this.normalizeAngle(magnitude, revolution);
770
+ magnitude = this.convertAzimuthToPersistenceConvention(magnitude, spec, revolution);
766
771
  return { ok: true, value: magnitude };
767
772
  }
768
773
  static parseAzimuthFormat(inString, spec) {
@@ -788,6 +793,8 @@ class Parser {
788
793
  const inputIsClockwise = spec.format.azimuthClockwiseOrDefault;
789
794
  if (inputIsClockwise && azimuthBase === 0) {
790
795
  // parsed result already has the same base and orientation as our desired output
796
+ if (spec.outUnit.phenomenon === Units_generated_1.Phenomena.ANGLE)
797
+ return { ok: true, value: this.convertAzimuthToPersistenceConvention(magnitude, spec, revolution) };
791
798
  return parsedResult;
792
799
  }
793
800
  if (inputIsClockwise)
@@ -795,6 +802,7 @@ class Parser {
795
802
  else
796
803
  magnitude = azimuthBase - magnitude;
797
804
  magnitude = this.normalizeAngle(magnitude, revolution);
805
+ magnitude = this.convertAzimuthToPersistenceConvention(magnitude, spec, revolution);
798
806
  return { ok: true, value: magnitude };
799
807
  }
800
808
  /**
@@ -936,6 +944,15 @@ class Parser {
936
944
  }
937
945
  return converted.magnitude;
938
946
  }
947
+ /** Converts an azimuth-convention magnitude back to a raw math angle when `spec.outUnit` is
948
+ * `ANGLE`-phenomenon (mirrors the transform in `Formatter.processBearingAndAzimuth`). No-op for
949
+ * `HORIZONTAL_DIRECTION`, which is already a true azimuth. */
950
+ static convertAzimuthToPersistenceConvention(magnitude, spec, revolution) {
951
+ if (spec.outUnit.phenomenon !== Units_generated_1.Phenomena.ANGLE)
952
+ return magnitude;
953
+ const quarterRevolution = revolution / 4;
954
+ return this.normalizeAngle(quarterRevolution - magnitude, revolution);
955
+ }
939
956
  static parseAndProcessTokens(inString, format, unitsConversions) {
940
957
  const tokens = Parser.parseQuantitySpecification(inString, format);
941
958
  if (Parser._log) {