import { html, css, LitElement } from 'lit'; import { customElement, state, query } from 'lit/decorators.js'; import { RecaptchaWidgetInterface } from '../src/recaptcha-widget'; import { RecaptchaManager, RecaptchaManagerInterface, } from '../src/recaptcha-manager'; @customElement('app-root') export class AppRoot extends LitElement { @state() result?: string; @state() result2?: string; @query('#timeout') timeoutInput!: HTMLInputElement; private recaptchaManager: RecaptchaManagerInterface = new RecaptchaManager({ defaultSiteKey: '6Ld64a8UAAAAAGbDwi1927ztGNw7YABQ-dqzvTN2', }); private recaptcha1?: RecaptchaWidgetInterface; private recaptcha2?: RecaptchaWidgetInterface; render() { return html`
${this.result ? html`
Token:
${this.result}
` : ''}${this.result2 ? html`
Token 2:
${this.result2}
` : ''} `; } private updateTimeout() { this.recaptchaManager.setTimeoutDelay(+this.timeoutInput.value); } private async loadRecaptcha() { this.recaptcha1 = await this.recaptchaManager?.getRecaptchaWidget({ recaptchaParams: { tabindex: 0, theme: 'light', type: 'image', }, }); } private async executeRecaptcha() { if (!this.recaptcha1) { await this.loadRecaptcha(); } if (!this.recaptcha1) { console.error('error loading recaptcha'); return; } this.result = await this.recaptcha1.execute(); } private async loadRecaptcha2() { this.recaptcha2 = await this.recaptchaManager?.getRecaptchaWidget({ siteKey: '