@perses-dev/components 0.54.0-beta.0 → 0.54.0-beta.2

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 (330) hide show
  1. package/dist/AlignSelector/AlignSelector.js +1 -1
  2. package/dist/AlignSelector/AlignSelector.js.map +1 -1
  3. package/dist/ColorPicker/ColorPicker.js +1 -1
  4. package/dist/ColorPicker/ColorPicker.js.map +1 -1
  5. package/dist/ColorPicker/OptionsColorPicker.js +1 -1
  6. package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
  7. package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
  8. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  9. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +1 -1
  10. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  11. package/dist/ContentWithLegend/model/content-with-legend-model.js +1 -1
  12. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  13. package/dist/Dialog/DiscardChangesConfirmationDialog.js +1 -1
  14. package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
  15. package/dist/DragAndDrop/DragAndDropList.js +1 -1
  16. package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
  17. package/dist/DragAndDrop/DragButton.js +1 -1
  18. package/dist/DragAndDrop/DragButton.js.map +1 -1
  19. package/dist/DragAndDrop/DropIndicator.js +1 -1
  20. package/dist/DragAndDrop/DropIndicator.js.map +1 -1
  21. package/dist/Drawer/Drawer.js +1 -1
  22. package/dist/Drawer/Drawer.js.map +1 -1
  23. package/dist/EChart/EChart.js +1 -1
  24. package/dist/EChart/EChart.js.map +1 -1
  25. package/dist/ErrorAlert.js +1 -1
  26. package/dist/ErrorAlert.js.map +1 -1
  27. package/dist/FormEditor/FormActions.d.ts +1 -1
  28. package/dist/FormEditor/FormActions.d.ts.map +1 -1
  29. package/dist/FormEditor/FormActions.js +1 -1
  30. package/dist/FormEditor/FormActions.js.map +1 -1
  31. package/dist/FormatControls/FormatControls.d.ts +1 -1
  32. package/dist/FormatControls/FormatControls.d.ts.map +1 -1
  33. package/dist/FormatControls/FormatControls.js +2 -2
  34. package/dist/FormatControls/FormatControls.js.map +1 -1
  35. package/dist/FormatControls/UnitSelector.d.ts +1 -1
  36. package/dist/FormatControls/UnitSelector.d.ts.map +1 -1
  37. package/dist/FormatControls/UnitSelector.js +1 -1
  38. package/dist/FormatControls/UnitSelector.js.map +1 -1
  39. package/dist/JSONEditor.js +1 -1
  40. package/dist/JSONEditor.js.map +1 -1
  41. package/dist/Legend/CompactLegend.js +1 -1
  42. package/dist/Legend/CompactLegend.js.map +1 -1
  43. package/dist/Legend/Legend.js +2 -2
  44. package/dist/Legend/Legend.js.map +1 -1
  45. package/dist/Legend/LegendColorBadge.js +1 -1
  46. package/dist/Legend/LegendColorBadge.js.map +1 -1
  47. package/dist/Legend/ListLegend.js +1 -1
  48. package/dist/Legend/ListLegend.js.map +1 -1
  49. package/dist/Legend/ListLegendItem.js +1 -1
  50. package/dist/Legend/ListLegendItem.js.map +1 -1
  51. package/dist/Legend/TableLegend.d.ts.map +1 -1
  52. package/dist/Legend/TableLegend.js +18 -4
  53. package/dist/Legend/TableLegend.js.map +1 -1
  54. package/dist/Legend/legend-model.d.ts +1 -1
  55. package/dist/Legend/legend-model.d.ts.map +1 -1
  56. package/dist/Legend/legend-model.js.map +1 -1
  57. package/dist/LinksEditor/LinkEditorForm.js +1 -1
  58. package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
  59. package/dist/LinksEditor/LinksEditor.js +1 -1
  60. package/dist/LinksEditor/LinksEditor.js.map +1 -1
  61. package/dist/OptionsEditorLayout/OptionsEditorColumn.js +1 -1
  62. package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
  63. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  64. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  65. package/dist/OptionsEditorLayout/OptionsEditorGrid.js +1 -1
  66. package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
  67. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +1 -1
  68. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
  69. package/dist/Overlay/Overlay.js +1 -1
  70. package/dist/Overlay/Overlay.js.map +1 -1
  71. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +1 -1
  72. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
  73. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +1 -1
  74. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  75. package/dist/SortSelector/SortSelectorButtons.js +1 -1
  76. package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
  77. package/dist/Table/InnerTable.js +1 -1
  78. package/dist/Table/InnerTable.js.map +1 -1
  79. package/dist/Table/Table.d.ts +1 -1
  80. package/dist/Table/Table.d.ts.map +1 -1
  81. package/dist/Table/Table.js +47 -14
  82. package/dist/Table/Table.js.map +1 -1
  83. package/dist/Table/TableBody.js +1 -1
  84. package/dist/Table/TableBody.js.map +1 -1
  85. package/dist/Table/TableCell.js +1 -1
  86. package/dist/Table/TableCell.js.map +1 -1
  87. package/dist/Table/TableCheckbox.js +1 -1
  88. package/dist/Table/TableCheckbox.js.map +1 -1
  89. package/dist/Table/TableFoot.js +1 -1
  90. package/dist/Table/TableFoot.js.map +1 -1
  91. package/dist/Table/TableHead.js +1 -1
  92. package/dist/Table/TableHead.js.map +1 -1
  93. package/dist/Table/TableHeaderCell.d.ts +20 -1
  94. package/dist/Table/TableHeaderCell.d.ts.map +1 -1
  95. package/dist/Table/TableHeaderCell.js +56 -24
  96. package/dist/Table/TableHeaderCell.js.map +1 -1
  97. package/dist/Table/TableRow.js +1 -1
  98. package/dist/Table/TableRow.js.map +1 -1
  99. package/dist/Table/TableToolbar.d.ts +46 -0
  100. package/dist/Table/TableToolbar.d.ts.map +1 -0
  101. package/dist/Table/TableToolbar.js +138 -0
  102. package/dist/Table/TableToolbar.js.map +1 -0
  103. package/dist/Table/VirtualizedTable.d.ts +7 -3
  104. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  105. package/dist/Table/VirtualizedTable.js +157 -123
  106. package/dist/Table/VirtualizedTable.js.map +1 -1
  107. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -1
  108. package/dist/Table/VirtualizedTableContainer.js +6 -2
  109. package/dist/Table/VirtualizedTableContainer.js.map +1 -1
  110. package/dist/Table/hooks/useFuzzySearch.d.ts +14 -0
  111. package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -0
  112. package/dist/Table/hooks/useFuzzySearch.js +62 -0
  113. package/dist/Table/hooks/useFuzzySearch.js.map +1 -0
  114. package/dist/Table/model/table-model.d.ts +78 -4
  115. package/dist/Table/model/table-model.d.ts.map +1 -1
  116. package/dist/Table/model/table-model.js +37 -19
  117. package/dist/Table/model/table-model.js.map +1 -1
  118. package/dist/ThresholdsEditor/ThresholdInput.d.ts +1 -1
  119. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
  120. package/dist/ThresholdsEditor/ThresholdInput.js +1 -1
  121. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  122. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +1 -1
  123. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
  124. package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -1
  125. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  126. package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
  127. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  128. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
  129. package/dist/TimeRangeSelector/TimeRangeSelector.js +25 -2
  130. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  131. package/dist/TimeSeriesTooltip/SeriesInfo.js +1 -1
  132. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  133. package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +1 -1
  134. package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
  135. package/dist/TimeSeriesTooltip/SeriesMarker.js +1 -1
  136. package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
  137. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +1 -2
  138. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
  139. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +1 -1
  140. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  141. package/dist/TimeSeriesTooltip/TooltipContent.js +1 -1
  142. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  143. package/dist/TimeSeriesTooltip/TooltipHeader.js +1 -1
  144. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  145. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
  146. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  147. package/dist/TimeSeriesTooltip/nearby-series.js +1 -2
  148. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  149. package/dist/TimeZoneSelector.js +1 -1
  150. package/dist/TimeZoneSelector.js.map +1 -1
  151. package/dist/ToolbarIconButton/ToolbarIconButton.js +1 -1
  152. package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  153. package/dist/TransformsEditor/TransformEditor.d.ts +1 -1
  154. package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
  155. package/dist/TransformsEditor/TransformEditor.js +1 -1
  156. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  157. package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -1
  158. package/dist/TransformsEditor/TransformEditorContainer.js +2 -2
  159. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  160. package/dist/TransformsEditor/TransformsEditor.d.ts +1 -1
  161. package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -1
  162. package/dist/TransformsEditor/TransformsEditor.js +1 -1
  163. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  164. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts +1 -1
  165. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts.map +1 -1
  166. package/dist/ValueMappingEditor/ValueMappingEditor.js +1 -1
  167. package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
  168. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts +1 -1
  169. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -1
  170. package/dist/ValueMappingEditor/ValueMappingsEditor.js +1 -1
  171. package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
  172. package/dist/YAxisLabel.js +1 -1
  173. package/dist/YAxisLabel.js.map +1 -1
  174. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +2 -2
  175. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -2
  176. package/dist/cjs/FormatControls/FormatControls.js +4 -4
  177. package/dist/cjs/FormatControls/UnitSelector.js +3 -3
  178. package/dist/cjs/Legend/Legend.js +2 -2
  179. package/dist/cjs/Legend/TableLegend.js +16 -2
  180. package/dist/cjs/Table/Table.js +44 -11
  181. package/dist/cjs/Table/TableHeaderCell.js +54 -22
  182. package/dist/cjs/Table/TableToolbar.js +151 -0
  183. package/dist/cjs/Table/VirtualizedTable.js +155 -121
  184. package/dist/cjs/Table/VirtualizedTableContainer.js +5 -1
  185. package/dist/cjs/Table/hooks/useFuzzySearch.js +67 -0
  186. package/dist/cjs/Table/model/table-model.js +43 -19
  187. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +23 -0
  188. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -3
  189. package/dist/cjs/TransformsEditor/TransformEditorContainer.js +2 -2
  190. package/dist/cjs/model/action.js +43 -0
  191. package/dist/cjs/model/bits.js +113 -0
  192. package/dist/cjs/model/bytes.js +115 -0
  193. package/dist/cjs/model/constants.js +23 -0
  194. package/dist/cjs/model/currency.js +126 -0
  195. package/dist/cjs/model/date.js +297 -0
  196. package/dist/cjs/model/decimal.js +72 -0
  197. package/dist/cjs/model/formatterCache.js +120 -0
  198. package/dist/cjs/model/index.js +17 -0
  199. package/dist/cjs/model/legend.js +101 -0
  200. package/dist/cjs/model/percent.js +82 -0
  201. package/dist/cjs/model/temperature.js +72 -0
  202. package/dist/cjs/model/thresholds.js +16 -0
  203. package/dist/cjs/model/throughput.js +161 -0
  204. package/dist/cjs/model/time.js +178 -0
  205. package/dist/cjs/model/transforms.js +29 -0
  206. package/dist/cjs/model/types.js +16 -0
  207. package/dist/cjs/model/units.js +186 -0
  208. package/dist/cjs/model/utils.js +48 -0
  209. package/dist/cjs/model/value-mapping.js +16 -0
  210. package/dist/cjs/theme/typography.js +1 -1
  211. package/dist/cjs/utils/axis.js +5 -5
  212. package/dist/cjs/utils/format.js +20 -0
  213. package/dist/cjs/utils/index.js +1 -0
  214. package/dist/cjs/utils/request-interpolation.js +49 -0
  215. package/dist/context/ChartsProvider.js +1 -1
  216. package/dist/context/ChartsProvider.js.map +1 -1
  217. package/dist/context/ItemActionsProvider.js +1 -1
  218. package/dist/context/ItemActionsProvider.js.map +1 -1
  219. package/dist/context/SelectionProvider.js +1 -1
  220. package/dist/context/SelectionProvider.js.map +1 -1
  221. package/dist/context/SnackbarProvider.js +1 -1
  222. package/dist/context/SnackbarProvider.js.map +1 -1
  223. package/dist/context/TimeZoneProvider.js +1 -1
  224. package/dist/context/TimeZoneProvider.js.map +1 -1
  225. package/dist/controls/TextField.js +1 -1
  226. package/dist/controls/TextField.js.map +1 -1
  227. package/dist/model/action.d.ts +4 -0
  228. package/dist/model/action.d.ts.map +1 -0
  229. package/dist/model/action.js +27 -0
  230. package/dist/model/action.js.map +1 -0
  231. package/dist/model/bits.d.ts +12 -0
  232. package/dist/model/bits.d.ts.map +1 -0
  233. package/dist/model/bits.js +89 -0
  234. package/dist/model/bits.js.map +1 -0
  235. package/dist/model/bytes.d.ts +12 -0
  236. package/dist/model/bytes.d.ts.map +1 -0
  237. package/dist/model/bytes.js +91 -0
  238. package/dist/model/bytes.js.map +1 -0
  239. package/dist/model/constants.d.ts +2 -0
  240. package/dist/model/constants.d.ts.map +1 -0
  241. package/dist/model/constants.js +15 -0
  242. package/dist/model/constants.js.map +1 -0
  243. package/dist/model/currency.d.ts +11 -0
  244. package/dist/model/currency.d.ts.map +1 -0
  245. package/dist/model/currency.js +107 -0
  246. package/dist/model/currency.js.map +1 -0
  247. package/dist/model/date.d.ts +28 -0
  248. package/dist/model/date.d.ts.map +1 -0
  249. package/dist/model/date.js +278 -0
  250. package/dist/model/date.js.map +1 -0
  251. package/dist/model/decimal.d.ts +12 -0
  252. package/dist/model/decimal.d.ts.map +1 -0
  253. package/dist/model/decimal.js +53 -0
  254. package/dist/model/decimal.js.map +1 -0
  255. package/dist/model/formatterCache.d.ts +11 -0
  256. package/dist/model/formatterCache.d.ts.map +1 -0
  257. package/dist/model/formatterCache.js +104 -0
  258. package/dist/model/formatterCache.js.map +1 -0
  259. package/dist/model/index.d.ts +17 -0
  260. package/dist/model/index.d.ts.map +1 -1
  261. package/dist/model/index.js +17 -0
  262. package/dist/model/index.js.map +1 -1
  263. package/dist/model/legend.d.ts +19 -0
  264. package/dist/model/legend.d.ts.map +1 -0
  265. package/dist/model/legend.js +61 -0
  266. package/dist/model/legend.js.map +1 -0
  267. package/dist/model/percent.d.ts +11 -0
  268. package/dist/model/percent.d.ts.map +1 -0
  269. package/dist/model/percent.js +63 -0
  270. package/dist/model/percent.js.map +1 -0
  271. package/dist/model/temperature.d.ts +11 -0
  272. package/dist/model/temperature.d.ts.map +1 -0
  273. package/dist/model/temperature.js +53 -0
  274. package/dist/model/temperature.js.map +1 -0
  275. package/dist/model/theme.d.ts +1 -1
  276. package/dist/model/theme.d.ts.map +1 -1
  277. package/dist/model/theme.js.map +1 -1
  278. package/dist/model/thresholds.d.ts +16 -0
  279. package/dist/model/thresholds.d.ts.map +1 -0
  280. package/dist/model/thresholds.js +15 -0
  281. package/dist/model/thresholds.js.map +1 -0
  282. package/dist/model/throughput.d.ts +12 -0
  283. package/dist/model/throughput.d.ts.map +1 -0
  284. package/dist/model/throughput.js +142 -0
  285. package/dist/model/throughput.js.map +1 -0
  286. package/dist/model/time.d.ts +23 -0
  287. package/dist/model/time.d.ts.map +1 -0
  288. package/dist/model/time.js +158 -0
  289. package/dist/model/time.js.map +1 -0
  290. package/dist/model/transforms.d.ts +43 -0
  291. package/dist/model/transforms.d.ts.map +1 -0
  292. package/dist/model/transforms.js +22 -0
  293. package/dist/model/transforms.js.map +1 -0
  294. package/dist/model/types.d.ts +56 -0
  295. package/dist/model/types.d.ts.map +1 -0
  296. package/dist/model/types.js +15 -0
  297. package/dist/model/types.js.map +1 -0
  298. package/dist/model/units.d.ts +105 -0
  299. package/dist/model/units.d.ts.map +1 -0
  300. package/dist/model/units.js +132 -0
  301. package/dist/model/units.js.map +1 -0
  302. package/dist/model/utils.d.ts +4 -0
  303. package/dist/model/utils.d.ts.map +1 -0
  304. package/dist/model/utils.js +32 -0
  305. package/dist/model/utils.js.map +1 -0
  306. package/dist/model/value-mapping.d.ts +35 -0
  307. package/dist/model/value-mapping.d.ts.map +1 -0
  308. package/dist/model/value-mapping.js +15 -0
  309. package/dist/model/value-mapping.js.map +1 -0
  310. package/dist/test/render.js +1 -1
  311. package/dist/test/render.js.map +1 -1
  312. package/dist/theme/typography.js +1 -1
  313. package/dist/theme/typography.js.map +1 -1
  314. package/dist/utils/axis.d.ts +1 -1
  315. package/dist/utils/axis.d.ts.map +1 -1
  316. package/dist/utils/axis.js +1 -1
  317. package/dist/utils/axis.js.map +1 -1
  318. package/dist/utils/format.d.ts +1 -0
  319. package/dist/utils/format.d.ts.map +1 -1
  320. package/dist/utils/format.js +17 -0
  321. package/dist/utils/format.js.map +1 -1
  322. package/dist/utils/index.d.ts +1 -0
  323. package/dist/utils/index.d.ts.map +1 -1
  324. package/dist/utils/index.js +1 -0
  325. package/dist/utils/index.js.map +1 -1
  326. package/dist/utils/request-interpolation.d.ts +6 -0
  327. package/dist/utils/request-interpolation.d.ts.map +1 -0
  328. package/dist/utils/request-interpolation.js +33 -0
  329. package/dist/utils/request-interpolation.js.map +1 -0
  330. package/package.json +4 -2
