@nanahoshi/mona-ui 0.27.2 → 0.28.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 (208) hide show
  1. package/docs/api/chart.md +2 -2
  2. package/docs/api/popup.md +1 -1
  3. package/docs/api/theme.md +2 -2
  4. package/docs/chart.md +14 -0
  5. package/docs/editor.md +2 -0
  6. package/docs/installation.md +147 -15
  7. package/docs/introduction.md +37 -15
  8. package/docs/theming-built-in-themes.md +67 -0
  9. package/docs/theming-custom-colors.md +274 -0
  10. package/docs/theming-custom-themes.md +168 -0
  11. package/docs/theming.md +164 -248
  12. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1089 -603
  13. package/fesm2022/nanahoshi-mona-ui-avatar.mjs +369 -184
  14. package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +658 -371
  15. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +513 -359
  16. package/fesm2022/nanahoshi-mona-ui-button.mjs +622 -517
  17. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +2070 -1573
  18. package/fesm2022/nanahoshi-mona-ui-card.mjs +620 -316
  19. package/fesm2022/nanahoshi-mona-ui-chart.mjs +61151 -64921
  20. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +646 -317
  21. package/fesm2022/nanahoshi-mona-ui-chip.mjs +737 -516
  22. package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +441 -242
  23. package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +443 -390
  24. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +1138 -814
  25. package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +1114 -959
  26. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +858 -504
  27. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1181 -742
  28. package/fesm2022/nanahoshi-mona-ui-command.mjs +1454 -853
  29. package/fesm2022/nanahoshi-mona-ui-common.mjs +569 -743
  30. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +978 -532
  31. package/fesm2022/nanahoshi-mona-ui-date-input.mjs +283 -266
  32. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +973 -451
  33. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +1203 -658
  34. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +1415 -936
  35. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +1165 -568
  36. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1142 -677
  37. package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +1018 -734
  38. package/fesm2022/nanahoshi-mona-ui-editor.mjs +3589 -2122
  39. package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +577 -359
  40. package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +311 -151
  41. package/fesm2022/nanahoshi-mona-ui-filter.mjs +1086 -718
  42. package/fesm2022/nanahoshi-mona-ui-grid-grid-colgroup.component-NhONCVIX.mjs +77 -0
  43. package/fesm2022/nanahoshi-mona-ui-grid-grid-footer-row.component-Djv8ZnT5.mjs +480 -0
  44. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-WbXAzGCa.mjs +470 -0
  45. package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-DkWTD3pN.mjs +2115 -0
  46. package/fesm2022/nanahoshi-mona-ui-grid-grid-virtual-list.component-DAHqTwBJ.mjs +330 -0
  47. package/fesm2022/nanahoshi-mona-ui-grid-grid.styles-BmLU-3zP.mjs +3766 -0
  48. package/fesm2022/nanahoshi-mona-ui-grid.mjs +5418 -2
  49. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +1379 -1079
  50. package/fesm2022/nanahoshi-mona-ui-i18n.mjs +4451 -5077
  51. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +344 -143
  52. package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +257 -127
  53. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +2080 -1829
  54. package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +103 -141
  55. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +2498 -2706
  56. package/fesm2022/nanahoshi-mona-ui-internal.mjs +722 -1007
  57. package/fesm2022/nanahoshi-mona-ui-label.mjs +313 -202
  58. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +1308 -1009
  59. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +1411 -677
  60. package/fesm2022/nanahoshi-mona-ui-list.mjs +1 -6
  61. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +556 -577
  62. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +530 -573
  63. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +530 -573
  64. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +533 -576
  65. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +520 -555
  66. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +530 -571
  67. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +520 -555
  68. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +520 -555
  69. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +530 -571
  70. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +576 -591
  71. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +530 -565
  72. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +520 -555
  73. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +520 -555
  74. package/fesm2022/nanahoshi-mona-ui-locales.mjs +59 -77
  75. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +1411 -829
  76. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1326 -702
  77. package/fesm2022/nanahoshi-mona-ui-notification.mjs +763 -675
  78. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1306 -826
  79. package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +1122 -897
  80. package/fesm2022/nanahoshi-mona-ui-pager.mjs +1110 -651
  81. package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +95 -53
  82. package/fesm2022/nanahoshi-mona-ui-popover.mjs +559 -397
  83. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +2323 -1694
  84. package/fesm2022/nanahoshi-mona-ui-popup.mjs +1657 -1455
  85. package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +441 -267
  86. package/fesm2022/nanahoshi-mona-ui-query.mjs +211 -340
  87. package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +1017 -548
  88. package/fesm2022/nanahoshi-mona-ui-rating.mjs +874 -624
  89. package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +1130 -917
  90. package/fesm2022/nanahoshi-mona-ui-segmented.mjs +705 -455
  91. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +461 -283
  92. package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +2791 -2449
  93. package/fesm2022/nanahoshi-mona-ui-skeleton.mjs +145 -90
  94. package/fesm2022/nanahoshi-mona-ui-slider.mjs +1563 -1103
  95. package/fesm2022/nanahoshi-mona-ui-spinner.mjs +738 -673
  96. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +1287 -647
  97. package/fesm2022/nanahoshi-mona-ui-splitter.mjs +1313 -909
  98. package/fesm2022/nanahoshi-mona-ui-stepper.mjs +761 -540
  99. package/fesm2022/nanahoshi-mona-ui-switch.mjs +611 -280
  100. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +1393 -841
  101. package/fesm2022/nanahoshi-mona-ui-text-area.mjs +142 -73
  102. package/fesm2022/nanahoshi-mona-ui-text-box.mjs +876 -374
  103. package/fesm2022/nanahoshi-mona-ui-theme.mjs +1465 -1449
  104. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +897 -443
  105. package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +1100 -703
  106. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +789 -538
  107. package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +1361 -805
  108. package/fesm2022/nanahoshi-mona-ui-window.mjs +2145 -1531
  109. package/fesm2022/nanahoshi-mona-ui.mjs +1 -8
  110. package/llms.txt +6 -2
  111. package/package.json +62 -23
  112. package/types/nanahoshi-mona-ui-auto-complete.d.ts +367 -233
  113. package/types/nanahoshi-mona-ui-avatar.d.ts +722 -649
  114. package/types/nanahoshi-mona-ui-breadcrumb.d.ts +134 -103
  115. package/types/nanahoshi-mona-ui-button-group.d.ts +213 -152
  116. package/types/nanahoshi-mona-ui-button.d.ts +227 -166
  117. package/types/nanahoshi-mona-ui-calendar.d.ts +324 -259
  118. package/types/nanahoshi-mona-ui-card.d.ts +125 -111
  119. package/types/nanahoshi-mona-ui-chart.d.ts +10483 -7326
  120. package/types/nanahoshi-mona-ui-check-box.d.ts +293 -180
  121. package/types/nanahoshi-mona-ui-chip.d.ts +208 -141
  122. package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +194 -133
  123. package/types/nanahoshi-mona-ui-collapsible.d.ts +103 -87
  124. package/types/nanahoshi-mona-ui-color-gradient.d.ts +281 -213
  125. package/types/nanahoshi-mona-ui-color-palette.d.ts +201 -138
  126. package/types/nanahoshi-mona-ui-color-picker.d.ts +283 -194
  127. package/types/nanahoshi-mona-ui-combo-box.d.ts +401 -262
  128. package/types/nanahoshi-mona-ui-command.d.ts +279 -191
  129. package/types/nanahoshi-mona-ui-common.d.ts +354 -385
  130. package/types/nanahoshi-mona-ui-contextmenu.d.ts +142 -117
  131. package/types/nanahoshi-mona-ui-date-input.d.ts +79 -96
  132. package/types/nanahoshi-mona-ui-date-picker.d.ts +338 -208
  133. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +413 -259
  134. package/types/nanahoshi-mona-ui-dialog.d.ts +470 -381
  135. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +216 -168
  136. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +369 -243
  137. package/types/nanahoshi-mona-ui-dropdowns.d.ts +231 -217
  138. package/types/nanahoshi-mona-ui-editor.d.ts +302 -235
  139. package/types/nanahoshi-mona-ui-expansion-panel.d.ts +140 -109
  140. package/types/nanahoshi-mona-ui-fieldset.d.ts +98 -68
  141. package/types/nanahoshi-mona-ui-filter.d.ts +150 -124
  142. package/types/nanahoshi-mona-ui-grid.d.ts +1956 -1678
  143. package/types/nanahoshi-mona-ui-i18n-icu.d.ts +25 -34
  144. package/types/nanahoshi-mona-ui-i18n.d.ts +987 -1052
  145. package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +118 -71
  146. package/types/nanahoshi-mona-ui-internal-indicator-icon.d.ts +56 -27
  147. package/types/nanahoshi-mona-ui-internal-list.d.ts +474 -408
  148. package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +143 -150
  149. package/types/nanahoshi-mona-ui-internal-tree.d.ts +493 -506
  150. package/types/nanahoshi-mona-ui-internal.d.ts +195 -213
  151. package/types/nanahoshi-mona-ui-label.d.ts +108 -78
  152. package/types/nanahoshi-mona-ui-list-box.d.ts +392 -322
  153. package/types/nanahoshi-mona-ui-list-view.d.ts +423 -282
  154. package/types/nanahoshi-mona-ui-list.d.ts +2 -1
  155. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +540 -542
  156. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +540 -542
  157. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +540 -542
  158. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +540 -542
  159. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +540 -542
  160. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +540 -542
  161. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +540 -542
  162. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +540 -542
  163. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +540 -542
  164. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +540 -542
  165. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +540 -542
  166. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +540 -542
  167. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +540 -542
  168. package/types/nanahoshi-mona-ui-locales.d.ts +17 -19
  169. package/types/nanahoshi-mona-ui-menubar.d.ts +210 -181
  170. package/types/nanahoshi-mona-ui-multi-select.d.ts +416 -276
  171. package/types/nanahoshi-mona-ui-notification.d.ts +140 -151
  172. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +407 -270
  173. package/types/nanahoshi-mona-ui-otp-input.d.ts +364 -241
  174. package/types/nanahoshi-mona-ui-pager.d.ts +379 -301
  175. package/types/nanahoshi-mona-ui-placeholder.d.ts +35 -28
  176. package/types/nanahoshi-mona-ui-popover.d.ts +176 -134
  177. package/types/nanahoshi-mona-ui-popup-menu.d.ts +488 -344
  178. package/types/nanahoshi-mona-ui-popup.d.ts +698 -560
  179. package/types/nanahoshi-mona-ui-progress-bar.d.ts +197 -137
  180. package/types/nanahoshi-mona-ui-query.d.ts +82 -88
  181. package/types/nanahoshi-mona-ui-radio-button.d.ts +434 -269
  182. package/types/nanahoshi-mona-ui-rating.d.ts +348 -254
  183. package/types/nanahoshi-mona-ui-scroll-view.d.ts +244 -172
  184. package/types/nanahoshi-mona-ui-segmented.d.ts +250 -175
  185. package/types/nanahoshi-mona-ui-sheet.d.ts +115 -63
  186. package/types/nanahoshi-mona-ui-sidebar.d.ts +653 -493
  187. package/types/nanahoshi-mona-ui-skeleton.d.ts +55 -39
  188. package/types/nanahoshi-mona-ui-slider.d.ts +503 -354
  189. package/types/nanahoshi-mona-ui-spinner.d.ts +125 -112
  190. package/types/nanahoshi-mona-ui-split-button.d.ts +241 -196
  191. package/types/nanahoshi-mona-ui-splitter.d.ts +124 -78
  192. package/types/nanahoshi-mona-ui-stepper.d.ts +206 -181
  193. package/types/nanahoshi-mona-ui-switch.d.ts +197 -131
  194. package/types/nanahoshi-mona-ui-tabs.d.ts +349 -248
  195. package/types/nanahoshi-mona-ui-text-area.d.ts +52 -36
  196. package/types/nanahoshi-mona-ui-text-box.d.ts +349 -218
  197. package/types/nanahoshi-mona-ui-theme.d.ts +415 -408
  198. package/types/nanahoshi-mona-ui-time-picker.d.ts +357 -217
  199. package/types/nanahoshi-mona-ui-time-selector.d.ts +255 -170
  200. package/types/nanahoshi-mona-ui-tooltip.d.ts +222 -144
  201. package/types/nanahoshi-mona-ui-tree-view.d.ts +466 -308
  202. package/types/nanahoshi-mona-ui-window.d.ts +494 -399
  203. package/types/nanahoshi-mona-ui.d.ts +1 -2
  204. package/fesm2022/nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs +0 -181
  205. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs +0 -208
  206. package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs +0 -1082
  207. package/fesm2022/nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs +0 -186
  208. package/fesm2022/nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs +0 -7568
