UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

862 lines (859 loc) • 38.1 kB
import { jsx } from "react/jsx-runtime"; import { Children, isValidElement, useContext, useRef, useState } from "react"; import { Platform } from "react-native"; import { dispatchSDKEvent, swiftStyleNative, validSDKEventValue } from "./generated/swiftStyleNative.native.js"; import { viewSlotArguments, viewSlotAvailability, viewSlotEvents } from "./generated/viewSlots.native.js"; import NativeButton from "./specs/OneNativeButtonNativeComponent.native.js"; import NativeContainerSlot from "./specs/OneNativeContainerSlotNativeComponent.native.js"; import NativeControlGroup from "./specs/OneNativeControlGroupNativeComponent.native.js"; import NativeDisclosureGroup from "./specs/OneNativeDisclosureGroupNativeComponent.native.js"; import NativeDivider from "./specs/OneNativeDividerNativeComponent.native.js"; import NativeForm from "./specs/OneNativeFormNativeComponent.native.js"; import NativeGlass from "./specs/OneNativeGlassNativeComponent.native.js"; import NativeGlassEffectContainer from "./specs/OneNativeGlassEffectContainerNativeComponent.native.js"; import NativeGeometryReader from "./specs/OneNativeGeometryReaderNativeComponent.native.js"; import NativeGroup from "./specs/OneNativeGroupNativeComponent.native.js"; import NativeHost from "./specs/OneNativeHostNativeComponent.native.js"; import NativeLabeledContent from "./specs/OneNativeLabeledContentNativeComponent.native.js"; import NativeGroupBox from "./specs/OneNativeGroupBoxNativeComponent.native.js"; import NativeViewThatFits from "./specs/OneNativeViewThatFitsNativeComponent.native.js"; import NativeLazyHStack from "./specs/OneNativeLazyHStackNativeComponent.native.js"; import NativeLazyVStack from "./specs/OneNativeLazyVStackNativeComponent.native.js"; import NativeLazyVGrid from "./specs/OneNativeLazyVGridNativeComponent.native.js"; import NativeLazyHGrid from "./specs/OneNativeLazyHGridNativeComponent.native.js"; import NativeGrid from "./specs/OneNativeGridNativeComponent.native.js"; import NativeGridRow from "./specs/OneNativeGridRowNativeComponent.native.js"; import NativeLink from "./specs/OneNativeLinkNativeComponent.native.js"; import NativeList from "./specs/OneNativeListNativeComponent.native.js"; import NativeOverlay from "./specs/OneNativeOverlayNativeComponent.native.js"; import NativeOverlayContent from "./specs/OneNativeOverlayContentNativeComponent.native.js"; import NativeScrollView from "./specs/OneNativeScrollViewNativeComponent.native.js"; import NativeScrollViewReader, { Commands } from "./specs/OneNativeScrollViewReaderNativeComponent.native.js"; import NativeSwipeActions from "./specs/OneNativeSwipeActionsNativeComponent.native.js"; import NativeSwipeActionsActions from "./specs/OneNativeSwipeActionsActionsNativeComponent.native.js"; import NativeSection from "./specs/OneNativeSectionNativeComponent.native.js"; import NativeSpacer from "./specs/OneNativeSpacerNativeComponent.native.js"; import NativeZStack from "./specs/OneNativeZStackNativeComponent.native.js"; import { assertSwiftUIValue } from "./generated/swiftui.native.js"; import { useControlled } from "./controlled.native.js"; import { labeledContentProps } from "./labeledContent.native.js"; import { Pager } from "./Pager.native.js"; import { Tabs } from "./Tabs.native.js"; import { viewportStyle } from "./viewportStyle.native.js"; import { lazyHStackAlignments, lazyVStackAlignments, scrollViewAxes, unitPoints } from "./listTypes.native.js"; import { swipeActionsEdges, viewThatFitsAxes } from "./groupTypes.native.js"; import { hostAlignments, hostAxes, zStackAlignments } from "./generated/containerTypes.native.js"; import { glassEffectShapes, glassEffects, materials } from "./generated/controlTypes.native.js"; import { InsideContainer, assertOneNativeChildren } from "./containerChildren.native.js"; import { NavigationStack } from "./NavigationStack.native.js"; import { gridAlignments, gridHorizontalAlignments, gridItems, gridSpacing, gridVerticalAlignments } from "./gridTypes.native.js"; var containers = "Swift.Host, Swift.HStack, Swift.VStack, Swift.ZStack, Swift.Form, Swift.Section, Swift.Glass, Swift.GroupBox, Swift.ViewThatFits, Swift.GlassEffectContainer, Swift.List, Swift.ScrollView, Swift.LazyVStack, Swift.LazyHStack, Swift.LazyVGrid, Swift.LazyHGrid, Swift.Grid, Swift.GridRow, Swift.ControlGroup, Swift.DisclosureGroup, Swift.Link, Swift.Group, Swift.Overlay, Swift.SwipeActions, Swift.NavigationStack, Swift.Toolbar, or Swift.ToolbarItem"; function nativeEnvironmentProps(param) { var { colorScheme, dynamicTypeSize, controlSize, locale, tint, isEnabled } = param; var iosVersion = Number.parseFloat(String(Platform.Version)); if (colorScheme) assertSwiftUIValue("ColorScheme", colorScheme, iosVersion); if (dynamicTypeSize) assertSwiftUIValue("DynamicTypeSize", dynamicTypeSize, iosVersion); if (controlSize) assertSwiftUIValue("ControlSize", controlSize, iosVersion); if (locale !== void 0 && (typeof locale !== "string" || !locale.trim())) throw new Error("Swift.Host and Swift.Form locale must be a non-empty identifier"); return { colorScheme: colorScheme !== null && colorScheme !== void 0 ? colorScheme : "", dynamicTypeSize: dynamicTypeSize !== null && dynamicTypeSize !== void 0 ? dynamicTypeSize : "", controlSize: controlSize !== null && controlSize !== void 0 ? controlSize : "", locale: locale !== null && locale !== void 0 ? locale : "", tint, isEnabled: isEnabled === void 0 ? "" : isEnabled ? "enabled" : "disabled" }; } function assertNoGreedyContainer(children, owner) { var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var child = _step.value; if (!/* @__PURE__ */ isValidElement(child)) continue; var name = child.type === Form ? "Swift.Form" : child.type === List ? "Swift.List" : child.type === ScrollView ? "Swift.ScrollView" : child.type === Tabs ? "Swift.Tabs" : child.type === Pager ? "Swift.Pager" : child.type === NavigationStack ? "Swift.NavigationStack" : null; if (name) throw new Error(`${name} cannot be a child of ${owner}; give it its own box`); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } } function HostStack(param) { var { name, axis, spacing = 0, alignment = "leading", colorScheme, dynamicTypeSize, controlSize, locale, tint, isEnabled, children, style, ...props } = param; if (!hostAxes.includes(axis)) throw new Error(`${name} axis must be one of ${hostAxes.join(", ")}`); if (!hostAlignments.includes(alignment)) throw new Error(`${name} alignment must be one of ${hostAlignments.join(", ")}`); if (!Number.isFinite(spacing) || spacing < 0) throw new Error(`${name} spacing must be a non-negative number`); assertNoGreedyContainer(children, name); assertOneNativeChildren(children, name); return /* @__PURE__ */ jsx(NativeHost, { ...props, style: [{ alignSelf: "stretch" }, style], axis, spacing, alignment, ...nativeEnvironmentProps({ colorScheme, dynamicTypeSize, controlSize, locale, tint, isEnabled }), children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Host(param) { var { axis = "vertical", ...props } = param; return /* @__PURE__ */ jsx(HostStack, { ...props, name: "Swift.Host", axis }); } function HStack(props) { return /* @__PURE__ */ jsx(HostStack, { ...props, name: "Swift.HStack", axis: "horizontal" }); } function VStack(props) { return /* @__PURE__ */ jsx(HostStack, { ...props, name: "Swift.VStack", axis: "vertical" }); } function ZStack(param) { var { alignment = "center", children, style, ...props } = param; if (!zStackAlignments.includes(alignment)) throw new Error(`Swift.ZStack alignment must be one of ${zStackAlignments.join(", ")}`); assertNoGreedyContainer(children, "Swift.ZStack"); assertOneNativeChildren(children, "Swift.ZStack"); return /* @__PURE__ */ jsx(NativeZStack, { ...props, style: [{ alignSelf: "stretch" }, style], alignment, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Spacer(param) { var { minLength = 0, style, ...props } = param; var inside = useContext(InsideContainer); if (!inside) throw new Error(`Swift.Spacer must be a child of ${containers}`); if (!Number.isFinite(minLength) || minLength < 0) throw new Error("Swift.Spacer minLength must be a non-negative number"); return /* @__PURE__ */ jsx(NativeSpacer, { ...props, style, minLength }); } var formSizings = ["fill", "content"]; function Form(param) { var { children, style, sizing = "fill", colorScheme, dynamicTypeSize, controlSize, locale, tint, isEnabled, ...props } = param; if (!formSizings.includes(sizing)) throw new Error(`Swift.Form sizing must be one of ${formSizings.join(", ")}`); assertOneNativeChildren(children, "Swift.Form"); return /* @__PURE__ */ jsx(NativeForm, { ...props, ...nativeEnvironmentProps({ colorScheme, dynamicTypeSize, controlSize, locale, tint, isEnabled }), sizing, style: sizing === "content" ? [{ alignSelf: "stretch" }, style] : [{ flex: 1 }, style], children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }, sizing); } function Section(param) { var { title = "", footer = "", children, swiftStyle, style, ...props } = param; if (typeof title !== "string" || typeof footer !== "string") throw new Error("Swift.Section title and footer must be strings"); assertOneNativeChildren(children, "Swift.Section"); return /* @__PURE__ */ jsx(NativeSection, { ...props, style: [{ flex: 1 }, style], title, footer, swiftStyle: swiftStyleNative(swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return dispatchSDKEvent(swiftStyle, nativeEvent.name, nativeEvent.value); }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function List(param) { var { listStyle = "automatic", children, selection, onSelectionChange, swiftStyle, style, ...props } = param; assertSwiftUIValue("ListStyle", listStyle, Number.parseFloat(String(Platform.Version))); if (selection !== void 0 && (!Array.isArray(selection) || selection.some(function(value) { return typeof value !== "string"; }) || new Set(selection).size !== selection.length)) throw new Error("Swift.List selection must contain unique string tags"); assertOneNativeChildren(children, "Swift.List"); return /* @__PURE__ */ jsx(NativeList, { ...props, style: viewportStyle(style), listStyle, selection: JSON.stringify(selection !== null && selection !== void 0 ? selection : []), selectionIsControlled: selection !== void 0, swiftStyle: swiftStyleNative(swiftStyle), onNativeListSelectionChange: function onNativeListSelectionChange(param2) { var { nativeEvent } = param2; var next = JSON.parse(nativeEvent.selection); if (!Array.isArray(next) || next.some(function(value) { return typeof value !== "string"; }) || new Set(next).size !== next.length) throw new Error("Swift.List received an invalid native selection"); onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(next); }, onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return dispatchSDKEvent(swiftStyle, nativeEvent.name, nativeEvent.value); }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function ScrollView(param) { var { axes = "vertical", showsIndicators = true, children, swiftStyle, style, ...props } = param; if (!scrollViewAxes.includes(axes)) throw new Error(`Swift.ScrollView axes must be one of ${scrollViewAxes.join(", ")}`); assertOneNativeChildren(children, "Swift.ScrollView"); return /* @__PURE__ */ jsx(NativeScrollView, { ...props, style: viewportStyle(style), axes, showsIndicators, swiftStyle: swiftStyleNative(swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return dispatchSDKEvent(swiftStyle, nativeEvent.name, nativeEvent.value); }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function unitPoint(anchor) { if (typeof anchor === "string") { if (!Object.hasOwn(unitPoints, anchor)) throw new Error(`Swift.ScrollViewProxy.scrollTo anchor must be a UnitPoint: one of ${Object.keys(unitPoints).join(", ")}, or { x, y }`); return unitPoints[anchor]; } if (typeof anchor !== "object" || !Number.isFinite(anchor.x) || !Number.isFinite(anchor.y)) throw new Error("Swift.ScrollViewProxy.scrollTo anchor { x, y } must be finite numbers"); return anchor; } function ScrollViewReader(param) { var { children, style, ...props } = param; var host = useRef(null); var building = useRef(false); var [proxy] = useState(function() { return { scrollTo(id, anchor) { var _ref, _ref1; if (building.current) throw new Error("Swift.ScrollViewProxy.scrollTo cannot run while Swift.ScrollViewReader builds its content; call it from an event handler or effect"); if (typeof id !== "string") throw new Error("Swift.ScrollViewProxy.scrollTo id must be a string matching a swiftStyle.id"); var point = anchor == null ? null : unitPoint(anchor); if (!host.current) throw new Error("Swift.ScrollViewProxy.scrollTo needs its Swift.ScrollViewReader mounted"); Commands.scrollTo(host.current, id, point !== null, (_ref = point === null || point === void 0 ? void 0 : point.x) !== null && _ref !== void 0 ? _ref : 0, (_ref1 = point === null || point === void 0 ? void 0 : point.y) !== null && _ref1 !== void 0 ? _ref1 : 0); } }; }); if (typeof children !== "function") throw new Error("Swift.ScrollViewReader takes a render function of its proxy; pass (proxy) => content"); building.current = true; var content; try { content = children(proxy); } finally { building.current = false; } assertOneNativeChildren(content, "Swift.ScrollViewReader"); return /* @__PURE__ */ jsx(NativeScrollViewReader, { ...props, ref: host, style: viewportStyle(style), children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children: content }) }); } function LazyVStack(param) { var { alignment = "center", spacing, children, style, ...props } = param; if (!lazyVStackAlignments.includes(alignment)) throw new Error(`Swift.LazyVStack alignment must be one of ${lazyVStackAlignments.join(", ")}`); if (spacing !== void 0 && (!Number.isFinite(spacing) || spacing < 0)) throw new Error("Swift.LazyVStack spacing must be a non-negative number"); assertOneNativeChildren(children, "Swift.LazyVStack"); return /* @__PURE__ */ jsx(NativeLazyVStack, { ...props, style: [{ alignSelf: "stretch" }, style], alignment, spacing: spacing !== null && spacing !== void 0 ? spacing : -1, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function LazyHStack(param) { var { alignment = "center", spacing, children, style, ...props } = param; if (!lazyHStackAlignments.includes(alignment)) throw new Error(`Swift.LazyHStack alignment must be one of ${lazyHStackAlignments.join(", ")}`); if (spacing !== void 0 && (!Number.isFinite(spacing) || spacing < 0)) throw new Error("Swift.LazyHStack spacing must be a non-negative number"); assertOneNativeChildren(children, "Swift.LazyHStack"); return /* @__PURE__ */ jsx(NativeLazyHStack, { ...props, style: [{ alignSelf: "stretch" }, style], alignment, spacing: spacing !== null && spacing !== void 0 ? spacing : -1, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function LazyVGrid(param) { var { columns, alignment = "center", spacing, children, style, ...props } = param; if (!gridHorizontalAlignments.includes(alignment)) throw new Error("Swift.LazyVGrid alignment must be leading, center, or trailing"); assertOneNativeChildren(children, "Swift.LazyVGrid"); return /* @__PURE__ */ jsx(NativeLazyVGrid, { ...props, style: [{ alignSelf: "stretch" }, style], columns: gridItems(columns, "Swift.LazyVGrid"), alignment, spacing: gridSpacing(spacing, "Swift.LazyVGrid"), children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function LazyHGrid(param) { var { rows, alignment = "center", spacing, children, style, ...props } = param; if (!gridVerticalAlignments.includes(alignment)) throw new Error("Swift.LazyHGrid alignment must be a SwiftUI VerticalAlignment"); assertOneNativeChildren(children, "Swift.LazyHGrid"); return /* @__PURE__ */ jsx(NativeLazyHGrid, { ...props, style: [{ alignSelf: "stretch" }, style], rows: gridItems(rows, "Swift.LazyHGrid"), alignment, spacing: gridSpacing(spacing, "Swift.LazyHGrid"), children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Grid(param) { var { alignment = "center", horizontalSpacing, verticalSpacing, children, style, ...props } = param; if (!gridAlignments.includes(alignment)) throw new Error("Swift.Grid alignment must be a SwiftUI Alignment"); assertOneNativeChildren(children, "Swift.Grid"); return /* @__PURE__ */ jsx(NativeGrid, { ...props, style: [{ alignSelf: "stretch" }, style], alignment, horizontalSpacing: gridSpacing(horizontalSpacing, "Swift.Grid horizontal"), verticalSpacing: gridSpacing(verticalSpacing, "Swift.Grid vertical"), children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function GridRow(param) { var { alignment, children, style, ...props } = param; if (alignment !== void 0 && !gridVerticalAlignments.includes(alignment)) throw new Error("Swift.GridRow alignment must be a SwiftUI VerticalAlignment"); assertOneNativeChildren(children, "Swift.GridRow"); return /* @__PURE__ */ jsx(NativeGridRow, { ...props, style: [{ alignSelf: "stretch" }, style], alignment: alignment !== null && alignment !== void 0 ? alignment : "", children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function LabeledContent(param) { var { label, value, systemImage, children, style, ...props } = param; var content = labeledContentProps({ label, value, systemImage, hasChildren: Children.toArray(children).length > 0 }); assertOneNativeChildren(children, "Swift.LabeledContent"); return /* @__PURE__ */ jsx(NativeLabeledContent, { ...props, style: [{ alignSelf: "stretch" }, style], label: content.label, value: content.value, systemImage: content.systemImage, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function GroupBox(param) { var { label, children, style, ...props } = param; if (label !== void 0 && typeof label !== "string") throw new Error("GroupBox label must be a string when provided"); assertOneNativeChildren(children, "Swift.GroupBox"); return /* @__PURE__ */ jsx(NativeGroupBox, { ...props, label: label !== null && label !== void 0 ? label : "", style: [{ alignSelf: "stretch" }, style], children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function ViewThatFits(param) { var { axes = "both", children, style, ...props } = param; if (Number.parseFloat(String(Platform.Version)) < 16) throw new Error("Swift.ViewThatFits requires iOS 16 or newer"); if (!viewThatFitsAxes.includes(axes)) throw new Error(`Swift.ViewThatFits axes must be one of ${viewThatFitsAxes.join(", ")}`); assertOneNativeChildren(children, "Swift.ViewThatFits"); assertNoGreedyContainer(children, "Swift.ViewThatFits"); return /* @__PURE__ */ jsx(NativeViewThatFits, { ...props, axes, style: [{ alignSelf: "stretch" }, style], children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Button(param) { var { onPress, label = "", disabled = false, subtitle = "", systemImage = "", buttonRole = "", buttonStyle = "automatic", disclosureIndicator = false, children, swiftStyle, style, ...props } = param; if (typeof label !== "string") throw new Error("Button label must be a string"); var hasChildren = Children.toArray(children).length > 0; if (hasChildren && (label !== "" || systemImage !== "" || subtitle !== "")) throw new Error("Swift.Button takes either a label or children"); if (!label && !systemImage && !hasChildren) throw new Error("Button needs a label, a systemImage, or both"); if (buttonRole) assertSwiftUIValue("ButtonRole", buttonRole, Number.parseFloat(String(Platform.Version))); assertSwiftUIValue("PrimitiveButtonStyle", buttonStyle, Number.parseFloat(String(Platform.Version))); assertOneNativeChildren(children, "Swift.Button"); return /* @__PURE__ */ jsx(NativeButton, { ...props, style, swiftStyle: swiftStyleNative(swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return dispatchSDKEvent(swiftStyle, nativeEvent.name, nativeEvent.value); }, label, disabled, subtitle, systemImage, buttonRole, buttonStyle, disclosureIndicator, onNativeButtonPress: function onNativeButtonPress(param2) { var { nativeEvent } = param2; return onPress === null || onPress === void 0 ? void 0 : onPress(); }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Glass(param) { var { material, glassEffect, interactive = false, shape, cornerRadius, tint, colorScheme, children, style, ...props } = param; if (glassEffect !== void 0 && !glassEffects.includes(glassEffect)) throw new Error(`Swift.Glass glassEffect must be one of ${glassEffects.join(", ")}`); if (material !== void 0 && !materials.includes(material)) throw new Error(`Swift.Glass material must be one of ${materials.join(", ")}`); if (shape !== void 0 && !glassEffectShapes.includes(shape)) throw new Error(`Swift.Glass shape must be one of ${glassEffectShapes.join(", ")}`); if (cornerRadius !== void 0 && (!Number.isFinite(cornerRadius) || cornerRadius < 0)) throw new Error("Swift.Glass cornerRadius must be a non-negative number"); if (shape !== void 0 && shape !== "roundedRectangle" && cornerRadius !== void 0) throw new Error("Swift.Glass cornerRadius requires shape=\"roundedRectangle\""); if (colorScheme) assertSwiftUIValue("ColorScheme", colorScheme, Number.parseFloat(String(Platform.Version))); assertOneNativeChildren(children, "Swift.Glass"); return /* @__PURE__ */ jsx(NativeGlass, { ...props, style: [{ alignSelf: "stretch" }, style], material: material !== null && material !== void 0 ? material : "", glassEffect: glassEffect !== null && glassEffect !== void 0 ? glassEffect : material ? "" : "regular", interactive, shape: shape !== null && shape !== void 0 ? shape : "", cornerRadius: cornerRadius !== null && cornerRadius !== void 0 ? cornerRadius : -1, tint, colorScheme: colorScheme !== null && colorScheme !== void 0 ? colorScheme : "", children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function GlassEffectContainer(param) { var { spacing, children, style, ...props } = param; if (Number.parseFloat(String(Platform.Version)) < 26) throw new Error("Swift.GlassEffectContainer requires iOS 26 or newer"); if (spacing !== void 0 && !Number.isFinite(spacing)) throw new Error("Swift.GlassEffectContainer spacing must be finite"); assertOneNativeChildren(children, "Swift.GlassEffectContainer"); return /* @__PURE__ */ jsx(NativeGlassEffectContainer, { ...props, style: [{ alignSelf: "stretch" }, style], spacing: spacing !== null && spacing !== void 0 ? spacing : 0, hasSpacing: spacing !== void 0, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function geometryNumber(value) { return typeof value === "number" && Number.isFinite(value) ? value : void 0; } function sameGeometry(a, b) { if (!a) return false; return a.size.width === b.size.width && a.size.height === b.size.height && a.globalFrame.x === b.globalFrame.x && a.globalFrame.y === b.globalFrame.y && a.globalFrame.width === b.globalFrame.width && a.globalFrame.height === b.globalFrame.height && a.localFrame.x === b.localFrame.x && a.localFrame.y === b.localFrame.y && a.localFrame.width === b.localFrame.width && a.localFrame.height === b.localFrame.height && a.safeAreaInsets.top === b.safeAreaInsets.top && a.safeAreaInsets.leading === b.safeAreaInsets.leading && a.safeAreaInsets.bottom === b.safeAreaInsets.bottom && a.safeAreaInsets.trailing === b.safeAreaInsets.trailing; } function GeometryReader(param) { var { children, style, ...props } = param; var [geometry, setGeometry] = useState(null); var latest = useRef(null); if (typeof children !== "function") throw new Error("Swift.GeometryReader takes a render function of its geometry; pass (geometry) => content"); var content = geometry === null ? null : children(geometry); assertOneNativeChildren(content, "Swift.GeometryReader"); return /* @__PURE__ */ jsx(NativeGeometryReader, { ...props, style: [{ alignSelf: "stretch" }, style], onNativeGeometryReaderChange: function onNativeGeometryReaderChange(param2) { var { nativeEvent } = param2; var event = nativeEvent; var fields = [ "x", "y", "width", "height", "localX", "localY", "localWidth", "localHeight", "sizeWidth", "sizeHeight", "safeAreaTop", "safeAreaLeading", "safeAreaBottom", "safeAreaTrailing" ]; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var field = _step.value; if (geometryNumber(event === null || event === void 0 ? void 0 : event[field]) === void 0) throw new Error("Swift.GeometryReader emitted an invalid geometry"); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } var values = event; var next = { size: { width: values.sizeWidth, height: values.sizeHeight }, safeAreaInsets: { top: values.safeAreaTop, leading: values.safeAreaLeading, bottom: values.safeAreaBottom, trailing: values.safeAreaTrailing }, globalFrame: { x: values.x, y: values.y, width: values.width, height: values.height }, localFrame: { x: values.localX, y: values.localY, width: values.localWidth, height: values.localHeight } }; if (sameGeometry(latest.current, next)) return; latest.current = next; setGeometry({ size: next.size, safeAreaInsets: next.safeAreaInsets, frame(coordinateSpace) { if (coordinateSpace === "global") return { ...next.globalFrame }; if (coordinateSpace === "local") return { ...next.localFrame }; throw new Error("Swift.GeometryProxy.frame supports global and local coordinate spaces; named spaces are not yet bound"); } }); }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children: content }) }); } function ControlGroup(param) { var { label = "", systemImage = "", controlGroupStyle = "automatic", children, style, ...props } = param; if (typeof label !== "string" || typeof systemImage !== "string") throw new Error("Swift.ControlGroup label and systemImage must be strings"); assertSwiftUIValue("ControlGroupStyle", controlGroupStyle, Number.parseFloat(String(Platform.Version))); assertOneNativeChildren(children, "Swift.ControlGroup"); return /* @__PURE__ */ jsx(NativeControlGroup, { ...props, style: [{ alignSelf: "stretch" }, style], label, systemImage, controlGroupStyle, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function DisclosureGroup(param) { var { label, isExpanded, onIsExpandedChange, revision = 0, children, style, ...props } = param; if (typeof label !== "string" || !label) throw new Error("Swift.DisclosureGroup label must be a non-empty string"); if (typeof isExpanded !== "boolean") throw new Error("Swift.DisclosureGroup isExpanded must be a boolean"); assertOneNativeChildren(children, "Swift.DisclosureGroup"); var controlled = useControlled(function(event) { return onIsExpandedChange(event.value); }, revision); return /* @__PURE__ */ jsx(NativeDisclosureGroup, { ...props, style: [{ alignSelf: "stretch" }, style], label, isExpanded, acknowledgedEvent: controlled.acknowledgedEvent, revision, onNativeDisclosureGroupIsExpandedChange: function onNativeDisclosureGroupIsExpandedChange(param2) { var { nativeEvent } = param2; return controlled.onNativeChange(nativeEvent); }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Divider(param) { var { children, style, ...props } = param; var inside = useContext(InsideContainer); if (!inside) throw new Error(`Swift.Divider must be a child of ${containers}`); if (Children.toArray(children).length > 0) throw new Error("Swift.Divider holds no content"); return /* @__PURE__ */ jsx(NativeDivider, { ...props, style }); } function Link(param) { var { destination, label = "", children, style, ...props } = param; if (typeof destination !== "string" || !destination) throw new Error("Swift.Link destination must be a non-empty string"); try { new URL(destination); } catch (unused) { throw new Error("Swift.Link destination must be a parseable URL"); } if (Children.toArray(children).length === 0 && !label) throw new Error("Swift.Link needs a label or children"); assertOneNativeChildren(children, "Swift.Link"); return /* @__PURE__ */ jsx(NativeLink, { ...props, style: [{ alignSelf: "stretch" }, style], destination, label, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function Group(param) { var { children, style, ...props } = param; assertOneNativeChildren(children, "Swift.Group"); return /* @__PURE__ */ jsx(NativeGroup, { ...props, style: [{ alignSelf: "stretch" }, style], children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function OverlayContent(param) { var { children, style, ...props } = param; assertOneNativeChildren(children, "Swift.Overlay.Content"); return /* @__PURE__ */ jsx(NativeOverlayContent, { ...props, style, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function OverlayFn(param) { var { alignment = "center", children, style, ...props } = param; if (!zStackAlignments.includes(alignment)) throw new Error(`Swift.Overlay alignment must be one of ${zStackAlignments.join(", ")}`); var markers = Children.toArray(children).filter(function(child) { return /* @__PURE__ */ isValidElement(child) && child.type === OverlayContent; }); if (markers.length > 1) throw new Error("Swift.Overlay takes a single Overlay.Content child"); assertOneNativeChildren(children, "Swift.Overlay"); return /* @__PURE__ */ jsx(NativeOverlay, { ...props, style: [{ alignSelf: "stretch" }, style], alignment, slotName: "", slotValues: "[]", children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } var Overlay = Object.assign(OverlayFn, { Content: OverlayContent }); function ViewSlotFn(param) { var { name, options, children, style, ...props } = param; if (!Object.hasOwn(viewSlotAvailability, name)) throw new Error(`unknown Swift.ViewSlot: ${name}`); if (Number.parseFloat(String(Platform.Version)) < viewSlotAvailability[name]) throw new Error(`Swift.ViewSlot ${name} requires iOS ${viewSlotAvailability[name]} or later`); var markers = Children.toArray(children).filter(function(child) { return /* @__PURE__ */ isValidElement(child) && child.type === OverlayContent; }); if (markers.length !== 1) throw new Error("Swift.ViewSlot takes one ViewSlot.Content child"); assertOneNativeChildren(children, "Swift.ViewSlot"); var preferenceEvent = Object.hasOwn(viewSlotEvents, name) ? viewSlotEvents[name] : void 0; if (preferenceEvent && typeof (options === null || options === void 0 ? void 0 : options.onValue) !== "function") throw new Error(`Swift.ViewSlot ${name}.onValue must be a callback`); var values = viewSlotArguments[name].map(function(argument) { var value = options === null || options === void 0 ? void 0 : options[argument.field]; if (argument.kind === "bindingBoolean" || argument.kind === "bindingString") { if (typeof value !== "object" || value === null || typeof value.value !== (argument.kind === "bindingBoolean" ? "boolean" : "string") || typeof value.onChange !== "function") throw new Error(`Swift.ViewSlot ${name}.${argument.field} must be a ${argument.kind === "bindingBoolean" ? "boolean" : "string"} binding`); return String(value.value); } if (argument.kind === "boolean") { if (typeof value !== "boolean") throw new Error(`Swift.ViewSlot ${name}.${argument.field} must be a boolean`); return String(value); } if (argument.kind === "string") { if (typeof value !== "string") throw new Error(`Swift.ViewSlot ${name}.${argument.field} must be a string`); return value; } if (typeof value !== "string" || !Object.hasOwn(argument.cases, value)) throw new Error(`Swift.ViewSlot ${name}.${argument.field} must be a declared SDK case`); if (Number.parseFloat(String(Platform.Version)) < argument.cases[value]) throw new Error(`Swift.ViewSlot ${name}.${argument.field}=${value} is unavailable on this iOS version`); return value; }); return /* @__PURE__ */ jsx(NativeOverlay, { ...props, style: [{ alignSelf: "stretch" }, style], alignment: "center", slotName: name, slotValues: JSON.stringify(values), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; if (nativeEvent.name !== name) throw new Error(`Swift.ViewSlot ${name} emitted an invalid binding event`); if (preferenceEvent) { var value; try { value = JSON.parse(nativeEvent.value); } catch (unused) { throw new Error(`Swift.ViewSlot ${name} emitted an invalid preference value`); } if (!validSDKEventValue(value, preferenceEvent)) throw new Error(`Swift.ViewSlot ${name} emitted an invalid preference value`); options.onValue(value); return; } var argument = viewSlotArguments[name].find(function(item) { return item.kind === "bindingBoolean" || item.kind === "bindingString"; }); if (!argument) throw new Error(`Swift.ViewSlot ${name} emitted an unexpected event`); if (argument.kind === "bindingBoolean") { if (nativeEvent.value !== "true" && nativeEvent.value !== "false") throw new Error(`Swift.ViewSlot ${name} emitted an invalid boolean binding`); var binding = options[argument.field]; binding.onChange(nativeEvent.value === "true"); } else { var binding1 = options[argument.field]; binding1.onChange(nativeEvent.value); } }, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } var ViewSlot = Object.assign(ViewSlotFn, { Content: OverlayContent }); function SwipeActionsActions(param) { var { edge = "trailing", allowsFullSwipe = true, children, style, ...props } = param; if (!swipeActionsEdges.includes(edge)) throw new Error(`Swift.SwipeActions edge must be one of ${swipeActionsEdges.join(", ")}`); assertOneNativeChildren(children, "Swift.SwipeActions.Actions"); return /* @__PURE__ */ jsx(NativeSwipeActionsActions, { ...props, style, edge, allowsFullSwipe, children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } function SwipeActionsFn(param) { var { children, style, ...props } = param; var edges = Children.toArray(children).flatMap(function(child) { var _child_props_edge; return /* @__PURE__ */ isValidElement(child) && child.type === SwipeActionsActions ? [(_child_props_edge = child.props.edge) !== null && _child_props_edge !== void 0 ? _child_props_edge : "trailing"] : []; }); if (new Set(edges).size !== edges.length) throw new Error("Swift.SwipeActions takes at most one Actions group per edge"); assertOneNativeChildren(children, "Swift.SwipeActions"); return /* @__PURE__ */ jsx(NativeSwipeActions, { ...props, style: [{ alignSelf: "stretch" }, style], children: /* @__PURE__ */ jsx(InsideContainer, { value: true, children }) }); } var SwipeActions = Object.assign(SwipeActionsFn, { Actions: SwipeActionsActions }); function Slot(param) { var { height, width = 0, children, style, ...props } = param; var inside = useContext(InsideContainer); if (!inside) throw new Error(`Swift.Slot must be a child of ${containers}`); if (!Number.isFinite(height) || height <= 0) throw new Error("Swift.Slot height must be a positive number"); if (!Number.isFinite(width) || width < 0) throw new Error("Swift.Slot width must be a non-negative number"); return /* @__PURE__ */ jsx(NativeContainerSlot, { ...props, style, height, width, children: /* @__PURE__ */ jsx(InsideContainer, { value: false, children }) }); } export { Button, ControlGroup, DisclosureGroup, Divider, Form, GeometryReader, Glass, GlassEffectContainer, Grid, GridRow, Group, GroupBox, HStack, Host, InsideContainer, LabeledContent, LazyHGrid, LazyHStack, LazyVGrid, LazyVStack, Link, List, Overlay, OverlayContent, ScrollView, ScrollViewReader, Section, Slot, Spacer, SwipeActions, SwipeActionsActions, VStack, ViewSlot, ViewThatFits, ZStack, assertOneNativeChildren }; //# sourceMappingURL=Containers.native.js.map