@itwin/core-common 5.14.0-dev.22 → 5.14.0-dev.23

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.
@@ -1 +1 @@
1
- {"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextField.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;AAE3H;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,iBAAiB;IAChC,qGAAqG;IACrG,YAAY,EAAE,MAAM,CAAC;IACrB,kHAAkH;IAClH,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,SAAS,EAAE,UAAU,CAAC;IACtB,+EAA+E;IAC/E,UAAU,EAAE,MAAM,CAAC;IACnB,6HAA6H;IAC7H,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,4BAA4B,CAAC;IAC3C,mDAAmD;IACnD,aAAa,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,IAAI,CAAC,EAAE,SAAS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,CAAC;IACxB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,0BAA0B,CAAC;IACtC,oFAAoF;IACpF,QAAQ,CAAC,EAAE,0BAA0B,CAAC;CACvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TextField.js","sourceRoot":"","sources":["../../../src/annotation/TextField.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG","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 Annotation\r\n */\r\n\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\n\r\n/** Enumerates the different kinds of [Property]($ecschema-metadata) values that can be used as the basis for a [[FieldRun]]'s display string.\r\n * A field's property type is derived from the property's [PrimitiveType]($ecschema-metadata) and other attributes like its [PrimitiveOrEnumPropertyBase.extendedTypeName]($ecschema-metadata).\r\n * The conversion of the raw property value into a display string can be customized by different [[FieldFormatOptions]] based on its type.\r\n * The following types are currently recognized:\r\n * - \"quantity\": an often-unitized scalar value like a distance or area, formatted using a quantity [Format]($core-quantity).\r\n * - \"coordinate\": a 2- or 3-dimensional point, with each component formatted as a \"quantity\".\r\n * - \"boolean\": a true or false value.\r\n * - \"datetime\": an ECMAScript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date).\r\n * - \"int-enum\": an integer [EnumerationProperty]($ecschema-metadata) formatted using the enum value's display label.\r\n * - \"string-enum\": a string [EnumerationProperty]($ecschema-metadata) formatted using the enum value's display label.\r\n * - \"string\": a value convertible to a string.\r\n * @note Currently, only formatting of \"string\" and \"datetime\" types is implemented. Other types are converted to and formatted as \"string\".\r\n * @beta\r\n */\r\nexport type FieldPropertyType = \"quantity\" | \"coordinate\" | \"string\" | \"boolean\" | \"datetime\" | \"int-enum\" | \"string-enum\";\r\n\r\n/** A chain of property accesses that resolves to a primitive value that forms the basis of the displayed content\r\n * of a [[FieldRun]].\r\n * The simplest property paths consist of a [[propertyName]] and nothing else, where `propertyName` identifies\r\n * a primitive property.\r\n * If `propertyName` identifies a struct or array property, then additional [[accessors]] are required to identify the specific value.\r\n * Some examples:\r\n * ```\r\n * | Access String | propertyName | accessors |\r\n * | ------------- | ------------ | --------- |\r\n * | name | \"name\" | undefined |\r\n * | spouse.name | \"spouse\" | [name] |\r\n * | colors[2] | \"colors\" | [2] |\r\n * | spouse.favoriteRestaurants[1].address | \"spouse\" | [\"favoriteRestaurants\", 1, \"address\"] |\r\n * ```\r\n * @beta\r\n */\r\nexport interface FieldPropertyPath {\r\n /** The name of the BIS property of the [[FieldPropertyHost]] that serves as the root of the path. */\r\n propertyName: string;\r\n /** Property names and/or array indices describing the path from [[propertyName]] to the ultimate BIS property. */\r\n accessors?: Array<string | number>;\r\n}\r\n\r\n/** Describes the source of the property value against which a [[FieldPropertyPath]] is evaluated.\r\n * A field property is always hosted by an [Element]($backend). It may refer to a property belonging to any of the following:\r\n * - The element's BIS class itself;\r\n * - One of the element's [ElementAspect]($backend)s;\r\n * - Or an [EC view]($docs/learning/ECSqlReference/Views.md) with the same ECInstanceId as the element.\r\n * The [[schemaName]] and [[className]] should always identify the exact class that contains [[FieldPropertyPath.propertyName]] - not a subclass thereof.\r\n * @beta\r\n */\r\nexport interface FieldPropertyHost {\r\n /** The Id of the [Element]($backend) that hosts the property. */\r\n elementId: Id64String;\r\n /** The name of the schema containing the class identified by [[className]]. */\r\n schemaName: string;\r\n /** The name of the exact class (not a subclass) containing the property identified by [[FieldPropertyPath.propertyName]]. */\r\n className: string;\r\n}\r\n\r\n/** As part of [[FieldFormatOptions]], specifies how to modify the case of the display string.\r\n * \"as-is\" leaves it unmodified. \"upper\" and \"lower\" convert it to all upper-case or all lower-case, respectively.\r\n * @beta\r\n */\r\nexport type FieldCase = \"as-is\" | \"upper\" | \"lower\";\r\n\r\n/** As part of a [[FieldFormatOptions]], specifies how to format properties of [[FieldPropertyType]] \"datetime\".\r\n * @beta\r\n */\r\nexport interface DateTimeFieldFormatOptions {\r\n /** The locale with which to localize the display string.\r\n * Default: \"en-US\".\r\n */\r\n locale?: Intl.UnicodeBCP47LocaleIdentifier;\r\n /** Describes how to produce the display string. */\r\n formatOptions?: Intl.DateTimeFormatOptions;\r\n}\r\n\r\n/** Customizes how to format the raw property value resolved by a [[FieldPropertyPath]] into a [[FieldRun]]'s display string.\r\n * The exact options used depend upon the [[FieldPropertyType]].\r\n * @beta\r\n */\r\nexport interface FieldFormatOptions {\r\n /** A string inserted before the formatted string. This string is not affected by [[case]]. */\r\n prefix?: string;\r\n /** A string inserted after the formatted string. This string is not affected by [[case]]. */\r\n suffix?: string;\r\n /** Modifies the case of the formatted string. */\r\n case?: FieldCase;\r\n /** Formatting options for [[FieldPropertyType]] \"datetime\". */\r\n dateTime?: DateTimeFieldFormatOptions;\r\n}\r\n"]}
1
+ {"version":3,"file":"TextField.js","sourceRoot":"","sources":["../../../src/annotation/TextField.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG","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 Annotation\r\n */\r\n\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\n\r\n/** Enumerates the different kinds of [Property]($ecschema-metadata) values that can be used as the basis for a [[FieldRun]]'s display string.\r\n * A field's property type is derived from the property's [PrimitiveType]($ecschema-metadata) and other attributes like its [PrimitiveOrEnumPropertyBase.extendedTypeName]($ecschema-metadata).\r\n * The conversion of the raw property value into a display string can be customized by different [[FieldFormatOptions]] based on its type.\r\n * The following types are currently recognized:\r\n * - \"quantity\": an often-unitized scalar value like a distance or area, formatted using a quantity [Format]($core-quantity).\r\n * - \"coordinate\": a 2- or 3-dimensional point, with each component formatted as a \"quantity\".\r\n * - \"boolean\": a true or false value; currently converted via `toString()` (localized formatting not yet implemented).\r\n * - \"datetime\": an ECMAScript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date).\r\n * - \"int-enum\": an integer [EnumerationProperty]($ecschema-metadata); currently converted via `toString()` (display-label lookup not yet implemented).\r\n * - \"string-enum\": a string [EnumerationProperty]($ecschema-metadata); currently converted via `toString()` (display-label lookup not yet implemented).\r\n * - \"string\": a value convertible to a string.\r\n * @note `\"quantity\"` and `\"coordinate\"` values format through the quantity pipeline when a\r\n * [Format]($core-quantity) resolves for the field, from the FormatSets configured via\r\n * [ElementDrivesTextAnnotation.registerFieldFormatting]($backend) or from the iModel's schemas.\r\n * Otherwise they render as `value.toString()` — a bare number, or `(x, y[, z])` for a coordinate.\r\n * @beta\r\n */\r\nexport type FieldPropertyType = \"quantity\" | \"coordinate\" | \"string\" | \"boolean\" | \"datetime\" | \"int-enum\" | \"string-enum\";\r\n\r\n/** A chain of property accesses that resolves to a primitive value that forms the basis of the displayed content\r\n * of a [[FieldRun]].\r\n * The simplest property paths consist of a [[propertyName]] and nothing else, where `propertyName` identifies\r\n * a primitive property.\r\n * If `propertyName` identifies a struct or array property, then additional [[accessors]] are required to identify the specific value.\r\n * If `propertyName` (including any [[accessors]]) resolves to a string property of extended type `Json`, such as `JsonProperties`,\r\n * then additional [[jsonAccessors]] are required to identify a specific value within the serialized JSON.\r\n * Some examples:\r\n * ```\r\n * | Access String | propertyName | accessors | jsonAccessors |\r\n * | ------------- | ------------ | --------- | ------------- |\r\n * | name | \"name\" | undefined | undefined |\r\n * | spouse.name | \"spouse\" | [name] | undefined |\r\n * | colors[2] | \"colors\" | [2] | undefined |\r\n * | spouse.favoriteRestaurants[1].address | \"spouse\" | [\"favoriteRestaurants\", 1, \"address\"] | undefined |\r\n * | jsonProperties.contactInfo.email | \"jsonProperties\" | undefined | [\"contactInfo\", \"email\"] |\r\n * | spouse.jsonProperties.contactInfo.phoneNumbers[0].areaCode | \"spouse\" | [\"jsonProperties\"] | [\"contactInfo\", \"phoneNumbers\", 0, \"areaCode\"] |\r\n * ```\r\n * A path using `jsonAccessors` must end on a scalar (string, number, or boolean); a path that ends on an object, an array,\r\n * or a JSON `null` resolves to no value.\r\n *\r\n * For example, to display a value stored in an element's `JsonProperties`:\r\n * ```ts\r\n * [[include:TextFields_JsonAccessors]]\r\n * ```\r\n * Or, when the JSON property is reached through a struct member:\r\n * ```ts\r\n * [[include:TextFields_NestedJsonAccessors]]\r\n * ```\r\n * @beta\r\n */\r\nexport interface FieldPropertyPath {\r\n /** The name of the BIS property of the [[FieldPropertyHost]] that serves as the root of the path. */\r\n propertyName: string;\r\n /** Property names and/or array indices describing the path from [[propertyName]] to the ultimate BIS property. */\r\n accessors?: Array<string | number>;\r\n /** If [[propertyName]] and [[accessors]] (if defined) resolve to a BIS string property of extended type `Json`, property names and/or\r\n * array indices for selecting a primitive value within the JSON.\r\n */\r\n jsonAccessors?: Array<string | number>;\r\n}\r\n\r\n/** Describes the source of the property value against which a [[FieldPropertyPath]] is evaluated.\r\n * A field property is always hosted by an [Element]($backend). It may refer to a property belonging to any of the following:\r\n * - The element's BIS class itself;\r\n * - One of the element's [ElementAspect]($backend)s;\r\n * - Or an [EC view]($docs/learning/ECSqlReference/Views.md) with the same ECInstanceId as the element.\r\n * The [[schemaName]] and [[className]] should always identify the exact class that contains [[FieldPropertyPath.propertyName]] - not a subclass thereof.\r\n * @beta\r\n */\r\nexport interface FieldPropertyHost {\r\n /** The Id of the [Element]($backend) that hosts the property. */\r\n elementId: Id64String;\r\n /** The name of the schema containing the class identified by [[className]]. */\r\n schemaName: string;\r\n /** The name of the exact class (not a subclass) containing the property identified by [[FieldPropertyPath.propertyName]]. */\r\n className: string;\r\n}\r\n\r\n/** As part of a [[FieldFormatOptions]], specifies how to modify the case of the display string.\r\n * \"as-is\" leaves it unmodified. \"upper\" and \"lower\" convert it to all upper-case or all lower-case, respectively.\r\n * @beta\r\n */\r\nexport type FieldCase = \"as-is\" | \"upper\" | \"lower\";\r\n\r\n/** As part of a [[FieldFormatOptions]], specifies how to format properties of [[FieldPropertyType]] \"datetime\".\r\n * @beta\r\n */\r\nexport interface DateTimeFieldFormatOptions {\r\n /** The locale with which to localize the display string.\r\n * Default: \"en-US\".\r\n */\r\n locale?: Intl.UnicodeBCP47LocaleIdentifier;\r\n /** Describes how to produce the display string. */\r\n formatOptions?: Intl.DateTimeFormatOptions;\r\n}\r\n\r\n/** As part of a [[FieldFormatOptions]], specifies how to format [[FieldPropertyType]]\r\n * `\"quantity\"` or `\"coordinate\"` values.\r\n *\r\n * [[kindOfQuantity]] and [[persistenceUnit]] are independent overrides: setting one falls\r\n * through to the property for the other, and an empty string counts as unset. A name the iModel's\r\n * schemas define may use any case and either `Schema.Item` or `Schema:Item` spelling; a\r\n * KindOfQuantity defined only by a FormatSet must match its key exactly. A field that resolves\r\n * no format renders its raw value.\r\n *\r\n * These property names are also the persisted form — a [[FieldRun]] serializes them verbatim\r\n * into its element's `TextAnnotationData` — so applications can query for annotations carrying\r\n * quantity overrides by the literal strings `\"kindOfQuantity\"` and `\"persistenceUnit\"`.\r\n * @see [Quantity formatting for text annotation fields]($docs/learning/backend/TextAnnotationFields.md)\r\n * for the full resolution order.\r\n * @beta\r\n */\r\nexport interface QuantityFieldFormatOptions {\r\n /** Full name of a [Unit]($ecschema-metadata) (e.g. `\"Units.M\"`) the magnitude is expressed in,\r\n * for a property that has no persistence unit of its own — a coordinate, a plain `double`, or a\r\n * JSON leaf.\r\n *\r\n * Because this states what the value *means* rather than how it looks, the property's own\r\n * persistence unit is authoritative when it has one: a `persistenceUnit` that names a different\r\n * unit is ignored and a warning is logged.\r\n */\r\n persistenceUnit?: string;\r\n /** Full name of a [KindOfQuantity]($ecschema-metadata) (e.g. `\"AecUnits.LENGTH\"`) to format\r\n * through, overriding the property's own.\r\n */\r\n kindOfQuantity?: string;\r\n /** Identifier of a FormatSet whose formats take precedence for this field, letting one iModel\r\n * mix presentations such as metric and imperial callouts.\r\n *\r\n * Application-chosen, and matched against the ids supplied to\r\n * [ElementDrivesTextAnnotation.registerFieldFormatting]($backend); iTwin.js does not\r\n * resolve it against anything persisted in the iModel. A field naming an id that was never\r\n * supplied resolves as if it named none: through the iModel's adopted FormatSet, then the\r\n * schema presentation format.\r\n */\r\n formatSet?: string;\r\n}\r\n\r\n/** Customizes how to format the raw property value resolved by a [[FieldPropertyPath]] into a [[FieldRun]]'s display string.\r\n * The exact options used depend upon the [[FieldPropertyType]].\r\n * @beta\r\n */\r\nexport interface FieldFormatOptions {\r\n /** A string inserted before the formatted string. This string is not affected by [[case]]. */\r\n prefix?: string;\r\n /** A string inserted after the formatted string. This string is not affected by [[case]]. */\r\n suffix?: string;\r\n /** Modifies the case of the formatted string. */\r\n case?: FieldCase;\r\n /** Formatting options for [[FieldPropertyType]] \"datetime\". */\r\n dateTime?: DateTimeFieldFormatOptions;\r\n /** Formatting options for [[FieldPropertyType]] `\"quantity\"` and `\"coordinate\"`. */\r\n quantity?: QuantityFieldFormatOptions;\r\n}\r\n"]}
@@ -8,11 +8,40 @@ export type FieldPrimitiveValue = boolean | number | string | Date | XAndY | XYA
8
8
  * @internal