@@ -1,95 +1,103 @@
1
- import { NgTemplateOutlet } from '@angular/common';
2
- import * as i0 from '@angular/core';
3
- import { Directive, inject, DestroyRef, ElementRef, computed, signal, contentChildren, TemplateRef, viewChild, input, booleanAttribute, output, effect, untracked, afterNextRender, model, Component } from '@angular/core';
4
- import { LucideChevronUp, LucideChevronDown } from '@lucide/angular';
5
- import { ButtonDirective } from '@nanahoshi/mona-ui/button';
6
- import { MonaI18nService, formatNumber, getNumberSymbols, validateLocalizedDecimalEdit, validateLocalizedDecimal, validateLocalizedNumberEdit, validateLocalizedNumber } from '@nanahoshi/mona-ui/i18n';
7
- import { TextBoxDirective } from '@nanahoshi/mona-ui/text-box';
8
- import { FocusMonitor } from '@angular/cdk/a11y';
9
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
10
- import { themeControlSurfaceClasses, injectEffectiveDisabled, createElementControlId, rxTimeout } from '@nanahoshi/mona-ui/internal';
11
- import { Subject, filter, switchMap, of, tap, delay, concatMap, timer, takeUntil, map } from 'rxjs';
12
- import { twMerge } from 'tailwind-merge';
13
- import { cva } from 'class-variance-authority';
14
-
15
- /**
16
- * Exact arithmetic on canonical decimal strings (see `parseLocalizedDecimal`), using a `bigint` scaled by a power
17
- * of ten. Only what the decimal text box needs: adding a step and comparing against bounds.
18
- */
1
+ import { NgTemplateOutlet } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { Component, DestroyRef, Directive, ElementRef, TemplateRef, afterNextRender, booleanAttribute, computed, contentChildren, effect, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
4
+ import { LucideChevronDown, LucideChevronUp } from "@lucide/angular";
5
+ import { ButtonDirective } from "@nanahoshi/mona-ui/button";
6
+ import { MonaI18nService, formatNumber, getNumberSymbols, validateLocalizedDecimal, validateLocalizedDecimalEdit, validateLocalizedNumber, validateLocalizedNumberEdit } from "@nanahoshi/mona-ui/i18n";
7
+ import { TextBoxDirective } from "@nanahoshi/mona-ui/text-box";
8
+ import { FocusMonitor } from "@angular/cdk/a11y";
9
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
10
+ import { createElementControlId, injectEffectiveDisabled, rxTimeout, themeControlSurfaceClasses } from "@nanahoshi/mona-ui/internal";
11
+ import { Subject, concatMap, delay, filter, map, of, switchMap, takeUntil, tap, timer } from "rxjs";
12
+ import { twMerge } from "tailwind-merge";
13
+ import { cva } from "class-variance-authority";
19
14
  const DECIMAL_REGEX = /^(-)?(\d+)(?:\.(\d+))?$/;
20
- /** Writes a number in plain decimal notation, never with an exponent. */
21
- const PLAIN_NUMBER_FORMAT = new Intl.NumberFormat("en-US", { maximumFractionDigits: 100, useGrouping: false });
15
+ const PLAIN_NUMBER_FORMAT = new Intl.NumberFormat("en-US", {
16
+ maximumFractionDigits: 100,
17
+ useGrouping: false
18
+ });
22
19
  function toScaled(value) {
23
- const match = DECIMAL_REGEX.exec(value);
24
- if (!match) {
25
- throw new Error(`"${value}" is not a decimal string.`);
26
- }
27
- const fraction = match[3] ?? "";
28
- const units = BigInt(match[2] + fraction);
29
- return { scale: fraction.length, units: match[1] ? -units : units };
20
+ const match = DECIMAL_REGEX.exec(value);
21
+ if (!match) throw new Error(`"${value}" is not a decimal string.`);
22
+ const fraction = match[3] ?? "";
23
+ const units = BigInt(match[2] + fraction);
24
+ return {
25
+ scale: fraction.length,
26
+ units: match[1] ? -units : units
27
+ };
30
28
  }
31
29
  function toCommonScale(a, b) {
32
- const scale = Math.max(a.scale, b.scale);
33
- return [a.units * 10n ** BigInt(scale - a.scale), b.units * 10n ** BigInt(scale - b.scale), scale];
30
+ const scale = Math.max(a.scale, b.scale);
31
+ return [
32
+ a.units * 10n ** BigInt(scale - a.scale),
33
+ b.units * 10n ** BigInt(scale - b.scale),
34
+ scale
35
+ ];
34
36
  }
35
37
  function fromScaled(units, scale) {
36
- const negative = units < 0n;
37
- const digits = (negative ? -units : units).toString().padStart(scale + 1, "0");
38
- const integer = digits.slice(0, digits.length - scale);
39
- const fraction = digits.slice(digits.length - scale).replace(/0+$/, "");
40
- const text = fraction ? `${integer}.${fraction}` : integer;
41
- return negative ? `-${text}` : text;
38
+ const negative = units < 0n;
39
+ const digits = (negative ? -units : units).toString().padStart(scale + 1, "0");
40
+ const integer = digits.slice(0, digits.length - scale);
41
+ const fraction = digits.slice(digits.length - scale).replace(/0+$/, "");
42
+ const text = fraction ? `${integer}.${fraction}` : integer;
43
+ return negative ? `-${text}` : text;
42
44
  }
43
- /**
44
- * Canonical decimal string for a decimal string or a finite number, or `null` for anything else. Leading zeros,
45
- * trailing fraction zeros and the sign of zero are dropped, so equal values have equal strings.
46
- */
47
45
  function toDecimalString(value) {
48
- if (value == null) {
49
- return null;
50
- }
51
- if (typeof value === "number") {
52
- return Number.isFinite(value) ? toDecimalString(PLAIN_NUMBER_FORMAT.format(value)) : null;
53
- }
54
- const text = value.trim();
55
- if (!DECIMAL_REGEX.test(text)) {
56
- return null;
57
- }
58
- const { scale, units } = toScaled(text);
59
- return fromScaled(units, scale);
46
+ if (value == null) return null;
47
+ if (typeof value === "number") return Number.isFinite(value) ? toDecimalString(PLAIN_NUMBER_FORMAT.format(value)) : null;
48
+ const text = value.trim();
49
+ if (!DECIMAL_REGEX.test(text)) return null;
50
+ const { scale, units } = toScaled(text);
51
+ return fromScaled(units, scale);
60
52
  }
61
53
  function addDecimals(a, b) {
62
- const [x, y, scale] = toCommonScale(toScaled(a), toScaled(b));
63
- return fromScaled(x + y, scale);
54
+ const [x, y, scale] = toCommonScale(toScaled(a), toScaled(b));
55
+ return fromScaled(x + y, scale);
64
56
  }
65
57
  function subtractDecimals(a, b) {
66
- const [x, y, scale] = toCommonScale(toScaled(a), toScaled(b));
67
- return fromScaled(x - y, scale);
58
+ const [x, y, scale] = toCommonScale(toScaled(a), toScaled(b));
59
+ return fromScaled(x - y, scale);
68
60
  }
69
- /** Negative when `a < b`, zero when equal, positive when `a > b`. */
70
61
  function compareDecimals(a, b) {
71
- const [x, y] = toCommonScale(toScaled(a), toScaled(b));
72
- return x === y ? 0 : x < y ? -1 : 1;
73
- }
74
-
75
- class NumericTextBoxPrefixTemplateDirective {
76
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NumericTextBoxPrefixTemplateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
77
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.6", type: NumericTextBoxPrefixTemplateDirective, isStandalone: true, selector: "ng-template[monaNumericTextBoxPrefixTemplate]", ngImport: i0 }); }
62
+ const [x, y] = toCommonScale(toScaled(a), toScaled(b));
63
+ return x === y ? 0 : x < y ? -1 : 1;
78
64
  }
79
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NumericTextBoxPrefixTemplateDirective, decorators: [{
80
- type: Directive,
81
- args: [{
82
- selector: "ng-template[monaNumericTextBoxPrefixTemplate]"
83
- }]
84
- }] });
85
-
86
- // Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
87
- // Edit the JSON file and run `npm run generate:locale-catalogs`.
65
+ var NumericTextBoxPrefixTemplateDirective = class NumericTextBoxPrefixTemplateDirective {
66
+ static {
67
+ this.ɵfac = i0.ɵɵngDeclareFactory({
68
+ minVersion: "12.0.0",
69
+ version: "22.2.6",
70
+ ngImport: i0,
71
+ type: NumericTextBoxPrefixTemplateDirective,
72
+ deps: [],
73
+ target: i0.ɵɵFactoryTarget.Directive
74
+ });
75
+ }
76
+ static {
77
+ this.ɵdir = i0.ɵɵngDeclareDirective({
78
+ minVersion: "14.0.0",
79
+ version: "22.2.6",
80
+ type: NumericTextBoxPrefixTemplateDirective,
81
+ isStandalone: true,
82
+ selector: "ng-template[monaNumericTextBoxPrefixTemplate]",
83
+ ngImport: i0
84
+ });
85
+ }
86
+ };
87
+ i0.ɵɵngDeclareClassMetadata({
88
+ minVersion: "12.0.0",
89
+ version: "22.2.6",
90
+ ngImport: i0,
91
+ type: NumericTextBoxPrefixTemplateDirective,
92
+ decorators: [{
93
+ type: Directive,
94
+ args: [{ selector: "ng-template[monaNumericTextBoxPrefixTemplate]" }]
95
+ }]
96
+ });
88
97
  const NUMERIC_TEXT_BOX_DEFAULT_MESSAGES = {
89
- decrease: "Decrease value",
90
- increase: "Increase value"
98
+ decrease: "Decrease value",
99
+ increase: "Increase value"
91
100
  };
