UNPKG

@anilkumarthakur/vue3-recaptcha

Version:

This plugin provides a Vue 3 component and plugin for integrating Google reCAPTCHA V3. The plugin enables easy reCAPTCHA token generation, management, and configuration within a Vue 3 application.

3 lines (2 loc) 1.55 kB
(function(c,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(c=typeof globalThis<"u"?globalThis:c||self,t(c["@anilkumarthakur/vue3-recaptcha"]={},c.Vue))})(this,function(c,t){"use strict";const d=t.defineComponent({__name:"RecaptchaV3",props:{siteKey:{},action:{},modelValue:{}},emits:["update:modelValue"],setup(o,{expose:r,emit:m}){const s=o,p=t.computed({get:()=>s.modelValue,set:e=>f("update:modelValue",e||"")}),f=m;function u(){return new Promise((e,a)=>{window.grecaptcha?window.grecaptcha.ready(()=>{h().then(e).catch(a)}):a(new Error("Recaptcha is not loaded"))})}async function h(){return window.grecaptcha.execute(s.siteKey??(n==null?void 0:n.siteKey)??"",{action:s.action??(n==null?void 0:n.action)??""}).then(e=>(p.value=e,e))}async function y(){return new Promise((e,a)=>{if(window.grecaptcha)u().then(e).catch(a);else{const i=document.createElement("script");i.src=`https://www.google.com/recaptcha/api.js?render=${s.siteKey||(n?n.siteKey:"")}`,i.async=!0,i.defer=!0,i.onload=()=>{u().then(e).catch(a)},document.head.appendChild(i)}})}r({loadRecaptcha:y,executeRecaptcha:h,initializeRecaptcha:u,recaptchaToken:p});const n=t.inject("recaptcha");return(e,a)=>(t.openBlock(),t.createElementBlock("div"))}}),l={install(o,r){o.component("RecaptchaV3",d),o.provide("recaptcha",{siteKey:r.siteKey,action:r.action})}};c.RecaptchaV3=d,c.recaptchaPlugin=l,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=index.umd.js.map