@itwin/core-quantity 5.9.0-dev.9 → 5.9.1
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.
- package/CHANGELOG.md +32 -1
- package/lib/cjs/BasicUnitsProvider.d.ts +44 -0
- package/lib/cjs/BasicUnitsProvider.d.ts.map +1 -0
- package/lib/cjs/BasicUnitsProvider.js +241 -0
- package/lib/cjs/BasicUnitsProvider.js.map +1 -0
- package/lib/cjs/CompositeUnitsProvider.d.ts +45 -0
- package/lib/cjs/CompositeUnitsProvider.d.ts.map +1 -0
- package/lib/cjs/CompositeUnitsProvider.js +111 -0
- package/lib/cjs/CompositeUnitsProvider.js.map +1 -0
- package/lib/cjs/FormatSpecHandle.d.ts +56 -0
- package/lib/cjs/FormatSpecHandle.d.ts.map +1 -0
- package/lib/cjs/FormatSpecHandle.js +87 -0
- package/lib/cjs/FormatSpecHandle.js.map +1 -0
- package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
- package/lib/cjs/Formatter/Formatter.js.map +1 -1
- package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
- package/lib/cjs/Formatter/FormatterSpec.js +14 -0
- package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
- package/lib/cjs/Formatter/FormattingReadyCollector.d.ts +16 -0
- package/lib/cjs/Formatter/FormattingReadyCollector.d.ts.map +1 -0
- package/lib/cjs/Formatter/FormattingReadyCollector.js +44 -0
- package/lib/cjs/Formatter/FormattingReadyCollector.js.map +1 -0
- package/lib/cjs/Formatter/Interfaces.d.ts +51 -3
- package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Formatter/Interfaces.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +31 -1
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Parser.d.ts.map +1 -1
- package/lib/cjs/Parser.js +16 -1
- package/lib/cjs/Parser.js.map +1 -1
- package/lib/cjs/ParserSpec.d.ts.map +1 -1
- package/lib/cjs/ParserSpec.js +15 -2
- package/lib/cjs/ParserSpec.js.map +1 -1
- package/lib/cjs/QuantityLoggerCategory.d.ts +16 -0
- package/lib/cjs/QuantityLoggerCategory.d.ts.map +1 -0
- package/lib/cjs/QuantityLoggerCategory.js +24 -0
- package/lib/cjs/QuantityLoggerCategory.js.map +1 -0
- package/lib/cjs/SerializedUnitSchema.d.ts +98 -0
- package/lib/cjs/SerializedUnitSchema.d.ts.map +1 -0
- package/lib/cjs/SerializedUnitSchema.js +25 -0
- package/lib/cjs/SerializedUnitSchema.js.map +1 -0
- package/lib/cjs/UnitConversion/Graph.d.ts +35 -0
- package/lib/cjs/UnitConversion/Graph.d.ts.map +1 -0
- package/lib/cjs/UnitConversion/Graph.js +87 -0
- package/lib/cjs/UnitConversion/Graph.js.map +1 -0
- package/lib/cjs/UnitConversion/Parser.d.ts +9 -0
- package/lib/cjs/UnitConversion/Parser.d.ts.map +1 -0
- package/lib/cjs/UnitConversion/Parser.js +42 -0
- package/lib/cjs/UnitConversion/Parser.js.map +1 -0
- package/lib/cjs/UnitConversion/UnitConversion.d.ts +56 -0
- package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -0
- package/lib/cjs/UnitConversion/UnitConversion.js +80 -0
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -0
- package/lib/cjs/UnitConversion/UnitDefinitionResolver.d.ts +29 -0
- package/lib/cjs/UnitConversion/UnitDefinitionResolver.d.ts.map +1 -0
- package/lib/cjs/UnitConversion/UnitDefinitionResolver.js +102 -0
- package/lib/cjs/UnitConversion/UnitDefinitionResolver.js.map +1 -0
- package/lib/cjs/UnitConversion/nameUtils.d.ts +11 -0
- package/lib/cjs/UnitConversion/nameUtils.d.ts.map +1 -0
- package/lib/cjs/UnitConversion/nameUtils.js +25 -0
- package/lib/cjs/UnitConversion/nameUtils.js.map +1 -0
- package/lib/cjs/assets/Units.json +4215 -0
- package/lib/cjs/core-quantity.d.ts +22 -1
- package/lib/cjs/core-quantity.d.ts.map +1 -1
- package/lib/cjs/core-quantity.js +24 -1
- package/lib/cjs/core-quantity.js.map +1 -1
- package/lib/cjs/internal/cross-package.d.ts +4 -0
- package/lib/cjs/internal/cross-package.d.ts.map +1 -0
- package/lib/cjs/internal/cross-package.js +13 -0
- package/lib/cjs/internal/cross-package.js.map +1 -0
- package/lib/esm/BasicUnitsProvider.d.ts +44 -0
- package/lib/esm/BasicUnitsProvider.d.ts.map +1 -0
- package/lib/esm/BasicUnitsProvider.js +213 -0
- package/lib/esm/BasicUnitsProvider.js.map +1 -0
- package/lib/esm/CompositeUnitsProvider.d.ts +45 -0
- package/lib/esm/CompositeUnitsProvider.d.ts.map +1 -0
- package/lib/esm/CompositeUnitsProvider.js +108 -0
- package/lib/esm/CompositeUnitsProvider.js.map +1 -0
- package/lib/esm/FormatSpecHandle.d.ts +56 -0
- package/lib/esm/FormatSpecHandle.d.ts.map +1 -0
- package/lib/esm/FormatSpecHandle.js +83 -0
- package/lib/esm/FormatSpecHandle.js.map +1 -0
- package/lib/esm/Formatter/FormatEnums.js.map +1 -1
- package/lib/esm/Formatter/Formatter.js.map +1 -1
- package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
- package/lib/esm/Formatter/FormatterSpec.js +14 -0
- package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
- package/lib/esm/Formatter/FormattingReadyCollector.d.ts +16 -0
- package/lib/esm/Formatter/FormattingReadyCollector.d.ts.map +1 -0
- package/lib/esm/Formatter/FormattingReadyCollector.js +40 -0
- package/lib/esm/Formatter/FormattingReadyCollector.js.map +1 -0
- package/lib/esm/Formatter/Interfaces.d.ts +51 -3
- package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
- package/lib/esm/Formatter/Interfaces.js.map +1 -1
- package/lib/esm/Interfaces.d.ts +31 -1
- package/lib/esm/Interfaces.d.ts.map +1 -1
- package/lib/esm/Interfaces.js.map +1 -1
- package/lib/esm/Parser.d.ts.map +1 -1
- package/lib/esm/Parser.js +16 -1
- package/lib/esm/Parser.js.map +1 -1
- package/lib/esm/ParserSpec.d.ts.map +1 -1
- package/lib/esm/ParserSpec.js +15 -2
- package/lib/esm/ParserSpec.js.map +1 -1
- package/lib/esm/QuantityLoggerCategory.d.ts +16 -0
- package/lib/esm/QuantityLoggerCategory.d.ts.map +1 -0
- package/lib/esm/QuantityLoggerCategory.js +21 -0
- package/lib/esm/QuantityLoggerCategory.js.map +1 -0
- package/lib/esm/SerializedUnitSchema.d.ts +98 -0
- package/lib/esm/SerializedUnitSchema.d.ts.map +1 -0
- package/lib/esm/SerializedUnitSchema.js +22 -0
- package/lib/esm/SerializedUnitSchema.js.map +1 -0
- package/lib/esm/UnitConversion/Graph.d.ts +35 -0
- package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
- package/lib/esm/UnitConversion/Graph.js +83 -0
- package/lib/esm/UnitConversion/Graph.js.map +1 -0
- package/lib/esm/UnitConversion/Parser.d.ts +9 -0
- package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
- package/lib/esm/UnitConversion/Parser.js +39 -0
- package/lib/esm/UnitConversion/Parser.js.map +1 -0
- package/lib/esm/UnitConversion/UnitConversion.d.ts +56 -0
- package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitConversion.js +76 -0
- package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
- package/lib/esm/UnitConversion/UnitDefinitionResolver.d.ts +29 -0
- package/lib/esm/UnitConversion/UnitDefinitionResolver.d.ts.map +1 -0
- package/lib/esm/UnitConversion/UnitDefinitionResolver.js +98 -0
- package/lib/esm/UnitConversion/UnitDefinitionResolver.js.map +1 -0
- package/lib/esm/UnitConversion/nameUtils.d.ts +11 -0
- package/lib/esm/UnitConversion/nameUtils.d.ts.map +1 -0
- package/lib/esm/UnitConversion/nameUtils.js +21 -0
- package/lib/esm/UnitConversion/nameUtils.js.map +1 -0
- package/lib/esm/assets/Units.json +4215 -0
- package/lib/esm/core-quantity.d.ts +22 -1
- package/lib/esm/core-quantity.d.ts.map +1 -1
- package/lib/esm/core-quantity.js +22 -1
- package/lib/esm/core-quantity.js.map +1 -1
- package/lib/esm/internal/cross-package.d.ts +4 -0
- package/lib/esm/internal/cross-package.d.ts.map +1 -0
- package/lib/esm/internal/cross-package.js +8 -0
- package/lib/esm/internal/cross-package.js.map +1 -0
- package/package.json +6 -5
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Quantity
|
|
7
7
|
*/
|
|
8
|
+
import { Logger } from "@itwin/core-bentley";
|
|
9
|
+
import { QuantityLoggerCategory } from "../QuantityLoggerCategory";
|
|
8
10
|
import { FormatType } from "./FormatEnums";
|
|
9
11
|
import { Formatter } from "./Formatter";
|
|
10
12
|
// cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses
|
|
@@ -60,6 +62,9 @@ export class FormatterSpec {
|
|
|
60
62
|
const [denominatorUnit, denominatorLabel] = units[1];
|
|
61
63
|
// Compute ratio scale: how many numerator units per denominator unit (e.g., IN:FT = 12)
|
|
62
64
|
const denominatorToNumerator = await unitsProvider.getConversion(denominatorUnit, numeratorUnit);
|
|
65
|
+
if (denominatorToNumerator.error) {
|
|
66
|
+
Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from "${denominatorUnit.name}" to "${numeratorUnit.name}" could not be resolved.`);
|
|
67
|
+
}
|
|
63
68
|
const displayRatioScale = denominatorToNumerator.factor;
|
|
64
69
|
// Avoid double-scaling: if persistence unit already encodes the display ratio, use factor 1.
|
|
65
70
|
// Check by name heuristic (e.g., IN_PER_FT with ratioUnits [IN, FT] → no scaling needed)
|
|
@@ -119,6 +124,9 @@ export class FormatterSpec {
|
|
|
119
124
|
let unitConversion;
|
|
120
125
|
if (convertFromUnit) {
|
|
121
126
|
unitConversion = await unitsProvider.getConversion(convertFromUnit, unit[0]);
|
|
127
|
+
if (unitConversion.error) {
|
|
128
|
+
Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from "${convertFromUnit.name}" to "${unit[0].name}" could not be resolved.`);
|
|
129
|
+
}
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
132
|
unitConversion = { factor: 1.0, offset: 0.0 };
|
|
@@ -151,6 +159,9 @@ export class FormatterSpec {
|
|
|
151
159
|
if (format.azimuthBaseUnit !== undefined) {
|
|
152
160
|
if (inputUnit !== undefined) {
|
|
153
161
|
azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, inputUnit);
|
|
162
|
+
if (azimuthBaseConversion.error) {
|
|
163
|
+
Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from "${format.azimuthBaseUnit.name}" to "${inputUnit.name}" could not be resolved.`);
|
|
164
|
+
}
|
|
154
165
|
}
|
|
155
166
|
else {
|
|
156
167
|
azimuthBaseConversion = { factor: 1.0, offset: 0.0 };
|
|
@@ -160,6 +171,9 @@ export class FormatterSpec {
|
|
|
160
171
|
if (format.revolutionUnit !== undefined) {
|
|
161
172
|
if (inputUnit !== undefined) {
|
|
162
173
|
revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, inputUnit);
|
|
174
|
+
if (revolutionConversion.error) {
|
|
175
|
+
Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from "${format.revolutionUnit.name}" to "${inputUnit.name}" could not be resolved.`);
|
|
176
|
+
}
|
|
163
177
|
}
|
|
164
178
|
else {
|
|
165
179
|
revolutionConversion = { factor: 1.0, offset: 0.0 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatterSpec.js","sourceRoot":"","sources":["../../../src/Formatter/FormatterSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,sFAAsF;AACtF,6J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xC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,oBAAoB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;YAC7F,CAAC;iBAAM,CAAC;gBACN,oBAAoB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YACtD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;IAC9G,CAAC;IAED,+BAA+B;IACxB,eAAe,CAAC,SAAiB;QACtC,OAAO,SAAS,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;CACF","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 { UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"../Interfaces\";\nimport { Format } from \"./Format\";\nimport { FormatType } from \"./FormatEnums\";\nimport { Formatter } from \"./Formatter\";\n\n// cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses\n// cSpell:ignore trailzeroes, keepsinglezero, zeroempty, keepdecimalpoint, applyrounding, fractiondash, showunitlabel, prependunitlabel, exponentonlynegative\n\n/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format.\n * Once created the FormatterSpec will be able to format quantity values with synchronous calls.\n * @beta\n */\nexport class FormatterSpec {\n protected _name: string;\n protected _conversions: UnitConversionSpec[] = []; // max four entries\n protected _format: Format;\n protected _persistenceUnit: UnitProps;\n protected _azimuthBaseConversion?: UnitConversionProps; // converts azimuth base unit to persistence unit\n protected _revolutionConversion?: UnitConversionProps; // converts revolution unit to persistence unit\n\n /** Constructor\n * @param name The name of a format specification.\n * @param format Defines the output format for the quantity value.\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format.\n * @param persistenceUnit The unit the magnitude value is input.\n * @param azimuthBaseConversion The conversion used to interpret azimuth base values.\n * @param revolutionConversion The conversion used to determine a revolution value (used for bearing and azimuth).\n */\n constructor(name: string, format: Format, conversions?: UnitConversionSpec[], persistenceUnit?: UnitProps, azimuthBaseConversion?: UnitConversionProps, revolutionConversion?: UnitConversionProps) {\n if (!persistenceUnit) {\n if (format.units) {\n const [props] = format.units[0];\n persistenceUnit = props;\n } else {\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\n }\n }\n\n this._name = name;\n this._format = format;\n this._persistenceUnit = persistenceUnit;\n if (conversions)\n this._conversions = conversions;\n this._azimuthBaseConversion = azimuthBaseConversion;\n this._revolutionConversion = revolutionConversion;\n }\n\n public get name(): string { return this._name; }\n /** Returns an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\n public get format(): Format { return this._format; }\n public get persistenceUnit(): UnitProps { return this._persistenceUnit; }\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\n\n /** Build conversion specs for ratio format with 2 composite units (numerator/denominator). */\n private static async getRatioUnitConversions(units: ReadonlyArray<[UnitProps, string | undefined]>, unitsProvider: UnitsProvider, persistenceUnit: UnitProps): Promise<UnitConversionSpec[]> {\n const conversions: UnitConversionSpec[] = [];\n\n const [numeratorUnit, numeratorLabel] = units[0];\n const [denominatorUnit, denominatorLabel] = units[1];\n\n // Compute ratio scale: how many numerator units per denominator unit (e.g., IN:FT = 12)\n const denominatorToNumerator = await unitsProvider.getConversion(denominatorUnit, numeratorUnit);\n const displayRatioScale = denominatorToNumerator.factor;\n\n // Avoid double-scaling: if persistence unit already encodes the display ratio, use factor 1.\n // Check by name heuristic (e.g., IN_PER_FT with ratioUnits [IN, FT] → no scaling needed)\n const persistenceName = persistenceUnit.name.toUpperCase();\n const numName = numeratorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\n const denName = denominatorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\n // Split by word boundaries (underscores, dots) and check for exact token matches\n const persistenceTokens = persistenceName.split(/[._]/);\n const isPersistenceMatchingRatio = persistenceTokens.includes(numName) && persistenceTokens.includes(denName);\n const ratioScaleFactor = isPersistenceMatchingRatio ? 1.0 : displayRatioScale;\n\n // First conversion spec: effective ratio unit conversion\n const ratioConversionSpec: UnitConversionSpec = {\n name: `${numeratorUnit.name}_per_${denominatorUnit.name}`,\n label: \"\",\n system: numeratorUnit.system,\n conversion: { factor: ratioScaleFactor, offset: 0.0 },\n };\n conversions.push(ratioConversionSpec);\n\n // Numerator unit for label lookup\n const numeratorSpec: UnitConversionSpec = {\n name: numeratorUnit.name,\n label: numeratorLabel?.length ? numeratorLabel : numeratorUnit.label,\n system: numeratorUnit.system,\n conversion: { factor: 1.0, offset: 0.0 },\n };\n conversions.push(numeratorSpec);\n\n // Denominator unit for label lookup\n const denominatorSpec: UnitConversionSpec = {\n name: denominatorUnit.name,\n label: denominatorLabel?.length ? denominatorLabel : denominatorUnit.label,\n system: denominatorUnit.system,\n conversion: { factor: 1.0, offset: 0.0 },\n };\n conversions.push(denominatorSpec);\n\n return conversions;\n }\n\n /** Get an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\n public static async getUnitConversions(format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<UnitConversionSpec[]> {\n const conversions: UnitConversionSpec[] = [];\n let persistenceUnit = inputUnit;\n if (!persistenceUnit) {\n if (format.units) {\n const [props] = format.units[0];\n persistenceUnit = props;\n } else {\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\n }\n }\n\n // Handle 2-unit composite for ratio formats (scale factors)\n if (format.type === FormatType.Ratio && format.units && format.units.length === 2) {\n return FormatterSpec.getRatioUnitConversions(format.units, unitsProvider, persistenceUnit);\n }\n\n if (format.units) {\n let convertFromUnit = inputUnit;\n for (const unit of format.units) {\n let unitConversion: UnitConversionProps;\n if (convertFromUnit) {\n unitConversion = await unitsProvider.getConversion(convertFromUnit, unit[0]);\n } else {\n unitConversion = { factor: 1.0, offset: 0.0 };\n }\n const unitLabel = (unit[1] && unit[1].length > 0) ? unit[1] : unit[0].label;\n const spec = ({ name: unit[0].name, label: unitLabel, conversion: unitConversion, system: unit[0].system }) as UnitConversionSpec;\n\n conversions.push(spec);\n convertFromUnit = unit[0];\n }\n } else {\n // if format is only numeric and a input unit is defined set spec to use the input unit as the format unit\n if (inputUnit) {\n const spec: UnitConversionSpec = { name: inputUnit.name, label: inputUnit.label, system: inputUnit.system, conversion: { factor: 1.0, offset: 0.0 } };\n conversions.push(spec);\n }\n }\n\n return conversions;\n }\n\n /** Static async method to create a FormatSpec given the format and unit of the quantity that will be passed to the Formatter. The input unit will\n * be used to generate conversion information for each unit specified in the Format. This method is async due to the fact that the units provider must make\n * async calls to lookup unit definitions.\n * @param name The name of a format specification.\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\n * @param inputUnit The unit the value to be formatted. This unit is often referred to as persistence unit.\n */\n public static async create(name: string, format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<FormatterSpec> {\n const conversions: UnitConversionSpec[] = await FormatterSpec.getUnitConversions(format, unitsProvider, inputUnit);\n let azimuthBaseConversion: UnitConversionProps | undefined;\n if (format.azimuthBaseUnit !== undefined) {\n if (inputUnit !== undefined) {\n azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, inputUnit);\n } else {\n azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n let revolutionConversion: UnitConversionProps | undefined;\n if (format.revolutionUnit !== undefined) {\n if (inputUnit !== undefined) {\n revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, inputUnit);\n } else {\n revolutionConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n\n return new FormatterSpec(name, format, conversions, inputUnit, azimuthBaseConversion, revolutionConversion);\n }\n\n /** Format a quantity value. */\n public applyFormatting(magnitude: number): string {\n return Formatter.formatQuantity(magnitude, this);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FormatterSpec.js","sourceRoot":"","sources":["../../../src/Formatter/FormatterSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,sFAAsF;AACtF,6JAA6J;AAE7J;;;GAGG;AACH,MAAM,OAAO,aAAa;IACd,KAAK,CAAS;IACd,YAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;IAC7D,OAAO,CAAS;IAChB,gBAAgB,CAAY;IAC5B,sBAAsB,CAAuB,CAAC,iDAAiD;IAC/F,qBAAqB,CAAuB,CAAC,+CAA+C;IAEtG;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,MAAc,EAAE,WAAkC,EAAE,eAA2B,EAAE,qBAA2C,EAAE,oBAA0C;QAChM,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAChC,eAAe,GAAG,KAAK,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IA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AS,CAAC,CAAC;gBAC3F,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;oBAC/B,MAAM,CAAC,UAAU,CAAC,sBAAsB,CAAC,UAAU,EAAE,yBAAyB,MAAM,CAAC,cAAc,CAAC,IAAI,SAAS,SAAS,CAAC,IAAI,0BAA0B,CAAC,CAAC;gBAC7J,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,oBAAoB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YACtD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;IAC9G,CAAC;IAED,+BAA+B;IACxB,eAAe,CAAC,SAAiB;QACtC,OAAO,SAAS,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;CACF","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 { Logger } from \"@itwin/core-bentley\";\nimport { UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"../Interfaces\";\nimport { QuantityLoggerCategory } from \"../QuantityLoggerCategory\";\nimport { Format } from \"./Format\";\nimport { FormatType } from \"./FormatEnums\";\nimport { Formatter } from \"./Formatter\";\n\n// cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses\n// cSpell:ignore trailzeroes, keepsinglezero, zeroempty, keepdecimalpoint, applyrounding, fractiondash, showunitlabel, prependunitlabel, exponentonlynegative\n\n/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format.\n * Once created the FormatterSpec will be able to format quantity values with synchronous calls.\n * @beta\n */\nexport class FormatterSpec {\n protected _name: string;\n protected _conversions: UnitConversionSpec[] = []; // max four entries\n protected _format: Format;\n protected _persistenceUnit: UnitProps;\n protected _azimuthBaseConversion?: UnitConversionProps; // converts azimuth base unit to persistence unit\n protected _revolutionConversion?: UnitConversionProps; // converts revolution unit to persistence unit\n\n /** Constructor\n * @param name The name of a format specification.\n * @param format Defines the output format for the quantity value.\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format.\n * @param persistenceUnit The unit the magnitude value is input.\n * @param azimuthBaseConversion The conversion used to interpret azimuth base values.\n * @param revolutionConversion The conversion used to determine a revolution value (used for bearing and azimuth).\n */\n constructor(name: string, format: Format, conversions?: UnitConversionSpec[], persistenceUnit?: UnitProps, azimuthBaseConversion?: UnitConversionProps, revolutionConversion?: UnitConversionProps) {\n if (!persistenceUnit) {\n if (format.units) {\n const [props] = format.units[0];\n persistenceUnit = props;\n } else {\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\n }\n }\n\n this._name = name;\n this._format = format;\n this._persistenceUnit = persistenceUnit;\n if (conversions)\n this._conversions = conversions;\n this._azimuthBaseConversion = azimuthBaseConversion;\n this._revolutionConversion = revolutionConversion;\n }\n\n public get name(): string { return this._name; }\n /** Returns an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\n public get format(): Format { return this._format; }\n public get persistenceUnit(): UnitProps { return this._persistenceUnit; }\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\n\n /** Build conversion specs for ratio format with 2 composite units (numerator/denominator). */\n private static async getRatioUnitConversions(units: ReadonlyArray<[UnitProps, string | undefined]>, unitsProvider: UnitsProvider, persistenceUnit: UnitProps): Promise<UnitConversionSpec[]> {\n const conversions: UnitConversionSpec[] = [];\n\n const [numeratorUnit, numeratorLabel] = units[0];\n const [denominatorUnit, denominatorLabel] = units[1];\n\n // Compute ratio scale: how many numerator units per denominator unit (e.g., IN:FT = 12)\n const denominatorToNumerator = await unitsProvider.getConversion(denominatorUnit, numeratorUnit);\n if (denominatorToNumerator.error) {\n Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from \"${denominatorUnit.name}\" to \"${numeratorUnit.name}\" could not be resolved.`);\n }\n const displayRatioScale = denominatorToNumerator.factor;\n\n // Avoid double-scaling: if persistence unit already encodes the display ratio, use factor 1.\n // Check by name heuristic (e.g., IN_PER_FT with ratioUnits [IN, FT] → no scaling needed)\n const persistenceName = persistenceUnit.name.toUpperCase();\n const numName = numeratorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\n const denName = denominatorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\n // Split by word boundaries (underscores, dots) and check for exact token matches\n const persistenceTokens = persistenceName.split(/[._]/);\n const isPersistenceMatchingRatio = persistenceTokens.includes(numName) && persistenceTokens.includes(denName);\n const ratioScaleFactor = isPersistenceMatchingRatio ? 1.0 : displayRatioScale;\n\n // First conversion spec: effective ratio unit conversion\n const ratioConversionSpec: UnitConversionSpec = {\n name: `${numeratorUnit.name}_per_${denominatorUnit.name}`,\n label: \"\",\n system: numeratorUnit.system,\n conversion: { factor: ratioScaleFactor, offset: 0.0 },\n };\n conversions.push(ratioConversionSpec);\n\n // Numerator unit for label lookup\n const numeratorSpec: UnitConversionSpec = {\n name: numeratorUnit.name,\n label: numeratorLabel?.length ? numeratorLabel : numeratorUnit.label,\n system: numeratorUnit.system,\n conversion: { factor: 1.0, offset: 0.0 },\n };\n conversions.push(numeratorSpec);\n\n // Denominator unit for label lookup\n const denominatorSpec: UnitConversionSpec = {\n name: denominatorUnit.name,\n label: denominatorLabel?.length ? denominatorLabel : denominatorUnit.label,\n system: denominatorUnit.system,\n conversion: { factor: 1.0, offset: 0.0 },\n };\n conversions.push(denominatorSpec);\n\n return conversions;\n }\n\n /** Get an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\n public static async getUnitConversions(format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<UnitConversionSpec[]> {\n const conversions: UnitConversionSpec[] = [];\n let persistenceUnit = inputUnit;\n if (!persistenceUnit) {\n if (format.units) {\n const [props] = format.units[0];\n persistenceUnit = props;\n } else {\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\n }\n }\n\n // Handle 2-unit composite for ratio formats (scale factors)\n if (format.type === FormatType.Ratio && format.units && format.units.length === 2) {\n return FormatterSpec.getRatioUnitConversions(format.units, unitsProvider, persistenceUnit);\n }\n\n if (format.units) {\n let convertFromUnit = inputUnit;\n for (const unit of format.units) {\n let unitConversion: UnitConversionProps;\n if (convertFromUnit) {\n unitConversion = await unitsProvider.getConversion(convertFromUnit, unit[0]);\n if (unitConversion.error) {\n Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from \"${convertFromUnit.name}\" to \"${unit[0].name}\" could not be resolved.`);\n }\n } else {\n unitConversion = { factor: 1.0, offset: 0.0 };\n }\n const unitLabel = (unit[1] && unit[1].length > 0) ? unit[1] : unit[0].label;\n const spec = ({ name: unit[0].name, label: unitLabel, conversion: unitConversion, system: unit[0].system }) as UnitConversionSpec;\n\n conversions.push(spec);\n convertFromUnit = unit[0];\n }\n } else {\n // if format is only numeric and a input unit is defined set spec to use the input unit as the format unit\n if (inputUnit) {\n const spec: UnitConversionSpec = { name: inputUnit.name, label: inputUnit.label, system: inputUnit.system, conversion: { factor: 1.0, offset: 0.0 } };\n conversions.push(spec);\n }\n }\n\n return conversions;\n }\n\n /** Static async method to create a FormatSpec given the format and unit of the quantity that will be passed to the Formatter. The input unit will\n * be used to generate conversion information for each unit specified in the Format. This method is async due to the fact that the units provider must make\n * async calls to lookup unit definitions.\n * @param name The name of a format specification.\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\n * @param inputUnit The unit the value to be formatted. This unit is often referred to as persistence unit.\n */\n public static async create(name: string, format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<FormatterSpec> {\n const conversions: UnitConversionSpec[] = await FormatterSpec.getUnitConversions(format, unitsProvider, inputUnit);\n let azimuthBaseConversion: UnitConversionProps | undefined;\n if (format.azimuthBaseUnit !== undefined) {\n if (inputUnit !== undefined) {\n azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, inputUnit);\n if (azimuthBaseConversion.error) {\n Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from \"${format.azimuthBaseUnit.name}\" to \"${inputUnit.name}\" could not be resolved.`);\n }\n } else {\n azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n let revolutionConversion: UnitConversionProps | undefined;\n if (format.revolutionUnit !== undefined) {\n if (inputUnit !== undefined) {\n revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, inputUnit);\n if (revolutionConversion.error) {\n Logger.logWarning(QuantityLoggerCategory.Formatting, `Unit conversion from \"${format.revolutionUnit.name}\" to \"${inputUnit.name}\" could not be resolved.`);\n }\n } else {\n revolutionConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n\n return new FormatterSpec(name, format, conversions, inputUnit, azimuthBaseConversion, revolutionConversion);\n }\n\n /** Format a quantity value. */\n public applyFormatting(magnitude: number): string {\n return Formatter.formatQuantity(magnitude, this);\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @module Quantity */
|
|
2
|
+
/** Collects async work from formatting providers during the pre-ready phase.
|
|
3
|
+
* Providers call [[addPendingWork]] to register promises that the formatter
|
|
4
|
+
* will await before signaling [[QuantityFormatter.onFormattingReady]].
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export declare class FormattingReadyCollector {
|
|
8
|
+
private _promises;
|
|
9
|
+
/** Register async work that must complete before the formatter signals ready.
|
|
10
|
+
* Call this from an `onBeforeFormattingReady` listener.
|
|
11
|
+
*/
|
|
12
|
+
addPendingWork(work: Promise<void>): void;
|
|
13
|
+
/** @internal Await all registered work with a timeout. Logs warnings for rejections and timeouts. */
|
|
14
|
+
awaitAll(timeoutMs?: number): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=FormattingReadyCollector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormattingReadyCollector.d.ts","sourceRoot":"","sources":["../../../src/Formatter/FormattingReadyCollector.ts"],"names":[],"mappings":"AAIA,uBAAuB;AAKvB;;;;GAIG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,SAAS,CAAuB;IAExC;;OAEG;IACI,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIhD,qGAAqG;IACxF,QAAQ,CAAC,SAAS,GAAE,MAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBjE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @module Quantity */
|
|
6
|
+
import { Logger } from "@itwin/core-bentley";
|
|
7
|
+
import { QuantityLoggerCategory } from "../QuantityLoggerCategory";
|
|
8
|
+
/** Collects async work from formatting providers during the pre-ready phase.
|
|
9
|
+
* Providers call [[addPendingWork]] to register promises that the formatter
|
|
10
|
+
* will await before signaling [[QuantityFormatter.onFormattingReady]].
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export class FormattingReadyCollector {
|
|
14
|
+
_promises = [];
|
|
15
|
+
/** Register async work that must complete before the formatter signals ready.
|
|
16
|
+
* Call this from an `onBeforeFormattingReady` listener.
|
|
17
|
+
*/
|
|
18
|
+
addPendingWork(work) {
|
|
19
|
+
this._promises.push(work);
|
|
20
|
+
}
|
|
21
|
+
/** @internal Await all registered work with a timeout. Logs warnings for rejections and timeouts. */
|
|
22
|
+
async awaitAll(timeoutMs = 20_000) {
|
|
23
|
+
if (this._promises.length === 0)
|
|
24
|
+
return;
|
|
25
|
+
const timeout = new Promise((resolve) => setTimeout(() => resolve("timeout"), timeoutMs));
|
|
26
|
+
const work = Promise.allSettled(this._promises).then((results) => {
|
|
27
|
+
for (const result of results) {
|
|
28
|
+
if (result.status === "rejected") {
|
|
29
|
+
Logger.logWarning(QuantityLoggerCategory.Formatting, "FormattingReadyCollector: a provider's async work rejected", () => ({ reason: result.reason }));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "done";
|
|
33
|
+
});
|
|
34
|
+
const outcome = await Promise.race([work, timeout]);
|
|
35
|
+
if (outcome === "timeout") {
|
|
36
|
+
Logger.logWarning(QuantityLoggerCategory.Formatting, `FormattingReadyCollector: timed out after ${timeoutMs}ms waiting for ${this._promises.length} provider(s). Proceeding with ready signal.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=FormattingReadyCollector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormattingReadyCollector.js","sourceRoot":"","sources":["../../../src/Formatter/FormattingReadyCollector.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,uBAAuB;AAEvB,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,OAAO,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,MAAM,CAAC,UAAU,CAAC,sBAAsB,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,MAAM,CAAC,UAAU,CAAC,sBAAsB,CAAC,UAAU,EAAE,6CAA6C,SAAS,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,6CAA6C,CAAC,CAAC;QACnM,CAAC;IACH,CAAC;CACF","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,9 +1,11 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Quantity
|
|
3
3
|
*/
|
|
4
|
-
import { BeEvent } from "@itwin/core-bentley";
|
|
5
|
-
import { UnitProps } from "../Interfaces";
|
|
4
|
+
import { BeEvent, BeUnorderedUiEvent } from "@itwin/core-bentley";
|
|
5
|
+
import { UnitProps, UnitSystemKey } from "../Interfaces";
|
|
6
6
|
import { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from "./FormatEnums";
|
|
7
|
+
import type { FormatterSpec } from "./FormatterSpec";
|
|
8
|
+
import type { ParserSpec } from "../ParserSpec";
|
|
7
9
|
/** Defines a unit specification with a name and optional label override.
|
|
8
10
|
* Used in composite formats and ratio unit specifications.
|
|
9
11
|
* @beta
|
|
@@ -150,6 +152,13 @@ export interface FormatsChangedArgs {
|
|
|
150
152
|
* If array, the array items list the names of formats that were changed or removed.
|
|
151
153
|
*/
|
|
152
154
|
formatsChanged: "all" | string[];
|
|
155
|
+
/** If set, indicates that the format set implies a particular unit system. The consumer
|
|
156
|
+
* (e.g., QuantityFormatter) will synchronize the active unit system to match.
|
|
157
|
+
* If `undefined`, the format change does not imply a unit system switch — the active
|
|
158
|
+
* unit system remains unchanged.
|
|
159
|
+
* @beta
|
|
160
|
+
*/
|
|
161
|
+
impliedUnitSystem?: UnitSystemKey;
|
|
153
162
|
}
|
|
154
163
|
/** This interface is implemented by a class that would provide formats for use in formatting quantities.
|
|
155
164
|
* @beta
|
|
@@ -158,7 +167,7 @@ export interface FormatsProvider {
|
|
|
158
167
|
/**
|
|
159
168
|
* @param name The full name of the Format or KindOfQuantity.
|
|
160
169
|
*/
|
|
161
|
-
getFormat(name: string): Promise<FormatDefinition | undefined>;
|
|
170
|
+
getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;
|
|
162
171
|
/**
|
|
163
172
|
* Fired when formats are added, removed, or changed.
|
|
164
173
|
* If all formats are changed, a single string "all" is emitted. Else, an array of changed format names is emitted.
|
|
@@ -179,4 +188,43 @@ export interface MutableFormatsProvider extends FormatsProvider {
|
|
|
179
188
|
*/
|
|
180
189
|
removeFormat(name: string): Promise<void>;
|
|
181
190
|
}
|
|
191
|
+
/** Entries returned when looking up specs from the format registry.
|
|
192
|
+
* @beta
|
|
193
|
+
*/
|
|
194
|
+
export interface FormattingSpecEntry {
|
|
195
|
+
formatterSpec: FormatterSpec;
|
|
196
|
+
parserSpec: ParserSpec;
|
|
197
|
+
}
|
|
198
|
+
/** Arguments for looking up a formatting spec entry.
|
|
199
|
+
* @beta
|
|
200
|
+
*/
|
|
201
|
+
export interface FormattingSpecArgs {
|
|
202
|
+
/** The KoQ name to look up. */
|
|
203
|
+
name: string;
|
|
204
|
+
/** The persistence unit name (e.g., `"Units.M"`). */
|
|
205
|
+
persistenceUnitName: string;
|
|
206
|
+
/** Optional unit system override. When omitted, the active system is used. */
|
|
207
|
+
system?: UnitSystemKey;
|
|
208
|
+
}
|
|
209
|
+
/** Arguments for registering a formatting spec entry.
|
|
210
|
+
* @beta
|
|
211
|
+
*/
|
|
212
|
+
export interface AddFormattingSpecArgs extends FormattingSpecArgs {
|
|
213
|
+
/** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */
|
|
214
|
+
formatProps?: FormatProps;
|
|
215
|
+
}
|
|
216
|
+
/** Minimal contract required by [[FormatSpecHandle]] to look up specs and subscribe to reloads.
|
|
217
|
+
* Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.
|
|
218
|
+
* @beta
|
|
219
|
+
*/
|
|
220
|
+
export interface FormattingSpecProvider {
|
|
221
|
+
/** Look up a formatting spec entry by KoQ name and persistence unit. */
|
|
222
|
+
getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;
|
|
223
|
+
/** Format a numeric value using the given formatter spec. */
|
|
224
|
+
formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;
|
|
225
|
+
/** Event raised after the provider has finished reloading its caches.
|
|
226
|
+
* Uses Set-backed event for safe concurrent add/remove during emit.
|
|
227
|
+
*/
|
|
228
|
+
readonly onFormattingReady: BeUnorderedUiEvent<void>;
|
|
229
|
+
}
|
|
182
230
|
//# sourceMappingURL=Interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
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,C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
-
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAsHH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,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 Quantity\n */\n\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { UnitProps } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\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}\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): 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"]}
|
|
1
|
+
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwHH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,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 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 specs and subscribe to reloads.\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"]}
|
package/lib/esm/Interfaces.d.ts
CHANGED
|
@@ -66,6 +66,13 @@ export interface UnitConversionProps {
|
|
|
66
66
|
offset: number;
|
|
67
67
|
/** If set, inverts the unit value (1/x) before or after conversion. */
|
|
68
68
|
inversion?: UnitConversionInvert;
|
|
69
|
+
/**
|
|
70
|
+
* If `true`, the conversion could not be resolved (e.g. unknown unit, incompatible phenomena).
|
|
71
|
+
* When `error` is `true`, `factor` MUST be `1.0` and `offset` MUST be `0.0` (identity).
|
|
72
|
+
* Callers must check this flag before applying the conversion — applying an identity conversion
|
|
73
|
+
* silently produces wrong output.
|
|
74
|
+
*/
|
|
75
|
+
error?: boolean;
|
|
69
76
|
}
|
|
70
77
|
/** Interface that defines potential parse units that may be found in user's string input of a quantity value.
|
|
71
78
|
* @beta
|
|
@@ -90,10 +97,33 @@ export interface UnitsProvider {
|
|
|
90
97
|
findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
|
|
91
98
|
getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;
|
|
92
99
|
findUnitByName(unitName: string): Promise<UnitProps>;
|
|
100
|
+
/**
|
|
101
|
+
* Compute the conversion factors from `fromUnit` to `toUnit`.
|
|
102
|
+
* On failure (unknown unit, incompatible phenomena), implementations MUST return
|
|
103
|
+
* `{ factor: 1.0, offset: 0.0, error: true }`. Throwing is also permitted;
|
|
104
|
+
* composite providers treat a throw as equivalent to `error: true`.
|
|
105
|
+
* Callers MUST check `result.error` before applying the conversion.
|
|
106
|
+
*/
|
|
93
107
|
getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;
|
|
94
108
|
}
|
|
95
109
|
/**
|
|
96
|
-
*
|
|
110
|
+
* Identifies a user-facing unit system preference group.
|
|
111
|
+
*
|
|
112
|
+
* A `UnitSystemKey` does **not** map one-to-one to an EC `UnitSystem` element. Instead, each key
|
|
113
|
+
* represents a *preference group* that matches against one or more EC `UnitSystem` names in
|
|
114
|
+
* priority order when resolving formats from a `KindOfQuantity`:
|
|
115
|
+
*
|
|
116
|
+
* | Key | EC UnitSystems matched (highest priority first) |
|
|
117
|
+
* | -------------- | ------------------------------------------------------- |
|
|
118
|
+
* | `"metric"` | SI / METRIC, INTERNATIONAL, FINANCE |
|
|
119
|
+
* | `"imperial"` | IMPERIAL, USCUSTOM, INTERNATIONAL, FINANCE |
|
|
120
|
+
* | `"usCustomary"`| USCUSTOM, INTERNATIONAL, FINANCE |
|
|
121
|
+
* | `"usSurvey"` | USSURVEY, USCUSTOM, INTERNATIONAL, FINANCE |
|
|
122
|
+
*
|
|
123
|
+
* EC `UnitSystem` elements not listed above (e.g. CGS, MARITIME, INDUSTRIAL) are not covered by
|
|
124
|
+
* any preference group and will only appear if a `KindOfQuantity` explicitly references them.
|
|
125
|
+
*
|
|
126
|
+
* @see [SchemaFormatsProvider]($ecschema-metadata) for how preference groups resolve formats.
|
|
97
127
|
* @beta
|
|
98
128
|
*/
|
|
99
129
|
export type UnitSystemKey = "metric" | "imperial" | "usCustomary" | "usSurvey";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,sBAAsB,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,MAAM,EAAE,GAAG,SAAS,CAAC;CACnE;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wHAAwH;IACxH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uGAAuG;IACvG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,IAAI,EAAE,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SAAS,CAAC,CAAC;IACrD;;;;;;OAMG;IACH,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAmDH;;GAEG;AACH,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,KAApB,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\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 getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAmDH;;GAEG;AACH,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,KAApB,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"]}
|
package/lib/esm/Parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../src/Parser.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
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,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AAC,gBAAgB;IAsF/B,OAAO,CAAC,MAAM,CAAC,cAAc;IAS7B,OAAO,CAAC,MAAM,CAAC,aAAa;IAc5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAepC,+HAA+H;WAC3G,gCAAgC,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,qBAAqB,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA+B1L,+HAA+H;WAC3G,yBAAyB,CAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,EAAE,qBAAqB,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAmDhO"}
|
package/lib/esm/Parser.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Quantity
|
|
7
7
|
*/
|
|
8
|
+
import { Logger } from "@itwin/core-bentley";
|
|
8
9
|
import { QuantityConstants } from "./Constants";
|
|
9
10
|
import { QuantityError, QuantityStatus } from "./Exception";
|
|
10
11
|
import { FormatTraits, FormatType } from "./Formatter/FormatEnums";
|
|
12
|
+
import { QuantityLoggerCategory } from "./QuantityLoggerCategory";
|
|
11
13
|
import { applyConversion, Quantity } from "./Quantity";
|
|
12
14
|
/** Possible parser errors
|
|
13
15
|
* @beta
|
|
@@ -388,6 +390,9 @@ export class Parser {
|
|
|
388
390
|
else {
|
|
389
391
|
// Add new conversion to the list.
|
|
390
392
|
const conversion = await unitsProvider.getConversion(unitProps, outUnit);
|
|
393
|
+
if (conversion.error) {
|
|
394
|
+
Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from "${unitProps.name}" to "${outUnit.name}" could not be resolved.`);
|
|
395
|
+
}
|
|
391
396
|
if (conversion) {
|
|
392
397
|
spec = {
|
|
393
398
|
conversion,
|
|
@@ -408,7 +413,11 @@ export class Parser {
|
|
|
408
413
|
static async createQuantityFromParseTokens(tokens, format, unitsProvider, altUnitLabelsProvider) {
|
|
409
414
|
const unitConversionInfos = await this.getRequiredUnitsConversionsToParseTokens(tokens, format, unitsProvider, altUnitLabelsProvider);
|
|
410
415
|
if (unitConversionInfos.outUnit) {
|
|
411
|
-
const
|
|
416
|
+
const outUnitConversion = await unitsProvider.getConversion(unitConversionInfos.outUnit, unitConversionInfos.outUnit);
|
|
417
|
+
if (outUnitConversion.error) {
|
|
418
|
+
Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from "${unitConversionInfos.outUnit.name}" to "${unitConversionInfos.outUnit.name}" could not be resolved.`);
|
|
419
|
+
}
|
|
420
|
+
const value = Parser.getQuantityValueFromParseTokens(tokens, format, unitConversionInfos.specs, outUnitConversion);
|
|
412
421
|
if (value.ok) {
|
|
413
422
|
return new Quantity(unitConversionInfos.outUnit, value.value);
|
|
414
423
|
}
|
|
@@ -943,6 +952,9 @@ export class Parser {
|
|
|
943
952
|
const familyUnits = await unitsProvider.getUnitsByFamily(outUnit.phenomenon);
|
|
944
953
|
for (const unit of familyUnits) {
|
|
945
954
|
const conversion = await unitsProvider.getConversion(unit, outUnit);
|
|
955
|
+
if (conversion.error) {
|
|
956
|
+
Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from "${unit.name}" to "${outUnit.name}" could not be resolved.`);
|
|
957
|
+
}
|
|
946
958
|
const parseLabels = [unit.label.toLocaleLowerCase()];
|
|
947
959
|
const alternateLabels = altUnitLabelsProvider?.getAlternateUnitLabels(unit);
|
|
948
960
|
// add any alternate labels that may be defined for the Unit
|
|
@@ -980,6 +992,9 @@ export class Parser {
|
|
|
980
992
|
continue;
|
|
981
993
|
}
|
|
982
994
|
const conversion = await unitsProvider.getConversion(unit, outUnit);
|
|
995
|
+
if (conversion.error) {
|
|
996
|
+
Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from "${unit.name}" to "${outUnit.name}" could not be resolved.`);
|
|
997
|
+
}
|
|
983
998
|
const parseLabels = [unit.label.toLocaleLowerCase()];
|
|
984
999
|
const alternateLabels = altUnitLabelsProvider?.getAlternateUnitLabels(unit);
|
|
985
1000
|
// add any alternate labels that may be defined for the Unit
|