react-native-nitro-input 0.3.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/README.md +9 -4
  3. package/android/CMakeLists.txt +1 -0
  4. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputMeasure.kt +52 -0
  5. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +74 -80
  6. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +18 -18
  7. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +14 -14
  8. package/android/src/main/java/com/margelo/nitro/nitroinput/InputFonts.kt +199 -0
  9. package/android/src/main/java/com/margelo/nitro/nitroinput/InputSizing.kt +398 -0
  10. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +112 -333
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +178 -30
  12. package/cpp/RollingEngine.cpp +68 -5
  13. package/cpp/RollingEngine.hpp +13 -0
  14. package/cpp/numberformat/FormatFigure.cpp +134 -0
  15. package/cpp/numberformat/FormatFigure.hpp +65 -0
  16. package/cpp/numberformat/HybridNitroNumberFormat.cpp +32 -10
  17. package/cpp/numberformat/HybridNitroNumberFormat.hpp +9 -1
  18. package/ios/HybridNitroInputView.swift +69 -75
  19. package/ios/HybridNitroNumberView.swift +18 -18
  20. package/ios/HybridNitroTextView.swift +14 -14
  21. package/ios/InputSizing.swift +534 -0
  22. package/ios/NitroInputView.swift +102 -198
  23. package/ios/NitroNumberView.swift +98 -23
  24. package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  25. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  26. package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  27. package/lib/commonjs/src/NitroInput.js +164 -23
  28. package/lib/commonjs/src/NitroNumber.js +19 -11
  29. package/lib/commonjs/src/NitroText.js +6 -6
  30. package/lib/commonjs/src/NumberFormat.js +20 -0
  31. package/lib/commonjs/src/formatProps.js +57 -81
  32. package/lib/commonjs/src/specs/NitroInputMeasure.nitro.js +2 -0
  33. package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  34. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  35. package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  36. package/lib/module/src/NitroInput.js +165 -24
  37. package/lib/module/src/NitroNumber.js +20 -12
  38. package/lib/module/src/NitroText.js +6 -6
  39. package/lib/module/src/NumberFormat.js +18 -0
  40. package/lib/module/src/formatProps.js +54 -81
  41. package/lib/module/src/specs/NitroInputMeasure.nitro.js +1 -0
  42. package/lib/typescript/src/NitroInput.d.ts +9 -16
  43. package/lib/typescript/src/NitroNumber.d.ts +25 -7
  44. package/lib/typescript/src/NumberFormat.d.ts +15 -1
  45. package/lib/typescript/src/formatProps.d.ts +23 -18
  46. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +17 -8
  47. package/lib/typescript/src/specs/NitroInputMeasure.nitro.d.ts +67 -0
  48. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +6 -6
  49. package/lib/typescript/src/specs/NitroText.nitro.d.ts +6 -6
  50. package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +33 -0
  51. package/nitro.json +10 -0
  52. package/nitrogen/generated/android/NitroInput+autolinking.cmake +2 -0
  53. package/nitrogen/generated/android/NitroInputOnLoad.cpp +16 -0
  54. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.cpp +93 -0
  55. package/nitrogen/generated/android/c++/JHybridNitroInputMeasureSpec.hpp +63 -0
  56. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +76 -40
  57. package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +24 -16
  58. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +30 -30
  59. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +12 -12
  60. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +30 -30
  61. package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +12 -12
  62. package/nitrogen/generated/android/c++/JNitroInputSize.hpp +61 -0
  63. package/nitrogen/generated/android/c++/JNitroInputSizing.hpp +284 -0
  64. package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +44 -24
  65. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +18 -18
  66. package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +18 -18
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputMeasureSpec.kt +56 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +32 -8
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +6 -6
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +6 -6
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSize.kt +56 -0
  72. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputSizing.kt +246 -0
  73. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +17 -0
  74. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +29 -0
  75. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +11 -0
  76. package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
  77. package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
  78. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.cpp +11 -0
  79. package/nitrogen/generated/ios/c++/HybridNitroInputMeasureSpecSwift.hpp +112 -0
  80. package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +56 -32
  81. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +24 -24
  82. package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +24 -24
  83. package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +56 -32
  84. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +24 -24
  85. package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +24 -24
  86. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec.swift +55 -0
  87. package/nitrogen/generated/ios/swift/HybridNitroInputMeasureSpec_cxx.swift +138 -0
  88. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +12 -8
  89. package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +68 -24
  90. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +6 -6
  91. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +18 -18
  92. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +6 -6
  93. package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +18 -18
  94. package/nitrogen/generated/ios/swift/NitroInputSize.swift +34 -0
  95. package/nitrogen/generated/ios/swift/NitroInputSizing.swift +242 -0
  96. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.cpp +21 -0
  97. package/nitrogen/generated/shared/c++/HybridNitroInputMeasureSpec.hpp +66 -0
  98. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +24 -16
  99. package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +24 -16
  100. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.cpp +2 -0
  101. package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.hpp +8 -0
  102. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +12 -12
  103. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +12 -12
  104. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +12 -12
  105. package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +12 -12
  106. package/nitrogen/generated/shared/c++/NitroInputSize.hpp +87 -0
  107. package/nitrogen/generated/shared/c++/NitroInputSizing.hpp +263 -0
  108. package/nitrogen/generated/shared/c++/NumberFigure.hpp +95 -0
  109. package/nitrogen/generated/shared/c++/NumberFormatLayout.hpp +112 -0
  110. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +24 -16
  111. package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +36 -24
  112. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +12 -12
  113. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +18 -18
  114. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +12 -12
  115. package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +18 -18
  116. package/nitrogen/generated/shared/json/NitroInputViewConfig.json +12 -8
  117. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +6 -6
  118. package/nitrogen/generated/shared/json/NitroTextViewConfig.json +6 -6
  119. package/package.json +5 -3
  120. package/src/NitroInput.tsx +201 -64
  121. package/src/NitroNumber.tsx +54 -25
  122. package/src/NitroText.tsx +6 -6
  123. package/src/NumberFormat.ts +22 -0
  124. package/src/formatProps.ts +59 -99
  125. package/src/specs/NitroInput.nitro.ts +17 -8
  126. package/src/specs/NitroInputMeasure.nitro.ts +76 -0
  127. package/src/specs/NitroNumber.nitro.ts +6 -6
  128. package/src/specs/NitroText.nitro.ts +6 -6
  129. package/src/specs/NumberFormat.nitro.ts +35 -0