9
9
  */
10
10
  export interface FieldValue {
11
+ /** The raw property value, typed by [[type]]. For structured or array properties, this is
12
+ * the primitive scalar the [FieldRun]($common)'s propertyPath ultimately resolved to.
13
+ */
11
14
  value: FieldPrimitiveValue;
15
+ /** How [[value]] should be formatted; drives the per-type branch in [[formatFieldValue]]. */
12
16
  type: FieldPropertyType;
13
17
  }
14
- /** @internal */
15
- export declare function formatFieldValue(value: FieldValue, options: FieldFormatOptions | undefined): string | undefined;
16
- /** @internal */
18
+ /** Renders one magnitude of a `"quantity"` or `"coordinate"` value — typically by applying a
19
+ * [FormatterSpec]($core-quantity) the caller resolved ahead of time. Supplying one is what lets
20
+ * field evaluation stay synchronous on paths that cannot await.
21
+ * @internal
22
+ */
23
+ export type FormatMagnitude = (magnitude: number) => string;
24
+ /** Arguments supplied to [[formatFieldValue]].
25
+ * @internal
26
+ */
27
+ export interface FormatFieldValueArgs {
28
+ /** The resolved field value to render. */
29
+ value: FieldValue;
30
+ /** Prefix, suffix, case, and per-type options applied to the rendered string. */
31
+ options?: FieldFormatOptions;
32
+ /** Consulted only by the `"quantity"` and `"coordinate"` branches. */
33
+ formatMagnitude?: FormatMagnitude;
34
+ }
35
+ /** Formats `value` through the per-type entry in [[formatters]], wrapping the result with
36
+ * prefix/suffix/case.
37
+ *
38
+ * `formatMagnitude` is consulted only by the `"quantity"` and `"coordinate"` branches. Omitting
39
+ * it falls those values back to `value.toString()`.
40
+ * @internal
41
+ */
42
+ export declare function formatFieldValue({ value, options, formatMagnitude }: FormatFieldValueArgs): string | undefined;
43
+ /** Type guard for [[FieldPropertyType]] strings that have a built-in per-type formatter.
44
+ * @internal
45
+ */
17
46
  export declare function isKnownFieldPropertyType(type: string): type is FieldPropertyType;
