import { useForwardExpose } from "../shared/useForwardExpose.js"; import { Presence_default } from "../Presence/Presence.js"; import { injectToastProviderContext } from "./ToastProvider.js"; import { ToastRootImpl_default } from "./ToastRootImpl.js"; import { computed, createBlock, createVNode, defineComponent, mergeProps, openBlock, ref, renderSlot, unref, watch, withCtx } from "vue"; import { useVModel } from "@vueuse/core"; //#region src/Toast/ToastRoot.vue?vue&type=script&setup=true&lang.ts var ToastRoot_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({ __name: "ToastRoot", props: { defaultOpen: { type: Boolean, required: false, default: true }, forceMount: { type: Boolean, required: false }, type: { type: String, required: false, default: "foreground" }, open: { type: Boolean, required: false, default: void 0 }, duration: { type: Number, required: false }, toast: { type: Object, required: false }, asChild: { type: Boolean, required: false }, as: { type: null, required: false, default: "li" } }, emits: [ "escapeKeyDown", "pause", "resume", "swipeStart", "swipeMove", "swipeCancel", "swipeEnd", "update:open" ], setup(__props, { emit: __emit }) { const props = __props; const emits = __emit; const { forwardRef } = useForwardExpose(); const open = useVModel(props, "open", emits, { defaultValue: props.defaultOpen, passive: props.open === void 0 }); const providerContext = injectToastProviderContext(); const isOpen = computed(() => props.toast ? props.toast.open : open.value); const resolvedType = computed(() => props.toast?.type ?? props.type); const resolvedDuration = computed(() => props.toast?.status === "loading" ? Number.POSITIVE_INFINITY : props.toast?.duration ?? props.duration); function close() { if (props.toast) { providerContext.toastStore.close(props.toast.id); emits("update:open", false); } else open.value = false; } const isContentMounted = ref(false); watch([() => props.toast, isContentMounted], ([toast, mounted]) => { if (toast && !toast.open && !mounted) providerContext.toastStore.remove(toast.id); }, { immediate: true }); return (_ctx, _cache) => { return openBlock(), createBlock(unref(Presence_default), { present: __props.forceMount || isOpen.value }, { default: withCtx(() => [createVNode(ToastRootImpl_default, mergeProps({ ref: unref(forwardRef), open: isOpen.value, type: resolvedType.value, as: __props.as, "as-child": __props.asChild, duration: resolvedDuration.value, toast: __props.toast }, _ctx.$attrs, { onVnodeMounted: _cache[0] || (_cache[0] = ($event) => isContentMounted.value = true), onVnodeUnmounted: _cache[1] || (_cache[1] = ($event) => isContentMounted.value = false), onClose: close, onPause: _cache[2] || (_cache[2] = ($event) => emits("pause")), onResume: _cache[3] || (_cache[3] = ($event) => emits("resume")), onEscapeKeyDown: _cache[4] || (_cache[4] = ($event) => emits("escapeKeyDown", $event)), onSwipeStart: _cache[5] || (_cache[5] = (event) => { emits("swipeStart", event); if (!event.defaultPrevented) event.currentTarget.setAttribute("data-swipe", "start"); }), onSwipeMove: _cache[6] || (_cache[6] = (event) => { emits("swipeMove", event); if (!event.defaultPrevented) { const { x, y } = event.detail.delta; const target = event.currentTarget; target.setAttribute("data-swipe", "move"); target.style.setProperty("--reka-toast-swipe-move-x", `${x}px`); target.style.setProperty("--reka-toast-swipe-move-y", `${y}px`); } }), onSwipeCancel: _cache[7] || (_cache[7] = (event) => { emits("swipeCancel", event); if (!event.defaultPrevented) { const target = event.currentTarget; target.setAttribute("data-swipe", "cancel"); target.style.removeProperty("--reka-toast-swipe-move-x"); target.style.removeProperty("--reka-toast-swipe-move-y"); target.style.removeProperty("--reka-toast-swipe-end-x"); target.style.removeProperty("--reka-toast-swipe-end-y"); } }), onSwipeEnd: _cache[8] || (_cache[8] = (event) => { emits("swipeEnd", event); if (!event.defaultPrevented) { const { x, y } = event.detail.delta; const target = event.currentTarget; target.setAttribute("data-swipe", "end"); target.style.removeProperty("--reka-toast-swipe-move-x"); target.style.removeProperty("--reka-toast-swipe-move-y"); target.style.setProperty("--reka-toast-swipe-end-x", `${x}px`); target.style.setProperty("--reka-toast-swipe-end-y", `${y}px`); close(); } }) }), { default: withCtx(({ remaining, duration: _duration }) => [renderSlot(_ctx.$slots, "default", { remaining, duration: _duration, open: isOpen.value })]), _: 3 }, 16, [ "open", "type", "as", "as-child", "duration", "toast" ])]), _: 3 }, 8, ["present"]); }; } }); //#endregion //#region src/Toast/ToastRoot.vue var ToastRoot_default = ToastRoot_vue_vue_type_script_setup_true_lang_default; //#endregion export { ToastRoot_default }; //# sourceMappingURL=ToastRoot.js.map