package/src/NitroText.tsx CHANGED
@@ -134,13 +134,13 @@ export function NitroText({
134
134
  const native: NativeNitroTextProps & Record<string, unknown> = viewProps as never
135
135
  native.text = text
136
136
  native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style]
137
- if (size !== 17) native.fontSize = size
138
- if (weight !== 400) native.fontWeight = weight
139
- if (family !== '') native.fontFamily = family
140
- if (spacing !== 0) native.letterSpacing = spacing
137
+ if (size !== 17) native.textSize = size
138
+ if (weight !== 400) native.textWeight = weight
139
+ if (family !== '') native.textFamily = family
140
+ if (spacing !== 0) native.textLetterSpacing = spacing
141
141
  const processedColor = toProcessedColor(color)
142
- if (processedColor !== undefined) native.color = processedColor
143
- if (textAlign !== undefined) native.textAlign = textAlign
142
+ if (processedColor !== undefined) native.textColor = processedColor
143
+ if (textAlign !== undefined) native.textAlignment = textAlign
144
144
  if (duration !== undefined) native.duration = duration
145
145
  if (easing !== undefined) native.easing = easing
146
146
  if (bounce !== undefined) native.bounce = bounce
@@ -2,6 +2,8 @@ import { NitroModules } from 'react-native-nitro-modules'
2
2
  import type {
3
3
  NitroNumberFormat,
4
4
  NitroNumberFormatFactory,
5
+ NumberFigure,
6
+ NumberFormatLayout,
5
7
  NumberFormatOptions,
6
8
  NumberFormatPart,
7
9
  ResolvedNumberFormatOptions,
@@ -390,6 +392,26 @@ export function sharedFormatterOf(value: unknown): object | undefined {
390
392
  return typeof value === 'object' && value !== null ? slots.get(value)?.native : undefined
391
393
  }
392
394
 
395
+ /**
396
+ * What `format` shows for `value`, as `NitroNumber` rolls it: the figure
397
+ * rounded and trimmed as the format prints it, and the text around it. Read
398
+ * in C++ off the formatter's own parts, from the number, bigint or decimal
399
+ * string itself.
400
+ * @internal
401
+ */
402
+ export function figureOf(format: NumberFormat, value: number | bigint | string): NumberFigure {
403
+ return nativeOf(format, 'figure').figure(toMathematicalValue(value))
404
+ }
405
+
406
+ /**
407
+ * The prefix, suffix, separators, sign placement, grouping and digits of
408
+ * `format`, read in C++ off its parts.
409
+ * @internal
410
+ */
411
+ export function layoutOf(format: NumberFormat): NumberFormatLayout {
412
+ return nativeOf(format, 'layout').layout()
413
+ }
414
+
393
415
  // `length` is 0 as the specification says: the arguments are read from `arguments`.
394
416
  function NumberFormatConstructor(this: unknown): unknown {
395
417
  const locales = arguments[0]
@@ -1,4 +1,6 @@
1
- import { NumberFormat, sharedFormatterOf } from './NumberFormat'
1
+ import { layoutOf, sharedFormatterOf, type NumberFormat } from './NumberFormat'
2
+
3
+ export { figureOf } from './NumberFormat'
2
4
 
3
5
  /** What `NitroNumber` and `NitroInput` take from a `NumberFormat` through their `format` prop. */
4
6
  export interface FormatProps {
@@ -6,7 +8,11 @@ export interface FormatProps {
6
8
  suffix: string
7
9
  groupingSeparator: string
8
10
  decimalSeparator: string
9
- /** The digits after the decimal separator: the format's maximum. */
11
+ /**
12
+ * The digits after the decimal separator: the format's maximum. What one
13
+ * value shows can be fewer (`trailingZeroDisplay`, a minimum below the
14
+ * maximum): `figureOf` says per value.
15
+ */
10
16
  fractionDigits: number
11
17
  minimumIntegerDigits: number
12
18
  /** Whether a negative amount's sign comes before the prefix ("-$5") or after it ("$-5"). */
@@ -21,47 +27,17 @@ export interface FormatProps {
21
27
  digitGlyphs: string[]
22
28
  /** The first digit group and every later one, from the decimal point ([3, 2]: 12,34,567). */
23
29
  groupingSizes: number[]
24
- /** Compact notation: the prefix, suffix and digits follow the value (`compactParts`). */
30
+ /** Compact notation: the prefix, suffix and digits follow the value (`figureOf`). */
25
31
  compact: boolean
26
32
  }
27
33
 
28
- const NUMBER_PARTS = new Set(['integer', 'group', 'decimal', 'fraction'])
29
34
  // By the native formatter, which instances built with the same locales and options share.
30
35
  const cache = new WeakMap<object, FormatProps>()
31
36
 
32
- type Part = { type: string; value: string }
33
-
34
- function join(parts: Part[], from: number, to: number): string {
35
- return parts
36
- .slice(from, to)
37
- .map((p) => p.value)
38
- .join('')
39
- }
40
-
41
- /** The text before and after the number in `parts`. */
42
- function affixes(parts: Part[]): { prefix: string; suffix: string } {
43
- const first = parts.findIndex((p) => NUMBER_PARTS.has(p.type))
44
- let last = first
45
- parts.forEach((p, i) => {
46
- if (NUMBER_PARTS.has(p.type)) last = i
47
- })
48
- // The sign is the component's own glyph, not part of an affix.
49
- const unsigned = (from: number, to: number) =>
50
- join(
51
- parts.map((p) => (p.type === 'minusSign' || p.type === 'plusSign' ? { ...p, value: '' } : p)),
52
- from,
53
- to
54
- )
55
- return {
56
- prefix: first < 0 ? '' : unsigned(0, first),
57
- suffix: first < 0 ? '' : unsigned(last + 1, parts.length),
58
- }
59
- }
60
-
61
37
  /**
62
- * The prefix, suffix, separators and digit counts of `format`, read off its
63
- * parts once and cached per formatter. The components keep their own model
64
- * (a sign, a prefix, digits in groups, a suffix), so a format outside it
38
+ * The prefix, suffix, separators and digit counts of `format`, read in C++
39
+ * off its parts once and cached per formatter. The components keep their own
40
+ * model (a sign, a prefix, digits in groups, a suffix), so a format outside it
65
41
  * (accounting parentheses, a unit between the digits) is followed as far as
66
42
  * that model goes.
67
43
  */
@@ -70,80 +46,64 @@ export function formatProps(format: NumberFormat): FormatProps {
70
46
  const cached = cache.get(key)
71
47
  if (cached) return cached
72
48
  const resolved = format.resolvedOptions()
73
- const compact = resolved.notation === 'compact'
74
- const fractionDigits = resolved.maximumFractionDigits ?? 0
75
- // A value with every part: groups, and a fraction when the format has one.
76
- // Compact notation would print it "1.2M", so its affixes come per value.
77
- const parts = format.formatToParts(compact ? 1 : fractionDigits > 0 ? 1234567.5 : 1234567) as Part[]
78
- const negative = format.formatToParts(-1) as Part[]
79
- const minus = negative.findIndex((p) => p.type === 'minusSign')
80
- const currency = negative.findIndex((p) => p.type === 'currency' || p.type === 'percentSign')
81
- const integers = parts.filter((p) => p.type === 'integer').map((p) => p.value.length)
49
+ const layout = layoutOf(format)
82
50
  const props: FormatProps = {
83
- ...affixes(parts),
84
- groupingSeparator: parts.find((p) => p.type === 'group')?.value ?? '',
85
- decimalSeparator: parts.find((p) => p.type === 'decimal')?.value ?? '.',
86
- fractionDigits,
51
+ prefix: layout.prefix,
52
+ suffix: layout.suffix,
53
+ groupingSeparator: layout.groupingSeparator,
54
+ decimalSeparator: layout.decimalSeparator,
55
+ fractionDigits: resolved.maximumFractionDigits ?? 0,
87
56
  minimumIntegerDigits: resolved.minimumIntegerDigits,
88
- signPlacement: minus >= 0 && currency >= 0 && minus > currency ? 'afterAffix' : 'beforeAffix',
57
+ signPlacement: layout.signAfterAffix ? 'afterAffix' : 'beforeAffix',
89
58
  signDisplay: (resolved.signDisplay ?? 'auto') as FormatProps['signDisplay'],
90
- minusSign: negative[minus]?.value ?? '-',
59
+ minusSign: layout.minusSign,
91
60
  plusSign: '+',
92
- digitGlyphs: digitGlyphsOf(resolved.locale, resolved.numberingSystem),
93
- // "12,34,567": the last group is the first size, the one before it every later one.
94
- groupingSizes: integers.length >= 3 ? [integers[integers.length - 1]!, integers[integers.length - 2]!] : [3],
95
- compact,
61
+ digitGlyphs: layout.digitGlyphs,
62
+ groupingSizes: layout.groupingSizes,
63
+ compact: resolved.notation === 'compact',
96
64
  }
97
65
  cache.set(key, props)
98
66
  return props
99
67
  }
100
68
 
101
- const digitGlyphCache = new Map<string, string[]>()
102
-
103
- /** The ten digits of a numbering system, or [] for Latin ones. */
104
- function digitGlyphsOf(locale: string, numberingSystem: string | undefined): string[] {
105
- if (!numberingSystem || numberingSystem === 'latn') return []
106
- const cached = digitGlyphCache.get(numberingSystem)
107
- if (cached) return cached
108
- const digits = new NumberFormat(locale, { numberingSystem, useGrouping: false })
109
- const glyphs = Array.from({ length: 10 }, (_, d) => digits.format(d))
110
- const result = glyphs.every((g, d) => g === String(d)) ? [] : glyphs
111
- digitGlyphCache.set(numberingSystem, result)
112
- return result
113
- }
114
-
115
- /** What a compact format shows for one value: the figure to roll and the text around it. */
116
- export interface CompactParts {
117
- /** The figure as the digits show it: 1.2 for "1.2K". */
118
- value: number
119
- fractionDigits: number
120
- prefix: string
121
- suffix: string
122
- }
69
+ /** A value as `NumberFormat` takes it: a number, a bigint or a decimal string. */
70
+ export type NumericInput = number | bigint | string
123
71
 
124
72
  /**
125
- * Compact notation's parts for `value`: "1.2K" is the figure 1.2 with the
126
- * suffix "K", so the digits roll and the suffix swaps as the value crosses
127
- * a thousand, a million…
73
+ * `value` read in units of 10^-`minorDigits`, exactly: 123456n with 2 minor
74
+ * digits is "1234.56". A bigint or a numeric string is shifted as text, so no
75
+ * digit goes through a double: a decimal ("1234.5"), one with an exponent
76
+ * ("1e5" becomes "1e3"), or a 0x / 0o / 0b integer, as `Intl.NumberFormat`
77
+ * reads strings. A number that is a safe integer is shifted the same way, any
78
+ * other number is divided. A string that is not a number ("1,234.56") comes
79
+ * back as it is, which the format shows as NaN, never as a wrong amount.
128
80
  */
129
- export function compactParts(format: NumberFormat, value: number): CompactParts {
130
- const parts = format.formatToParts(value) as Part[]
131
- const props = formatProps(format)
132
- const latin = (text: string) =>
133
- props.digitGlyphs.length === 10
134
- ? Array.from(text)
135
- .map((c) => {
136
- const d = props.digitGlyphs.indexOf(c)
137
- return d >= 0 ? String(d) : c
138
- })
139
- .join('')
140
- : text
141
- const integer = latin(parts.filter((p) => p.type === 'integer').map((p) => p.value).join(''))
142
- const fraction = latin(parts.filter((p) => p.type === 'fraction').map((p) => p.value).join(''))
143
- const magnitude = Number(fraction ? `${integer}.${fraction}` : integer)
144
- return {
145
- value: (value < 0 ? -1 : 1) * (Number.isFinite(magnitude) ? magnitude : 0),
146
- fractionDigits: fraction.length,
147
- ...affixes(parts),
81
+ export function withMinorDigits(value: NumericInput, minorDigits: number | undefined): NumericInput {
82
+ const digits = minorDigits === undefined ? 0 : Math.max(0, Math.trunc(minorDigits))
83
+ if (digits === 0) return value
84
+ if (typeof value === 'number') {
85
+ if (!Number.isSafeInteger(value)) return value / 10 ** digits
86
+ value = BigInt(value)
148
87
  }
88
+ let text = typeof value === 'bigint' ? value.toString() : value.trim()
89
+ if (/^0[xob][0-9a-f]+$/i.test(text)) {
90
+ // A non-decimal integer: BigInt reads it as Intl does, exactly.
91
+ text = BigInt(text).toString()
92
+ }
93
+ const match = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(text)
94
+ if (!match || (match[2] === '' && match[3] === undefined && text !== '')) return value
95
+ const [, sign = '', whole = '', fraction = '', exponent] = match
96
+ if (whole === '' && fraction === '' && text.includes('.')) return value
97
+ if (exponent !== undefined) {
98
+ // Moving the point is moving the exponent.
99
+ return `${sign}${whole}${fraction ? `.${fraction}` : ''}e${Number(exponent) - digits}`
100
+ }
101
+ const all = (whole + fraction).padStart(digits + fraction.length + 1, '0')
102
+ const point = all.length - fraction.length - digits
103
+ return `${sign}${all.slice(0, point)}.${all.slice(point)}`
104
+ }
105
+
106
+ /** `value` as a double, for comparisons and for the engine when there is no format. */
107
+ export function toNumber(value: NumericInput): number {
108
+ return typeof value === 'number' ? value : Number(value)
149
109
  }
@@ -267,7 +267,7 @@ export interface NitroInputProps extends HybridViewProps {
267
267
  /** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
268
268
  suffixAlign: NitroInputAffixAlign
269
269
  /** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. */
270
- letterSpacing: number
270
+ textLetterSpacing: number
271
271
  /** Points between the prefix and the text, in place of the letter spacing there. Not finite: the letter spacing. */
272
272
  prefixSpacing: number
273
273
  /** Points between the text and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -289,7 +289,7 @@ export interface NitroInputProps extends HybridViewProps {
289
289
  /** How characters enter and leave. Default: `'auto'`. */
290
290
  effect: NitroInputEffect
291
291
  /** Font size of the text in points. Default: `32`. */
292
- fontSize: number
292
+ textSize: number
293
293
  /**
294
294
  * Height of the line box in points — the CSS meaning: the total height a
295
295
  * line occupies, not extra leading. `0` (the default) uses the font's own.
@@ -302,15 +302,15 @@ export interface NitroInputProps extends HybridViewProps {
302
302
  * `lineHeight < font.lineHeight`), and the reason a compressed `lineHeight`
303
303
  * renders off-centre on a `TextInput`.
304
304
  */
305
- lineHeight: number
305
+ textLineHeight: number
306
306
  /** Numeric font weight, `100`–`900`. Default: `400`. */
307
- fontWeight: number
307
+ textWeight: number
308
308
  /** Font family name; empty = system font. */
309
- fontFamily: string
309
+ textFamily: string
310
310
  /** Text color as a processed ARGB integer; `NaN` = platform label color. */
311
- color: number
311
+ textColor: number
312
312
  /** Where the text sits when the view is wider than it. Default: `'auto'`, the start edge. */
313
- textAlign: NitroInputTextAlign
313
+ textAlignment: NitroInputTextAlign
314
314
  /**
315
315
  * Lay the field out right-to-left: `'auto'` alignment resolves to the right
316
316
  * edge, the prefix moves to the right and the suffix to the left, and a
@@ -361,7 +361,16 @@ export interface NitroInputProps extends HybridViewProps {
361
361
  */
362
362
  numberOfLines: number
363
363
  /** `multiline`: where the text sits in the box. Default: `'auto'` (top). */
364
- textAlignVertical: NitroInputTextAlignVertical
364
+ textVerticalAlignment: NitroInputTextAlignVertical
365
+ /**
366
+ * The style's padding and border, in points, resolved per edge by
367
+ * `NitroInput`. Android insets the text, the overlay and the frame by them;
368
+ * on iOS React Native already lays the view's content out inside them.
369
+ */
370
+ textInsetLeft: number
371
+ textInsetTop: number
372
+ textInsetRight: number
373
+ textInsetBottom: number
365
374
  /**
366
375
  * `multiline`: whether the field scrolls once the text is taller than it.
367
376
  * Turning it off lets a growing field drive its own height. Default: `true`.
@@ -0,0 +1,76 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules'
2
+ import type {
3
+ NitroInputCharacterMapping,
4
+ NitroInputLabelBehavior,
5
+ NitroInputMaskAffinity,
6
+ NitroInputMode,
7
+ NitroInputNotation,
8
+ NitroInputSignPlacement,
9
+ NitroInputTextCase,
10
+ NitroInputVariant,
11
+ } from './NitroInput.nitro'
12
+
13
+ /**
14
+ * What a field's size follows: the subset of `NitroInputProps` the
15
+ * native views read when they report `onSizeChange`, under the same names and
16
+ * already resolved the same way by `NitroInput`.
17
+ */
18
+ export interface NitroInputSizing {
19
+ text: string
20
+ mode: NitroInputMode
21
+ plain: boolean
22
+ multiline: boolean
23
+ secureTextEntry: boolean
24
+ maxLength: number
25
+ fractionDigits: number
26
+ maxIntegerDigits: number
27
+ groupingSeparator: string
28
+ decimalSeparator: string
29
+ prefix: string
30
+ suffix: string
31
+ signPlacement: NitroInputSignPlacement
32
+ placeholder: string
33
+ mask: string
34
+ maskNotations: NitroInputNotation[]
35
+ maskAutocomplete: boolean
36
+ maskAutoSkip: boolean
37
+ maskAffinityFormats: string[]
38
+ maskAffinityStrategy: NitroInputMaskAffinity
39
+ maskTextCase: NitroInputTextCase
40
+ maskCharacterMap: NitroInputCharacterMapping[]
41
+ maskSlotPlaceholder: string
42
+ keepPlaceholder: boolean
43
+ textSize: number
44
+ textLineHeight: number
45
+ prefixFontSize: number
46
+ suffixFontSize: number
47
+ textWeight: number
48
+ textFamily: string
49
+ textLetterSpacing: number
50
+ prefixSpacing: number
51
+ suffixSpacing: number
52
+ allowFontScaling: boolean
53
+ maxFontSizeMultiplier: number
54
+ variant: NitroInputVariant
55
+ label: string
56
+ labelBehavior: NitroInputLabelBehavior
57
+ labelFontSize: number
58
+ cornerRadius: number
59
+ }
60
+
61
+ /** A size in points (iOS) or dp (Android). */
62
+ export interface NitroInputSize {
63
+ width: number
64
+ height: number
65
+ }
66
+
67
+ /**
68
+ * Measures a single-line field on the JS thread, before its view exists, with
69
+ * the code the view sizes itself with: `NitroInput` lays out at its real size
70
+ * in the commit that mounts it, as React Native's `TextInput` does, instead of
71
+ * at its parent's width until the view's first `onSizeChange` arrives.
72
+ */
73
+ export interface NitroInputMeasure extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
74
+ /** What the field reports through `onSizeChange` once mounted, unfocused. */
75
+ measure(sizing: NitroInputSizing): NitroInputSize
76
+ }
@@ -196,7 +196,7 @@ export interface NitroNumberProps extends HybridViewProps {
196
196
  /** A pause after each sweep, in ms. Default: `0`. */
197
197
  shimmerDelay?: number
198
198
  /** Font size of the digits in points. Default: `32`. */
199
- fontSize?: number
199
+ textSize?: number
200
200
  /** Font size of `prefix` in points. Defaults to `fontSize`. */
201
201
  prefixFontSize?: number
202
202
  /** Font size of `suffix` in points. Defaults to `fontSize`. */
@@ -208,7 +208,7 @@ export interface NitroNumberProps extends HybridViewProps {
208
208
  /** Vertical alignment of `suffix` only. Defaults to `affixAlign`. */
209
209
  suffixAlign?: NitroNumberAffixAlign
210
210
  /** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. Default: `0`. */
211
- letterSpacing?: number
211
+ textLetterSpacing?: number
212
212
  /** Points between the prefix and the digits, in place of the letter spacing there. Not finite: the letter spacing. */
213
213
  prefixSpacing?: number
214
214
  /** Points between the digits and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
@@ -274,13 +274,13 @@ export interface NitroNumberProps extends HybridViewProps {
274
274
  /** Upper bound for `allowFontScaling`, e.g. `1.3`. `0` means no cap. Default: `0`. */
275
275
  maxFontSizeMultiplier?: number
276
276
  /** Numeric font weight, `100`–`900`. Default: `400`. */
277
- fontWeight?: number
277
+ textWeight?: number
278
278
  /** Font family name. Defaults to the system font. */
279
- fontFamily?: string
279
+ textFamily?: string
280
280
  /** Text color as a processed ARGB integer (from `processColor`). Defaults to the platform label color. */
281
- color?: number
281
+ textColor?: number
282
282
  /** Where the number sits inside the view when the view is wider than the number. Default: `'auto'`, the start edge. */
283
- textAlign?: NitroNumberTextAlign
283
+ textAlignment?: NitroNumberTextAlign
284
284
  /**
285
285
  * Lay the figure out right-to-left: `'auto'` alignment resolves to the right
286
286
  * edge, the prefix moves to the right and the suffix to the left, and the
@@ -21,16 +21,16 @@ import type { NitroInputEasing, NitroInputEffect } from './NitroInput.nitro'
21
21
  export interface NitroTextProps extends HybridViewProps {
22
22
  text: string
23
23
  /** In points, already scaled for the system text size when the wrapper was asked to. Default 17. */
24
- fontSize?: number
24
+ textSize?: number
25
25
  /** Numeric weight, 100–900. Default 400. */
26
- fontWeight?: number
26
+ textWeight?: number
27
27
  /** Default: the system font. */
28
- fontFamily?: string
28
+ textFamily?: string
29
29
  /** Processed ARGB. Default: the platform label colour. */
30
- color?: number
30
+ textColor?: number
31
31
  /** Points after every character. */
32
- letterSpacing?: number
33
- textAlign?: NitroNumberTextAlign
32
+ textLetterSpacing?: number
33
+ textAlignment?: NitroNumberTextAlign
34
34
  rightToLeft?: boolean
35
35
  /** Of a morph, in ms. Default 400. */
36
36
  duration?: number
@@ -69,6 +69,37 @@ export interface NumberFormatPart {
69
69
  value: string
70
70
  }
71
71
 
72
+ /**
73
+ * One value as `NitroNumber` rolls it: the figure its digits show, rounded and
74
+ * trimmed as the format prints it, and the text around it.
75
+ */
76
+ export interface NumberFigure {
77
+ /** The figure as the digits show it, signed: 1.2 for "1.2K", 2.12 for "$2.12"; 0 (never -0) when it rounds to nothing, or for NaN and infinities. */
78
+ value: number
79
+ /** The fraction digits this value shows ("$1,234" 0, "$1,234.50" 2); the format's maximum for NaN and infinities. */
80
+ fractionDigits: number
81
+ /** The text before the number, without the sign. */
82
+ prefix: string
83
+ /** The text after the number, without the sign. */
84
+ suffix: string
85
+ }
86
+
87
+ /** The shape of a format, as `NitroNumber` and `NitroInput` lay a number out. */
88
+ export interface NumberFormatLayout {
89
+ prefix: string
90
+ suffix: string
91
+ /** Empty when the format does not group. */
92
+ groupingSeparator: string
93
+ decimalSeparator: string
94
+ /** A negative amount's sign comes after the prefix ("$-5"), not before it ("-$5"). */
95
+ signAfterAffix: boolean
96
+ minusSign: string
97
+ /** The group nearest the decimal point and every one before it ([3, 2]: 12,34,567). */
98
+ groupingSizes: number[]
99
+ /** The format's digits 0…9, or empty for Latin ones. */
100
+ digitGlyphs: string[]
101
+ }
102
+
72
103
  /**
73
104
  * A number formatter with the API of `Intl.NumberFormat`. It learns a
74
105
  * locale's format once from the platform (Foundation on iOS, ICU on Android)
@@ -80,6 +111,10 @@ export interface NitroNumberFormat extends HybridObject<{ ios: 'c++'; android: '
80
111
  format(value: number | Int64 | string): string
81
112
  formatToParts(value: number | Int64 | string): NumberFormatPart[]
82
113
  resolvedOptions(): ResolvedNumberFormatOptions
114
+ /** For the components, not part of `Intl.NumberFormat`: what `value` shows, as a figure. */
115
+ figure(value: number | Int64 | string): NumberFigure
116
+ /** For the components, not part of `Intl.NumberFormat`: the shape of the format. */
117
+ layout(): NumberFormatLayout
83
118
  }
84
119
 
85
120
  export interface NitroNumberFormatFactory extends HybridObject<{ ios: 'c++'; android: 'c++' }> {