92
-
93
101
  const numericTextboxThemeVariants = cva(`
94
102
  flex w-full min-w-0 items-center
95
103
  overflow-hidden p-0
@@ -114,22 +122,20 @@ const numericTextboxThemeVariants = cva(`
114
122
  data-[invalid='true']:ring-2 data-[invalid='true']:ring-error/35
115
123
  data-[invalid='true']:focus-within:border-error
116
124
  data-[invalid='true']:focus-within:ring-error/35
117
- `, {
118
- variants: {
119
- rounded: {
120
- full: "rounded-full",
121
- large: "rounded-lg",
122
- medium: "rounded-md",
123
- none: "rounded-none",
124
- small: "rounded-sm"
125
- },
126
- size: {
127
- large: "h-10 text-base",
128
- medium: "h-9 text-sm",
129
- small: "h-8 text-xs"
130
- }
131
- }
132
- });
125
+ `, { variants: {
126
+ rounded: {
127
+ full: "rounded-full",
128
+ large: "rounded-lg",
129
+ medium: "rounded-md",
130
+ none: "rounded-none",
131
+ small: "rounded-sm"
132
+ },
133
+ size: {
134
+ large: "h-10 text-base",
135
+ medium: "h-9 text-sm",
136
+ small: "h-8 text-xs"
137
+ }
138
+ } });
133
139
  const numericTextboxInputThemeVariants = cva(`
134
140
  h-full w-full
135
141
  bg-transparent
@@ -137,39 +143,37 @@ const numericTextboxInputThemeVariants = cva(`
137
143
  rounded-none
138
144
  outline-none focus-visible:outline-hidden ring-0
139
145
  focus-visible:border-transparent focus-visible:ring-0
140
- `, {
141
- variants: {
142
- startRounded: {
143
- full: "rounded-s-full",
144
- large: "rounded-s-lg",
145
- medium: "rounded-s-md",
146
- none: "rounded-s-none",
147
- small: "rounded-s-sm"
148
- },
149
- endRounded: {
150
- full: `
146
+ `, { variants: {
147
+ startRounded: {
148
+ full: "rounded-s-full",
149
+ large: "rounded-s-lg",
150
+ medium: "rounded-s-md",
151
+ none: "rounded-s-none",
152
+ small: "rounded-s-sm"
153
+ },
154
+ endRounded: {
155
+ full: `
151
156
  rounded-e-full
152
157
  data-[spinners='true']:rounded-e-none
153
158
  `,
154
- large: `
159
+ large: `
155
160
  rounded-e-lg
156
161
  data-[spinners='true']:rounded-e-none
157
162
  `,
158
- medium: `
163
+ medium: `
159
164
  rounded-e-md
160
165
  data-[spinners='true']:rounded-e-none
161
166
  `,
162
- none: `
167
+ none: `
163
168
  rounded-e-none
164
169
  data-[spinners='true']:rounded-e-none
165
170
  `,
166
- small: `
171
+ small: `
167
172
  rounded-e-sm
168
173
  data-[spinners='true']:rounded-e-none
169
174
  `
170
- }
171
- }
172
- });
175
+ }
176
+ } });
173
177
  const numericTextboxButtonThemeVariants = cva(`
174
178
  flex h-full flex-col
175
179
  overflow-y-hidden
@@ -183,726 +187,1202 @@ const numericTextboxButtonThemeVariants = cva(`
183
187
  [&>button]:last:rounded-s-none
184
188
  [&>button]:last:rounded-t-none
185
189
  [&>button]:last:h-1/2
186
- `, {
187
- variants: {
188
- size: {
189
- large: "w-16 min-w-16",
190
- medium: "w-10 min-w-10",
191
- small: "w-8 min-w-8"
192
- }
193
- }
194
- });
195
-
196
- /** PageUp and PageDown move by this many steps. */
190
+ `, { variants: { size: {
191
+ large: "w-16 min-w-16",
192
+ medium: "w-10 min-w-10",
193
+ small: "w-8 min-w-8"
194
+ } } });
197
195
  const PAGE_STEP_COUNT = 10;
198
- /**
199
- * Typing, pasting, spinning, formatting and ARIA for a numeric input, shared by the number and decimal text boxes.
200
- * Subclasses declare the value-typed inputs and say how to parse, compare and step their value type.
201
- */
202
- class NumericTextBoxBaseComponent {
203
- #destroyRef;
204
- #focusMonitor;
205
- #hostElementRef;
206
- #i18n;
207
- /** The value this component last wrote, so a value set from outside can be told apart. */
208
- #ownValue;
209
- #pendingPaste;
210
- constructor() {
211
- this.#destroyRef = inject(DestroyRef);
212
- this.#focusMonitor = inject(FocusMonitor);
213
- this.#hostElementRef = inject((ElementRef));
214
- this.#i18n = inject(MonaI18nService);
215
- /** The value this component last wrote, so a value set from outside can be told apart. */
216
- this.#ownValue = undefined;
217
- this.#pendingPaste = false;
218
- this.beforeInput$ = new Subject();
219
- this.classes = computed(() => {
220
- const rounded = this.rounded();
221
- const size = this.size();
222
- const classes = numericTextboxThemeVariants({ rounded, size });
223
- const userClass = this.userClass();
224
- return twMerge(classes, userClass);
225
- }, /* @ts-ignore */
226
- ...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
227
- this.effectiveDisabled = injectEffectiveDisabled(() => this.disabled());
228
- this.focused = signal(false, /* @ts-ignore */
229
- ...(ngDevMode ? [{ debugName: "focused" }] : /* istanbul ignore next */ []));
230
- this.formattedValue = computed(() => {
231
- if (this.focused() && !this.readonly()) {
232
- return this.rawInputValue();
233
- }
234
- return this.formatValueForDisplay(this.value());
235
- }, /* @ts-ignore */
236
- ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
237
- this.inputClasses = computed(() => {
238
- const hasPrefixTemplate = this.prefixTemplateList().length > 0;
239
- const startRounded = hasPrefixTemplate ? "none" : this.rounded();
240
- const endRounded = this.showSpinners() ? "none" : this.rounded();
241
- const inputVariants = numericTextboxInputThemeVariants({ endRounded, startRounded });
242
- return twMerge(inputVariants);
243
- }, /* @ts-ignore */
244
- ...(ngDevMode ? [{ debugName: "inputClasses" }] : /* istanbul ignore next */ []));
245
- this.invalidInput = computed(() => this.touched() && (this.invalid() || (this.required() && this.value() == null)), /* @ts-ignore */
246
- ...(ngDevMode ? [{ debugName: "invalidInput" }] : /* istanbul ignore next */ []));
247
- this.keydown$ = new Subject();
248
- this.messages = this.#i18n.componentMessages("numericTextBox", NUMERIC_TEXT_BOX_DEFAULT_MESSAGES);
249
- this.prefixTemplateList = contentChildren(NumericTextBoxPrefixTemplateDirective, { ...(ngDevMode ? { debugName: "prefixTemplateList" } : /* istanbul ignore next */ {}), read: TemplateRef });
250
- this.rawInputValue = signal("", /* @ts-ignore */
251
- ...(ngDevMode ? [{ debugName: "rawInputValue" }] : /* istanbul ignore next */ []));
252
- /** Spin buttons on a read-only field would look usable but do nothing, so they are hidden there. */
253
- this.showSpinners = computed(() => this.spinners() && !this.readonly(), /* @ts-ignore */
254
- ...(ngDevMode ? [{ debugName: "showSpinners" }] : /* istanbul ignore next */ []));
255
- this.spin$ = new Subject();
256
- this.spinButtonClasses = computed(() => {
257
- const size = this.size();
258
- return numericTextboxButtonThemeVariants({ size });
259
- }, /* @ts-ignore */
260
- ...(ngDevMode ? [{ debugName: "spinButtonClasses" }] : /* istanbul ignore next */ []));
261
- this.spinButtonIconSize = computed(() => {
262
- const size = this.size();
263
- return size === "large" ? 20 : size === "medium" ? 16 : 14;
264
- }, /* @ts-ignore */
265
- ...(ngDevMode ? [{ debugName: "spinButtonIconSize" }] : /* istanbul ignore next */ []));
266
- this.spinStop$ = new Subject();
267
- this.valueChange$ = new Subject();
268
- this.valueTextBoxRef = viewChild.required("valueTextBox", /* @ts-ignore */
269
- ...(ngDevMode ? [{ debugName: "valueTextBoxRef" }] : /* istanbul ignore next */ []));
270
- this.wheel$ = new Subject();
271
- /**
272
- * @description ID of an element that provides an extended description for the input, such as a hint or an
273
- * error message.
274
- * @default ""
275
- */
276
- this.ariaDescribedBy = input("", { ...(ngDevMode ? { debugName: "ariaDescribedBy" } : /* istanbul ignore next */ {}), alias: "aria-describedby" });
277
- /**
278
- * @description Accessible name for the input. Prefer a visible label, linked through {@link inputId} or
279
- * `aria-labelledby`.
280
- */
281
- this.ariaLabel = input(null, { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
282
- /**
283
- * @description ID of an external element that provides the accessible name for the input.
284
- * @default ""
285
- */
286
- this.ariaLabelledBy = input("", { ...(ngDevMode ? { debugName: "ariaLabelledBy" } : /* istanbul ignore next */ {}), alias: "aria-labelledby" });
287
- /**
288
- * @description Number of fractional decimal places to display and accept. Values are truncated to an integer
289
- * and clamped to the range 0–20. Non-finite and negative values normalize to 0.
290
- * @default 0
291
- */
292
- this.decimals = input(0, { ...(ngDevMode ? { debugName: "decimals" } : /* istanbul ignore next */ {}), transform: (value) => {
293
- const num = Math.trunc(value);
294
- if (!Number.isFinite(num) || num < 0) {
295
- return 0;
296
- }
297
- return Math.min(20, num);
298
- } });
299
- /**
300
- * @description Sets whether the input is disabled.
301
- */
302
- this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
303
- /**
304
- * @description Emits when focus leaves the component, after the value has been clamped to the bounds. Moving
305
- * focus between the input and elements inside the component (such as a prefix template) doesn't count.
306
- */
307
- this.inputBlur = output();
308
- /**
309
- * @description Emits when the inner input element is focused.
310
- */
311
- this.inputFocus = output();
312
- /**
313
- * @description Emits when the inner input element loses focus.
314
- */
315
- this.inputFocusOut = output();
316
- /**
317
- * @description ID of the inner input, so a `<label for>` or `<mona-label for>` can point at it.
318
- * @default a generated ID
319
- */
320
- this.inputId = input(createElementControlId(), /* @ts-ignore */
321
- ...(ngDevMode ? [{ debugName: "inputId" }] : /* istanbul ignore next */ []));
322
- /**
323
- * @description Marks the text box as invalid. When bound to a signal form field via `[formField]`,
324
- * this is written by the `FormField` directive.
325
- * @default false
326
- */
327
- this.invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
328
- /**
329
- * @description Sets whether the input can be empty. When `false`, leaving an empty field sets it to the
330
- * minimum, or to zero when there is no minimum (clamped to the maximum).
331
- */
332
- this.nullable = input(true, { ...(ngDevMode ? { debugName: "nullable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
333
- /**
334
- * @description Text shown in the input while it is empty. It isn't a label: it disappears once there is a
335
- * value.
336
- * @default ""
337
- */
338
- this.placeholder = input("", /* @ts-ignore */
339
- ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
340
- /**
341
- * @description Sets whether the input is readonly. The spin buttons are hidden while it is.
342
- */
343
- this.readonly = input(false, { ...(ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
344
- /**
345
- * @description Sets whether the input is required.
346
- */
347
- this.required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
348
- /**
349
- * @description Sets the border radius of the input.
350
- */
351
- this.rounded = input(`medium`, /* @ts-ignore */
352
- ...(ngDevMode ? [{ debugName: "rounded" }] : /* istanbul ignore next */ []));
353
- /**
354
- * @description Sets the size of the input.
355
- */
356
- this.size = input(`medium`, /* @ts-ignore */
357
- ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
358
- /**
359
- * @description Sets whether the spin buttons are visible.
360
- */
361
- this.spinners = input(true, { ...(ngDevMode ? { debugName: "spinners" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
362
- /**
363
- * @description Tab index of the input.
364
- */
365
- this.tabindex = input(0, /* @ts-ignore */
366
- ...(ngDevMode ? [{ debugName: "tabindex" }] : /* istanbul ignore next */ []));
367
- /**
368
- * @description Emitted when focus leaves the component, as a native input is touched on blur. Typing and
369
- * spinning don't count. The `FormField` directive listens to this to mark the field as touched.
370
- */
371
- this.touch = output();
372
- /**
373
- * @description Sets the touched state of the text box. When bound to a signal form field via `[formField]`,
374
- * this is written by the `FormField` directive.
375
- * @default false
376
- */
377
- this.touched = input(false, { ...(ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
378
- /**
379
- * @description Additional CSS classes merged onto the host element via `tailwind-merge`.
380
- * @default ""
381
- */
382
- this.userClass = input("", { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: "class" });
383
- effect(() => {
384
- const value = this.value();
385
- untracked(() => {
386
- if (value === this.#ownValue) {
387
- return;
388
- }
389
- // Set from outside (a form patch, a binding): show it, even while the user is in the field.
390
- this.#ownValue = value;
391
- if (this.focused() && !this.readonly()) {
392
- this.rawInputValue.set(this.formatEditValue(value));
393
- }
394
- });
395
- });
396
- effect(() => {
397
- this.#i18n.localeId();
398
- untracked(() => {
399
- if (this.focused() && !this.readonly()) {
400
- this.rawInputValue.set(this.formatEditValue(this.value()));
401
- }
402
- });
403
- });
404
- afterNextRender({
405
- read: () => {
406
- this.setSubscriptions();
407
- this.rawInputValue.set(this.formatValueForDisplay(this.value()));
408
- this.#focusMonitor
409
- .monitor(this.#hostElementRef, true)
410
- .pipe(takeUntilDestroyed(this.#destroyRef))
411
- .subscribe((focusOrigin) => {
412
- const isFocused = focusOrigin !== null;
413
- this.focused.set(isFocused);
414
- if (isFocused && !this.readonly()) {
415
- const currentValue = this.value();
416
- const rawValue = this.formatEditValue(currentValue);
417
- this.rawInputValue.set(rawValue);
418
- }
419
- });
420
- }
421
- });
422
- this.#destroyRef.onDestroy(() => this.#focusMonitor.stopMonitoring(this.#hostElementRef.nativeElement));
423
- }
424
- /** Steps the value down by `step` and moves focus to the input. */
425
- decrease() {
426
- this.spinValue("-");
427
- this.focus();
428
- }
429
- /**
430
- * Moves focus to the input, with the caret at the end.
431
- * @param options passed to the native `focus()` call, for example `{ preventScroll: true }`.
432
- */
433
- focus(options) {
434
- this.#focusMonitor.focusVia(this.valueTextBoxRef(), "keyboard", options);
435
- rxTimeout(this.#destroyRef, () => {
436
- this.valueTextBoxRef().nativeElement.scrollLeft = this.valueTextBoxRef().nativeElement.scrollWidth;
437
- });
438
- }
439
- /** Steps the value up by `step` and moves focus to the input. */
440
- increase() {
441
- this.spinValue("+");
442
- this.focus();
443
- }
444
- /** Runs when focus leaves an element inside the component: clamps the value and marks the field touched. */
445
- onBlur(event) {
446
- // Removing a focused text box from the page fires focusout after it is destroyed.
447
- if (this.#destroyRef.destroyed) {
448
- return;
449
- }
450
- this.#pendingPaste = false;
451
- const relatedTarget = event.relatedTarget;
452
- if (relatedTarget instanceof Node && this.#hostElementRef.nativeElement.contains(relatedTarget)) {
453
- return;
454
- }
455
- this.correctValue();
456
- this.rawInputValue.set(this.formatValueForDisplay(this.value()));
457
- this.touch.emit();
458
- this.inputBlur.emit(event);
459
- }
460
- applyRawValue(text) {
461
- this.rawInputValue.set(text);
462
- this.valueChange$.next(text);
463
- }
464
- onPaste(event) {
465
- const pastedText = event.clipboardData?.getData("text/plain");
466
- if (pastedText == null) {
467
- this.#pendingPaste = false;
468
- return;
469
- }
470
- const inputElement = this.valueTextBoxRef()?.nativeElement;
471
- if (!inputElement) {
472
- this.#pendingPaste = false;
473
- return;
474
- }
475
- const { value, selectionStart, selectionEnd } = inputElement;
476
- const start = selectionStart ?? value.length;
477
- const end = selectionEnd ?? value.length;
478
- const proposedValue = value.slice(0, start) + pastedText + value.slice(end);
479
- const validation = this.readLocaleText(proposedValue, this.#i18n.localeId(), this.decimals());
480
- if (!validation.valid || validation.value === null) {
481
- event.preventDefault();
482
- this.#pendingPaste = false;
483
- return;
484
- }
485
- this.#pendingPaste = true;
486
- }
487
- onSpinPointerDown(event, direction) {
488
- // Only the primary button spins: a right-click opens the context menu and would never see a pointerup.
489
- if (event.button !== 0) {
490
- return;
491
- }
492
- this.spin$.next(direction);
493
- }
494
- /** Limits a value to the min and max bounds. */
495
- clampValue(value) {
496
- const min = this.minValue();
497
- const max = this.maxValue();
498
- if (min != null && this.compareValues(value, min) < 0) {
499
- return min;
500
- }
501
- if (max != null && this.compareValues(value, max) > 0) {
502
- return max;
503
- }
504
- return value;
505
- }
506
- commitValue(value) {
507
- this.setOwnValue(value);
508
- this.rawInputValue.set(this.focused() && !this.readonly() ? this.formatEditValue(value) : this.formatValueForDisplay(value));
509
- }
510
- correctValue() {
511
- const value = this.value();
512
- if (value == null) {
513
- if (this.nullable()) {
514
- if (this.rawInputValue() !== "") {
515
- this.rawInputValue.set("");
516
- }
517
- return;
518
- }
519
- this.commitValue(this.clampValue(this.minValue() ?? this.zeroValue));
520
- return;
521
- }
522
- const clamped = this.clampValue(value);
523
- if (this.compareValues(clamped, value) !== 0) {
524
- this.commitValue(clamped);
525
- }
526
- }
527
- formatEditValue(value) {
528
- if (value == null) {
529
- return "";
530
- }
531
- return formatNumber(value, this.#i18n.localeId(), {
532
- maximumFractionDigits: this.editFractionDigits,
533
- useGrouping: false
534
- });
535
- }
536
- formatValueForDisplay(value) {
537
- if (value == null) {
538
- return "";
539
- }
540
- const formatter = this.formatter();
541
- if (formatter) {
542
- return formatter(value);
543
- }
544
- const decimals = this.decimals();
545
- return formatNumber(value, this.#i18n.localeId(), {
546
- minimumFractionDigits: decimals,
547
- maximumFractionDigits: decimals,
548
- useGrouping: false
549
- });
550
- }
551
- /**
552
- * The numpad decimal key types "." or "," depending on the keyboard layout, not the locale. Insert the
553
- * locale's decimal separator instead, so a de-DE layout used with an en-US locale still types a decimal.
554
- */
555
- insertLocaleDecimal(event) {
556
- const localeId = this.#i18n.localeId();
557
- const decimal = getNumberSymbols(localeId).decimal;
558
- if (event.key.length !== 1 || event.key === decimal || event.ctrlKey || event.altKey || event.metaKey) {
559
- return;
560
- }
561
- event.preventDefault();
562
- const inputElement = this.valueTextBoxRef().nativeElement;
563
- const { value, selectionStart, selectionEnd } = inputElement;
564
- const start = selectionStart ?? value.length;
565
- const end = selectionEnd ?? value.length;
566
- const proposedValue = value.slice(0, start) + decimal + value.slice(end);
567
- if (!this.readEditText(proposedValue, localeId, this.decimals()).valid) {
568
- return;
569
- }
570
- inputElement.setRangeText(decimal, start, end, "end");
571
- inputElement.dispatchEvent(new Event("input", { bubbles: true }));
572
- }
573
- parseValue(value) {
574
- const raw = value == null ? "" : value;
575
- this.rawInputValue.set(raw);
576
- const isPaste = this.#pendingPaste;
577
- this.#pendingPaste = false;
578
- if (isPaste) {
579
- const validation = this.readLocaleText(raw, this.#i18n.localeId(), this.decimals());
580
- return validation.valid && validation.value !== null ? validation.value : this.value();
581
- }
582
- if (raw === "") {
583
- return null;
584
- }
585
- if (raw.trim() !== raw) {
586
- return this.value();
587
- }
588
- const edit = this.readEditText(raw, this.#i18n.localeId(), this.decimals());
589
- if (edit.valid) {
590
- return edit.value === null ? this.value() : edit.value;
591
- }
592
- const localeValidation = this.readLocaleText(raw, this.#i18n.localeId(), this.decimals());
593
- if (localeValidation.valid && localeValidation.value !== null) {
594
- return localeValidation.value;
595
- }
596
- return this.value();
597
- }
598
- setBeforeInputSubscription() {
599
- this.beforeInput$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((event) => {
600
- const inputElement = event.target;
601
- const isPaste = event.inputType === "insertFromPaste" || (this.#pendingPaste && event.inputType !== "insertText");
602
- if (!isPaste) {
603
- this.#pendingPaste = false;
604
- }
605
- const insertedText = event.data ?? event.dataTransfer?.getData("text/plain");
606
- if (insertedText == null) {
607
- return;
608
- }
609
- const { value, selectionStart, selectionEnd } = inputElement;
610
- if (selectionStart == null || selectionEnd == null) {
611
- return;
612
- }
613
- const proposedValue = value.slice(0, selectionStart) + insertedText + value.slice(selectionEnd);
614
- const localeId = this.#i18n.localeId();
615
- const decimals = this.decimals();
616
- if (isPaste) {
617
- const validation = this.readLocaleText(proposedValue, localeId, decimals);
618
- if (!validation.valid || validation.value === null) {
619
- event.preventDefault();
620
- this.#pendingPaste = false;
621
- }
622
- else {
623
- this.#pendingPaste = true;
624
- }
625
- return;
626
- }
627
- this.#pendingPaste = false;
628
- if (!this.readEditText(proposedValue, localeId, decimals).valid) {
629
- event.preventDefault();
630
- }
631
- });
632
- }
633
- setKeydownSubscription() {
634
- this.keydown$
635
- .pipe(takeUntilDestroyed(this.#destroyRef),
636
- // Keys pressed while an IME is composing belong to the IME (Safari reports them as keyCode 229).
637
- filter(event => !event.isComposing && event.keyCode !== 229), filter(() => !this.readonly() && !this.effectiveDisabled()))
638
- .subscribe((event) => {
639
- switch (event.key) {
640
- case "ArrowUp":
641
- event.preventDefault();
642
- this.increase();
643
- return;
644
- case "ArrowDown":
645
- event.preventDefault();
646
- this.decrease();
647
- return;
648
- case "PageUp":
649
- event.preventDefault();
650
- this.spinValue("+", PAGE_STEP_COUNT);
651
- return;
652
- case "PageDown":
653
- event.preventDefault();
654
- this.spinValue("-", PAGE_STEP_COUNT);
655
- return;
656
- case "Home":
657
- // Without a minimum, Home keeps moving the caret.
658
- this.spinToBound(event, this.minValue());
659
- return;
660
- case "End":
661
- this.spinToBound(event, this.maxValue());
662
- return;
663
- }
664
- if (event.code === "NumpadDecimal") {
665
- this.insertLocaleDecimal(event);
666
- }
667
- });
668
- }
669
- setOwnValue(value) {
670
- this.#ownValue = value;
671
- this.value.set(value);
672
- }
673
- setSpinSubscription() {
674
- this.spin$
675
- .pipe(filter(() => !this.readonly() && !this.effectiveDisabled()), switchMap(sign => of(sign).pipe(tap(sign => (sign === "-" ? this.decrease() : this.increase())), delay(300), concatMap(() => timer(0, 30).pipe(tap(() => (sign === "-" ? this.decrease() : this.increase())), takeUntil(this.spinStop$))), takeUntil(this.spinStop$))), takeUntilDestroyed(this.#destroyRef))
676
- .subscribe();
677
- }
678
- setSubscriptions() {
679
- this.setValueChangeSubscription();
680
- this.setKeydownSubscription();
681
- this.setSpinSubscription();
682
- this.setWheelSubscription();
683
- this.setBeforeInputSubscription();
684
- }
685
- setValueChangeSubscription() {
686
- this.valueChange$
687
- .pipe(takeUntilDestroyed(this.#destroyRef), map(v => this.parseValue(v)))
688
- .subscribe(value => this.setOwnValue(value));
689
- }
690
- setWheelSubscription() {
691
- this.wheel$
692
- .pipe(takeUntilDestroyed(this.#destroyRef),
693
- // The wheel spins only the field being edited: scrolling the page over an unfocused field, a
694
- // horizontal scroll and Ctrl+wheel (zoom) are left to the browser.
695
- filter(event => this.focused() && event.deltaY !== 0 && !event.ctrlKey), filter(() => !this.readonly() && !this.effectiveDisabled()))
696
- .subscribe((event) => {
697
- event.preventDefault();
698
- this.spinValue(event.deltaY < 0 ? "+" : "-");
699
- });
700
- }
701
- spinToBound(event, bound) {
702
- if (bound == null) {
703
- return;
704
- }
705
- event.preventDefault();
706
- this.commitValue(bound);
707
- }
708
- spinValue(direction, steps = 1) {
709
- const value = this.value();
710
- if (value == null) {
711
- this.commitValue(this.clampValue(this.zeroValue));
712
- return;
713
- }
714
- let result = value;
715
- for (let index = 0; index < steps; index++) {
716
- result = this.stepValue(result, direction);
717
- }
718
- // A value outside the bounds (set from outside) comes back inside them in the direction of the step.
719
- this.commitValue(this.clampValue(result));
720
- }
721
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NumericTextBoxBaseComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
722
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "22.0.6", type: NumericTextBoxBaseComponent, isStandalone: true, inputs: { ariaDescribedBy: { classPropertyName: "ariaDescribedBy", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, decimals: { classPropertyName: "decimals", publicName: "decimals", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, inputId: { classPropertyName: "inputId", publicName: "inputId", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, nullable: { classPropertyName: "nullable", publicName: "nullable", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, spinners: { classPropertyName: "spinners", publicName: "spinners", isSignal: true, isRequired: false, transformFunction: null }, tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { inputBlur: "inputBlur", inputFocus: "inputFocus", inputFocusOut: "inputFocusOut", touch: "touch" }, host: { listeners: { "focusout": "onBlur($event)" }, properties: { "attr.aria-describedby": "null", "attr.aria-label": "null", "attr.aria-labelledby": "null", "class": "classes()", "attr.data-disabled": "effectiveDisabled() || null", "attr.data-invalid": "invalidInput() || null", "attr.data-readonly": "readonly() || null", "attr.data-required": "required() || null" } }, queries: [{ propertyName: "prefixTemplateList", predicate: NumericTextBoxPrefixTemplateDirective, read: TemplateRef, isSignal: true }], viewQueries: [{ propertyName: "valueTextBoxRef", first: true, predicate: ["valueTextBox"], descendants: true, isSignal: true }], ngImport: i0 }); }
723
- }
724
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NumericTextBoxBaseComponent, decorators: [{
725
- type: Directive,
726
- args: [{
727
- host: {
728
- // The host has no role: the inner input is the spinbutton and carries the name, description and state. A
729
- // static aria-* attribute written on the host element would otherwise stay on the host as well.
730
- "[attr.aria-describedby]": "null",
731
- "[attr.aria-label]": "null",
732
- "[attr.aria-labelledby]": "null",
733
- "[class]": "classes()",
734
- "[attr.data-disabled]": "effectiveDisabled() || null",
735
- "[attr.data-invalid]": "invalidInput() || null",
736
- "[attr.data-readonly]": "readonly() || null",
737
- "[attr.data-required]": "required() || null",
738
- "(focusout)": "onBlur($event)"
739
- }
740
- }]
741
- }], ctorParameters: () => [], propDecorators: { prefixTemplateList: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => NumericTextBoxPrefixTemplateDirective), { ...{
742
- read: TemplateRef
743
- }, isSignal: true }] }], valueTextBoxRef: [{ type: i0.ViewChild, args: ["valueTextBox", { isSignal: true }] }], ariaDescribedBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-describedby", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], decimals: [{ type: i0.Input, args: [{ isSignal: true, alias: "decimals", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], inputBlur: [{ type: i0.Output, args: ["inputBlur"] }], inputFocus: [{ type: i0.Output, args: ["inputFocus"] }], inputFocusOut: [{ type: i0.Output, args: ["inputFocusOut"] }], inputId: [{ type: i0.Input, args: [{ isSignal: true, alias: "inputId", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], nullable: [{ type: i0.Input, args: [{ isSignal: true, alias: "nullable", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], spinners: [{ type: i0.Input, args: [{ isSignal: true, alias: "spinners", required: false }] }], tabindex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabindex", required: false }] }], touch: [{ type: i0.Output, args: ["touch"] }], touched: [{ type: i0.Input, args: [{ isSignal: true, alias: "touched", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }] } });
744
-
196
+ var NumericTextBoxBaseComponent = class NumericTextBoxBaseComponent {
197
+ #destroyRef;
198
+ #focusMonitor;
199
+ #hostElementRef;
200
+ #i18n;
201
+ #ownValue;
202
+ #pendingPaste;
203
+ constructor() {
204
+ this.#destroyRef = inject(DestroyRef);
205
+ this.#focusMonitor = inject(FocusMonitor);
206
+ this.#hostElementRef = inject(ElementRef);
207
+ this.#i18n = inject(MonaI18nService);
208
+ this.#ownValue = void 0;
209
+ this.#pendingPaste = false;
210
+ this.beforeInput$ = new Subject();
211
+ this.classes = computed(() => {
212
+ const rounded = this.rounded();
213
+ const size = this.size();
214
+ const classes = numericTextboxThemeVariants({
215
+ rounded,
216
+ size
217
+ });
218
+ const userClass = this.userClass();
219
+ return twMerge(classes, userClass);
220
+ }, ...ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []);
221
+ this.effectiveDisabled = injectEffectiveDisabled(() => this.disabled());
222
+ this.focused = signal(false, ...ngDevMode ? [{ debugName: "focused" }] : /* istanbul ignore next */ []);
223
+ this.formattedValue = computed(() => {
224
+ if (this.focused() && !this.readonly()) return this.rawInputValue();
225
+ return this.formatValueForDisplay(this.value());
226
+ }, ...ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []);
227
+ this.inputClasses = computed(() => {
228
+ const startRounded = this.prefixTemplateList().length > 0 ? "none" : this.rounded();
229
+ const endRounded = this.showSpinners() ? "none" : this.rounded();
230
+ const inputVariants = numericTextboxInputThemeVariants({
231
+ endRounded,
232
+ startRounded
233
+ });
234
+ return twMerge(inputVariants);
235
+ }, ...ngDevMode ? [{ debugName: "inputClasses" }] : /* istanbul ignore next */ []);
236
+ this.invalidInput = computed(() => this.touched() && (this.invalid() || this.required() && this.value() == null), ...ngDevMode ? [{ debugName: "invalidInput" }] : /* istanbul ignore next */ []);
237
+ this.keydown$ = new Subject();
238
+ this.messages = this.#i18n.componentMessages("numericTextBox", NUMERIC_TEXT_BOX_DEFAULT_MESSAGES);
239
+ this.prefixTemplateList = contentChildren(NumericTextBoxPrefixTemplateDirective, {
240
+ ...ngDevMode ? { debugName: "prefixTemplateList" } : /* istanbul ignore next */ {},
241
+ read: TemplateRef
242
+ });
243
+ this.rawInputValue = signal("", ...ngDevMode ? [{ debugName: "rawInputValue" }] : /* istanbul ignore next */ []);
244
+ this.showSpinners = computed(() => this.spinners() && !this.readonly(), ...ngDevMode ? [{ debugName: "showSpinners" }] : /* istanbul ignore next */ []);
245
+ this.spin$ = new Subject();
246
+ this.spinButtonClasses = computed(() => {
247
+ const size = this.size();
248
+ return numericTextboxButtonThemeVariants({ size });
249
+ }, ...ngDevMode ? [{ debugName: "spinButtonClasses" }] : /* istanbul ignore next */ []);
250
+ this.spinButtonIconSize = computed(() => {
251
+ const size = this.size();
252
+ return size === "large" ? 20 : size === "medium" ? 16 : 14;
253
+ }, ...ngDevMode ? [{ debugName: "spinButtonIconSize" }] : /* istanbul ignore next */ []);
254
+ this.spinStop$ = new Subject();
255
+ this.valueChange$ = new Subject();
256
+ this.valueTextBoxRef = viewChild.required("valueTextBox", ...ngDevMode ? [{ debugName: "valueTextBoxRef" }] : /* istanbul ignore next */ []);
257
+ this.wheel$ = new Subject();
258
+ this.ariaDescribedBy = input("", {
259
+ ...ngDevMode ? { debugName: "ariaDescribedBy" } : /* istanbul ignore next */ {},
260
+ alias: "aria-describedby"
261
+ });
262
+ this.ariaLabel = input(null, {
263
+ ...ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {},
264
+ alias: "aria-label"
265
+ });
266
+ this.ariaLabelledBy = input("", {
267
+ ...ngDevMode ? { debugName: "ariaLabelledBy" } : /* istanbul ignore next */ {},
268
+ alias: "aria-labelledby"
269
+ });
270
+ this.decimals = input(0, {
271
+ ...ngDevMode ? { debugName: "decimals" } : /* istanbul ignore next */ {},
272
+ transform: (value) => {
273
+ const num = Math.trunc(value);
274
+ if (!Number.isFinite(num) || num < 0) return 0;
275
+ return Math.min(20, num);
276
+ }
277
+ });
278
+ this.disabled = input(false, {
279
+ ...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
280
+ transform: booleanAttribute
281
+ });
282
+ this.inputBlur = output();
283
+ this.inputFocus = output();
284
+ this.inputFocusOut = output();
285
+ this.inputId = input(createElementControlId(), ...ngDevMode ? [{ debugName: "inputId" }] : /* istanbul ignore next */ []);
286
+ this.invalid = input(false, {
287
+ ...ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {},
288
+ transform: booleanAttribute
289
+ });
290
+ this.nullable = input(true, {
291
+ ...ngDevMode ? { debugName: "nullable" } : /* istanbul ignore next */ {},
292
+ transform: booleanAttribute
293
+ });
294
+ this.placeholder = input("", ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
295
+ this.readonly = input(false, {
296
+ ...ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {},
297
+ transform: booleanAttribute
298
+ });
299
+ this.required = input(false, {
300
+ ...ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {},
301
+ transform: booleanAttribute
302
+ });
303
+ this.rounded = input(`medium`, ...ngDevMode ? [{ debugName: "rounded" }] : /* istanbul ignore next */ []);
304
+ this.size = input(`medium`, ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
305
+ this.spinners = input(true, {
306
+ ...ngDevMode ? { debugName: "spinners" } : /* istanbul ignore next */ {},
307
+ transform: booleanAttribute
308
+ });
309
+ this.tabindex = input(0, ...ngDevMode ? [{ debugName: "tabindex" }] : /* istanbul ignore next */ []);
310
+ this.touch = output();
311
+ this.touched = input(false, {
312
+ ...ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {},
313
+ transform: booleanAttribute
314
+ });
315
+ this.userClass = input("", {
316
+ ...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
317
+ alias: "class"
318
+ });
319
+ effect(() => {
320
+ const value = this.value();
321
+ untracked(() => {
322
+ if (value === this.#ownValue) return;
323
+ this.#ownValue = value;
324
+ if (this.focused() && !this.readonly()) this.rawInputValue.set(this.formatEditValue(value));
325
+ });
326
+ });
327
+ effect(() => {
328
+ this.#i18n.localeId();
329
+ untracked(() => {
330
+ if (this.focused() && !this.readonly()) this.rawInputValue.set(this.formatEditValue(this.value()));
331
+ });
332
+ });
333
+ afterNextRender({ read: () => {
334
+ this.setSubscriptions();
335
+ this.rawInputValue.set(this.formatValueForDisplay(this.value()));
336
+ this.#focusMonitor.monitor(this.#hostElementRef, true).pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((focusOrigin) => {
337
+ const isFocused = focusOrigin !== null;
338
+ this.focused.set(isFocused);
339
+ if (isFocused && !this.readonly()) {
340
+ const currentValue = this.value();
341
+ const rawValue = this.formatEditValue(currentValue);
342
+ this.rawInputValue.set(rawValue);
343
+ }
344
+ });
345
+ } });
346
+ this.#destroyRef.onDestroy(() => this.#focusMonitor.stopMonitoring(this.#hostElementRef.nativeElement));
347
+ }
348
+ decrease() {
349
+ this.spinValue("-");
350
+ this.focus();
351
+ }
352
+ focus(options) {
353
+ this.#focusMonitor.focusVia(this.valueTextBoxRef(), "keyboard", options);
354
+ rxTimeout(this.#destroyRef, () => {
355
+ this.valueTextBoxRef().nativeElement.scrollLeft = this.valueTextBoxRef().nativeElement.scrollWidth;
356
+ });
357
+ }
358
+ increase() {
359
+ this.spinValue("+");
360
+ this.focus();
361
+ }
362
+ onBlur(event) {
363
+ if (this.#destroyRef.destroyed) return;
364
+ this.#pendingPaste = false;
365
+ const relatedTarget = event.relatedTarget;
366
+ if (relatedTarget instanceof Node && this.#hostElementRef.nativeElement.contains(relatedTarget)) return;
367
+ this.correctValue();
368
+ this.rawInputValue.set(this.formatValueForDisplay(this.value()));
369
+ this.touch.emit();
370
+ this.inputBlur.emit(event);
371
+ }
372
+ applyRawValue(text) {
373
+ this.rawInputValue.set(text);
374
+ this.valueChange$.next(text);
375
+ }
376
+ onPaste(event) {
377
+ const pastedText = event.clipboardData?.getData("text/plain");
378
+ if (pastedText == null) {
379
+ this.#pendingPaste = false;
380
+ return;
381
+ }
382
+ const inputElement = this.valueTextBoxRef()?.nativeElement;
383
+ if (!inputElement) {
384
+ this.#pendingPaste = false;
385
+ return;
386
+ }
387
+ const { value, selectionStart, selectionEnd } = inputElement;
388
+ const start = selectionStart ?? value.length;
389
+ const end = selectionEnd ?? value.length;
390
+ const proposedValue = value.slice(0, start) + pastedText + value.slice(end);
391
+ const validation = this.readLocaleText(proposedValue, this.#i18n.localeId(), this.decimals());
392
+ if (!validation.valid || validation.value === null) {
393
+ event.preventDefault();
394
+ this.#pendingPaste = false;
395
+ return;
396
+ }
397
+ this.#pendingPaste = true;
398
+ }
399
+ onSpinPointerDown(event, direction) {
400
+ if (event.button !== 0) return;
401
+ this.spin$.next(direction);
402
+ }
403
+ clampValue(value) {
404
+ const min = this.minValue();
405
+ const max = this.maxValue();
406
+ if (min != null && this.compareValues(value, min) < 0) return min;
407
+ if (max != null && this.compareValues(value, max) > 0) return max;
408
+ return value;
409
+ }
410
+ commitValue(value) {
411
+ this.setOwnValue(value);
412
+ this.rawInputValue.set(this.focused() && !this.readonly() ? this.formatEditValue(value) : this.formatValueForDisplay(value));
413
+ }
414
+ correctValue() {
415
+ const value = this.value();
416
+ if (value == null) {
417
+ if (this.nullable()) {
418
+ if (this.rawInputValue() !== "") this.rawInputValue.set("");
419
+ return;
420
+ }
421
+ this.commitValue(this.clampValue(this.minValue() ?? this.zeroValue));
422
+ return;
423
+ }
424
+ const clamped = this.clampValue(value);
425
+ if (this.compareValues(clamped, value) !== 0) this.commitValue(clamped);
426
+ }
427
+ formatEditValue(value) {
428
+ if (value == null) return "";
429
+ return formatNumber(value, this.#i18n.localeId(), {
430
+ maximumFractionDigits: this.editFractionDigits,
431
+ useGrouping: false
432
+ });
433
+ }
434
+ formatValueForDisplay(value) {
435
+ if (value == null) return "";
436
+ const formatter = this.formatter();
437
+ if (formatter) return formatter(value);
438
+ const decimals = this.decimals();
439
+ return formatNumber(value, this.#i18n.localeId(), {
440
+ minimumFractionDigits: decimals,
441
+ maximumFractionDigits: decimals,
442
+ useGrouping: false
443
+ });
444
+ }
445
+ insertLocaleDecimal(event) {
446
+ const localeId = this.#i18n.localeId();
447
+ const decimal = getNumberSymbols(localeId).decimal;
448
+ if (event.key.length !== 1 || event.key === decimal || event.ctrlKey || event.altKey || event.metaKey) return;
449
+ event.preventDefault();
450
+ const inputElement = this.valueTextBoxRef().nativeElement;
451
+ const { value, selectionStart, selectionEnd } = inputElement;
452
+ const start = selectionStart ?? value.length;
453
+ const end = selectionEnd ?? value.length;
454
+ const proposedValue = value.slice(0, start) + decimal + value.slice(end);
455
+ if (!this.readEditText(proposedValue, localeId, this.decimals()).valid) return;
456
+ inputElement.setRangeText(decimal, start, end, "end");
457
+ inputElement.dispatchEvent(new Event("input", { bubbles: true }));
458
+ }
459
+ parseValue(value) {
460
+ const raw = value == null ? "" : value;
461
+ this.rawInputValue.set(raw);
462
+ const isPaste = this.#pendingPaste;
463
+ this.#pendingPaste = false;
464
+ if (isPaste) {
465
+ const validation = this.readLocaleText(raw, this.#i18n.localeId(), this.decimals());
466
+ return validation.valid && validation.value !== null ? validation.value : this.value();
467
+ }
468
+ if (raw === "") return null;
469
+ if (raw.trim() !== raw) return this.value();
470
+ const edit = this.readEditText(raw, this.#i18n.localeId(), this.decimals());
471
+ if (edit.valid) return edit.value === null ? this.value() : edit.value;
472
+ const localeValidation = this.readLocaleText(raw, this.#i18n.localeId(), this.decimals());
473
+ if (localeValidation.valid && localeValidation.value !== null) return localeValidation.value;
474
+ return this.value();
475
+ }
476
+ setBeforeInputSubscription() {
477
+ this.beforeInput$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((event) => {
478
+ const inputElement = event.target;
479
+ const isPaste = event.inputType === "insertFromPaste" || this.#pendingPaste && event.inputType !== "insertText";
480
+ if (!isPaste) this.#pendingPaste = false;
481
+ const insertedText = event.data ?? event.dataTransfer?.getData("text/plain");
482
+ if (insertedText == null) return;
483
+ const { value, selectionStart, selectionEnd } = inputElement;
484
+ if (selectionStart == null || selectionEnd == null) return;
485
+ const proposedValue = value.slice(0, selectionStart) + insertedText + value.slice(selectionEnd);
486
+ const localeId = this.#i18n.localeId();
487
+ const decimals = this.decimals();
488
+ if (isPaste) {
489
+ const validation = this.readLocaleText(proposedValue, localeId, decimals);
490
+ if (!validation.valid || validation.value === null) {
491
+ event.preventDefault();
492
+ this.#pendingPaste = false;
493
+ } else this.#pendingPaste = true;
494
+ return;
495
+ }
496
+ this.#pendingPaste = false;
497
+ if (!this.readEditText(proposedValue, localeId, decimals).valid) event.preventDefault();
498
+ });
499
+ }
500
+ setKeydownSubscription() {
501
+ this.keydown$.pipe(takeUntilDestroyed(this.#destroyRef), filter((event) => !event.isComposing && event.keyCode !== 229), filter(() => !this.readonly() && !this.effectiveDisabled())).subscribe((event) => {
502
+ switch (event.key) {
503
+ case "ArrowUp":
504
+ event.preventDefault();
505
+ this.increase();
506
+ return;
507
+ case "ArrowDown":
508
+ event.preventDefault();
509
+ this.decrease();
510
+ return;
511
+ case "PageUp":
512
+ event.preventDefault();
513
+ this.spinValue("+", PAGE_STEP_COUNT);
514
+ return;
515
+ case "PageDown":
516
+ event.preventDefault();
517
+ this.spinValue("-", PAGE_STEP_COUNT);
518
+ return;
519
+ case "Home":
520
+ this.spinToBound(event, this.minValue());
521
+ return;
522
+ case "End":
523
+ this.spinToBound(event, this.maxValue());
524
+ return;
525
+ }
526
+ if (event.code === "NumpadDecimal") this.insertLocaleDecimal(event);
527
+ });
528
+ }
529
+ setOwnValue(value) {
530
+ this.#ownValue = value;
531
+ this.value.set(value);
532
+ }
533
+ setSpinSubscription() {
534
+ this.spin$.pipe(filter(() => !this.readonly() && !this.effectiveDisabled()), switchMap((sign) => of(sign).pipe(tap((sign) => sign === "-" ? this.decrease() : this.increase()), delay(300), concatMap(() => timer(0, 30).pipe(tap(() => sign === "-" ? this.decrease() : this.increase()), takeUntil(this.spinStop$))), takeUntil(this.spinStop$))), takeUntilDestroyed(this.#destroyRef)).subscribe();
535
+ }
536
+ setSubscriptions() {
537
+ this.setValueChangeSubscription();
538
+ this.setKeydownSubscription();
539
+ this.setSpinSubscription();
540
+ this.setWheelSubscription();
541
+ this.setBeforeInputSubscription();
542
+ }
543
+ setValueChangeSubscription() {
544
+ this.valueChange$.pipe(takeUntilDestroyed(this.#destroyRef), map((v) => this.parseValue(v))).subscribe((value) => this.setOwnValue(value));
545
+ }
546
+ setWheelSubscription() {
547
+ this.wheel$.pipe(takeUntilDestroyed(this.#destroyRef), filter((event) => this.focused() && event.deltaY !== 0 && !event.ctrlKey), filter(() => !this.readonly() && !this.effectiveDisabled())).subscribe((event) => {
548
+ event.preventDefault();
549
+ this.spinValue(event.deltaY < 0 ? "+" : "-");
550
+ });
551
+ }
552
+ spinToBound(event, bound) {
553
+ if (bound == null) return;
554
+ event.preventDefault();
555
+ this.commitValue(bound);
556
+ }
557
+ spinValue(direction, steps = 1) {
558
+ const value = this.value();
559
+ if (value == null) {
560
+ this.commitValue(this.clampValue(this.zeroValue));
561
+ return;
562
+ }
563
+ let result = value;
564
+ for (let index = 0; index < steps; index++) result = this.stepValue(result, direction);
565
+ this.commitValue(this.clampValue(result));
566
+ }
567
+ static {
568
+ this.ɵfac = i0.ɵɵngDeclareFactory({
569
+ minVersion: "12.0.0",
570
+ version: "22.2.6",
571
+ ngImport: i0,
572
+ type: NumericTextBoxBaseComponent,
573
+ deps: [],
574
+ target: i0.ɵɵFactoryTarget.Directive
575
+ });
576
+ }
577
+ static {
578
+ this.ɵdir = i0.ɵɵngDeclareDirective({
579
+ minVersion: "17.2.0",
580
+ version: "22.2.6",
581
+ type: NumericTextBoxBaseComponent,
582
+ isStandalone: true,
583
+ inputs: {
584
+ ariaDescribedBy: {
585
+ classPropertyName: "ariaDescribedBy",
586
+ publicName: "aria-describedby",
587
+ isSignal: true,
588
+ isRequired: false,
589
+ transformFunction: null
590
+ },
591
+ ariaLabel: {
592
+ classPropertyName: "ariaLabel",
593
+ publicName: "aria-label",
594
+ isSignal: true,
595
+ isRequired: false,
596
+ transformFunction: null
597
+ },
598
+ ariaLabelledBy: {
599
+ classPropertyName: "ariaLabelledBy",
600
+ publicName: "aria-labelledby",
601
+ isSignal: true,
602
+ isRequired: false,
603
+ transformFunction: null
604
+ },
605
+ decimals: {
606
+ classPropertyName: "decimals",
607
+ publicName: "decimals",
608
+ isSignal: true,
609
+ isRequired: false,
610
+ transformFunction: null
611
+ },
612
+ disabled: {
613
+ classPropertyName: "disabled",
614
+ publicName: "disabled",
615
+ isSignal: true,
616
+ isRequired: false,
617
+ transformFunction: null
618
+ },
619
+ inputId: {
620
+ classPropertyName: "inputId",
621
+ publicName: "inputId",
622
+ isSignal: true,
623
+ isRequired: false,
624
+ transformFunction: null
625
+ },
626
+ invalid: {
627
+ classPropertyName: "invalid",
628
+ publicName: "invalid",
629
+ isSignal: true,
630
+ isRequired: false,
631
+ transformFunction: null
632
+ },
633
+ nullable: {
634
+ classPropertyName: "nullable",
635
+ publicName: "nullable",
636
+ isSignal: true,
637
+ isRequired: false,
638
+ transformFunction: null
639
+ },
640
+ placeholder: {
641
+ classPropertyName: "placeholder",
642
+ publicName: "placeholder",
643
+ isSignal: true,
644
+ isRequired: false,
645
+ transformFunction: null
646
+ },
647
+ readonly: {
648
+ classPropertyName: "readonly",
649
+ publicName: "readonly",
650
+ isSignal: true,
651
+ isRequired: false,
652
+ transformFunction: null
653
+ },
654
+ required: {
655
+ classPropertyName: "required",
656
+ publicName: "required",
657
+ isSignal: true,
658
+ isRequired: false,
659
+ transformFunction: null
660
+ },
661
+ rounded: {
662
+ classPropertyName: "rounded",
663
+ publicName: "rounded",
664
+ isSignal: true,
665
+ isRequired: false,
666
+ transformFunction: null
667
+ },
668
+ size: {
669
+ classPropertyName: "size",
670
+ publicName: "size",
671
+ isSignal: true,
672
+ isRequired: false,
673
+ transformFunction: null
674
+ },
675
+ spinners: {
676
+ classPropertyName: "spinners",
677
+ publicName: "spinners",
678
+ isSignal: true,
679
+ isRequired: false,
680
+ transformFunction: null
681
+ },
682
+ tabindex: {
683
+ classPropertyName: "tabindex",
684
+ publicName: "tabindex",
685
+ isSignal: true,
686
+ isRequired: false,
687
+ transformFunction: null
688
+ },
689
+ touched: {
690
+ classPropertyName: "touched",
691
+ publicName: "touched",
692
+ isSignal: true,
693
+ isRequired: false,
694
+ transformFunction: null
695
+ },
696
+ userClass: {
697
+ classPropertyName: "userClass",
698
+ publicName: "class",
699
+ isSignal: true,
700
+ isRequired: false,
701
+ transformFunction: null
702
+ }
703
+ },
704
+ outputs: {
705
+ inputBlur: "inputBlur",
706
+ inputFocus: "inputFocus",
707
+ inputFocusOut: "inputFocusOut",
708
+ touch: "touch"
709
+ },
710
+ host: {
711
+ listeners: { "focusout": "onBlur($event)" },
712
+ properties: {
713
+ "attr.aria-describedby": "null",
714
+ "attr.aria-label": "null",
715
+ "attr.aria-labelledby": "null",
716
+ "class": "classes()",
717
+ "attr.data-disabled": "effectiveDisabled() || null",
718
+ "attr.data-invalid": "invalidInput() || null",
719
+ "attr.data-readonly": "readonly() || null",
720
+ "attr.data-required": "required() || null"
721
+ }
722
+ },
723
+ queries: [{
724
+ propertyName: "prefixTemplateList",
725
+ predicate: NumericTextBoxPrefixTemplateDirective,
726
+ read: TemplateRef,
727
+ isSignal: true
728
+ }],
729
+ viewQueries: [{
730
+ propertyName: "valueTextBoxRef",
731
+ first: true,
732
+ predicate: ["valueTextBox"],
733
+ descendants: true,
734
+ isSignal: true
735
+ }],
736
+ ngImport: i0
737
+ });
738
+ }
739
+ };
740
+ i0.ɵɵngDeclareClassMetadata({
741
+ minVersion: "12.0.0",
742
+ version: "22.2.6",
743
+ ngImport: i0,
744
+ type: NumericTextBoxBaseComponent,
745
+ decorators: [{
746
+ type: Directive,
747
+ args: [{ host: {
748
+ "[attr.aria-describedby]": "null",
749
+ "[attr.aria-label]": "null",
750
+ "[attr.aria-labelledby]": "null",
751
+ "[class]": "classes()",
752
+ "[attr.data-disabled]": "effectiveDisabled() || null",
753
+ "[attr.data-invalid]": "invalidInput() || null",
754
+ "[attr.data-readonly]": "readonly() || null",
755
+ "[attr.data-required]": "required() || null",
756
+ "(focusout)": "onBlur($event)"
757
+ } }]
758
+ }],
759
+ ctorParameters: () => [],
760
+ propDecorators: {
761
+ prefixTemplateList: [{
762
+ type: i0.ContentChildren,
763
+ args: [i0.forwardRef(() => NumericTextBoxPrefixTemplateDirective), {
764
+ read: TemplateRef,
765
+ isSignal: true
766
+ }]
767
+ }],
768
+ valueTextBoxRef: [{
769
+ type: i0.ViewChild,
770
+ args: ["valueTextBox", { isSignal: true }]
771
+ }],
772
+ ariaDescribedBy: [{
773
+ type: i0.Input,
774
+ args: [{
775
+ isSignal: true,
776
+ alias: "aria-describedby",
777
+ required: false
778
+ }]
779
+ }],
780
+ ariaLabel: [{
781
+ type: i0.Input,
782
+ args: [{
783
+ isSignal: true,
784
+ alias: "aria-label",
785
+ required: false
786
+ }]
787
+ }],
788
+ ariaLabelledBy: [{
789
+ type: i0.Input,
790
+ args: [{
791
+ isSignal: true,
792
+ alias: "aria-labelledby",
793
+ required: false
794
+ }]
795
+ }],
796
+ decimals: [{
797
+ type: i0.Input,
798
+ args: [{
799
+ isSignal: true,
800
+ alias: "decimals",
801
+ required: false
802
+ }]
803
+ }],
804
+ disabled: [{
805
+ type: i0.Input,
806
+ args: [{
807
+ isSignal: true,
808
+ alias: "disabled",
809
+ required: false
810
+ }]
811
+ }],
812
+ inputBlur: [{
813
+ type: i0.Output,
814
+ args: ["inputBlur"]
815
+ }],
816
+ inputFocus: [{
817
+ type: i0.Output,
818
+ args: ["inputFocus"]
819
+ }],
820
+ inputFocusOut: [{
821
+ type: i0.Output,
822
+ args: ["inputFocusOut"]
823
+ }],
824
+ inputId: [{
825
+ type: i0.Input,
826
+ args: [{
827
+ isSignal: true,
828
+ alias: "inputId",
829
+ required: false
830
+ }]
831
+ }],
832
+ invalid: [{
833
+ type: i0.Input,
834
+ args: [{
835
+ isSignal: true,
836
+ alias: "invalid",
837
+ required: false
838
+ }]
839
+ }],
840
+ nullable: [{
841
+ type: i0.Input,
842
+ args: [{
843
+ isSignal: true,
844
+ alias: "nullable",
845
+ required: false
846
+ }]
847
+ }],
848
+ placeholder: [{
849
+ type: i0.Input,
850
+ args: [{
851
+ isSignal: true,
852
+ alias: "placeholder",
853
+ required: false
854
+ }]
855
+ }],
856
+ readonly: [{
857
+ type: i0.Input,
858
+ args: [{
859
+ isSignal: true,
860
+ alias: "readonly",
861
+ required: false
862
+ }]
863
+ }],
864
+ required: [{
865
+ type: i0.Input,
866
+ args: [{
867
+ isSignal: true,
868
+ alias: "required",
869
+ required: false
870
+ }]
871
+ }],
872
+ rounded: [{
873
+ type: i0.Input,
874
+ args: [{
875
+ isSignal: true,
876
+ alias: "rounded",
877
+ required: false
878
+ }]
879
+ }],
880
+ size: [{
881
+ type: i0.Input,
882
+ args: [{
883
+ isSignal: true,
884
+ alias: "size",
885
+ required: false
886
+ }]
887
+ }],
888
+ spinners: [{
889
+ type: i0.Input,
890
+ args: [{
891
+ isSignal: true,
892
+ alias: "spinners",
893
+ required: false
894
+ }]
895
+ }],
896
+ tabindex: [{
897
+ type: i0.Input,
898
+ args: [{
899
+ isSignal: true,
900
+ alias: "tabindex",
901
+ required: false
902
+ }]
903
+ }],
904
+ touch: [{
905
+ type: i0.Output,
906
+ args: ["touch"]
907
+ }],
908
+ touched: [{
909
+ type: i0.Input,
910
+ args: [{
911
+ isSignal: true,
912
+ alias: "touched",
913
+ required: false
914
+ }]
915
+ }],
916
+ userClass: [{
917
+ type: i0.Input,
918
+ args: [{
919
+ isSignal: true,
920
+ alias: "class",
921
+ required: false
922
+ }]
923
+ }]
924
+ }
925
+ });
745
926
  function warnInvalidDecimal(name, value) {
746
- if (typeof ngDevMode !== "undefined" && ngDevMode) {
747
- console.warn(`mona-decimal-text-box: ${name} ${JSON.stringify(value)} is not a decimal string; it is ignored.`);
748
- }
927
+ if (typeof ngDevMode !== "undefined" && ngDevMode) console.warn(`mona-decimal-text-box: ${name} ${JSON.stringify(value)} is not a decimal string; it is ignored.`);
749
928
  }
750
929
  function decimalInput(name) {
751
- return value => {
752
- const decimal = toDecimalString(value);
753
- if (decimal === null && value != null) {
754
- warnInvalidDecimal(name, value);
755
- }
756
- return decimal;
757
- };
930
+ return (value) => {
931
+ const decimal = toDecimalString(value);
932
+ if (decimal === null && value != null) warnInvalidDecimal(name, value);
933
+ return decimal;
934
+ };
758
935
  }
759
- /**
760
- * A numeric input whose value is a decimal string, for amounts a JavaScript `number` cannot hold exactly (money,
761
- * quantities with many digits, identifiers). Typing, paste, spin buttons and bounds use exact decimal arithmetic,
762
- * so there is no precision limit. The value is canonical: `"-1234.5"`, with `.` as the separator and no grouping,
763
- * exponent, leading zeros or trailing fraction zeros.
764
- */
765
- class DecimalTextBoxComponent extends NumericTextBoxBaseComponent {
766
- constructor() {
767
- super();
768
- // Intl.NumberFormat's limit: a decimal string can carry more digits than a number.
769
- this.editFractionDigits = 100;
770
- this.zeroValue = "0";
771
- /**
772
- * @description Formats the value to be displayed in the input when the input is not focused.
773
- */
774
- this.formatter = input(null, /* @ts-ignore */
775
- ...(ngDevMode ? [{ debugName: "formatter" }] : /* istanbul ignore next */ []));
776
- /**
777
- * @description Maximum value that can be entered, as a decimal string or a number.
778
- */
779
- this.maxValue = input(null, { ...(ngDevMode ? { debugName: "maxValue" } : /* istanbul ignore next */ {}), transform: decimalInput("maxValue") });
780
- /**
781
- * @description Minimum value that can be entered, as a decimal string or a number.
782
- */
783
- this.minValue = input(null, { ...(ngDevMode ? { debugName: "minValue" } : /* istanbul ignore next */ {}), transform: decimalInput("minValue") });
784
- /**
785
- * @description Step value to increment or decrement the value, as a decimal string or a number.
786
- * @default "1"
787
- */
788
- this.step = input("1", { ...(ngDevMode ? { debugName: "step" } : /* istanbul ignore next */ {}), transform: value => decimalInput("step")(value) ?? "1" });
789
- /**
790
- * @description Two-way bindable current value, as a canonical decimal string such as `"-1234.5"`.
791
- * @default null
792
- */
793
- this.value = model(null, /* @ts-ignore */
794
- ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
795
- effect(() => {
796
- const value = this.value();
797
- if (value != null && toDecimalString(value) === null) {
798
- warnInvalidDecimal("value", value);
799
- }
800
- });
801
- }
802
- compareValues(a, b) {
803
- return compareDecimals(toDecimalString(a) ?? "0", toDecimalString(b) ?? "0");
804
- }
805
- readEditText(text, localeId, decimals) {
806
- return validateLocalizedDecimalEdit(text, localeId, { decimals });
807
- }
808
- readLocaleText(text, localeId, decimals) {
809
- return validateLocalizedDecimal(text, localeId, { mode: "locale", decimals });
810
- }
811
- stepValue(value, direction) {
812
- const current = toDecimalString(value) ?? "0";
813
- return direction === "+" ? addDecimals(current, this.step()) : subtractDecimals(current, this.step());
814
- }
815
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DecimalTextBoxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
816
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: DecimalTextBoxComponent, isStandalone: true, selector: "mona-decimal-text-box", inputs: { formatter: { classPropertyName: "formatter", publicName: "formatter", isSignal: true, isRequired: false, transformFunction: null }, maxValue: { classPropertyName: "maxValue", publicName: "maxValue", isSignal: true, isRequired: false, transformFunction: null }, minValue: { classPropertyName: "minValue", publicName: "minValue", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "step", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange" }, usesInheritance: true, ngImport: i0, template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: TextBoxDirective, selector: "input[monaTextBox]", inputs: ["invalid", "rounded", "size", "touched", "class"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class", "value"], outputs: ["lookChange", "selectedChange"] }, { kind: "component", type: LucideChevronUp, selector: "svg[lucideChevronUp]" }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }] }); }
817
- }
818
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DecimalTextBoxComponent, decorators: [{
819
- type: Component,
820
- args: [{ selector: "mona-decimal-text-box", imports: [NgTemplateOutlet, TextBoxDirective, ButtonDirective, LucideChevronUp, LucideChevronDown], template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n" }]
821
- }], ctorParameters: () => [], propDecorators: { formatter: [{ type: i0.Input, args: [{ isSignal: true, alias: "formatter", required: false }] }], maxValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxValue", required: false }] }], minValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "minValue", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "step", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }] } });
822
-
823
- class NumericTextBoxComponent extends NumericTextBoxBaseComponent {
824
- constructor() {
825
- super(...arguments);
826
- this.editFractionDigits = 20;
827
- this.zeroValue = 0;
828
- /**
829
- * @description Formats the value to be displayed in the input when the input is not focused.
830
- */
831
- this.formatter = input(null, /* @ts-ignore */
832
- ...(ngDevMode ? [{ debugName: "formatter" }] : /* istanbul ignore next */ []));
833
- /**
834
- * @description Maximum value that can be entered.
835
- */
836
- this.maxValue = input(null, /* @ts-ignore */
837
- ...(ngDevMode ? [{ debugName: "maxValue" }] : /* istanbul ignore next */ []));
838
- /**
839
- * @description Minimum value that can be entered.
840
- */
841
- this.minValue = input(null, /* @ts-ignore */
842
- ...(ngDevMode ? [{ debugName: "minValue" }] : /* istanbul ignore next */ []));
843
- /**
844
- * @description Step value to increment or decrement the value.
845
- */
846
- this.step = input(1, /* @ts-ignore */
847
- ...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
848
- /**
849
- * @description Two-way bindable current value of the numeric text box.
850
- * @default null
851
- */
852
- this.value = model(null, /* @ts-ignore */
853
- ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
854
- }
855
- static calculate(value, step, type) {
856
- const precision = Math.max(NumericTextBoxComponent.getPrecision(value), NumericTextBoxComponent.getPrecision(step));
857
- const factor = Math.pow(10, precision);
858
- const signFactor = type === "+" ? 1 : -1;
859
- const newValue = (value * factor + signFactor * step * factor) / factor;
860
- return precision > 0 ? parseFloat(newValue.toFixed(precision)) : newValue;
861
- }
862
- /** The number of fraction digits, including those of exponent forms such as `1e-7`. */
863
- static getPrecision(value) {
864
- const [mantissa, exponent] = value.toString().split("e");
865
- const fractionDigits = mantissa.split(".")[1]?.length ?? 0;
866
- return Math.max(0, fractionDigits - Number(exponent ?? 0));
867
- }
868
- /** -0 reads and shows as "-0"; the field treats it as zero. */
869
- static withoutNegativeZero(result) {
870
- return Object.is(result.value, -0) ? { ...result, value: 0 } : result;
871
- }
872
- compareValues(a, b) {
873
- return a - b;
874
- }
875
- readEditText(text, localeId, decimals) {
876
- return NumericTextBoxComponent.withoutNegativeZero(validateLocalizedNumberEdit(text, localeId, { decimals }));
877
- }
878
- readLocaleText(text, localeId, decimals) {
879
- return NumericTextBoxComponent.withoutNegativeZero(validateLocalizedNumber(text, localeId, { mode: "locale", decimals }));
880
- }
881
- stepValue(value, direction) {
882
- const result = NumericTextBoxComponent.calculate(value, this.step(), direction);
883
- // Past the safe range a number can no longer hold every step exactly.
884
- const limited = Math.min(Math.max(result, Number.MIN_SAFE_INTEGER), Number.MAX_SAFE_INTEGER);
885
- // A value already past that range (set from outside) stays put rather than jumping the wrong way.
886
- if ((direction === "+" && limited < value) || (direction === "-" && limited > value)) {
887
- return value;
888
- }
889
- return limited;
890
- }
891
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NumericTextBoxComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
892
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: NumericTextBoxComponent, isStandalone: true, selector: "mona-numeric-text-box", inputs: { formatter: { classPropertyName: "formatter", publicName: "formatter", isSignal: true, isRequired: false, transformFunction: null }, maxValue: { classPropertyName: "maxValue", publicName: "maxValue", isSignal: true, isRequired: false, transformFunction: null }, minValue: { classPropertyName: "minValue", publicName: "minValue", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "step", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange" }, usesInheritance: true, ngImport: i0, template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: TextBoxDirective, selector: "input[monaTextBox]", inputs: ["invalid", "rounded", "size", "touched", "class"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class", "value"], outputs: ["lookChange", "selectedChange"] }, { kind: "component", type: LucideChevronUp, selector: "svg[lucideChevronUp]" }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }] }); }
893
- }
894
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NumericTextBoxComponent, decorators: [{
895
- type: Component,
896
- args: [{ selector: "mona-numeric-text-box", imports: [NgTemplateOutlet, TextBoxDirective, ButtonDirective, LucideChevronUp, LucideChevronDown], template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n" }]
897
- }], propDecorators: { formatter: [{ type: i0.Input, args: [{ isSignal: true, alias: "formatter", required: false }] }], maxValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxValue", required: false }] }], minValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "minValue", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "step", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }] } });
898
-
899
- /*
900
- * Public API Surface of @nanahoshi/mona-ui/numeric-text-box
901
- */
902
-
903
- /**
904
- * Generated bundle index. Do not edit.
905
- */
906
-
936
+ var DecimalTextBoxComponent = class DecimalTextBoxComponent extends NumericTextBoxBaseComponent {
937
+ constructor() {
938
+ super();
939
+ this.editFractionDigits = 100;
940
+ this.zeroValue = "0";
941
+ this.formatter = input(null, ...ngDevMode ? [{ debugName: "formatter" }] : /* istanbul ignore next */ []);
942
+ this.maxValue = input(null, {
943
+ ...ngDevMode ? { debugName: "maxValue" } : /* istanbul ignore next */ {},
944
+ transform: decimalInput("maxValue")
945
+ });
946
+ this.minValue = input(null, {
947
+ ...ngDevMode ? { debugName: "minValue" } : /* istanbul ignore next */ {},
948
+ transform: decimalInput("minValue")
949
+ });
950
+ this.step = input("1", {
951
+ ...ngDevMode ? { debugName: "step" } : /* istanbul ignore next */ {},
952
+ transform: (value) => decimalInput("step")(value) ?? "1"
953
+ });
954
+ this.value = model(null, ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
955
+ effect(() => {
956
+ const value = this.value();
957
+ if (value != null && toDecimalString(value) === null) warnInvalidDecimal("value", value);
958
+ });
959
+ }
960
+ compareValues(a, b) {
961
+ return compareDecimals(toDecimalString(a) ?? "0", toDecimalString(b) ?? "0");
962
+ }
963
+ readEditText(text, localeId, decimals) {
964
+ return validateLocalizedDecimalEdit(text, localeId, { decimals });
965
+ }
966
+ readLocaleText(text, localeId, decimals) {
967
+ return validateLocalizedDecimal(text, localeId, {
968
+ mode: "locale",
969
+ decimals
970
+ });
971
+ }
972
+ stepValue(value, direction) {
973
+ const current = toDecimalString(value) ?? "0";
974
+ return direction === "+" ? addDecimals(current, this.step()) : subtractDecimals(current, this.step());
975
+ }
976
+ static {
977
+ this.ɵfac = i0.ɵɵngDeclareFactory({
978
+ minVersion: "12.0.0",
979
+ version: "22.2.6",
980
+ ngImport: i0,
981
+ type: DecimalTextBoxComponent,
982
+ deps: [],
983
+ target: i0.ɵɵFactoryTarget.Component
984
+ });
985
+ }
986
+ static {
987
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
988
+ minVersion: "17.0.0",
989
+ version: "22.2.6",
990
+ type: DecimalTextBoxComponent,
991
+ isStandalone: true,
992
+ selector: "mona-decimal-text-box",
993
+ inputs: {
994
+ formatter: {
995
+ classPropertyName: "formatter",
996
+ publicName: "formatter",
997
+ isSignal: true,
998
+ isRequired: false,
999
+ transformFunction: null
1000
+ },
1001
+ maxValue: {
1002
+ classPropertyName: "maxValue",
1003
+ publicName: "maxValue",
1004
+ isSignal: true,
1005
+ isRequired: false,
1006
+ transformFunction: null
1007
+ },
1008
+ minValue: {
1009
+ classPropertyName: "minValue",
1010
+ publicName: "minValue",
1011
+ isSignal: true,
1012
+ isRequired: false,
1013
+ transformFunction: null
1014
+ },
1015
+ step: {
1016
+ classPropertyName: "step",
1017
+ publicName: "step",
1018
+ isSignal: true,
1019
+ isRequired: false,
1020
+ transformFunction: null
1021
+ },
1022
+ value: {
1023
+ classPropertyName: "value",
1024
+ publicName: "value",
1025
+ isSignal: true,
1026
+ isRequired: false,
1027
+ transformFunction: null
1028
+ }
1029
+ },
1030
+ outputs: { value: "valueChange" },
1031
+ usesInheritance: true,
1032
+ ngImport: i0,
1033
+ template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n",
1034
+ dependencies: [
1035
+ {
1036
+ kind: "directive",
1037
+ type: NgTemplateOutlet,
1038
+ selector: "[ngTemplateOutlet]",
1039
+ inputs: [
1040
+ "ngTemplateOutletContext",
1041
+ "ngTemplateOutlet",
1042
+ "ngTemplateOutletInjector"
1043
+ ]
1044
+ },
1045
+ {
1046
+ kind: "directive",
1047
+ type: TextBoxDirective,
1048
+ selector: "input[monaTextBox]",
1049
+ inputs: [
1050
+ "invalid",
1051
+ "rounded",
1052
+ "size",
1053
+ "touched",
1054
+ "class"
1055
+ ]
1056
+ },
1057
+ {
1058
+ kind: "directive",
1059
+ type: ButtonDirective,
1060
+ selector: "button[monaButton]",
1061
+ inputs: [
1062
+ "aria-haspopup",
1063
+ "disabled",
1064
+ "iconOnly",
1065
+ "loading",
1066
+ "look",
1067
+ "rounded",
1068
+ "selected",
1069
+ "size",
1070
+ "tabindex",
1071
+ "toggleable",
1072
+ "type",
1073
+ "class",
1074
+ "value"
1075
+ ],
1076
+ outputs: ["lookChange", "selectedChange"]
1077
+ },
1078
+ {
1079
+ kind: "component",
1080
+ type: LucideChevronUp,
1081
+ selector: "svg[lucideChevronUp]"
1082
+ },
1083
+ {
1084
+ kind: "component",
1085
+ type: LucideChevronDown,
1086
+ selector: "svg[lucideChevronDown]"
1087
+ }
1088
+ ]
1089
+ });
1090
+ }
1091
+ };
1092
+ i0.ɵɵngDeclareClassMetadata({
1093
+ minVersion: "12.0.0",
1094
+ version: "22.2.6",
1095
+ ngImport: i0,
1096
+ type: DecimalTextBoxComponent,
1097
+ decorators: [{
1098
+ type: Component,
1099
+ args: [{
1100
+ selector: "mona-decimal-text-box",
1101
+ imports: [
1102
+ NgTemplateOutlet,
1103
+ TextBoxDirective,
1104
+ ButtonDirective,
1105
+ LucideChevronUp,
1106
+ LucideChevronDown
1107
+ ],
1108
+ template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n"
1109
+ }]
1110
+ }],
1111
+ ctorParameters: () => [],
1112
+ propDecorators: {
1113
+ formatter: [{
1114
+ type: i0.Input,
1115
+ args: [{
1116
+ isSignal: true,
1117
+ alias: "formatter",
1118
+ required: false
1119
+ }]
1120
+ }],
1121
+ maxValue: [{
1122
+ type: i0.Input,
1123
+ args: [{
1124
+ isSignal: true,
1125
+ alias: "maxValue",
1126
+ required: false
1127
+ }]
1128
+ }],
1129
+ minValue: [{
1130
+ type: i0.Input,
1131
+ args: [{
1132
+ isSignal: true,
1133
+ alias: "minValue",
1134
+ required: false
1135
+ }]
1136
+ }],
1137
+ step: [{
1138
+ type: i0.Input,
1139
+ args: [{
1140
+ isSignal: true,
1141
+ alias: "step",
1142
+ required: false
1143
+ }]
1144
+ }],
1145
+ value: [{
1146
+ type: i0.Input,
1147
+ args: [{
1148
+ isSignal: true,
1149
+ alias: "value",
1150
+ required: false
1151
+ }]
1152
+ }, {
1153
+ type: i0.Output,
1154
+ args: ["valueChange"]
1155
+ }]
1156
+ }
1157
+ });
1158
+ var NumericTextBoxComponent = class NumericTextBoxComponent extends NumericTextBoxBaseComponent {
1159
+ constructor() {
1160
+ super(...arguments);
1161
+ this.editFractionDigits = 20;
1162
+ this.zeroValue = 0;
1163
+ this.formatter = input(null, ...ngDevMode ? [{ debugName: "formatter" }] : /* istanbul ignore next */ []);
1164
+ this.maxValue = input(null, ...ngDevMode ? [{ debugName: "maxValue" }] : /* istanbul ignore next */ []);
1165
+ this.minValue = input(null, ...ngDevMode ? [{ debugName: "minValue" }] : /* istanbul ignore next */ []);
1166
+ this.step = input(1, ...ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []);
1167
+ this.value = model(null, ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
1168
+ }
1169
+ static calculate(value, step, type) {
1170
+ const precision = Math.max(NumericTextBoxComponent.getPrecision(value), NumericTextBoxComponent.getPrecision(step));
1171
+ const factor = Math.pow(10, precision);
1172
+ const signFactor = type === "+" ? 1 : -1;
1173
+ const newValue = (value * factor + signFactor * step * factor) / factor;
1174
+ return precision > 0 ? parseFloat(newValue.toFixed(precision)) : newValue;
1175
+ }
1176
+ static getPrecision(value) {
1177
+ const [mantissa, exponent] = value.toString().split("e");
1178
+ const fractionDigits = mantissa.split(".")[1]?.length ?? 0;
1179
+ return Math.max(0, fractionDigits - Number(exponent ?? 0));
1180
+ }
1181
+ static withoutNegativeZero(result) {
1182
+ return Object.is(result.value, -0) ? {
1183
+ ...result,
1184
+ value: 0
1185
+ } : result;
1186
+ }
1187
+ compareValues(a, b) {
1188
+ return a - b;
1189
+ }
1190
+ readEditText(text, localeId, decimals) {
1191
+ return NumericTextBoxComponent.withoutNegativeZero(validateLocalizedNumberEdit(text, localeId, { decimals }));
1192
+ }
1193
+ readLocaleText(text, localeId, decimals) {
1194
+ return NumericTextBoxComponent.withoutNegativeZero(validateLocalizedNumber(text, localeId, {
1195
+ mode: "locale",
1196
+ decimals
1197
+ }));
1198
+ }
1199
+ stepValue(value, direction) {
1200
+ const result = NumericTextBoxComponent.calculate(value, this.step(), direction);
1201
+ const limited = Math.min(Math.max(result, Number.MIN_SAFE_INTEGER), Number.MAX_SAFE_INTEGER);
1202
+ if (direction === "+" && limited < value || direction === "-" && limited > value) return value;
1203
+ return limited;
1204
+ }
1205
+ static {
1206
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1207
+ minVersion: "12.0.0",
1208
+ version: "22.2.6",
1209
+ ngImport: i0,
1210
+ type: NumericTextBoxComponent,
1211
+ deps: null,
1212
+ target: i0.ɵɵFactoryTarget.Component
1213
+ });
1214
+ }
1215
+ static {
1216
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
1217
+ minVersion: "17.0.0",
1218
+ version: "22.2.6",
1219
+ type: NumericTextBoxComponent,
1220
+ isStandalone: true,
1221
+ selector: "mona-numeric-text-box",
1222
+ inputs: {
1223
+ formatter: {
1224
+ classPropertyName: "formatter",
1225
+ publicName: "formatter",
1226
+ isSignal: true,
1227
+ isRequired: false,
1228
+ transformFunction: null
1229
+ },
1230
+ maxValue: {
1231
+ classPropertyName: "maxValue",
1232
+ publicName: "maxValue",
1233
+ isSignal: true,
1234
+ isRequired: false,
1235
+ transformFunction: null
1236
+ },
1237
+ minValue: {
1238
+ classPropertyName: "minValue",
1239
+ publicName: "minValue",
1240
+ isSignal: true,
1241
+ isRequired: false,
1242
+ transformFunction: null
1243
+ },
1244
+ step: {
1245
+ classPropertyName: "step",
1246
+ publicName: "step",
1247
+ isSignal: true,
1248
+ isRequired: false,
1249
+ transformFunction: null
1250
+ },
1251
+ value: {
1252
+ classPropertyName: "value",
1253
+ publicName: "value",
1254
+ isSignal: true,
1255
+ isRequired: false,
1256
+ transformFunction: null
1257
+ }
1258
+ },
1259
+ outputs: { value: "valueChange" },
1260
+ usesInheritance: true,
1261
+ ngImport: i0,
1262
+ template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n",
1263
+ dependencies: [
1264
+ {
1265
+ kind: "directive",
1266
+ type: NgTemplateOutlet,
1267
+ selector: "[ngTemplateOutlet]",
1268
+ inputs: [
1269
+ "ngTemplateOutletContext",
1270
+ "ngTemplateOutlet",
1271
+ "ngTemplateOutletInjector"
1272
+ ]
1273
+ },
1274
+ {
1275
+ kind: "directive",
1276
+ type: TextBoxDirective,
1277
+ selector: "input[monaTextBox]",
1278
+ inputs: [
1279
+ "invalid",
1280
+ "rounded",
1281
+ "size",
1282
+ "touched",
1283
+ "class"
1284
+ ]
1285
+ },
1286
+ {
1287
+ kind: "directive",
1288
+ type: ButtonDirective,
1289
+ selector: "button[monaButton]",
1290
+ inputs: [
1291
+ "aria-haspopup",
1292
+ "disabled",
1293
+ "iconOnly",
1294
+ "loading",
1295
+ "look",
1296
+ "rounded",
1297
+ "selected",
1298
+ "size",
1299
+ "tabindex",
1300
+ "toggleable",
1301
+ "type",
1302
+ "class",
1303
+ "value"
1304
+ ],
1305
+ outputs: ["lookChange", "selectedChange"]
1306
+ },
1307
+ {
1308
+ kind: "component",
1309
+ type: LucideChevronUp,
1310
+ selector: "svg[lucideChevronUp]"
1311
+ },
1312
+ {
1313
+ kind: "component",
1314
+ type: LucideChevronDown,
1315
+ selector: "svg[lucideChevronDown]"
1316
+ }
1317
+ ]
1318
+ });
1319
+ }
1320
+ };
1321
+ i0.ɵɵngDeclareClassMetadata({
1322
+ minVersion: "12.0.0",
1323
+ version: "22.2.6",
1324
+ ngImport: i0,
1325
+ type: NumericTextBoxComponent,
1326
+ decorators: [{
1327
+ type: Component,
1328
+ args: [{
1329
+ selector: "mona-numeric-text-box",
1330
+ imports: [
1331
+ NgTemplateOutlet,
1332
+ TextBoxDirective,
1333
+ ButtonDirective,
1334
+ LucideChevronUp,
1335
+ LucideChevronDown
1336
+ ],
1337
+ template: "@for (prefixTemplate of prefixTemplateList(); track $index) {\n <span class=\"flex h-full flex-none flex-wrap items-center overflow-hidden border-none\">\n <ng-container *ngTemplateOutlet=\"prefixTemplate\"></ng-container>\n </span>\n}\n<input\n monaTextBox\n [id]=\"inputId()\"\n [disabled]=\"effectiveDisabled()\"\n [required]=\"required()\"\n [type]=\"'text'\"\n [attr.inputmode]=\"decimals() > 0 ? 'decimal' : 'numeric'\"\n [readonly]=\"readonly()\"\n [tabIndex]=\"tabindex()\"\n [placeholder]=\"placeholder()\"\n [value]=\"formattedValue()\"\n (input)=\"applyRawValue(valueTextBox.value)\"\n (keydown)=\"keydown$.next($event)\"\n (focus)=\"inputFocus.emit($event)\"\n (focusout)=\"inputFocusOut.emit($event)\"\n (beforeinput)=\"beforeInput$.next($event)\"\n (paste)=\"onPaste($event)\"\n (wheel)=\"wheel$.next($event)\"\n [size]=\"size()\"\n [class]=\"inputClasses()\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n [attr.aria-describedby]=\"ariaDescribedBy() || null\"\n [attr.aria-invalid]=\"invalidInput() || null\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-valuenow]=\"value()\"\n [attr.aria-valuemin]=\"minValue()\"\n [attr.aria-valuemax]=\"maxValue()\"\n [attr.aria-valuetext]=\"formattedValue() || null\"\n [attr.data-spinners]=\"showSpinners()\"\n #valueTextBox />\n@if (showSpinners()) {\n <div [class]=\"spinButtonClasses()\">\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '+')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().increase\">\n <svg lucideChevronUp [size]=\"spinButtonIconSize()\"></svg>\n </button>\n <button\n monaButton\n [disabled]=\"effectiveDisabled()\"\n [tabindex]=\"-1\"\n look=\"ghost\"\n [size]=\"size()\"\n (mousedown)=\"$event.preventDefault()\"\n (pointerdown)=\"onSpinPointerDown($event, '-')\"\n (pointerup)=\"spinStop$.next()\"\n (pointerleave)=\"spinStop$.next()\"\n [attr.aria-label]=\"messages().decrease\">\n <svg lucideChevronDown [size]=\"spinButtonIconSize()\"></svg>\n </button>\n </div>\n}\n"
1338
+ }]
1339
+ }],
1340
+ propDecorators: {
1341
+ formatter: [{
1342
+ type: i0.Input,
1343
+ args: [{
1344
+ isSignal: true,
1345
+ alias: "formatter",
1346
+ required: false
1347
+ }]
1348
+ }],
1349
+ maxValue: [{
1350
+ type: i0.Input,
1351
+ args: [{
1352
+ isSignal: true,
1353
+ alias: "maxValue",
1354
+ required: false
1355
+ }]
1356
+ }],
1357
+ minValue: [{
1358
+ type: i0.Input,
1359
+ args: [{
1360
+ isSignal: true,
1361
+ alias: "minValue",
1362
+ required: false
1363
+ }]
1364
+ }],
1365
+ step: [{
1366
+ type: i0.Input,
1367
+ args: [{
1368
+ isSignal: true,
1369
+ alias: "step",
1370
+ required: false
1371
+ }]
1372
+ }],
1373
+ value: [{
1374
+ type: i0.Input,
1375
+ args: [{
1376
+ isSignal: true,
1377
+ alias: "value",
1378
+ required: false
1379
+ }]
1380
+ }, {
1381
+ type: i0.Output,
1382
+ args: ["valueChange"]
1383
+ }]
1384
+ }
1385
+ });
907
1386
  export { DecimalTextBoxComponent, NUMERIC_TEXT_BOX_DEFAULT_MESSAGES, NumericTextBoxComponent, NumericTextBoxPrefixTemplateDirective };
908
- //# sourceMappingURL=nanahoshi-mona-ui-numeric-text-box.mjs.map
1387
+
1388
+ //# sourceMappingURL=nanahoshi-mona-ui-numeric-text-box.mjs.map