karsten-design-system 1.1.71 → 1.1.72

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 (66) hide show
  1. package/dist/{index.esm.js → index.js} +31 -1
  2. package/dist/index.js.map +1 -0
  3. package/dist/types/assets/icons/error.d.ts +1 -0
  4. package/dist/types/assets/icons/filter.d.ts +5 -0
  5. package/dist/types/assets/icons/info.d.ts +1 -0
  6. package/dist/types/assets/icons/success.d.ts +1 -0
  7. package/dist/types/assets/icons/text.d.ts +1 -0
  8. package/dist/types/assets/logoSmall.d.ts +1 -0
  9. package/dist/types/components/floating-label/index.d.ts +8 -0
  10. package/dist/types/index.d.ts +40 -4
  11. package/dist/types/stories/components/accordion.d.ts +15 -0
  12. package/dist/types/stories/components/autoComplete.d.ts +7 -0
  13. package/dist/types/stories/components/basicHeader.d.ts +1 -0
  14. package/dist/types/stories/components/breadcrumb.d.ts +5 -0
  15. package/dist/types/stories/components/button.d.ts +18 -0
  16. package/dist/types/stories/components/calendarInput.d.ts +8 -0
  17. package/dist/types/stories/components/card.d.ts +6 -0
  18. package/dist/types/stories/components/cardButton.d.ts +7 -0
  19. package/dist/types/stories/components/cardIconsButton.d.ts +8 -0
  20. package/dist/types/stories/components/chart.d.ts +3 -0
  21. package/dist/types/stories/components/dialog.d.ts +8 -0
  22. package/dist/types/stories/components/divider.d.ts +2 -0
  23. package/dist/types/stories/components/emptyContent.d.ts +5 -0
  24. package/dist/types/stories/components/expandablePanel.d.ts +8 -0
  25. package/dist/types/stories/components/fileUpload.d.ts +21 -0
  26. package/dist/types/stories/components/filterButton.d.ts +26 -0
  27. package/dist/types/stories/components/header.d.ts +10 -0
  28. package/dist/types/stories/components/iconButton.d.ts +11 -0
  29. package/dist/types/stories/components/infoCard.d.ts +9 -0
  30. package/dist/types/stories/components/input.d.ts +18 -0
  31. package/dist/types/stories/components/inputSwitch.d.ts +8 -0
  32. package/dist/types/stories/components/inputTextArea.d.ts +10 -0
  33. package/dist/types/stories/components/internalMenu.d.ts +6 -0
  34. package/dist/types/stories/components/link.d.ts +6 -0
  35. package/dist/types/stories/components/megaMenu.d.ts +5 -0
  36. package/dist/types/stories/components/modal.d.ts +13 -0
  37. package/dist/types/stories/components/multiselect.d.ts +15 -0
  38. package/dist/types/stories/components/notification.d.ts +15 -0
  39. package/dist/types/stories/components/notificationItem.d.ts +8 -0
  40. package/dist/types/stories/components/paginator.d.ts +2 -0
  41. package/dist/types/stories/components/radioButton.d.ts +16 -0
  42. package/dist/types/stories/components/select.d.ts +15 -0
  43. package/dist/types/stories/components/sidebar.d.ts +14 -0
  44. package/dist/types/stories/components/skeleton.d.ts +2 -0
  45. package/dist/types/stories/components/spinner.d.ts +15 -0
  46. package/dist/types/stories/components/table.d.ts +39 -0
  47. package/dist/types/stories/components/tabs.d.ts +14 -0
  48. package/dist/types/stories/components/tagStatus.d.ts +6 -0
  49. package/dist/types/stories/components/toast.d.ts +10 -0
  50. package/dist/types/stories/components/tooltip.d.ts +6 -0
  51. package/dist/types/types/breadcrumbItems.d.ts +4 -0
  52. package/dist/types/types/index.d.ts +4 -0
  53. package/dist/types/types/internalMenu.d.ts +15 -0
  54. package/dist/types/types/megaMenuItems.d.ts +6 -0
  55. package/dist/types/types/notification.d.ts +7 -0
  56. package/dist/types/types/options.d.ts +4 -0
  57. package/dist/types/types/table.d.ts +10 -0
  58. package/dist/types/utils/masks/index.d.ts +8 -0
  59. package/dist/types/utils/nestedValue.d.ts +1 -0
  60. package/dist/types/utils/sortData.d.ts +2 -0
  61. package/package.json +30 -7
  62. package/dist/index.cjs.css +0 -4
  63. package/dist/index.cjs.js +0 -4537
  64. package/dist/index.cjs.js.map +0 -1
  65. package/dist/index.esm.css +0 -4
  66. package/dist/index.esm.js.map +0 -1