18
47
  //# sourceMappingURL=FieldFormatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FieldFormatter.d.ts","sourceRoot":"","sources":["../../../../src/internal/annotations/FieldFormatter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAA8B,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/G;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,GAAG,UAA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GAAG,SAAS,CAG9G;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,iBAAiB,CAEhF"}
@@ -6,9 +6,8 @@ const formatters = {
6
6
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
7
7
  "string": (v, o) => formatString(v.toString(), o),
8
8
  "datetime": (v, o) => formatString(formatDateTime(v, o?.dateTime), o),
9
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
10
- "quantity": (v, o) => formatString(v.toString(), o),
11
- "coordinate": (v, o) => formatString(formatPointBasic(v), o),
9
+ "quantity": (v, o, fm) => formatString(formatMagnitudeValue(v, fm), o),
10
+ "coordinate": (v, o, fm) => formatString(formatPoint(v, fm), o),
12
11
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
13
12
  "boolean": (v, o) => formatString(v.toString(), o),
14
13
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
@@ -49,25 +48,56 @@ function formatDateTime(v, o) {
49
48
  }
50
49
  return undefined;
51
50
  }
52
- // ###TODO replace this with actual quantity coordinate formatting.
53
- function formatPointBasic(v) {
54
- if (typeof v === "object" && "x" in v && "y" in v) {
55
- const parts = [v.x, v.y];
56
- const z = v.z;
57
- if (undefined !== z) {
58
- parts.push(z);
59
- }
60
- return `(${parts.join(", ")})`;
51
+ /** A `"quantity"` magnitude rendered through `formatMagnitude`, or its raw string
52
+ * representation when no callback was supplied or the value is not a number.
53
+ */
54
+ function formatMagnitudeValue(v, formatMagnitude) {
55
+ if (formatMagnitude && typeof v === "number") {
56
+ return formatMagnitude(v);
61
57
  }
62
- return undefined;
58
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
59
+ return v.toString();
63
60
  }
64
- /** @internal */
65
- export function formatFieldValue(value, options) {
61
+ /** A coordinate rendered as `(x, y[, z])`, each component passed through `formatMagnitude` when
62
+ * one is supplied. Without a callback the components render bare, with no unit labels — Core
63
+ * carries no built-in coordinate format.
64
+ */
65
+ function formatPoint(v, formatMagnitude) {
66
+ const magnitudes = getCoordinateMagnitudes(v);
67
+ if (!magnitudes) {
68
+ return undefined;
69
+ }
70
+ return `(${magnitudes.map((m) => formatMagnitude ? formatMagnitude(m) : `${m}`).join(", ")})`;
71
+ }
72
+ /** Formats `value` through the per-type entry in [[formatters]], wrapping the result with
73
+ * prefix/suffix/case.
74
+ *
75
+ * `formatMagnitude` is consulted only by the `"quantity"` and `"coordinate"` branches. Omitting
76
+ * it falls those values back to `value.toString()`.
77
+ * @internal
78
+ */
79
+ export function formatFieldValue({ value, options, formatMagnitude }) {
66
80
  const formatter = formatters[value.type];
67
- return formatter ? formatter(value.value, options) : undefined;
81
+ return formatter ? formatter(value.value, options, formatMagnitude) : undefined;
68
82
  }
69
- /** @internal */
83
+ /** Type guard for [[FieldPropertyType]] strings that have a built-in per-type formatter.
84
+ * @internal
85
+ */
70
86
  export function isKnownFieldPropertyType(type) {
71
87
  return type in formatters;
72
88
  }
89
+ /** The `x`, `y` and (when present) `z` components of a coordinate value, or `undefined` if `v` is
90
+ * not one.
91
+ */
92
+ function getCoordinateMagnitudes(v) {
93
+ if (typeof v !== "object" || !("x" in v) || !("y" in v)) {
94
+ return undefined;
95
+ }
96
+ const parts = [v.x, v.y];
97
+ const z = "z" in v ? v.z : undefined;
98
+ if (undefined !== z) {
99
+ parts.push(z);
100
+ }
101
+ return parts;
102
+ }
73
103
  //# sourceMappingURL=FieldFormatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FieldFormatter.js","sourceRoot":"","sources":["../../../../src/internal/annotations/FieldFormatter.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAoB/F,MAAM,UAAU,GAAmD;IACjE,gEAAgE;IAChE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEjD,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,C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CAAC,GAAG,CAAC;IACjC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,OAAuC;IACzF,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,OAAO,IAAI,IAAI,UAAU,CAAC;AAC5B,CAAC","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\r\nimport { XAndY, XYAndZ } from \"@itwin/core-geometry\";\r\nimport { DateTimeFieldFormatOptions, FieldFormatOptions, FieldPropertyType } from \"../../annotation/TextField\";\r\n\r\n/** A FieldPropertyPath must ultimately resolve to one of these primitive types.\r\n * @internal\r\n */\r\nexport type FieldPrimitiveValue = boolean | number | string | Date | XAndY | XYAndZ | Uint8Array;\r\n\r\n/** Resolved value of a field.\r\n * @internal\r\n */\r\nexport interface FieldValue {\r\n value: FieldPrimitiveValue;\r\n type: FieldPropertyType;\r\n}\r\n\r\ntype FieldFormatter = (value: FieldPrimitiveValue, options: FieldFormatOptions | undefined) => string | undefined;\r\n\r\nconst formatters: { [type: string]: FieldFormatter | undefined } = {\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"string\": (v, o) => formatString(v.toString(), o),\r\n\r\n \"datetime\": (v, o) => formatString(formatDateTime(v, o?.dateTime), o),\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"quantity\": (v, o) => formatString(v.toString(), o),\r\n \r\n \"coordinate\": (v, o) => formatString(formatPointBasic(v), o),\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"boolean\": (v, o) => formatString(v.toString(), o),\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"int-enum\": (v, o) => formatString(v.toString(), o),\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"string-enum\": (v, o) => formatString(v.toString(), o),\r\n};\r\n\r\nfunction formatString(s: string | undefined, o?: FieldFormatOptions): string | undefined {\r\n if (undefined === s || !o) {\r\n return s;\r\n }\r\n\r\n switch (o.case) {\r\n case \"upper\":\r\n s = s.toUpperCase();\r\n break;\r\n case \"lower\":\r\n s = s.toLowerCase();\r\n break;\r\n }\r\n\r\n if (o.prefix || o.suffix) {\r\n s = `${o.prefix ?? \"\"}${s}${o.suffix ?? \"\"}`;\r\n }\r\n\r\n return s;\r\n}\r\n\r\nfunction formatDateTime(v: FieldPrimitiveValue, o?: DateTimeFieldFormatOptions): string | undefined {\r\n if (!(v instanceof Date))\r\n return undefined;\r\n\r\n if (!isNaN(v.getTime())) {\r\n if (o?.formatOptions) {\r\n const locale = o.locale ?? \"en-US\";\r\n if (!Intl.DateTimeFormat.supportedLocalesOf([locale], { localeMatcher: \"lookup\" }).includes(locale)) {\r\n return undefined;\r\n }\r\n\r\n const formatter = new Intl.DateTimeFormat(locale, o.formatOptions);\r\n return formatter.format(v);\r\n }\r\n return v.toString();\r\n }\r\n return undefined;\r\n}\r\n\r\n// ###TODO replace this with actual quantity coordinate formatting.\r\nfunction formatPointBasic(v: FieldPrimitiveValue): string | undefined {\r\n if (typeof v === \"object\" && \"x\" in v && \"y\" in v) {\r\n const parts = [v.x, v.y];\r\n const z = (v as any).z;\r\n if (undefined !== z) {\r\n parts.push(z);\r\n }\r\n\r\n return `(${parts.join(\", \")})`;\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\n/** @internal */\r\nexport function formatFieldValue(value: FieldValue, options: FieldFormatOptions | undefined): string | undefined {\r\n const formatter = formatters[value.type];\r\n return formatter ? formatter(value.value, options) : undefined;\r\n}\r\n\r\n/** @internal */\r\nexport function isKnownFieldPropertyType(type: string): type is FieldPropertyType {\r\n return type in formatters;\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"FieldFormatter.js","sourceRoot":"","sources":["../../../../src/internal/annotations/FieldFormatter.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AA+B/F,MAAM,UAAU,GAAmD;IACjE,gEAAgE;IAChE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEjD,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;IAErE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAEtE,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/D,gEAAgE;IAChE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClD,gEAAgE;IAChE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnD,gEAAgE;IAChE,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;CACvD,CAAC;AAEF,SAAS,YAAY,C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AI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC;QACxD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","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\r\nimport { XAndY, XYAndZ } from \"@itwin/core-geometry\";\r\nimport { DateTimeFieldFormatOptions, FieldFormatOptions, FieldPropertyType } from \"../../annotation/TextField\";\r\n\r\n/** A FieldPropertyPath must ultimately resolve to one of these primitive types.\r\n * @internal\r\n */\r\nexport type FieldPrimitiveValue = boolean | number | string | Date | XAndY | XYAndZ | Uint8Array;\r\n\r\n/** Resolved value of a field.\r\n * @internal\r\n */\r\nexport interface FieldValue {\r\n /** The raw property value, typed by [[type]]. For structured or array properties, this is\r\n * the primitive scalar the [FieldRun]($common)'s propertyPath ultimately resolved to.\r\n */\r\n value: FieldPrimitiveValue;\r\n /** How [[value]] should be formatted; drives the per-type branch in [[formatFieldValue]]. */\r\n type: FieldPropertyType;\r\n}\r\n\r\n/** Renders one magnitude of a `\"quantity\"` or `\"coordinate\"` value — typically by applying a\r\n * [FormatterSpec]($core-quantity) the caller resolved ahead of time. Supplying one is what lets\r\n * field evaluation stay synchronous on paths that cannot await.\r\n * @internal\r\n */\r\nexport type FormatMagnitude = (magnitude: number) => string;\r\n\r\ntype FieldFormatter = (value: FieldPrimitiveValue, options: FieldFormatOptions | undefined, formatMagnitude?: FormatMagnitude) => string | undefined;\r\n\r\nconst formatters: { [type: string]: FieldFormatter | undefined } = {\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"string\": (v, o) => formatString(v.toString(), o),\r\n\r\n \"datetime\": (v, o) => formatString(formatDateTime(v, o?.dateTime), o),\r\n\r\n \"quantity\": (v, o, fm) => formatString(formatMagnitudeValue(v, fm), o),\r\n\r\n \"coordinate\": (v, o, fm) => formatString(formatPoint(v, fm), o),\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"boolean\": (v, o) => formatString(v.toString(), o),\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"int-enum\": (v, o) => formatString(v.toString(), o),\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n \"string-enum\": (v, o) => formatString(v.toString(), o),\r\n};\r\n\r\nfunction formatString(s: string | undefined, o?: FieldFormatOptions): string | undefined {\r\n if (undefined === s || !o) {\r\n return s;\r\n }\r\n\r\n switch (o.case) {\r\n case \"upper\":\r\n s = s.toUpperCase();\r\n break;\r\n case \"lower\":\r\n s = s.toLowerCase();\r\n break;\r\n }\r\n\r\n if (o.prefix || o.suffix) {\r\n s = `${o.prefix ?? \"\"}${s}${o.suffix ?? \"\"}`;\r\n }\r\n\r\n return s;\r\n}\r\n\r\nfunction formatDateTime(v: FieldPrimitiveValue, o?: DateTimeFieldFormatOptions): string | undefined {\r\n if (!(v instanceof Date))\r\n return undefined;\r\n\r\n if (!isNaN(v.getTime())) {\r\n if (o?.formatOptions) {\r\n const locale = o.locale ?? \"en-US\";\r\n if (!Intl.DateTimeFormat.supportedLocalesOf([locale], { localeMatcher: \"lookup\" }).includes(locale)) {\r\n return undefined;\r\n }\r\n\r\n const formatter = new Intl.DateTimeFormat(locale, o.formatOptions);\r\n return formatter.format(v);\r\n }\r\n return v.toString();\r\n }\r\n return undefined;\r\n}\r\n\r\n/** A `\"quantity\"` magnitude rendered through `formatMagnitude`, or its raw string\r\n * representation when no callback was supplied or the value is not a number.\r\n */\r\nfunction formatMagnitudeValue(v: FieldPrimitiveValue, formatMagnitude?: FormatMagnitude): string | undefined {\r\n if (formatMagnitude && typeof v === \"number\") {\r\n return formatMagnitude(v);\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n return v.toString();\r\n}\r\n\r\n/** A coordinate rendered as `(x, y[, z])`, each component passed through `formatMagnitude` when\r\n * one is supplied. Without a callback the components render bare, with no unit labels — Core\r\n * carries no built-in coordinate format.\r\n */\r\nfunction formatPoint(v: FieldPrimitiveValue, formatMagnitude?: FormatMagnitude): string | undefined {\r\n const magnitudes = getCoordinateMagnitudes(v);\r\n if (!magnitudes) {\r\n return undefined;\r\n }\r\n\r\n return `(${magnitudes.map((m) => formatMagnitude ? formatMagnitude(m) : `${m}`).join(\", \")})`;\r\n}\r\n\r\n/** Arguments supplied to [[formatFieldValue]].\r\n * @internal\r\n */\r\nexport interface FormatFieldValueArgs {\r\n /** The resolved field value to render. */\r\n value: FieldValue;\r\n /** Prefix, suffix, case, and per-type options applied to the rendered string. */\r\n options?: FieldFormatOptions;\r\n /** Consulted only by the `\"quantity\"` and `\"coordinate\"` branches. */\r\n formatMagnitude?: FormatMagnitude;\r\n}\r\n\r\n/** Formats `value` through the per-type entry in [[formatters]], wrapping the result with\r\n * prefix/suffix/case.\r\n *\r\n * `formatMagnitude` is consulted only by the `\"quantity\"` and `\"coordinate\"` branches. Omitting\r\n * it falls those values back to `value.toString()`.\r\n * @internal\r\n */\r\nexport function formatFieldValue({ value, options, formatMagnitude }: FormatFieldValueArgs): string | undefined {\r\n const formatter = formatters[value.type];\r\n return formatter ? formatter(value.value, options, formatMagnitude) : undefined;\r\n}\r\n\r\n/** Type guard for [[FieldPropertyType]] strings that have a built-in per-type formatter.\r\n * @internal\r\n */\r\nexport function isKnownFieldPropertyType(type: string): type is FieldPropertyType {\r\n return type in formatters;\r\n}\r\n\r\n/** The `x`, `y` and (when present) `z` components of a coordinate value, or `undefined` if `v` is\r\n * not one.\r\n */\r\nfunction getCoordinateMagnitudes(v: FieldPrimitiveValue): number[] | undefined {\r\n if (typeof v !== \"object\" || !(\"x\" in v) || !(\"y\" in v)) {\r\n return undefined;\r\n }\r\n const parts = [v.x, v.y];\r\n const z = \"z\" in v ? v.z : undefined;\r\n if (undefined !== z) {\r\n parts.push(z);\r\n }\r\n return parts;\r\n}\r\n"]}
@@ -4,5 +4,5 @@ export { MultiModelPackedFeatureTable, PackedFeatureModelTable, PackedFeatureTab
4
4
  export type { BackendReadable, BackendWritable, BackendBuffer } from "./BackendTypes";
5
5
  export { RenderMaterialParams } from "./RenderMaterialParams";
6
6
  export { RenderTextureParams } from "./RenderTextureParams";
7
- export { type FieldPrimitiveValue, type FieldValue, formatFieldValue, isKnownFieldPropertyType } from "./annotations/FieldFormatter";
7
+ export { type FieldPrimitiveValue, type FieldValue, type FormatFieldValueArgs, type FormatMagnitude, formatFieldValue, isKnownFieldPropertyType } from "./annotations/FieldFormatter";
8
8
  //# sourceMappingURL=cross-package.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cross-package.d.ts","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EACL,KAAK,uBAAuB,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EACvI,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAAE,uBAAuB,EAAE,kBAAkB,EAC1E,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"cross-package.d.ts","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EACL,KAAK,uBAAuB,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EACvI,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAAE,uBAAuB,EAAE,kBAAkB,EAC1E,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,KAAK,oBAAoB,EAAE,KAAK,eAAe,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"cross-package.js","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAG/F,OAAO,EACyB,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAyB,gBAAgB,EAAE,kBAAkB,EACvI,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAAE,uBAAuB,EAAE,kBAAkB,EAC1E,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAA6C,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC","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\r\nexport type { DecorationGeometryProps, SnapRequestProps, SnapResponseProps } from \"./Snapping\";\r\nexport {\r\n type EdgeAppearanceOverrides, EdgeArgs, MeshEdge, MeshEdges, MeshPolyline, type MeshPolylineList, PolylineEdgeArgs, SilhouetteEdgeArgs\r\n} from \"./RenderMesh\";\r\nexport {\r\n MultiModelPackedFeatureTable, PackedFeatureModelTable, PackedFeatureTable\r\n} from \"./PackedFeatureTable\";\r\n// eslint-disable-next-line @typescript-eslint/no-deprecated\r\nexport type { BackendReadable, BackendWritable, BackendBuffer } from \"./BackendTypes\";\r\nexport { RenderMaterialParams } from \"./RenderMaterialParams\";\r\nexport { RenderTextureParams } from \"./RenderTextureParams\";\r\nexport { type FieldPrimitiveValue, type FieldValue, formatFieldValue, isKnownFieldPropertyType } from \"./annotations/FieldFormatter\";\r\n"]}
1
+ {"version":3,"file":"cross-package.js","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAG/F,OAAO,EACyB,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAyB,gBAAgB,EAAE,kBAAkB,EACvI,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAAE,uBAAuB,EAAE,kBAAkB,EAC1E,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAA8F,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC","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\r\nexport type { DecorationGeometryProps, SnapRequestProps, SnapResponseProps } from \"./Snapping\";\r\nexport {\r\n type EdgeAppearanceOverrides, EdgeArgs, MeshEdge, MeshEdges, MeshPolyline, type MeshPolylineList, PolylineEdgeArgs, SilhouetteEdgeArgs\r\n} from \"./RenderMesh\";\r\nexport {\r\n MultiModelPackedFeatureTable, PackedFeatureModelTable, PackedFeatureTable\r\n} from \"./PackedFeatureTable\";\r\n// eslint-disable-next-line @typescript-eslint/no-deprecated\r\nexport type { BackendReadable, BackendWritable, BackendBuffer } from \"./BackendTypes\";\r\nexport { RenderMaterialParams } from \"./RenderMaterialParams\";\r\nexport { RenderTextureParams } from \"./RenderTextureParams\";\r\nexport { type FieldPrimitiveValue, type FieldValue, type FormatFieldValueArgs, type FormatMagnitude, formatFieldValue, isKnownFieldPropertyType } from \"./annotations/FieldFormatter\";\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-common",
3
- "version": "5.14.0-dev.22",
3
+ "version": "5.14.0-dev.23",
4
4
  "description": "iTwin.js components common to frontend and backend",
5
5
  "main": "lib/cjs/core-common.js",
6
6
  "module": "lib/esm/core-common.js",
@@ -27,8 +27,8 @@
27
27
  "js-base64": "^3.6.1"
28
28
  },
29
29
  "peerDependencies": {
30
- "@itwin/core-bentley": "5.14.0-dev.22",
31
- "@itwin/core-geometry": "5.14.0-dev.22"
30
+ "@itwin/core-bentley": "5.14.0-dev.23",
31
+ "@itwin/core-geometry": "5.14.0-dev.23"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@itwin/eslint-plugin": "^6.0.0",
@@ -40,9 +40,9 @@
40
40
  "rimraf": "^6.0.1",
41
41
  "typescript": "~5.6.2",
42
42
  "vitest": "^4.1.10",
43
- "@itwin/build-tools": "5.14.0-dev.22",
44
- "@itwin/core-bentley": "5.14.0-dev.22",
45
- "@itwin/core-geometry": "5.14.0-dev.22"
43
+ "@itwin/core-bentley": "5.14.0-dev.23",
44
+ "@itwin/build-tools": "5.14.0-dev.23",
45
+ "@itwin/core-geometry": "5.14.0-dev.23"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "npm run -s build:cjs && npm run -s build:esm",