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
@@ -66,7 +66,7 @@ const TRANSITION_DEFAULTS = {
66
66
  * The view sizes itself to its content unless you pass an explicit `width` /
67
67
  * `height` in `style`.
68
68
  */
69
- exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, tabularNums, format, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, signDisplay, plusSign, minusSign, prefixColor, suffixColor, fractionColor, fractionFontSize, fractionAlign, digitGlyphs, groupingSizes, digits, continuous, animated, respectReduceMotion, onAnimationStart, onAnimationEnd, onNativeRef, style, ...viewProps }, ref) {
69
+ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, minorDigits, fractionDigits, minimumIntegerDigits, groupingSeparator, decimalSeparator, prefix, suffix, transition, flashUpColor, flashDownColor, flashDuration, popOnChange, duration, easing, bounce, stagger, direction, reveal, revealStyle, revealDuration, revealBounce, revealGrow, revealStagger, revealMilestones, revealMilestoneHold, onRevealEnd, onRevealMilestone, loading, shimmerColor, shimmerDuration, shimmerAngle, shimmerWidth, shimmerBaseColor, shimmerDirection, shimmerDelay, fontSize, prefixFontSize, suffixFontSize, affixAlign, prefixAlign, suffixAlign, letterSpacing, prefixSpacing, suffixSpacing, prefixOffset, suffixOffset, tabularNums, format, adjustsFontSizeToFit, minimumFontScale, allowFontScaling, maxFontSizeMultiplier, fontWeight, fontFamily, color, textAlign, signDisplay, plusSign, minusSign, prefixColor, suffixColor, fractionColor, fractionFontSize, fractionAlign, digitGlyphs, groupingSizes, digits, continuous, animated, respectReduceMotion, onAnimationStart, onAnimationEnd, onNativeRef, style, ...viewProps }, ref) {
70
70
  const nativeRef = (0, react_1.useRef)(null);
71
71
  const latestOnNativeRef = (0, react_1.useRef)(onNativeRef);
72
72
  latestOnNativeRef.current = onNativeRef;
@@ -74,8 +74,10 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
74
74
  latestOnRevealEnd.current = onRevealEnd;
75
75
  const latestOnRevealMilestone = (0, react_1.useRef)(onRevealMilestone);
76
76
  latestOnRevealMilestone.current = onRevealMilestone;
77
- const latestValue = (0, react_1.useRef)(value);
78
- latestValue.current = value;
77
+ // The value as the format takes it: minor units shifted in, exactly.
78
+ const input = (0, formatProps_1.withMinorDigits)(value, minorDigits);
79
+ const latestValue = (0, react_1.useRef)(input);
80
+ latestValue.current = input;
79
81
  const latestOnAnimationStart = (0, react_1.useRef)(onAnimationStart);
80
82
  latestOnAnimationStart.current = onAnimationStart;
81
83
  const latestOnAnimationEnd = (0, react_1.useRef)(onAnimationEnd);
@@ -107,7 +109,7 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
107
109
  }), []);
108
110
  // The figure a compact format rolls is not the value (1.2 for 1,234): report the value.
109
111
  const onAnimationEndCallback = (0, react_1.useMemo)(() => (0, react_native_nitro_modules_1.callback)((shown) => {
110
- latestOnAnimationEnd.current?.(compactRef.current ? latestValue.current : shown);
112
+ latestOnAnimationEnd.current?.(compactRef.current ? (0, formatProps_1.toNumber)(latestValue.current) : shown);
111
113
  }), []);
112
114
  // A new array literal each render must not re-set the native prop. Always an
113
115
  // array (empty = no tiers): removing the prop would reach native as `null`,
@@ -122,7 +124,7 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
122
124
  jumpTo: (next) => nativeRef.current?.jumpTo(next),
123
125
  animateTo: (next) => nativeRef.current?.animateTo(next),
124
126
  revealTo: (next) => nativeRef.current?.revealTo(next),