package/dist/index.cjs.js DELETED
@@ -1,4537 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var clsx = require('clsx');
5
- var React = require('react');
6
- var iconfield = require('primereact/iconfield');
7
- var inputicon = require('primereact/inputicon');
8
- var inputtext = require('primereact/inputtext');
9
- var reactRouterDom = require('react-router-dom');
10
- var button = require('primereact/button');
11
- var api = require('primereact/api');
12
- var calendar = require('primereact/calendar');
13
- var chart = require('primereact/chart');
14
- var divider = require('primereact/divider');
15
- var ReactDOM = require('react-dom');
16
- var inputswitch = require('primereact/inputswitch');
17
- var inputtextarea = require('primereact/inputtextarea');
18
- var sidebar = require('primereact/sidebar');
19
- var paginator = require('primereact/paginator');
20
- var utils = require('primereact/utils');
21
- var skeleton = require('primereact/skeleton');
22
-
23
- function Accordion({ tabsChildren, headers, multiple = false, activeIndex, className, onClickFavorite, showFavorite = false, }) {
24
- const [openIndexes, setOpenIndexes] = React.useState(activeIndex
25
- ? Array.isArray(activeIndex)
26
- ? activeIndex
27
- : [activeIndex]
28
- : []);
29
- const toggleTab = (index) => {
30
- if (multiple) {
31
- setOpenIndexes((prev) => prev.includes(index)
32
- ? prev.filter((i) => i !== index)
33
- : [...prev, index]);
34
- }
35
- else {
36
- setOpenIndexes((prev) => (prev.includes(index) ? [] : [index]));
37
- }
38
- };
39
- return (jsxRuntime.jsx("div", { className: clsx('w-full flex flex-col text-primary', className), children: tabsChildren.map((tab, index) => (jsxRuntime.jsxs("div", { className: "w-full", children: [jsxRuntime.jsx("div", { className: "flex items-center justify-between w-full border-b border-b-primary bg-background", children: jsxRuntime.jsxs("button", { onClick: () => toggleTab(index), className: "flex items-center justify-between w-full px-4 py-2", "aria-label": "Abrir aba de menus", children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [showFavorite && (jsxRuntime.jsx("i", { className: clsx('text-primary cursor-pointer text-lg', headers[index]?.isFavorite
40
- ? 'pi pi-star-fill text-primary'
41
- : 'pi pi-star'), onClick: (e) => {
42
- e.stopPropagation();
43
- onClickFavorite?.(index);
44
- } })), jsxRuntime.jsx("span", { className: "text-left text-primary text-base font-bold font-roboto", children: headers[index].label })] }), jsxRuntime.jsx("i", { className: clsx('pi', openIndexes.includes(index) ? 'pi-angle-up' : 'pi-angle-down', 'text-primary ml-4') })] }) }), openIndexes.includes(index) && jsxRuntime.jsx("div", { className: "py-4", children: tab })] }, index))) }));
45
- }
46
-
47
- const FloatingLabel = ({ value, label, disabled, error, }) => {
48
- const [isFloating, setIsFloating] = React.useState(!!value);
49
- React.useEffect(() => {
50
- setIsFloating(!!value);
51
- }, [value]);
52
- return (jsxRuntime.jsx("label", { className: clsx('absolute left-4 text-gray transition-all bg-background px-1 z-20 font-roboto text-sm', isFloating ? '-top-3 text-primary' : 'top-[9px]', disabled ? 'text-stoneDark' : error ? 'text-redError' : 'text-gray'), children: isFloating ? label : value }));
53
- };
54
-
55
- const maskCPF = (value) => {
56
- value = value.replace(/\D/g, '');
57
- value = value.slice(0, 11);
58
- if (value.length <= 3) {
59
- return value;
60
- }
61
- if (value.length <= 6) {
62
- return value.replace(/(\d{3})(\d{1,})/, '$1.$2');
63
- }
64
- if (value.length <= 9) {
65
- return value.replace(/(\d{3})(\d{3})(\d{1,})/, '$1.$2.$3');
66
- }
67
- return value.replace(/(\d{3})(\d{3})(\d{3})(\d{1,})/, '$1.$2.$3-$4');
68
- };
69
- const maskCNPJ = (value) => {
70
- value = value.replace(/\D/g, '');
71
- value = value.slice(0, 14);
72
- if (value.length <= 2) {
73
- return value;
74
- }
75
- if (value.length <= 5) {
76
- return value.replace(/(\d{2})(\d{1,})/, '$1.$2');
77
- }
78
- if (value.length <= 8) {
79
- return value.replace(/(\d{2})(\d{3})(\d{1,})/, '$1.$2.$3');
80
- }
81
- if (value.length <= 12) {
82
- return value.replace(/(\d{2})(\d{3})(\d{3})(\d{1,})/, '$1.$2.$3/$4');
83
- }
84
- return value.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{1,})/, '$1.$2.$3/$4-$5');
85
- };
86
- // export const maskNumber = (value: string) => {
87
- // value = value.replace(/\D/g, '');
88
- // value = value.slice(0, 12);
89
- // return value.replace(/(\d)(\d{2})$/, '$1,$2');
90
- // };
91
- const maskOnlyNumbers = (value) => {
92
- value = value.replace(/\D/g, '');
93
- value = value.slice(0, 15);
94
- return value;
95
- };
96
- const maskNumberWithDecimal = (value) => {
97
- const regex = /^[0-9]+([.,][0-9]+)?$/;
98
- value = value.slice(0, 20);
99
- if (!regex.test(value)) {
100
- return value.replace(/[^0-9.,]/g, '').replace(/([.,]).*\1/g, '$1');
101
- }
102
- return value;
103
- };
104
- const maskCellphone = (value) => {
105
- value = value.replace(/\D/g, '');
106
- value = value.slice(0, 11);
107
- if (value.length <= 2) {
108
- return value.replace(/(\d{2})/, '($1');
109
- }
110
- if (value.length <= 6) {
111
- return value.replace(/(\d{2})(\d{4})/, '($1) $2');
112
- }
113
- return value.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2-$3');
114
- };
115
- const maskPhone = (value) => {
116
- value = value.replace(/\D/g, '');
117
- value = value.slice(0, 10);
118
- if (value.length <= 2) {
119
- return value.replace(/(\d{2})/, '($1');
120
- }
121
- if (value.length <= 6) {
122
- return value.replace(/(\d{2})(\d{4})/, '($1) $2');
123
- }
124
- return value.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2-$3');
125
- };
126
- const maskCEP = (value) => {
127
- value = value.replace(/\D/g, '');
128
- value = value.slice(0, 8);
129
- return value.replace(/(\d{5})(\d{1,})/, '$1-$2');
130
- };
131
- const maskMoneyBRL = (value) => {
132
- value = value.replace(/\D/g, '');
133
- if (!value)
134
- return '';
135
- value = value.slice(0, 13);
136
- const numericValue = parseFloat(value) / 100;
137
- return numericValue.toLocaleString('pt-BR', {
138
- style: 'currency',
139
- currency: 'BRL',
140
- });
141
- };
142
-
143
- const variants$4 = {
144
- green: 'text-green',
145
- gray: 'text-gray',
146
- };
147
- function Input({ onChange, placeholder, disabled = false, error, icon, onClickIcon, iconColor = 'green', label, mask, ...props }) {
148
- const inputId = React.useId();
149
- const [inputValue, setInputValue] = React.useState('');
150
- const applyMask = (value, mask) => {
151
- switch (mask) {
152
- case 'cpf':
153
- return maskCPF(value);
154
- case 'cnpj':
155
- return maskCNPJ(value);
156
- case 'numbers':
157
- return maskOnlyNumbers(value);
158
- case 'cellphone':
159
- return maskCellphone(value);
160
- case 'phone':
161
- return maskPhone(value);
162
- case 'decimal':
163
- return maskNumberWithDecimal(value);
164
- case 'cep':
165
- return maskCEP(value);
166
- case 'currency':
167
- return maskMoneyBRL(value);
168
- default:
169
- return value;
170
- }
171
- };
172
- React.useEffect(() => {
173
- const formatted = applyMask(props?.value ?? '', mask);
174
- setInputValue(formatted);
175
- }, [props?.value, mask]);
176
- const handleChange = (e) => {
177
- const value = applyMask(e.target.value, mask);
178
- setInputValue(value);
179
- onChange(value);
180
- };
181
- const hasError = (props?.value && error && !disabled) ||
182
- (!!error && !disabled && props?.value?.length === 0);
183
- return (jsxRuntime.jsxs("div", { className: "relative flex flex-col w-100", children: [jsxRuntime.jsxs(iconfield.IconField, { className: "w-100", children: [jsxRuntime.jsx(inputicon.InputIcon, { className: clsx(`pi ${icon} px-2 cursor-pointer`, hasError
184
- ? 'text-redError'
185
- : disabled
186
- ? 'text-stone'
187
- : variants$4[iconColor]), onClick: onClickIcon }), jsxRuntime.jsx(inputtext.InputText, { id: inputId, type: "text", placeholder: placeholder, className: clsx('focus:shadow-none text-base w-100 font-roboto border !p-2 rounded-md', hasError
188
- ? 'border-redError placeholder:text-redError'
189
- : 'border-gray focus:border-primary', disabled && 'border-stoneDark text-disabled', error && 'border-redError text-redError', !error && 'border-gray placeholder:text-gray'), onChange: handleChange, disabled: disabled, invalid: hasError, ...props, value: inputValue })] }), jsxRuntime.jsx(FloatingLabel, { value: props?.value ? props?.value?.toString() : '', label: label || '', disabled: disabled, error: error }), hasError && jsxRuntime.jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
190
- }
191
-
192
- function AutoComplete({ items, onChange, error, ...props }) {
193
- const [isOpen, setIsOpen] = React.useState(false);
194
- const [filteredItems, setFilteredItems] = React.useState(items);
195
- const handleInputChange = (value) => {
196
- onChange(value);
197
- setIsOpen(!!value);
198
- const filtered = items.filter((item) => item.toLowerCase().includes(value.toLowerCase()));
199
- setFilteredItems(filtered);
200
- };
201
- const handleSelect = (selectedValue) => {
202
- onChange(selectedValue);
203
- setIsOpen(false);
204
- };
205
- const handleIconClick = () => {
206
- if (isOpen) {
207
- onChange('');
208
- setFilteredItems(items);
209
- }
210
- setIsOpen(!isOpen);
211
- };
212
- return (jsxRuntime.jsxs("div", { className: "relative w-100", children: [jsxRuntime.jsx(iconfield.IconField, { className: "w-100", children: jsxRuntime.jsx(Input, { ...props, onChange: handleInputChange, icon: isOpen ? 'pi-times' : 'pi-search', iconColor: isOpen ? 'gray' : 'green', onClickIcon: handleIconClick, error: error }) }), isOpen && filteredItems.length > 0 && (jsxRuntime.jsx("div", { className: "absolute w-100 max-h-48 -bottom-1 translate-y-full overflow-y-auto bg-white shadow-md z-10 rounded-md border border-stoneDark [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:rounded-r-md [&::-webkit-scrollbar-thumb]:rounded-md [&::-webkit-scrollbar-track]:bg-stone [&::-webkit-scrollbar-thumb]:bg-stoneDark", children: jsxRuntime.jsx("ul", { children: filteredItems.map((item) => (jsxRuntime.jsx("li", { onClick: () => handleSelect(item), className: "p-3 text-backgroundDark cursor-pointer hover:bg-secondary rounded-md", children: item }, item))) }) }))] }));
213
- }
214
-
215
- function LogoSmall() {
216
- return (jsxRuntime.jsxs("svg", { width: "92", height: "19", viewBox: "0 0 92 19", fill: "none", children: [jsxRuntime.jsxs("g", { clipPath: "url(#clip0_297_2300)", children: [jsxRuntime.jsx("path", { d: "M91.7394 11.8865C91.7803 10.4995 91.7909 9.58382 91.7705 9.14601C91.7156 7.98967 91.4236 7.04721 90.8966 6.31195C90.3697 5.5767 89.4247 4.87486 88.0886 4.78128C85.8182 4.62755 84.8462 4.99183 83.2655 6.19498C82.5381 6.74642 81.8208 7.64544 81.1852 8.34393L81.3415 5.3862H77.1061C77.1809 7.94956 77.1775 10.5229 77.0959 13.1031L77.0109 15.2888C76.9701 16.141 76.9225 16.9932 76.8647 17.8488H81.1274C81.1172 17.0066 81.1443 15.8736 81.2123 14.4499C81.2803 13.0295 81.3619 11.9968 81.4639 11.3451C81.6236 10.4126 82.0046 9.63732 82.6027 9.02573C83.2008 8.41077 83.9454 7.66883 84.8699 7.66883C86.5865 7.70893 87.484 9.38328 87.6403 11.8331C87.7082 13.2066 87.6943 15.2152 87.6059 17.8488H91.8179C91.7328 16.1644 91.7091 14.1759 91.7394 11.8865Z", fill: "#878787" }), jsxRuntime.jsx("path", { d: "M70.8993 16.094C69.6314 16.1241 68.5607 15.586 67.7176 15.0079C66.8747 14.4297 66.4192 13.4137 66.3477 11.9532H76.0593V10.9806C75.8622 6.92673 73.6051 4.90479 69.2337 4.90479C68.1051 4.90479 67.0854 5.0886 66.1778 5.45622C65.2702 5.82385 64.5054 6.33853 63.8697 7.00695C63.2409 7.66868 62.7718 8.44069 62.4727 9.31301C62.1701 10.1919 62.0409 11.1311 62.0919 12.1337C62.1667 13.6777 62.595 14.9009 63.3734 15.7966C64.1553 16.6956 65.1274 17.3206 66.2933 17.6648C67.4593 18.0091 68.7204 18.263 70.0665 18.1828C72.361 18.0491 74.5875 16.9563 76.0593 16.0172V14.0988C74.4414 15.195 72.0211 16.0673 70.8993 16.094ZM66.2253 10.5261C66.1778 9.55028 66.4089 8.70469 66.9222 7.98617C67.4389 7.26428 68.2411 6.88329 69.3323 6.8365C69.9033 6.8365 70.386 6.96684 70.7803 7.22084C71.178 7.47483 71.4738 7.80904 71.6709 8.22012C71.8681 8.62785 71.9803 9.06567 72.0041 9.52688C72.0109 9.6672 71.9973 9.84769 71.9667 10.0783C71.9361 10.3022 71.9157 10.4493 71.9123 10.5261H66.2253Z", fill: "#878787" }), jsxRuntime.jsx("path", { d: "M62.0138 5.39624H57.9823L58.1285 1.92383L54.1003 2.76603C53.876 6.74309 53.8114 10.7335 53.7095 14.7239C53.7026 15.0214 53.6823 15.3924 53.7061 15.8368C53.7367 16.4451 53.9372 16.9364 54.148 17.3107C54.3587 17.6817 54.6918 17.9657 55.1337 18.1563C55.5756 18.3468 56.3643 18.5372 57.1087 18.4938C58.8321 18.3902 59.7363 18.0827 60.4705 17.8288L60.909 15.5394C60.4909 15.6864 60.0116 15.8101 59.6717 15.8368C58.9612 15.887 58.5262 15.8435 57.9517 15.252C57.6016 14.8877 57.7851 12.7588 57.8021 12.0871L57.9075 7.95292H61.4631C61.5549 7.09736 61.7827 6.3153 62.0138 5.39624Z", fill: "#878787" }), jsxRuntime.jsx("path", { d: "M51.4557 7.79912L51.6257 5.51983C49.8478 5.15554 47.9443 4.94165 46.6764 5.01851C45.1841 5.10541 43.9808 5.33935 43.0766 5.89414C42.1758 6.45226 41.7475 7.27107 41.8018 8.34387C41.8291 8.94547 41.9922 9.4534 42.2811 9.86453C42.5701 10.2789 43.046 10.7535 43.7122 11.2916C43.8822 11.4319 44.2221 11.6826 44.7286 12.0469C45.2351 12.4145 45.643 12.7253 45.9523 12.986C46.2651 13.2467 46.5234 13.5307 46.7444 13.8382C46.9585 14.1457 47.0775 14.4632 47.0945 14.784C47.0673 15.2619 46.826 15.5961 46.3738 15.7866C45.9252 15.9738 45.3982 16.0708 44.8068 16.0708C44.2255 16.0373 43.6 15.9371 42.9169 15.7666C42.237 15.5928 41.6659 15.3722 41.207 15.1115L41.5164 17.9189C42.9882 18.2664 44.7116 18.4402 46.69 18.4402C47.5092 18.4402 48.3012 18.2932 49.0694 18.0058C49.8376 17.7117 50.4563 17.3039 50.9254 16.7826C51.3945 16.2545 51.6121 15.663 51.5815 15.0046C51.5509 14.3964 51.3265 13.8215 50.905 13.2901C50.4869 12.762 49.8717 12.204 49.0661 11.6224C48.8485 11.4787 48.5799 11.3016 48.2604 11.0911C47.9409 10.8738 47.635 10.6365 47.3427 10.3658C47.0537 10.0917 46.8123 9.79769 46.6186 9.4768C46.4283 9.15599 46.2855 8.81513 46.3059 8.4575C46.35 7.73895 47.0469 7.33791 48.2672 7.29112C49.0729 7.2577 49.943 7.37801 51.4557 7.79912Z", fill: "#878787" }), jsxRuntime.jsx("path", { d: "M40.459 8.32386L40.7479 4.92163C39.9151 4.92163 38.5826 5.22577 37.7396 5.69365C36.917 6.15151 36.4139 6.68624 35.6593 7.43153L35.7375 5.41292C34.3132 5.41292 32.9739 5.36947 31.5496 5.36947C31.7161 9.63397 31.7569 13.7113 31.5088 17.9658H35.8497C35.8258 17.4812 35.7443 17.0634 35.7238 16.7024C35.6593 15.6129 35.6083 14.6337 35.6253 13.7614C35.6422 12.8891 35.7273 12.0402 35.87 11.2315C36.0162 10.416 36.2099 9.66065 36.5396 9.27635C37.2399 8.46088 38.2767 8.21357 39.3882 8.21357C39.7553 8.21357 40.1122 8.24699 40.459 8.32386Z", fill: "#878787" }), jsxRuntime.jsx("path", { d: "M24.2312 5.07852C22.1339 5.10192 20.0467 5.36928 17.9086 5.77368L17.6435 7.81233C18.8842 7.41128 20.1793 7.11384 21.539 6.84982C24.7445 6.22485 27.1749 9.11574 23.2692 10.0983C20.0196 10.9104 16.9365 11.6825 16.2362 13.0794C14.8595 15.8233 16.9501 17.5946 19.7646 18.2095C21.5798 18.6072 23.3779 18.5036 25.1523 17.9622C26.5427 17.9555 27.7018 17.9488 29.092 17.9388C29.1091 14.5867 29.3164 11.2346 29.2892 7.87918C29.2756 5.90401 27.1409 5.04845 24.2312 5.07852ZM25.3088 15.9135C24.068 16.368 22.936 16.6354 21.4812 16.2744C19.9584 15.8968 19.5641 13.9685 21.1651 13.1062C22.552 12.3542 24.4793 11.8997 25.5365 11.2346L25.3088 15.9135Z", fill: "#878787" }), jsxRuntime.jsx("path", { d: "M16.6135 0.5C14.8935 0.5 13.1735 0.5 11.4535 0.5C8.955 2.37156 5.90933 5.30589 4.76379 8.58446C4.77399 7.47824 4.79439 6.12804 4.82838 4.53054C4.85897 2.8194 4.87937 1.47589 4.89297 0.5H0.249625C0.259823 2.42503 0.27342 3.87549 0.27342 4.85805C0.280218 5.84062 0.283618 7.12732 0.283618 8.73148C0.287018 10.3357 0.280219 11.95 0.259824 13.5808C0.242828 15.2118 0.219032 16.6389 0.181641 17.8587H4.99154C4.98135 17.6615 4.96435 17.3741 4.93716 16.9931C4.90996 16.6121 4.88956 16.3247 4.88277 16.1375C4.82158 14.8709 4.78419 13.6209 4.77059 12.3944C4.757 11.2514 4.7536 10.5596 4.76379 9.48347C6.27985 11.1612 7.39819 12.4981 8.22761 13.6978C9.09099 14.9478 9.80141 16.3314 10.6784 17.8587H16.1478L8.80209 8.67804C9.04001 6.5057 13.9791 1.58617 16.6135 0.5Z", fill: "#878787" })] }), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", { id: "clip0_297_2300", children: jsxRuntime.jsx("rect", { width: "91.6364", height: "18", fill: "white", transform: "translate(0.181641 0.5)" }) }) })] }));
217
- }
218
-
219
- function BasicHeader() {
220
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "w-100 min-h-16 border-b border-b-stone flex flex-row justify-between items-center px-8 shadow-header", children: jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-4", children: jsxRuntime.jsx(LogoSmall, {}) }) }) }));
221
- }
222
-
223
- function Breadcrumb({ items }) {
224
- return (jsxRuntime.jsx("nav", { className: "w-100", children: jsxRuntime.jsx("ol", { className: "flex items-center gap-2", children: items?.map((item, index) => (jsxRuntime.jsxs("li", { className: "flex flex-row gap-2", "aria-label": "breadcrumb", children: [jsxRuntime.jsx(reactRouterDom.Link, { to: item.href, className: clsx('text-base text-primary hover:underline'), children: item.label }), index < items.length - 1 && (jsxRuntime.jsx("span", { className: "text-base text-primary", children: '>' }))] }, index))) }) }));
225
- }
226
-
227
- const variants$3 = {
228
- primary: 'bg-primary !text-background border-primary hover:bg-primaryActive disabled:bg-stoneDark disabled:border-stoneDark',
229
- outline: 'bg-background !text-primary border-primary hover:bg-stone disabled:bg-stoneDark disabled:text-background disabled:border-stoneDark',
230
- secondary: 'bg-stoneLight !text-grayDark border-stoneLight hover:bg-stone hover:border-stone disabled:bg-stone disabled:border-stone',
231
- secondaryOutline: 'bg-transparent !text-backgroundDark border-stoneDark hover:bg-stone disabled:text-stoneDark',
232
- gray: 'bg-gray !text-background border-gray hover:bg-grayDark hover:border-grayDark ',
233
- grayOutline: 'bg-transparent !text-gray100 border-gray50 hover:bg-stone disabled:bg-stone disabled:text-stoneDark',
234
- tab: 'bg-background !text-primary border-background hover:bg-secondaryActive hover:border-grayDark disabled:bg-stoneDark disabled:text-background disabled:border-stoneDark',
235
- };
236
- function Button({ variant = 'primary', selected = false, rightIcon, className, width = 'w-100', ...props }) {
237
- return (jsxRuntime.jsx(button.Button, { ...props, className: clsx('!py-2 !shadow-none font-roboto', variants$3[variant], selected && variant === 'tab' && 'bg-secondary border-grayDark ', width, className), "aria-label": "Componente Bot\u00E3o Padr\u00E3o", children: rightIcon && jsxRuntime.jsx("span", { className: `pi pl-2 ${rightIcon}`, children: " " }) }));
238
- }
239
-
240
- api.addLocale('pt-BR', {
241
- firstDayOfWeek: 0,
242
- dayNames: [
243
- 'domingo',
244
- 'segunda-feira',
245
- 'terça-feira',
246
- 'quarta-feira',
247
- 'quinta-feira',
248
- 'sexta-feira',
249
- 'sábado',
250
- ],
251
- dayNamesShort: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'],
252
- dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
253
- monthNames: [
254
- 'janeiro',
255
- 'fevereiro',
256
- 'março',
257
- 'abril',
258
- 'maio',
259
- 'junho',
260
- 'julho',
261
- 'agosto',
262
- 'setembro',
263
- 'outubro',
264
- 'novembro',
265
- 'dezembro',
266
- ],
267
- monthNamesShort: [
268
- 'jan',
269
- 'fev',
270
- 'mar',
271
- 'abr',
272
- 'mai',
273
- 'jun',
274
- 'jul',
275
- 'ago',
276
- 'set',
277
- 'out',
278
- 'nov',
279
- 'dez',
280
- ],
281
- today: 'Hoje',
282
- clear: 'Limpar',
283
- dateFormat: 'dd/mm/yy',
284
- });
285
- function CalendarInput({ error, placeholder = 'Selecione uma data', label, disabled = false, ...props }) {
286
- const calendarRef = React.useRef(null);
287
- const hasError = (error && !disabled) || (!!error && !disabled);
288
- const dateTemplate = (data) => {
289
- const date = new Date(`${data.year}/${data.month + 1}/${data.day}`);
290
- const dayComponent = (className) => {
291
- return (jsxRuntime.jsx("div", { className: `w-full h-full flex justify-center items-center text-grayDark ${className}`, children: data.day }));
292
- };
293
- if (props.selectionMode === 'range') {
294
- const [start, end] = Array.isArray(props.value)
295
- ? props.value
296
- : [null, null];
297
- if (start && date.getTime() === start.getTime()) {
298
- return dayComponent('bg-stone');
299
- }
300
- if (start && end && date >= start && date <= end) {
301
- return dayComponent('bg-stone');
302
- }
303
- return dayComponent();
304
- }
305
- if (props.selectionMode === 'single' || !props.selectionMode) {
306
- const selectedDate = props.value;
307
- if (selectedDate && date.getTime() === selectedDate.getTime()) {
308
- return dayComponent('bg-stone');
309
- }
310
- }
311
- return dayComponent();
312
- };
313
- const handleInputClick = () => {
314
- if (!disabled) {
315
- calendarRef.current?.show();
316
- }
317
- };
318
- return (jsxRuntime.jsx("div", { className: "relative flex flex-col w-full min-w-full", children: jsxRuntime.jsxs("div", { onClick: handleInputClick, children: [jsxRuntime.jsx(FloatingLabel, { value: props?.value ? props.value.toString() : '', label: label, disabled: disabled, error: error }), jsxRuntime.jsxs("div", { className: "relative w-full min-w-full", children: [jsxRuntime.jsx(calendar.Calendar, { ...props, disabled: disabled, placeholder: placeholder, ref: calendarRef, panelStyle: { width: '530px', height: '500px' }, className: clsx('w-full min-w-full focus:shadow-none border-none z-0 font-roboto border rounded-md', hasError
319
- ? 'border-redError placeholder:!text-redError p-invalid'
320
- : 'border-gray focus:border-primary', disabled && 'border-stoneDark text-disabled', error && 'border-redError text-redError p-invalid', !error && 'border-gray p-custom'), dateFormat: "dd/mm/yy", inputStyle: {
321
- border: `1px solid ${error && !props.value ? '#EC4A54' : '#a0a4b3'}`,
322
- boxShadow: 'none',
323
- color: hasError ? '#EC4A54' : '',
324
- height: '42px',
325
- fontSize: '16px',
326
- }, hideOnDateTimeSelect: true, hideOnRangeSelection: true, todayButtonClassName: "bg-primary text-background", dateTemplate: dateTemplate, invalid: hasError, locale: "pt-BR" }), jsxRuntime.jsx(inputicon.InputIcon, { className: clsx(`pi pi-calendar text-gray cursor-pointer absolute right-3 top-1/2 transform -translate-y-1/2`, disabled && 'text-disabled', hasError && 'text-redError') })] }), hasError && (jsxRuntime.jsx("div", { className: "mb-4", children: jsxRuntime.jsx("span", { className: "absolute text-redError text-xs px-2", children: error }) }))] }) }));
327
- }
328
-
329
- function Card({ children, className, ariaLabel = 'Card de informação', }) {
330
- return (jsxRuntime.jsx("div", { className: clsx('bg-background shadow-container rounded-md p-3', className ? className : 'w-full h-full'), "aria-label": ariaLabel, children: children }));
331
- }
332
-
333
- function CardButton({ label, description, onClick, isLight = true, }) {
334
- return (jsxRuntime.jsxs("div", { className: `cursor-pointer rounded-2xl p-4 h-[160px] w-full bg-gradient-to-br hover:shadow-md transition-shadow duration-200 border ${isLight ? 'border-[#f3f4f6] from-[#f3f4f6] to-white' : 'border-[#13294B] from-[#13294B] to-[#0C1C34]'}`, onClick: () => {
335
- if (onClick)
336
- onClick();
337
- }, children: [jsxRuntime.jsx("h3", { className: `text-lg font-bold ${isLight ? 'text-[#13294B]' : 'text-white'}`, children: label }), description && (jsxRuntime.jsx("p", { className: `text-sm mt-2 line-clamp-3 ${isLight ? 'text-[#13294B]' : 'text-white'}`, children: description }))] }));
338
- }
339
-
340
- function CardIconsButton({ label, leftIcon, onClick, isLight = true, }) {
341
- return (jsxRuntime.jsxs("div", { className: `cursor-pointer rounded-xl p-4 w-full min-h-[60px] bg-gradient-to-br hover:shadow-md transition-shadow duration-200 border flex items-center justify-between gap-4 ${isLight ? 'border-[#f3f4f6] from-[#f3f4f6] to-white' : 'border-[#13294B] from-[#13294B] to-[#0C1C34]'}`, onClick: () => {
342
- if (onClick)
343
- onClick();
344
- }, "aria-label": `Botão de navegação para ${label}`, children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-3 flex-grow overflow-hidden", children: [leftIcon && (jsxRuntime.jsx("div", { className: `text-xl flex-shrink-0 flex items-center ${isLight ? 'text-[#13294B]' : 'text-white'}`, children: leftIcon })), jsxRuntime.jsx("h3", { className: `text-base font-semibold break-words ${isLight ? 'text-[#646981]' : 'text-white'}`, children: label })] }), jsxRuntime.jsx("div", { className: "flex items-center justify-center h-full", children: jsxRuntime.jsx("i", { className: `pi pi-angle-right text-xl flex-shrink-0 ${isLight ? 'text-[#646981]' : 'text-white'}` }) })] }));
345
- }
346
-
347
- function Chart(props) {
348
- return jsxRuntime.jsx(chart.Chart, { ...props });
349
- }
350
-
351
- function Dialog({ title, description, labelConfirmButton, onClose, onClick, }) {
352
- return (jsxRuntime.jsx("div", { className: "fixed inset-0 bg-black bg-opacity-50 z-20 flex justify-center items-center", children: jsxRuntime.jsxs(Card, { className: "flex flex-col", children: [jsxRuntime.jsxs("div", { className: "flex flex-row items-center justify-between px-4 pt-4 pb-6 border-b border-b-stone", children: [jsxRuntime.jsx("h2", { className: "text-primary font-semibold", children: title }), jsxRuntime.jsx("i", { className: "pi pi-times", style: { color: '#606060', cursor: 'pointer' }, onClick: onClose })] }), jsxRuntime.jsxs("div", { className: "flex flex-col items-center p-6", children: [jsxRuntime.jsx("span", { className: "text-primary", children: description }), jsxRuntime.jsxs("div", { className: "w-100 flex flex-row justify-end pt-10 gap-4", children: [jsxRuntime.jsx("div", { className: "w-1/3", children: jsxRuntime.jsx(Button, { label: "Cancelar", variant: "outline", onClick: onClose }) }), jsxRuntime.jsx("div", { className: "w-1/3", children: jsxRuntime.jsx(Button, { label: labelConfirmButton, variant: "primary", onClick: onClick }) })] })] })] }) }));
353
- }
354
-
355
- function Divider({ ...props }) {
356
- return jsxRuntime.jsx(divider.Divider, { ...props });
357
- }
358
-
359
- function EmptyContent({ message = 'Não há dados disponíveis.' }) {
360
- return (jsxRuntime.jsx("div", { className: "p-6 text-justify text-primary bg-stoneBackground", children: jsxRuntime.jsxs("div", { className: 'py-2 px-4 rounded-lg font-semibold', children: [jsxRuntime.jsx("i", { className: 'pi pi-database mr-2' }), message] }) }));
361
- }
362
-
363
- function ExpandablePanel({ title, children, defaultOpen = true, isLight = true, }) {
364
- const [isOpen, setIsOpen] = React.useState(defaultOpen);
365
- return (jsxRuntime.jsx("div", { className: "relative p-[2px] rounded-lg bg-gradient-to-r from-[#FAFAFB] via-[#FAFAFB] to-[#FAFAFB] mb-4", children: jsxRuntime.jsxs("div", { className: "bg-white rounded-lg overflow-hidden", children: [jsxRuntime.jsxs("div", { className: `flex justify-between items-center px-4 py-2 cursor-pointer bg-gradient-to-r ${isLight ? 'from-[#FFFFFF] via-[#FAFAFB] to-[#FFFFFF]' : 'from-[#13294B] to-[#0C1C34]'}`, onClick: () => setIsOpen(!isOpen), children: [jsxRuntime.jsx("div", { className: `text-xl font-bold ${isLight ? 'text-primary' : 'text-white'}`, children: title }), jsxRuntime.jsx("button", { children: isOpen ? (jsxRuntime.jsx("i", { className: `pi pi-chevron-down ${isLight ? 'text-primary' : 'text-white'}` })) : (jsxRuntime.jsx("i", { className: `pi pi-chevron-up ${isLight ? 'text-primary' : 'text-white'}` })) })] }), isOpen && jsxRuntime.jsx("div", { className: "p-4 text-primary", children: children })] }) }));
366
- }
367
-
368
- function FileUpload({ label = 'Enviar arquivos', value = [], onChange, multiple = true, fileTypes, className, error, disabled = false, }) {
369
- const [isDragging, setIsDragging] = React.useState(false);
370
- const fileInputRef = React.useRef(null);
371
- const [uploadFiles, setUploadFiles] = React.useState(value);
372
- React.useEffect(() => {
373
- setUploadFiles(value);
374
- }, [value]);
375
- const updateFiles = (newFiles) => {
376
- setUploadFiles(newFiles);
377
- onChange?.(newFiles);
378
- };
379
- const generateFileWithPreview = (files, allowedTypes = ['image', 'pdf']) => {
380
- const allowedMimeTypes = getAcceptedMimeTypes(allowedTypes).split(',');
381
- return Array.from(files)
382
- .filter((file) => allowedMimeTypes.some((mime) => {
383
- if (mime === 'image/*')
384
- return file.type.startsWith('image/');
385
- return file.type === mime;
386
- }))
387
- .map((file) => {
388
- const type = file.type.startsWith('image/') ? 'image' : 'pdf';
389
- const previewUrl = type === 'image' ? URL.createObjectURL(file) : undefined;
390
- return { file, type, previewUrl };
391
- });
392
- };
393
- const getAcceptedMimeTypes = (types = ['image', 'pdf']) => {
394
- const mimeMap = {
395
- image: 'image/*',
396
- pdf: 'application/pdf',
397
- };
398
- return types.map((type) => mimeMap[type]).join(',');
399
- };
400
- const handleFileChange = (selectedFiles) => {
401
- if (!selectedFiles)
402
- return;
403
- const newFiles = generateFileWithPreview(selectedFiles, fileTypes);
404
- updateFiles([...(uploadFiles || []), ...newFiles]);
405
- };
406
- const handleRemoveFile = (fileToRemove) => {
407
- const updated = uploadFiles
408
- .map((file) => {
409
- if (file.id && file.id === fileToRemove.id) {
410
- return { ...file, isDeleted: true };
411
- }
412
- if (!file.id && file.file === fileToRemove.file) {
413
- return null;
414
- }
415
- return file;
416
- })
417
- .filter(Boolean);
418
- updateFiles(updated);
419
- };
420
- const getSupportedFileText = (types = ['image', 'pdf']) => {
421
- const includesImage = types.includes('image');
422
- const includesPdf = types.includes('pdf');
423
- if (includesImage && includesPdf)
424
- return 'Suporta imagens e PDFs';
425
- if (includesImage)
426
- return 'Suporta apenas imagens';
427
- if (includesPdf)
428
- return 'Suporta apenas PDFs';
429
- return '';
430
- };
431
- const handleDragOver = (e) => {
432
- e.preventDefault();
433
- setIsDragging(true);
434
- };
435
- const handleDragLeave = (e) => {
436
- e.preventDefault();
437
- setIsDragging(false);
438
- };
439
- const handleDrop = (e) => {
440
- e.preventDefault();
441
- setIsDragging(false);
442
- if (isDisabled || disabled)
443
- return;
444
- handleFileChange(e.dataTransfer.files);
445
- };
446
- const visibleFiles = uploadFiles.filter((file) => !file.isDeleted);
447
- const isDisabled = !multiple && visibleFiles.length > 0;
448
- return (jsxRuntime.jsxs("div", { className: clsx('space-y-3', className), children: [jsxRuntime.jsx("label", { htmlFor: "file-upload", className: "text-[18px] font-medium text-primary", children: label }), jsxRuntime.jsxs("div", { role: "button", "aria-label": "\u00C1rea de envio de arquivos", "aria-disabled": isDisabled || disabled, className: clsx('border-2 border-dashed rounded-lg p-2 text-center cursor-pointer transition-colors', isDragging && !error
449
- ? 'border-primary bg-primary/5'
450
- : 'border-[#e6e6e6] hover:border-primary/50', isDisabled || (disabled && 'bg-gray-200 cursor-auto'), error && 'border-red-500 hover:border-red-500'), onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onClick: () => fileInputRef.current?.click(), children: [jsxRuntime.jsx("input", { id: "file-upload", ref: fileInputRef, type: "file", onChange: (e) => handleFileChange(e.target.files), className: "hidden", multiple: multiple, accept: getAcceptedMimeTypes(fileTypes), disabled: isDisabled || disabled }), jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center space-y-3", children: [jsxRuntime.jsx("i", { className: "pi pi-upload text-xl text-[#a0a4b3]" }), jsxRuntime.jsx("p", { className: "text-lg font-semibold text-primary", children: isDisabled ? 'Limite atingido' : 'Arraste e solte arquivos aqui' }), jsxRuntime.jsx("p", { className: "text-sm text-[#a0a4b3]", children: isDisabled
451
- ? 'Já possui um arquivo selecionado'
452
- : 'ou clique para selecionar arquivos' }), jsxRuntime.jsx("p", { className: "text-xs text-[#a0a4b3]", children: getSupportedFileText(fileTypes) })] })] }), error && (jsxRuntime.jsx("span", { className: "text-redError text-xs", role: "alert", "aria-live": "assertive", children: error })), visibleFiles.length > 0 && (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsxs("p", { className: "text-base text-[#a0a4b3]", children: ["Arquivos selecionados (", visibleFiles.length, ")"] }), jsxRuntime.jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4", children: visibleFiles.map((file, index) => (jsxRuntime.jsxs("div", { className: "relative group overflow-hidden rounded border border-gray-200", children: [jsxRuntime.jsx("div", { className: "aspect-square bg-[#e6e6e6] flex items-center justify-center", children: file.type === 'image' && file.previewUrl ? (jsxRuntime.jsx("img", { src: file?.previewUrl, alt: file?.file?.name || file?.name, className: "object-cover w-full h-full transition-transform duration-300 ease-in-out group-hover:scale-105" })) : (jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center p-4 transition-transform duration-300 ease-in-out group-hover:scale-105", children: [jsxRuntime.jsx("i", { className: "pi pi-file-pdf text-4xl text-primary" }), jsxRuntime.jsx("span", { className: "mt-2 text-xs text-center truncate max-w-full", children: file?.file?.name || file?.name })] })) }), jsxRuntime.jsx("button", { type: "button", className: "absolute top-1 right-1 w-6 h-6 flex items-center justify-center bg-primary hover:bg-primaryActive rounded-full transition-colors", onClick: (e) => {
453
- e.stopPropagation();
454
- handleRemoveFile(file);
455
- }, "aria-label": `Remover o arquivo ${file.file?.name || file.name}`, children: jsxRuntime.jsx("i", { className: "pi pi-times text-white text-xs hover:text-slate-200" }) })] }, index))) })] }))] }));
456
- }
457
-
458
- const variants$2 = {
459
- green: {
460
- text: '!text-green',
461
- button: 'bg-greenBackground hover:bg-greenBackgroundActive',
462
- },
463
- main: {
464
- text: '!text-white',
465
- button: 'bg-gray hover:bg-grayDark',
466
- },
467
- primary: {
468
- text: '!text-white',
469
- button: 'bg-primary hover:bg-primaryActive',
470
- },
471
- };
472
- function FilterButton({ filterOptions, setOption, option, variant, icon, label, ...props }) {
473
- const [isOpen, setIsOpen] = React.useState(false);
474
- const toggleDropdown = () => {
475
- setIsOpen(!isOpen);
476
- };
477
- const handleSelect = (selectedOption) => {
478
- setIsOpen(false);
479
- setOption(selectedOption.value === option?.value ? null : selectedOption);
480
- };
481
- return (jsxRuntime.jsxs("div", { className: "relative flex flex-col items-end", children: [jsxRuntime.jsx(button.Button, { ...props, icon: icon, label: label, className: clsx('w-max shadow-none border-none !py-2 gap-2 items-center disabled:bg-stoneDark', props.disabled ? '!disabled:text-background' : variants$2[variant].text, variants$2[variant].button), onClick: toggleDropdown }), isOpen && (jsxRuntime.jsx("div", { className: `absolute w-40 bg-background shadow-md border border-gray z-[9] rounded-md p-2 -bottom-1 translate-y-full`, children: jsxRuntime.jsx("ul", { children: filterOptions.map((filterOption) => (jsxRuntime.jsxs("li", { onClick: () => handleSelect(filterOption), className: "p-2 flex justify-between items-center cursor-pointer", children: [filterOption.label, jsxRuntime.jsx("input", { type: "radio", onChange: () => handleSelect(filterOption), checked: filterOption?.value === option?.value, className: "appearance-none w-2 h-2 rounded-full ring-1 ring-offset-2 ring-offset-background ring-gray checked:bg-primary cursor-pointer" })] }, filterOption.value))) }) }))] }));
482
- }
483
-
484
- function Tooltip({ text, children }) {
485
- const [isVisible, setIsVisible] = React.useState(false);
486
- const [coords, setCoords] = React.useState({ top: 0, left: 0 });
487
- const [adjustedLeft, setAdjustedLeft] = React.useState(null);
488
- const [isClient, setIsClient] = React.useState(false);
489
- const ref = React.useRef(null);
490
- const tooltipRef = React.useRef(null);
491
- React.useEffect(() => {
492
- setIsClient(true);
493
- }, []);
494
- const showTooltip = () => {
495
- if (!text)
496
- return;
497
- setIsVisible(true);
498
- if (ref?.current) {
499
- const rect = ref.current.getBoundingClientRect();
500
- setCoords({
501
- top: rect.top,
502
- left: rect.left + rect.width / 2,
503
- });
504
- }
505
- };
506
- React.useEffect(() => {
507
- if (isClient && isVisible && tooltipRef.current) {
508
- const tooltipRect = tooltipRef.current.getBoundingClientRect();
509
- const overflowRight = tooltipRect.right > window.innerWidth;
510
- const overflowLeft = tooltipRect.left < 0;
511
- let newLeft = coords.left;
512
- if (overflowLeft) {
513
- newLeft = 120;
514
- }
515
- if (overflowRight && !overflowLeft) {
516
- newLeft += -28;
517
- }
518
- setAdjustedLeft(newLeft);
519
- }
520
- }, [isClient, isVisible, coords]);
521
- return (jsxRuntime.jsxs("div", { ref: ref, className: "inline-block", onMouseEnter: showTooltip, onMouseLeave: () => {
522
- setIsVisible(false);
523
- setAdjustedLeft(null);
524
- }, children: [children, isClient &&
525
- isVisible &&
526
- typeof document !== 'undefined' &&
527
- ReactDOM.createPortal(jsxRuntime.jsx("div", { ref: tooltipRef, className: "fixed z-50 bg-[#646981] text-white text-sm py-1 px-2 rounded-md whitespace-nowrap", style: {
528
- top: coords.top - 10,
529
- left: adjustedLeft ?? coords.left,
530
- transform: 'translate(-50%, -100%)',
531
- pointerEvents: 'none',
532
- }, children: text }), document.body)] }));
533
- }
534
-
535
- function Sidebar({ item, onClose, topItem }) {
536
- return (jsxRuntime.jsxs("div", { className: "relative w-100", children: [jsxRuntime.jsx("div", { className: "fixed bottom-0 w-100 h-[calc(100vh_-_64px)] bg-backgroundDark/20 z-50", onClick: onClose }), jsxRuntime.jsxs("div", { className: "fixed h-[calc(100vh_-_64px)] bottom-0 w-72 bg-background z-50", children: [jsxRuntime.jsx("div", { className: "cursor-pointer flex flex-row gap-3 items-center border-b pl-6 px-2 py-2 border-b-stone hover:bg-stoneBackground hover:font-bold", children: jsxRuntime.jsx(reactRouterDom.Link, { to: "/", className: "font-roboto text-base text-backgroundDark hover:font-bold", onClick: onClose, "aria-label": "Ir para o inicio", children: "In\u00EDcio" }, "home-id") }, 'home-div'), topItem &&
537
- topItem.map((item) => (jsxRuntime.jsxs("div", { className: "cursor-pointer flex flex-row gap-3 items-center border-b pl-6 px-2 py-2 border-b-stone hover:bg-stoneBackground hover:font-bold", children: [item?.isWindowOpen && (jsxRuntime.jsx("button", { className: "font-roboto text-base text-backgroundDark hover:font-bold", onClick: () => {
538
- if (onClose)
539
- onClose();
540
- if (typeof window !== 'undefined') {
541
- window.open(item?.path, '_blank');
542
- }
543
- }, "aria-label": `Ir para ${item?.title}`, children: jsxRuntime.jsx(Tooltip, { text: item?.tooltipText, children: item?.title }) }, item?.id || item.title)), !item?.isWindowOpen && (jsxRuntime.jsx(reactRouterDom.Link, { to: item?.path || '', className: "font-roboto text-base text-backgroundDark hover:font-bold", onClick: onClose, "aria-label": `Ir para ${item?.title}`, children: jsxRuntime.jsx(Tooltip, { text: item?.tooltipText, children: item?.title }) }, item?.id || item.title))] }, `top-item-${item?.id ?? item.title}`))), jsxRuntime.jsxs("div", { className: "flex flex-row gap-3 items-center pl-6 pt-8 pb-4", children: [jsxRuntime.jsx("i", { className: "pi pi-star !text-backgroundDark !font-bold text-lg" }), jsxRuntime.jsx("p", { className: "text-backgroundDark font-bold text-lg", children: "Favoritos" })] }), jsxRuntime.jsx("div", { className: "overflow-y-auto overflow-x-hidden [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:rounded-r-md [&::-webkit-scrollbar-thumb]:rounded-md [&::-webkit-scrollbar-track]:bg-stone [&::-webkit-scrollbar-thumb]:bg-stoneDark", children: item &&
544
- item.map((item) => (jsxRuntime.jsx(reactRouterDom.Link, { className: "flex flex-row items-center pl-6 gap-2 border-b border-b-stone hover:bg-stoneBackground hover:font-bold", to: item.path || '', onClick: onClose, "aria-label": `Ir para ${item.title}`, children: jsxRuntime.jsx("span", { className: "font-roboto text-base py-2 text-backgroundDark hover:font-bold", children: jsxRuntime.jsx(Tooltip, { text: item?.tooltipText, children: item.title }) }) }, item.id))) })] }, 'sidebar-div')] }));
545
- }
546
-
547
- function Header({ sidebarItems, sidebarTopItems, username, userConfigItems, setOpenNotifications, }) {
548
- const [openSidebar, setOpenSidebar] = React.useState(false);
549
- const [openUserConfig, setOpenUserConfig] = React.useState(false);
550
- const userConfigRef = React.useRef(null);
551
- React.useEffect(() => {
552
- function handleClickOutside(event) {
553
- if (userConfigRef.current &&
554
- !userConfigRef.current.contains(event.target)) {
555
- setOpenUserConfig(false);
556
- }
557
- }
558
- if (openUserConfig) {
559
- document.addEventListener('mousedown', handleClickOutside);
560
- }
561
- else {
562
- document.removeEventListener('mousedown', handleClickOutside);
563
- }
564
- return () => {
565
- document.removeEventListener('mousedown', handleClickOutside);
566
- };
567
- }, [openUserConfig]);
568
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "w-100 min-h-16 border-b border-b-stone flex flex-row justify-between items-center px-8 shadow-header", children: [jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-4", children: [jsxRuntime.jsx("button", { className: "bg-transparent border-none", onClick: () => setOpenSidebar(!openSidebar), "aria-label": "Abrir menu lateral", children: jsxRuntime.jsx("i", { className: `${openSidebar ? 'pi pi-list' : 'pi pi-bars'} text-[#878787] cursor-pointer hover:text-backgroundDark text-xl mt-1 }` }) }), jsxRuntime.jsx(LogoSmall, {})] }), jsxRuntime.jsxs("div", { className: "relative flex flex-row gap-4 items-center", children: [jsxRuntime.jsx("button", { className: "bg-transparent border-none", onClick: () => setOpenNotifications(true), "aria-label": "Abrir notifica\u00E7\u00E3o", children: jsxRuntime.jsx("i", { className: "pi pi-bell text-[#878787] cursor-pointer hover:text-backgroundDark" }) }), jsxRuntime.jsxs("div", { ref: userConfigRef, className: "relative", children: [jsxRuntime.jsx("button", { className: "bg-transparent border-none", onClick: () => setOpenUserConfig(!openUserConfig), "aria-label": "Abrir menu de configura\u00E7\u00F5es do usu\u00E1rio", children: jsxRuntime.jsxs("p", { className: "text-[#878787] hover:text-backgroundDark font-roboto font-bold cursor-pointer transition-colors duration-200", children: ["Ol\u00E1, ", username] }) }), openUserConfig && (jsxRuntime.jsx("div", { className: `absolute w-100 bg-background shadow-md border border-stoneLight z-20 rounded-md p-2 -bottom-1 translate-y-full`, children: jsxRuntime.jsx("ul", { children: userConfigItems.map(({ id, title, onClick, path }) => (jsxRuntime.jsx("li", { className: "p-2 hover:bg-stoneBackground", children: jsxRuntime.jsx("a", { onClick: () => {
569
- if (onClick)
570
- onClick();
571
- setOpenUserConfig(false);
572
- }, href: path, className: "block w-full font-base font-roboto text-backgroundDark cursor-pointer hover:font-bold", "aria-label": "Op\u00E7\u00F5es de configura\u00E7\u00F5es do usu\u00E1rio", children: title }) }, id))) }) }))] })] })] }), openSidebar && (jsxRuntime.jsx(Sidebar, { topItem: sidebarTopItems, item: sidebarItems, onClose: () => {
573
- setOpenSidebar(false);
574
- } }))] }));
575
- }
576
-
577
- const variants$1 = {
578
- border: 'border-primary hover:border-primary shadow-none',
579
- shadow: 'border-background hover:border-stone focus:shadow-md',
580
- };
581
- function IconButton({ variant, icon, ...props }) {
582
- return (jsxRuntime.jsx(button.Button, { ...props, icon: `pi ${icon}`, rounded: true, text: variant === 'shadow', raised: variant === 'shadow', outlined: variant === 'border', className: clsx('bg-background text-primary hover:bg-stone disabled:bg-stoneDark disabled:border-stoneDark disabled:text-background', variants$1[variant]) }));
583
- }
584
-
585
- function InfoCard({ title, children, icon, className, titleClassName, }) {
586
- return (jsxRuntime.jsxs("div", { className: clsx('bg-background rounded-lg p-4 border border-stone overflow-hidden', className), children: [jsxRuntime.jsxs("div", { className: "flex justify-between items-center mb-2", children: [jsxRuntime.jsx("span", { className: clsx('text-sm font-roboto text-primary', titleClassName), children: title }), icon] }), jsxRuntime.jsx("div", { className: "font-roboto text-primary break-words overflow-wrap break-all max-w-full", children: children })] }));
587
- }
588
-
589
- function InputSwitch({ checked, onChange, disabled = false, error, ariaLabel = 'Switch', }) {
590
- const inputId = React.useId();
591
- return (jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [jsxRuntime.jsx(inputswitch.InputSwitch, { id: inputId, checked: checked, onChange: (e) => onChange(e.value), disabled: disabled, className: clsx('transition-all border-2 rounded-full p-inputswitch', disabled
592
- ? 'opacity-50 cursor-not-allowed border-none'
593
- : 'border-none', error ? 'p-inputswitch-error' : '', checked ? 'p-inputswitch-checked' : ''), "aria-label": ariaLabel }), error && jsxRuntime.jsx("span", { className: "text-redError text-xs", children: error })] }));
594
- }
595
-
596
- function InputTextArea({ onChange, placeholder, disabled = false, error, label, rows = 2, ...props }) {
597
- const inputTextAreaId = React.useId();
598
- const handleChange = (e) => {
599
- onChange(e.target.value);
600
- };
601
- const hasError = (props.value && error && !disabled) ||
602
- (!!error && !disabled && props.value?.length === 0);
603
- return (jsxRuntime.jsxs("div", { className: "relative flex flex-col w-full", children: [jsxRuntime.jsx(inputtextarea.InputTextarea, { id: inputTextAreaId, rows: rows, placeholder: placeholder, onChange: handleChange, disabled: disabled, invalid: hasError, className: clsx('w-100 font-roboto border !p-2 rounded-md focus:shadow-none', hasError
604
- ? 'border-redError placeholder:text-redError'
605
- : 'border-gray focus:border-primary', disabled && 'border-stoneDark text-disabled', error && 'border-redError text-redError', !error && 'border-gray placeholder:text-gray'), ...props }), jsxRuntime.jsx(FloatingLabel, { value: props?.value ? props.value.toString() : '', label: label || '', disabled: disabled, error: error }), hasError && jsxRuntime.jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
606
- }
607
-
608
- function TextIcon() {
609
- return (jsxRuntime.jsxs("svg", { width: "16", height: "10", viewBox: "0 0 16 10", fill: "none", children: [jsxRuntime.jsx("path", { d: "M1 1H14.5", stroke: "#666666", strokeWidth: "2", strokeLinecap: "round" }), jsxRuntime.jsx("path", { d: "M1 5H14.5", stroke: "#666666", strokeWidth: "2", strokeLinecap: "round" }), jsxRuntime.jsx("path", { d: "M1 9H10", stroke: "#666666", strokeWidth: "2", strokeLinecap: "round" })] }));
610
- }
611
-
612
- function InternalMenu({ item, isFiltering }) {
613
- const [openItems, setOpenItems] = React.useState([]);
614
- const toggleMenu = (menuItem) => {
615
- setOpenItems((prev) => prev.includes(menuItem)
616
- ? prev.filter((item) => item !== menuItem)
617
- : [...prev, menuItem]);
618
- };
619
- React.useEffect(() => {
620
- if (isFiltering) {
621
- setOpenItems(item);
622
- }
623
- else {
624
- const initialOpen = item.filter((menuItem) => menuItem.isActive);
625
- setOpenItems(initialOpen);
626
- }
627
- }, [isFiltering, item]);
628
- return (jsxRuntime.jsx("div", { className: "w-72 overflow-x-hidden overflow-y-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:rounded-r-md [&::-webkit-scrollbar-thumb]:rounded-md [&::-webkit-scrollbar-track]:bg-stone [&::-webkit-scrollbar-thumb]:bg-stoneDark ", children: item.map((menuItem) => {
629
- const isOpen = openItems.includes(menuItem);
630
- return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "cursor-pointer flex flex-row justify-between items-center border-b px-2 py-1 border-b-stone", onClick: () => toggleMenu(menuItem), children: [jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2", children: [jsxRuntime.jsx(TextIcon, {}), jsxRuntime.jsx("span", { className: "font-roboto text-base text-primary", children: menuItem.title })] }), menuItem.subItem && (jsxRuntime.jsx("i", { className: `pi ${isOpen ? 'pi-angle-up' : 'pi-angle-down'} px-2 text-primary` }))] }), menuItem.subItem && isOpen && (jsxRuntime.jsx("div", { className: "flex flex-col", children: menuItem.subItem.map((subItem) => (jsxRuntime.jsx(reactRouterDom.Link, { className: clsx('cursor-pointer text-base text-primary pl-6 py-1 hover:font-bold hover:text-primary hover:bg-stoneBackground', subItem.isActive ? 'text-primary font-bold' : ''), to: subItem.path, children: jsxRuntime.jsx(Tooltip, { text: subItem?.tooltipText, children: jsxRuntime.jsx("span", { children: subItem.title }) }) }, subItem.id))) }))] }, menuItem.id));
631
- }) }));
632
- }
633
-
634
- function Link({ href, children, className }) {
635
- return (jsxRuntime.jsx("a", { href: href, className: `text-primary hover:underline font-bold font-roboto ${className}`, children: children }));
636
- }
637
-
638
- function MegaMenu({ items }) {
639
- return (jsxRuntime.jsx("div", { className: "w-100 flex items-center justify-between", children: items.map((item, index) => {
640
- const isfirst = index === 0;
641
- const isLast = index === items.length - 1;
642
- return (jsxRuntime.jsx("a", { onClick: item.onClick, className: clsx('w-100 p-2 font-medium border border-stoneDark text-center cursor-pointer', item.active && 'bg-primary text-background', !item.active && 'text-primary', isfirst && 'rounded-l-full', !isfirst && 'border-l-0', isLast && 'rounded-r-full'), "aria-label": "Itens do menu", children: item.label }, index));
643
- }) }));
644
- }
645
-
646
- function Modal({ title, size = 'md', onClose, onConfirm, labelCloseButton = 'Fechar', labelConfirmButton = 'Confirmar', isExpanded = false, ariaLabel = 'Modal de informçoes', children, }) {
647
- const [isFullScreen, setIsFullScreen] = React.useState(false);
648
- const toggleFullScreen = () => {
649
- setIsFullScreen(!isFullScreen);
650
- };
651
- const modalSizeClass = isFullScreen
652
- ? 'w-screen h-screen'
653
- : {
654
- sm: 'w-1/3',
655
- md: 'w-1/2',
656
- lg: 'w-2/3',
657
- xl: 'w-[90%]',
658
- }[size];
659
- return (jsxRuntime.jsx("div", { className: "fixed inset-0 bg-black bg-opacity-50 z-20 flex justify-center items-center", children: jsxRuntime.jsxs(Card, { className: `flex flex-col ${modalSizeClass}`, "aria-label": ariaLabel, children: [jsxRuntime.jsxs("div", { className: `flex flex-row items-center justify-between px-4 pt-4 pb-6 border-b border-b-stone`, children: [title && (jsxRuntime.jsx("div", { className: "text-primary font-bold text-xl", children: title })), jsxRuntime.jsxs("div", { className: "flex items-center gap-6", children: [isExpanded && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: isFullScreen ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("button", { onClick: toggleFullScreen, "aria-label": "Minimizar tela", style: {
660
- color: '#606060',
661
- width: '24px',
662
- height: '24px',
663
- cursor: 'pointer',
664
- }, children: jsxRuntime.jsx("i", { className: "pi pi-window-minimize" }) }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("button", { onClick: toggleFullScreen, "aria-label": "Maximizar tela", style: {
665
- color: '#606060',
666
- width: '24px',
667
- height: '24px',
668
- cursor: 'pointer',
669
- }, children: jsxRuntime.jsx("i", { className: "pi pi-window-maximize" }) }) })) })), jsxRuntime.jsx("button", { onClick: onClose, "aria-label": "Fechar modal", style: {
670
- color: '#606060',
671
- width: '24px',
672
- height: '24px',
673
- cursor: 'pointer',
674
- }, children: jsxRuntime.jsx("i", { className: "pi pi-times cursor-pointer" }) })] })] }), jsxRuntime.jsx("div", { className: `flex-1 overflow-y-auto text-primary ${isFullScreen ? 'h-full' : 'max-h-[70vh]'} p-6`, children: children }), jsxRuntime.jsxs("div", { className: "w-full flex flex-col sm:flex-row sm:justify-end pt-10 gap-4 px-6", children: [onClose && (jsxRuntime.jsx(Button, { label: labelCloseButton, variant: "outline", onClick: onClose, className: "w-full sm:w-auto lg:min-w-[110px] md:min-w-[110px] px-4", "aria-label": "Fechar modal" })), onConfirm && (jsxRuntime.jsx(Button, { label: labelConfirmButton, variant: "primary", onClick: onConfirm, className: "w-full sm:w-auto lg:min-w-[110px] md:min-w-[110px] px-4", "aria-label": "Confirmar modal", type: "button" }))] })] }) }));
675
- }
676
-
677
- function MultiSelect(props) {
678
- const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma ou mais opções', } = props;
679
- const [isOpen, setIsOpen] = React.useState(false);
680
- const [visibleText, setVisibleText] = React.useState('');
681
- const [searchText, setSearchText] = React.useState('');
682
- const [highlightedIndex, setHighlightedIndex] = React.useState(-1);
683
- const containerRef = React.useRef(null);
684
- const normalize = (str) => str
685
- .normalize('NFD')
686
- .replace(/[\u0300-\u036f]/g, '')
687
- .toLowerCase();
688
- const filteredOptions = options.filter((option) => normalize(option.label).includes(normalize(searchText)));
689
- const toggleDropdown = () => {
690
- if (!disabled && !isLoading) {
691
- const newState = !isOpen;
692
- setIsOpen(newState);
693
- if (!newState) {
694
- setSearchText('');
695
- setHighlightedIndex(-1);
696
- }
697
- }
698
- };
699
- const handleSelect = (option) => {
700
- const currentValues = Array.isArray(props.value) ? props.value : [];
701
- const alreadySelected = currentValues.some((v) => v.value === option.value);
702
- const newValues = alreadySelected
703
- ? currentValues.filter((v) => v.value !== option.value)
704
- : [...currentValues, option];
705
- props.onChange(newValues.length > 0 ? newValues : null);
706
- setSearchText('');
707
- const newFiltered = options.filter((opt) => normalize(opt.label).includes(normalize('')));
708
- const newIndex = newFiltered.findIndex((o) => o.value === option.value);
709
- setHighlightedIndex(newIndex);
710
- };
711
- const hasError = !!error && !disabled;
712
- const isInputDisabled = disabled || isLoading;
713
- React.useEffect(() => {
714
- const handleClickOutside = (event) => {
715
- if (containerRef.current &&
716
- !containerRef.current.contains(event.target)) {
717
- setIsOpen(false);
718
- setSearchText('');
719
- setHighlightedIndex(-1);
720
- }
721
- };
722
- document.addEventListener('mousedown', handleClickOutside);
723
- return () => {
724
- document.removeEventListener('mousedown', handleClickOutside);
725
- };
726
- }, []);
727
- const selectedText = () => {
728
- const selected = Array.isArray(props.value) ? props.value : [];
729
- if (selected.length === 0)
730
- return '';
731
- if (selected.length === 1)
732
- return selected[0].label;
733
- return `${selected.length} itens selecionados`;
734
- };
735
- React.useEffect(() => {
736
- const selected = Array.isArray(props.value) ? props.value : [];
737
- if (selected.length === 0) {
738
- setVisibleText('');
739
- }
740
- else if (selected.length === 1) {
741
- setVisibleText(selected[0].label);
742
- }
743
- else {
744
- const count = selected.length;
745
- setVisibleText(`${count} itens selecionados`);
746
- }
747
- }, [props.value]);
748
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { ref: containerRef, className: "relative flex flex-col w-100", children: [jsxRuntime.jsxs("div", { className: "relative w-full cursor-pointer", onClick: toggleDropdown, children: [jsxRuntime.jsx(FloatingLabel, { value: selectedText(), label: label, disabled: isInputDisabled, error: error }), jsxRuntime.jsxs(iconfield.IconField, { className: "w-full", children: [jsxRuntime.jsx(inputtext.InputText, { placeholder: placeholder, type: "text", value: isLoading
749
- ? 'Carregando...'
750
- : isOpen && !isReadOnly
751
- ? searchText
752
- : visibleText, onChange: (e) => {
753
- setSearchText(e.target.value);
754
- props.onInputChange?.(e.target.value);
755
- if (!isOpen)
756
- setIsOpen(true);
757
- setHighlightedIndex(-1);
758
- }, onKeyDown: (e) => {
759
- if (!isOpen)
760
- return;
761
- if (e.key === 'ArrowDown') {
762
- e.preventDefault();
763
- setHighlightedIndex((prev) => prev < filteredOptions.length - 1 ? prev + 1 : 0);
764
- }
765
- if (e.key === 'ArrowUp') {
766
- e.preventDefault();
767
- setHighlightedIndex((prev) => prev > 0 ? prev - 1 : filteredOptions.length - 1);
768
- }
769
- if (e.key === 'Enter') {
770
- e.preventDefault();
771
- if (highlightedIndex >= 0 &&
772
- highlightedIndex < filteredOptions.length) {
773
- handleSelect(filteredOptions[highlightedIndex]);
774
- }
775
- }
776
- if (e.key === 'Escape') {
777
- e.preventDefault();
778
- setIsOpen(false);
779
- setSearchText('');
780
- setHighlightedIndex(-1);
781
- }
782
- }, onClick: toggleDropdown, className: clsx('focus:shadow-none text-base w-100 font-roboto border !p-2 rounded-md', hasError
783
- ? 'border-redError placeholder:text-redError'
784
- : 'border-gray focus:border-primary', isInputDisabled && 'border-stoneDark text-disabled', error && 'border-redError text-redError', !error && 'border-gray placeholder:text-gray', isLoading && 'text-gray', 'truncate'), invalid: hasError, readOnly: !isOpen || isReadOnly, style: { height: '42px', fontSize: '16px' }, disabled: isInputDisabled, "aria-label": ariaLabel }), jsxRuntime.jsx(inputicon.InputIcon, { className: clsx(isLoading
785
- ? 'pi pi-spinner pi-spin'
786
- : isOpen
787
- ? 'pi pi-angle-up'
788
- : 'pi pi-angle-down', 'text-gray px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && !isLoading && (jsxRuntime.jsx("div", { className: clsx('absolute w-full bg-background border shadow-md z-40 rounded-md -bottom-1 translate-y-full', error ? 'border-redError' : 'border-gray'), children: jsxRuntime.jsx("div", { children: jsxRuntime.jsx("ul", { className: "max-h-60 overflow-y-auto", children: filteredOptions.map((option, index) => (jsxRuntime.jsxs("li", { onClick: () => handleSelect(option), className: clsx('p-2 flex justify-between items-center cursor-pointer', 'hover:bg-stoneBackground hover:font-bold', index === highlightedIndex &&
789
- 'bg-stoneBackground font-bold'), title: option.label, children: [jsxRuntime.jsx("span", { className: "truncate max-w-[calc(100%-20px)]", children: option.label }), jsxRuntime.jsx("input", { type: 'checkbox', checked: Array.isArray(props.value) &&
790
- props.value.some((v) => v.value === option.value), onChange: () => handleSelect(option), className: clsx('appearance-none w-2 h-2 ring-1 ring-offset-2 ring-offset-background ring-gray checked:bg-primary cursor-pointer rounded-md') })] }, option.value))) }) }) })), hasError && (jsxRuntime.jsx("span", { className: "text-redError text-xs px-2", children: error }))] }) }));
791
- }
792
-
793
- function FilterIcon({ color }) {
794
- return (jsxRuntime.jsx("svg", { width: "16", height: "15", viewBox: "0 0 16 15", fill: "none", children: jsxRuntime.jsx("path", { d: "M14.3164 0.75C14.918 0.75 15.2188 1.46094 14.7812 1.87109L9.75 6.92969V14.0938C9.75 14.6406 9.14844 14.9414 8.71094 14.6406L6.52344 13.1094C6.33203 13 6.25 12.7812 6.25 12.5625V6.92969L1.19141 1.87109C0.753906 1.46094 1.05469 0.75 1.65625 0.75H14.3164Z", fill: color }) }));
795
- }
796
-
797
- /**
798
- * @module constants
799
- * @summary Useful constants
800
- * @description
801
- * Collection of useful date constants.
802
- *
803
- * The constants could be imported from `date-fns/constants`:
804
- *
805
- * ```ts
806
- * import { maxTime, minTime } from "./constants/date-fns/constants";
807
- *
808
- * function isAllowedTime(time) {
809
- * return time <= maxTime && time >= minTime;
810
- * }
811
- * ```
812
- */
813
-
814
-
815
- /**
816
- * @constant
817
- * @name millisecondsInWeek
818
- * @summary Milliseconds in 1 week.
819
- */
820
- const millisecondsInWeek = 604800000;
821
-
822
- /**
823
- * @constant
824
- * @name millisecondsInDay
825
- * @summary Milliseconds in 1 day.
826
- */
827
- const millisecondsInDay = 86400000;
828
-
829
- /**
830
- * @constant
831
- * @name constructFromSymbol
832
- * @summary Symbol enabling Date extensions to inherit properties from the reference date.
833
- *
834
- * The symbol is used to enable the `constructFrom` function to construct a date
835
- * using a reference date and a value. It allows to transfer extra properties
836
- * from the reference date to the new date. It's useful for extensions like
837
- * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
838
- * a constructor argument.
839
- */
840
- const constructFromSymbol = Symbol.for("constructDateFrom");
841
-
842
- /**
843
- * @name constructFrom
844
- * @category Generic Helpers
845
- * @summary Constructs a date using the reference date and the value
846
- *
847
- * @description
848
- * The function constructs a new date using the constructor from the reference
849
- * date and the given value. It helps to build generic functions that accept
850
- * date extensions.
851
- *
852
- * It defaults to `Date` if the passed reference date is a number or a string.
853
- *
854
- * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
855
- * enabling to transfer extra properties from the reference date to the new date.
856
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
857
- * that accept a time zone as a constructor argument.
858
- *
859
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
860
- *
861
- * @param date - The reference date to take constructor from
862
- * @param value - The value to create the date
863
- *
864
- * @returns Date initialized using the given date and value
865
- *
866
- * @example
867
- * import { constructFrom } from "./constructFrom/date-fns";
868
- *
869
- * // A function that clones a date preserving the original type
870
- * function cloneDate<DateType extends Date>(date: DateType): DateType {
871
- * return constructFrom(
872
- * date, // Use constructor from the given date
873
- * date.getTime() // Use the date value to create a new date
874
- * );
875
- * }
876
- */
877
- function constructFrom(date, value) {
878
- if (typeof date === "function") return date(value);
879
-
880
- if (date && typeof date === "object" && constructFromSymbol in date)
881
- return date[constructFromSymbol](value);
882
-
883
- if (date instanceof Date) return new date.constructor(value);
884
-
885
- return new Date(value);
886
- }
887
-
888
- /**
889
- * @name toDate
890
- * @category Common Helpers
891
- * @summary Convert the given argument to an instance of Date.
892
- *
893
- * @description
894
- * Convert the given argument to an instance of Date.
895
- *
896
- * If the argument is an instance of Date, the function returns its clone.
897
- *
898
- * If the argument is a number, it is treated as a timestamp.
899
- *
900
- * If the argument is none of the above, the function returns Invalid Date.
901
- *
902
- * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
903
- * enabling to transfer extra properties from the reference date to the new date.
904
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
905
- * that accept a time zone as a constructor argument.
906
- *
907
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
908
- *
909
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
910
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
911
- *
912
- * @param argument - The value to convert
913
- *
914
- * @returns The parsed date in the local time zone
915
- *
916
- * @example
917
- * // Clone the date:
918
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
919
- * //=> Tue Feb 11 2014 11:30:30
920
- *
921
- * @example
922
- * // Convert the timestamp to date:
923
- * const result = toDate(1392098430000)
924
- * //=> Tue Feb 11 2014 11:30:30
925
- */
926
- function toDate(argument, context) {
927
- // [TODO] Get rid of `toDate` or `constructFrom`?
928
- return constructFrom(context || argument, argument);
929
- }
930
-
931
- let defaultOptions = {};
932
-
933
- function getDefaultOptions() {
934
- return defaultOptions;
935
- }
936
-
937
- /**
938
- * The {@link startOfWeek} function options.
939
- */
940
-
941
- /**
942
- * @name startOfWeek
943
- * @category Week Helpers
944
- * @summary Return the start of a week for the given date.
945
- *
946
- * @description
947
- * Return the start of a week for the given date.
948
- * The result will be in the local timezone.
949
- *
950
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
951
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
952
- *
953
- * @param date - The original date
954
- * @param options - An object with options
955
- *
956
- * @returns The start of a week
957
- *
958
- * @example
959
- * // The start of a week for 2 September 2014 11:55:00:
960
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
961
- * //=> Sun Aug 31 2014 00:00:00
962
- *
963
- * @example
964
- * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
965
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
966
- * //=> Mon Sep 01 2014 00:00:00
967
- */
968
- function startOfWeek(date, options) {
969
- const defaultOptions = getDefaultOptions();
970
- const weekStartsOn =
971
- options?.weekStartsOn ??
972
- options?.locale?.options?.weekStartsOn ??
973
- defaultOptions.weekStartsOn ??
974
- defaultOptions.locale?.options?.weekStartsOn ??
975
- 0;
976
-
977
- const _date = toDate(date, options?.in);
978
- const day = _date.getDay();
979
- const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
980
-
981
- _date.setDate(_date.getDate() - diff);
982
- _date.setHours(0, 0, 0, 0);
983
- return _date;
984
- }
985
-
986
- /**
987
- * The {@link startOfISOWeek} function options.
988
- */
989
-
990
- /**
991
- * @name startOfISOWeek
992
- * @category ISO Week Helpers
993
- * @summary Return the start of an ISO week for the given date.
994
- *
995
- * @description
996
- * Return the start of an ISO week for the given date.
997
- * The result will be in the local timezone.
998
- *
999
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
1000
- *
1001
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
1002
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1003
- *
1004
- * @param date - The original date
1005
- * @param options - An object with options
1006
- *
1007
- * @returns The start of an ISO week
1008
- *
1009
- * @example
1010
- * // The start of an ISO week for 2 September 2014 11:55:00:
1011
- * const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0))
1012
- * //=> Mon Sep 01 2014 00:00:00
1013
- */
1014
- function startOfISOWeek(date, options) {
1015
- return startOfWeek(date, { ...options, weekStartsOn: 1 });
1016
- }
1017
-
1018
- /**
1019
- * The {@link getISOWeekYear} function options.
1020
- */
1021
-
1022
- /**
1023
- * @name getISOWeekYear
1024
- * @category ISO Week-Numbering Year Helpers
1025
- * @summary Get the ISO week-numbering year of the given date.
1026
- *
1027
- * @description
1028
- * Get the ISO week-numbering year of the given date,
1029
- * which always starts 3 days before the year's first Thursday.
1030
- *
1031
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
1032
- *
1033
- * @param date - The given date
1034
- *
1035
- * @returns The ISO week-numbering year
1036
- *
1037
- * @example
1038
- * // Which ISO-week numbering year is 2 January 2005?
1039
- * const result = getISOWeekYear(new Date(2005, 0, 2))
1040
- * //=> 2004
1041
- */
1042
- function getISOWeekYear(date, options) {
1043
- const _date = toDate(date, options?.in);
1044
- const year = _date.getFullYear();
1045
-
1046
- const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
1047
- fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
1048
- fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
1049
- const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
1050
-
1051
- const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
1052
- fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
1053
- fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
1054
- const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
1055
-
1056
- if (_date.getTime() >= startOfNextYear.getTime()) {
1057
- return year + 1;
1058
- } else if (_date.getTime() >= startOfThisYear.getTime()) {
1059
- return year;
1060
- } else {
1061
- return year - 1;
1062
- }
1063
- }
1064
-
1065
- /**
1066
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
1067
- * They usually appear for dates that denote time before the timezones were introduced
1068
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
1069
- * and GMT+01:00:00 after that date)
1070
- *
1071
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
1072
- * which would lead to incorrect calculations.
1073
- *
1074
- * This function returns the timezone offset in milliseconds that takes seconds in account.
1075
- */
1076
- function getTimezoneOffsetInMilliseconds(date) {
1077
- const _date = toDate(date);
1078
- const utcDate = new Date(
1079
- Date.UTC(
1080
- _date.getFullYear(),
1081
- _date.getMonth(),
1082
- _date.getDate(),
1083
- _date.getHours(),
1084
- _date.getMinutes(),
1085
- _date.getSeconds(),
1086
- _date.getMilliseconds(),
1087
- ),
1088
- );
1089
- utcDate.setUTCFullYear(_date.getFullYear());
1090
- return +date - +utcDate;
1091
- }
1092
-
1093
- function normalizeDates(context, ...dates) {
1094
- const normalize = constructFrom.bind(
1095
- null,
1096
- dates.find((date) => typeof date === "object"),
1097
- );
1098
- return dates.map(normalize);
1099
- }
1100
-
1101
- /**
1102
- * The {@link startOfDay} function options.
1103
- */
1104
-
1105
- /**
1106
- * @name startOfDay
1107
- * @category Day Helpers
1108
- * @summary Return the start of a day for the given date.
1109
- *
1110
- * @description
1111
- * Return the start of a day for the given date.
1112
- * The result will be in the local timezone.
1113
- *
1114
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
1115
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1116
- *
1117
- * @param date - The original date
1118
- * @param options - The options
1119
- *
1120
- * @returns The start of a day
1121
- *
1122
- * @example
1123
- * // The start of a day for 2 September 2014 11:55:00:
1124
- * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
1125
- * //=> Tue Sep 02 2014 00:00:00
1126
- */
1127
- function startOfDay(date, options) {
1128
- const _date = toDate(date, options?.in);
1129
- _date.setHours(0, 0, 0, 0);
1130
- return _date;
1131
- }
1132
-
1133
- /**
1134
- * The {@link differenceInCalendarDays} function options.
1135
- */
1136
-
1137
- /**
1138
- * @name differenceInCalendarDays
1139
- * @category Day Helpers
1140
- * @summary Get the number of calendar days between the given dates.
1141
- *
1142
- * @description
1143
- * Get the number of calendar days between the given dates. This means that the times are removed
1144
- * from the dates and then the difference in days is calculated.
1145
- *
1146
- * @param laterDate - The later date
1147
- * @param earlierDate - The earlier date
1148
- * @param options - The options object
1149
- *
1150
- * @returns The number of calendar days
1151
- *
1152
- * @example
1153
- * // How many calendar days are between
1154
- * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
1155
- * const result = differenceInCalendarDays(
1156
- * new Date(2012, 6, 2, 0, 0),
1157
- * new Date(2011, 6, 2, 23, 0)
1158
- * )
1159
- * //=> 366
1160
- * // How many calendar days are between
1161
- * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
1162
- * const result = differenceInCalendarDays(
1163
- * new Date(2011, 6, 3, 0, 1),
1164
- * new Date(2011, 6, 2, 23, 59)
1165
- * )
1166
- * //=> 1
1167
- */
1168
- function differenceInCalendarDays(laterDate, earlierDate, options) {
1169
- const [laterDate_, earlierDate_] = normalizeDates(
1170
- options?.in,
1171
- laterDate,
1172
- earlierDate,
1173
- );
1174
-
1175
- const laterStartOfDay = startOfDay(laterDate_);
1176
- const earlierStartOfDay = startOfDay(earlierDate_);
1177
-
1178
- const laterTimestamp =
1179
- +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
1180
- const earlierTimestamp =
1181
- +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
1182
-
1183
- // Round the number of days to the nearest integer because the number of
1184
- // milliseconds in a day is not constant (e.g. it's different in the week of
1185
- // the daylight saving time clock shift).
1186
- return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
1187
- }
1188
-
1189
- /**
1190
- * The {@link startOfISOWeekYear} function options.
1191
- */
1192
-
1193
- /**
1194
- * @name startOfISOWeekYear
1195
- * @category ISO Week-Numbering Year Helpers
1196
- * @summary Return the start of an ISO week-numbering year for the given date.
1197
- *
1198
- * @description
1199
- * Return the start of an ISO week-numbering year,
1200
- * which always starts 3 days before the year's first Thursday.
1201
- * The result will be in the local timezone.
1202
- *
1203
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
1204
- *
1205
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
1206
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1207
- *
1208
- * @param date - The original date
1209
- * @param options - An object with options
1210
- *
1211
- * @returns The start of an ISO week-numbering year
1212
- *
1213
- * @example
1214
- * // The start of an ISO week-numbering year for 2 July 2005:
1215
- * const result = startOfISOWeekYear(new Date(2005, 6, 2))
1216
- * //=> Mon Jan 03 2005 00:00:00
1217
- */
1218
- function startOfISOWeekYear(date, options) {
1219
- const year = getISOWeekYear(date, options);
1220
- const fourthOfJanuary = constructFrom(date, 0);
1221
- fourthOfJanuary.setFullYear(year, 0, 4);
1222
- fourthOfJanuary.setHours(0, 0, 0, 0);
1223
- return startOfISOWeek(fourthOfJanuary);
1224
- }
1225
-
1226
- /**
1227
- * @name isDate
1228
- * @category Common Helpers
1229
- * @summary Is the given value a date?
1230
- *
1231
- * @description
1232
- * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
1233
- *
1234
- * @param value - The value to check
1235
- *
1236
- * @returns True if the given value is a date
1237
- *
1238
- * @example
1239
- * // For a valid date:
1240
- * const result = isDate(new Date())
1241
- * //=> true
1242
- *
1243
- * @example
1244
- * // For an invalid date:
1245
- * const result = isDate(new Date(NaN))
1246
- * //=> true
1247
- *
1248
- * @example
1249
- * // For some value:
1250
- * const result = isDate('2014-02-31')
1251
- * //=> false
1252
- *
1253
- * @example
1254
- * // For an object:
1255
- * const result = isDate({})
1256
- * //=> false
1257
- */
1258
- function isDate(value) {
1259
- return (
1260
- value instanceof Date ||
1261
- (typeof value === "object" &&
1262
- Object.prototype.toString.call(value) === "[object Date]")
1263
- );
1264
- }
1265
-
1266
- /**
1267
- * @name isValid
1268
- * @category Common Helpers
1269
- * @summary Is the given date valid?
1270
- *
1271
- * @description
1272
- * Returns false if argument is Invalid Date and true otherwise.
1273
- * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate)
1274
- * Invalid Date is a Date, whose time value is NaN.
1275
- *
1276
- * Time value of Date: http://es5.github.io/#x15.9.1.1
1277
- *
1278
- * @param date - The date to check
1279
- *
1280
- * @returns The date is valid
1281
- *
1282
- * @example
1283
- * // For the valid date:
1284
- * const result = isValid(new Date(2014, 1, 31))
1285
- * //=> true
1286
- *
1287
- * @example
1288
- * // For the value, convertible into a date:
1289
- * const result = isValid(1393804800000)
1290
- * //=> true
1291
- *
1292
- * @example
1293
- * // For the invalid date:
1294
- * const result = isValid(new Date(''))
1295
- * //=> false
1296
- */
1297
- function isValid(date) {
1298
- return !((!isDate(date) && typeof date !== "number") || isNaN(+toDate(date)));
1299
- }
1300
-
1301
- /**
1302
- * The {@link startOfYear} function options.
1303
- */
1304
-
1305
- /**
1306
- * @name startOfYear
1307
- * @category Year Helpers
1308
- * @summary Return the start of a year for the given date.
1309
- *
1310
- * @description
1311
- * Return the start of a year for the given date.
1312
- * The result will be in the local timezone.
1313
- *
1314
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
1315
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1316
- *
1317
- * @param date - The original date
1318
- * @param options - The options
1319
- *
1320
- * @returns The start of a year
1321
- *
1322
- * @example
1323
- * // The start of a year for 2 September 2014 11:55:00:
1324
- * const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00))
1325
- * //=> Wed Jan 01 2014 00:00:00
1326
- */
1327
- function startOfYear(date, options) {
1328
- const date_ = toDate(date, options?.in);
1329
- date_.setFullYear(date_.getFullYear(), 0, 1);
1330
- date_.setHours(0, 0, 0, 0);
1331
- return date_;
1332
- }
1333
-
1334
- const formatDistanceLocale$1 = {
1335
- lessThanXSeconds: {
1336
- one: "less than a second",
1337
- other: "less than {{count}} seconds",
1338
- },
1339
-
1340
- xSeconds: {
1341
- one: "1 second",
1342
- other: "{{count}} seconds",
1343
- },
1344
-
1345
- halfAMinute: "half a minute",
1346
-
1347
- lessThanXMinutes: {
1348
- one: "less than a minute",
1349
- other: "less than {{count}} minutes",
1350
- },
1351
-
1352
- xMinutes: {
1353
- one: "1 minute",
1354
- other: "{{count}} minutes",
1355
- },
1356
-
1357
- aboutXHours: {
1358
- one: "about 1 hour",
1359
- other: "about {{count}} hours",
1360
- },
1361
-
1362
- xHours: {
1363
- one: "1 hour",
1364
- other: "{{count}} hours",
1365
- },
1366
-
1367
- xDays: {
1368
- one: "1 day",
1369
- other: "{{count}} days",
1370
- },
1371
-
1372
- aboutXWeeks: {
1373
- one: "about 1 week",
1374
- other: "about {{count}} weeks",
1375
- },
1376
-
1377
- xWeeks: {
1378
- one: "1 week",
1379
- other: "{{count}} weeks",
1380
- },
1381
-
1382
- aboutXMonths: {
1383
- one: "about 1 month",
1384
- other: "about {{count}} months",
1385
- },
1386
-
1387
- xMonths: {
1388
- one: "1 month",
1389
- other: "{{count}} months",
1390
- },
1391
-
1392
- aboutXYears: {
1393
- one: "about 1 year",
1394
- other: "about {{count}} years",
1395
- },
1396
-
1397
- xYears: {
1398
- one: "1 year",
1399
- other: "{{count}} years",
1400
- },
1401
-
1402
- overXYears: {
1403
- one: "over 1 year",
1404
- other: "over {{count}} years",
1405
- },
1406
-
1407
- almostXYears: {
1408
- one: "almost 1 year",
1409
- other: "almost {{count}} years",
1410
- },
1411
- };
1412
-
1413
- const formatDistance$1 = (token, count, options) => {
1414
- let result;
1415
-
1416
- const tokenValue = formatDistanceLocale$1[token];
1417
- if (typeof tokenValue === "string") {
1418
- result = tokenValue;
1419
- } else if (count === 1) {
1420
- result = tokenValue.one;
1421
- } else {
1422
- result = tokenValue.other.replace("{{count}}", count.toString());
1423
- }
1424
-
1425
- if (options?.addSuffix) {
1426
- if (options.comparison && options.comparison > 0) {
1427
- return "in " + result;
1428
- } else {
1429
- return result + " ago";
1430
- }
1431
- }
1432
-
1433
- return result;
1434
- };
1435
-
1436
- function buildFormatLongFn(args) {
1437
- return (options = {}) => {
1438
- // TODO: Remove String()
1439
- const width = options.width ? String(options.width) : args.defaultWidth;
1440
- const format = args.formats[width] || args.formats[args.defaultWidth];
1441
- return format;
1442
- };
1443
- }
1444
-
1445
- const dateFormats$1 = {
1446
- full: "EEEE, MMMM do, y",
1447
- long: "MMMM do, y",
1448
- medium: "MMM d, y",
1449
- short: "MM/dd/yyyy",
1450
- };
1451
-
1452
- const timeFormats$1 = {
1453
- full: "h:mm:ss a zzzz",
1454
- long: "h:mm:ss a z",
1455
- medium: "h:mm:ss a",
1456
- short: "h:mm a",
1457
- };
1458
-
1459
- const dateTimeFormats$1 = {
1460
- full: "{{date}} 'at' {{time}}",
1461
- long: "{{date}} 'at' {{time}}",
1462
- medium: "{{date}}, {{time}}",
1463
- short: "{{date}}, {{time}}",
1464
- };
1465
-
1466
- const formatLong$1 = {
1467
- date: buildFormatLongFn({
1468
- formats: dateFormats$1,
1469
- defaultWidth: "full",
1470
- }),
1471
-
1472
- time: buildFormatLongFn({
1473
- formats: timeFormats$1,
1474
- defaultWidth: "full",
1475
- }),
1476
-
1477
- dateTime: buildFormatLongFn({
1478
- formats: dateTimeFormats$1,
1479
- defaultWidth: "full",
1480
- }),
1481
- };
1482
-
1483
- const formatRelativeLocale$1 = {
1484
- lastWeek: "'last' eeee 'at' p",
1485
- yesterday: "'yesterday at' p",
1486
- today: "'today at' p",
1487
- tomorrow: "'tomorrow at' p",
1488
- nextWeek: "eeee 'at' p",
1489
- other: "P",
1490
- };
1491
-
1492
- const formatRelative$1 = (token, _date, _baseDate, _options) =>
1493
- formatRelativeLocale$1[token];
1494
-
1495
- /**
1496
- * The localize function argument callback which allows to convert raw value to
1497
- * the actual type.
1498
- *
1499
- * @param value - The value to convert
1500
- *
1501
- * @returns The converted value
1502
- */
1503
-
1504
- /**
1505
- * The map of localized values for each width.
1506
- */
1507
-
1508
- /**
1509
- * The index type of the locale unit value. It types conversion of units of
1510
- * values that don't start at 0 (i.e. quarters).
1511
- */
1512
-
1513
- /**
1514
- * Converts the unit value to the tuple of values.
1515
- */
1516
-
1517
- /**
1518
- * The tuple of localized era values. The first element represents BC,
1519
- * the second element represents AD.
1520
- */
1521
-
1522
- /**
1523
- * The tuple of localized quarter values. The first element represents Q1.
1524
- */
1525
-
1526
- /**
1527
- * The tuple of localized day values. The first element represents Sunday.
1528
- */
1529
-
1530
- /**
1531
- * The tuple of localized month values. The first element represents January.
1532
- */
1533
-
1534
- function buildLocalizeFn(args) {
1535
- return (value, options) => {
1536
- const context = options?.context ? String(options.context) : "standalone";
1537
-
1538
- let valuesArray;
1539
- if (context === "formatting" && args.formattingValues) {
1540
- const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
1541
- const width = options?.width ? String(options.width) : defaultWidth;
1542
-
1543
- valuesArray =
1544
- args.formattingValues[width] || args.formattingValues[defaultWidth];
1545
- } else {
1546
- const defaultWidth = args.defaultWidth;
1547
- const width = options?.width ? String(options.width) : args.defaultWidth;
1548
-
1549
- valuesArray = args.values[width] || args.values[defaultWidth];
1550
- }
1551
- const index = args.argumentCallback ? args.argumentCallback(value) : value;
1552
-
1553
- // @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
1554
- return valuesArray[index];
1555
- };
1556
- }
1557
-
1558
- const eraValues$1 = {
1559
- narrow: ["B", "A"],
1560
- abbreviated: ["BC", "AD"],
1561
- wide: ["Before Christ", "Anno Domini"],
1562
- };
1563
-
1564
- const quarterValues$1 = {
1565
- narrow: ["1", "2", "3", "4"],
1566
- abbreviated: ["Q1", "Q2", "Q3", "Q4"],
1567
- wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
1568
- };
1569
-
1570
- // Note: in English, the names of days of the week and months are capitalized.
1571
- // If you are making a new locale based on this one, check if the same is true for the language you're working on.
1572
- // Generally, formatted dates should look like they are in the middle of a sentence,
1573
- // e.g. in Spanish language the weekdays and months should be in the lowercase.
1574
- const monthValues$1 = {
1575
- narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
1576
- abbreviated: [
1577
- "Jan",
1578
- "Feb",
1579
- "Mar",
1580
- "Apr",
1581
- "May",
1582
- "Jun",
1583
- "Jul",
1584
- "Aug",
1585
- "Sep",
1586
- "Oct",
1587
- "Nov",
1588
- "Dec",
1589
- ],
1590
-
1591
- wide: [
1592
- "January",
1593
- "February",
1594
- "March",
1595
- "April",
1596
- "May",
1597
- "June",
1598
- "July",
1599
- "August",
1600
- "September",
1601
- "October",
1602
- "November",
1603
- "December",
1604
- ],
1605
- };
1606
-
1607
- const dayValues$1 = {
1608
- narrow: ["S", "M", "T", "W", "T", "F", "S"],
1609
- short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
1610
- abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
1611
- wide: [
1612
- "Sunday",
1613
- "Monday",
1614
- "Tuesday",
1615
- "Wednesday",
1616
- "Thursday",
1617
- "Friday",
1618
- "Saturday",
1619
- ],
1620
- };
1621
-
1622
- const dayPeriodValues$1 = {
1623
- narrow: {
1624
- am: "a",
1625
- pm: "p",
1626
- midnight: "mi",
1627
- noon: "n",
1628
- morning: "morning",
1629
- afternoon: "afternoon",
1630
- evening: "evening",
1631
- night: "night",
1632
- },
1633
- abbreviated: {
1634
- am: "AM",
1635
- pm: "PM",
1636
- midnight: "midnight",
1637
- noon: "noon",
1638
- morning: "morning",
1639
- afternoon: "afternoon",
1640
- evening: "evening",
1641
- night: "night",
1642
- },
1643
- wide: {
1644
- am: "a.m.",
1645
- pm: "p.m.",
1646
- midnight: "midnight",
1647
- noon: "noon",
1648
- morning: "morning",
1649
- afternoon: "afternoon",
1650
- evening: "evening",
1651
- night: "night",
1652
- },
1653
- };
1654
-
1655
- const formattingDayPeriodValues$1 = {
1656
- narrow: {
1657
- am: "a",
1658
- pm: "p",
1659
- midnight: "mi",
1660
- noon: "n",
1661
- morning: "in the morning",
1662
- afternoon: "in the afternoon",
1663
- evening: "in the evening",
1664
- night: "at night",
1665
- },
1666
- abbreviated: {
1667
- am: "AM",
1668
- pm: "PM",
1669
- midnight: "midnight",
1670
- noon: "noon",
1671
- morning: "in the morning",
1672
- afternoon: "in the afternoon",
1673
- evening: "in the evening",
1674
- night: "at night",
1675
- },
1676
- wide: {
1677
- am: "a.m.",
1678
- pm: "p.m.",
1679
- midnight: "midnight",
1680
- noon: "noon",
1681
- morning: "in the morning",
1682
- afternoon: "in the afternoon",
1683
- evening: "in the evening",
1684
- night: "at night",
1685
- },
1686
- };
1687
-
1688
- const ordinalNumber$1 = (dirtyNumber, _options) => {
1689
- const number = Number(dirtyNumber);
1690
-
1691
- // If ordinal numbers depend on context, for example,
1692
- // if they are different for different grammatical genders,
1693
- // use `options.unit`.
1694
- //
1695
- // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
1696
- // 'day', 'hour', 'minute', 'second'.
1697
-
1698
- const rem100 = number % 100;
1699
- if (rem100 > 20 || rem100 < 10) {
1700
- switch (rem100 % 10) {
1701
- case 1:
1702
- return number + "st";
1703
- case 2:
1704
- return number + "nd";
1705
- case 3:
1706
- return number + "rd";
1707
- }
1708
- }
1709
- return number + "th";
1710
- };
1711
-
1712
- const localize$1 = {
1713
- ordinalNumber: ordinalNumber$1,
1714
-
1715
- era: buildLocalizeFn({
1716
- values: eraValues$1,
1717
- defaultWidth: "wide",
1718
- }),
1719
-
1720
- quarter: buildLocalizeFn({
1721
- values: quarterValues$1,
1722
- defaultWidth: "wide",
1723
- argumentCallback: (quarter) => quarter - 1,
1724
- }),
1725
-
1726
- month: buildLocalizeFn({
1727
- values: monthValues$1,
1728
- defaultWidth: "wide",
1729
- }),
1730
-
1731
- day: buildLocalizeFn({
1732
- values: dayValues$1,
1733
- defaultWidth: "wide",
1734
- }),
1735
-
1736
- dayPeriod: buildLocalizeFn({
1737
- values: dayPeriodValues$1,
1738
- defaultWidth: "wide",
1739
- formattingValues: formattingDayPeriodValues$1,
1740
- defaultFormattingWidth: "wide",
1741
- }),
1742
- };
1743
-
1744
- function buildMatchFn(args) {
1745
- return (string, options = {}) => {
1746
- const width = options.width;
1747
-
1748
- const matchPattern =
1749
- (width && args.matchPatterns[width]) ||
1750
- args.matchPatterns[args.defaultMatchWidth];
1751
- const matchResult = string.match(matchPattern);
1752
-
1753
- if (!matchResult) {
1754
- return null;
1755
- }
1756
- const matchedString = matchResult[0];
1757
-
1758
- const parsePatterns =
1759
- (width && args.parsePatterns[width]) ||
1760
- args.parsePatterns[args.defaultParseWidth];
1761
-
1762
- const key = Array.isArray(parsePatterns)
1763
- ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
1764
- : // [TODO] -- I challenge you to fix the type
1765
- findKey(parsePatterns, (pattern) => pattern.test(matchedString));
1766
-
1767
- let value;
1768
-
1769
- value = args.valueCallback ? args.valueCallback(key) : key;
1770
- value = options.valueCallback
1771
- ? // [TODO] -- I challenge you to fix the type
1772
- options.valueCallback(value)
1773
- : value;
1774
-
1775
- const rest = string.slice(matchedString.length);
1776
-
1777
- return { value, rest };
1778
- };
1779
- }
1780
-
1781
- function findKey(object, predicate) {
1782
- for (const key in object) {
1783
- if (
1784
- Object.prototype.hasOwnProperty.call(object, key) &&
1785
- predicate(object[key])
1786
- ) {
1787
- return key;
1788
- }
1789
- }
1790
- return undefined;
1791
- }
1792
-
1793
- function findIndex(array, predicate) {
1794
- for (let key = 0; key < array.length; key++) {
1795
- if (predicate(array[key])) {
1796
- return key;
1797
- }
1798
- }
1799
- return undefined;
1800
- }
1801
-
1802
- function buildMatchPatternFn(args) {
1803
- return (string, options = {}) => {
1804
- const matchResult = string.match(args.matchPattern);
1805
- if (!matchResult) return null;
1806
- const matchedString = matchResult[0];
1807
-
1808
- const parseResult = string.match(args.parsePattern);
1809
- if (!parseResult) return null;
1810
- let value = args.valueCallback
1811
- ? args.valueCallback(parseResult[0])
1812
- : parseResult[0];
1813
-
1814
- // [TODO] I challenge you to fix the type
1815
- value = options.valueCallback ? options.valueCallback(value) : value;
1816
-
1817
- const rest = string.slice(matchedString.length);
1818
-
1819
- return { value, rest };
1820
- };
1821
- }
1822
-
1823
- const matchOrdinalNumberPattern$1 = /^(\d+)(th|st|nd|rd)?/i;
1824
- const parseOrdinalNumberPattern$1 = /\d+/i;
1825
-
1826
- const matchEraPatterns$1 = {
1827
- narrow: /^(b|a)/i,
1828
- abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
1829
- wide: /^(before christ|before common era|anno domini|common era)/i,
1830
- };
1831
- const parseEraPatterns$1 = {
1832
- any: [/^b/i, /^(a|c)/i],
1833
- };
1834
-
1835
- const matchQuarterPatterns$1 = {
1836
- narrow: /^[1234]/i,
1837
- abbreviated: /^q[1234]/i,
1838
- wide: /^[1234](th|st|nd|rd)? quarter/i,
1839
- };
1840
- const parseQuarterPatterns$1 = {
1841
- any: [/1/i, /2/i, /3/i, /4/i],
1842
- };
1843
-
1844
- const matchMonthPatterns$1 = {
1845
- narrow: /^[jfmasond]/i,
1846
- abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
1847
- wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i,
1848
- };
1849
- const parseMonthPatterns$1 = {
1850
- narrow: [
1851
- /^j/i,
1852
- /^f/i,
1853
- /^m/i,
1854
- /^a/i,
1855
- /^m/i,
1856
- /^j/i,
1857
- /^j/i,
1858
- /^a/i,
1859
- /^s/i,
1860
- /^o/i,
1861
- /^n/i,
1862
- /^d/i,
1863
- ],
1864
-
1865
- any: [
1866
- /^ja/i,
1867
- /^f/i,
1868
- /^mar/i,
1869
- /^ap/i,
1870
- /^may/i,
1871
- /^jun/i,
1872
- /^jul/i,
1873
- /^au/i,
1874
- /^s/i,
1875
- /^o/i,
1876
- /^n/i,
1877
- /^d/i,
1878
- ],
1879
- };
1880
-
1881
- const matchDayPatterns$1 = {
1882
- narrow: /^[smtwf]/i,
1883
- short: /^(su|mo|tu|we|th|fr|sa)/i,
1884
- abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
1885
- wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i,
1886
- };
1887
- const parseDayPatterns$1 = {
1888
- narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
1889
- any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i],
1890
- };
1891
-
1892
- const matchDayPeriodPatterns$1 = {
1893
- narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
1894
- any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i,
1895
- };
1896
- const parseDayPeriodPatterns$1 = {
1897
- any: {
1898
- am: /^a/i,
1899
- pm: /^p/i,
1900
- midnight: /^mi/i,
1901
- noon: /^no/i,
1902
- morning: /morning/i,
1903
- afternoon: /afternoon/i,
1904
- evening: /evening/i,
1905
- night: /night/i,
1906
- },
1907
- };
1908
-
1909
- const match$1 = {
1910
- ordinalNumber: buildMatchPatternFn({
1911
- matchPattern: matchOrdinalNumberPattern$1,
1912
- parsePattern: parseOrdinalNumberPattern$1,
1913
- valueCallback: (value) => parseInt(value, 10),
1914
- }),
1915
-
1916
- era: buildMatchFn({
1917
- matchPatterns: matchEraPatterns$1,
1918
- defaultMatchWidth: "wide",
1919
- parsePatterns: parseEraPatterns$1,
1920
- defaultParseWidth: "any",
1921
- }),
1922
-
1923
- quarter: buildMatchFn({
1924
- matchPatterns: matchQuarterPatterns$1,
1925
- defaultMatchWidth: "wide",
1926
- parsePatterns: parseQuarterPatterns$1,
1927
- defaultParseWidth: "any",
1928
- valueCallback: (index) => index + 1,
1929
- }),
1930
-
1931
- month: buildMatchFn({
1932
- matchPatterns: matchMonthPatterns$1,
1933
- defaultMatchWidth: "wide",
1934
- parsePatterns: parseMonthPatterns$1,
1935
- defaultParseWidth: "any",
1936
- }),
1937
-
1938
- day: buildMatchFn({
1939
- matchPatterns: matchDayPatterns$1,
1940
- defaultMatchWidth: "wide",
1941
- parsePatterns: parseDayPatterns$1,
1942
- defaultParseWidth: "any",
1943
- }),
1944
-
1945
- dayPeriod: buildMatchFn({
1946
- matchPatterns: matchDayPeriodPatterns$1,
1947
- defaultMatchWidth: "any",
1948
- parsePatterns: parseDayPeriodPatterns$1,
1949
- defaultParseWidth: "any",
1950
- }),
1951
- };
1952
-
1953
- /**
1954
- * @category Locales
1955
- * @summary English locale (United States).
1956
- * @language English
1957
- * @iso-639-2 eng
1958
- * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp)
1959
- * @author Lesha Koss [@leshakoss](https://github.com/leshakoss)
1960
- */
1961
- const enUS = {
1962
- code: "en-US",
1963
- formatDistance: formatDistance$1,
1964
- formatLong: formatLong$1,
1965
- formatRelative: formatRelative$1,
1966
- localize: localize$1,
1967
- match: match$1,
1968
- options: {
1969
- weekStartsOn: 0 /* Sunday */,
1970
- firstWeekContainsDate: 1,
1971
- },
1972
- };
1973
-
1974
- /**
1975
- * The {@link getDayOfYear} function options.
1976
- */
1977
-
1978
- /**
1979
- * @name getDayOfYear
1980
- * @category Day Helpers
1981
- * @summary Get the day of the year of the given date.
1982
- *
1983
- * @description
1984
- * Get the day of the year of the given date.
1985
- *
1986
- * @param date - The given date
1987
- * @param options - The options
1988
- *
1989
- * @returns The day of year
1990
- *
1991
- * @example
1992
- * // Which day of the year is 2 July 2014?
1993
- * const result = getDayOfYear(new Date(2014, 6, 2))
1994
- * //=> 183
1995
- */
1996
- function getDayOfYear(date, options) {
1997
- const _date = toDate(date, options?.in);
1998
- const diff = differenceInCalendarDays(_date, startOfYear(_date));
1999
- const dayOfYear = diff + 1;
2000
- return dayOfYear;
2001
- }
2002
-
2003
- /**
2004
- * The {@link getISOWeek} function options.
2005
- */
2006
-
2007
- /**
2008
- * @name getISOWeek
2009
- * @category ISO Week Helpers
2010
- * @summary Get the ISO week of the given date.
2011
- *
2012
- * @description
2013
- * Get the ISO week of the given date.
2014
- *
2015
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
2016
- *
2017
- * @param date - The given date
2018
- * @param options - The options
2019
- *
2020
- * @returns The ISO week
2021
- *
2022
- * @example
2023
- * // Which week of the ISO-week numbering year is 2 January 2005?
2024
- * const result = getISOWeek(new Date(2005, 0, 2))
2025
- * //=> 53
2026
- */
2027
- function getISOWeek(date, options) {
2028
- const _date = toDate(date, options?.in);
2029
- const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
2030
-
2031
- // Round the number of weeks to the nearest integer because the number of
2032
- // milliseconds in a week is not constant (e.g. it's different in the week of
2033
- // the daylight saving time clock shift).
2034
- return Math.round(diff / millisecondsInWeek) + 1;
2035
- }
2036
-
2037
- /**
2038
- * The {@link getWeekYear} function options.
2039
- */
2040
-
2041
- /**
2042
- * @name getWeekYear
2043
- * @category Week-Numbering Year Helpers
2044
- * @summary Get the local week-numbering year of the given date.
2045
- *
2046
- * @description
2047
- * Get the local week-numbering year of the given date.
2048
- * The exact calculation depends on the values of
2049
- * `options.weekStartsOn` (which is the index of the first day of the week)
2050
- * and `options.firstWeekContainsDate` (which is the day of January, which is always in
2051
- * the first week of the week-numbering year)
2052
- *
2053
- * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
2054
- *
2055
- * @param date - The given date
2056
- * @param options - An object with options.
2057
- *
2058
- * @returns The local week-numbering year
2059
- *
2060
- * @example
2061
- * // Which week numbering year is 26 December 2004 with the default settings?
2062
- * const result = getWeekYear(new Date(2004, 11, 26))
2063
- * //=> 2005
2064
- *
2065
- * @example
2066
- * // Which week numbering year is 26 December 2004 if week starts on Saturday?
2067
- * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
2068
- * //=> 2004
2069
- *
2070
- * @example
2071
- * // Which week numbering year is 26 December 2004 if the first week contains 4 January?
2072
- * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
2073
- * //=> 2004
2074
- */
2075
- function getWeekYear(date, options) {
2076
- const _date = toDate(date, options?.in);
2077
- const year = _date.getFullYear();
2078
-
2079
- const defaultOptions = getDefaultOptions();
2080
- const firstWeekContainsDate =
2081
- options?.firstWeekContainsDate ??
2082
- options?.locale?.options?.firstWeekContainsDate ??
2083
- defaultOptions.firstWeekContainsDate ??
2084
- defaultOptions.locale?.options?.firstWeekContainsDate ??
2085
- 1;
2086
-
2087
- const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
2088
- firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
2089
- firstWeekOfNextYear.setHours(0, 0, 0, 0);
2090
- const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
2091
-
2092
- const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
2093
- firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
2094
- firstWeekOfThisYear.setHours(0, 0, 0, 0);
2095
- const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
2096
-
2097
- if (+_date >= +startOfNextYear) {
2098
- return year + 1;
2099
- } else if (+_date >= +startOfThisYear) {
2100
- return year;
2101
- } else {
2102
- return year - 1;
2103
- }
2104
- }
2105
-
2106
- /**
2107
- * The {@link startOfWeekYear} function options.
2108
- */
2109
-
2110
- /**
2111
- * @name startOfWeekYear
2112
- * @category Week-Numbering Year Helpers
2113
- * @summary Return the start of a local week-numbering year for the given date.
2114
- *
2115
- * @description
2116
- * Return the start of a local week-numbering year.
2117
- * The exact calculation depends on the values of
2118
- * `options.weekStartsOn` (which is the index of the first day of the week)
2119
- * and `options.firstWeekContainsDate` (which is the day of January, which is always in
2120
- * the first week of the week-numbering year)
2121
- *
2122
- * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
2123
- *
2124
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
2125
- * @typeParam ResultDate - The result `Date` type.
2126
- *
2127
- * @param date - The original date
2128
- * @param options - An object with options
2129
- *
2130
- * @returns The start of a week-numbering year
2131
- *
2132
- * @example
2133
- * // The start of an a week-numbering year for 2 July 2005 with default settings:
2134
- * const result = startOfWeekYear(new Date(2005, 6, 2))
2135
- * //=> Sun Dec 26 2004 00:00:00
2136
- *
2137
- * @example
2138
- * // The start of a week-numbering year for 2 July 2005
2139
- * // if Monday is the first day of week
2140
- * // and 4 January is always in the first week of the year:
2141
- * const result = startOfWeekYear(new Date(2005, 6, 2), {
2142
- * weekStartsOn: 1,
2143
- * firstWeekContainsDate: 4
2144
- * })
2145
- * //=> Mon Jan 03 2005 00:00:00
2146
- */
2147
- function startOfWeekYear(date, options) {
2148
- const defaultOptions = getDefaultOptions();
2149
- const firstWeekContainsDate =
2150
- options?.firstWeekContainsDate ??
2151
- options?.locale?.options?.firstWeekContainsDate ??
2152
- defaultOptions.firstWeekContainsDate ??
2153
- defaultOptions.locale?.options?.firstWeekContainsDate ??
2154
- 1;
2155
-
2156
- const year = getWeekYear(date, options);
2157
- const firstWeek = constructFrom(options?.in || date, 0);
2158
- firstWeek.setFullYear(year, 0, firstWeekContainsDate);
2159
- firstWeek.setHours(0, 0, 0, 0);
2160
- const _date = startOfWeek(firstWeek, options);
2161
- return _date;
2162
- }
2163
-
2164
- /**
2165
- * The {@link getWeek} function options.
2166
- */
2167
-
2168
- /**
2169
- * @name getWeek
2170
- * @category Week Helpers
2171
- * @summary Get the local week index of the given date.
2172
- *
2173
- * @description
2174
- * Get the local week index of the given date.
2175
- * The exact calculation depends on the values of
2176
- * `options.weekStartsOn` (which is the index of the first day of the week)
2177
- * and `options.firstWeekContainsDate` (which is the day of January, which is always in
2178
- * the first week of the week-numbering year)
2179
- *
2180
- * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
2181
- *
2182
- * @param date - The given date
2183
- * @param options - An object with options
2184
- *
2185
- * @returns The week
2186
- *
2187
- * @example
2188
- * // Which week of the local week numbering year is 2 January 2005 with default options?
2189
- * const result = getWeek(new Date(2005, 0, 2))
2190
- * //=> 2
2191
- *
2192
- * @example
2193
- * // Which week of the local week numbering year is 2 January 2005,
2194
- * // if Monday is the first day of the week,
2195
- * // and the first week of the year always contains 4 January?
2196
- * const result = getWeek(new Date(2005, 0, 2), {
2197
- * weekStartsOn: 1,
2198
- * firstWeekContainsDate: 4
2199
- * })
2200
- * //=> 53
2201
- */
2202
- function getWeek(date, options) {
2203
- const _date = toDate(date, options?.in);
2204
- const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
2205
-
2206
- // Round the number of weeks to the nearest integer because the number of
2207
- // milliseconds in a week is not constant (e.g. it's different in the week of
2208
- // the daylight saving time clock shift).
2209
- return Math.round(diff / millisecondsInWeek) + 1;
2210
- }
2211
-
2212
- function addLeadingZeros(number, targetLength) {
2213
- const sign = number < 0 ? "-" : "";
2214
- const output = Math.abs(number).toString().padStart(targetLength, "0");
2215
- return sign + output;
2216
- }
2217
-
2218
- /*
2219
- * | | Unit | | Unit |
2220
- * |-----|--------------------------------|-----|--------------------------------|
2221
- * | a | AM, PM | A* | |
2222
- * | d | Day of month | D | |
2223
- * | h | Hour [1-12] | H | Hour [0-23] |
2224
- * | m | Minute | M | Month |
2225
- * | s | Second | S | Fraction of second |
2226
- * | y | Year (abs) | Y | |
2227
- *
2228
- * Letters marked by * are not implemented but reserved by Unicode standard.
2229
- */
2230
-
2231
- const lightFormatters = {
2232
- // Year
2233
- y(date, token) {
2234
- // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
2235
- // | Year | y | yy | yyy | yyyy | yyyyy |
2236
- // |----------|-------|----|-------|-------|-------|
2237
- // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
2238
- // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
2239
- // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
2240
- // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
2241
- // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
2242
-
2243
- const signedYear = date.getFullYear();
2244
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
2245
- const year = signedYear > 0 ? signedYear : 1 - signedYear;
2246
- return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
2247
- },
2248
-
2249
- // Month
2250
- M(date, token) {
2251
- const month = date.getMonth();
2252
- return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
2253
- },
2254
-
2255
- // Day of the month
2256
- d(date, token) {
2257
- return addLeadingZeros(date.getDate(), token.length);
2258
- },
2259
-
2260
- // AM or PM
2261
- a(date, token) {
2262
- const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
2263
-
2264
- switch (token) {
2265
- case "a":
2266
- case "aa":
2267
- return dayPeriodEnumValue.toUpperCase();
2268
- case "aaa":
2269
- return dayPeriodEnumValue;
2270
- case "aaaaa":
2271
- return dayPeriodEnumValue[0];
2272
- case "aaaa":
2273
- default:
2274
- return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
2275
- }
2276
- },
2277
-
2278
- // Hour [1-12]
2279
- h(date, token) {
2280
- return addLeadingZeros(date.getHours() % 12 || 12, token.length);
2281
- },
2282
-
2283
- // Hour [0-23]
2284
- H(date, token) {
2285
- return addLeadingZeros(date.getHours(), token.length);
2286
- },
2287
-
2288
- // Minute
2289
- m(date, token) {
2290
- return addLeadingZeros(date.getMinutes(), token.length);
2291
- },
2292
-
2293
- // Second
2294
- s(date, token) {
2295
- return addLeadingZeros(date.getSeconds(), token.length);
2296
- },
2297
-
2298
- // Fraction of second
2299
- S(date, token) {
2300
- const numberOfDigits = token.length;
2301
- const milliseconds = date.getMilliseconds();
2302
- const fractionalSeconds = Math.trunc(
2303
- milliseconds * Math.pow(10, numberOfDigits - 3),
2304
- );
2305
- return addLeadingZeros(fractionalSeconds, token.length);
2306
- },
2307
- };
2308
-
2309
- const dayPeriodEnum = {
2310
- midnight: "midnight",
2311
- noon: "noon",
2312
- morning: "morning",
2313
- afternoon: "afternoon",
2314
- evening: "evening",
2315
- night: "night",
2316
- };
2317
-
2318
- /*
2319
- * | | Unit | | Unit |
2320
- * |-----|--------------------------------|-----|--------------------------------|
2321
- * | a | AM, PM | A* | Milliseconds in day |
2322
- * | b | AM, PM, noon, midnight | B | Flexible day period |
2323
- * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
2324
- * | d | Day of month | D | Day of year |
2325
- * | e | Local day of week | E | Day of week |
2326
- * | f | | F* | Day of week in month |
2327
- * | g* | Modified Julian day | G | Era |
2328
- * | h | Hour [1-12] | H | Hour [0-23] |
2329
- * | i! | ISO day of week | I! | ISO week of year |
2330
- * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
2331
- * | k | Hour [1-24] | K | Hour [0-11] |
2332
- * | l* | (deprecated) | L | Stand-alone month |
2333
- * | m | Minute | M | Month |
2334
- * | n | | N | |
2335
- * | o! | Ordinal number modifier | O | Timezone (GMT) |
2336
- * | p! | Long localized time | P! | Long localized date |
2337
- * | q | Stand-alone quarter | Q | Quarter |
2338
- * | r* | Related Gregorian year | R! | ISO week-numbering year |
2339
- * | s | Second | S | Fraction of second |
2340
- * | t! | Seconds timestamp | T! | Milliseconds timestamp |
2341
- * | u | Extended year | U* | Cyclic year |
2342
- * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
2343
- * | w | Local week of year | W* | Week of month |
2344
- * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
2345
- * | y | Year (abs) | Y | Local week-numbering year |
2346
- * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
2347
- *
2348
- * Letters marked by * are not implemented but reserved by Unicode standard.
2349
- *
2350
- * Letters marked by ! are non-standard, but implemented by date-fns:
2351
- * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
2352
- * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
2353
- * i.e. 7 for Sunday, 1 for Monday, etc.
2354
- * - `I` is ISO week of year, as opposed to `w` which is local week of year.
2355
- * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
2356
- * `R` is supposed to be used in conjunction with `I` and `i`
2357
- * for universal ISO week-numbering date, whereas
2358
- * `Y` is supposed to be used in conjunction with `w` and `e`
2359
- * for week-numbering date specific to the locale.
2360
- * - `P` is long localized date format
2361
- * - `p` is long localized time format
2362
- */
2363
-
2364
- const formatters = {
2365
- // Era
2366
- G: function (date, token, localize) {
2367
- const era = date.getFullYear() > 0 ? 1 : 0;
2368
- switch (token) {
2369
- // AD, BC
2370
- case "G":
2371
- case "GG":
2372
- case "GGG":
2373
- return localize.era(era, { width: "abbreviated" });
2374
- // A, B
2375
- case "GGGGG":
2376
- return localize.era(era, { width: "narrow" });
2377
- // Anno Domini, Before Christ
2378
- case "GGGG":
2379
- default:
2380
- return localize.era(era, { width: "wide" });
2381
- }
2382
- },
2383
-
2384
- // Year
2385
- y: function (date, token, localize) {
2386
- // Ordinal number
2387
- if (token === "yo") {
2388
- const signedYear = date.getFullYear();
2389
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
2390
- const year = signedYear > 0 ? signedYear : 1 - signedYear;
2391
- return localize.ordinalNumber(year, { unit: "year" });
2392
- }
2393
-
2394
- return lightFormatters.y(date, token);
2395
- },
2396
-
2397
- // Local week-numbering year
2398
- Y: function (date, token, localize, options) {
2399
- const signedWeekYear = getWeekYear(date, options);
2400
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
2401
- const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
2402
-
2403
- // Two digit year
2404
- if (token === "YY") {
2405
- const twoDigitYear = weekYear % 100;
2406
- return addLeadingZeros(twoDigitYear, 2);
2407
- }
2408
-
2409
- // Ordinal number
2410
- if (token === "Yo") {
2411
- return localize.ordinalNumber(weekYear, { unit: "year" });
2412
- }
2413
-
2414
- // Padding
2415
- return addLeadingZeros(weekYear, token.length);
2416
- },
2417
-
2418
- // ISO week-numbering year
2419
- R: function (date, token) {
2420
- const isoWeekYear = getISOWeekYear(date);
2421
-
2422
- // Padding
2423
- return addLeadingZeros(isoWeekYear, token.length);
2424
- },
2425
-
2426
- // Extended year. This is a single number designating the year of this calendar system.
2427
- // The main difference between `y` and `u` localizers are B.C. years:
2428
- // | Year | `y` | `u` |
2429
- // |------|-----|-----|
2430
- // | AC 1 | 1 | 1 |
2431
- // | BC 1 | 1 | 0 |
2432
- // | BC 2 | 2 | -1 |
2433
- // Also `yy` always returns the last two digits of a year,
2434
- // while `uu` pads single digit years to 2 characters and returns other years unchanged.
2435
- u: function (date, token) {
2436
- const year = date.getFullYear();
2437
- return addLeadingZeros(year, token.length);
2438
- },
2439
-
2440
- // Quarter
2441
- Q: function (date, token, localize) {
2442
- const quarter = Math.ceil((date.getMonth() + 1) / 3);
2443
- switch (token) {
2444
- // 1, 2, 3, 4
2445
- case "Q":
2446
- return String(quarter);
2447
- // 01, 02, 03, 04
2448
- case "QQ":
2449
- return addLeadingZeros(quarter, 2);
2450
- // 1st, 2nd, 3rd, 4th
2451
- case "Qo":
2452
- return localize.ordinalNumber(quarter, { unit: "quarter" });
2453
- // Q1, Q2, Q3, Q4
2454
- case "QQQ":
2455
- return localize.quarter(quarter, {
2456
- width: "abbreviated",
2457
- context: "formatting",
2458
- });
2459
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2460
- case "QQQQQ":
2461
- return localize.quarter(quarter, {
2462
- width: "narrow",
2463
- context: "formatting",
2464
- });
2465
- // 1st quarter, 2nd quarter, ...
2466
- case "QQQQ":
2467
- default:
2468
- return localize.quarter(quarter, {
2469
- width: "wide",
2470
- context: "formatting",
2471
- });
2472
- }
2473
- },
2474
-
2475
- // Stand-alone quarter
2476
- q: function (date, token, localize) {
2477
- const quarter = Math.ceil((date.getMonth() + 1) / 3);
2478
- switch (token) {
2479
- // 1, 2, 3, 4
2480
- case "q":
2481
- return String(quarter);
2482
- // 01, 02, 03, 04
2483
- case "qq":
2484
- return addLeadingZeros(quarter, 2);
2485
- // 1st, 2nd, 3rd, 4th
2486
- case "qo":
2487
- return localize.ordinalNumber(quarter, { unit: "quarter" });
2488
- // Q1, Q2, Q3, Q4
2489
- case "qqq":
2490
- return localize.quarter(quarter, {
2491
- width: "abbreviated",
2492
- context: "standalone",
2493
- });
2494
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2495
- case "qqqqq":
2496
- return localize.quarter(quarter, {
2497
- width: "narrow",
2498
- context: "standalone",
2499
- });
2500
- // 1st quarter, 2nd quarter, ...
2501
- case "qqqq":
2502
- default:
2503
- return localize.quarter(quarter, {
2504
- width: "wide",
2505
- context: "standalone",
2506
- });
2507
- }
2508
- },
2509
-
2510
- // Month
2511
- M: function (date, token, localize) {
2512
- const month = date.getMonth();
2513
- switch (token) {
2514
- case "M":
2515
- case "MM":
2516
- return lightFormatters.M(date, token);
2517
- // 1st, 2nd, ..., 12th
2518
- case "Mo":
2519
- return localize.ordinalNumber(month + 1, { unit: "month" });
2520
- // Jan, Feb, ..., Dec
2521
- case "MMM":
2522
- return localize.month(month, {
2523
- width: "abbreviated",
2524
- context: "formatting",
2525
- });
2526
- // J, F, ..., D
2527
- case "MMMMM":
2528
- return localize.month(month, {
2529
- width: "narrow",
2530
- context: "formatting",
2531
- });
2532
- // January, February, ..., December
2533
- case "MMMM":
2534
- default:
2535
- return localize.month(month, { width: "wide", context: "formatting" });
2536
- }
2537
- },
2538
-
2539
- // Stand-alone month
2540
- L: function (date, token, localize) {
2541
- const month = date.getMonth();
2542
- switch (token) {
2543
- // 1, 2, ..., 12
2544
- case "L":
2545
- return String(month + 1);
2546
- // 01, 02, ..., 12
2547
- case "LL":
2548
- return addLeadingZeros(month + 1, 2);
2549
- // 1st, 2nd, ..., 12th
2550
- case "Lo":
2551
- return localize.ordinalNumber(month + 1, { unit: "month" });
2552
- // Jan, Feb, ..., Dec
2553
- case "LLL":
2554
- return localize.month(month, {
2555
- width: "abbreviated",
2556
- context: "standalone",
2557
- });
2558
- // J, F, ..., D
2559
- case "LLLLL":
2560
- return localize.month(month, {
2561
- width: "narrow",
2562
- context: "standalone",
2563
- });
2564
- // January, February, ..., December
2565
- case "LLLL":
2566
- default:
2567
- return localize.month(month, { width: "wide", context: "standalone" });
2568
- }
2569
- },
2570
-
2571
- // Local week of year
2572
- w: function (date, token, localize, options) {
2573
- const week = getWeek(date, options);
2574
-
2575
- if (token === "wo") {
2576
- return localize.ordinalNumber(week, { unit: "week" });
2577
- }
2578
-
2579
- return addLeadingZeros(week, token.length);
2580
- },
2581
-
2582
- // ISO week of year
2583
- I: function (date, token, localize) {
2584
- const isoWeek = getISOWeek(date);
2585
-
2586
- if (token === "Io") {
2587
- return localize.ordinalNumber(isoWeek, { unit: "week" });
2588
- }
2589
-
2590
- return addLeadingZeros(isoWeek, token.length);
2591
- },
2592
-
2593
- // Day of the month
2594
- d: function (date, token, localize) {
2595
- if (token === "do") {
2596
- return localize.ordinalNumber(date.getDate(), { unit: "date" });
2597
- }
2598
-
2599
- return lightFormatters.d(date, token);
2600
- },
2601
-
2602
- // Day of year
2603
- D: function (date, token, localize) {
2604
- const dayOfYear = getDayOfYear(date);
2605
-
2606
- if (token === "Do") {
2607
- return localize.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
2608
- }
2609
-
2610
- return addLeadingZeros(dayOfYear, token.length);
2611
- },
2612
-
2613
- // Day of week
2614
- E: function (date, token, localize) {
2615
- const dayOfWeek = date.getDay();
2616
- switch (token) {
2617
- // Tue
2618
- case "E":
2619
- case "EE":
2620
- case "EEE":
2621
- return localize.day(dayOfWeek, {
2622
- width: "abbreviated",
2623
- context: "formatting",
2624
- });
2625
- // T
2626
- case "EEEEE":
2627
- return localize.day(dayOfWeek, {
2628
- width: "narrow",
2629
- context: "formatting",
2630
- });
2631
- // Tu
2632
- case "EEEEEE":
2633
- return localize.day(dayOfWeek, {
2634
- width: "short",
2635
- context: "formatting",
2636
- });
2637
- // Tuesday
2638
- case "EEEE":
2639
- default:
2640
- return localize.day(dayOfWeek, {
2641
- width: "wide",
2642
- context: "formatting",
2643
- });
2644
- }
2645
- },
2646
-
2647
- // Local day of week
2648
- e: function (date, token, localize, options) {
2649
- const dayOfWeek = date.getDay();
2650
- const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
2651
- switch (token) {
2652
- // Numerical value (Nth day of week with current locale or weekStartsOn)
2653
- case "e":
2654
- return String(localDayOfWeek);
2655
- // Padded numerical value
2656
- case "ee":
2657
- return addLeadingZeros(localDayOfWeek, 2);
2658
- // 1st, 2nd, ..., 7th
2659
- case "eo":
2660
- return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
2661
- case "eee":
2662
- return localize.day(dayOfWeek, {
2663
- width: "abbreviated",
2664
- context: "formatting",
2665
- });
2666
- // T
2667
- case "eeeee":
2668
- return localize.day(dayOfWeek, {
2669
- width: "narrow",
2670
- context: "formatting",
2671
- });
2672
- // Tu
2673
- case "eeeeee":
2674
- return localize.day(dayOfWeek, {
2675
- width: "short",
2676
- context: "formatting",
2677
- });
2678
- // Tuesday
2679
- case "eeee":
2680
- default:
2681
- return localize.day(dayOfWeek, {
2682
- width: "wide",
2683
- context: "formatting",
2684
- });
2685
- }
2686
- },
2687
-
2688
- // Stand-alone local day of week
2689
- c: function (date, token, localize, options) {
2690
- const dayOfWeek = date.getDay();
2691
- const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
2692
- switch (token) {
2693
- // Numerical value (same as in `e`)
2694
- case "c":
2695
- return String(localDayOfWeek);
2696
- // Padded numerical value
2697
- case "cc":
2698
- return addLeadingZeros(localDayOfWeek, token.length);
2699
- // 1st, 2nd, ..., 7th
2700
- case "co":
2701
- return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
2702
- case "ccc":
2703
- return localize.day(dayOfWeek, {
2704
- width: "abbreviated",
2705
- context: "standalone",
2706
- });
2707
- // T
2708
- case "ccccc":
2709
- return localize.day(dayOfWeek, {
2710
- width: "narrow",
2711
- context: "standalone",
2712
- });
2713
- // Tu
2714
- case "cccccc":
2715
- return localize.day(dayOfWeek, {
2716
- width: "short",
2717
- context: "standalone",
2718
- });
2719
- // Tuesday
2720
- case "cccc":
2721
- default:
2722
- return localize.day(dayOfWeek, {
2723
- width: "wide",
2724
- context: "standalone",
2725
- });
2726
- }
2727
- },
2728
-
2729
- // ISO day of week
2730
- i: function (date, token, localize) {
2731
- const dayOfWeek = date.getDay();
2732
- const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
2733
- switch (token) {
2734
- // 2
2735
- case "i":
2736
- return String(isoDayOfWeek);
2737
- // 02
2738
- case "ii":
2739
- return addLeadingZeros(isoDayOfWeek, token.length);
2740
- // 2nd
2741
- case "io":
2742
- return localize.ordinalNumber(isoDayOfWeek, { unit: "day" });
2743
- // Tue
2744
- case "iii":
2745
- return localize.day(dayOfWeek, {
2746
- width: "abbreviated",
2747
- context: "formatting",
2748
- });
2749
- // T
2750
- case "iiiii":
2751
- return localize.day(dayOfWeek, {
2752
- width: "narrow",
2753
- context: "formatting",
2754
- });
2755
- // Tu
2756
- case "iiiiii":
2757
- return localize.day(dayOfWeek, {
2758
- width: "short",
2759
- context: "formatting",
2760
- });
2761
- // Tuesday
2762
- case "iiii":
2763
- default:
2764
- return localize.day(dayOfWeek, {
2765
- width: "wide",
2766
- context: "formatting",
2767
- });
2768
- }
2769
- },
2770
-
2771
- // AM or PM
2772
- a: function (date, token, localize) {
2773
- const hours = date.getHours();
2774
- const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
2775
-
2776
- switch (token) {
2777
- case "a":
2778
- case "aa":
2779
- return localize.dayPeriod(dayPeriodEnumValue, {
2780
- width: "abbreviated",
2781
- context: "formatting",
2782
- });
2783
- case "aaa":
2784
- return localize
2785
- .dayPeriod(dayPeriodEnumValue, {
2786
- width: "abbreviated",
2787
- context: "formatting",
2788
- })
2789
- .toLowerCase();
2790
- case "aaaaa":
2791
- return localize.dayPeriod(dayPeriodEnumValue, {
2792
- width: "narrow",
2793
- context: "formatting",
2794
- });
2795
- case "aaaa":
2796
- default:
2797
- return localize.dayPeriod(dayPeriodEnumValue, {
2798
- width: "wide",
2799
- context: "formatting",
2800
- });
2801
- }
2802
- },
2803
-
2804
- // AM, PM, midnight, noon
2805
- b: function (date, token, localize) {
2806
- const hours = date.getHours();
2807
- let dayPeriodEnumValue;
2808
- if (hours === 12) {
2809
- dayPeriodEnumValue = dayPeriodEnum.noon;
2810
- } else if (hours === 0) {
2811
- dayPeriodEnumValue = dayPeriodEnum.midnight;
2812
- } else {
2813
- dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
2814
- }
2815
-
2816
- switch (token) {
2817
- case "b":
2818
- case "bb":
2819
- return localize.dayPeriod(dayPeriodEnumValue, {
2820
- width: "abbreviated",
2821
- context: "formatting",
2822
- });
2823
- case "bbb":
2824
- return localize
2825
- .dayPeriod(dayPeriodEnumValue, {
2826
- width: "abbreviated",
2827
- context: "formatting",
2828
- })
2829
- .toLowerCase();
2830
- case "bbbbb":
2831
- return localize.dayPeriod(dayPeriodEnumValue, {
2832
- width: "narrow",
2833
- context: "formatting",
2834
- });
2835
- case "bbbb":
2836
- default:
2837
- return localize.dayPeriod(dayPeriodEnumValue, {
2838
- width: "wide",
2839
- context: "formatting",
2840
- });
2841
- }
2842
- },
2843
-
2844
- // in the morning, in the afternoon, in the evening, at night
2845
- B: function (date, token, localize) {
2846
- const hours = date.getHours();
2847
- let dayPeriodEnumValue;
2848
- if (hours >= 17) {
2849
- dayPeriodEnumValue = dayPeriodEnum.evening;
2850
- } else if (hours >= 12) {
2851
- dayPeriodEnumValue = dayPeriodEnum.afternoon;
2852
- } else if (hours >= 4) {
2853
- dayPeriodEnumValue = dayPeriodEnum.morning;
2854
- } else {
2855
- dayPeriodEnumValue = dayPeriodEnum.night;
2856
- }
2857
-
2858
- switch (token) {
2859
- case "B":
2860
- case "BB":
2861
- case "BBB":
2862
- return localize.dayPeriod(dayPeriodEnumValue, {
2863
- width: "abbreviated",
2864
- context: "formatting",
2865
- });
2866
- case "BBBBB":
2867
- return localize.dayPeriod(dayPeriodEnumValue, {
2868
- width: "narrow",
2869
- context: "formatting",
2870
- });
2871
- case "BBBB":
2872
- default:
2873
- return localize.dayPeriod(dayPeriodEnumValue, {
2874
- width: "wide",
2875
- context: "formatting",
2876
- });
2877
- }
2878
- },
2879
-
2880
- // Hour [1-12]
2881
- h: function (date, token, localize) {
2882
- if (token === "ho") {
2883
- let hours = date.getHours() % 12;
2884
- if (hours === 0) hours = 12;
2885
- return localize.ordinalNumber(hours, { unit: "hour" });
2886
- }
2887
-
2888
- return lightFormatters.h(date, token);
2889
- },
2890
-
2891
- // Hour [0-23]
2892
- H: function (date, token, localize) {
2893
- if (token === "Ho") {
2894
- return localize.ordinalNumber(date.getHours(), { unit: "hour" });
2895
- }
2896
-
2897
- return lightFormatters.H(date, token);
2898
- },
2899
-
2900
- // Hour [0-11]
2901
- K: function (date, token, localize) {
2902
- const hours = date.getHours() % 12;
2903
-
2904
- if (token === "Ko") {
2905
- return localize.ordinalNumber(hours, { unit: "hour" });
2906
- }
2907
-
2908
- return addLeadingZeros(hours, token.length);
2909
- },
2910
-
2911
- // Hour [1-24]
2912
- k: function (date, token, localize) {
2913
- let hours = date.getHours();
2914
- if (hours === 0) hours = 24;
2915
-
2916
- if (token === "ko") {
2917
- return localize.ordinalNumber(hours, { unit: "hour" });
2918
- }
2919
-
2920
- return addLeadingZeros(hours, token.length);
2921
- },
2922
-
2923
- // Minute
2924
- m: function (date, token, localize) {
2925
- if (token === "mo") {
2926
- return localize.ordinalNumber(date.getMinutes(), { unit: "minute" });
2927
- }
2928
-
2929
- return lightFormatters.m(date, token);
2930
- },
2931
-
2932
- // Second
2933
- s: function (date, token, localize) {
2934
- if (token === "so") {
2935
- return localize.ordinalNumber(date.getSeconds(), { unit: "second" });
2936
- }
2937
-
2938
- return lightFormatters.s(date, token);
2939
- },
2940
-
2941
- // Fraction of second
2942
- S: function (date, token) {
2943
- return lightFormatters.S(date, token);
2944
- },
2945
-
2946
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
2947
- X: function (date, token, _localize) {
2948
- const timezoneOffset = date.getTimezoneOffset();
2949
-
2950
- if (timezoneOffset === 0) {
2951
- return "Z";
2952
- }
2953
-
2954
- switch (token) {
2955
- // Hours and optional minutes
2956
- case "X":
2957
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
2958
-
2959
- // Hours, minutes and optional seconds without `:` delimiter
2960
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2961
- // so this token always has the same output as `XX`
2962
- case "XXXX":
2963
- case "XX": // Hours and minutes without `:` delimiter
2964
- return formatTimezone(timezoneOffset);
2965
-
2966
- // Hours, minutes and optional seconds with `:` delimiter
2967
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2968
- // so this token always has the same output as `XXX`
2969
- case "XXXXX":
2970
- case "XXX": // Hours and minutes with `:` delimiter
2971
- default:
2972
- return formatTimezone(timezoneOffset, ":");
2973
- }
2974
- },
2975
-
2976
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
2977
- x: function (date, token, _localize) {
2978
- const timezoneOffset = date.getTimezoneOffset();
2979
-
2980
- switch (token) {
2981
- // Hours and optional minutes
2982
- case "x":
2983
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
2984
-
2985
- // Hours, minutes and optional seconds without `:` delimiter
2986
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2987
- // so this token always has the same output as `xx`
2988
- case "xxxx":
2989
- case "xx": // Hours and minutes without `:` delimiter
2990
- return formatTimezone(timezoneOffset);
2991
-
2992
- // Hours, minutes and optional seconds with `:` delimiter
2993
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2994
- // so this token always has the same output as `xxx`
2995
- case "xxxxx":
2996
- case "xxx": // Hours and minutes with `:` delimiter
2997
- default:
2998
- return formatTimezone(timezoneOffset, ":");
2999
- }
3000
- },
3001
-
3002
- // Timezone (GMT)
3003
- O: function (date, token, _localize) {
3004
- const timezoneOffset = date.getTimezoneOffset();
3005
-
3006
- switch (token) {
3007
- // Short
3008
- case "O":
3009
- case "OO":
3010
- case "OOO":
3011
- return "GMT" + formatTimezoneShort(timezoneOffset, ":");
3012
- // Long
3013
- case "OOOO":
3014
- default:
3015
- return "GMT" + formatTimezone(timezoneOffset, ":");
3016
- }
3017
- },
3018
-
3019
- // Timezone (specific non-location)
3020
- z: function (date, token, _localize) {
3021
- const timezoneOffset = date.getTimezoneOffset();
3022
-
3023
- switch (token) {
3024
- // Short
3025
- case "z":
3026
- case "zz":
3027
- case "zzz":
3028
- return "GMT" + formatTimezoneShort(timezoneOffset, ":");
3029
- // Long
3030
- case "zzzz":
3031
- default:
3032
- return "GMT" + formatTimezone(timezoneOffset, ":");
3033
- }
3034
- },
3035
-
3036
- // Seconds timestamp
3037
- t: function (date, token, _localize) {
3038
- const timestamp = Math.trunc(+date / 1000);
3039
- return addLeadingZeros(timestamp, token.length);
3040
- },
3041
-
3042
- // Milliseconds timestamp
3043
- T: function (date, token, _localize) {
3044
- return addLeadingZeros(+date, token.length);
3045
- },
3046
- };
3047
-
3048
- function formatTimezoneShort(offset, delimiter = "") {
3049
- const sign = offset > 0 ? "-" : "+";
3050
- const absOffset = Math.abs(offset);
3051
- const hours = Math.trunc(absOffset / 60);
3052
- const minutes = absOffset % 60;
3053
- if (minutes === 0) {
3054
- return sign + String(hours);
3055
- }
3056
- return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
3057
- }
3058
-
3059
- function formatTimezoneWithOptionalMinutes(offset, delimiter) {
3060
- if (offset % 60 === 0) {
3061
- const sign = offset > 0 ? "-" : "+";
3062
- return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
3063
- }
3064
- return formatTimezone(offset, delimiter);
3065
- }
3066
-
3067
- function formatTimezone(offset, delimiter = "") {
3068
- const sign = offset > 0 ? "-" : "+";
3069
- const absOffset = Math.abs(offset);
3070
- const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
3071
- const minutes = addLeadingZeros(absOffset % 60, 2);
3072
- return sign + hours + delimiter + minutes;
3073
- }
3074
-
3075
- const dateLongFormatter = (pattern, formatLong) => {
3076
- switch (pattern) {
3077
- case "P":
3078
- return formatLong.date({ width: "short" });
3079
- case "PP":
3080
- return formatLong.date({ width: "medium" });
3081
- case "PPP":
3082
- return formatLong.date({ width: "long" });
3083
- case "PPPP":
3084
- default:
3085
- return formatLong.date({ width: "full" });
3086
- }
3087
- };
3088
-
3089
- const timeLongFormatter = (pattern, formatLong) => {
3090
- switch (pattern) {
3091
- case "p":
3092
- return formatLong.time({ width: "short" });
3093
- case "pp":
3094
- return formatLong.time({ width: "medium" });
3095
- case "ppp":
3096
- return formatLong.time({ width: "long" });
3097
- case "pppp":
3098
- default:
3099
- return formatLong.time({ width: "full" });
3100
- }
3101
- };
3102
-
3103
- const dateTimeLongFormatter = (pattern, formatLong) => {
3104
- const matchResult = pattern.match(/(P+)(p+)?/) || [];
3105
- const datePattern = matchResult[1];
3106
- const timePattern = matchResult[2];
3107
-
3108
- if (!timePattern) {
3109
- return dateLongFormatter(pattern, formatLong);
3110
- }
3111
-
3112
- let dateTimeFormat;
3113
-
3114
- switch (datePattern) {
3115
- case "P":
3116
- dateTimeFormat = formatLong.dateTime({ width: "short" });
3117
- break;
3118
- case "PP":
3119
- dateTimeFormat = formatLong.dateTime({ width: "medium" });
3120
- break;
3121
- case "PPP":
3122
- dateTimeFormat = formatLong.dateTime({ width: "long" });
3123
- break;
3124
- case "PPPP":
3125
- default:
3126
- dateTimeFormat = formatLong.dateTime({ width: "full" });
3127
- break;
3128
- }
3129
-
3130
- return dateTimeFormat
3131
- .replace("{{date}}", dateLongFormatter(datePattern, formatLong))
3132
- .replace("{{time}}", timeLongFormatter(timePattern, formatLong));
3133
- };
3134
-
3135
- const longFormatters = {
3136
- p: timeLongFormatter,
3137
- P: dateTimeLongFormatter,
3138
- };
3139
-
3140
- const dayOfYearTokenRE = /^D+$/;
3141
- const weekYearTokenRE = /^Y+$/;
3142
-
3143
- const throwTokens = ["D", "DD", "YY", "YYYY"];
3144
-
3145
- function isProtectedDayOfYearToken(token) {
3146
- return dayOfYearTokenRE.test(token);
3147
- }
3148
-
3149
- function isProtectedWeekYearToken(token) {
3150
- return weekYearTokenRE.test(token);
3151
- }
3152
-
3153
- function warnOrThrowProtectedError(token, format, input) {
3154
- const _message = message(token, format, input);
3155
- console.warn(_message);
3156
- if (throwTokens.includes(token)) throw new RangeError(_message);
3157
- }
3158
-
3159
- function message(token, format, input) {
3160
- const subject = token[0] === "Y" ? "years" : "days of the month";
3161
- return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
3162
- }
3163
-
3164
- // This RegExp consists of three parts separated by `|`:
3165
- // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
3166
- // (one of the certain letters followed by `o`)
3167
- // - (\w)\1* matches any sequences of the same letter
3168
- // - '' matches two quote characters in a row
3169
- // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
3170
- // except a single quote symbol, which ends the sequence.
3171
- // Two quote characters do not end the sequence.
3172
- // If there is no matching single quote
3173
- // then the sequence will continue until the end of the string.
3174
- // - . matches any single character unmatched by previous parts of the RegExps
3175
- const formattingTokensRegExp =
3176
- /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
3177
-
3178
- // This RegExp catches symbols escaped by quotes, and also
3179
- // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
3180
- const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
3181
-
3182
- const escapedStringRegExp = /^'([^]*?)'?$/;
3183
- const doubleQuoteRegExp = /''/g;
3184
- const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
3185
-
3186
- /**
3187
- * The {@link format} function options.
3188
- */
3189
-
3190
- /**
3191
- * @name format
3192
- * @alias formatDate
3193
- * @category Common Helpers
3194
- * @summary Format the date.
3195
- *
3196
- * @description
3197
- * Return the formatted date string in the given format. The result may vary by locale.
3198
- *
3199
- * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
3200
- * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3201
- *
3202
- * The characters wrapped between two single quotes characters (') are escaped.
3203
- * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
3204
- * (see the last example)
3205
- *
3206
- * Format of the string is based on Unicode Technical Standard #35:
3207
- * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
3208
- * with a few additions (see note 7 below the table).
3209
- *
3210
- * Accepted patterns:
3211
- * | Unit | Pattern | Result examples | Notes |
3212
- * |---------------------------------|---------|-----------------------------------|-------|
3213
- * | Era | G..GGG | AD, BC | |
3214
- * | | GGGG | Anno Domini, Before Christ | 2 |
3215
- * | | GGGGG | A, B | |
3216
- * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
3217
- * | | yo | 44th, 1st, 0th, 17th | 5,7 |
3218
- * | | yy | 44, 01, 00, 17 | 5 |
3219
- * | | yyy | 044, 001, 1900, 2017 | 5 |
3220
- * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
3221
- * | | yyyyy | ... | 3,5 |
3222
- * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
3223
- * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
3224
- * | | YY | 44, 01, 00, 17 | 5,8 |
3225
- * | | YYY | 044, 001, 1900, 2017 | 5 |
3226
- * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
3227
- * | | YYYYY | ... | 3,5 |
3228
- * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
3229
- * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
3230
- * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
3231
- * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
3232
- * | | RRRRR | ... | 3,5,7 |
3233
- * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
3234
- * | | uu | -43, 01, 1900, 2017 | 5 |
3235
- * | | uuu | -043, 001, 1900, 2017 | 5 |
3236
- * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
3237
- * | | uuuuu | ... | 3,5 |
3238
- * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
3239
- * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
3240
- * | | QQ | 01, 02, 03, 04 | |
3241
- * | | QQQ | Q1, Q2, Q3, Q4 | |
3242
- * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
3243
- * | | QQQQQ | 1, 2, 3, 4 | 4 |
3244
- * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
3245
- * | | qo | 1st, 2nd, 3rd, 4th | 7 |
3246
- * | | qq | 01, 02, 03, 04 | |
3247
- * | | qqq | Q1, Q2, Q3, Q4 | |
3248
- * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
3249
- * | | qqqqq | 1, 2, 3, 4 | 4 |
3250
- * | Month (formatting) | M | 1, 2, ..., 12 | |
3251
- * | | Mo | 1st, 2nd, ..., 12th | 7 |
3252
- * | | MM | 01, 02, ..., 12 | |
3253
- * | | MMM | Jan, Feb, ..., Dec | |
3254
- * | | MMMM | January, February, ..., December | 2 |
3255
- * | | MMMMM | J, F, ..., D | |
3256
- * | Month (stand-alone) | L | 1, 2, ..., 12 | |
3257
- * | | Lo | 1st, 2nd, ..., 12th | 7 |
3258
- * | | LL | 01, 02, ..., 12 | |
3259
- * | | LLL | Jan, Feb, ..., Dec | |
3260
- * | | LLLL | January, February, ..., December | 2 |
3261
- * | | LLLLL | J, F, ..., D | |
3262
- * | Local week of year | w | 1, 2, ..., 53 | |
3263
- * | | wo | 1st, 2nd, ..., 53th | 7 |
3264
- * | | ww | 01, 02, ..., 53 | |
3265
- * | ISO week of year | I | 1, 2, ..., 53 | 7 |
3266
- * | | Io | 1st, 2nd, ..., 53th | 7 |
3267
- * | | II | 01, 02, ..., 53 | 7 |
3268
- * | Day of month | d | 1, 2, ..., 31 | |
3269
- * | | do | 1st, 2nd, ..., 31st | 7 |
3270
- * | | dd | 01, 02, ..., 31 | |
3271
- * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
3272
- * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
3273
- * | | DD | 01, 02, ..., 365, 366 | 9 |
3274
- * | | DDD | 001, 002, ..., 365, 366 | |
3275
- * | | DDDD | ... | 3 |
3276
- * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
3277
- * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
3278
- * | | EEEEE | M, T, W, T, F, S, S | |
3279
- * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
3280
- * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
3281
- * | | io | 1st, 2nd, ..., 7th | 7 |
3282
- * | | ii | 01, 02, ..., 07 | 7 |
3283
- * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
3284
- * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
3285
- * | | iiiii | M, T, W, T, F, S, S | 7 |
3286
- * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
3287
- * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
3288
- * | | eo | 2nd, 3rd, ..., 1st | 7 |
3289
- * | | ee | 02, 03, ..., 01 | |
3290
- * | | eee | Mon, Tue, Wed, ..., Sun | |
3291
- * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
3292
- * | | eeeee | M, T, W, T, F, S, S | |
3293
- * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
3294
- * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
3295
- * | | co | 2nd, 3rd, ..., 1st | 7 |
3296
- * | | cc | 02, 03, ..., 01 | |
3297
- * | | ccc | Mon, Tue, Wed, ..., Sun | |
3298
- * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
3299
- * | | ccccc | M, T, W, T, F, S, S | |
3300
- * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
3301
- * | AM, PM | a..aa | AM, PM | |
3302
- * | | aaa | am, pm | |
3303
- * | | aaaa | a.m., p.m. | 2 |
3304
- * | | aaaaa | a, p | |
3305
- * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
3306
- * | | bbb | am, pm, noon, midnight | |
3307
- * | | bbbb | a.m., p.m., noon, midnight | 2 |
3308
- * | | bbbbb | a, p, n, mi | |
3309
- * | Flexible day period | B..BBB | at night, in the morning, ... | |
3310
- * | | BBBB | at night, in the morning, ... | 2 |
3311
- * | | BBBBB | at night, in the morning, ... | |
3312
- * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
3313
- * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
3314
- * | | hh | 01, 02, ..., 11, 12 | |
3315
- * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
3316
- * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
3317
- * | | HH | 00, 01, 02, ..., 23 | |
3318
- * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
3319
- * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
3320
- * | | KK | 01, 02, ..., 11, 00 | |
3321
- * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
3322
- * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
3323
- * | | kk | 24, 01, 02, ..., 23 | |
3324
- * | Minute | m | 0, 1, ..., 59 | |
3325
- * | | mo | 0th, 1st, ..., 59th | 7 |
3326
- * | | mm | 00, 01, ..., 59 | |
3327
- * | Second | s | 0, 1, ..., 59 | |
3328
- * | | so | 0th, 1st, ..., 59th | 7 |
3329
- * | | ss | 00, 01, ..., 59 | |
3330
- * | Fraction of second | S | 0, 1, ..., 9 | |
3331
- * | | SS | 00, 01, ..., 99 | |
3332
- * | | SSS | 000, 001, ..., 999 | |
3333
- * | | SSSS | ... | 3 |
3334
- * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
3335
- * | | XX | -0800, +0530, Z | |
3336
- * | | XXX | -08:00, +05:30, Z | |
3337
- * | | XXXX | -0800, +0530, Z, +123456 | 2 |
3338
- * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
3339
- * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
3340
- * | | xx | -0800, +0530, +0000 | |
3341
- * | | xxx | -08:00, +05:30, +00:00 | 2 |
3342
- * | | xxxx | -0800, +0530, +0000, +123456 | |
3343
- * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
3344
- * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
3345
- * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
3346
- * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
3347
- * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
3348
- * | Seconds timestamp | t | 512969520 | 7 |
3349
- * | | tt | ... | 3,7 |
3350
- * | Milliseconds timestamp | T | 512969520900 | 7 |
3351
- * | | TT | ... | 3,7 |
3352
- * | Long localized date | P | 04/29/1453 | 7 |
3353
- * | | PP | Apr 29, 1453 | 7 |
3354
- * | | PPP | April 29th, 1453 | 7 |
3355
- * | | PPPP | Friday, April 29th, 1453 | 2,7 |
3356
- * | Long localized time | p | 12:00 AM | 7 |
3357
- * | | pp | 12:00:00 AM | 7 |
3358
- * | | ppp | 12:00:00 AM GMT+2 | 7 |
3359
- * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
3360
- * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
3361
- * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
3362
- * | | PPPppp | April 29th, 1453 at ... | 7 |
3363
- * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
3364
- * Notes:
3365
- * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
3366
- * are the same as "stand-alone" units, but are different in some languages.
3367
- * "Formatting" units are declined according to the rules of the language
3368
- * in the context of a date. "Stand-alone" units are always nominative singular:
3369
- *
3370
- * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
3371
- *
3372
- * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
3373
- *
3374
- * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
3375
- * the single quote characters (see below).
3376
- * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
3377
- * the output will be the same as default pattern for this unit, usually
3378
- * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
3379
- * are marked with "2" in the last column of the table.
3380
- *
3381
- * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
3382
- *
3383
- * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
3384
- *
3385
- * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
3386
- *
3387
- * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
3388
- *
3389
- * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
3390
- *
3391
- * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
3392
- * The output will be padded with zeros to match the length of the pattern.
3393
- *
3394
- * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
3395
- *
3396
- * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
3397
- * These tokens represent the shortest form of the quarter.
3398
- *
3399
- * 5. The main difference between `y` and `u` patterns are B.C. years:
3400
- *
3401
- * | Year | `y` | `u` |
3402
- * |------|-----|-----|
3403
- * | AC 1 | 1 | 1 |
3404
- * | BC 1 | 1 | 0 |
3405
- * | BC 2 | 2 | -1 |
3406
- *
3407
- * Also `yy` always returns the last two digits of a year,
3408
- * while `uu` pads single digit years to 2 characters and returns other years unchanged:
3409
- *
3410
- * | Year | `yy` | `uu` |
3411
- * |------|------|------|
3412
- * | 1 | 01 | 01 |
3413
- * | 14 | 14 | 14 |
3414
- * | 376 | 76 | 376 |
3415
- * | 1453 | 53 | 1453 |
3416
- *
3417
- * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
3418
- * except local week-numbering years are dependent on `options.weekStartsOn`
3419
- * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear)
3420
- * and [getWeekYear](https://date-fns.org/docs/getWeekYear)).
3421
- *
3422
- * 6. Specific non-location timezones are currently unavailable in `date-fns`,
3423
- * so right now these tokens fall back to GMT timezones.
3424
- *
3425
- * 7. These patterns are not in the Unicode Technical Standard #35:
3426
- * - `i`: ISO day of week
3427
- * - `I`: ISO week of year
3428
- * - `R`: ISO week-numbering year
3429
- * - `t`: seconds timestamp
3430
- * - `T`: milliseconds timestamp
3431
- * - `o`: ordinal number modifier
3432
- * - `P`: long localized date
3433
- * - `p`: long localized time
3434
- *
3435
- * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
3436
- * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3437
- *
3438
- * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
3439
- * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3440
- *
3441
- * @param date - The original date
3442
- * @param format - The string of tokens
3443
- * @param options - An object with options
3444
- *
3445
- * @returns The formatted date string
3446
- *
3447
- * @throws `date` must not be Invalid Date
3448
- * @throws `options.locale` must contain `localize` property
3449
- * @throws `options.locale` must contain `formatLong` property
3450
- * @throws use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3451
- * @throws use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3452
- * @throws use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3453
- * @throws use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3454
- * @throws format string contains an unescaped latin alphabet character
3455
- *
3456
- * @example
3457
- * // Represent 11 February 2014 in middle-endian format:
3458
- * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
3459
- * //=> '02/11/2014'
3460
- *
3461
- * @example
3462
- * // Represent 2 July 2014 in Esperanto:
3463
- * import { eoLocale } from 'date-fns/locale/eo'
3464
- * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
3465
- * locale: eoLocale
3466
- * })
3467
- * //=> '2-a de julio 2014'
3468
- *
3469
- * @example
3470
- * // Escape string by single quote characters:
3471
- * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
3472
- * //=> "3 o'clock"
3473
- */
3474
- function format(date, formatStr, options) {
3475
- const defaultOptions = getDefaultOptions();
3476
- const locale = options?.locale ?? defaultOptions.locale ?? enUS;
3477
-
3478
- const firstWeekContainsDate =
3479
- options?.firstWeekContainsDate ??
3480
- options?.locale?.options?.firstWeekContainsDate ??
3481
- defaultOptions.firstWeekContainsDate ??
3482
- defaultOptions.locale?.options?.firstWeekContainsDate ??
3483
- 1;
3484
-
3485
- const weekStartsOn =
3486
- options?.weekStartsOn ??
3487
- options?.locale?.options?.weekStartsOn ??
3488
- defaultOptions.weekStartsOn ??
3489
- defaultOptions.locale?.options?.weekStartsOn ??
3490
- 0;
3491
-
3492
- const originalDate = toDate(date, options?.in);
3493
-
3494
- if (!isValid(originalDate)) {
3495
- throw new RangeError("Invalid time value");
3496
- }
3497
-
3498
- let parts = formatStr
3499
- .match(longFormattingTokensRegExp)
3500
- .map((substring) => {
3501
- const firstCharacter = substring[0];
3502
- if (firstCharacter === "p" || firstCharacter === "P") {
3503
- const longFormatter = longFormatters[firstCharacter];
3504
- return longFormatter(substring, locale.formatLong);
3505
- }
3506
- return substring;
3507
- })
3508
- .join("")
3509
- .match(formattingTokensRegExp)
3510
- .map((substring) => {
3511
- // Replace two single quote characters with one single quote character
3512
- if (substring === "''") {
3513
- return { isToken: false, value: "'" };
3514
- }
3515
-
3516
- const firstCharacter = substring[0];
3517
- if (firstCharacter === "'") {
3518
- return { isToken: false, value: cleanEscapedString(substring) };
3519
- }
3520
-
3521
- if (formatters[firstCharacter]) {
3522
- return { isToken: true, value: substring };
3523
- }
3524
-
3525
- if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
3526
- throw new RangeError(
3527
- "Format string contains an unescaped latin alphabet character `" +
3528
- firstCharacter +
3529
- "`",
3530
- );
3531
- }
3532
-
3533
- return { isToken: false, value: substring };
3534
- });
3535
-
3536
- // invoke localize preprocessor (only for french locales at the moment)
3537
- if (locale.localize.preprocessor) {
3538
- parts = locale.localize.preprocessor(originalDate, parts);
3539
- }
3540
-
3541
- const formatterOptions = {
3542
- firstWeekContainsDate,
3543
- weekStartsOn,
3544
- locale,
3545
- };
3546
-
3547
- return parts
3548
- .map((part) => {
3549
- if (!part.isToken) return part.value;
3550
-
3551
- const token = part.value;
3552
-
3553
- if (
3554
- (!options?.useAdditionalWeekYearTokens &&
3555
- isProtectedWeekYearToken(token)) ||
3556
- (!options?.useAdditionalDayOfYearTokens &&
3557
- isProtectedDayOfYearToken(token))
3558
- ) {
3559
- warnOrThrowProtectedError(token, formatStr, String(date));
3560
- }
3561
-
3562
- const formatter = formatters[token[0]];
3563
- return formatter(originalDate, token, locale.localize, formatterOptions);
3564
- })
3565
- .join("");
3566
- }
3567
-
3568
- function cleanEscapedString(input) {
3569
- const matched = input.match(escapedStringRegExp);
3570
-
3571
- if (!matched) {
3572
- return input;
3573
- }
3574
-
3575
- return matched[1].replace(doubleQuoteRegExp, "'");
3576
- }
3577
-
3578
- const formatDistanceLocale = {
3579
- lessThanXSeconds: {
3580
- one: "menos de um segundo",
3581
- other: "menos de {{count}} segundos",
3582
- },
3583
-
3584
- xSeconds: {
3585
- one: "1 segundo",
3586
- other: "{{count}} segundos",
3587
- },
3588
-
3589
- halfAMinute: "meio minuto",
3590
-
3591
- lessThanXMinutes: {
3592
- one: "menos de um minuto",
3593
- other: "menos de {{count}} minutos",
3594
- },
3595
-
3596
- xMinutes: {
3597
- one: "1 minuto",
3598
- other: "{{count}} minutos",
3599
- },
3600
-
3601
- aboutXHours: {
3602
- one: "cerca de 1 hora",
3603
- other: "cerca de {{count}} horas",
3604
- },
3605
-
3606
- xHours: {
3607
- one: "1 hora",
3608
- other: "{{count}} horas",
3609
- },
3610
-
3611
- xDays: {
3612
- one: "1 dia",
3613
- other: "{{count}} dias",
3614
- },
3615
-
3616
- aboutXWeeks: {
3617
- one: "cerca de 1 semana",
3618
- other: "cerca de {{count}} semanas",
3619
- },
3620
-
3621
- xWeeks: {
3622
- one: "1 semana",
3623
- other: "{{count}} semanas",
3624
- },
3625
-
3626
- aboutXMonths: {
3627
- one: "cerca de 1 mês",
3628
- other: "cerca de {{count}} meses",
3629
- },
3630
-
3631
- xMonths: {
3632
- one: "1 mês",
3633
- other: "{{count}} meses",
3634
- },
3635
-
3636
- aboutXYears: {
3637
- one: "cerca de 1 ano",
3638
- other: "cerca de {{count}} anos",
3639
- },
3640
-
3641
- xYears: {
3642
- one: "1 ano",
3643
- other: "{{count}} anos",
3644
- },
3645
-
3646
- overXYears: {
3647
- one: "mais de 1 ano",
3648
- other: "mais de {{count}} anos",
3649
- },
3650
-
3651
- almostXYears: {
3652
- one: "quase 1 ano",
3653
- other: "quase {{count}} anos",
3654
- },
3655
- };
3656
-
3657
- const formatDistance = (token, count, options) => {
3658
- let result;
3659
-
3660
- const tokenValue = formatDistanceLocale[token];
3661
- if (typeof tokenValue === "string") {
3662
- result = tokenValue;
3663
- } else if (count === 1) {
3664
- result = tokenValue.one;
3665
- } else {
3666
- result = tokenValue.other.replace("{{count}}", String(count));
3667
- }
3668
-
3669
- if (options?.addSuffix) {
3670
- if (options.comparison && options.comparison > 0) {
3671
- return "em " + result;
3672
- } else {
3673
- return "há " + result;
3674
- }
3675
- }
3676
-
3677
- return result;
3678
- };
3679
-
3680
- const dateFormats = {
3681
- full: "EEEE, d 'de' MMMM 'de' y",
3682
- long: "d 'de' MMMM 'de' y",
3683
- medium: "d MMM y",
3684
- short: "dd/MM/yyyy",
3685
- };
3686
-
3687
- const timeFormats = {
3688
- full: "HH:mm:ss zzzz",
3689
- long: "HH:mm:ss z",
3690
- medium: "HH:mm:ss",
3691
- short: "HH:mm",
3692
- };
3693
-
3694
- const dateTimeFormats = {
3695
- full: "{{date}} 'às' {{time}}",
3696
- long: "{{date}} 'às' {{time}}",
3697
- medium: "{{date}}, {{time}}",
3698
- short: "{{date}}, {{time}}",
3699
- };
3700
-
3701
- const formatLong = {
3702
- date: buildFormatLongFn({
3703
- formats: dateFormats,
3704
- defaultWidth: "full",
3705
- }),
3706
-
3707
- time: buildFormatLongFn({
3708
- formats: timeFormats,
3709
- defaultWidth: "full",
3710
- }),
3711
-
3712
- dateTime: buildFormatLongFn({
3713
- formats: dateTimeFormats,
3714
- defaultWidth: "full",
3715
- }),
3716
- };
3717
-
3718
- const formatRelativeLocale = {
3719
- lastWeek: (date) => {
3720
- const weekday = date.getDay();
3721
- const last = weekday === 0 || weekday === 6 ? "último" : "última";
3722
- return "'" + last + "' eeee 'às' p";
3723
- },
3724
- yesterday: "'ontem às' p",
3725
- today: "'hoje às' p",
3726
- tomorrow: "'amanhã às' p",
3727
- nextWeek: "eeee 'às' p",
3728
- other: "P",
3729
- };
3730
-
3731
- const formatRelative = (token, date, _baseDate, _options) => {
3732
- const format = formatRelativeLocale[token];
3733
-
3734
- if (typeof format === "function") {
3735
- return format(date);
3736
- }
3737
-
3738
- return format;
3739
- };
3740
-
3741
- const eraValues = {
3742
- narrow: ["AC", "DC"],
3743
- abbreviated: ["AC", "DC"],
3744
- wide: ["antes de cristo", "depois de cristo"],
3745
- };
3746
-
3747
- const quarterValues = {
3748
- narrow: ["1", "2", "3", "4"],
3749
- abbreviated: ["T1", "T2", "T3", "T4"],
3750
- wide: ["1º trimestre", "2º trimestre", "3º trimestre", "4º trimestre"],
3751
- };
3752
-
3753
- const monthValues = {
3754
- narrow: ["j", "f", "m", "a", "m", "j", "j", "a", "s", "o", "n", "d"],
3755
- abbreviated: [
3756
- "jan",
3757
- "fev",
3758
- "mar",
3759
- "abr",
3760
- "mai",
3761
- "jun",
3762
- "jul",
3763
- "ago",
3764
- "set",
3765
- "out",
3766
- "nov",
3767
- "dez",
3768
- ],
3769
-
3770
- wide: [
3771
- "janeiro",
3772
- "fevereiro",
3773
- "março",
3774
- "abril",
3775
- "maio",
3776
- "junho",
3777
- "julho",
3778
- "agosto",
3779
- "setembro",
3780
- "outubro",
3781
- "novembro",
3782
- "dezembro",
3783
- ],
3784
- };
3785
-
3786
- const dayValues = {
3787
- narrow: ["D", "S", "T", "Q", "Q", "S", "S"],
3788
- short: ["dom", "seg", "ter", "qua", "qui", "sex", "sab"],
3789
- abbreviated: [
3790
- "domingo",
3791
- "segunda",
3792
- "terça",
3793
- "quarta",
3794
- "quinta",
3795
- "sexta",
3796
- "sábado",
3797
- ],
3798
-
3799
- wide: [
3800
- "domingo",
3801
- "segunda-feira",
3802
- "terça-feira",
3803
- "quarta-feira",
3804
- "quinta-feira",
3805
- "sexta-feira",
3806
- "sábado",
3807
- ],
3808
- };
3809
-
3810
- const dayPeriodValues = {
3811
- narrow: {
3812
- am: "a",
3813
- pm: "p",
3814
- midnight: "mn",
3815
- noon: "md",
3816
- morning: "manhã",
3817
- afternoon: "tarde",
3818
- evening: "tarde",
3819
- night: "noite",
3820
- },
3821
- abbreviated: {
3822
- am: "AM",
3823
- pm: "PM",
3824
- midnight: "meia-noite",
3825
- noon: "meio-dia",
3826
- morning: "manhã",
3827
- afternoon: "tarde",
3828
- evening: "tarde",
3829
- night: "noite",
3830
- },
3831
- wide: {
3832
- am: "a.m.",
3833
- pm: "p.m.",
3834
- midnight: "meia-noite",
3835
- noon: "meio-dia",
3836
- morning: "manhã",
3837
- afternoon: "tarde",
3838
- evening: "tarde",
3839
- night: "noite",
3840
- },
3841
- };
3842
-
3843
- const formattingDayPeriodValues = {
3844
- narrow: {
3845
- am: "a",
3846
- pm: "p",
3847
- midnight: "mn",
3848
- noon: "md",
3849
- morning: "da manhã",
3850
- afternoon: "da tarde",
3851
- evening: "da tarde",
3852
- night: "da noite",
3853
- },
3854
- abbreviated: {
3855
- am: "AM",
3856
- pm: "PM",
3857
- midnight: "meia-noite",
3858
- noon: "meio-dia",
3859
- morning: "da manhã",
3860
- afternoon: "da tarde",
3861
- evening: "da tarde",
3862
- night: "da noite",
3863
- },
3864
- wide: {
3865
- am: "a.m.",
3866
- pm: "p.m.",
3867
- midnight: "meia-noite",
3868
- noon: "meio-dia",
3869
- morning: "da manhã",
3870
- afternoon: "da tarde",
3871
- evening: "da tarde",
3872
- night: "da noite",
3873
- },
3874
- };
3875
-
3876
- const ordinalNumber = (dirtyNumber, options) => {
3877
- const number = Number(dirtyNumber);
3878
-
3879
- if (options?.unit === "week") {
3880
- return number + "ª";
3881
- }
3882
- return number + "º";
3883
- };
3884
-
3885
- const localize = {
3886
- ordinalNumber,
3887
-
3888
- era: buildLocalizeFn({
3889
- values: eraValues,
3890
- defaultWidth: "wide",
3891
- }),
3892
-
3893
- quarter: buildLocalizeFn({
3894
- values: quarterValues,
3895
- defaultWidth: "wide",
3896
- argumentCallback: (quarter) => quarter - 1,
3897
- }),
3898
-
3899
- month: buildLocalizeFn({
3900
- values: monthValues,
3901
- defaultWidth: "wide",
3902
- }),
3903
-
3904
- day: buildLocalizeFn({
3905
- values: dayValues,
3906
- defaultWidth: "wide",
3907
- }),
3908
-
3909
- dayPeriod: buildLocalizeFn({
3910
- values: dayPeriodValues,
3911
- defaultWidth: "wide",
3912
- formattingValues: formattingDayPeriodValues,
3913
- defaultFormattingWidth: "wide",
3914
- }),
3915
- };
3916
-
3917
- const matchOrdinalNumberPattern = /^(\d+)[ºªo]?/i;
3918
- const parseOrdinalNumberPattern = /\d+/i;
3919
-
3920
- const matchEraPatterns = {
3921
- narrow: /^(ac|dc|a|d)/i,
3922
- abbreviated: /^(a\.?\s?c\.?|d\.?\s?c\.?)/i,
3923
- wide: /^(antes de cristo|depois de cristo)/i,
3924
- };
3925
- const parseEraPatterns = {
3926
- any: [/^ac/i, /^dc/i],
3927
- wide: [/^antes de cristo/i, /^depois de cristo/i],
3928
- };
3929
-
3930
- const matchQuarterPatterns = {
3931
- narrow: /^[1234]/i,
3932
- abbreviated: /^T[1234]/i,
3933
- wide: /^[1234](º)? trimestre/i,
3934
- };
3935
- const parseQuarterPatterns = {
3936
- any: [/1/i, /2/i, /3/i, /4/i],
3937
- };
3938
-
3939
- const matchMonthPatterns = {
3940
- narrow: /^[jfmajsond]/i,
3941
- abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i,
3942
- wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i,
3943
- };
3944
- const parseMonthPatterns = {
3945
- narrow: [
3946
- /^j/i,
3947
- /^f/i,
3948
- /^m/i,
3949
- /^a/i,
3950
- /^m/i,
3951
- /^j/i,
3952
- /^j/i,
3953
- /^a/i,
3954
- /^s/i,
3955
- /^o/i,
3956
- /^n/i,
3957
- /^d/i,
3958
- ],
3959
-
3960
- any: [
3961
- /^ja/i,
3962
- /^fev/i,
3963
- /^mar/i,
3964
- /^abr/i,
3965
- /^mai/i,
3966
- /^jun/i,
3967
- /^jul/i,
3968
- /^ago/i,
3969
- /^set/i,
3970
- /^out/i,
3971
- /^nov/i,
3972
- /^dez/i,
3973
- ],
3974
- };
3975
-
3976
- const matchDayPatterns = {
3977
- narrow: /^(dom|[23456]ª?|s[aá]b)/i,
3978
- short: /^(dom|[23456]ª?|s[aá]b)/i,
3979
- abbreviated: /^(dom|seg|ter|qua|qui|sex|s[aá]b)/i,
3980
- wide: /^(domingo|(segunda|ter[cç]a|quarta|quinta|sexta)([- ]feira)?|s[aá]bado)/i,
3981
- };
3982
- const parseDayPatterns = {
3983
- short: [/^d/i, /^2/i, /^3/i, /^4/i, /^5/i, /^6/i, /^s[aá]/i],
3984
- narrow: [/^d/i, /^2/i, /^3/i, /^4/i, /^5/i, /^6/i, /^s[aá]/i],
3985
- any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[aá]b/i],
3986
- };
3987
-
3988
- const matchDayPeriodPatterns = {
3989
- narrow: /^(a|p|mn|md|(da) (manhã|tarde|noite))/i,
3990
- any: /^([ap]\.?\s?m\.?|meia[-\s]noite|meio[-\s]dia|(da) (manhã|tarde|noite))/i,
3991
- };
3992
- const parseDayPeriodPatterns = {
3993
- any: {
3994
- am: /^a/i,
3995
- pm: /^p/i,
3996
- midnight: /^mn|^meia[-\s]noite/i,
3997
- noon: /^md|^meio[-\s]dia/i,
3998
- morning: /manhã/i,
3999
- afternoon: /tarde/i,
4000
- evening: /tarde/i,
4001
- night: /noite/i,
4002
- },
4003
- };
4004
-
4005
- const match = {
4006
- ordinalNumber: buildMatchPatternFn({
4007
- matchPattern: matchOrdinalNumberPattern,
4008
- parsePattern: parseOrdinalNumberPattern,
4009
- valueCallback: (value) => parseInt(value, 10),
4010
- }),
4011
-
4012
- era: buildMatchFn({
4013
- matchPatterns: matchEraPatterns,
4014
- defaultMatchWidth: "wide",
4015
- parsePatterns: parseEraPatterns,
4016
- defaultParseWidth: "any",
4017
- }),
4018
-
4019
- quarter: buildMatchFn({
4020
- matchPatterns: matchQuarterPatterns,
4021
- defaultMatchWidth: "wide",
4022
- parsePatterns: parseQuarterPatterns,
4023
- defaultParseWidth: "any",
4024
- valueCallback: (index) => index + 1,
4025
- }),
4026
-
4027
- month: buildMatchFn({
4028
- matchPatterns: matchMonthPatterns,
4029
- defaultMatchWidth: "wide",
4030
- parsePatterns: parseMonthPatterns,
4031
- defaultParseWidth: "any",
4032
- }),
4033
-
4034
- day: buildMatchFn({
4035
- matchPatterns: matchDayPatterns,
4036
- defaultMatchWidth: "wide",
4037
- parsePatterns: parseDayPatterns,
4038
- defaultParseWidth: "any",
4039
- }),
4040
-
4041
- dayPeriod: buildMatchFn({
4042
- matchPatterns: matchDayPeriodPatterns,
4043
- defaultMatchWidth: "any",
4044
- parsePatterns: parseDayPeriodPatterns,
4045
- defaultParseWidth: "any",
4046
- }),
4047
- };
4048
-
4049
- /**
4050
- * @category Locales
4051
- * @summary Portuguese locale (Brazil).
4052
- * @language Portuguese
4053
- * @iso-639-2 por
4054
- * @author Lucas Duailibe [@duailibe](https://github.com/duailibe)
4055
- * @author Yago Carballo [@yagocarballo](https://github.com/YagoCarballo)
4056
- */
4057
- const ptBR = {
4058
- code: "pt-BR",
4059
- formatDistance: formatDistance,
4060
- formatLong: formatLong,
4061
- formatRelative: formatRelative,
4062
- localize: localize,
4063
- match: match,
4064
- options: {
4065
- weekStartsOn: 0 /* Sunday */,
4066
- firstWeekContainsDate: 1,
4067
- },
4068
- };
4069
-
4070
- const formatDate = (date) => {
4071
- return format(date, "EEEE',' dd 'de' MMM '-' HH:mm", {
4072
- locale: ptBR,
4073
- }).replace('.', '');
4074
- };
4075
- function NotificationItem({ notification, onDelete, onClick, }) {
4076
- return (jsxRuntime.jsxs("div", { className: "flex flex-row items-start gap-2 px-4 hover:text-primary cursor-pointer rounded", children: [jsxRuntime.jsx("i", { className: "pi pi-circle-fill text-xs pt-1.5", style: { color: notification.active ? '#0AA836' : '#A0A4B3' } }), jsxRuntime.jsxs("div", { className: "flex-1 text-left", onClick: () => onClick(notification.id), children: [jsxRuntime.jsx("h2", { className: clsx('text-base font-bold', !notification.active && 'text-gray'), children: notification.title }), jsxRuntime.jsx("p", { className: clsx('text-sm py-1 text-gray'), children: notification.description }), jsxRuntime.jsx("p", { className: clsx('text-sm font-bold', !notification.active && 'text-gray'), children: formatDate(notification.date) })] }), jsxRuntime.jsx("div", { className: "min-w-6 cursor-pointer", onClick: () => onDelete(notification.id), children: jsxRuntime.jsx("i", { className: "pi pi-trash text-[#878787] hover:text-backgroundDark" }) })] }, notification.id));
4077
- }
4078
-
4079
- function Notification({ onClose, onReadAll, onDeleteNotificationbyId, onClickNotification, notifications, setFilter, filter, setInputValue, inputValue, filterOptions, }) {
4080
- const customContent = (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "flex justify-between items-center px-4 py-3 border-b border-[#F1F1F4]", children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx("i", { className: "pi pi-bell text-backgroundDark" }), jsxRuntime.jsx("h2", { className: "font-roboto text-base text-backgroundDark font-bold", children: "Notifica\u00E7\u00F5es" })] }), jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: jsxRuntime.jsx(Button, { label: "Marcar todas como lidas", variant: "secondaryOutline", onClick: onReadAll, className: "px-2 py-1 text-xs h-7" }) })] }), jsxRuntime.jsxs("div", { className: "px-4 py-2 flex flex-row gap-4", children: [jsxRuntime.jsx(Input, { value: inputValue, onChange: setInputValue, label: "Pesquisar", placeholder: "Pesquisar", icon: "pi-search", iconColor: "gray" }), jsxRuntime.jsx(FilterButton, { variant: "primary", label: "Filter", icon: jsxRuntime.jsx(FilterIcon, { color: "#FFFFFF" }), option: filter, setOption: (option) => setFilter(option), filterOptions: filterOptions })] }), jsxRuntime.jsx("div", { className: "text-center pt-4", children: notifications.length > 0 ? (jsxRuntime.jsx("div", { className: "w-100 h-[calc(100vh_-114.8px)] overflow-y-auto [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:rounded-r-md [&::-webkit-scrollbar-thumb]:rounded-md [&::-webkit-scrollbar-track]:bg-stone [&::-webkit-scrollbar-thumb]:bg-stoneDark", children: notifications.map((notification) => (jsxRuntime.jsxs("div", { className: "w-100 hover:bg-stoneBackground", children: [jsxRuntime.jsx(NotificationItem, { notification: notification, onDelete: onDeleteNotificationbyId, onClick: onClickNotification }), jsxRuntime.jsx(divider.Divider, {})] }, notification.id))) })) : (jsxRuntime.jsx("p", { children: " Sem notifica\u00E7\u00F5es" })) })] }));
4081
- return (jsxRuntime.jsx(sidebar.Sidebar, { visible: true, position: "right", onHide: onClose, className: "w-10/12 md:w-1/2 lg:w-1/3", content: customContent }));
4082
- }
4083
-
4084
- function Paginator(props) {
4085
- const template = {
4086
- layout: 'PrevPageLink PageLinks NextPageLink',
4087
- PrevPageLink: (options) => {
4088
- return (jsxRuntime.jsx("button", { className: utils.classNames(options.className, '!w-8 !h-8 min-w-0 mr-2 font-roboto'), onClick: options.onClick, disabled: options.disabled, "aria-label": "Pr\u00F3xima p\u00E1gina", children: jsxRuntime.jsx("span", { className: "pi pi-angle-left" }) }));
4089
- },
4090
- NextPageLink: (options) => {
4091
- return (jsxRuntime.jsx("button", { className: utils.classNames(options.className, '!w-8 !h-8 min-w-0 ml-2 font-roboto'), onClick: options.onClick, disabled: options.disabled, "aria-label": "P\u00E1gina anterior", children: jsxRuntime.jsx("span", { className: "pi pi-angle-right" }) }));
4092
- },
4093
- PageLinks: (options) => {
4094
- return React.cloneElement(options.element, {
4095
- className: utils.classNames(options.element.props.className, '!rounded-full !w-8 !h-8 min-w-0 font-roboto', {
4096
- 'bg-primary text-white': options.page === options.currentPage,
4097
- 'hover:bg-gray-100': options.page !== options.currentPage,
4098
- }),
4099
- });
4100
- },
4101
- };
4102
- return jsxRuntime.jsx(paginator.Paginator, { ...props, template: template });
4103
- }
4104
-
4105
- const variants = {
4106
- white: 'ring-offset-background',
4107
- secondary: 'ring-offset-secondary',
4108
- };
4109
- function RadioButton({ label, value, checked, onChange, disabled = false, error = false, variant = 'secondary', ariaLabel = 'Radio button', }) {
4110
- return (jsxRuntime.jsxs("label", { className: clsx('flex items-center gap-2 cursor-pointer font-roboto text-primary', disabled && 'text-disabled', error && !checked && 'text-redError'), children: [jsxRuntime.jsx("input", { type: "radio", value: value, checked: checked, onChange: onChange, disabled: disabled, className: clsx('font-roboto appearance-none w-2 h-2 border-0 rounded-full shadow-none ring-1 ring-offset-2 checked:bg-primary transition-colors duration-200', disabled
4111
- ? 'ring-stone'
4112
- : error && !checked
4113
- ? 'ring-redError'
4114
- : 'ring-gray', variants[variant]), "aria-label": ariaLabel }), label] }));
4115
- }
4116
-
4117
- function Select(props) {
4118
- const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma opção', } = props;
4119
- const [isOpen, setIsOpen] = React.useState(false);
4120
- const [searchText, setSearchText] = React.useState('');
4121
- const [highlightedIndex, setHighlightedIndex] = React.useState(-1);
4122
- const containerRef = React.useRef(null);
4123
- const normalize = (str) => str
4124
- .normalize('NFD')
4125
- .replace(/[\u0300-\u036f]/g, '')
4126
- .toLowerCase();
4127
- const filteredOptions = options.filter((option) => normalize(option.label).includes(normalize(searchText)));
4128
- const toggleDropdown = () => {
4129
- if (!disabled && !isLoading) {
4130
- const newState = !isOpen;
4131
- setIsOpen(newState);
4132
- setSearchText('');
4133
- setHighlightedIndex(-1);
4134
- }
4135
- };
4136
- const handleSelect = (option) => {
4137
- if (props.value?.value === option.value) {
4138
- props.onChange(null);
4139
- }
4140
- else {
4141
- props.onChange(option);
4142
- }
4143
- setSearchText('');
4144
- setIsOpen(false);
4145
- setHighlightedIndex(-1);
4146
- };
4147
- const hasError = !!error && !disabled;
4148
- const isInputDisabled = disabled || isLoading;
4149
- React.useEffect(() => {
4150
- const handleClickOutside = (event) => {
4151
- if (containerRef.current &&
4152
- !containerRef.current.contains(event.target)) {
4153
- setIsOpen(false);
4154
- setSearchText('');
4155
- setHighlightedIndex(-1);
4156
- }
4157
- };
4158
- document.addEventListener('mousedown', handleClickOutside);
4159
- return () => {
4160
- document.removeEventListener('mousedown', handleClickOutside);
4161
- };
4162
- }, []);
4163
- return (jsxRuntime.jsxs("div", { ref: containerRef, className: "relative flex flex-col w-100", children: [jsxRuntime.jsxs("div", { className: "relative w-full cursor-pointer", onClick: toggleDropdown, children: [jsxRuntime.jsx(FloatingLabel, { value: props.value ? props.value.label : '', label: label, disabled: isInputDisabled, error: error }), jsxRuntime.jsxs(iconfield.IconField, { className: "w-full", children: [jsxRuntime.jsx(inputtext.InputText, { placeholder: placeholder, type: "text", value: isLoading
4164
- ? 'Carregando...'
4165
- : isOpen
4166
- ? searchText
4167
- : (props.value?.label ?? ''), onClick: toggleDropdown, onChange: (e) => {
4168
- if (isOpen) {
4169
- setSearchText(e.target.value);
4170
- setHighlightedIndex(0);
4171
- props.onInputChange?.(e.target.value);
4172
- }
4173
- }, onKeyDown: (e) => {
4174
- if (!isOpen)
4175
- return;
4176
- if (e.key === 'ArrowDown') {
4177
- e.preventDefault();
4178
- setHighlightedIndex((prev) => prev < filteredOptions.length - 1 ? prev + 1 : 0);
4179
- }
4180
- if (e.key === 'ArrowUp') {
4181
- e.preventDefault();
4182
- setHighlightedIndex((prev) => prev > 0 ? prev - 1 : filteredOptions.length - 1);
4183
- }
4184
- if (e.key === 'Enter') {
4185
- e.preventDefault();
4186
- if (highlightedIndex >= 0 &&
4187
- highlightedIndex < filteredOptions.length) {
4188
- handleSelect(filteredOptions[highlightedIndex]);
4189
- }
4190
- }
4191
- if (e.key === 'Escape') {
4192
- e.preventDefault();
4193
- setIsOpen(false);
4194
- setSearchText('');
4195
- setHighlightedIndex(-1);
4196
- }
4197
- }, className: clsx('focus:shadow-none text-base w-100 font-roboto border !p-2 rounded-md', hasError
4198
- ? 'border-redError placeholder:text-redError'
4199
- : 'border-gray focus:border-primary', isInputDisabled && 'border-stoneDark text-disabled', error && 'border-redError text-redError', !error && 'border-gray placeholder:text-gray', isLoading && 'text-gray', 'truncate'), invalid: hasError, readOnly: !isOpen || isReadOnly, style: { height: '42px', fontSize: '16px' }, disabled: isInputDisabled, "aria-label": ariaLabel }), jsxRuntime.jsx(inputicon.InputIcon, { className: clsx(isLoading
4200
- ? 'pi pi-spinner pi-spin'
4201
- : isOpen
4202
- ? 'pi pi-angle-up'
4203
- : 'pi pi-angle-down', 'text-gray px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && !isLoading && (jsxRuntime.jsx("div", { className: clsx('absolute w-full bg-background border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full', error ? 'border-redError' : 'border-gray'), children: jsxRuntime.jsx("ul", { className: "max-h-60 overflow-y-auto", children: filteredOptions.map((option, index) => (jsxRuntime.jsxs("li", { onClick: () => handleSelect(option), className: clsx('p-2 flex justify-between items-center cursor-pointer', 'hover:bg-stoneBackground hover:font-bold', index === highlightedIndex && 'bg-stoneBackground font-bold'), children: [jsxRuntime.jsx("span", { className: "truncate max-w-[calc(100%-20px)]", children: option.label }), jsxRuntime.jsx("input", { type: 'radio', checked: props.value?.value === option.value, onChange: () => handleSelect(option), className: clsx('appearance-none w-2 h-2 rounded-full ring-1 ring-offset-2 ring-offset-background ring-gray checked:bg-primary cursor-pointer') })] }, option.value))) }) })), hasError && jsxRuntime.jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
4204
- }
4205
-
4206
- function Skeleton({ shape = 'rectangle', width = '100%', height = '1rem', borderRadius, animation = 'wave', size, className, }) {
4207
- return (jsxRuntime.jsx("div", { className: className, children: jsxRuntime.jsx(skeleton.Skeleton, { shape: shape, width: width, height: height, borderRadius: borderRadius, animation: animation, size: size, "aria-label": "skeleton" }) }));
4208
- }
4209
-
4210
- const colorVariants = {
4211
- primary: 'border-primary',
4212
- secondary: 'border-secondary',
4213
- };
4214
- const sizeVariants = {
4215
- sm: 'w-4 h-4',
4216
- md: 'w-6 h-6',
4217
- lg: 'w-8 h-8',
4218
- };
4219
- function Spinner({ size = 'md', color = 'primary' }) {
4220
- return (jsxRuntime.jsx("div", { className: clsx('border-2 border-t-transparent animate-spin rounded-full', colorVariants[color], sizeVariants[size]), "aria-label": "loading", role: "status" }));
4221
- }
4222
-
4223
- /* eslint-disable @typescript-eslint/no-explicit-any */
4224
- function getNestedValue(obj, path) {
4225
- if (!obj || !path)
4226
- return undefined;
4227
- return path.split('.').reduce((acc, part) => acc?.[part], obj);
4228
- }
4229
-
4230
- // import { SortDirection } from '../types'
4231
- // export function sortData<T>(
4232
- // data: T[],
4233
- // column: keyof T,
4234
- // direction: SortDirection
4235
- // ): T[] {
4236
- // return [...data].sort((a, b) => {
4237
- // const aValue = a[column]
4238
- // const bValue = b[column]
4239
- // if (typeof aValue === 'number' && typeof bValue === 'number') {
4240
- // return direction === 'ASC' ? aValue - bValue : bValue - aValue
4241
- // }
4242
- // if (aValue instanceof Date && bValue instanceof Date) {
4243
- // return direction === 'ASC'
4244
- // ? aValue.getTime() - bValue.getTime()
4245
- // : bValue.getTime() - aValue.getTime()
4246
- // }
4247
- // const aString = String(aValue).toLowerCase()
4248
- // const bString = String(bValue).toLowerCase()
4249
- // return direction === 'ASC'
4250
- // ? aString.localeCompare(bString)
4251
- // : bString.localeCompare(aString)
4252
- // })
4253
- // }
4254
- function sortData(data, columnPath, direction) {
4255
- return [...data].sort((a, b) => {
4256
- const aValue = getNestedValue(a, columnPath);
4257
- const bValue = getNestedValue(b, columnPath);
4258
- if (typeof aValue === 'number' && typeof bValue === 'number') {
4259
- return direction === 'ASC' ? aValue - bValue : bValue - aValue;
4260
- }
4261
- if (aValue instanceof Date && bValue instanceof Date) {
4262
- return direction === 'ASC'
4263
- ? aValue.getTime() - bValue.getTime()
4264
- : bValue.getTime() - aValue.getTime();
4265
- }
4266
- const aString = String(aValue || '').toLowerCase();
4267
- const bString = String(bValue || '').toLowerCase();
4268
- return direction === 'ASC'
4269
- ? aString.localeCompare(bString)
4270
- : bString.localeCompare(aString);
4271
- });
4272
- }
4273
-
4274
- function parseDateRange(value) {
4275
- try {
4276
- const parsed = JSON.parse(value);
4277
- const start = parsed[0] ? new Date(parsed[0]) : null;
4278
- const end = parsed[1] ? new Date(parsed[1]) : null;
4279
- return [start, end];
4280
- }
4281
- catch {
4282
- return [null, null];
4283
- }
4284
- }
4285
- function Table({ columns, data, totalRecords, actions = [], isOrdered = true, actionsHeaderClassName = '', actionsColumnsClassName = '', rowsPerPage = 10, onPageChange, isPaginated = true, isLoading = false, onFilterChange, onSortChange, }) {
4286
- const [sortDirection, setSortDirection] = React.useState({});
4287
- const [sortedData, setSortedData] = React.useState(data);
4288
- const [currentPage, setCurrentPage] = React.useState(1);
4289
- const [filters, setFilters] = React.useState({});
4290
- const [openFilter, setOpenFilter] = React.useState(null);
4291
- const filterModalRef = React.useRef(null);
4292
- const [filterStatus, setFilterStatus] = React.useState({});
4293
- const handleSort = (dataIndex) => {
4294
- setSortDirection((prev) => {
4295
- const current = prev[dataIndex];
4296
- let nextDirection;
4297
- if (current === 'ASC')
4298
- nextDirection = 'DESC';
4299
- else if (current === 'DESC')
4300
- nextDirection = null;
4301
- else
4302
- nextDirection = 'ASC';
4303
- const newSortDirection = { [dataIndex]: nextDirection };
4304
- if (nextDirection === null) {
4305
- setSortedData(data);
4306
- }
4307
- else {
4308
- const sorted = sortData(data, dataIndex, nextDirection);
4309
- setSortedData(sorted);
4310
- }
4311
- if (onSortChange) {
4312
- onSortChange(dataIndex, nextDirection);
4313
- }
4314
- return newSortDirection;
4315
- });
4316
- };
4317
- React.useEffect(() => {
4318
- setSortedData(data);
4319
- }, [data]);
4320
- React.useEffect(() => {
4321
- const handleClickOutside = (event) => {
4322
- const target = event.target;
4323
- const isClickInsideFilter = filterModalRef.current && filterModalRef.current.contains(target);
4324
- const isClickInsideCalendar = (target instanceof HTMLElement && target.closest('.p-datepicker')) !==
4325
- null;
4326
- if (!isClickInsideFilter && !isClickInsideCalendar) {
4327
- setOpenFilter(null);
4328
- }
4329
- };
4330
- document.addEventListener('mousedown', handleClickOutside);
4331
- return () => {
4332
- document.removeEventListener('mousedown', handleClickOutside);
4333
- };
4334
- }, []);
4335
- const handleFilter = (column) => {
4336
- setOpenFilter(null);
4337
- if (onFilterChange) {
4338
- onFilterChange(filters);
4339
- }
4340
- setFilterStatus((prev) => ({
4341
- ...prev,
4342
- [column.dataIndex]: filters[column.dataIndex]
4343
- ? 'applied'
4344
- : 'default',
4345
- }));
4346
- };
4347
- const handleClearFilter = (column) => {
4348
- const dataIndex = column.dataIndex;
4349
- const newFilters = {
4350
- ...filters,
4351
- [dataIndex]: '',
4352
- };
4353
- setFilters(newFilters);
4354
- setFilterStatus((prev) => ({
4355
- ...prev,
4356
- [dataIndex]: 'default',
4357
- }));
4358
- setOpenFilter(null);
4359
- if (onFilterChange) {
4360
- onFilterChange(newFilters);
4361
- }
4362
- };
4363
- return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("table", { className: "w-100", children: [jsxRuntime.jsx("thead", { children: jsxRuntime.jsxs("tr", { className: "bg-gray-100", children: [columns.map((column) => (jsxRuntime.jsxs("th", { scope: "col", className: "bg-primary first:rounded-ss-lg font-bold text-background text-sm uppercase p-3 text-left", children: [jsxRuntime.jsx("div", { children: openFilter === column.dataIndex && (jsxRuntime.jsxs("div", { ref: filterModalRef, className: "absolute mt-6 bg-background border rounded-md shadow-md p-4 z-10 w-[276px] normal-case", children: [jsxRuntime.jsxs("div", { className: "space-y-4 text-primary", children: [jsxRuntime.jsxs("h1", { className: "text-primary text-sm", children: ["Filtrar por ", column?.label?.toLowerCase()] }), jsxRuntime.jsxs("div", { className: "w-full", children: [column.filterType === 'text' && (jsxRuntime.jsx(Input, { placeholder: "Digite para filtrar", value: filters[column.dataIndex] || '', onChange: (e) => setFilters((prev) => ({
4364
- ...prev,
4365
- [column.dataIndex]: e,
4366
- })), mask: column?.mask, "aria-label": `Filtrar por ${column.label}` })), column.filterType === 'select' && (jsxRuntime.jsx(Select, { options: column.filterOptions || [], value: column.filterOptions?.find((option) => option.value ===
4367
- filters[column.dataIndex]) || null, onChange: (selected) => setFilters((prev) => ({
4368
- ...prev,
4369
- [column.dataIndex]: selected?.value ?? null,
4370
- })), placeholder: "Selecione uma op\u00E7\u00E3o", label: "", "aria-label": `Filtrar por ${column.label}` })), column.filterType === 'multiSelect' && (jsxRuntime.jsx(MultiSelect, { options: column.filterOptions || [], value: (filters[column.dataIndex]
4371
- ? JSON.parse(filters[column.dataIndex])
4372
- : []), onChange: (selected) => setFilters((prev) => ({
4373
- ...prev,
4374
- [column.dataIndex]: selected
4375
- ? JSON.stringify(selected)
4376
- : '',
4377
- })), placeholder: "Selecione uma ou mais op\u00E7\u00F5es", label: "", "aria-label": `Filtrar por ${column.label}` })), column.filterType === 'singleDate' && (jsxRuntime.jsx(CalendarInput, { label: "", selectionMode: "single", placeholder: "Selecione uma data", value: filters[column.dataIndex]
4378
- ? new Date(filters[column.dataIndex])
4379
- : null, onChange: (e) => {
4380
- const value = e?.value;
4381
- setFilters((prev) => ({
4382
- ...prev,
4383
- [column.dataIndex]: value instanceof Date
4384
- ? value.toISOString()
4385
- : '',
4386
- }));
4387
- }, ariaLabel: `Filtrar por ${column.label}` })), column.filterType === 'rangeDate' && (jsxRuntime.jsx(CalendarInput, { label: "", selectionMode: "range", placeholder: "Selecione as datas", value: filters[column.dataIndex]
4388
- ? parseDateRange(filters[column.dataIndex])
4389
- : null, onChange: (e) => {
4390
- const range = e?.value;
4391
- setFilters((prev) => ({
4392
- ...prev,
4393
- [column.dataIndex]: range
4394
- ? JSON.stringify(range)
4395
- : '',
4396
- }));
4397
- }, ariaLabel: `Filtrar por ${column.label}` }))] })] }), jsxRuntime.jsxs("div", { className: "flex justify-between mt-4", children: [jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
4398
- setFilters((prev) => ({
4399
- ...prev,
4400
- [column.dataIndex]: '',
4401
- }));
4402
- setOpenFilter(null);
4403
- }, label: "Fechar", width: "10", size: "small", "aria-label": "Fechar filtro" }), jsxRuntime.jsx(Button, { variant: "secondary", onClick: () => handleClearFilter(column), label: "Limpar", width: "10", size: "small", "aria-label": "Limpar filtro" }), jsxRuntime.jsx(Button, { variant: "primary", onClick: () => handleFilter(column), label: "Aplicar", width: "10", size: "small", "aria-label": "Aplicar filtro" })] })] })) }), column.label, isOrdered && (jsxRuntime.jsx("button", { onClick: () => handleSort(column.dataIndex), "aria-label": `Ordenar por ${column.label}`, children: jsxRuntime.jsx("i", { className: clsx('pl-2 text-xs cursor-pointer pi', sortDirection[column.dataIndex] === 'ASC' &&
4404
- 'pi-sort-amount-up-alt', sortDirection[column.dataIndex] === 'DESC' &&
4405
- 'pi-sort-amount-down', !sortDirection[column.dataIndex] && 'pi-sort-alt') }) })), column.filterable && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("button", { onClick: () => setOpenFilter((prev) => prev === column.dataIndex
4406
- ? null
4407
- : column.dataIndex), "aria-label": `Filtrar por ${column.label}`, children: jsxRuntime.jsx("i", { className: clsx('pl-2 text-xs cursor-pointer', filterStatus[column.dataIndex] === 'applied'
4408
- ? 'pi pi-filter-slash'
4409
- : 'pi pi-filter') }) }) }))] }, String(column.dataIndex)))), actions.length > 0 && (jsxRuntime.jsx("th", { scope: "col", className: clsx('bg-primary rounded-se-lg font-bold text-background text-sm uppercase p-3 text-right pr-4', actionsHeaderClassName), children: "A\u00C7\u00D5ES" }))] }) }), jsxRuntime.jsx("tbody", { children: isLoading ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: columns.length + (actions.length > 0 ? 1 : 0), className: "p-6 text-center bg-gray-50", children: jsxRuntime.jsx("div", { className: "py-2 px-4 flex justify-center items-center gap-2", children: jsxRuntime.jsx(Spinner, { size: "lg" }) }) }) })) : sortedData.length > 0 ? (sortedData.map((row, index) => (jsxRuntime.jsxs("tr", { className: clsx(index % 2 === 0 ? 'bg-stoneBackground' : 'bg-background', 'text-primary text-base'), children: [columns.map((column) => {
4410
- const value = getNestedValue(row, column.dataIndex);
4411
- return (jsxRuntime.jsx("td", { className: clsx('p-3 text-sm text-left', typeof column.style === 'function'
4412
- ? column.style(getNestedValue(row, column.dataIndex), row)
4413
- : column.style), children: jsxRuntime.jsxs(Tooltip, { text: column?.tooltipText?.(value, row), children: [' ', column.render
4414
- ? column.render(value, row)
4415
- : String(value)] }) }, String(column.dataIndex)));
4416
- }), actions.length > 0 && (jsxRuntime.jsx("td", { className: clsx('text-sm text-right flex flex-row justify-end p-3 gap-2', actionsColumnsClassName), children: actions.map((action, idx) => (jsxRuntime.jsx("span", { className: clsx('cursor-pointer', action.disabled &&
4417
- 'opacity-50 pointer-events-none cursor-not-allowed'), onClick: () => {
4418
- if (!action.disabled)
4419
- action.onClick(row);
4420
- }, "aria-label": action?.ariaLabel || action.label, role: "button", children: jsxRuntime.jsx(Tooltip, { text: action?.label, children: action.icon }) }, idx))) }))] }, index)))) : (jsxRuntime.jsx("tr", { children: jsxRuntime.jsxs("td", { colSpan: columns.length + (actions.length > 0 ? 1 : 0), className: "p-6 text-center text-primary bg-stoneBackground", children: [jsxRuntime.jsx("i", { className: "pi pi-database mr-2" }), " N\u00E3o h\u00E1 dados dispon\u00EDveis."] }) })) })] }), sortedData.length > 0 && isPaginated && (jsxRuntime.jsx(Paginator, { first: (currentPage - 1) * rowsPerPage, rows: rowsPerPage, totalRecords: totalRecords, onPageChange: (event) => {
4421
- setCurrentPage(event.page + 1);
4422
- onPageChange(event.page + 1);
4423
- } }))] }));
4424
- }
4425
-
4426
- function Tabs({ tabs, activeIndex = 0, onTabChange, className, }) {
4427
- const [internalIndex, setInternalIndex] = React.useState(activeIndex);
4428
- const currentIndex = onTabChange ? activeIndex : internalIndex;
4429
- const setIndex = (index) => {
4430
- if (tabs[index].disabled)
4431
- return;
4432
- if (onTabChange) {
4433
- onTabChange(index);
4434
- }
4435
- else {
4436
- setInternalIndex(index);
4437
- }
4438
- };
4439
- return (jsxRuntime.jsxs("div", { className: clsx('w-full', className), children: [jsxRuntime.jsx("div", { className: "flex border-b border-gray-300", children: tabs.map((tab, index) => {
4440
- const isActive = index === currentIndex;
4441
- return (jsxRuntime.jsx("button", { type: "button", onClick: () => setIndex(index), disabled: tab.disabled, className: clsx('px-4 py-2 -mb-[1px] border-b-2 text-md transition-all duration-200 hover:bg-stoneBackground cursor-pointer text-base text-primary', tab.disabled ? 'disabled:text-stoneDark' : '', isActive
4442
- ? 'border-primary font-semibold'
4443
- : 'border-transparent hover:text-primary hover:border-grayDark font-normal', !isActive && !tab.disabled && 'hover:font-semibold'), children: tab.label }, index));
4444
- }) }), jsxRuntime.jsx("div", { className: "py-1 px-3", children: tabs.map((tab, index) => (jsxRuntime.jsx("div", { className: clsx(index !== currentIndex && 'hidden'), children: tab.content }, index))) })] }));
4445
- }
4446
-
4447
- const colorMap = {
4448
- blue: 'bg-[#DBEAFE] text-[#1E40AF] border-[#BFDBFE]',
4449
- red: 'bg-[#FEE2E2] text-[#991B1B] border-[#FCA5A5]',
4450
- green: 'bg-[#D1FAE5] text-[#065F46] border-[#6EE7B7]',
4451
- gray: 'bg-[#F3F4F6] text-[#374151] border-[#D1D5DB]',
4452
- purple: 'bg-[#EDE9FE] text-[#6B21A8] border-[#C4B5FD]',
4453
- yellow: 'bg-[#FEF9C3] text-[#92400E] border-[#FCD34D]',
4454
- orange: 'bg-[#FFEDD5] text-[#9A3412] border-[#FDBA74]',
4455
- pink: 'bg-[#FCE7F3] text-[#9D174D] border-[#F9A8D4]',
4456
- emerald: 'bg-[#D1FAE5] text-[#065F46] border-[#6EE7B7]',
4457
- teal: 'bg-[#CCFBF1] text-[#134E4A] border-[#5EEAD4]',
4458
- cyan: 'bg-[#CFFAFE] text-[#155E75] border-[#67E8F9]',
4459
- sky: 'bg-[#E0F2FE] text-[#0369A1] border-[#7DD3FC]',
4460
- indigo: 'bg-[#E0E7FF] text-[#3730A3] border-[#A5B4FC]',
4461
- violet: 'bg-[#EDE9FE] text-[#6D28D9] border-[#C4B5FD]',
4462
- fuchsia: 'bg-[#FAE8FF] text-[#A21CAF] border-[#F0ABFC]',
4463
- rose: 'bg-[#FFE4E6] text-[#BE123C] border-[#FDA4AF]',
4464
- stone: 'bg-[#E7E5E4] text-[#44403C] border-[#D6D3D1]',
4465
- amber: 'bg-[#FEF3C7] text-[#92400E] border-[#FCD34D]',
4466
- lime: 'bg-[#ECFCCB] text-[#365314] border-[#BEF264]',
4467
- slate: 'bg-[#F1F5F9] text-[#334155] border-[#CBD5E1]',
4468
- zinc: 'bg-[#F4F4F5] text-[#3F3F46] border-[#D4D4D8]',
4469
- neutral: 'bg-[#F5F5F5] text-[#404040] border-[#D4D4D4]',
4470
- };
4471
- function TagStatus({ value, color = 'gray' }) {
4472
- const colorClass = colorMap[color];
4473
- return (jsxRuntime.jsx("span", { className: `text-sm px-2 py-1 rounded-xl font-medium border ${colorClass}`, children: value }));
4474
- }
4475
-
4476
- function ErrorIcon() {
4477
- return (jsxRuntime.jsxs("svg", { width: "27", height: "27", viewBox: "0 0 27 27", fill: "none", className: "min-w-7", children: [jsxRuntime.jsx("circle", { cx: "13.5", cy: "13.5", r: "12.5", stroke: "#B71C1C", strokeWidth: "2" }), jsxRuntime.jsx("path", { d: "M8 8L19 19", stroke: "#B71C1C", strokeWidth: "2", strokeLinecap: "round" }), jsxRuntime.jsx("path", { d: "M19 8L8 19", stroke: "#B71C1C", strokeWidth: "2", strokeLinecap: "round" })] }));
4478
- }
4479
-
4480
- function InfoIcon() {
4481
- return (jsxRuntime.jsxs("svg", { width: "27", height: "27", viewBox: "0 0 27 27", fill: "none", children: [jsxRuntime.jsx("circle", { cx: "13.5", cy: "13.5", r: "12.5", stroke: "#0045ba", strokeWidth: "2" }), jsxRuntime.jsx("path", { d: "M14.6294 8L14.3877 15.4048H12.6299L12.3809 8H14.6294ZM12.3223 17.6973C12.3223 17.3848 12.4297 17.126 12.6445 16.9209C12.8643 16.7109 13.1523 16.606 13.5088 16.606C13.8701 16.606 14.1582 16.7109 14.373 16.9209C14.5879 17.126 14.6953 17.3848 14.6953 17.6973C14.6953 18 14.5879 18.2563 14.373 18.4663C14.1582 18.6763 13.8701 18.7812 13.5088 18.7812C13.1523 18.7812 12.8643 18.6763 12.6445 18.4663C12.4297 18.2563 12.3223 18 12.3223 17.6973Z", fill: "#0045ba" })] }));
4482
- }
4483
-
4484
- function SuccessIcon() {
4485
- return (jsxRuntime.jsxs("svg", { width: "27", height: "27", viewBox: "0 0 27 27", fill: "none", className: "min-w-7", children: [jsxRuntime.jsx("circle", { cx: "13.5", cy: "13.5", r: "12.5", stroke: '#1B5E20', strokeWidth: "2" }), jsxRuntime.jsx("path", { d: "M7 12.5L12 17.5L19.5 10", stroke: '#1B5E20', strokeWidth: "2", strokeLinecap: "round" })] }));
4486
- }
4487
-
4488
- function Toast({ messages }) {
4489
- return (jsxRuntime.jsx("div", { className: "fixed top-5 right-5 flex flex-col gap-2 z-[999]", children: messages.map(({ id, severity, summary, detail }) => (jsxRuntime.jsxs("div", { className: clsx('p-2 rounded flex items-center gap-2 transition-opacity bg-white border border-l-4 rounded-r-lg shadow-[0_4px_12px_rgba(0,0,0,0.50)]', severity === 'success'
4490
- ? 'bg-[#E6F4EA] border-[#2E7D32] text-[#1B5E20]'
4491
- : '', severity === 'info'
4492
- ? 'bg-[#E3F2FD] border-[#1565C0] text-[#0D47A1]'
4493
- : '', severity === 'error'
4494
- ? 'bg-[#FFEBEE] border-[#C62828] text-[#B71C1C]'
4495
- : ''), "aria-label": "toast", children: [severity === 'success' && jsxRuntime.jsx(SuccessIcon, {}), severity === 'info' && jsxRuntime.jsx(InfoIcon, {}), severity === 'error' && jsxRuntime.jsx(ErrorIcon, {}), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: summary }), jsxRuntime.jsx("p", { children: detail })] })] }, id))) }));
4496
- }
4497
-
4498
- exports.Accordion = Accordion;
4499
- exports.AutoComplete = AutoComplete;
4500
- exports.BasicHeader = BasicHeader;
4501
- exports.Breadcrumb = Breadcrumb;
4502
- exports.Button = Button;
4503
- exports.CalendarInput = CalendarInput;
4504
- exports.Card = Card;
4505
- exports.CardButton = CardButton;
4506
- exports.CardIconsButton = CardIconsButton;
4507
- exports.Chart = Chart;
4508
- exports.Dialog = Dialog;
4509
- exports.Divider = Divider;
4510
- exports.EmptyContent = EmptyContent;
4511
- exports.ExpandablePanel = ExpandablePanel;
4512
- exports.FileUpload = FileUpload;
4513
- exports.FilterButton = FilterButton;
4514
- exports.Header = Header;
4515
- exports.IconButton = IconButton;
4516
- exports.InfoCard = InfoCard;
4517
- exports.Input = Input;
4518
- exports.InputSwitch = InputSwitch;
4519
- exports.InputTextArea = InputTextArea;
4520
- exports.InternalMenu = InternalMenu;
4521
- exports.Link = Link;
4522
- exports.MegaMenu = MegaMenu;
4523
- exports.Modal = Modal;
4524
- exports.MultiSelect = MultiSelect;
4525
- exports.Notification = Notification;
4526
- exports.Paginator = Paginator;
4527
- exports.RadioButton = RadioButton;
4528
- exports.Select = Select;
4529
- exports.Sidebar = Sidebar;
4530
- exports.Skeleton = Skeleton;
4531
- exports.Spinner = Spinner;
4532
- exports.Table = Table;
4533
- exports.Tabs = Tabs;
4534
- exports.TagStatus = TagStatus;
4535
- exports.Toast = Toast;
4536
- exports.Tooltip = Tooltip;
4537
- //# sourceMappingURL=index.cjs.js.map