react-native-month-day-picker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +269 -0
- package/lib/commonjs/BirthdayPicker.js +177 -0
- package/lib/commonjs/BirthdayPicker.js.map +1 -0
- package/lib/commonjs/BirthdayPickerModal.js +176 -0
- package/lib/commonjs/BirthdayPickerModal.js.map +1 -0
- package/lib/commonjs/constants.js +80 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/hooks/useBirthdayPicker.js +90 -0
- package/lib/commonjs/hooks/useBirthdayPicker.js.map +1 -0
- package/lib/commonjs/index.js +89 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/dateUtils.js +103 -0
- package/lib/commonjs/utils/dateUtils.js.map +1 -0
- package/lib/commonjs/utils/localeUtils.js +90 -0
- package/lib/commonjs/utils/localeUtils.js.map +1 -0
- package/lib/module/BirthdayPicker.js +169 -0
- package/lib/module/BirthdayPicker.js.map +1 -0
- package/lib/module/BirthdayPickerModal.js +169 -0
- package/lib/module/BirthdayPickerModal.js.map +1 -0
- package/lib/module/constants.js +74 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/hooks/useBirthdayPicker.js +84 -0
- package/lib/module/hooks/useBirthdayPicker.js.map +1 -0
- package/lib/module/index.js +16 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/dateUtils.js +92 -0
- package/lib/module/utils/dateUtils.js.map +1 -0
- package/lib/module/utils/localeUtils.js +81 -0
- package/lib/module/utils/localeUtils.js.map +1 -0
- package/lib/typescript/BirthdayPicker.d.ts +25 -0
- package/lib/typescript/BirthdayPicker.d.ts.map +1 -0
- package/lib/typescript/BirthdayPickerModal.d.ts +24 -0
- package/lib/typescript/BirthdayPickerModal.d.ts.map +1 -0
- package/lib/typescript/constants.d.ts +39 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/hooks/useBirthdayPicker.d.ts +17 -0
- package/lib/typescript/hooks/useBirthdayPicker.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +160 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils/dateUtils.d.ts +43 -0
- package/lib/typescript/utils/dateUtils.d.ts.map +1 -0
- package/lib/typescript/utils/localeUtils.d.ts +28 -0
- package/lib/typescript/utils/localeUtils.d.ts.map +1 -0
- package/package.json +137 -0
- package/src/BirthdayPicker.tsx +210 -0
- package/src/BirthdayPickerModal.tsx +192 -0
- package/src/constants.ts +64 -0
- package/src/hooks/useBirthdayPicker.ts +106 -0
- package/src/index.ts +31 -0
- package/src/types.ts +189 -0
- package/src/utils/dateUtils.ts +101 -0
- package/src/utils/localeUtils.ts +99 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MONTHS_IN_YEAR = exports.LEAP_DAY = exports.FEBRUARY = exports.DEFAULT_VISIBLE_ITEMS = exports.DEFAULT_MONTH_FORMAT = exports.DEFAULT_LOCALE = exports.DEFAULT_ITEM_HEIGHT = exports.DEFAULT_BIRTHDAY_VALUE = exports.DAYS_IN_MONTH = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Default birthday value (January 1st)
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_BIRTHDAY_VALUE = exports.DEFAULT_BIRTHDAY_VALUE = {
|
|
11
|
+
month: 1,
|
|
12
|
+
day: 1
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Default locale for month formatting
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_LOCALE = exports.DEFAULT_LOCALE = 'en-US';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Default month format
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_MONTH_FORMAT = exports.DEFAULT_MONTH_FORMAT = 'long';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Default item height in pixels
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_ITEM_HEIGHT = exports.DEFAULT_ITEM_HEIGHT = 40;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default number of visible items
|
|
32
|
+
*/
|
|
33
|
+
const DEFAULT_VISIBLE_ITEMS = exports.DEFAULT_VISIBLE_ITEMS = 5;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Days in each month (1-indexed, index 0 is unused)
|
|
37
|
+
* February is set to 28, leap day handling is separate
|
|
38
|
+
*/
|
|
39
|
+
const DAYS_IN_MONTH = exports.DAYS_IN_MONTH = [0,
|
|
40
|
+
// Index 0 unused
|
|
41
|
+
31,
|
|
42
|
+
// January
|
|
43
|
+
28,
|
|
44
|
+
// February (leap day handled separately)
|
|
45
|
+
31,
|
|
46
|
+
// March
|
|
47
|
+
30,
|
|
48
|
+
// April
|
|
49
|
+
31,
|
|
50
|
+
// May
|
|
51
|
+
30,
|
|
52
|
+
// June
|
|
53
|
+
31,
|
|
54
|
+
// July
|
|
55
|
+
31,
|
|
56
|
+
// August
|
|
57
|
+
30,
|
|
58
|
+
// September
|
|
59
|
+
31,
|
|
60
|
+
// October
|
|
61
|
+
30,
|
|
62
|
+
// November
|
|
63
|
+
31 // December
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Number of months in a year
|
|
68
|
+
*/
|
|
69
|
+
const MONTHS_IN_YEAR = exports.MONTHS_IN_YEAR = 12;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* February month number
|
|
73
|
+
*/
|
|
74
|
+
const FEBRUARY = exports.FEBRUARY = 2;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Leap day (Feb 29)
|
|
78
|
+
*/
|
|
79
|
+
const LEAP_DAY = exports.LEAP_DAY = 29;
|
|
80
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_BIRTHDAY_VALUE","exports","month","day","DEFAULT_LOCALE","DEFAULT_MONTH_FORMAT","DEFAULT_ITEM_HEIGHT","DEFAULT_VISIBLE_ITEMS","DAYS_IN_MONTH","MONTHS_IN_YEAR","FEBRUARY","LEAP_DAY"],"sourceRoot":"../../src","sources":["constants.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,MAAMA,sBAAqC,GAAAC,OAAA,CAAAD,sBAAA,GAAG;EACnDE,KAAK,EAAE,CAAC;EACRC,GAAG,EAAE;AACP,CAAC;;AAED;AACA;AACA;AACO,MAAMC,cAAc,GAAAH,OAAA,CAAAG,cAAA,GAAG,OAAO;;AAErC;AACA;AACA;AACO,MAAMC,oBAAiC,GAAAJ,OAAA,CAAAI,oBAAA,GAAG,MAAM;;AAEvD;AACA;AACA;AACO,MAAMC,mBAAmB,GAAAL,OAAA,CAAAK,mBAAA,GAAG,EAAE;;AAErC;AACA;AACA;AACO,MAAMC,qBAAqB,GAAAN,OAAA,CAAAM,qBAAA,GAAG,CAAC;;AAEtC;AACA;AACA;AACA;AACO,MAAMC,aAAgC,GAAAP,OAAA,CAAAO,aAAA,GAAG,CAC9C,CAAC;AAAE;AACH,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE;AAAE;AACJ,EAAE,CAAE;AAAA,CACL;;AAED;AACA;AACA;AACO,MAAMC,cAAc,GAAAR,OAAA,CAAAQ,cAAA,GAAG,EAAE;;AAEhC;AACA;AACA;AACO,MAAMC,QAAQ,GAAAT,OAAA,CAAAS,QAAA,GAAG,CAAC;;AAEzB;AACA;AACA;AACO,MAAMC,QAAQ,GAAAV,OAAA,CAAAU,QAAA,GAAG,EAAE","ignoreList":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.useBirthdayPicker = useBirthdayPicker;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
var _dateUtils = require("../utils/dateUtils");
|
|
11
|
+
/**
|
|
12
|
+
* Hook for managing birthday picker state
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration options
|
|
15
|
+
* @returns State and handlers for birthday picker
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const { value, setMonth, setDay, daysInMonth } = useBirthdayPicker({
|
|
20
|
+
* initialValue: { month: 6, day: 15 },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function useBirthdayPicker(options = {}) {
|
|
25
|
+
const {
|
|
26
|
+
initialValue = _constants.DEFAULT_BIRTHDAY_VALUE,
|
|
27
|
+
allowLeapDay = true
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
// Normalize the initial value
|
|
31
|
+
const normalizedInitial = (0, _react.useMemo)(() => (0, _dateUtils.normalizeBirthday)(initialValue, allowLeapDay),
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
[] // Only compute once on mount
|
|
34
|
+
);
|
|
35
|
+
const [value, setValueInternal] = (0, _react.useState)(normalizedInitial);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Set the month, clamping the day if necessary
|
|
39
|
+
*/
|
|
40
|
+
const setMonth = (0, _react.useCallback)(month => {
|
|
41
|
+
setValueInternal(prev => {
|
|
42
|
+
const clampedMonth = Math.max(1, Math.min(month, 12));
|
|
43
|
+
const clampedDay = (0, _dateUtils.clampDay)(prev.day, clampedMonth, allowLeapDay);
|
|
44
|
+
return {
|
|
45
|
+
month: clampedMonth,
|
|
46
|
+
day: clampedDay
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}, [allowLeapDay]);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Set the day, clamping to valid range for current month
|
|
53
|
+
*/
|
|
54
|
+
const setDay = (0, _react.useCallback)(day => {
|
|
55
|
+
setValueInternal(prev => {
|
|
56
|
+
const clampedDay = (0, _dateUtils.clampDay)(day, prev.month, allowLeapDay);
|
|
57
|
+
return {
|
|
58
|
+
...prev,
|
|
59
|
+
day: clampedDay
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}, [allowLeapDay]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Set the entire value, normalizing both month and day
|
|
66
|
+
*/
|
|
67
|
+
const setValue = (0, _react.useCallback)(newValue => {
|
|
68
|
+
setValueInternal((0, _dateUtils.normalizeBirthday)(newValue, allowLeapDay));
|
|
69
|
+
}, [allowLeapDay]);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Number of days in the currently selected month
|
|
73
|
+
*/
|
|
74
|
+
const daysInMonth = (0, _react.useMemo)(() => (0, _dateUtils.getDaysInMonth)(value.month, allowLeapDay), [value.month, allowLeapDay]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether the current value is valid
|
|
78
|
+
*/
|
|
79
|
+
const isValid = (0, _react.useMemo)(() => (0, _dateUtils.isValidBirthday)(value, allowLeapDay), [value, allowLeapDay]);
|
|
80
|
+
return {
|
|
81
|
+
value,
|
|
82
|
+
setMonth,
|
|
83
|
+
setDay,
|
|
84
|
+
setValue,
|
|
85
|
+
daysInMonth,
|
|
86
|
+
isValid
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var _default = exports.default = useBirthdayPicker;
|
|
90
|
+
//# sourceMappingURL=useBirthdayPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_constants","_dateUtils","useBirthdayPicker","options","initialValue","DEFAULT_BIRTHDAY_VALUE","allowLeapDay","normalizedInitial","useMemo","normalizeBirthday","value","setValueInternal","useState","setMonth","useCallback","month","prev","clampedMonth","Math","max","min","clampedDay","clampDay","day","setDay","setValue","newValue","daysInMonth","getDaysInMonth","isValid","isValidBirthday","_default","exports","default"],"sourceRoot":"../../../src","sources":["hooks/useBirthdayPicker.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,iBAAiBA,CAC/BC,OAAiC,GAAG,CAAC,CAAC,EACb;EACzB,MAAM;IAAEC,YAAY,GAAGC,iCAAsB;IAAEC,YAAY,GAAG;EAAK,CAAC,GAClEH,OAAO;;EAET;EACA,MAAMI,iBAAiB,GAAG,IAAAC,cAAO,EAC/B,MAAM,IAAAC,4BAAiB,EAACL,YAAY,EAAEE,YAAY,CAAC;EACnD;EACA,EAAE,CAAC;EACL,CAAC;EAED,MAAM,CAACI,KAAK,EAAEC,gBAAgB,CAAC,GAAG,IAAAC,eAAQ,EAAgBL,iBAAiB,CAAC;;EAE5E;AACF;AACA;EACE,MAAMM,QAAQ,GAAG,IAAAC,kBAAW,EACzBC,KAAa,IAAK;IACjBJ,gBAAgB,CAAEK,IAAI,IAAK;MACzB,MAAMC,YAAY,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAACL,KAAK,EAAE,EAAE,CAAC,CAAC;MACrD,MAAMM,UAAU,GAAG,IAAAC,mBAAQ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@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BirthdayPicker", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _BirthdayPicker.BirthdayPicker;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "BirthdayPickerModal", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _BirthdayPickerModal.BirthdayPickerModal;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "clampDay", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _dateUtils.clampDay;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "default", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _BirthdayPicker.BirthdayPicker;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "formatDay", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _localeUtils.formatDay;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "formatMonth", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _localeUtils.formatMonth;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "getDaysArray", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _dateUtils.getDaysArray;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "getDaysInMonth", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _dateUtils.getDaysInMonth;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "getMonthNames", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _localeUtils.getMonthNames;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "getMonthsArray", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _dateUtils.getMonthsArray;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "isValidBirthday", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _dateUtils.isValidBirthday;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "normalizeBirthday", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _dateUtils.normalizeBirthday;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "useBirthdayPicker", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _useBirthdayPicker.useBirthdayPicker;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
var _BirthdayPicker = require("./BirthdayPicker");
|
|
85
|
+
var _BirthdayPickerModal = require("./BirthdayPickerModal");
|
|
86
|
+
var _useBirthdayPicker = require("./hooks/useBirthdayPicker");
|
|
87
|
+
var _dateUtils = require("./utils/dateUtils");
|
|
88
|
+
var _localeUtils = require("./utils/localeUtils");
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_BirthdayPicker","require","_BirthdayPickerModal","_useBirthdayPicker","_dateUtils","_localeUtils"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAGA,IAAAE,kBAAA,GAAAF,OAAA;AAaA,IAAAG,UAAA,GAAAH,OAAA;AASA,IAAAI,YAAA,GAAAJ,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clampDay = clampDay;
|
|
7
|
+
exports.getDaysArray = getDaysArray;
|
|
8
|
+
exports.getDaysInMonth = getDaysInMonth;
|
|
9
|
+
exports.getMonthsArray = getMonthsArray;
|
|
10
|
+
exports.isValidBirthday = isValidBirthday;
|
|
11
|
+
exports.normalizeBirthday = normalizeBirthday;
|
|
12
|
+
var _constants = require("../constants");
|
|
13
|
+
/**
|
|
14
|
+
* Get the number of days in a given month
|
|
15
|
+
* @param month - Month (1-12)
|
|
16
|
+
* @param allowLeapDay - Whether to allow Feb 29
|
|
17
|
+
* @returns Number of days in the month
|
|
18
|
+
*/
|
|
19
|
+
function getDaysInMonth(month, allowLeapDay = true) {
|
|
20
|
+
if (month < 1 || month > _constants.MONTHS_IN_YEAR) {
|
|
21
|
+
throw new Error(`Invalid month: ${month}. Must be between 1 and 12.`);
|
|
22
|
+
}
|
|
23
|
+
if (month === _constants.FEBRUARY && allowLeapDay) {
|
|
24
|
+
return _constants.LEAP_DAY;
|
|
25
|
+
}
|
|
26
|
+
return _constants.DAYS_IN_MONTH[month];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Clamp a day value to be valid for a given month
|
|
31
|
+
* @param day - Day to clamp
|
|
32
|
+
* @param month - Month (1-12)
|
|
33
|
+
* @param allowLeapDay - Whether to allow Feb 29
|
|
34
|
+
* @returns Clamped day value
|
|
35
|
+
*/
|
|
36
|
+
function clampDay(day, month, allowLeapDay = true) {
|
|
37
|
+
const maxDays = getDaysInMonth(month, allowLeapDay);
|
|
38
|
+
return Math.max(1, Math.min(day, maxDays));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a birthday value is valid
|
|
43
|
+
* @param value - Birthday value to validate
|
|
44
|
+
* @param allowLeapDay - Whether to allow Feb 29
|
|
45
|
+
* @returns Whether the value is valid
|
|
46
|
+
*/
|
|
47
|
+
function isValidBirthday(value, allowLeapDay = true) {
|
|
48
|
+
const {
|
|
49
|
+
month,
|
|
50
|
+
day
|
|
51
|
+
} = value;
|
|
52
|
+
|
|
53
|
+
// Check month range
|
|
54
|
+
if (month < 1 || month > _constants.MONTHS_IN_YEAR) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Check day range
|
|
59
|
+
const maxDays = getDaysInMonth(month, allowLeapDay);
|
|
60
|
+
if (day < 1 || day > maxDays) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Generate an array of day numbers for a given month
|
|
68
|
+
* @param month - Month (1-12)
|
|
69
|
+
* @param allowLeapDay - Whether to allow Feb 29
|
|
70
|
+
* @returns Array of day numbers [1, 2, 3, ..., n]
|
|
71
|
+
*/
|
|
72
|
+
function getDaysArray(month, allowLeapDay = true) {
|
|
73
|
+
const maxDays = getDaysInMonth(month, allowLeapDay);
|
|
74
|
+
return Array.from({
|
|
75
|
+
length: maxDays
|
|
76
|
+
}, (_, i) => i + 1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate an array of month numbers
|
|
81
|
+
* @returns Array of month numbers [1, 2, 3, ..., 12]
|
|
82
|
+
*/
|
|
83
|
+
function getMonthsArray() {
|
|
84
|
+
return Array.from({
|
|
85
|
+
length: _constants.MONTHS_IN_YEAR
|
|
86
|
+
}, (_, i) => i + 1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Normalize a birthday value to ensure it's valid
|
|
91
|
+
* @param value - Birthday value to normalize
|
|
92
|
+
* @param allowLeapDay - Whether to allow Feb 29
|
|
93
|
+
* @returns Normalized birthday value
|
|
94
|
+
*/
|
|
95
|
+
function normalizeBirthday(value, allowLeapDay = true) {
|
|
96
|
+
const month = Math.max(1, Math.min(value.month, _constants.MONTHS_IN_YEAR));
|
|
97
|
+
const day = clampDay(value.day, month, allowLeapDay);
|
|
98
|
+
return {
|
|
99
|
+
month,
|
|
100
|
+
day
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=dateUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_constants","require","getDaysInMonth","month","allowLeapDay","MONTHS_IN_YEAR","Error","FEBRUARY","LEAP_DAY","DAYS_IN_MONTH","clampDay","day","maxDays","Math","max","min","isValidBirthday","value","getDaysArray","Array","from","length","_","i","getMonthsArray","normalizeBirthday"],"sourceRoot":"../../../src","sources":["utils/dateUtils.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAQA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAACC,KAAa,EAAEC,YAAY,GAAG,IAAI,EAAU;EACzE,IAAID,KAAK,GAAG,CAAC,IAAIA,KAAK,GAAGE,yBAAc,EAAE;IACvC,MAAM,IAAIC,KAAK,CAAC,kBAAkBH,KAAK,6BAA6B,CAAC;EACvE;EAEA,IAAIA,KAAK,KAAKI,mBAAQ,IAAIH,YAAY,EAAE;IACtC,OAAOI,mBAAQ;EACjB;EAEA,OAAOC,wBAAa,CAACN,KAAK,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,QAAQA,CACtBC,GAAW,EACXR,KA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D,KAAK,GAAGU,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,GAAG,CAACE,KAAK,CAACd,KAAK,EAAEE,yBAAc,CAAC,CAAC;EAChE,MAAMM,GAAG,GAAGD,QAAQ,CAACO,KAAK,CAACN,GAAG,EAAER,KAAK,EAAEC,YAAY,CAAC;EACpD,OAAO;IAAED,KAAK;IAAEQ;EAAI,CAAC;AACvB","ignoreList":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearMonthNamesCache = clearMonthNamesCache;
|
|
7
|
+
exports.formatDay = formatDay;
|
|
8
|
+
exports.formatMonth = formatMonth;
|
|
9
|
+
exports.getMonthNames = getMonthNames;
|
|
10
|
+
var _constants = require("../constants");
|
|
11
|
+
/**
|
|
12
|
+
* Cache for month names to avoid repeated Intl.DateTimeFormat calls
|
|
13
|
+
*/
|
|
14
|
+
const monthNamesCache = new Map();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generate a cache key for month names
|
|
18
|
+
*/
|
|
19
|
+
function getCacheKey(locale, format) {
|
|
20
|
+
return `${locale}-${format}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get month names for a given locale and format
|
|
25
|
+
* @param locale - BCP 47 locale string (e.g., 'en-US', 'ja-JP')
|
|
26
|
+
* @param format - Format for month names ('long', 'short', 'numeric')
|
|
27
|
+
* @returns Array of month names/numbers (1-indexed, index 0 is empty string)
|
|
28
|
+
*/
|
|
29
|
+
function getMonthNames(locale = _constants.DEFAULT_LOCALE, format = _constants.DEFAULT_MONTH_FORMAT) {
|
|
30
|
+
const cacheKey = getCacheKey(locale, format);
|
|
31
|
+
|
|
32
|
+
// Return cached result if available
|
|
33
|
+
if (monthNamesCache.has(cacheKey)) {
|
|
34
|
+
return monthNamesCache.get(cacheKey);
|
|
35
|
+
}
|
|
36
|
+
const names = [''];
|
|
37
|
+
if (format === 'numeric') {
|
|
38
|
+
// For numeric format, just use month numbers
|
|
39
|
+
for (let i = 1; i <= _constants.MONTHS_IN_YEAR; i++) {
|
|
40
|
+
names.push(String(i));
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
// Use Intl.DateTimeFormat for localized month names
|
|
44
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
45
|
+
month: format
|
|
46
|
+
});
|
|
47
|
+
for (let i = 0; i < _constants.MONTHS_IN_YEAR; i++) {
|
|
48
|
+
// Create a date in month i (0-indexed for Date constructor)
|
|
49
|
+
const date = new Date(2024, i, 1);
|
|
50
|
+
names.push(formatter.format(date));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Cache the result
|
|
55
|
+
monthNamesCache.set(cacheKey, names);
|
|
56
|
+
return names;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Format a single month number to a localized string
|
|
61
|
+
* @param month - Month number (1-12)
|
|
62
|
+
* @param locale - BCP 47 locale string
|
|
63
|
+
* @param format - Format for month name
|
|
64
|
+
* @returns Formatted month name
|
|
65
|
+
*/
|
|
66
|
+
function formatMonth(month, locale = _constants.DEFAULT_LOCALE, format = _constants.DEFAULT_MONTH_FORMAT) {
|
|
67
|
+
if (month < 1 || month > _constants.MONTHS_IN_YEAR) {
|
|
68
|
+
throw new Error(`Invalid month: ${month}. Must be between 1 and 12.`);
|
|
69
|
+
}
|
|
70
|
+
const names = getMonthNames(locale, format);
|
|
71
|
+
return names[month];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Format a day number with optional locale-specific formatting
|
|
76
|
+
* @param day - Day number (1-31)
|
|
77
|
+
* @param locale - BCP 47 locale string (currently unused, for future i18n)
|
|
78
|
+
* @returns Formatted day string
|
|
79
|
+
*/
|
|
80
|
+
function formatDay(day, locale = _constants.DEFAULT_LOCALE) {
|
|
81
|
+
return new Intl.NumberFormat(locale).format(day);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Clear the month names cache (useful for testing)
|
|
86
|
+
*/
|
|
87
|
+
function clearMonthNamesCache() {
|
|
88
|
+
monthNamesCache.clear();
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=localeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_constants","require","monthNamesCache","Map","getCacheKey","locale","format","getMonthNames","DEFAULT_LOCALE","DEFAULT_MONTH_FORMAT","cacheKey","has","get","names","i","MONTHS_IN_YEAR","push","String","formatter","Intl","DateTimeFormat","month","date","Date","set","formatMonth","Error","formatDay","day","NumberFormat","clearMonthNamesCache","clear"],"sourceRoot":"../../../src","sources":["utils/localeUtils.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAOA;AACA;AACA;AACA,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA,SAASC,WAAWA,CAACC,MAAc,EAAEC,MAAmB,EAAU;EAChE,OAAO,GAAGD,MAAM,IAAIC,MAAM,EAAE;AAC9B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAC3BF,MAAc,GAAGG,yBAAc,EAC/BF,MAAmB,GAAGG,+BAAoB,EAChC;EACV,MAAMC,QAAQ,GAAGN,WAAW,CAACC,MAAM,EAAEC,MAAM,CAAC;;EAE5C;EACA,IAAIJ,eAAe,CAACS,GAAG,CAACD,QAAQ,CAAC,EAAE;IACjC,OAAOR,eAAe,CAACU,GAAG,CAACF,QAAQ,CAAC;EACtC;EAEA,MAAMG,KAAe,GAAG,CAAC,EAAE,CAAC;EAE5B,IAAIP,MAAM,KAAK,SAAS,EAAE;IACxB;IACA,KAAK,IAAIQ,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIC,yBAAc,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B","ignoreList":[]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import WheelPicker from '@quidone/react-native-wheel-picker';
|
|
4
|
+
import { DEFAULT_BIRTHDAY_VALUE, DEFAULT_LOCALE, DEFAULT_MONTH_FORMAT, DEFAULT_ITEM_HEIGHT, DEFAULT_VISIBLE_ITEMS } from './constants';
|
|
5
|
+
import { getDaysArray, getMonthsArray, clampDay, getDaysInMonth } from './utils/dateUtils';
|
|
6
|
+
import { getMonthNames, formatDay } from './utils/localeUtils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Item type for wheel picker
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A birthday picker component that allows selecting month and day.
|
|
14
|
+
* Does not include year for privacy-friendly birthday selection.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* // Uncontrolled mode
|
|
19
|
+
* <BirthdayPicker
|
|
20
|
+
* defaultValue={{ month: 6, day: 15 }}
|
|
21
|
+
* onChange={(value) => console.log(value)}
|
|
22
|
+
* />
|
|
23
|
+
*
|
|
24
|
+
* // Controlled mode
|
|
25
|
+
* const [birthday, setBirthday] = useState({ month: 1, day: 1 });
|
|
26
|
+
* <BirthdayPicker
|
|
27
|
+
* value={birthday}
|
|
28
|
+
* onChange={setBirthday}
|
|
29
|
+
* />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function BirthdayPicker({
|
|
33
|
+
value: controlledValue,
|
|
34
|
+
defaultValue = DEFAULT_BIRTHDAY_VALUE,
|
|
35
|
+
onChange,
|
|
36
|
+
locale = DEFAULT_LOCALE,
|
|
37
|
+
monthFormat = DEFAULT_MONTH_FORMAT,
|
|
38
|
+
allowLeapDay = true,
|
|
39
|
+
disabled = false,
|
|
40
|
+
testID,
|
|
41
|
+
style,
|
|
42
|
+
itemHeight = DEFAULT_ITEM_HEIGHT,
|
|
43
|
+
visibleItems = DEFAULT_VISIBLE_ITEMS,
|
|
44
|
+
monthAccessibilityLabel = 'Month picker',
|
|
45
|
+
dayAccessibilityLabel = 'Day picker'
|
|
46
|
+
}) {
|
|
47
|
+
// Determine if we're in controlled or uncontrolled mode
|
|
48
|
+
const isControlled = controlledValue !== undefined;
|
|
49
|
+
|
|
50
|
+
// Internal state for uncontrolled mode
|
|
51
|
+
const [internalValue, setInternalValue] = React.useState(() => controlledValue ?? defaultValue);
|
|
52
|
+
|
|
53
|
+
// The actual value to display
|
|
54
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
55
|
+
|
|
56
|
+
// Track previous month to detect changes for day clamping
|
|
57
|
+
const prevMonthRef = useRef(value.month);
|
|
58
|
+
|
|
59
|
+
// Get month names based on locale and format
|
|
60
|
+
const monthNames = useMemo(() => getMonthNames(locale, monthFormat), [locale, monthFormat]);
|
|
61
|
+
|
|
62
|
+
// Generate month items for wheel picker
|
|
63
|
+
const monthItems = useMemo(() => {
|
|
64
|
+
return getMonthsArray().map(month => ({
|
|
65
|
+
value: month,
|
|
66
|
+
label: monthNames[month]
|
|
67
|
+
}));
|
|
68
|
+
}, [monthNames]);
|
|
69
|
+
|
|
70
|
+
// Generate day items based on selected month
|
|
71
|
+
const dayItems = useMemo(() => {
|
|
72
|
+
return getDaysArray(value.month, allowLeapDay).map(day => ({
|
|
73
|
+
value: day,
|
|
74
|
+
label: formatDay(day, locale)
|
|
75
|
+
}));
|
|
76
|
+
}, [value.month, allowLeapDay, locale]);
|
|
77
|
+
|
|
78
|
+
// Handle internal value changes
|
|
79
|
+
const handleValueChange = useCallback(newValue => {
|
|
80
|
+
if (!isControlled) {
|
|
81
|
+
setInternalValue(newValue);
|
|
82
|
+
}
|
|
83
|
+
onChange?.(newValue);
|
|
84
|
+
}, [isControlled, onChange]);
|
|
85
|
+
|
|
86
|
+
// Handle month change
|
|
87
|
+
const handleMonthChange = useCallback(({
|
|
88
|
+
item
|
|
89
|
+
}) => {
|
|
90
|
+
const newMonth = item.value;
|
|
91
|
+
const clampedDay = clampDay(value.day, newMonth, allowLeapDay);
|
|
92
|
+
const newValue = {
|
|
93
|
+
month: newMonth,
|
|
94
|
+
day: clampedDay
|
|
95
|
+
};
|
|
96
|
+
handleValueChange(newValue);
|
|
97
|
+
}, [value.day, allowLeapDay, handleValueChange]);
|
|
98
|
+
|
|
99
|
+
// Handle day change
|
|
100
|
+
const handleDayChange = useCallback(({
|
|
101
|
+
item
|
|
102
|
+
}) => {
|
|
103
|
+
const newValue = {
|
|
104
|
+
month: value.month,
|
|
105
|
+
day: item.value
|
|
106
|
+
};
|
|
107
|
+
handleValueChange(newValue);
|
|
108
|
+
}, [value.month, handleValueChange]);
|
|
109
|
+
|
|
110
|
+
// Sync internal state when controlled value changes
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (isControlled && controlledValue) {
|
|
113
|
+
setInternalValue(controlledValue);
|
|
114
|
+
}
|
|
115
|
+
}, [isControlled, controlledValue]);
|
|
116
|
+
|
|
117
|
+
// Clamp day when month changes and day exceeds max days
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (value.month !== prevMonthRef.current) {
|
|
120
|
+
const maxDays = getDaysInMonth(value.month, allowLeapDay);
|
|
121
|
+
if (value.day > maxDays) {
|
|
122
|
+
const clampedValue = {
|
|
123
|
+
month: value.month,
|
|
124
|
+
day: maxDays
|
|
125
|
+
};
|
|
126
|
+
handleValueChange(clampedValue);
|
|
127
|
+
}
|
|
128
|
+
prevMonthRef.current = value.month;
|
|
129
|
+
}
|
|
130
|
+
}, [value.month, value.day, allowLeapDay, handleValueChange]);
|
|
131
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
132
|
+
style: [styles.container, style],
|
|
133
|
+
testID: testID,
|
|
134
|
+
pointerEvents: disabled ? 'none' : 'auto',
|
|
135
|
+
accessibilityRole: "adjustable"
|
|
136
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
137
|
+
style: styles.pickerContainer,
|
|
138
|
+
accessibilityLabel: monthAccessibilityLabel
|
|
139
|
+
}, /*#__PURE__*/React.createElement(WheelPicker, {
|
|
140
|
+
data: monthItems,
|
|
141
|
+
value: value.month,
|
|
142
|
+
onValueChanged: handleMonthChange,
|
|
143
|
+
itemHeight: itemHeight,
|
|
144
|
+
visibleItemCount: visibleItems,
|
|
145
|
+
testID: testID ? `${testID}-month` : undefined
|
|
146
|
+
})), /*#__PURE__*/React.createElement(View, {
|
|
147
|
+
style: styles.pickerContainer,
|
|
148
|
+
accessibilityLabel: dayAccessibilityLabel
|
|
149
|
+
}, /*#__PURE__*/React.createElement(WheelPicker, {
|
|
150
|
+
data: dayItems,
|
|
151
|
+
value: value.day,
|
|
152
|
+
onValueChanged: handleDayChange,
|
|
153
|
+
itemHeight: itemHeight,
|
|
154
|
+
visibleItemCount: visibleItems,
|
|
155
|
+
testID: testID ? `${testID}-day` : undefined
|
|
156
|
+
})));
|
|
157
|
+
}
|
|
158
|
+
const styles = StyleSheet.create({
|
|
159
|
+
container: {
|
|
160
|
+
flexDirection: 'row',
|
|
161
|
+
alignItems: 'center',
|
|
162
|
+
justifyContent: 'center'
|
|
163
|
+
},
|
|
164
|
+
pickerContainer: {
|
|
165
|
+
flex: 1
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
export default BirthdayPicker;
|
|
169
|
+
//# sourceMappingURL=BirthdayPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useMemo","useRef","View","StyleSheet","WheelPicker","DEFAULT_BIRTHDAY_VALUE","DEFAULT_LOCALE","DEFAULT_MONTH_FORMAT","DEFAULT_ITEM_HEIGHT","DEFAULT_VISIBLE_ITEMS","getDaysArray","getMonthsArray","clampDay","getDaysInMonth","getMonthNames","formatDay","BirthdayPicker","value","controlledValue","defaultValue","onChange","locale","monthFormat","allowLeapDay","disabled","testID","style","itemHeight","visibleItems","monthAccessibilityLabel","dayAccessibilityLabel","isControlled","undefined","internalValue","setInternalValue","useState","prevMonthRef","month","monthNames","monthItems","map","label","dayItems","day","handleValueChange","newValue","handleMonthChange","item","newMonth","clampedDay","handleDayChange","current","maxDays","clampedValue","createElement","styles","container","pointerEvents","accessibilityRole","pickerContainer","accessibilityLabel","data","onValueChanged","visibleItemCount","create","flexDirection","alignItems","justifyContent","flex"],"sourceRoot":"../../src","sources":["BirthdayPicker.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AACtE,SAASC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAC/C,OAAOC,WAAW,MAAM,oCAAoC;AAE5D,SACEC,sBAAsB,EACtBC,cAAc,EACdC,oBAAoB,EACpBC,mBAAmB,EACnBC,qBAAqB,QAChB,aAAa;AACpB,SACEC,YAAY,EACZC,cAAc,EACdC,QAAQ,EACRC,cAAc,QACT,mBAAmB;AAC1B,SAASC,aAAa,EAAEC,SAAS,QAAQ,qBAAqB;;AAE9D;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAC;EAC7BC,KAAK,EAAEC,eAAe;EACtBC,YAAY,GAAGd,sBAAsB;EACrCe,QAAQ;EACRC,MAAM,GAAGf,cAAc;EACvBgB,WAAW,GAAGf,oBAAoB;EAClCgB,YAAY,GAAG,IAAI;EACnBC,QAAQ,GAAG,KAAK;EAChBC,MAAM;EACNC,KAAK;EACLC,UAAU,GAAGnB,mBAAmB;EAChCoB,YAAY,GAAGnB,qBAAqB;EACpCoB,uBAAuB,GAAG,cAAc;EACxCC,qBAAqB,GAAG;AACL,CAAC,EAAsB;EAC1C;EACA,MAAMC,YAAY,GAAGb,eAAe,KAAKc,SAAS;;EAElD;EACA,MAAM,CAACC,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