125
- getValue: () => (compactRef.current ? latestValue.current : nativeRef.current?.value ?? latestValue.current),
127
+ getValue: () => compactRef.current ? (0, formatProps_1.toNumber)(latestValue.current) : nativeRef.current?.value ?? (0, formatProps_1.toNumber)(latestValue.current),
126
128
  get native() {
127
129
  return nativeRef.current;
128
130
  },
@@ -143,14 +145,20 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
143
145
  const resolvedFontSize = fontSize ?? 32;
144
146
  const resolvedAffixAlign = affixAlign ?? 'baseline';
145
147
  const derived = format ? (0, formatProps_1.formatProps)(format) : undefined;
146
- // Compact notation: "1.2K" rolls the figure 1.2 and swaps the suffix.
147
- const compact = format && derived?.compact ? (0, formatProps_1.compactParts)(format, value) : undefined;
148
+ // What the format shows for this value: the figure rounded its way, in the
149
+ // fraction digits it prints. Compact notation also swaps the suffix: "1.2K"
150
+ // rolls the figure 1.2.
151
+ const figure = (0, react_1.useMemo)(() => (format ? (0, formatProps_1.figureOf)(format, input) : undefined), [format, input]);
152
+ const compact = derived?.compact ? figure : undefined;
148
153
  const compactRef = (0, react_1.useRef)(false);
149
154
  compactRef.current = compact !== undefined;
150
155
  // Which way the value moved, for a compact figure that fell while the value grew (999 → 1K).
151
- const previousValue = (0, react_1.useRef)(value);
152
- const compactDirection = compact && direction === undefined ? (value >= previousValue.current ? 'up' : 'down') : undefined;
153
- previousValue.current = value;
156
+ const numericValue = (0, formatProps_1.toNumber)(input);
157
+ const previousValue = (0, react_1.useRef)(numericValue);
158
+ const compactDirection = compact && direction === undefined ? (numericValue >= previousValue.current ? 'up' : 'down') : undefined;
159
+ previousValue.current = numericValue;
160
+ // Without a format the engine rounds the double, as it always has.
161
+ const shownValue = figure ? figure.value : numericValue;
154
162
  const processedPrefixColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(prefixColor) ?? Infinity, [prefixColor]);
155
163
  const processedSuffixColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(suffixColor) ?? Infinity, [suffixColor]);
156
164
  const processedFractionColor = (0, react_1.useMemo)(() => (0, styleHelpers_1.toProcessedColor)(fractionColor) ?? Infinity, [fractionColor]);
