one
Version:
One is a React framework for web, iOS, and Android apps.
931 lines (930 loc) • 44.8 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var composeValidation_exports = {};
__export(composeValidation_exports, {
animatedVisibilityTransitions: () => animatedVisibilityTransitions,
assertBoolean: () => assertBoolean,
assertComposeStyle: () => assertComposeStyle,
assertFiniteNumber: () => assertFiniteNumber,
assertFunction: () => assertFunction,
assertOneOf: () => assertOneOf,
assertOptionalBoolean: () => assertOptionalBoolean,
assertOptionalString: () => assertOptionalString,
assertString: () => assertString,
buttonTones: () => buttonTones,
buttonVariants: () => buttonVariants,
composeIconGlyph: () => composeIconGlyph,
composeUtcDay: () => composeUtcDay,
contentAlignments: () => contentAlignments,
fontWeights: () => fontWeights,
horizontalAlignments: () => horizontalAlignments,
horizontalArrangements: () => horizontalArrangements,
imageContentScales: () => imageContentScales,
lazyAlignments: () => lazyAlignments,
lazyRowAlignments: () => lazyRowAlignments,
progressStrokeCaps: () => progressStrokeCaps,
progressVariants: () => progressVariants,
snackbarDurations: () => snackbarDurations,
textAlignments: () => textAlignments,
textFieldCapitalizations: () => textFieldCapitalizations,
textFieldImeActions: () => textFieldImeActions,
textFieldKeyboardTypes: () => textFieldKeyboardTypes,
textFieldVariants: () => textFieldVariants,
validateAlertDialogProps: () => validateAlertDialogProps,
validateAnimatedVisibilityProps: () => validateAnimatedVisibilityProps,
validateBadgeProps: () => validateBadgeProps,
validateBoxProps: () => validateBoxProps,
validateButtonProps: () => validateButtonProps,
validateCardProps: () => validateCardProps,
validateCheckboxProps: () => validateCheckboxProps,
validateChipProps: () => validateChipProps,
validateColumnProps: () => validateColumnProps,
validateDatePickerProps: () => validateDatePickerProps,
validateDialogProps: () => validateDialogProps,
validateDividerProps: () => validateDividerProps,
validateDropdownMenuItemProps: () => validateDropdownMenuItemProps,
validateDropdownMenuProps: () => validateDropdownMenuProps,
validateExposedDropdownMenuBoxProps: () => validateExposedDropdownMenuBoxProps,
validateFloatingActionButtonProps: () => validateFloatingActionButtonProps,
validateFlowRowProps: () => validateFlowRowProps,
validateIconButtonProps: () => validateIconButtonProps,
validateIconProps: () => validateIconProps,
validateImageProps: () => validateImageProps,
validateLazyColumnProps: () => validateLazyColumnProps,
validateLazyRowProps: () => validateLazyRowProps,
validateListItemProps: () => validateListItemProps,
validateLoadingIndicatorProps: () => validateLoadingIndicatorProps,
validateModalBottomSheetProps: () => validateModalBottomSheetProps,
validateNavigationBarItemProps: () => validateNavigationBarItemProps,
validateNavigationBarProps: () => validateNavigationBarProps,
validatePickerDialogProps: () => validatePickerDialogProps,
validateProgressIndicatorProps: () => validateProgressIndicatorProps,
validatePullToRefreshBoxProps: () => validatePullToRefreshBoxProps,
validateRadioButtonProps: () => validateRadioButtonProps,
validateRowProps: () => validateRowProps,
validateSearchBarProps: () => validateSearchBarProps,
validateSegmentedButtonProps: () => validateSegmentedButtonProps,
validateSliderProps: () => validateSliderProps,
validateSnackbarProps: () => validateSnackbarProps,
validateSnackbarShowOptions: () => validateSnackbarShowOptions,
validateSurfaceProps: () => validateSurfaceProps,
validateSwitchProps: () => validateSwitchProps,
validateTextFieldProps: () => validateTextFieldProps,
validateTextProps: () => validateTextProps,
validateTimePickerProps: () => validateTimePickerProps,
validateToggleButtonProps: () => validateToggleButtonProps,
validateTooltipBoxProps: () => validateTooltipBoxProps,
verticalAlignments: () => verticalAlignments,
verticalArrangements: () => verticalArrangements
});
module.exports = __toCommonJS(composeValidation_exports);
var import_composeTypes = require("./composeTypes.cjs");
var import_composeIcons = require("./generated/composeIcons.cjs");
var import_syncStore = require("./syncStore.cjs");
const horizontalAlignments = [
"start",
"centerHorizontally",
"end"
];
const verticalAlignments = [
"top",
"centerVertically",
"bottom"
];
const contentAlignments = [
"topStart",
"topCenter",
"topEnd",
"centerStart",
"center",
"centerEnd",
"bottomStart",
"bottomCenter",
"bottomEnd",
"top",
"bottom",
"start",
"end"
];
const verticalArrangements = [
"top",
"center",
"bottom",
"spaceBetween",
"spaceAround",
"spaceEvenly"
];
const horizontalArrangements = [
"start",
"center",
"end",
"spaceBetween",
"spaceAround",
"spaceEvenly"
];
const textAlignments = [
"unspecified",
"left",
"right",
"center",
"justify",
"start",
"end"
];
const fontWeights = [
"thin",
"extraLight",
"light",
"normal",
"medium",
"semiBold",
"bold",
"extraBold",
"black"
];
const buttonVariants = [
"filled",
"tonal",
"elevated",
"outlined",
"text"
];
const buttonTones = ["default", "danger"];
const textFieldVariants = ["filled", "outlined"];
const textFieldKeyboardTypes = [
"default",
"number",
"decimal",
"email",
"password",
"phone",
"url"
];
const textFieldImeActions = [
"default",
"none",
"go",
"search",
"send",
"previous",
"next",
"done"
];
const textFieldCapitalizations = [
"none",
"characters",
"words",
"sentences"
];
const progressVariants = [
"linear",
"circular",
"linearWavy",
"circularWavy"
];
const progressStrokeCaps = [
"round",
"butt",
"square"
];
const composeStyleKeys = /* @__PURE__ */ new Set([
"backgroundColor",
"foregroundColor",
"padding",
"paddingTop",
"paddingRight",
"paddingBottom",
"paddingLeft",
"width",
"height",
"fillMaxWidth",
"fillMaxHeight",
"weight",
"cornerRadius",
"opacity",
"borderColor",
"borderWidth"
]);
const composeStyleNumberKeys = /* @__PURE__ */ new Set([
"padding",
"paddingTop",
"paddingRight",
"paddingBottom",
"paddingLeft",
"width",
"height",
"cornerRadius",
"borderWidth"
]);
const composeStyleColorKeys = /* @__PURE__ */ new Set([
"backgroundColor",
"foregroundColor",
"borderColor"
]);
const checkboxColorKeys = /* @__PURE__ */ new Set([
"checkedColor",
"disabledCheckedColor",
"uncheckedColor",
"disabledUncheckedColor",
"checkmarkColor"
]);
const radioColorKeys = /* @__PURE__ */ new Set([
"selectedColor",
"unselectedColor",
"disabledSelectedColor",
"disabledUnselectedColor"
]);
const cardColorKeys = /* @__PURE__ */ new Set(["containerColor", "contentColor"]);
const listItemColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"contentColor",
"leadingContentColor",
"trailingContentColor",
"supportingContentColor",
"overlineContentColor"
]);
function validateListItemProps(props) {
if (props.colors !== void 0) assertComposeColors(props.colors, listItemColorKeys, "ListItem");
if (props.tonalElevation !== void 0) {
assertFiniteNumber(props.tonalElevation, "ListItem tonalElevation");
if (props.tonalElevation < 0) throw new Error("Compose ListItem tonalElevation must be nonnegative");
}
if (props.shadowElevation !== void 0) {
assertFiniteNumber(props.shadowElevation, "ListItem shadowElevation");
if (props.shadowElevation < 0) throw new Error("Compose ListItem shadowElevation must be nonnegative");
}
}
function validateBadgeProps(props) {
if (props.containerColor !== void 0) assertComposeColorValue(props.containerColor, "Badge containerColor");
if (props.contentColor !== void 0) assertComposeColorValue(props.contentColor, "Badge contentColor");
}
const assistChipColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"labelColor",
"leadingIconContentColor",
"trailingIconContentColor"
]);
const filterChipColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"labelColor",
"iconColor",
"selectedContainerColor",
"selectedLabelColor",
"selectedLeadingIconColor",
"selectedTrailingIconColor"
]);
const inputChipColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"labelColor",
"leadingIconColor",
"trailingIconColor",
"selectedContainerColor",
"selectedLabelColor",
"selectedLeadingIconColor",
"selectedTrailingIconColor"
]);
const suggestionChipColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"labelColor",
"iconContentColor"
]);
const iconButtonColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"contentColor",
"disabledContainerColor",
"disabledContentColor"
]);
const toggleButtonColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"contentColor",
"checkedContainerColor",
"checkedContentColor",
"disabledContainerColor",
"disabledContentColor"
]);
const segmentedButtonColorKeys = /* @__PURE__ */ new Set([
"activeBorderColor",
"activeContentColor",
"inactiveBorderColor",
"inactiveContentColor",
"disabledActiveBorderColor",
"disabledActiveContentColor",
"disabledInactiveBorderColor",
"disabledInactiveContentColor",
"activeContainerColor",
"inactiveContainerColor",
"disabledActiveContainerColor",
"disabledInactiveContainerColor"
]);
const switchColorKeys = /* @__PURE__ */ new Set([
"checkedThumbColor",
"checkedTrackColor",
"checkedBorderColor",
"checkedIconColor",
"uncheckedThumbColor",
"uncheckedTrackColor",
"uncheckedBorderColor",
"uncheckedIconColor",
"disabledCheckedThumbColor",
"disabledCheckedTrackColor",
"disabledCheckedBorderColor",
"disabledCheckedIconColor",
"disabledUncheckedThumbColor",
"disabledUncheckedTrackColor",
"disabledUncheckedBorderColor",
"disabledUncheckedIconColor"
]);
const sliderColorKeys = /* @__PURE__ */ new Set([
"thumbColor",
"activeTrackColor",
"inactiveTrackColor",
"activeTickColor",
"inactiveTickColor"
]);
function assertComposeColorValue(value, name) {
const resourcePaths = value && typeof value === "object" && "resource_paths" in value ? value.resource_paths : void 0;
if ((typeof value !== "string" || !value.trim()) && (typeof value !== "number" || !Number.isFinite(value)) && (!Array.isArray(resourcePaths) || resourcePaths.length === 0 || resourcePaths.some((path) => typeof path !== "string" || !path))) throw new Error(`Compose ${name} must be a color value`);
}
function assertComposeColors(colors, keys, owner) {
if (!colors || typeof colors !== "object" || Array.isArray(colors)) throw new Error(`Compose ${owner} colors must be an object`);
for (const [key, value] of Object.entries(colors)) {
if (!keys.has(key)) throw new Error(`Compose ${owner} colors does not support ${key}`);
if (value !== void 0) assertComposeColorValue(value, `${owner} colors ${key}`);
}
}
function assertComposeStyle(style) {
if (style === void 0) return;
if (!style || typeof style !== "object" || Array.isArray(style)) throw new Error("Compose composeStyle must be an object");
for (const key of Object.keys(style)) {
if (!composeStyleKeys.has(key)) throw new Error(`Compose composeStyle does not support ${key}`);
const value = style[key];
if (value === void 0) continue;
if (composeStyleNumberKeys.has(key)) {
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new Error(`Compose composeStyle ${key} must be a nonnegative finite number`);
continue;
}
if (key === "opacity") {
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new Error("Compose composeStyle opacity must be a number from 0 to 1");
continue;
}
if (key === "weight") {
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) throw new Error("Compose composeStyle weight must be a positive finite number");
continue;
}
if (composeStyleColorKeys.has(key)) {
assertComposeColorValue(value, `composeStyle ${key}`);
continue;
}
if (typeof value !== "boolean") throw new Error(`Compose composeStyle ${key} must be a boolean`);
}
}
function assertString(value, name, nonEmpty = false) {
if (typeof value !== "string" || nonEmpty && !value.trim()) throw new Error(`Compose ${name} must be${nonEmpty ? " a non-empty" : ""} string`);
}
function assertOptionalString(value, name) {
if (value !== void 0) assertString(value, name);
}
function assertBoolean(value, name) {
if (typeof value !== "boolean") throw new Error(`Compose ${name} must be a boolean`);
}
function assertOptionalBoolean(value, name) {
if (value !== void 0) assertBoolean(value, name);
}
function assertOneOf(value, name, values) {
if (!values.includes(value)) throw new Error(`Compose ${name} must be one of ${values.join(", ")}`);
}
function assertFiniteNumber(value, name) {
if (typeof value !== "number" || !Number.isFinite(value)) throw new Error(`Compose ${name} must be a finite number`);
}
function assertFunction(value, name) {
if (typeof value !== "function") throw new Error(`Compose ${name} must be a function`);
}
function validateColumnProps(props) {
const horizontalAlignment = props.horizontalAlignment ?? "start";
const verticalArrangement = props.verticalArrangement ?? "top";
assertOneOf(horizontalAlignment, "Column horizontalAlignment", horizontalAlignments);
assertOneOf(verticalArrangement, "Column verticalArrangement", verticalArrangements);
if (props.spacing !== void 0 && (!Number.isFinite(props.spacing) || props.spacing < 0)) throw new Error("Compose Column spacing must be a nonnegative finite number");
if (props.spacing !== void 0 && verticalArrangement.startsWith("space")) throw new Error("Compose Column spacing cannot be combined with a space-distribution arrangement");
}
function validateRowProps(props) {
const verticalAlignment = props.verticalAlignment ?? "top";
const horizontalArrangement = props.horizontalArrangement ?? "start";
assertOneOf(verticalAlignment, "Row verticalAlignment", verticalAlignments);
assertOneOf(horizontalArrangement, "Row horizontalArrangement", horizontalArrangements);
if (props.spacing !== void 0 && (!Number.isFinite(props.spacing) || props.spacing < 0)) throw new Error("Compose Row spacing must be a nonnegative finite number");
if (props.spacing !== void 0 && horizontalArrangement.startsWith("space")) throw new Error("Compose Row spacing cannot be combined with a space-distribution arrangement");
}
function validateFlowRowProps(props) {
function arrangement(value, name, names) {
if (typeof value === "string") {
if (!names.includes(value)) throw new Error(`Compose FlowRow ${name} is unsupported`);
return;
}
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== 1 || !("spacedBy" in value) || typeof value.spacedBy !== "number" || !Number.isFinite(value.spacedBy) || value.spacedBy < 0) throw new Error(`Compose FlowRow ${name} spacedBy must be a nonnegative finite number`);
}
arrangement(props.horizontalArrangement ?? "start", "horizontalArrangement", horizontalArrangements);
arrangement(props.verticalArrangement ?? "top", "verticalArrangement", verticalArrangements);
}
function validateBoxProps(props) {
assertOneOf(props.contentAlignment ?? "topStart", "Box contentAlignment", contentAlignments);
}
function validateTextProps(props) {
assertString(props.text, "Text text");
if (props.fontSize !== void 0 && (!Number.isFinite(props.fontSize) || props.fontSize <= 0)) throw new Error("Compose Text fontSize must be a positive finite number");
if (props.fontWeight !== void 0) assertOneOf(props.fontWeight, "Text fontWeight", fontWeights);
if (props.textAlign !== void 0) assertOneOf(props.textAlign, "Text textAlign", textAlignments);
if (props.maxLines !== void 0 && (!Number.isInteger(props.maxLines) || props.maxLines <= 0)) throw new Error("Compose Text maxLines must be a positive integer");
}
function composeIconGlyph(owner, name) {
if (!Object.hasOwn(import_composeIcons.composeIconCodepoints, name)) throw new Error(`Compose ${owner} must be a Material Symbols name, got ${JSON.stringify(name)}`);
return String.fromCodePoint(import_composeIcons.composeIconCodepoints[name]);
}
function validateIconProps(props) {
assertString(props.name, "Icon name", true);
if (props.size !== void 0 && (!Number.isFinite(props.size) || props.size <= 0)) throw new Error("Compose Icon size must be a positive finite number");
assertOptionalBoolean(props.filled, "Icon filled");
composeIconGlyph("Icon name", props.name);
}
function validateButtonProps(props) {
assertString(props.label, "Button label", true);
assertBoolean(props.disabled ?? false, "Button disabled");
assertOneOf(props.variant ?? "filled", "Button variant", buttonVariants);
assertOneOf(props.tone ?? "default", "Button tone", buttonTones);
assertBoolean(props.iconFilled ?? false, "Button iconFilled");
if (props.icon !== void 0) composeIconGlyph("Button icon", props.icon);
if (props.onPress !== void 0) assertFunction(props.onPress, "Button onPress");
}
function validateIconButtonProps(props) {
assertBoolean(props.enabled ?? true, "IconButton enabled");
if (props.onClick !== void 0) assertFunction(props.onClick, "IconButton onClick");
if (props.colors !== void 0) assertComposeColors(props.colors, iconButtonColorKeys, "IconButton");
}
function validateFloatingActionButtonProps(props, variant) {
assertOneOf(variant, "FloatingActionButton variant", [
"small",
"medium",
"large",
"extended"
]);
assertBoolean(props.expanded ?? true, "FloatingActionButton expanded");
if (props.containerColor !== void 0) assertComposeColorValue(props.containerColor, "FloatingActionButton containerColor");
if (props.onClick !== void 0) assertFunction(props.onClick, "FloatingActionButton onClick");
}
function validateToggleButtonProps(props) {
assertBoolean(props.checked, "ToggleButton checked");
assertBoolean(props.enabled ?? true, "ToggleButton enabled");
if (props.onCheckedChange !== void 0) assertFunction(props.onCheckedChange, "ToggleButton onCheckedChange");
if (props.colors !== void 0) assertComposeColors(props.colors, toggleButtonColorKeys, "ToggleButton");
}
function validateSegmentedButtonProps(props) {
if (props.selected !== void 0) assertBoolean(props.selected, "SegmentedButton selected");
if (props.checked !== void 0) assertBoolean(props.checked, "SegmentedButton checked");
assertBoolean(props.enabled ?? true, "SegmentedButton enabled");
if (props.onClick !== void 0) assertFunction(props.onClick, "SegmentedButton onClick");
if (props.onCheckedChange !== void 0) assertFunction(props.onCheckedChange, "SegmentedButton onCheckedChange");
if (props.colors !== void 0) assertComposeColors(props.colors, segmentedButtonColorKeys, "SegmentedButton");
}
function validateSwitchProps(props) {
assertBoolean(props.isOn, "Switch isOn");
assertBoolean(props.disabled ?? false, "Switch disabled");
assertString(props.label ?? "", "Switch label");
assertFunction(props.onIsOnChange, "Switch onIsOnChange");
if (props.colors !== void 0) assertComposeColors(props.colors, switchColorKeys, "Switch");
}
function validateCheckboxProps(props) {
assertBoolean(props.value, "Checkbox value");
assertBoolean(props.disabled ?? false, "Checkbox disabled");
if (props.onCheckedChange !== void 0) assertFunction(props.onCheckedChange, "Checkbox onCheckedChange");
if (props.colors !== void 0) assertComposeColors(props.colors, checkboxColorKeys, "Checkbox");
}
function validateRadioButtonProps(props) {
assertBoolean(props.selected, "RadioButton selected");
assertBoolean(props.disabled ?? false, "RadioButton disabled");
if (props.onClick !== void 0) assertFunction(props.onClick, "RadioButton onClick");
if (props.colors !== void 0) assertComposeColors(props.colors, radioColorKeys, "RadioButton");
}
function validateCardProps(props, kind) {
if (props.colors !== void 0) assertComposeColors(props.colors, cardColorKeys, kind);
if (props.elevation !== void 0) {
assertFiniteNumber(props.elevation, `${kind} elevation`);
if (props.elevation < 0) throw new Error(`Compose ${kind} elevation must be nonnegative`);
}
if (kind === "ElevatedCard" && props.border !== void 0) throw new Error("Compose ElevatedCard does not support border");
assertComposeBorder(props.border, kind);
}
function validateSurfaceProps(props) {
if (props.color !== void 0) assertComposeColorValue(props.color, "Surface color");
if (props.contentColor !== void 0) assertComposeColorValue(props.contentColor, "Surface contentColor");
if (props.tonalElevation !== void 0) {
assertFiniteNumber(props.tonalElevation, "Surface tonalElevation");
if (props.tonalElevation < 0) throw new Error("Compose Surface tonalElevation must be nonnegative");
}
if (props.shadowElevation !== void 0) {
assertFiniteNumber(props.shadowElevation, "Surface shadowElevation");
if (props.shadowElevation < 0) throw new Error("Compose Surface shadowElevation must be nonnegative");
}
assertComposeBorder(props.border, "Surface");
assertOptionalBoolean(props.enabled, "Surface enabled");
assertOptionalBoolean(props.selected, "Surface selected");
assertOptionalBoolean(props.checked, "Surface checked");
if (props.onClick !== void 0) assertFunction(props.onClick, "Surface onClick");
if (props.onCheckedChange !== void 0) assertFunction(props.onCheckedChange, "Surface onCheckedChange");
}
function assertComposeBorder(border, kind) {
if (border === void 0) return;
if (!border || typeof border !== "object" || Array.isArray(border)) throw new Error(`Compose ${kind} border must be an object`);
for (const key of Object.keys(border)) if (key !== "width" && key !== "color") throw new Error(`Compose ${kind} border does not support ${key}`);
if (border.width !== void 0) {
assertFiniteNumber(border.width, `${kind} border width`);
if (border.width < 0) throw new Error(`Compose ${kind} border width must be nonnegative`);
}
if (border.color !== void 0) assertComposeColorValue(border.color, `${kind} border color`);
}
function validateChipProps(props, kind) {
const selected = "selected" in props ? props.selected : void 0;
if (kind === "FilterChip") assertBoolean(selected, `${kind} selected`);
else if (kind === "InputChip" && selected !== void 0) assertBoolean(selected, `${kind} selected`);
assertBoolean(props.enabled ?? true, `${kind} enabled`);
if (props.onClick !== void 0) assertFunction(props.onClick, `${kind} onClick`);
if (props.colors !== void 0) {
const keys = kind === "AssistChip" ? assistChipColorKeys : kind === "FilterChip" ? filterChipColorKeys : kind === "InputChip" ? inputChipColorKeys : suggestionChipColorKeys;
assertComposeColors(props.colors, keys, kind);
}
if (props.elevation !== void 0) {
assertFiniteNumber(props.elevation, `${kind} elevation`);
if (props.elevation < 0) throw new Error(`Compose ${kind} elevation must be nonnegative`);
}
assertComposeBorder(props.border, kind);
}
function validateDividerProps(props, kind) {
if (props.thickness !== void 0) {
assertFiniteNumber(props.thickness, `${kind} thickness`);
if (props.thickness < 0) throw new Error(`Compose ${kind} thickness must be nonnegative`);
}
if (props.color !== void 0) assertComposeColorValue(props.color, `${kind} color`);
}
function validateTextFieldProps(props) {
if (typeof props.text !== "string" && !(0, import_syncStore.isSyncState)(props.text)) throw new Error("Compose TextField text must be a string or NativeState handle");
assertFunction(props.onTextChange, "TextField onTextChange");
assertOptionalString(props.label, "TextField label");
assertOptionalString(props.placeholder, "TextField placeholder");
assertOptionalBoolean(props.disabled, "TextField disabled");
if (props.variant !== void 0) assertOneOf(props.variant, "TextField variant", textFieldVariants);
if (props.keyboardType !== void 0) assertOneOf(props.keyboardType, "TextField keyboardType", textFieldKeyboardTypes);
assertOptionalBoolean(props.secureText, "TextField secureText");
assertOptionalBoolean(props.focused, "TextField focused");
if (props.onFocusChange !== void 0) assertFunction(props.onFocusChange, "TextField onFocusChange");
if (props.imeAction !== void 0) assertOneOf(props.imeAction, "TextField imeAction", textFieldImeActions);
if (props.onSubmit !== void 0) assertFunction(props.onSubmit, "TextField onSubmit");
if (props.maxLength !== void 0 && (!Number.isInteger(props.maxLength) || props.maxLength < 0)) throw new Error("Compose TextField maxLength must be a nonnegative integer");
assertOptionalBoolean(props.multiline, "TextField multiline");
if (props.capitalization !== void 0) assertOneOf(props.capitalization, "TextField capitalization", textFieldCapitalizations);
assertOptionalBoolean(props.autoCorrect, "TextField autoCorrect");
if (props.textAlign !== void 0) assertOneOf(props.textAlign, "TextField textAlign", textAlignments);
}
function validateSliderProps(props) {
const minimumValue = props.minimumValue ?? 0;
const maximumValue = props.maximumValue ?? 1;
const step = props.step ?? 0;
assertFiniteNumber(props.value, "Slider value");
assertFiniteNumber(minimumValue, "Slider minimumValue");
assertFiniteNumber(maximumValue, "Slider maximumValue");
assertFiniteNumber(step, "Slider step");
if (props.lowerLimit !== void 0) assertFiniteNumber(props.lowerLimit, "Slider lowerLimit");
if (props.upperLimit !== void 0) assertFiniteNumber(props.upperLimit, "Slider upperLimit");
if (props.lowerLimit !== void 0 && !Number.isFinite(Math.fround(props.lowerLimit)) || props.upperLimit !== void 0 && !Number.isFinite(Math.fround(props.upperLimit))) throw new Error("Compose Slider limits must be representable by Android Float values");
if (minimumValue >= maximumValue) throw new Error("Compose Slider minimumValue must be less than maximumValue");
if (!Number.isFinite(Math.fround(minimumValue)) || !Number.isFinite(Math.fround(maximumValue)) || Math.fround(minimumValue) >= Math.fround(maximumValue)) throw new Error("Compose Slider range must be representable by Android Float values");
if (step < 0) throw new Error("Compose Slider step must be a nonnegative finite number");
if (step > 0) {
const intervals = (maximumValue - minimumValue) / step;
const roundedIntervals = Math.round(intervals);
if (Math.abs(intervals - roundedIntervals) > Number.EPSILON * Math.max(1, Math.abs(intervals)) * 8) throw new Error("Compose Slider step must evenly divide its range");
if (roundedIntervals > 1001) throw new Error("Compose Slider step must produce at most 1001 intervals");
}
if (props.value < minimumValue || props.value > maximumValue) throw new Error("Compose Slider value must be between minimumValue and maximumValue");
if (Math.max(Math.fround(minimumValue), Math.fround(props.lowerLimit ?? minimumValue)) > Math.min(Math.fround(maximumValue), Math.fround(props.upperLimit ?? maximumValue))) throw new Error("Compose Slider limits must overlap the value range");
assertFunction(props.onValueChange, "Slider onValueChange");
assertOptionalBoolean(props.disabled, "Slider disabled");
if (props.colors !== void 0) assertComposeColors(props.colors, sliderColorKeys, "Slider");
}
function validateAlertDialogProps(props) {
assertBoolean(props.visible, "AlertDialog visible");
assertOptionalString(props.title, "AlertDialog title");
assertOptionalString(props.message, "AlertDialog message");
assertString(props.confirmLabel, "AlertDialog confirmLabel", true);
assertOptionalString(props.dismissLabel, "AlertDialog dismissLabel");
assertFunction(props.onConfirm, "AlertDialog onConfirm");
assertFunction(props.onDismiss, "AlertDialog onDismiss");
}
function validateDialogProps(props) {
assertBoolean(props.visible, "Dialog visible");
assertFunction(props.onDismiss, "Dialog onDismiss");
}
function validateProgressIndicatorProps(props) {
if (props.variant !== void 0) assertOneOf(props.variant, "ProgressIndicator variant", progressVariants);
if (props.progress != null && (typeof props.progress !== "number" || !Number.isFinite(props.progress) || props.progress < 0 || props.progress > 1)) throw new Error("Compose ProgressIndicator progress must be a number from 0 to 1");
if (props.color !== void 0) assertComposeColorValue(props.color, "ProgressIndicator color");
if (props.trackColor !== void 0) assertComposeColorValue(props.trackColor, "ProgressIndicator trackColor");
const variant = props.variant ?? "circular";
if (props.strokeCap !== void 0) {
assertOneOf(props.strokeCap, "ProgressIndicator strokeCap", progressStrokeCaps);
if (variant !== "linear" && variant !== "circular") throw new Error("Compose ProgressIndicator strokeCap requires a regular indicator");
}
for (const key of [
"gapSize",
"strokeWidth",
"stopSize",
"amplitude",
"wavelength",
"waveSpeed"
]) {
const value = props[key];
if (value === void 0) continue;
assertFiniteNumber(value, `ProgressIndicator ${key}`);
if (value < 0 || key === "amplitude" && value > 1) throw new Error(`Compose ProgressIndicator ${key} is out of range`);
}
if (props.gapSize !== void 0 && variant !== "linear" && variant !== "circular") throw new Error("Compose ProgressIndicator gapSize requires a regular indicator");
if (props.strokeWidth !== void 0 && variant !== "circular") throw new Error("Compose ProgressIndicator strokeWidth requires a circular indicator");
if (props.stopSize !== void 0 && variant !== "linearWavy") throw new Error("Compose ProgressIndicator stopSize requires a linear wavy indicator");
if ((props.amplitude !== void 0 || props.wavelength !== void 0 || props.waveSpeed !== void 0) && variant !== "linearWavy" && variant !== "circularWavy") throw new Error("Compose ProgressIndicator wave settings require a wavy indicator");
if (props.drawStopIndicator !== void 0) {
if (variant !== "linear" || props.progress == null) throw new Error("Compose ProgressIndicator drawStopIndicator requires determinate linear progress");
const stop = props.drawStopIndicator;
if (typeof stop !== "object" || stop === null || Array.isArray(stop)) throw new Error("Compose ProgressIndicator drawStopIndicator must be an object");
for (const key of Object.keys(stop)) if (key !== "color" && key !== "strokeCap" && key !== "stopSize") throw new Error(`Compose ProgressIndicator drawStopIndicator has unknown key ${key}`);
if (stop.color !== void 0) assertComposeColorValue(stop.color, "ProgressIndicator drawStopIndicator color");
if (stop.strokeCap !== void 0) assertOneOf(stop.strokeCap, "ProgressIndicator drawStopIndicator strokeCap", progressStrokeCaps);
if (stop.stopSize !== void 0) {
assertFiniteNumber(stop.stopSize, "ProgressIndicator drawStopIndicator stopSize");
if (stop.stopSize < 0) throw new Error("Compose ProgressIndicator drawStopIndicator stopSize must be nonnegative");
}
}
}
function validateLoadingIndicatorProps(props) {
if (props.progress != null && (typeof props.progress !== "number" || !Number.isFinite(props.progress) || props.progress < 0 || props.progress > 1)) throw new Error("Compose LoadingIndicator progress must be a number from 0 to 1");
if (props.color !== void 0) assertComposeColorValue(props.color, "LoadingIndicator color");
if ("containerColor" in props && props.containerColor !== void 0) assertComposeColorValue(props.containerColor, "ContainedLoadingIndicator containerColor");
}
const datePickerColorKeys = new Set(import_composeTypes.composeDatePickerColorKeys);
const timePickerColorKeys = new Set(import_composeTypes.composeTimePickerColorKeys);
const pickerVariants = ["picker", "input"];
function assertDate(value, name) {
if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw new Error(`Compose ${name} must be a valid Date`);
}
function composeUtcDay(date) {
return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
}
function validatePickerShared(props, owner) {
assertDate(props.selection, `${owner} selection`);
if (props.variant !== void 0) assertOneOf(props.variant, `${owner} variant`, pickerVariants);
if (props.color !== void 0) assertComposeColorValue(props.color, `${owner} color`);
}
function validateDatePickerProps(props, owner = "DatePicker") {
validatePickerShared(props, owner);
assertOptionalBoolean(props.showModeToggle, `${owner} showModeToggle`);
if (props.minimumDate !== void 0) assertDate(props.minimumDate, `${owner} minimumDate`);
if (props.maximumDate !== void 0) assertDate(props.maximumDate, `${owner} maximumDate`);
const day = composeUtcDay(props.selection);
const minimum = props.minimumDate && composeUtcDay(props.minimumDate);
const maximum = props.maximumDate && composeUtcDay(props.maximumDate);
if (minimum !== void 0 && maximum !== void 0 && minimum > maximum) throw new Error(`Compose ${owner} minimumDate must not be after maximumDate`);
if (minimum !== void 0 && day < minimum || maximum !== void 0 && day > maximum) throw new Error(`Compose ${owner} selection must be between minimumDate and maximumDate`);
if (props.colors !== void 0) assertComposeColors(props.colors, datePickerColorKeys, owner);
}
function validateTimePickerProps(props, owner = "TimePicker") {
validatePickerShared(props, owner);
assertOptionalBoolean(props.is24Hour, `${owner} is24Hour`);
if (props.colors !== void 0) assertComposeColors(props.colors, timePickerColorKeys, owner);
}
function validatePickerDialogProps(props, owner) {
assertBoolean(props.visible, `${owner} visible`);
assertFunction(props.onConfirm, `${owner} onConfirm`);
assertFunction(props.onDismiss, `${owner} onDismiss`);
assertOptionalString(props.confirmLabel, `${owner} confirmLabel`);
assertOptionalString(props.dismissLabel, `${owner} dismissLabel`);
}
const lazyAlignments = [
"start",
"end",
"center"
];
const lazyRowAlignments = [
"top",
"bottom",
"center"
];
const lazyContentPaddingKeys = [
"start",
"end",
"top",
"bottom"
];
const imageContentScales = [
"fit",
"crop",
"fillBounds",
"fillWidth",
"fillHeight",
"inside",
"none"
];
const snackbarColorKeys = /* @__PURE__ */ new Set([
"containerColor",
"contentColor",
"actionColor",
"actionContentColor",
"dismissActionContentColor"
]);
const snackbarPropKeys = /* @__PURE__ */ new Set([...snackbarColorKeys, "actionOnNewLine"]);
const snackbarDurations = [
"short",
"long",
"indefinite"
];
const sheetPropertyKeys = /* @__PURE__ */ new Set(["shouldDismissOnClickOutside"]);
function assertSpacedBy(value, owner, name) {
if (value === void 0) return void 0;
if (typeof value === "string") {
assertOneOf(value, `${owner} ${name}`, name === "horizontalArrangement" ? horizontalArrangements : verticalArrangements);
return value;
}
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== 1 || !("spacedBy" in value)) throw new Error(`Compose ${owner} ${name} must be a preset or { spacedBy }`);
const spacedBy = value.spacedBy;
if (typeof spacedBy !== "number" || !Number.isFinite(spacedBy) || spacedBy < 0) throw new Error(`Compose ${owner} ${name} spacedBy must be a nonnegative finite number`);
return spacedBy;
}
function assertLazyContentPadding(value, owner) {
if (value === void 0) return;
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`Compose ${owner} contentPadding must be an object`);
for (const [key, entry] of Object.entries(value)) {
if (!lazyContentPaddingKeys.includes(key)) throw new Error(`Compose ${owner} contentPadding has unknown key ${key}`);
if (entry !== void 0 && (typeof entry !== "number" || !Number.isFinite(entry) || entry < 0)) throw new Error(`Compose ${owner} contentPadding ${key} must be a nonnegative finite number`);
}
}
function validateLazyColumnProps(props) {
assertOneOf(props.horizontalAlignment ?? "start", "LazyColumn horizontalAlignment", lazyAlignments);
assertSpacedBy(props.verticalArrangement ?? "top", "LazyColumn", "verticalArrangement");
assertLazyContentPadding(props.contentPadding, "LazyColumn");
}
function validateLazyRowProps(props) {
assertOneOf(props.verticalAlignment ?? "top", "LazyRow verticalAlignment", lazyRowAlignments);
assertSpacedBy(props.horizontalArrangement ?? "start", "LazyRow", "horizontalArrangement");
assertLazyContentPadding(props.contentPadding, "LazyRow");
}
function validateImageProps(props) {
const source = props.source;
const validSource = typeof source === "number" && Number.isFinite(source) || source !== null && typeof source === "object" && !Array.isArray(source) && typeof source.uri === "string" && source.uri.length > 0;
if (!validSource) throw new Error("Compose Image source must be a { uri } object or a bundled asset id");
if (props.contentScale !== void 0) assertOneOf(props.contentScale, "Image contentScale", imageContentScales);
if (props.alignment !== void 0) assertOneOf(props.alignment, "Image alignment", contentAlignments);
if (props.contentDescription !== void 0 && props.contentDescription !== null && typeof props.contentDescription !== "string") throw new Error("Compose Image contentDescription must be a string or null");
if (props.tint !== void 0) assertComposeColorValue(props.tint, "Image tint");
if (props.alpha !== void 0 && (typeof props.alpha !== "number" || !(props.alpha >= 0 && props.alpha <= 1))) throw new Error("Compose Image alpha must be a number from 0 to 1");
if (props.onLoad !== void 0) assertFunction(props.onLoad, "Image onLoad");
if (props.onError !== void 0) assertFunction(props.onError, "Image onError");
}
function validateSnackbarProps(props) {
for (const [key, value] of Object.entries(props)) {
if (key === "children") continue;
if (!snackbarPropKeys.has(key)) throw new Error(`Compose Snackbar colors does not support ${key}`);
if (key === "actionOnNewLine") {
if (value !== void 0) assertBoolean(value, "Snackbar actionOnNewLine");
} else if (value !== void 0) assertComposeColorValue(value, `Snackbar ${key}`);
}
}
function validateSnackbarShowOptions(options) {
if (!options || typeof options !== "object" || Array.isArray(options)) throw new Error("Compose SnackbarHost message must be a non-empty string");
if (typeof options.message !== "string" || !options.message.trim()) throw new Error("Compose SnackbarHost message must be a non-empty string");
if (options.actionLabel !== void 0 && typeof options.actionLabel !== "string") throw new Error("Compose SnackbarHost actionLabel must be a string");
if (options.duration !== void 0) assertOneOf(options.duration, "SnackbarHost duration", snackbarDurations);
if (options.withDismissAction !== void 0) assertBoolean(options.withDismissAction, "SnackbarHost withDismissAction");
}
const navigationBarItemColorKeys = /* @__PURE__ */ new Set([
"selectedIconColor",
"selectedTextColor",
"indicatorColor",
"unselectedIconColor",
"unselectedTextColor",
"disabledIconColor",
"disabledTextColor"
]);
function validateNavigationBarProps(props) {
if (props.containerColor !== void 0) assertComposeColorValue(props.containerColor, "NavigationBar containerColor");
if (props.contentColor !== void 0) assertComposeColorValue(props.contentColor, "NavigationBar contentColor");
if (props.tonalElevation !== void 0) {
assertFiniteNumber(props.tonalElevation, "NavigationBar tonalElevation");
if (props.tonalElevation < 0) throw new Error("Compose NavigationBar tonalElevation must be nonnegative");
}
}
function validateNavigationBarItemProps(props) {
assertBoolean(props.selected, "NavigationBarItem selected");
assertFunction(props.onClick, "NavigationBarItem onClick");
assertOptionalString(props.label, "NavigationBarItem label");
assertString(props.icon, "NavigationBarItem icon", true);
composeIconGlyph("NavigationBarItem icon", props.icon);
assertOptionalBoolean(props.iconFilled, "NavigationBarItem iconFilled");
assertOptionalBoolean(props.enabled, "NavigationBarItem enabled");
assertOptionalBoolean(props.alwaysShowLabel, "NavigationBarItem alwaysShowLabel");
if (props.colors !== void 0) assertComposeColors(props.colors, navigationBarItemColorKeys, "NavigationBarItem");
}
function validateSearchBarProps(props, owner = "SearchBar") {
assertString(props.query, `${owner} query`);
assertFunction(props.onQueryChange, `${owner} onQueryChange`);
assertBoolean(props.expanded, `${owner} expanded`);
assertFunction(props.onExpandedChange, `${owner} onExpandedChange`);
assertOptionalString(props.placeholder, `${owner} placeholder`);
assertOptionalBoolean(props.enabled, `${owner} enabled`);
if (props.onSearch !== void 0) assertFunction(props.onSearch, `${owner} onSearch`);
if (props.containerColor !== void 0) assertComposeColorValue(props.containerColor, `${owner} containerColor`);
}
const dropdownMenuItemColorKeys = /* @__PURE__ */ new Set([
"textColor",
"leadingIconColor",
"trailingIconColor",
"disabledTextColor",
"disabledLeadingIconColor",
"disabledTrailingIconColor"
]);
function validateDropdownMenuProps(props) {
assertBoolean(props.expanded, "DropdownMenu expanded");
assertFunction(props.onDismissRequest, "DropdownMenu onDismissRequest");
if (props.containerColor !== void 0) assertComposeColorValue(props.containerColor, "DropdownMenu containerColor");
}
function validateDropdownMenuItemProps(props) {
assertString(props.text, "DropdownMenuItem text", true);
assertFunction(props.onClick, "DropdownMenuItem onClick");
assertOptionalBoolean(props.enabled, "DropdownMenuItem enabled");
if (props.leadingIcon !== void 0) {
assertString(props.leadingIcon, "DropdownMenuItem leadingIcon", true);
composeIconGlyph("DropdownMenuItem leadingIcon", props.leadingIcon);
}
if (props.trailingIcon !== void 0) {
assertString(props.trailingIcon, "DropdownMenuItem trailingIcon", true);
composeIconGlyph("DropdownMenuItem trailingIcon", props.trailingIcon);
}
assertOptionalBoolean(props.iconFilled, "DropdownMenuItem iconFilled");
if (props.colors !== void 0) assertComposeColors(props.colors, dropdownMenuItemColorKeys, "DropdownMenuItem");
}
function validateExposedDropdownMenuBoxProps(props) {
assertBoolean(props.expanded, "ExposedDropdownMenuBox expanded");
assertFunction(props.onExpandedChange, "ExposedDropdownMenuBox onExpandedChange");
assertString(props.value, "ExposedDropdownMenuBox value");
assertOptionalString(props.placeholder, "ExposedDropdownMenuBox placeholder");
assertOptionalBoolean(props.enabled, "ExposedDropdownMenuBox enabled");
}
function validatePullToRefreshBoxProps(props) {
assertBoolean(props.isRefreshing, "PullToRefreshBox isRefreshing");
assertFunction(props.onRefresh, "PullToRefreshBox onRefresh");
assertOptionalBoolean(props.enabled, "PullToRefreshBox enabled");
}
const animatedVisibilityTransitions = [
"fade",
"scale",
"slideVertically",
"expandVertically"
];
function validateTooltipBoxProps(props) {
assertString(props.text, "TooltipBox text", true);
assertOptionalString(props.title, "TooltipBox title");
assertOptionalBoolean(props.enabled, "TooltipBox enabled");
}
function validateAnimatedVisibilityProps(props) {
assertBoolean(props.visible, "AnimatedVisibility visible");
if (props.enter !== void 0) assertOneOf(props.enter, "AnimatedVisibility enter", animatedVisibilityTransitions);
if (props.exit !== void 0) assertOneOf(props.exit, "AnimatedVisibility exit", animatedVisibilityTransitions);
}
function validateModalBottomSheetProps(props) {
assertFunction(props.onDismissRequest, "ModalBottomSheet onDismissRequest");
if (props.properties !== void 0) {
if (!props.properties || typeof props.properties !== "object" || Array.isArray(props.properties)) throw new Error("Compose ModalBottomSheet properties must be an object");
for (const [key, value] of Object.entries(props.properties)) {
if (!sheetPropertyKeys.has(key)) throw new Error(`Compose ModalBottomSheet properties has unknown key ${key}`);
if (value !== void 0) assertBoolean(value, `ModalBottomSheet properties ${key}`);
}
}
if (props.scrimColor !== void 0) assertComposeColorValue(props.scrimColor, "ModalBottomSheet scrimColor");
assertOptionalBoolean(props.skipPartiallyExpanded, "ModalBottomSheet skipPartiallyExpanded");
assertOptionalBoolean(props.initialFullyExpanded, "ModalBottomSheet initialFullyExpanded");
assertOptionalBoolean(props.showDragHandle, "ModalBottomSheet showDragHandle");
assertOptionalBoolean(props.sheetGesturesEnabled, "ModalBottomSheet sheetGesturesEnabled");
}