UNPKG

@abgov/react-components

Version:

Government of Alberta - UI components for React

2,147 lines 117 kB
"use strict"; var __defProp = Object.defineProperty; var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); var _PublicFormController_instances, updateObjectListState_fn, dispatchError_fn; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const react = require("react"); const icon = require("./icon-CK55b563.js"); function GoabAccordion({ open, heading, headingSize, secondaryText, headingContent, iconPosition, maxWidth, testId, onChange, children, mt, mr, mb, ml }) { const ref = react.useRef(null); react.useEffect(() => { const element = ref.current; if (element && onChange) { const handler = (event) => { const customEvent = event; onChange(customEvent.detail.open); }; element.addEventListener("_change", handler); return () => { element.removeEventListener("_change", handler); }; } }, [onChange]); return /* @__PURE__ */ jsxRuntime.jsxs( "goa-accordion", { ref, open: open ? "true" : void 0, headingsize: headingSize, heading, secondarytext: secondaryText, iconposition: iconPosition, maxwidth: maxWidth, testid: testId, mt, mr, mb, ml, children: [ headingContent && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "headingcontent", children: headingContent }), children ] } ); } function GoabAppHeader({ heading, url, maxContentWidth, fullMenuBreakpoint, testId, children, onMenuClick }) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) { return; } if (!onMenuClick) { return; } const current = el.current; const listener = () => { onMenuClick(); }; current.addEventListener("_menuClick", listener); return () => { current.removeEventListener("_menuClick", listener); }; }, [el, onMenuClick]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-app-header", { ref: el, heading, url, fullmenubreakpoint: fullMenuBreakpoint, maxcontentwidth: maxContentWidth, testid: testId, hasmenuclickhandler: onMenuClick ? "true" : "false", children } ); } function GoabAppHeaderMenu(props) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-app-header-menu", { heading: props.heading, leadingicon: props.leadingIcon, testid: props.testId, children: props.children } ); } function getIconValue(icon2, iconType) { if (icon2 !== void 0) { return icon2 ? "true" : "false"; } return iconType ? "true" : "false"; } function GoabBadge({ type, content, icon: icon2, testId, mt, mr, mb, ml, ariaLabel, iconType }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-badge", { type, content, icon: getIconValue(icon2, iconType), testid: testId, arialabel: ariaLabel, icontype: iconType, mt, mr, mb, ml } ); } function GoabInfoBadge({ content, testId, icon: icon2, mt, mr, mb, ml, ariaLabel }) { return /* @__PURE__ */ jsxRuntime.jsx( GoabBadge, { type: "information", icon: icon2, content, testId, ariaLabel, mt, mr, mb, ml } ); } function GoabSuccessBadge({ content, testId, icon: icon2, mt, mr, mb, ml, ariaLabel }) { return /* @__PURE__ */ jsxRuntime.jsx( GoabBadge, { type: "success", icon: icon2, content, ariaLabel, testId, mt, mr, mb, ml } ); } function GoabImportantBadge({ content, testId, icon: icon2, mt, mr, mb, ml, ariaLabel }) { return /* @__PURE__ */ jsxRuntime.jsx( GoabBadge, { type: "important", icon: icon2, content, testId, ariaLabel, mt, mr, mb, ml } ); } function GoabEmergencyBadge({ content, testId, icon: icon2, mt, mr, mb, ml, ariaLabel }) { return /* @__PURE__ */ jsxRuntime.jsx( GoabBadge, { type: "emergency", icon: icon2, content, testId, ariaLabel, mt, mr, mb, ml } ); } function GoabBlock(props) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-block", { gap: props.gap, direction: props.direction, alignment: props.alignment, mt: props.mt, mr: props.mr, mb: props.mb, ml: props.ml, testid: props.testId, children: props.children } ); } function GoabButton({ disabled, type, size, variant, leadingIcon, trailingIcon, width, testId, children, onClick, mt, mr, mb, ml, action, actionArgs, actionArg }) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) { return; } if (!onClick) { return; } const current = el.current; const listener = () => { onClick(); }; current.addEventListener("_click", listener); return () => { current.removeEventListener("_click", listener); }; }, [el, onClick]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-button", { ref: el, type, size, variant, disabled: disabled ? "true" : void 0, leadingicon: leadingIcon, trailingicon: trailingIcon, width, testid: testId, action, "action-arg": actionArg, "action-args": JSON.stringify(actionArgs), mt, mr, mb, ml, children } ); } function GoabButtonGroup({ alignment, gap, testId, children, mt, mr, mb, ml }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-button-group", { alignment, gap, mt, mr, mb, ml, testid: testId, children } ); } function GoabCalendar({ name, value, min, max, testId, mt, mr, mb, ml, onChange }) { const ref = react.useRef(null); react.useEffect(() => { if (!ref.current) { return; } const current = ref.current; const listener = (e) => { onChange({ name: name || "", value: e.detail.value }); }; current.addEventListener("_change", listener); return () => { current.removeEventListener("_change", listener); }; }, []); return /* @__PURE__ */ jsxRuntime.jsx( "goa-calendar", { ref, name, value, min: min || void 0, max: max || void 0, testid: testId, mt, mr, mb, ml } ); } const GoabCallout = ({ heading, type = "information", iconTheme = "outline", size = "large", maxWidth, testId, ariaLive = "off", children, mt, mr, mb, ml }) => { return /* @__PURE__ */ jsxRuntime.jsx( "goa-callout", { heading, type, size, maxwidth: maxWidth, arialive: ariaLive, icontheme: iconTheme, mt, mr, mb, ml, testid: testId, children } ); }; function GoabCheckbox({ id, name, testId, error, disabled, checked, indeterminate, value, text, description, reveal, revealAriaLabel, maxWidth, children, onChange, ariaLabel, mt, mr, mb, ml }) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) { return; } const current = el.current; const listener = (e) => { const detail = e.detail; onChange == null ? void 0 : onChange(detail); }; current.addEventListener("_change", listener); return () => { current.removeEventListener("_change", listener); }; }, [name, onChange]); return /* @__PURE__ */ jsxRuntime.jsxs( "goa-checkbox", { testid: testId, ref: el, id, name, error: error ? "true" : void 0, checked: checked ? "true" : void 0, indeterminate: indeterminate ? "true" : void 0, disabled: disabled ? "true" : void 0, text, value: typeof value === "boolean" ? value ? "true" : void 0 : value, arialabel: ariaLabel, revealarialabel: revealAriaLabel, description: typeof description === "string" ? description : void 0, maxwidth: maxWidth, mt, mr, mb, ml, children: [ children, typeof description !== "string" && description && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "description", children: description }), reveal && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "reveal", children: reveal }) ] } ); } function GoabCheckboxList({ name, value = [], disabled, error, testId, maxWidth, children, onChange, mt, mr, mb, ml }) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) return; const current = el.current; const listener = (e) => { try { const detail = e.detail; onChange == null ? void 0 : onChange(detail); } catch (error2) { console.error("Error handling checkbox list change:", error2); } }; try { current.addEventListener("_change", listener); } catch (error2) { console.error("Failed to attach checkbox list listener:", error2); } return () => { try { current.removeEventListener("_change", listener); } catch (error2) { console.error("Failed to remove checkbox list listener:", error2); } }; }, [onChange]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-checkbox-list", { ref: el, name, value, disabled: disabled ? "true" : void 0, error: error ? "true" : void 0, testid: testId, maxwidth: maxWidth, mt, mr, mb, ml, children } ); } const GoabChip = ({ leadingIcon, iconTheme, deletable, error, variant, content, onClick, mt, mr, mb, ml, testId }) => { const el = react.useRef(null); react.useEffect(() => { if (!el.current) return; if (!onClick) return; const current = el.current; const listener = () => { onClick(); }; current.addEventListener("_click", listener); return () => { current.removeEventListener("_click", listener); }; }, [el, onClick]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-chip", { ref: el, leadingicon: leadingIcon, icontheme: iconTheme, error: error ? "true" : void 0, deletable: deletable ? "true" : void 0, content, variant, mt, mr, mb, ml, testid: testId } ); }; const GoabCircularProgress = ({ visible, message: message2, progress, variant, size, testId }) => { return /* @__PURE__ */ jsxRuntime.jsx( "goa-circular-progress", { visible: visible ? "true" : void 0, message: message2, progress, variant, size, testid: testId } ); }; function GoabContainer({ accent, heading, title, padding, children, actions, type, width, maxWidth, mt, mr, mb, ml, testId }) { const headingContent = heading || title; return /* @__PURE__ */ jsxRuntime.jsxs( "goa-container", { type, padding, accent, width, maxwidth: maxWidth, mt, mr, mb, ml, testid: testId, children: [ headingContent && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "title", children: headingContent }), children, actions && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "actions", children: actions }) ] } ); } function GoabDatePicker({ name, value, error, min, max, testId, disabled, type, mt, mr, mb, ml, relative, width, onChange }) { const ref = react.useRef(null); react.useEffect(() => { if (value && typeof value !== "string") { console.warn("Using a `Date` type for value is deprecated. Instead use a string of the format `yyyy-mm-dd`"); } }, []); react.useEffect(() => { if (!ref.current) { return; } const current = ref.current; const handleChange = (e) => { const detail = e.detail; onChange == null ? void 0 : onChange(detail); }; if (onChange) { current.addEventListener("_change", handleChange); } return () => { if (onChange) { current.removeEventListener("_change", handleChange); } }; }, [onChange]); const formatValue = (value2) => { if (!value2) return ""; if (value2 instanceof Date) { return value2.toISOString(); } return value2; }; return /* @__PURE__ */ jsxRuntime.jsx( "goa-date-picker", { ref, name, value: formatValue(value) || void 0, type, error: error ? "true" : void 0, disabled: disabled ? "true" : void 0, min: formatValue(min) || void 0, max: formatValue(max) || void 0, testid: testId, mt, mr, mb, ml, relative: relative ? "true" : void 0, width } ); } function GoabDetails(props) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-details", { heading: props.heading, open: props.open ? "true" : void 0, maxwidth: props.maxWidth, testid: props.testId, mt: props.mt, mr: props.mr, mb: props.mb, ml: props.ml, children: props.children } ); } function GoabDivider(props) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-divider", { mt: props.mt, mr: props.mr, mb: props.mb, ml: props.ml, testid: props.testId } ); } function stringify(value) { if (typeof value === "undefined") { return ""; } if (typeof value === "string") { return value; } return JSON.stringify(value); } function GoabDropdown(props) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) { return; } const current = el.current; const handler = (e) => { var _a; const detail = e.detail; (_a = props.onChange) == null ? void 0 : _a.call(props, detail); }; if (props.onChange) { current.addEventListener("_change", handler); } return () => { if (props.onChange) { current.removeEventListener("_change", handler); } }; }, [el, props]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-dropdown", { ref: el, name: props.name, value: stringify(props.value), arialabel: props.ariaLabel, arialabelledby: props.ariaLabelledBy, disabled: props.disabled ? "true" : void 0, error: props.error ? "true" : void 0, filterable: props.filterable ? "true" : void 0, leadingicon: props.leadingIcon, maxheight: props.maxHeight, mb: props.mb, ml: props.ml, mr: props.mr, mt: props.mt, multiselect: props.multiselect ? "true" : void 0, native: props.native ? "true" : void 0, placeholder: props.placeholder, testid: props.testId, width: props.width, maxwidth: props.maxWidth, relative: props.relative ? "true" : void 0, autocomplete: props.autoComplete, id: props.id, children: props.children } ); } function GoabDropdownOption(props) { react.useEffect(() => { console.warn("GoabDropdownOption is deprecated. Please use GoabDropdownItem"); }, []); return /* @__PURE__ */ jsxRuntime.jsx(GoabDropdownItem, { ...props }); } function GoabDropdownItem({ value, label, filter, name, mountType = "append" }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-dropdown-item", { value, label, filter, name, mount: mountType } ); } function GoabFileUploadCard({ filename, size, type, progress, error, testId, onDelete, onCancel }) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) return; const current = el.current; const deleteHandler = () => onDelete == null ? void 0 : onDelete({ filename }); const cancelHandler = () => onCancel == null ? void 0 : onCancel({ filename }); current.addEventListener("_delete", deleteHandler); current.addEventListener("_cancel", cancelHandler); return () => { current.removeEventListener("_delete", deleteHandler); current.removeEventListener("_cancel", cancelHandler); }; }, [el, onDelete, onCancel]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-file-upload-card", { ref: el, filename, size, type, progress, error, testid: testId } ); } function GoabFileUploadInput({ variant, accept, maxFileSize, testId, onSelectFile }) { const el = react.useRef(null); react.useEffect(() => { if (!el.current) return; const current = el.current; const handler = (e) => { const detail = e.detail; onSelectFile(detail); }; current.addEventListener("_selectFile", handler); return () => { current.removeEventListener("_selectFile", handler); }; }, [el, onSelectFile]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-file-upload-input", { ref: el, variant, accept, maxfilesize: maxFileSize, testid: testId } ); } function GoabAppFooter({ maxContentWidth, children, testId, url }) { return /* @__PURE__ */ jsxRuntime.jsx("goa-app-footer", { maxcontentwidth: maxContentWidth, testid: testId, url, children }); } function GoabAppFooterMetaSection({ testId, children }) { return /* @__PURE__ */ jsxRuntime.jsx("goa-app-footer-meta-section", { testid: testId, slot: "meta", children }); } function GoabAppFooterNavSection({ heading, maxColumnCount = 1, testId, children }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-app-footer-nav-section", { slot: "nav", heading, maxcolumncount: maxColumnCount, testid: testId, children } ); } function GoabFieldset({ id, sectionTitle, dispatchOn, onContinue, children }) { const ref = react.useRef(null); react.useEffect(() => { if (!ref.current) return; const current = ref.current; const continueListener = (e) => { const event = e.detail; return onContinue == null ? void 0 : onContinue(event); }; if (onContinue) { current.addEventListener("_continue", continueListener); } return () => { if (onContinue) { current.removeEventListener("_continue", continueListener); } }; }, [ref, onContinue]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-fieldset", { ref, id, "section-title": sectionTitle, "dispatch-on": dispatchOn, children } ); } function GoabPublicFormPage({ id = "", heading = "", subHeading = "", summaryHeading = "", sectionTitle = "", backUrl = "", type = "step", buttonText = "", buttonVisibility = "visible", onContinue, children, mt, mr, mb, ml }) { const ref = react.useRef(null); react.useEffect(() => { if (!ref.current) return; const current = ref.current; const continueListener = (e) => { onContinue == null ? void 0 : onContinue(e); }; if (onContinue) { current.addEventListener("_continue", continueListener); } return () => { if (onContinue) { current.removeEventListener("_continue", continueListener); } }; }, [ref, onContinue]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-public-form-page", { ref, id, heading, "sub-heading": subHeading, "section-title": sectionTitle, "back-url": backUrl, type, "button-text": buttonText, "button-visibility": buttonVisibility, "summary-heading": summaryHeading, mt, mr, mb, ml, children } ); } function GoabPublicFormSummary({ heading = "" }) { const ref = react.useRef(null); return /* @__PURE__ */ jsxRuntime.jsx( "goa-public-form-summary", { ref, heading } ); } function GoabPublicForm({ status = "complete", name, onInit, onComplete, onStateChange, children }) { const ref = react.useRef(null); const initialized = react.useRef(false); react.useLayoutEffect(() => { if (!ref.current) return; const current = ref.current; const initListener = (e) => { onInit == null ? void 0 : onInit(e); }; if (onInit && !initialized.current) { current.addEventListener("_init", initListener); } const completeListener = (e) => { const detail = e.detail; onComplete == null ? void 0 : onComplete(detail); }; const stateChangeListener = (e) => { const detail = e.detail; onStateChange == null ? void 0 : onStateChange(detail.data); }; if (onComplete) { current.addEventListener("_complete", completeListener); } if (onStateChange) { current.addEventListener("_stateChange", stateChangeListener); } return () => { if (onInit) { current.removeEventListener("_init", initListener); } if (onComplete) { current.removeEventListener("_complete", completeListener); } if (onStateChange) { current.removeEventListener("_stateChange", stateChangeListener); } }; }, [onInit, onComplete, onStateChange]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-public-form", { ref, status, name, children } ); } function GoabPublicSubform({ id = "", name = "", continueMsg = "", onInit, onStateChange, children, mt, mr, mb, ml }) { const ref = react.useRef(null); react.useEffect(() => { if (!ref.current) return; const current = ref.current; const initListener = (e) => { onInit == null ? void 0 : onInit(e); }; const stateChangeListener = (e) => { onStateChange == null ? void 0 : onStateChange(e); }; if (onInit) { current.addEventListener("_init", initListener); } if (onStateChange) { current.addEventListener("_stateChange", stateChangeListener); } return () => { if (onInit) { current.removeEventListener("_init", initListener); } if (onStateChange) { current.removeEventListener("_stateChange", stateChangeListener); } }; }, [ref, onInit, onStateChange]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-public-subform", { ref, id, name, "continue-msg": continueMsg, mt, mr, mb, ml, children } ); } function GoabPublicSubformIndex({ heading = "", sectionTitle = "", actionButtonText = "", buttonVisibility = "hidden", children, mt, mr, mb, ml }) { const ref = react.useRef(null); return /* @__PURE__ */ jsxRuntime.jsx( "goa-public-subform-index", { ref, heading, "section-title": sectionTitle, "action-button-text": actionButtonText, "button-visibility": buttonVisibility, slot: "subform-index", mt, mr, mb, ml, children } ); } function GoabPublicFormTask({ status = "cannot-start", children }) { return /* @__PURE__ */ jsxRuntime.jsx("goa-public-form-task", { status, children }); } function GoabPublicFormTaskList({ heading = "", children, mt, mr, mb, ml }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-public-form-task-list", { heading, mt, mr, mb, ml, children } ); } function GoabFormItem({ children, helpText, error, requirement, label, labelSize, maxWidth, publicFormSummaryOrder, name, mt, mr, mb, ml, testId, id }) { return /* @__PURE__ */ jsxRuntime.jsxs( "goa-form-item", { label, labelsize: labelSize, error: typeof error === "string" ? error : void 0, requirement, helptext: typeof helpText === "string" ? helpText : void 0, maxwidth: maxWidth, "public-form-summary-order": publicFormSummaryOrder, name, mt, mr, mb, ml, testid: testId, id, children: [ error && typeof error !== "string" && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "error", children: error }), helpText && typeof helpText !== "string" && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "helptext", children: helpText }), children ] } ); } function GoabFormStep(props) { return /* @__PURE__ */ jsxRuntime.jsx("goa-form-step", { text: props.text, status: props.status }); } function GoabFormStepper({ testId, step, mt, mb, ml, mr, onChange, children }) { const ref = react.useRef(null); react.useEffect(() => { if (!ref.current) { return; } const current = ref.current; const changeListener = (e) => { const detail = e.detail; onChange == null ? void 0 : onChange(detail); }; current.addEventListener("_change", changeListener); return () => { current.removeEventListener("_change", changeListener); }; }, [ref, onChange]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-form-stepper", { ref, testid: testId, step, mt, mr, mb, ml, children } ); } function GoabGrid({ gap, minChildWidth, mt, mr, mb, ml, testId, children }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-grid", { gap, minchildwidth: minChildWidth, mt, mr, mb, ml, testid: testId, children } ); } function GoabHeroBanner({ heading, backgroundUrl, minHeight, maxContentWidth, backgroundColor, textColor, children, testId }) { return /* @__PURE__ */ jsxRuntime.jsx( "goa-hero-banner", { heading, backgroundurl: backgroundUrl, minheight: minHeight, maxcontentwidth: maxContentWidth, backgroundcolor: backgroundColor, textcolor: textColor, testid: testId, children } ); } function GoabHeroBannerActions({ children }) { return /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "actions", children }); } function GoabIconButton({ icon: icon2, disabled, variant = "color", onClick, size = "medium", title, ariaLabel, testId, children, mt, mr, mb, ml, action, actionArgs, actionArg }) { const ref = react.useRef(null); react.useEffect(() => { if (!ref.current) { return; } if (!onClick) { return; } const current = ref.current; const listener = () => { onClick(); }; current.addEventListener("_click", listener); return () => { current.removeEventListener("_click", listener); }; }, [ref, onClick]); return /* @__PURE__ */ jsxRuntime.jsx( "goa-icon-button", { ref, icon: icon2, disabled: disabled ? "true" : void 0, variant, size, title, arialabel: ariaLabel, action, "action-arg": actionArg, "action-args": JSON.stringify(actionArgs), mt, mr, mb, ml, testid: testId, children } ); } function toDate(argument) { const argStr = Object.prototype.toString.call(argument); if (argument instanceof Date || typeof argument === "object" && argStr === "[object Date]") { return new argument.constructor(+argument); } else if (typeof argument === "number" || argStr === "[object Number]" || typeof argument === "string" || argStr === "[object String]") { return new Date(argument); } else { return /* @__PURE__ */ new Date(NaN); } } function constructFrom(date, value) { if (date instanceof Date) { return new date.constructor(value); } else { return new Date(value); } } const millisecondsInWeek = 6048e5; const millisecondsInDay = 864e5; const millisecondsInMinute = 6e4; const millisecondsInHour = 36e5; let defaultOptions = {}; function getDefaultOptions() { return defaultOptions; } function startOfWeek(date, options) { var _a, _b, _c, _d; const defaultOptions2 = getDefaultOptions(); const weekStartsOn = (options == null ? void 0 : options.weekStartsOn) ?? ((_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.weekStartsOn) ?? defaultOptions2.weekStartsOn ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.weekStartsOn) ?? 0; const _date = toDate(date); const day = _date.getDay(); const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; _date.setDate(_date.getDate() - diff); _date.setHours(0, 0, 0, 0); return _date; } function startOfISOWeek(date) { return startOfWeek(date, { weekStartsOn: 1 }); } function getISOWeekYear(date) { const _date = toDate(date); const year = _date.getFullYear(); const fourthOfJanuaryOfNextYear = constructFrom(date, 0); fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4); fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0); const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear); const fourthOfJanuaryOfThisYear = constructFrom(date, 0); fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4); fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0); const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear); if (_date.getTime() >= startOfNextYear.getTime()) { return year + 1; } else if (_date.getTime() >= startOfThisYear.getTime()) { return year; } else { return year - 1; } } function startOfDay(date) { const _date = toDate(date); _date.setHours(0, 0, 0, 0); return _date; } function getTimezoneOffsetInMilliseconds(date) { const _date = toDate(date); const utcDate = new Date( Date.UTC( _date.getFullYear(), _date.getMonth(), _date.getDate(), _date.getHours(), _date.getMinutes(), _date.getSeconds(), _date.getMilliseconds() ) ); utcDate.setUTCFullYear(_date.getFullYear()); return +date - +utcDate; } function differenceInCalendarDays(dateLeft, dateRight) { const startOfDayLeft = startOfDay(dateLeft); const startOfDayRight = startOfDay(dateRight); const timestampLeft = +startOfDayLeft - getTimezoneOffsetInMilliseconds(startOfDayLeft); const timestampRight = +startOfDayRight - getTimezoneOffsetInMilliseconds(startOfDayRight); return Math.round((timestampLeft - timestampRight) / millisecondsInDay); } function startOfISOWeekYear(date) { const year = getISOWeekYear(date); const fourthOfJanuary = constructFrom(date, 0); fourthOfJanuary.setFullYear(year, 0, 4); fourthOfJanuary.setHours(0, 0, 0, 0); return startOfISOWeek(fourthOfJanuary); } function isDate(value) { return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]"; } function isValid(date) { if (!isDate(date) && typeof date !== "number") { return false; } const _date = toDate(date); return !isNaN(Number(_date)); } function startOfYear(date) { const cleanDate = toDate(date); const _date = constructFrom(date, 0); _date.setFullYear(cleanDate.getFullYear(), 0, 1); _date.setHours(0, 0, 0, 0); return _date; } const formatDistanceLocale = { lessThanXSeconds: { one: "less than a second", other: "less than {{count}} seconds" }, xSeconds: { one: "1 second", other: "{{count}} seconds" }, halfAMinute: "half a minute", lessThanXMinutes: { one: "less than a minute", other: "less than {{count}} minutes" }, xMinutes: { one: "1 minute", other: "{{count}} minutes" }, aboutXHours: { one: "about 1 hour", other: "about {{count}} hours" }, xHours: { one: "1 hour", other: "{{count}} hours" }, xDays: { one: "1 day", other: "{{count}} days" }, aboutXWeeks: { one: "about 1 week", other: "about {{count}} weeks" }, xWeeks: { one: "1 week", other: "{{count}} weeks" }, aboutXMonths: { one: "about 1 month", other: "about {{count}} months" }, xMonths: { one: "1 month", other: "{{count}} months" }, aboutXYears: { one: "about 1 year", other: "about {{count}} years" }, xYears: { one: "1 year", other: "{{count}} years" }, overXYears: { one: "over 1 year", other: "over {{count}} years" }, almostXYears: { one: "almost 1 year", other: "almost {{count}} years" } }; const formatDistance = (token, count, options) => { let result; const tokenValue = formatDistanceLocale[token]; if (typeof tokenValue === "string") { result = tokenValue; } else if (count === 1) { result = tokenValue.one; } else { result = tokenValue.other.replace("{{count}}", count.toString()); } if (options == null ? void 0 : options.addSuffix) { if (options.comparison && options.comparison > 0) { return "in " + result; } else { return result + " ago"; } } return result; }; function buildFormatLongFn(args) { return (options = {}) => { const width = options.width ? String(options.width) : args.defaultWidth; const format2 = args.formats[width] || args.formats[args.defaultWidth]; return format2; }; } const dateFormats = { full: "EEEE, MMMM do, y", long: "MMMM do, y", medium: "MMM d, y", short: "MM/dd/yyyy" }; const timeFormats = { full: "h:mm:ss a zzzz", long: "h:mm:ss a z", medium: "h:mm:ss a", short: "h:mm a" }; const dateTimeFormats = { full: "{{date}} 'at' {{time}}", long: "{{date}} 'at' {{time}}", medium: "{{date}}, {{time}}", short: "{{date}}, {{time}}" }; const formatLong = { date: buildFormatLongFn({ formats: dateFormats, defaultWidth: "full" }), time: buildFormatLongFn({ formats: timeFormats, defaultWidth: "full" }), dateTime: buildFormatLongFn({ formats: dateTimeFormats, defaultWidth: "full" }) }; const formatRelativeLocale = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", tomorrow: "'tomorrow at' p", nextWeek: "eeee 'at' p", other: "P" }; const formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token]; function buildLocalizeFn(args) { return (value, options) => { const context = (options == null ? void 0 : options.context) ? String(options.context) : "standalone"; let valuesArray; if (context === "formatting" && args.formattingValues) { const defaultWidth = args.defaultFormattingWidth || args.defaultWidth; const width = (options == null ? void 0 : options.width) ? String(options.width) : defaultWidth; valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; } else { const defaultWidth = args.defaultWidth; const width = (options == null ? void 0 : options.width) ? String(options.width) : args.defaultWidth; valuesArray = args.values[width] || args.values[defaultWidth]; } const index = args.argumentCallback ? args.argumentCallback(value) : value; return valuesArray[index]; }; } const eraValues = { narrow: ["B", "A"], abbreviated: ["BC", "AD"], wide: ["Before Christ", "Anno Domini"] }; const quarterValues = { narrow: ["1", "2", "3", "4"], abbreviated: ["Q1", "Q2", "Q3", "Q4"], wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"] }; const monthValues = { narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"], abbreviated: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ], wide: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] }; const dayValues = { narrow: ["S", "M", "T", "W", "T", "F", "S"], short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], wide: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] }; const dayPeriodValues = { narrow: { am: "a", pm: "p", midnight: "mi", noon: "n", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, abbreviated: { am: "AM", pm: "PM", midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, wide: { am: "a.m.", pm: "p.m.", midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" } }; const formattingDayPeriodValues = { narrow: { am: "a", pm: "p", midnight: "mi", noon: "n", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" }, abbreviated: { am: "AM", pm: "PM", midnight: "midnight", noon: "noon", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" }, wide: { am: "a.m.", pm: "p.m.", midnight: "midnight", noon: "noon", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" } }; const ordinalNumber = (dirtyNumber, _options) => { const number = Number(dirtyNumber); const rem100 = number % 100; if (rem100 > 20 || rem100 < 10) { switch (rem100 % 10) { case 1: return number + "st"; case 2: return number + "nd"; case 3: return number + "rd"; } } return number + "th"; }; const localize = { ordinalNumber, era: buildLocalizeFn({ values: eraValues, defaultWidth: "wide" }), quarter: buildLocalizeFn({ values: quarterValues, defaultWidth: "wide", argumentCallback: (quarter) => quarter - 1 }), month: buildLocalizeFn({ values: monthValues, defaultWidth: "wide" }), day: buildLocalizeFn({ values: dayValues, defaultWidth: "wide" }), dayPeriod: buildLocalizeFn({ values: dayPeriodValues, defaultWidth: "wide", formattingValues: formattingDayPeriodValues, defaultFormattingWidth: "wide" }) }; function buildMatchFn(args) { return (string, options = {}) => { const width = options.width; const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; const matchResult = string.match(matchPattern); if (!matchResult) { return null; } const matchedString = matchResult[0]; const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : ( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type findKey(parsePatterns, (pattern) => pattern.test(matchedString)) ); let value; value = args.valueCallback ? args.valueCallback(key) : key; value = options.valueCallback ? ( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type options.valueCallback(value) ) : value; const rest = string.slice(matchedString.length); return { value, rest }; }; } function findKey(object, predicate) { for (const key in object) { if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) { return key; } } return void 0; } function findIndex(array, predicate) { for (let key = 0; key < array.length; key++) { if (predicate(array[key])) { return key; } } return void 0; } function buildMatchPatternFn(args) { return (string, options = {}) => { const matchResult = string.match(args.matchPattern); if (!matchResult) return null; const matchedString = matchResult[0]; const parseResult = string.match(args.parsePattern); if (!parseResult) return null; let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; value = options.valueCallback ? options.valueCallback(value) : value; const rest = string.slice(matchedString.length); return { value, rest }; }; } const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; const parseOrdinalNumberPattern = /\d+/i; const matchEraPatterns = { narrow: /^(b|a)/i, abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, wide: /^(before christ|before common era|anno domini|common era)/i }; const parseEraPatterns = { any: [/^b/i, /^(a|c)/i] }; const matchQuarterPatterns = { narrow: /^[1234]/i, abbreviated: /^q[1234]/i, wide: /^[1234](th|st|nd|rd)? quarter/i }; const parseQuarterPatterns = { any: [/1/i, /2/i, /3/i, /4/i] }; const matchMonthPatterns = { narrow: /^[jfmasond]/i, abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i }; const parseMonthPatterns = { narrow: [ /^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i ], any: [ /^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i ] }; const matchDayPatterns = { narrow: /^[smtwf]/i, short: /^(su|mo|tu|we|th|fr|sa)/i, abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i }; const parseDayPatterns = { narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] }; const matchDayPeriodPatterns = { narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i }; const parseDayPeriodPatterns = { any: { am: /^a/i, pm: /^p/i, midnight: /^mi/i, noon: /^no/i, morning: /morning/i, afternoon: /afternoon/i, evening: /evening/i, night: /night/i } }; const match = { ordinalNumber: buildMatchPatternFn({ matchPattern: matchOrdinalNumberPattern, parsePattern: parseOrdinalNumberPattern, valueCallback: (value) => parseInt(value, 10) }), era: buildMatchFn({ matchPatterns: matchEraPatterns, defaultMatchWidth: "wide", parsePatterns: parseEraPatterns, defaultParseWidth: "any" }), quarter: buildMatchFn({ matchPatterns: matchQuarterPatterns, defaultMatchWidth: "wide", parsePatterns: parseQuarterPatterns, defaultParseWidth: "any", valueCallback: (index) => index + 1 }), month: buildMatchFn({ matchPatterns: matchMonthPatterns, defaultMatchWidth: "wide", parsePatterns: parseMonthPatterns, defaultParseWidth: "any" }), day: buildMatchFn({ matchPatterns: matchDayPatterns, defaultMatchWidth: "wide", parsePatterns: parseDayPatterns, defaultParseWidth: "any" }), dayPeriod: buildMatchFn({ matchPatterns: matchDayPeriodPatterns, defaultMatchWidth: "any", parsePatterns: parseDayPeriodPatterns, defaultParseWidth: "any" }) }; const enUS = { code: "en-US", formatDistance, formatLong, formatRelative, localize, match, options: { weekStartsOn: 0, firstWeekContainsDate: 1 } }; function getDayOfYear(date) { const _date = toDate(date); const diff = differenceInCalendarDays(_date, startOfYear(_date)); const dayOfYear = diff + 1; return dayOfYear; } function getISOWeek(date) { const _date = toDate(date); const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date); return Math.round(diff / millisecondsInWeek) + 1; } function getWeekYear(date, options) { var _a, _b, _c, _d; const _date = toDate(date); const year = _date.getFullYear(); const defaultOptions2 = getDefaultOptions(); const firstWeekContainsDate = (options == null ? void 0 : options.firstWeekContainsDate) ?? ((_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) ?? defaultOptions2.firstWeekContainsDate ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.firstWeekContainsDate) ?? 1; const firstWeekOfNextYear = constructFrom(date, 0); firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate); firstWeekOfNextYear.setHours(0, 0, 0, 0); const startOfNextYear = startOfWeek(firstWeekOfNextYear, options); const firstWeekOfThisYear = constructFrom(date, 0); firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate); firstWeekOfThisYear.setHours(0, 0, 0, 0); const startOfThisYear = startOfWeek(firstWeekOfThisYear, options); if (_date.getTime() >= startOfNextYear.getTime()) { return year + 1; } else if (_date.getTime() >= startOfThisYear.getTime()) { return year; } else { return year - 1; } } function startOfWeekYear(date, options) { var _a, _b, _c, _d; const defaultOptions2 = getDefaultOptions(); const firstWeekContainsDate = (options == null ? void 0 : options.firstWeekContainsDate) ?? ((_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) ?? defaultOptions2.firstWeekContainsDate ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.firstWeekContainsDate) ?? 1; const year = getWeekYear(date, options); const firstWeek = constructFrom(date, 0); firstWeek.setFullYear(year, 0, firstWeekContainsDate); firstWeek.setHours(0, 0, 0, 0); const _date = startOfWeek(firstWeek, options); return _date; } function getWeek(date, options) { const _date = toDate(date); const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options); return Math.round(diff / millisecondsInWeek) + 1; } function addLeadingZeros(number, targetLength) { const sign = number < 0 ? "-" : ""; const output = Math.abs(number).toString().padStart(targetLength, "0"); return sign + output; } const lightFormatters = { // Year y(date, token) { const signedYear = date.getFullYear(); const year = signedYear > 0 ? signedYear : 1 - signedYear; return addLeadingZeros(token === "yy" ? year % 100 : year, token.length); }, // Month M(date, token) { const month = date.getMonth(); return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2); }, // Day of the month d(date, token) { return addLeadingZeros(date.getDate(), token.length); }, // AM or PM a(date, token) { const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am"; switch (token) { case "a": case "aa": return dayPeriodEnumValue.toUpperCase(); case "aaa": return dayPeriodEnumValue; case "aaaaa": return dayPeriodEnumValue[0]; case "aaaa": default: return dayPeriodEnumValue === "am" ? "a.m." : "p.m."; } }, // Hour [1-12] h(date, token) { return addLeadingZeros(date.getHours() % 12 || 12, token.length); }, // Hour [0-23] H(date, token) { return addLeadingZeros(date.getHours(), token.length); }, // Minute m(date, token) { return addLeadingZeros(date.getMinutes(), token.length); }, // Second s(date, token) { return addLeadingZeros(date.getSeconds(), token.length); }, // Fraction of second S(date, token) { const numberOfDigits = token.length; const milliseconds = date.getMilliseconds(); const fractionalSeconds = Math.trunc( milliseconds * Math.pow(10, numberOfDigits - 3) ); return addLeadingZeros(fractionalSeconds, token.length); } }; const dayPeriodEnum = { midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }; const formatters = { // Era G: function(date, token, localize2) { const era = date.getFullYear() > 0 ? 1 : 0; switch (token) { case "G": case "GG": case "GGG": return localize2.era(era, { width: "abbreviated" }); case "GGGGG": return localize2.era(era, { width: "narrow" }); case "GGGG": default: return localize2.era(era, { width: "wide" }); } }, // Year y: function(date, token, localize2) { if (token === "yo") { const signedYear = date.getFullYear(); const year = signedYear > 0 ? signedYear : 1 - signedYear; return localize2.ordinalNumber(year, { unit: "year" }); } return lightFormatters.y(date, token); }, // Local week-numbering year Y: function(date, token, localize2, options) { const signedWeekYear = getWeekYear(date, options); const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; if (token === "YY") { const twoDigitYear = weekYear % 100; return addLeadingZeros(twoDigitYear, 2); } if (token === "Yo") { return localize2.ordinalNumber(weekYear, { unit: "year" }); } return addLeadingZeros(weekYear, token.length); }, // ISO week-numbering year R: function(date, token) { const isoWeek