@@ -0,0 +1,107 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { toUpper } from 'lodash';
14
+ import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
+ import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
16
+ import { getFormatterFromCache } from './formatterCache';
17
+ const CURRENCY_GROUP = 'Currency';
18
+ export const CURRENCY_GROUP_CONFIG = {
19
+ label: 'Currency',
20
+ decimalPlaces: true
21
+ };
22
+ export const CURRENCY_UNIT_CONFIG = {
23
+ aud: {
24
+ group: CURRENCY_GROUP,
25
+ label: 'Australian Dollar (A$)'
26
+ },
27
+ cad: {
28
+ group: CURRENCY_GROUP,
29
+ label: 'Canadian Dollar (CA$)'
30
+ },
31
+ chf: {
32
+ group: CURRENCY_GROUP,
33
+ label: 'Swiss Franc (CHF)'
34
+ },
35
+ cny: {
36
+ group: CURRENCY_GROUP,
37
+ label: 'Renminbi (CN¥)'
38
+ },
39
+ eur: {
40
+ group: CURRENCY_GROUP,
41
+ label: 'Euro (€)'
42
+ },
43
+ gbp: {
44
+ group: CURRENCY_GROUP,
45
+ label: 'Pound (£)'
46
+ },
47
+ hkd: {
48
+ group: CURRENCY_GROUP,
49
+ label: 'Hong Kong Dollar (HK$)'
50
+ },
51
+ inr: {
52
+ group: CURRENCY_GROUP,
53
+ label: 'Indian Rupee (₹)'
54
+ },
55
+ jpy: {
56
+ group: CURRENCY_GROUP,
57
+ label: 'Yen (¥)'
58
+ },
59
+ krw: {
60
+ group: CURRENCY_GROUP,
61
+ label: 'South Korean Won (₩)'
62
+ },
63
+ nok: {
64
+ group: CURRENCY_GROUP,
65
+ label: 'Norwegian Krone (NOK)'
66
+ },
67
+ nzd: {
68
+ group: CURRENCY_GROUP,
69
+ label: 'New Zealand Dollar (NZ$)'
70
+ },
71
+ sek: {
72
+ group: CURRENCY_GROUP,
73
+ label: 'Swedish Krona (SEK)'
74
+ },
75
+ sgd: {
76
+ group: CURRENCY_GROUP,
77
+ label: 'Singapore Dollar (S$)'
78
+ },
79
+ usd: {
80
+ group: CURRENCY_GROUP,
81
+ label: 'US Dollar ($)'
82
+ }
83
+ };
84
+ export function formatCurrency(value, { unit, decimalPlaces }) {
85
+ const formatterOptions = {
86
+ style: 'currency',
87
+ currency: toUpper(unit),
88
+ currencyDisplay: 'symbol'
89
+ };
90
+ if (hasDecimalPlaces(decimalPlaces)) {
91
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
92
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
93
+ } else {
94
+ formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
95
+ }
96
+ const key = [
97
+ formatterOptions.style,
98
+ formatterOptions.currency,
99
+ formatterOptions.currencyDisplay,
100
+ formatterOptions.maximumSignificantDigits,
101
+ decimalPlaces,
102
+ unit
103
+ ];
104
+ return getFormatterFromCache(key, 'currency', formatterOptions, 'en-US')(value);
105
+ }
106
+
107
+ //# sourceMappingURL=currency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/currency.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { toUpper } from 'lodash';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n// See Intl.supportedValuesOf(\"currency\") for valid options, key names will\n// be converted to uppercase to match the expectation of Intl.NumberFormat\ntype CurrencyUnits =\n | 'aud'\n | 'cad'\n | 'chf'\n | 'cny'\n | 'eur'\n | 'gbp'\n | 'hkd'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'nok'\n | 'nzd'\n | 'sek'\n | 'sgd'\n | 'usd';\nexport type CurrencyFormatOptions = {\n unit: CurrencyUnits;\n decimalPlaces?: number;\n};\n\nconst CURRENCY_GROUP = 'Currency';\nexport const CURRENCY_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Currency',\n decimalPlaces: true,\n};\nexport const CURRENCY_UNIT_CONFIG: Readonly<Record<CurrencyUnits, UnitConfig>> = {\n aud: {\n group: CURRENCY_GROUP,\n label: 'Australian Dollar (A$)',\n },\n cad: {\n group: CURRENCY_GROUP,\n label: 'Canadian Dollar (CA$)',\n },\n chf: {\n group: CURRENCY_GROUP,\n label: 'Swiss Franc (CHF)',\n },\n cny: {\n group: CURRENCY_GROUP,\n label: 'Renminbi (CN¥)',\n },\n eur: {\n group: CURRENCY_GROUP,\n label: 'Euro (€)',\n },\n gbp: {\n group: CURRENCY_GROUP,\n label: 'Pound (£)',\n },\n hkd: {\n group: CURRENCY_GROUP,\n label: 'Hong Kong Dollar (HK$)',\n },\n inr: {\n group: CURRENCY_GROUP,\n label: 'Indian Rupee (₹)',\n },\n jpy: {\n group: CURRENCY_GROUP,\n label: 'Yen (¥)',\n },\n krw: {\n group: CURRENCY_GROUP,\n label: 'South Korean Won (₩)',\n },\n nok: {\n group: CURRENCY_GROUP,\n label: 'Norwegian Krone (NOK)',\n },\n nzd: {\n group: CURRENCY_GROUP,\n label: 'New Zealand Dollar (NZ$)',\n },\n sek: {\n group: CURRENCY_GROUP,\n label: 'Swedish Krona (SEK)',\n },\n sgd: {\n group: CURRENCY_GROUP,\n label: 'Singapore Dollar (S$)',\n },\n usd: {\n group: CURRENCY_GROUP,\n label: 'US Dollar ($)',\n },\n};\n\nexport function formatCurrency(value: number, { unit, decimalPlaces }: CurrencyFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'currency',\n currency: toUpper(unit),\n currencyDisplay: 'symbol',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.currency,\n formatterOptions.currencyDisplay,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n unit,\n ];\n\n return getFormatterFromCache(key, 'currency', formatterOptions, 'en-US')(value);\n}\n"],"names":["toUpper","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","getFormatterFromCache","CURRENCY_GROUP","CURRENCY_GROUP_CONFIG","label","decimalPlaces","CURRENCY_UNIT_CONFIG","aud","group","cad","chf","cny","eur","gbp","hkd","inr","jpy","krw","nok","nzd","sek","sgd","usd","formatCurrency","value","unit","formatterOptions","style","currency","currencyDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;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qB,GAAG/B,mBAAmBK;IAC9D,OAAO;QACLqB,iBAAiBM,wBAAwB,GAAGlC;IAC9C;IAEA,MAAMmC,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,QAAQ;QACzBF,iBAAiBG,eAAe;QAChCH,iBAAiBM,wBAAwB;QACzC3B;QACAoB;KACD;IAED,OAAOxB,sBAAsBgC,KAAK,YAAYP,kBAAkB,SAASF;AAC3E"}
@@ -0,0 +1,28 @@
1
+ import { UnitGroupConfig, UnitConfig } from './types';
2
+ type DateUnits = 'datetime-iso' | 'datetime-us' | 'datetime-local' | 'date-iso' | 'date-us' | 'date-local' | 'time-local' | 'time-iso' | 'time-us' | 'relative-time' | 'unix-timestamp' | 'unix-timestamp-ms';
3
+ export type DateFormatOptions = {
4
+ unit?: DateUnits;
5
+ /**
6
+ * The locale to use for formatting. Defaults to the system's locale.
7
+ */
8
+ locale?: string;
9
+ /**
10
+ * The timezone to use for formatting. Defaults to the user's local timezone.
11
+ */
12
+ timeZone?: string;
13
+ /**
14
+ * For relative time formatting, the reference time to compare against.
15
+ * Defaults to current time.
16
+ */
17
+ referenceTime?: number;
18
+ /**
19
+ * This property is not used for date formatting, but is included for
20
+ * compatibility with the FormatControls UI component.
21
+ */
22
+ decimalPlaces?: number;
23
+ };
24
+ export declare const DATE_GROUP_CONFIG: UnitGroupConfig;
25
+ export declare const DATE_UNIT_CONFIG: Readonly<Record<DateUnits, UnitConfig>>;
26
+ export declare function formatDate(value: number, options?: DateFormatOptions): string;
27
+ export {};
28
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/model/date.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,KAAK,SAAS,GACV,cAAc,GACd,aAAa,GACb,gBAAgB,GAChB,UAAU,GACV,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,mBAAmB,CAAC;AAExB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,eAAO,MAAM,iBAAiB,EAAE,eAE/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAiDpE,CAAC;AAqGF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAwHjF"}
@@ -0,0 +1,278 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ const DATE_GROUP = 'Date';
14
+ export const DATE_GROUP_CONFIG = {
15
+ label: 'Date & Time'
16
+ };
17
+ export const DATE_UNIT_CONFIG = {
18
+ 'datetime-iso': {
19
+ group: DATE_GROUP,
20
+ label: 'DateTime (GMT)'
21
+ },
22
+ 'datetime-us': {
23
+ group: DATE_GROUP,
24
+ label: 'DateTime (US-East)'
25
+ },
26
+ 'datetime-local': {
27
+ group: DATE_GROUP,
28
+ label: 'DateTime (Browser Local)'
29
+ },
30
+ 'date-iso': {
31
+ group: DATE_GROUP,
32
+ label: 'Date (GMT)'
33
+ },
34
+ 'date-us': {
35
+ group: DATE_GROUP,
36
+ label: 'Date (US-East)'
37
+ },
38
+ 'date-local': {
39
+ group: DATE_GROUP,
40
+ label: 'Date (Browser Local)'
41
+ },
42
+ 'time-local': {
43
+ group: DATE_GROUP,
44
+ label: 'Time (Browser Local)'
45
+ },
46
+ 'time-iso': {
47
+ group: DATE_GROUP,
48
+ label: 'Time (GMT)'
49
+ },
50
+ 'time-us': {
51
+ group: DATE_GROUP,
52
+ label: 'Time (US-East)'
53
+ },
54
+ 'relative-time': {
55
+ group: DATE_GROUP,
56
+ label: 'Relative Time'
57
+ },
58
+ 'unix-timestamp': {
59
+ group: DATE_GROUP,
60
+ label: 'Unix Timestamp (s)'
61
+ },
62
+ 'unix-timestamp-ms': {
63
+ group: DATE_GROUP,
64
+ label: 'Unix Timestamp (ms)'
65
+ }
66
+ };
67
+ /**
68
+ * Converts a numeric value to a Date object.
69
+ * Handles both Unix timestamps (seconds) and millisecond timestamps.
70
+ */ function valueToDate(value) {
71
+ // Timestamp detection logic with special case handling
72
+ // Main threshold stays at 10 billion to maintain existing behavior
73
+ // Handle special edge cases explicitly
74
+ // Special case: negative timestamps
75
+ if (value < 0) {
76
+ // For negative values, check magnitude to distinguish seconds vs milliseconds
77
+ // Large negative values (> 1 billion in magnitude) are likely milliseconds
78
+ // Small negative values are likely seconds (rare edge case)
79
+ if (Math.abs(value) > 10000000000) {
80
+ return new Date(value); // milliseconds
81
+ } else {
82
+ return new Date(value * 1000); // seconds
83
+ }
84
+ }
85
+ // Special case: year 9999 in seconds (~253402300799)
86
+ // This is a very specific edge case for far-future timestamps
87
+ if (value >= 250000000000 && value <= 260000000000) {
88
+ // Check if this looks like year 9999 in seconds
89
+ const asSeconds = new Date(value * 1000);
90
+ const year = asSeconds.getUTCFullYear();
91
+ if (year >= 9999) {
92
+ return asSeconds; // seconds
93
+ }
94
+ }
95
+ const SECONDS_THRESHOLD = 10000000000; // ~year 2286 - original threshold
96
+ if (value < SECONDS_THRESHOLD) {
97
+ // Assume it's in seconds
98
+ return new Date(value * 1000);
99
+ } else {
100
+ // Assume it's in milliseconds
101
+ return new Date(value);
102
+ }
103
+ }
104
+ /**
105
+ * Formats a relative time string using the Intl.RelativeTimeFormat API.
106
+ */ function formatRelativeTime(date, referenceTime, locale) {
107
+ const referenceDate = new Date(referenceTime);
108
+ const diffMs = date.getTime() - referenceDate.getTime();
109
+ const units = [
110
+ {
111
+ unit: 'year',
112
+ ms: 1000 * 60 * 60 * 24 * 365
113
+ },
114
+ {
115
+ unit: 'month',
116
+ ms: 1000 * 60 * 60 * 24 * 30
117
+ },
118
+ {
119
+ unit: 'week',
120
+ ms: 1000 * 60 * 60 * 24 * 7
121
+ },
122
+ {
123
+ unit: 'day',
124
+ ms: 1000 * 60 * 60 * 24
125
+ },
126
+ {
127
+ unit: 'hour',
128
+ ms: 1000 * 60 * 60
129
+ },
130
+ {
131
+ unit: 'minute',
132
+ ms: 1000 * 60
133
+ },
134
+ {
135
+ unit: 'second',
136
+ ms: 1000
137
+ }
138
+ ];
139
+ for (const { unit, ms } of units){
140
+ // Determine the value for the current unit, ensuring it's an integer for Intl.RelativeTimeFormat
141
+ const value = Math.round(diffMs / ms);
142
+ // If the absolute value is 1 or more, use this unit
143
+ if (Math.abs(value) >= 1) {
144
+ const rtf = new Intl.RelativeTimeFormat(locale, {
145
+ numeric: 'auto'
146
+ });
147
+ return rtf.format(value, unit);
148
+ }
149
+ }
150
+ // If less than a second, show "now" or "0 seconds"
151
+ const rtf = new Intl.RelativeTimeFormat(locale, {
152
+ numeric: 'auto'
153
+ });
154
+ return rtf.format(0, 'second');
155
+ }
156
+ /**
157
+ * Gets the browser's preferred locale with comprehensive fallbacks.
158
+ */ const getBrowserLocale = ()=>{
159
+ if (typeof navigator !== 'undefined') {
160
+ if (navigator.language) return navigator.language;
161
+ if (navigator.languages && navigator.languages.length > 0) {
162
+ const firstLanguage = navigator.languages[0];
163
+ if (firstLanguage) return firstLanguage;
164
+ }
165
+ // Legacy fallbacks for older browsers
166
+ const nav = navigator;
167
+ if (nav.userLanguage) return nav.userLanguage;
168
+ if (nav.browserLanguage) return nav.browserLanguage;
169
+ if (nav.systemLanguage) return nav.systemLanguage;
170
+ }
171
+ // Node.js or server-side fallback, or if navigator is not available/empty
172
+ return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';
173
+ };
174
+ export function formatDate(value, options = {}) {
175
+ const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
176
+ const { unit = 'datetime-local', locale = getBrowserLocale(), timeZone = systemTimeZone, referenceTime = Date.now() } = options;
177
+ // Handle raw timestamp display
178
+ if (unit === 'unix-timestamp') {
179
+ // Ensure it's in seconds. If it looks like milliseconds, convert.
180
+ const timestamp = value > 1000000000000 ? Math.floor(value / 1000) : value;
181
+ return timestamp.toString();
182
+ }
183
+ if (unit === 'unix-timestamp-ms') {
184
+ // Ensure it's in milliseconds. If it looks like seconds, convert.
185
+ // Use 100 billion as threshold - values < 100B are likely seconds, >= 100B are likely milliseconds
186
+ // This distinguishes between 999999999 (seconds) and 999999999000 (milliseconds)
187
+ const MILLISECONDS_THRESHOLD = 100000000000; // 100 billion
188
+ const timestamp = value < MILLISECONDS_THRESHOLD ? value * 1000 : value;
189
+ return Math.floor(timestamp).toString();
190
+ }
191
+ const date = valueToDate(value);
192
+ // Handle relative time
193
+ if (unit === 'relative-time') {
194
+ return formatRelativeTime(date, referenceTime, locale);
195
+ }
196
+ // Configure Intl.DateTimeFormat options based on unit
197
+ const formatOptions = {
198
+ timeZone
199
+ };
200
+ switch(unit){
201
+ case 'datetime-iso':
202
+ // datetime-iso should ALWAYS show GMT/UTC time
203
+ return date.toISOString();
204
+ case 'datetime-us':
205
+ {
206
+ // datetime-us should ALWAYS show date in US Eastern timezone
207
+ formatOptions.timeZone = 'America/New_York';
208
+ formatOptions.year = 'numeric';
209
+ formatOptions.month = '2-digit';
210
+ formatOptions.day = '2-digit';
211
+ formatOptions.hour = '2-digit';
212
+ formatOptions.minute = '2-digit';
213
+ formatOptions.second = '2-digit';
214
+ formatOptions.hour12 = true; // 12-hour format with AM/PM
215
+ const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
216
+ return formatter.format(date);
217
+ }
218
+ case 'datetime-local':
219
+ // datetime-local should use the browser's local timezone (detected automatically)
220
+ // Don't override timeZone - let it use the detected system timezone
221
+ formatOptions.year = 'numeric';
222
+ formatOptions.month = '2-digit';
223
+ formatOptions.day = '2-digit';
224
+ formatOptions.hour = '2-digit';
225
+ formatOptions.minute = '2-digit';
226
+ formatOptions.second = '2-digit';
227
+ formatOptions.hour12 = false; // 24-hour format
228
+ break;
229
+ case 'date-iso':
230
+ // date-iso should ALWAYS show GMT/UTC date
231
+ return date.toISOString().split('T')[0];
232
+ case 'date-us':
233
+ {
234
+ // date-us should ALWAYS show date in US Eastern timezone
235
+ formatOptions.timeZone = 'America/New_York';
236
+ formatOptions.year = 'numeric';
237
+ formatOptions.month = '2-digit';
238
+ formatOptions.day = '2-digit';
239
+ const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
240
+ return formatter.format(date);
241
+ }
242
+ case 'date-local':
243
+ formatOptions.year = 'numeric';
244
+ formatOptions.month = '2-digit';
245
+ formatOptions.day = '2-digit';
246
+ break;
247
+ case 'time-local':
248
+ formatOptions.hour = '2-digit';
249
+ formatOptions.minute = '2-digit';
250
+ formatOptions.second = '2-digit';
251
+ formatOptions.hour12 = false; // 24-hour format
252
+ break;
253
+ case 'time-iso':
254
+ // time-iso should ALWAYS show GMT/UTC time
255
+ return date.toISOString().split('T')[1].replace('Z', '');
256
+ case 'time-us':
257
+ {
258
+ // time-us should show time in US-East timezone (Eastern Time)
259
+ formatOptions.timeZone = 'America/New_York';
260
+ formatOptions.hour = '2-digit';
261
+ formatOptions.minute = '2-digit';
262
+ formatOptions.second = '2-digit';
263
+ formatOptions.hour12 = true;
264
+ return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
265
+ }
266
+ default:
267
+ {
268
+ // This ensures that all DateUnits are handled at compile time.
269
+ const exhaustive = unit;
270
+ throw new Error(`Unknown date unit: ${exhaustive}`);
271
+ }
272
+ }
273
+ // For all other units, use Intl.DateTimeFormat with the specified locale and options
274
+ const formatter = new Intl.DateTimeFormat(locale, formatOptions);
275
+ return formatter.format(date);
276
+ }
277
+
278
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/date.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnitGroupConfig, UnitConfig } from './types';\n\ntype DateUnits =\n | 'datetime-iso'\n | 'datetime-us'\n | 'datetime-local'\n | 'date-iso'\n | 'date-us'\n | 'date-local'\n | 'time-local'\n | 'time-iso'\n | 'time-us'\n | 'relative-time'\n | 'unix-timestamp'\n | 'unix-timestamp-ms';\n\nexport type DateFormatOptions = {\n unit?: DateUnits;\n /**\n * The locale to use for formatting. Defaults to the system's locale.\n */\n locale?: string;\n /**\n * The timezone to use for formatting. Defaults to the user's local timezone.\n */\n timeZone?: string;\n /**\n * For relative time formatting, the reference time to compare against.\n * Defaults to current time.\n */\n referenceTime?: number;\n /**\n * This property is not used for date formatting, but is included for\n * compatibility with the FormatControls UI component.\n */\n decimalPlaces?: number;\n};\n\nconst DATE_GROUP = 'Date';\n\nexport const DATE_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Date & Time',\n};\n\nexport const DATE_UNIT_CONFIG: Readonly<Record<DateUnits, UnitConfig>> = {\n 'datetime-iso': {\n group: DATE_GROUP,\n label: 'DateTime (GMT)',\n },\n 'datetime-us': {\n group: DATE_GROUP,\n label: 'DateTime (US-East)',\n },\n 'datetime-local': {\n group: DATE_GROUP,\n label: 'DateTime (Browser Local)',\n },\n 'date-iso': {\n group: DATE_GROUP,\n label: 'Date (GMT)',\n },\n 'date-us': {\n group: DATE_GROUP,\n label: 'Date (US-East)',\n },\n 'date-local': {\n group: DATE_GROUP,\n label: 'Date (Browser Local)',\n },\n 'time-local': {\n group: DATE_GROUP,\n label: 'Time (Browser Local)',\n },\n 'time-iso': {\n group: DATE_GROUP,\n label: 'Time (GMT)',\n },\n 'time-us': {\n group: DATE_GROUP,\n label: 'Time (US-East)',\n },\n 'relative-time': {\n group: DATE_GROUP,\n label: 'Relative Time',\n },\n 'unix-timestamp': {\n group: DATE_GROUP,\n label: 'Unix Timestamp (s)',\n },\n 'unix-timestamp-ms': {\n group: DATE_GROUP,\n label: 'Unix Timestamp (ms)',\n },\n};\n\n/**\n * Converts a numeric value to a Date object.\n * Handles both Unix timestamps (seconds) and millisecond timestamps.\n */\nfunction valueToDate(value: number): Date {\n // Timestamp detection logic with special case handling\n // Main threshold stays at 10 billion to maintain existing behavior\n // Handle special edge cases explicitly\n\n // Special case: negative timestamps\n if (value < 0) {\n // For negative values, check magnitude to distinguish seconds vs milliseconds\n // Large negative values (> 1 billion in magnitude) are likely milliseconds\n // Small negative values are likely seconds (rare edge case)\n if (Math.abs(value) > 10000000000) {\n return new Date(value); // milliseconds\n } else {\n return new Date(value * 1000); // seconds\n }\n }\n\n // Special case: year 9999 in seconds (~253402300799)\n // This is a very specific edge case for far-future timestamps\n if (value >= 250000000000 && value <= 260000000000) {\n // Check if this looks like year 9999 in seconds\n const asSeconds = new Date(value * 1000);\n const year = asSeconds.getUTCFullYear();\n if (year >= 9999) {\n return asSeconds; // seconds\n }\n }\n\n const SECONDS_THRESHOLD = 10000000000; // ~year 2286 - original threshold\n\n if (value < SECONDS_THRESHOLD) {\n // Assume it's in seconds\n return new Date(value * 1000);\n } else {\n // Assume it's in milliseconds\n return new Date(value);\n }\n}\n\n/**\n * Formats a relative time string using the Intl.RelativeTimeFormat API.\n */\nfunction formatRelativeTime(date: Date, referenceTime: number, locale: string): string {\n const referenceDate = new Date(referenceTime);\n const diffMs = date.getTime() - referenceDate.getTime();\n\n const units = [\n { unit: 'year', ms: 1000 * 60 * 60 * 24 * 365 },\n { unit: 'month', ms: 1000 * 60 * 60 * 24 * 30 },\n { unit: 'week', ms: 1000 * 60 * 60 * 24 * 7 },\n { unit: 'day', ms: 1000 * 60 * 60 * 24 },\n { unit: 'hour', ms: 1000 * 60 * 60 },\n { unit: 'minute', ms: 1000 * 60 },\n { unit: 'second', ms: 1000 },\n ] as const;\n\n for (const { unit, ms } of units) {\n // Determine the value for the current unit, ensuring it's an integer for Intl.RelativeTimeFormat\n const value = Math.round(diffMs / ms);\n // If the absolute value is 1 or more, use this unit\n if (Math.abs(value) >= 1) {\n const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n return rtf.format(value, unit);\n }\n }\n\n // If less than a second, show \"now\" or \"0 seconds\"\n const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n return rtf.format(0, 'second');\n}\n\n/**\n * Gets the browser's preferred locale with comprehensive fallbacks.\n */\nconst getBrowserLocale = (): string => {\n if (typeof navigator !== 'undefined') {\n if (navigator.language) return navigator.language;\n if (navigator.languages && navigator.languages.length > 0) {\n const firstLanguage = navigator.languages[0];\n if (firstLanguage) return firstLanguage;\n }\n // Legacy fallbacks for older browsers\n const nav = navigator as Navigator & {\n userLanguage?: string;\n browserLanguage?: string;\n systemLanguage?: string;\n };\n if (nav.userLanguage) return nav.userLanguage;\n if (nav.browserLanguage) return nav.browserLanguage;\n if (nav.systemLanguage) return nav.systemLanguage;\n }\n // Node.js or server-side fallback, or if navigator is not available/empty\n return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';\n};\n\nexport function formatDate(value: number, options: DateFormatOptions = {}): string {\n const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n const {\n unit = 'datetime-local',\n locale = getBrowserLocale(),\n timeZone = systemTimeZone,\n referenceTime = Date.now(),\n } = options;\n\n // Handle raw timestamp display\n if (unit === 'unix-timestamp') {\n // Ensure it's in seconds. If it looks like milliseconds, convert.\n const timestamp = value > 1000000000000 ? Math.floor(value / 1000) : value;\n return timestamp.toString();\n }\n\n if (unit === 'unix-timestamp-ms') {\n // Ensure it's in milliseconds. If it looks like seconds, convert.\n // Use 100 billion as threshold - values < 100B are likely seconds, >= 100B are likely milliseconds\n // This distinguishes between 999999999 (seconds) and 999999999000 (milliseconds)\n const MILLISECONDS_THRESHOLD = 100000000000; // 100 billion\n const timestamp = value < MILLISECONDS_THRESHOLD ? value * 1000 : value;\n return Math.floor(timestamp).toString();\n }\n\n const date = valueToDate(value);\n\n // Handle relative time\n if (unit === 'relative-time') {\n return formatRelativeTime(date, referenceTime, locale);\n }\n\n // Configure Intl.DateTimeFormat options based on unit\n const formatOptions: Intl.DateTimeFormatOptions = {\n timeZone, // This will be overridden for specific units that need different timezones\n };\n\n switch (unit) {\n case 'datetime-iso':\n // datetime-iso should ALWAYS show GMT/UTC time\n return date.toISOString();\n\n case 'datetime-us': {\n // datetime-us should ALWAYS show date in US Eastern timezone\n formatOptions.timeZone = 'America/New_York';\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = true; // 12-hour format with AM/PM\n const formatter = new Intl.DateTimeFormat('en-US', formatOptions);\n return formatter.format(date);\n }\n\n case 'datetime-local':\n // datetime-local should use the browser's local timezone (detected automatically)\n // Don't override timeZone - let it use the detected system timezone\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = false; // 24-hour format\n break;\n\n case 'date-iso':\n // date-iso should ALWAYS show GMT/UTC date\n return date.toISOString().split('T')[0]!;\n\n case 'date-us': {\n // date-us should ALWAYS show date in US Eastern timezone\n formatOptions.timeZone = 'America/New_York';\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n const formatter = new Intl.DateTimeFormat('en-US', formatOptions);\n return formatter.format(date);\n }\n\n case 'date-local':\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n break;\n\n case 'time-local':\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = false; // 24-hour format\n break;\n\n case 'time-iso':\n // time-iso should ALWAYS show GMT/UTC time\n return date.toISOString().split('T')[1]!.replace('Z', '');\n\n case 'time-us': {\n // time-us should show time in US-East timezone (Eastern Time)\n formatOptions.timeZone = 'America/New_York';\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = true;\n return new Intl.DateTimeFormat('en-US', formatOptions).format(date);\n }\n\n default: {\n // This ensures that all DateUnits are handled at compile time.\n const exhaustive: never = unit;\n throw new Error(`Unknown date unit: ${exhaustive}`);\n }\n }\n\n // For all other units, use Intl.DateTimeFormat with the specified locale and options\n const formatter = new Intl.DateTimeFormat(locale, formatOptions);\n return formatter.format(date);\n}\n"],"names":["DATE_GROUP","DATE_GROUP_CONFIG","label","DATE_UNIT_CONFIG","group","valueToDate","value","Math","abs","Date","asSeconds","year","getUTCFullYear","SECONDS_THRESHOLD","formatRelativeTime","date","referenceTime","locale","referenceDate","diffMs","getTime","units","unit","ms","round","rtf","Intl","RelativeTimeFormat","numeric","format","getBrowserLocale","navigator","language","languages","length","firstLanguage","nav","userLanguage","browserLanguage","systemLanguage","DateTimeFormat","resolvedOptions","formatDate","options","systemTimeZone","timeZone","now","timestamp","floor","toString","MILLISECONDS_THRESHOLD","formatOptions","toISOString","month","day","hour","minute","second","hour12","formatter","split","replace","exhaustive","Error"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAwCjC,MAAMA,aAAa;AAEnB,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;AACT,EAAE;AAEF,OAAO,MAAMC,mBAA4D;IACvE,gBAAgB;QACdC,OAAOJ;QACPE,OAAO;IACT;IACA,eAAe;QACbE,OAAOJ;QACPE,OAAO;IACT;IACA,kBAAkB;QAChBE,OAAOJ;QACPE,OAAO;IACT;IACA,YAAY;QACVE,OAAOJ;QACPE,OAAO;IACT;IACA,WAAW;QACTE,OAAOJ;QACPE,OAAO;IACT;IACA,cAAc;QACZE,OAAOJ;QACPE,OAAO;IACT;IACA,cAAc;QACZE,OAAOJ;QACPE,OAAO;IACT;IACA,YAAY;QACVE,OAAOJ;QACPE,OAAO;IACT;IACA,WAAW;QACTE,OAAOJ;QACPE,OAAO;IACT;IACA,iBAAiB;QACfE,OAAOJ;QACPE,OAAO;IACT;IACA,kBAAkB;QAChBE,OAAOJ;QACPE,OAAO;IACT;IACA,qBAAqB;QACnBE,OAAOJ;QACPE,OAAO;IACT;AACF,EAAE;AAEF;;;CAGC,GACD,SAASG,YAAYC,KAAa;IAChC,uDAAuD;IACvD,mEAAmE;IACnE,uCAAuC;IAEvC,oCAAoC;IACpC,IAAIA,QAAQ,GAAG;QACb,8EAA8E;QAC9E,2EAA2E;QAC3E,4DAA4D;QAC5D,IAAIC,KAAKC,GAAG,CAACF,SAAS,aAAa;YACjC,OAAO,IAAIG,KAAKH,QAAQ,eAAe;QACzC,OAAO;YACL,OAAO,IAAIG,KAAKH,QAAQ,OAAO,UAAU;QAC3C;IACF;IAEA,qDAAqD;IACrD,8DAA8D;IAC9D,IAAIA,SAAS,gBAAgBA,SAAS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CAAC,SAASW;gBACnD,OAAOQ,UAAU9B,MAAM,CAACd;YAC1B;QAEA,KAAK;YACHoC,cAAcxC,IAAI,GAAG;YACrBwC,cAAcE,KAAK,GAAG;YACtBF,cAAcG,GAAG,GAAG;YACpB;QAEF,KAAK;YACHH,cAAcI,IAAI,GAAG;YACrBJ,cAAcK,MAAM,GAAG;YACvBL,cAAcM,MAAM,GAAG;YACvBN,cAAcO,MAAM,GAAG,OAAO,iBAAiB;YAC/C;QAEF,KAAK;YACH,2CAA2C;YAC3C,OAAO3C,KAAKqC,WAAW,GAAGQ,KAAK,CAAC,IAAI,CAAC,EAAE,CAAEC,OAAO,CAAC,KAAK;QAExD,KAAK;YAAW;gBACd,8DAA8D;gBAC9DV,cAAcN,QAAQ,GAAG;gBACzBM,cAAcI,IAAI,GAAG;gBACrBJ,cAAcK,MAAM,GAAG;gBACvBL,cAAcM,MAAM,GAAG;gBACvBN,cAAcO,MAAM,GAAG;gBACvB,OAAO,IAAIhC,KAAKc,cAAc,CAAC,SAASW,eAAetB,MAAM,CAACd;YAChE;QAEA;YAAS;gBACP,+DAA+D;gBAC/D,MAAM+C,aAAoBxC;gBAC1B,MAAM,IAAIyC,MAAM,CAAC,mBAAmB,EAAED,YAAY;YACpD;IACF;IAEA,qFAAqF;IACrF,MAAMH,YAAY,IAAIjC,KAAKc,cAAc,CAACvB,QAAQkC;IAClD,OAAOQ,UAAU9B,MAAM,CAACd;AAC1B"}
@@ -0,0 +1,12 @@
1
+ import { UnitGroupConfig, UnitConfig } from './types';
2
+ type DecimalUnit = 'decimal';
3
+ export type DecimalFormatOptions = {
4
+ unit?: DecimalUnit;
5
+ decimalPlaces?: number;
6
+ shortValues?: boolean;
7
+ };
8
+ export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
9
+ export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>>;
10
+ export declare function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string;
11
+ export {};
12
+ //# sourceMappingURL=decimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../src/model/decimal.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,WAAW,GAAG,SAAS,CAAC;AAC7B,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CA4BzG"}
@@ -0,0 +1,53 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
+ import { getFormatterFromCache } from './formatterCache';
15
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
16
+ export const DECIMAL_GROUP_CONFIG = {
17
+ label: 'Decimal',
18
+ decimalPlaces: true,
19
+ shortValues: true
20
+ };
21
+ export const DECIMAL_UNIT_CONFIG = {
22
+ decimal: {
23
+ group: 'Decimal',
24
+ label: 'Decimal'
25
+ }
26
+ };
27
+ export function formatDecimal(value, { shortValues, decimalPlaces }) {
28
+ const formatterOptions = {
29
+ style: 'decimal',
30
+ useGrouping: true
31
+ };
32
+ if (shouldShortenValues(shortValues)) {
33
+ formatterOptions.notation = 'compact';
34
+ }
35
+ if (hasDecimalPlaces(decimalPlaces)) {
36
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
37
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
38
+ } else {
39
+ if (shouldShortenValues(shortValues)) {
40
+ formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
41
+ }
42
+ }
43
+ const key = [
44
+ formatterOptions.style,
45
+ formatterOptions.useGrouping,
46
+ formatterOptions.notation,
47
+ formatterOptions.maximumSignificantDigits,
48
+ decimalPlaces
49
+ ];
50
+ return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);
51
+ }
52
+
53
+ //# sourceMappingURL=decimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/decimal.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { getFormatterFromCache } from './formatterCache';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype DecimalUnit = 'decimal';\nexport type DecimalFormatOptions = {\n unit?: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.notation,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n ];\n\n return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAQpF,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,WAAW,EAAED,aAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIZ,oBAAoBI,cAAc;QACpCM,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIf,iBAAiBK,gBAAgB;QACnCO,iBAAiBI,qBAAqB,GAAGf,mBAAmBI;QAC5DO,iBAAiBK,qBAAqB,GAAGhB,mBAAmBI;IAC9D,OAAO;QACL,IAAIH,oBAAoBI,cAAc;YACpCM,iBAAiBM,wBAAwB,GAAGpB;QAC9C;IACF;IAEA,MAAMqB,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,WAAW;QAC5BF,iBAAiBG,QAAQ;QACzBH,iBAAiBM,wBAAwB;QACzCb;KACD;IAED,OAAON,sBAAsBoB,KAAK,WAAWP,kBAAkB,SAASD;AAC1E"}
@@ -0,0 +1,11 @@
1
+ type FormatFn = (value: number | bigint) => string;
2
+ type InputType = 'time' | 'temperature' | 'bytes' | 'bits' | 'decimal' | 'currency' | 'percent' | 'throughput';
3
+ type Locals = 'en-US' | 'en-GB';
4
+ export declare function getFormatterFromCache(key: Array<string | number | boolean | undefined>, inputType: InputType, formatterOptions: Intl.NumberFormatOptions, locals?: Locals): FormatFn;
5
+ export interface IFormatterStats {
6
+ countCacheItems: (inputType: InputType | 'all') => number;
7
+ getKeys: (inputType: InputType) => string[];
8
+ }
9
+ export declare const getFormatterStats: () => IFormatterStats;
10
+ export {};
11
+ //# sourceMappingURL=formatterCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatterCache.d.ts","sourceRoot":"","sources":["../../src/model/formatterCache.ts"],"names":[],"mappings":"AAaA,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AACnD,KAAK,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,CAAC;AAC/G,KAAK,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAqChC,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EACjD,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,IAAI,CAAC,mBAAmB,EAC1C,MAAM,GAAE,MAAgB,GACvB,QAAQ,CAcV;AAGD,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,KAAK,KAAK,MAAM,CAAC;IAC1D,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,MAAM,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,iBAAiB,QAAO,eAcpC,CAAC"}