"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const ui = require("@tonconnect/ui"); const vueDemi = require("vue-demi"); class TonConnectUIVueError extends ui.TonConnectUIError { constructor(...args) { super(...args); Object.setPrototypeOf(this, TonConnectUIVueError.prototype); } } class TonConnectProviderNotSetError extends TonConnectUIVueError { constructor(...args) { super(...args); Object.setPrototypeOf(this, TonConnectProviderNotSetError.prototype); } } function checkProvider(provider) { if (!provider) { throw new TonConnectProviderNotSetError( "You should add on the top of the app to use TonConnect" ); } return true; } function isClientSide() { return typeof window !== "undefined"; } function isServerSide() { return !isClientSide(); } function useTonConnectUI() { var _a; if (isServerSide()) { return { tonConnectUI: null, setOptions: () => { } }; } const globalPropertiesMap = vueDemi.isVue2 ? (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy : vueDemi.getCurrentInstance().appContext.app.config.globalProperties; const tonConnectUI = globalPropertiesMap.$tonConnectUI; const setOptions = (options) => { if (tonConnectUI && tonConnectUI) { tonConnectUI.uiOptions = options; } }; checkProvider(tonConnectUI); return { tonConnectUI, setOptions }; } const _sfc_main = vueDemi.defineComponent({ name: "TonConnectButton", props: { buttonRootId: { type: String, default: "ton-connect-button" } }, setup(props, { slots }) { const { setOptions } = useTonConnectUI(); vueDemi.onMounted(() => { setOptions({ buttonRootId: props.buttonRootId }); }); vueDemi.onBeforeUnmount(() => { setOptions({ buttonRootId: null }); }); return () => { var _a; return vueDemi.h( "div", { id: props.buttonRootId || "", attrs: { id: props.buttonRootId || "" }, style: { width: "fit-content" } }, (_a = slots == null ? void 0 : slots.default) == null ? void 0 : _a.call(slots) ); }; } }); function useTonWallet() { const { tonConnectUI } = useTonConnectUI(); const wallet = vueDemi.ref( (tonConnectUI == null ? void 0 : tonConnectUI.wallet) || null ); const updateWallet = (value) => { wallet.value = value; }; vueDemi.onMounted(() => { if (tonConnectUI) { wallet.value = tonConnectUI.wallet; const unsubscribe = tonConnectUI.onStatusChange((value) => { updateWallet(value); }); vueDemi.onUnmounted(() => { unsubscribe(); }); } }); return wallet; } function useTonAddress(userFriendly = true) { const wallet = useTonWallet(); const tonAddress = vueDemi.computed(() => { if (wallet.value) { return userFriendly ? ui.toUserFriendlyAddress( wallet.value.account.address, wallet.value.account.chain === ui.CHAIN.TESTNET ) : wallet.value.account.address; } else { return ""; } }); return tonAddress; } function useTonConnectModal() { const { tonConnectUI } = useTonConnectUI(); const state = vueDemi.ref((tonConnectUI == null ? void 0 : tonConnectUI.modal.state) || null); vueDemi.onMounted(() => { if (tonConnectUI) { state.value = tonConnectUI.modal.state; tonConnectUI.onModalStateChange((value) => { state.value = value; }); } }); return { state, open: () => tonConnectUI == null ? void 0 : tonConnectUI.modal.open(), close: () => tonConnectUI == null ? void 0 : tonConnectUI.modal.close() }; } function useIsConnectionRestored() { const restored = vueDemi.ref(false); const { tonConnectUI } = useTonConnectUI(); vueDemi.onMounted(() => { if (tonConnectUI) { tonConnectUI.connectionRestored.then(() => { restored.value = true; }); } }); return restored; } const TonConnectUIPlugin = { install(app, options) { const tonConnectUI = vueDemi.shallowRef(null); if (isClientSide() && !tonConnectUI.value) { tonConnectUI.value = new ui.TonConnectUI(options || {}); } if (vueDemi.isVue2) { app.prototype.$tonConnectUI = tonConnectUI.value; } else { app.config.globalProperties.$tonConnectUI = tonConnectUI.value; } } }; exports.TonConnectButton = _sfc_main; exports.TonConnectProviderNotSetError = TonConnectProviderNotSetError; exports.TonConnectUIPlugin = TonConnectUIPlugin; exports.TonConnectUIVueError = TonConnectUIVueError; exports.useIsConnectionRestored = useIsConnectionRestored; exports.useTonAddress = useTonAddress; exports.useTonConnectModal = useTonConnectModal; exports.useTonConnectUI = useTonConnectUI; exports.useTonWallet = useTonWallet; Object.keys(ui).forEach((k) => { if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { enumerable: true, get: () => ui[k] }); });