@takuhon/contact 1.0.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets.d.ts +5 -0
- package/dist/assets.js +5 -0
- package/dist/contact-widget.js +1 -1
- package/package.json +6 -2
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Generated by scripts/emit-asset-strings.mjs — do not edit.
|
|
2
|
+
/** The built contact-widget IIFE (`dist/contact-widget.js`), inlined as a string. */
|
|
3
|
+
export declare const contactWidgetJs: string;
|
|
4
|
+
/** The built contact-widget stylesheet (`dist/contact-widget.css`), inlined as a string. */
|
|
5
|
+
export declare const contactWidgetCss: string;
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Generated by scripts/emit-asset-strings.mjs — do not edit.
|
|
2
|
+
// The built browser-widget assets, inlined as strings so host adapters can
|
|
3
|
+
// bundle and serve them (e.g. @takuhon/cloudflare's /contact-widget.{js,css}).
|
|
4
|
+
export const contactWidgetJs = "var TakuhonContact=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=[`ja`,`en`];function n(e){if(typeof e==`string`){let n=e.trim().toLowerCase().split(`-`)[0];if(n!==void 0&&t.includes(n))return n}return`ja`}var r=`/api/contact`;function i(e,t){if(e?.siteKey)return{...e,siteKey:e.siteKey};if(t?.siteKey)return{siteKey:t.siteKey,...t.endpoint?{endpoint:t.endpoint}:{},...t.locale?{locale:t.locale}:{},...t.lang?{lang:t.lang}:{},...t.pageUrl?{pageUrl:t.pageUrl}:{}}}function a(e){let t=typeof e.endpoint==`string`&&e.endpoint.trim()!==``?e.endpoint.trim():r;return{siteKey:e.siteKey,endpoint:t,locale:n(e.locale??e.lang),...e.pageUrl?{pageUrl:e.pageUrl}:{}}}var o={ja:{launcher:`お問い合わせ`,title:`お問い合わせ`,close:`閉じる`,greeting:`こんにちは。お問い合わせ内容をお送りください。確認後、メールで返信します。`,askEmail:`まず、返信先のメールアドレスを入力してください。`,askMessage:`ありがとうございます。次にお問い合わせ内容を入力してください。`,confirm:`送信してよろしいですか?`,send:`送信`,sending:`送信中…`,verifying:`確認中…`,done:`お問い合わせを受け付けました。確認後、メールで返信します。`,retry:`もう一度送信する`,challengePrompt:`送信前に確認にお答えください。`,emailPlaceholder:`you@example.com`,messagePlaceholder:`お問い合わせ内容`,errorEmail:`メールアドレスの形式が正しくないようです。`,errorChallenge:`確認に失敗しました。もう一度お試しください。`,errorGeneric:`送信に失敗しました。時間をおいて再度お試しください。`},en:{launcher:`Contact`,title:`Contact`,close:`Close`,greeting:`Hi! Send your question below and we'll reply by email.`,askEmail:`First, what email address should we reply to?`,askMessage:`Thanks! Now, what would you like to ask?`,confirm:`Ready to send?`,send:`Send`,sending:`Sending…`,verifying:`Verifying…`,done:`Got it — we'll review your message and reply by email.`,retry:`Try again`,challengePrompt:`Please complete the check before sending.`,emailPlaceholder:`you@example.com`,messagePlaceholder:`Your message`,errorEmail:`That email address doesn't look right.`,errorChallenge:`Verification failed. Please try again.`,errorGeneric:`Something went wrong. Please try again later.`}};function s(e,t){return o[e][t]}function c(e){return{email:e.email,message:e.message,locale:e.locale,token:e.token,hp:e.honeypot,...e.pageUrl?{pageUrl:e.pageUrl}:{}}}function l(e){switch(e){case`email_invalid`:case`email_missing`:case`email_too_long`:return`errorEmail`;case`challenge_failed`:return`errorChallenge`;default:return`errorGeneric`}}function u(e){\"@babel/helpers - typeof\";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var m=`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit`;function h(e){return/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(e.trim())}function g(){return globalThis.turnstile}var _;function v(){let e=g();return e?Promise.resolve(e):_||(_=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=m,n.async=!0,n.addEventListener(`load`,()=>{let n=g();n?e(n):t(Error(`turnstile unavailable after load`))}),n.addEventListener(`error`,()=>t(Error(`turnstile script failed to load`))),document.head.appendChild(n)}),_)}function y(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var b=`http://www.w3.org/2000/svg`;function x(){let e=document.createElementNS(b,`svg`);e.setAttribute(`viewBox`,`0 0 24 24`),e.setAttribute(`width`,`26`),e.setAttribute(`height`,`26`),e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`focusable`,`false`);let t=document.createElementNS(b,`path`);return t.setAttribute(`fill`,`currentColor`),t.setAttribute(`d`,`M12 3C6.5 3 2 6.58 2 11c0 2.4 1.32 4.56 3.4 6.04L5 21l3.9-2.05c.98.26 2.02.4 3.1.4 5.5 0 10-3.58 10-8s-4.5-8-10-8z`),e.appendChild(t),e}var S=class{constructor(e){p(this,`cfg`,void 0),p(this,`state`,void 0),p(this,`step`,`email`),p(this,`opened`,!1),p(this,`greeted`,!1),p(this,`turnstileRendered`,!1),p(this,`pendingSubmit`,!1),p(this,`root`,void 0),p(this,`launcher`,void 0),p(this,`panel`,void 0),p(this,`log`,void 0),p(this,`turnstileHost`,void 0),p(this,`form`,void 0),p(this,`input`,void 0),p(this,`honeypot`,void 0),p(this,`send`,void 0),this.cfg=a(e),this.state={email:``,message:``,token:``,honeypot:``,locale:this.cfg.locale,...this.cfg.pageUrl?{pageUrl:this.cfg.pageUrl}:{}}}tr(e){return s(this.cfg.locale,e)}mount(e=document.body){this.root=y(`div`,`tkc-root`),this.launcher=y(`button`,`tkc-launcher`),this.launcher.type=`button`,this.launcher.setAttribute(`aria-haspopup`,`dialog`),this.launcher.setAttribute(`aria-label`,this.tr(`launcher`)),this.launcher.append(x()),this.launcher.addEventListener(`click`,()=>this.open()),this.panel=y(`div`,`tkc-panel tkc-hidden`),this.panel.setAttribute(`role`,`dialog`),this.panel.setAttribute(`aria-label`,this.tr(`title`));let t=y(`div`,`tkc-header`);t.append(y(`span`,void 0,this.tr(`title`)));let n=y(`button`,`tkc-close`,`×`);n.type=`button`,n.setAttribute(`aria-label`,this.tr(`close`)),n.addEventListener(`click`,()=>this.close()),t.append(n),this.log=y(`div`,`tkc-log`),this.log.setAttribute(`role`,`log`),this.log.setAttribute(`aria-live`,`polite`),this.turnstileHost=y(`div`,`tkc-turnstile`),this.form=y(`form`,`tkc-form`),this.honeypot=y(`input`,`tkc-honeypot`),this.honeypot.type=`text`,this.honeypot.tabIndex=-1,this.honeypot.autocomplete=`off`,this.honeypot.setAttribute(`aria-hidden`,`true`),this.honeypot.name=`company`,this.input=y(`input`,`tkc-input`),this.input.type=`text`,this.input.autocomplete=`off`,this.input.setAttribute(`aria-label`,this.tr(`title`)),this.send=y(`button`,`tkc-send`,this.tr(`send`)),this.send.type=`submit`,this.form.append(this.honeypot,this.input,this.send),this.form.addEventListener(`submit`,e=>{e.preventDefault(),this.onSubmit()}),this.panel.append(t,this.log,this.turnstileHost,this.form),this.root.append(this.launcher,this.panel),e.append(this.root),document.addEventListener(`click`,e=>{if(!this.opened)return;let t=e.target;t instanceof Node&&this.root.contains(t)||this.close(!1)}),document.addEventListener(`keydown`,e=>{this.opened&&e.key===`Escape`&&this.close()})}open(){this.opened||(this.opened=!0,this.launcher.classList.add(`tkc-hidden`),this.panel.classList.remove(`tkc-hidden`),this.greeted||(this.greeted=!0,this.botSay(`greeting`),this.botSay(`askEmail`)),this.setStep(`email`),this.input.focus())}close(e=!0){this.opened=!1,this.panel.classList.add(`tkc-hidden`),this.launcher.classList.remove(`tkc-hidden`),e&&this.launcher.focus()}botSay(e){this.appendMessage(`tkc-msg-bot`,this.tr(e))}appendMessage(e,t){let n=y(`div`,`tkc-msg ${e}`,t);this.log.append(n),this.log.scrollTop=this.log.scrollHeight}setStep(e){this.step=e;let t=e===`email`||e===`message`;this.input.classList.toggle(`tkc-hidden`,!t),this.input.placeholder=e===`email`?this.tr(`emailPlaceholder`):this.tr(`messagePlaceholder`),this.input.value=``,this.send.disabled=e===`sending`,this.send.textContent=e===`sending`?this.tr(`sending`):this.tr(`send`),this.form.classList.toggle(`tkc-hidden`,e===`done`)}async onSubmit(){switch(this.step){case`email`:{let e=this.input.value.trim();if(!h(e)){this.botSay(`errorEmail`);return}this.state.email=e,this.appendMessage(`tkc-msg-user`,e),this.botSay(`askMessage`),this.setStep(`message`),this.input.focus();return}case`message`:{let e=this.input.value.trim();if(e===``)return;this.state.message=e,this.appendMessage(`tkc-msg-user`,e),this.botSay(`confirm`),this.setStep(`confirm`);return}case`confirm`:if(this.state.token){await this.submitInquiry();return}this.pendingSubmit=!0,this.send.disabled=!0,this.send.textContent=this.tr(`verifying`),this.renderTurnstile();return;default:return}}renderTurnstile(){this.turnstileRendered||(this.turnstileRendered=!0,v().then(e=>{e.render(this.turnstileHost,{sitekey:this.cfg.siteKey,theme:`auto`,language:this.cfg.locale,appearance:`interaction-only`,callback:e=>{this.state.token=e,this.pendingSubmit&&(this.pendingSubmit=!1,this.submitInquiry())},\"expired-callback\":()=>{this.state.token=``},\"error-callback\":()=>{this.state.token=``,this.pendingSubmit&&(this.botSay(`errorChallenge`),this.resetSendButton())}})}).catch(()=>{this.botSay(`errorGeneric`),this.resetSendButton()}))}resetSendButton(){this.pendingSubmit=!1,this.send.disabled=!1,this.send.textContent=this.tr(`retry`)}async submitInquiry(){this.state.honeypot=this.honeypot.value,this.setStep(`sending`),this.botSay(`sending`);let e=!1,t;try{let n=await fetch(this.cfg.endpoint,{method:`POST`,headers:{\"content-type\":`application/json`},body:JSON.stringify(c(this.state))}),r=await n.json().catch(()=>null);e=n.ok&&r?.ok===!0,t=r?.error}catch{}if(e){this.botSay(`done`),this.setStep(`done`);return}this.botSay(l(t)),this.state.token=``;let n=g();n&&n.reset(),this.send.textContent=this.tr(`retry`),this.send.disabled=!1,this.step=`confirm`}};function C(e,t){let n=new S(e);return n.mount(t),n}var w=document.currentScript;function T(){let e=w instanceof HTMLElement?w.dataset:void 0,t=i(window.TAKUHON_CONTACT,e);t?.siteKey&&C({siteKey:t.siteKey,endpoint:t.endpoint,locale:t.locale,lang:t.lang??document.documentElement.lang,pageUrl:t.pageUrl??window.location.href})}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,T,{once:!0}):T(),e.mountContactWidget=C,e})({});";
|
|
5
|
+
export const contactWidgetCss = ".tkc-root{z-index:2147483000;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Noto Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:14px;line-height:1.5;position:fixed;bottom:1rem;right:1rem}.tkc-launcher{color:#fff;cursor:pointer;background:#1e1888;border:none;border-radius:50%;justify-content:center;align-items:center;width:3.5rem;height:3.5rem;padding:0;transition:transform .15s,background .15s;display:inline-flex;box-shadow:0 6px 20px #00000038}.tkc-launcher:hover{background:#2a23a8;transform:scale(1.06)}.tkc-launcher:focus-visible{outline-offset:2px;outline:2px solid #818cf8}.tkc-send:focus-visible{outline-offset:2px;outline:2px solid #818cf8}.tkc-input:focus-visible{outline-offset:2px;outline:2px solid #818cf8}.tkc-close:focus-visible{outline-offset:2px;outline:2px solid #818cf8}.tkc-panel{color:#1f2430;background:#fff;border-radius:14px;flex-direction:column;width:min(22rem,100vw - 2rem);height:min(30rem,100vh - 4rem);display:flex;overflow:hidden;box-shadow:0 12px 40px #00000038}.tkc-header{color:#fff;background:#1e1888;justify-content:space-between;align-items:center;padding:.75rem 1rem;font-weight:600;display:flex}.tkc-close{color:inherit;cursor:pointer;background:0 0;border:none;padding:0 .25rem;font-size:1.3rem;line-height:1}.tkc-log{background:#f6f7fb;flex-direction:column;flex:1;gap:.5rem;padding:.9rem;display:flex;overflow-y:auto}.tkc-msg{white-space:pre-wrap;word-break:break-word;border-radius:12px;max-width:85%;padding:.5rem .75rem}.tkc-msg-bot{background:#fff;border:1px solid #e4e6ef;align-self:flex-start}.tkc-msg-user{color:#fff;background:#1e1888;align-self:flex-end}.tkc-turnstile{padding:0 .9rem}.tkc-turnstile:empty{display:none}.tkc-form{border-top:1px solid #e4e6ef;gap:.5rem;padding:.75rem;display:flex}.tkc-input{min-width:0;font:inherit;border:1px solid #c8ccda;border-radius:8px;flex:1;padding:.55rem .7rem}.tkc-honeypot{opacity:0;width:1px;height:1px;position:absolute;left:-9999px}.tkc-send{color:#fff;font:inherit;cursor:pointer;background:#1e1888;border:none;border-radius:8px;padding:.55rem 1rem;font-weight:600}.tkc-send:disabled{opacity:.55;cursor:default}.tkc-hidden{display:none!important}@media (prefers-color-scheme:dark){.tkc-panel{color:#e6e8f0;background:#1a1d29}.tkc-log{background:#11131c}.tkc-msg-bot{color:#e6e8f0;background:#232737;border-color:#2f3550}.tkc-form{border-top-color:#2f3550}.tkc-input{color:#e6e8f0;background:#232737;border-color:#3a4060}}\n/*$vite$:1*/";
|
package/dist/contact-widget.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var TakuhonContact=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=[`ja`,`en`];function n(e){if(typeof e==`string`){let n=e.trim().toLowerCase().split(`-`)[0];if(n!==void 0&&t.includes(n))return n}return`ja`}var r=`/api/contact`;function i(e){let t=typeof e.endpoint==`string`&&e.endpoint.trim()!==``?e.endpoint.trim():r;return{siteKey:e.siteKey,endpoint:t,locale:n(e.locale??e.lang),...e.pageUrl?{pageUrl:e.pageUrl}:{}}}var
|
|
1
|
+
var TakuhonContact=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=[`ja`,`en`];function n(e){if(typeof e==`string`){let n=e.trim().toLowerCase().split(`-`)[0];if(n!==void 0&&t.includes(n))return n}return`ja`}var r=`/api/contact`;function i(e,t){if(e?.siteKey)return{...e,siteKey:e.siteKey};if(t?.siteKey)return{siteKey:t.siteKey,...t.endpoint?{endpoint:t.endpoint}:{},...t.locale?{locale:t.locale}:{},...t.lang?{lang:t.lang}:{},...t.pageUrl?{pageUrl:t.pageUrl}:{}}}function a(e){let t=typeof e.endpoint==`string`&&e.endpoint.trim()!==``?e.endpoint.trim():r;return{siteKey:e.siteKey,endpoint:t,locale:n(e.locale??e.lang),...e.pageUrl?{pageUrl:e.pageUrl}:{}}}var o={ja:{launcher:`お問い合わせ`,title:`お問い合わせ`,close:`閉じる`,greeting:`こんにちは。お問い合わせ内容をお送りください。確認後、メールで返信します。`,askEmail:`まず、返信先のメールアドレスを入力してください。`,askMessage:`ありがとうございます。次にお問い合わせ内容を入力してください。`,confirm:`送信してよろしいですか?`,send:`送信`,sending:`送信中…`,verifying:`確認中…`,done:`お問い合わせを受け付けました。確認後、メールで返信します。`,retry:`もう一度送信する`,challengePrompt:`送信前に確認にお答えください。`,emailPlaceholder:`you@example.com`,messagePlaceholder:`お問い合わせ内容`,errorEmail:`メールアドレスの形式が正しくないようです。`,errorChallenge:`確認に失敗しました。もう一度お試しください。`,errorGeneric:`送信に失敗しました。時間をおいて再度お試しください。`},en:{launcher:`Contact`,title:`Contact`,close:`Close`,greeting:`Hi! Send your question below and we'll reply by email.`,askEmail:`First, what email address should we reply to?`,askMessage:`Thanks! Now, what would you like to ask?`,confirm:`Ready to send?`,send:`Send`,sending:`Sending…`,verifying:`Verifying…`,done:`Got it — we'll review your message and reply by email.`,retry:`Try again`,challengePrompt:`Please complete the check before sending.`,emailPlaceholder:`you@example.com`,messagePlaceholder:`Your message`,errorEmail:`That email address doesn't look right.`,errorChallenge:`Verification failed. Please try again.`,errorGeneric:`Something went wrong. Please try again later.`}};function s(e,t){return o[e][t]}function c(e){return{email:e.email,message:e.message,locale:e.locale,token:e.token,hp:e.honeypot,...e.pageUrl?{pageUrl:e.pageUrl}:{}}}function l(e){switch(e){case`email_invalid`:case`email_missing`:case`email_too_long`:return`errorEmail`;case`challenge_failed`:return`errorChallenge`;default:return`errorGeneric`}}function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var m=`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit`;function h(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim())}function g(){return globalThis.turnstile}var _;function v(){let e=g();return e?Promise.resolve(e):_||(_=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=m,n.async=!0,n.addEventListener(`load`,()=>{let n=g();n?e(n):t(Error(`turnstile unavailable after load`))}),n.addEventListener(`error`,()=>t(Error(`turnstile script failed to load`))),document.head.appendChild(n)}),_)}function y(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var b=`http://www.w3.org/2000/svg`;function x(){let e=document.createElementNS(b,`svg`);e.setAttribute(`viewBox`,`0 0 24 24`),e.setAttribute(`width`,`26`),e.setAttribute(`height`,`26`),e.setAttribute(`aria-hidden`,`true`),e.setAttribute(`focusable`,`false`);let t=document.createElementNS(b,`path`);return t.setAttribute(`fill`,`currentColor`),t.setAttribute(`d`,`M12 3C6.5 3 2 6.58 2 11c0 2.4 1.32 4.56 3.4 6.04L5 21l3.9-2.05c.98.26 2.02.4 3.1.4 5.5 0 10-3.58 10-8s-4.5-8-10-8z`),e.appendChild(t),e}var S=class{constructor(e){p(this,`cfg`,void 0),p(this,`state`,void 0),p(this,`step`,`email`),p(this,`opened`,!1),p(this,`greeted`,!1),p(this,`turnstileRendered`,!1),p(this,`pendingSubmit`,!1),p(this,`root`,void 0),p(this,`launcher`,void 0),p(this,`panel`,void 0),p(this,`log`,void 0),p(this,`turnstileHost`,void 0),p(this,`form`,void 0),p(this,`input`,void 0),p(this,`honeypot`,void 0),p(this,`send`,void 0),this.cfg=a(e),this.state={email:``,message:``,token:``,honeypot:``,locale:this.cfg.locale,...this.cfg.pageUrl?{pageUrl:this.cfg.pageUrl}:{}}}tr(e){return s(this.cfg.locale,e)}mount(e=document.body){this.root=y(`div`,`tkc-root`),this.launcher=y(`button`,`tkc-launcher`),this.launcher.type=`button`,this.launcher.setAttribute(`aria-haspopup`,`dialog`),this.launcher.setAttribute(`aria-label`,this.tr(`launcher`)),this.launcher.append(x()),this.launcher.addEventListener(`click`,()=>this.open()),this.panel=y(`div`,`tkc-panel tkc-hidden`),this.panel.setAttribute(`role`,`dialog`),this.panel.setAttribute(`aria-label`,this.tr(`title`));let t=y(`div`,`tkc-header`);t.append(y(`span`,void 0,this.tr(`title`)));let n=y(`button`,`tkc-close`,`×`);n.type=`button`,n.setAttribute(`aria-label`,this.tr(`close`)),n.addEventListener(`click`,()=>this.close()),t.append(n),this.log=y(`div`,`tkc-log`),this.log.setAttribute(`role`,`log`),this.log.setAttribute(`aria-live`,`polite`),this.turnstileHost=y(`div`,`tkc-turnstile`),this.form=y(`form`,`tkc-form`),this.honeypot=y(`input`,`tkc-honeypot`),this.honeypot.type=`text`,this.honeypot.tabIndex=-1,this.honeypot.autocomplete=`off`,this.honeypot.setAttribute(`aria-hidden`,`true`),this.honeypot.name=`company`,this.input=y(`input`,`tkc-input`),this.input.type=`text`,this.input.autocomplete=`off`,this.input.setAttribute(`aria-label`,this.tr(`title`)),this.send=y(`button`,`tkc-send`,this.tr(`send`)),this.send.type=`submit`,this.form.append(this.honeypot,this.input,this.send),this.form.addEventListener(`submit`,e=>{e.preventDefault(),this.onSubmit()}),this.panel.append(t,this.log,this.turnstileHost,this.form),this.root.append(this.launcher,this.panel),e.append(this.root),document.addEventListener(`click`,e=>{if(!this.opened)return;let t=e.target;t instanceof Node&&this.root.contains(t)||this.close(!1)}),document.addEventListener(`keydown`,e=>{this.opened&&e.key===`Escape`&&this.close()})}open(){this.opened||(this.opened=!0,this.launcher.classList.add(`tkc-hidden`),this.panel.classList.remove(`tkc-hidden`),this.greeted||(this.greeted=!0,this.botSay(`greeting`),this.botSay(`askEmail`)),this.setStep(`email`),this.input.focus())}close(e=!0){this.opened=!1,this.panel.classList.add(`tkc-hidden`),this.launcher.classList.remove(`tkc-hidden`),e&&this.launcher.focus()}botSay(e){this.appendMessage(`tkc-msg-bot`,this.tr(e))}appendMessage(e,t){let n=y(`div`,`tkc-msg ${e}`,t);this.log.append(n),this.log.scrollTop=this.log.scrollHeight}setStep(e){this.step=e;let t=e===`email`||e===`message`;this.input.classList.toggle(`tkc-hidden`,!t),this.input.placeholder=e===`email`?this.tr(`emailPlaceholder`):this.tr(`messagePlaceholder`),this.input.value=``,this.send.disabled=e===`sending`,this.send.textContent=e===`sending`?this.tr(`sending`):this.tr(`send`),this.form.classList.toggle(`tkc-hidden`,e===`done`)}async onSubmit(){switch(this.step){case`email`:{let e=this.input.value.trim();if(!h(e)){this.botSay(`errorEmail`);return}this.state.email=e,this.appendMessage(`tkc-msg-user`,e),this.botSay(`askMessage`),this.setStep(`message`),this.input.focus();return}case`message`:{let e=this.input.value.trim();if(e===``)return;this.state.message=e,this.appendMessage(`tkc-msg-user`,e),this.botSay(`confirm`),this.setStep(`confirm`);return}case`confirm`:if(this.state.token){await this.submitInquiry();return}this.pendingSubmit=!0,this.send.disabled=!0,this.send.textContent=this.tr(`verifying`),this.renderTurnstile();return;default:return}}renderTurnstile(){this.turnstileRendered||(this.turnstileRendered=!0,v().then(e=>{e.render(this.turnstileHost,{sitekey:this.cfg.siteKey,theme:`auto`,language:this.cfg.locale,appearance:`interaction-only`,callback:e=>{this.state.token=e,this.pendingSubmit&&(this.pendingSubmit=!1,this.submitInquiry())},"expired-callback":()=>{this.state.token=``},"error-callback":()=>{this.state.token=``,this.pendingSubmit&&(this.botSay(`errorChallenge`),this.resetSendButton())}})}).catch(()=>{this.botSay(`errorGeneric`),this.resetSendButton()}))}resetSendButton(){this.pendingSubmit=!1,this.send.disabled=!1,this.send.textContent=this.tr(`retry`)}async submitInquiry(){this.state.honeypot=this.honeypot.value,this.setStep(`sending`),this.botSay(`sending`);let e=!1,t;try{let n=await fetch(this.cfg.endpoint,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(c(this.state))}),r=await n.json().catch(()=>null);e=n.ok&&r?.ok===!0,t=r?.error}catch{}if(e){this.botSay(`done`),this.setStep(`done`);return}this.botSay(l(t)),this.state.token=``;let n=g();n&&n.reset(),this.send.textContent=this.tr(`retry`),this.send.disabled=!1,this.step=`confirm`}};function C(e,t){let n=new S(e);return n.mount(t),n}var w=document.currentScript;function T(){let e=w instanceof HTMLElement?w.dataset:void 0,t=i(window.TAKUHON_CONTACT,e);t?.siteKey&&C({siteKey:t.siteKey,endpoint:t.endpoint,locale:t.locale,lang:t.lang??document.documentElement.lang,pageUrl:t.pageUrl??window.location.href})}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,T,{once:!0}):T(),e.mountContactWidget=C,e})({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takuhon/contact",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Portable, framework-agnostic contact-form core for takuhon — validation, a stateless inquiry pipeline, and challenge/email transport interfaces. Host wiring (e.g. Cloudflare Turnstile + send_email) lives in the adapters.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Takuhon contributors",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"import": "./dist/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./assets": {
|
|
32
|
+
"types": "./dist/assets.d.ts",
|
|
33
|
+
"import": "./dist/assets.js"
|
|
34
|
+
},
|
|
31
35
|
"./package.json": "./package.json"
|
|
32
36
|
},
|
|
33
37
|
"files": [
|
|
@@ -45,7 +49,7 @@
|
|
|
45
49
|
},
|
|
46
50
|
"scripts": {
|
|
47
51
|
"typecheck": "tsc",
|
|
48
|
-
"build": "tsup src/index.ts --format esm --dts --clean --sourcemap && vite build",
|
|
52
|
+
"build": "tsup src/index.ts --format esm --dts --clean --sourcemap && vite build && node scripts/emit-asset-strings.mjs",
|
|
49
53
|
"test": "vitest run"
|
|
50
54
|
}
|
|
51
55
|
}
|