@@ -186,5 +194,5 @@ exports.NitroNumber = (0, react_1.forwardRef)(function NitroNumber({ value, frac
186
194
  // does not hand a Hybrid View its resolved direction, so native is told.
187
195
  const layoutDirection = (0, react_1.useMemo)(() => react_native_1.StyleSheet.flatten(style)?.direction, [style]);
188
196
  const rightToLeft = layoutDirection === 'rtl' || (layoutDirection !== 'ltr' && react_native_1.I18nManager.isRTL);
189
- return (react_1.default.createElement(exports.NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: compact ? compact.value : value, fractionDigits: fractionDigits ?? compact?.fractionDigits ?? derived?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? compact?.prefix ?? derived?.prefix ?? '', suffix: suffix ?? compact?.suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? compactDirection ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: still ? 0 : revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, onAnimationStart: onAnimationStartCallback, onAnimationEnd: onAnimationEndCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, shimmerAngle: shimmerAngle ?? 31, shimmerWidth: shimmerWidth ?? 1, shimmerBaseColor: processedShimmerBase, shimmerDirection: shimmerDirection ?? 'auto', shimmerDelay: shimmerDelay ?? 0, fontSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, letterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, signDisplay: signDisplay ?? derived?.signDisplay ?? 'auto', plusSign: plusSign ?? derived?.plusSign ?? '+', minusSign: minusSign ?? derived?.minusSign ?? '-', digitGlyphs: stableGlyphs, groupingSizes: stableGroups, digitMax: digitMax, continuous: continuous ?? false, prefixColor: processedPrefixColor, suffixColor: processedSuffixColor, fractionColor: processedFractionColor, fractionFontSize: fractionFontSize ?? Infinity, fractionAlign: fractionAlign ?? 'baseline', respectReduceMotion: respectReduceMotion ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, fontWeight: numericWeight, fontFamily: fontFamily ?? '', color: processedColor, textAlign: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
197
+ return (react_1.default.createElement(exports.NativeNitroNumberView, { ...viewProps, style: [autoSize, style], hybridRef: hybridRef, value: shownValue, fractionDigits: fractionDigits ?? figure?.fractionDigits ?? 0, minimumIntegerDigits: minimumIntegerDigits ?? derived?.minimumIntegerDigits ?? 1, groupingSeparator: groupingSeparator ?? derived?.groupingSeparator ?? '', decimalSeparator: decimalSeparator ?? derived?.decimalSeparator ?? '.', prefix: prefix ?? compact?.prefix ?? derived?.prefix ?? '', suffix: suffix ?? compact?.suffix ?? derived?.suffix ?? '', transition: transition ?? 'roll', flashUpColor: processedFlashUp, flashDownColor: processedFlashDown, flashDuration: flashDuration ?? 600, popOnChange: popOnChange ?? 0, duration: still ? 0 : duration ?? TRANSITION_DEFAULTS[transition ?? 'roll'].duration, easing: easing ?? TRANSITION_DEFAULTS[transition ?? 'roll'].easing, bounce: bounce ?? 0.15, stagger: stagger ?? TRANSITION_DEFAULTS[transition ?? 'roll'].stagger, rollDirection: direction ?? compactDirection ?? 'auto', revealState: reveal === undefined ? 0 : reveal ? 2 : 1, revealStyle: revealStyle ?? 'count', revealDuration: still ? 0 : revealDuration ?? 2200, revealBounce: revealBounce ?? 0.12, revealGrow: revealGrow ?? 0.2, revealStagger: revealStagger ?? 200, revealMilestones: stableMilestones, revealMilestoneHold: revealMilestoneHold ?? 0, onRevealEnd: onRevealEndCallback, onRevealMilestone: onRevealMilestoneCallback, onAnimationStart: onAnimationStartCallback, onAnimationEnd: onAnimationEndCallback, loading: loading ?? false, shimmerColor: processedShimmerColor, shimmerDuration: shimmerDuration ?? 950, shimmerAngle: shimmerAngle ?? 31, shimmerWidth: shimmerWidth ?? 1, shimmerBaseColor: processedShimmerBase, shimmerDirection: shimmerDirection ?? 'auto', shimmerDelay: shimmerDelay ?? 0, textSize: resolvedFontSize, prefixFontSize: prefixFontSize ?? resolvedFontSize, suffixFontSize: suffixFontSize ?? resolvedFontSize, affixAlign: resolvedAffixAlign, prefixAlign: prefixAlign ?? resolvedAffixAlign, suffixAlign: suffixAlign ?? resolvedAffixAlign, textLetterSpacing: letterSpacing ?? 0, prefixSpacing: prefixSpacing ?? Infinity, suffixSpacing: suffixSpacing ?? Infinity, prefixOffset: prefixOffset ?? 0, suffixOffset: suffixOffset ?? 0, tabularNums: tabularNums ?? true, signDisplay: signDisplay ?? derived?.signDisplay ?? 'auto', plusSign: plusSign ?? derived?.plusSign ?? '+', minusSign: minusSign ?? derived?.minusSign ?? '-', digitGlyphs: stableGlyphs, groupingSizes: stableGroups, digitMax: digitMax, continuous: continuous ?? false, prefixColor: processedPrefixColor, suffixColor: processedSuffixColor, fractionColor: processedFractionColor, fractionFontSize: fractionFontSize ?? Infinity, fractionAlign: fractionAlign ?? 'baseline', respectReduceMotion: respectReduceMotion ?? true, adjustsFontSizeToFit: adjustsFontSizeToFit ?? false, minimumFontScale: minimumFontScale ?? 0.5, allowFontScaling: allowFontScaling ?? false, maxFontSizeMultiplier: maxFontSizeMultiplier ?? 0, textWeight: numericWeight, textFamily: fontFamily ?? '', textColor: processedColor, textAlignment: textAlign ?? 'auto', rightToLeft: rightToLeft, onSizeChange: onSizeChange }));
190
198
  });
@@ -86,18 +86,18 @@ function NitroText({ children, fontSize, fontWeight, fontFamily, color, letterSp
86
86
  native.text = text;
87
87
  native.style = style == null ? { width: Math.ceil(width), height } : [{ width: Math.ceil(width), height }, style];
88
88
  if (size !== 17)
89
- native.fontSize = size;
89
+ native.textSize = size;
90
90
  if (weight !== 400)
91
- native.fontWeight = weight;
91
+ native.textWeight = weight;
92
92
  if (family !== '')
93
- native.fontFamily = family;
93
+ native.textFamily = family;
94
94
  if (spacing !== 0)
95
- native.letterSpacing = spacing;
95
+ native.textLetterSpacing = spacing;
96
96
  const processedColor = (0, styleHelpers_1.toProcessedColor)(color);
97
97
  if (processedColor !== undefined)
98
- native.color = processedColor;
98
+ native.textColor = processedColor;
99
99
  if (textAlign !== undefined)
100
- native.textAlign = textAlign;
100
+ native.textAlignment = textAlign;
101
101
  if (duration !== undefined)
102
102
  native.duration = duration;
103
103
  if (easing !== undefined)
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NumberFormat = void 0;
4
4
  exports.sharedFormatterOf = sharedFormatterOf;
5
+ exports.figureOf = figureOf;
6
+ exports.layoutOf = layoutOf;
5
7
  const react_native_nitro_modules_1 = require("react-native-nitro-modules");
6
8
  // MARK: - The native side
7
9
  let factory;
@@ -354,6 +356,24 @@ const nativeOf = (value, method, unwrap = false) => slotsOf(value, method, unwra
354
356
  function sharedFormatterOf(value) {
355
357
  return typeof value === 'object' && value !== null ? slots.get(value)?.native : undefined;
356
358
  }
359
+ /**
360
+ * What `format` shows for `value`, as `NitroNumber` rolls it: the figure
361
+ * rounded and trimmed as the format prints it, and the text around it. Read
362
+ * in C++ off the formatter's own parts, from the number, bigint or decimal
363
+ * string itself.
364
+ * @internal
365
+ */
366
+ function figureOf(format, value) {
367
+ return nativeOf(format, 'figure').figure(toMathematicalValue(value));
368
+ }
369
+ /**
370
+ * The prefix, suffix, separators, sign placement, grouping and digits of
371
+ * `format`, read in C++ off its parts.
372
+ * @internal
373
+ */
374
+ function layoutOf(format) {
375
+ return nativeOf(format, 'layout').layout();
376
+ }
357
377
  // `length` is 0 as the specification says: the arguments are read from `arguments`.
358
378
  function NumberFormatConstructor() {
359
379
  const locales = arguments[0];
@@ -1,36 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.figureOf = void 0;
3
4
  exports.formatProps = formatProps;
4
- exports.compactParts = compactParts;
5
+ exports.withMinorDigits = withMinorDigits;
6
+ exports.toNumber = toNumber;
5
7
  const NumberFormat_1 = require("./NumberFormat");
6
- const NUMBER_PARTS = new Set(['integer', 'group', 'decimal', 'fraction']);
8
+ var NumberFormat_2 = require("./NumberFormat");
9
+ Object.defineProperty(exports, "figureOf", { enumerable: true, get: function () { return NumberFormat_2.figureOf; } });
7
10
  // By the native formatter, which instances built with the same locales and options share.
8
11
  const cache = new WeakMap();
9
- function join(parts, from, to) {
10
- return parts
11
- .slice(from, to)
12
- .map((p) => p.value)
13
- .join('');
14
- }
15
- /** The text before and after the number in `parts`. */
16
- function affixes(parts) {
17
- const first = parts.findIndex((p) => NUMBER_PARTS.has(p.type));
18
- let last = first;
19
- parts.forEach((p, i) => {
20
- if (NUMBER_PARTS.has(p.type))
21
- last = i;
22
- });
23
- // The sign is the component's own glyph, not part of an affix.
24
- const unsigned = (from, to) => join(parts.map((p) => (p.type === 'minusSign' || p.type === 'plusSign' ? { ...p, value: '' } : p)), from, to);
25
- return {
26
- prefix: first < 0 ? '' : unsigned(0, first),
27
- suffix: first < 0 ? '' : unsigned(last + 1, parts.length),
28
- };
29
- }
30
12
  /**
31
- * The prefix, suffix, separators and digit counts of `format`, read off its
32
- * parts once and cached per formatter. The components keep their own model
33
- * (a sign, a prefix, digits in groups, a suffix), so a format outside it
13
+ * The prefix, suffix, separators and digit counts of `format`, read in C++
14
+ * off its parts once and cached per formatter. The components keep their own
15
+ * model (a sign, a prefix, digits in groups, a suffix), so a format outside it
34
16
  * (accounting parentheses, a unit between the digits) is followed as far as
35
17
  * that model goes.
36
18
  */
@@ -40,69 +22,63 @@ function formatProps(format) {
40
22
  if (cached)
41
23
  return cached;
42
24
  const resolved = format.resolvedOptions();
43
- const compact = resolved.notation === 'compact';
44
- const fractionDigits = resolved.maximumFractionDigits ?? 0;
45
- // A value with every part: groups, and a fraction when the format has one.
46
- // Compact notation would print it "1.2M", so its affixes come per value.
47
- const parts = format.formatToParts(compact ? 1 : fractionDigits > 0 ? 1234567.5 : 1234567);
48
- const negative = format.formatToParts(-1);
49
- const minus = negative.findIndex((p) => p.type === 'minusSign');
50
- const currency = negative.findIndex((p) => p.type === 'currency' || p.type === 'percentSign');
51
- const integers = parts.filter((p) => p.type === 'integer').map((p) => p.value.length);
25
+ const layout = (0, NumberFormat_1.layoutOf)(format);
52
26
  const props = {
53
- ...affixes(parts),
54
- groupingSeparator: parts.find((p) => p.type === 'group')?.value ?? '',
55
- decimalSeparator: parts.find((p) => p.type === 'decimal')?.value ?? '.',
56
- fractionDigits,
27
+ prefix: layout.prefix,
28
+ suffix: layout.suffix,
29
+ groupingSeparator: layout.groupingSeparator,
30
+ decimalSeparator: layout.decimalSeparator,
31
+ fractionDigits: resolved.maximumFractionDigits ?? 0,
57
32
  minimumIntegerDigits: resolved.minimumIntegerDigits,
58
- signPlacement: minus >= 0 && currency >= 0 && minus > currency ? 'afterAffix' : 'beforeAffix',
33
+ signPlacement: layout.signAfterAffix ? 'afterAffix' : 'beforeAffix',
59
34
  signDisplay: (resolved.signDisplay ?? 'auto'),
60
- minusSign: negative[minus]?.value ?? '-',
35
+ minusSign: layout.minusSign,
61
36
  plusSign: '+',
62
- digitGlyphs: digitGlyphsOf(resolved.locale, resolved.numberingSystem),
63
- // "12,34,567": the last group is the first size, the one before it every later one.
64
- groupingSizes: integers.length >= 3 ? [integers[integers.length - 1], integers[integers.length - 2]] : [3],
65
- compact,
37
+ digitGlyphs: layout.digitGlyphs,
38
+ groupingSizes: layout.groupingSizes,
39
+ compact: resolved.notation === 'compact',
66
40
  };
67
41
  cache.set(key, props);
68
42
  return props;
69
43
  }
70
- const digitGlyphCache = new Map();
71
- /** The ten digits of a numbering system, or [] for Latin ones. */
72
- function digitGlyphsOf(locale, numberingSystem) {
73
- if (!numberingSystem || numberingSystem === 'latn')
74
- return [];
75
- const cached = digitGlyphCache.get(numberingSystem);
76
- if (cached)
77
- return cached;
78
- const digits = new NumberFormat_1.NumberFormat(locale, { numberingSystem, useGrouping: false });
79
- const glyphs = Array.from({ length: 10 }, (_, d) => digits.format(d));
80
- const result = glyphs.every((g, d) => g === String(d)) ? [] : glyphs;
81
- digitGlyphCache.set(numberingSystem, result);
82
- return result;
83
- }
84
44
  /**
85
- * Compact notation's parts for `value`: "1.2K" is the figure 1.2 with the
86
- * suffix "K", so the digits roll and the suffix swaps as the value crosses
87
- * a thousand, a million…
45
+ * `value` read in units of 10^-`minorDigits`, exactly: 123456n with 2 minor
46
+ * digits is "1234.56". A bigint or a numeric string is shifted as text, so no
47
+ * digit goes through a double: a decimal ("1234.5"), one with an exponent
48
+ * ("1e5" becomes "1e3"), or a 0x / 0o / 0b integer, as `Intl.NumberFormat`
49
+ * reads strings. A number that is a safe integer is shifted the same way, any
50
+ * other number is divided. A string that is not a number ("1,234.56") comes
51
+ * back as it is, which the format shows as NaN, never as a wrong amount.
88
52
  */
89
- function compactParts(format, value) {
90
- const parts = format.formatToParts(value);
91
- const props = formatProps(format);
92
- const latin = (text) => props.digitGlyphs.length === 10
93
- ? Array.from(text)
94
- .map((c) => {
95
- const d = props.digitGlyphs.indexOf(c);
96
- return d >= 0 ? String(d) : c;
97
- })
98
- .join('')
99
- : text;
100
- const integer = latin(parts.filter((p) => p.type === 'integer').map((p) => p.value).join(''));
101
- const fraction = latin(parts.filter((p) => p.type === 'fraction').map((p) => p.value).join(''));
102
- const magnitude = Number(fraction ? `${integer}.${fraction}` : integer);
103
- return {
104
- value: (value < 0 ? -1 : 1) * (Number.isFinite(magnitude) ? magnitude : 0),
105
- fractionDigits: fraction.length,
106
- ...affixes(parts),
107
- };
53
+ function withMinorDigits(value, minorDigits) {
54
+ const digits = minorDigits === undefined ? 0 : Math.max(0, Math.trunc(minorDigits));
55
+ if (digits === 0)
56
+ return value;
57
+ if (typeof value === 'number') {
58
+ if (!Number.isSafeInteger(value))
59
+ return value / 10 ** digits;
60
+ value = BigInt(value);
61
+ }
62
+ let text = typeof value === 'bigint' ? value.toString() : value.trim();
63
+ if (/^0[xob][0-9a-f]+$/i.test(text)) {
64
+ // A non-decimal integer: BigInt reads it as Intl does, exactly.
65
+ text = BigInt(text).toString();
66
+ }
67
+ const match = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(text);
68
+ if (!match || (match[2] === '' && match[3] === undefined && text !== ''))
69
+ return value;
70
+ const [, sign = '', whole = '', fraction = '', exponent] = match;
71
+ if (whole === '' && fraction === '' && text.includes('.'))
72
+ return value;
73
+ if (exponent !== undefined) {
74
+ // Moving the point is moving the exponent.
75
+ return `${sign}${whole}${fraction ? `.${fraction}` : ''}e${Number(exponent) - digits}`;
76
+ }
77
+ const all = (whole + fraction).padStart(digits + fraction.length + 1, '0');
78
+ const point = all.length - fraction.length - digits;
79
+ return `${sign}${all.slice(0, point)}.${all.slice(point)}`;
80
+ }
81
+ /** `value` as a double, for comparisons and for the engine when there is no format. */
82
+ function toNumber(value) {
83
+ return typeof value === 'number' ? value : Number(value);
108
84
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -40,7 +40,7 @@
40
40
  "signPlacement": true,
41
41
  "prefixAlign": true,
42
42
  "suffixAlign": true,
43
- "letterSpacing": true,
43
+ "textLetterSpacing": true,
44
44
  "prefixSpacing": true,
45
45
  "suffixSpacing": true,
46
46
  "prefixOffset": true,
@@ -51,12 +51,12 @@
51
51
  "easing": true,
52
52
  "bounce": true,
53
53
  "effect": true,
54
- "fontSize": true,
55
- "lineHeight": true,
56
- "fontWeight": true,
57
- "fontFamily": true,
58
- "color": true,
59
- "textAlign": true,
54
+ "textSize": true,
55
+ "textLineHeight": true,
56
+ "textWeight": true,
57
+ "textFamily": true,
58
+ "textColor": true,
59
+ "textAlignment": true,
60
60
  "rightToLeft": true,
61
61
  "caretColor": true,
62
62
  "selectionColor": true,
@@ -72,7 +72,11 @@
72
72
  "editable": true,
73
73
  "multiline": true,
74
74
  "numberOfLines": true,
75
- "textAlignVertical": true,
75
+ "textVerticalAlignment": true,
76
+ "textInsetLeft": true,
77
+ "textInsetTop": true,
78
+ "textInsetRight": true,
79
+ "textInsetBottom": true,
76
80
  "scrollEnabled": true,
77
81
  "autoFocus": true,
78
82
  "fieldTestID": true,
@@ -37,13 +37,13 @@
37
37
  "shimmerBaseColor": true,
38
38
  "shimmerDirection": true,
39
39
  "shimmerDelay": true,
40
- "fontSize": true,
40
+ "textSize": true,
41
41
  "prefixFontSize": true,
42
42
  "suffixFontSize": true,
43
43
  "affixAlign": true,
44
44
  "prefixAlign": true,
45
45
  "suffixAlign": true,
46
- "letterSpacing": true,
46
+ "textLetterSpacing": true,
47
47
  "prefixSpacing": true,
48
48
  "suffixSpacing": true,
49
49
  "prefixOffset": true,
@@ -66,10 +66,10 @@
66
66
  "minimumFontScale": true,
67
67
  "allowFontScaling": true,
68
68
  "maxFontSizeMultiplier": true,
69
- "fontWeight": true,
70
- "fontFamily": true,
71
- "color": true,
72
- "textAlign": true,
69
+ "textWeight": true,
70
+ "textFamily": true,
71
+ "textColor": true,
72
+ "textAlignment": true,
73
73
  "rightToLeft": true,
74
74
  "onSizeChange": true,
75
75
  "onRevealEnd": true,
@@ -5,12 +5,12 @@
5
5
  "directEventTypes": {},
6
6
  "validAttributes": {
7
7
  "text": true,
8
- "fontSize": true,
9
- "fontWeight": true,
10
- "fontFamily": true,
11
- "color": true,
12
- "letterSpacing": true,
13
- "textAlign": true,
8
+ "textSize": true,
9
+ "textWeight": true,
10
+ "textFamily": true,
11
+ "textColor": true,
12
+ "textLetterSpacing": true,
13
+ "textAlignment": true,
14
14
  "rightToLeft": true,
15
15
  "duration": true,
16
16
  "easing": true,