recur-tw 0.13.0 → 0.13.2
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/checkout.js +10 -2
- package/dist/index.cjs +155 -80
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +155 -80
- package/dist/recur.umd.js +48 -49
- package/dist/server.cjs +1 -1
- package/dist/server.js +1 -1
- package/dist/widget.js +11 -3
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
package/dist/server.js
CHANGED
package/dist/widget.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var RecurWidgetScript=(()=>{var
|
|
1
|
+
"use strict";var RecurWidgetScript=(()=>{var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},k=(e,t,i,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!v.call(e,o)&&o!==i&&p(e,o,{get:()=>t[o],enumerable:!(a=x(t,o))||a.enumerable});return e};var C=e=>k(p({},"__esModule",{value:!0}),e);var L={};E(L,{default:()=>W});var d={text:"\u8A02\u95B1\u652F\u6301",color:"#667eea",textColor:"#ffffff",position:"right",xMargin:18,yMargin:18,embedUrl:"https://embed.recur.tw",apiUrl:"https://api.recur.tw"},r=null,n=null,u=null,g=null;function _(){let e=document.querySelectorAll("script[data-product]"),t=e[e.length-1];if(!t)return console.error("[Recur Widget] Missing data-product attribute on script tag"),null;let i=t.getAttribute("data-key"),a=t.getAttribute("data-product");return i?a?{key:i,product:a,text:t.getAttribute("data-text")||d.text,color:t.getAttribute("data-color")||d.color,textColor:t.getAttribute("data-text-color")||d.textColor,position:t.getAttribute("data-position")||d.position,xMargin:parseInt(t.getAttribute("data-x-margin")||String(d.xMargin),10),yMargin:parseInt(t.getAttribute("data-y-margin")||String(d.yMargin),10),embedUrl:t.getAttribute("data-embed-url")||d.embedUrl,apiUrl:t.getAttribute("data-api-url")||d.apiUrl}:(console.error("[Recur Widget] Missing data-product attribute on script tag"),null):(console.error("[Recur Widget] Missing data-key attribute on script tag"),null)}function M(){if(!r)return;let e=window.location.hostname;(e==="localhost"||e==="127.0.0.1"||e.includes(".local"))&&(r.embedUrl=`${window.location.protocol}//${e}:3002`,r.apiUrl=`${window.location.protocol}//${e}:3000/api`)}function R(){if(!r||document.getElementById("recur-widget-styles"))return;let e=document.createElement("style");e.id="recur-widget-styles",e.textContent=`
|
|
2
2
|
.recur-widget-button {
|
|
3
3
|
position: fixed;
|
|
4
4
|
bottom: ${r.yMargin}px;
|
|
@@ -77,6 +77,14 @@
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
.recur-widget-dialog__content {
|
|
81
|
+
display: flex;
|
|
82
|
+
flex-direction: column;
|
|
83
|
+
width: 100%;
|
|
84
|
+
height: 100%;
|
|
85
|
+
outline: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
80
88
|
.recur-widget-dialog__header {
|
|
81
89
|
display: flex;
|
|
82
90
|
justify-content: flex-end;
|
|
@@ -123,10 +131,10 @@
|
|
|
123
131
|
max-height: 95vh;
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
|
-
`,document.head.appendChild(e)}function
|
|
134
|
+
`,document.head.appendChild(e)}function A(){if(!r||n)return;let e=document.createElement("button");e.className="recur-widget-button",e.setAttribute("aria-label",r.text),e.innerHTML=`
|
|
127
135
|
<svg class="recur-widget-button__icon" viewBox="0 0 24 24" fill="currentColor">
|
|
128
136
|
<path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/>
|
|
129
137
|
</svg>
|
|
130
138
|
<span>${r.text}</span>
|
|
131
|
-
`,e.addEventListener("click",
|
|
139
|
+
`,e.addEventListener("click",h),document.body.appendChild(e),n=e}async function U(){if(!r)throw new Error("Widget not configured");let e=await fetch(`${r.apiUrl}/v1/checkouts`,{method:"POST",headers:{"Content-Type":"application/json","X-Recur-Publishable-Key":r.key,"X-Recur-Embed-Domain":r.embedUrl,"X-Recur-SDK-Type":"widget.js","X-Recur-Source":window.location.origin},body:JSON.stringify({productId:r.product})});if(!e.ok){let i=await e.json().catch(()=>({}));throw new Error(i.error?.message||i.error||"Failed to create checkout")}let t=await e.json();return{id:t.checkout.id,clientSecret:t.checkout.client_secret}}function S(e){if(!r)return;c();let t=document.createElement("dialog");t.className="recur-widget-dialog";let i=document.createElement("div");i.className="recur-widget-dialog__content",i.setAttribute("tabindex","-1"),i.setAttribute("autofocus","");let a=document.createElement("div");a.className="recur-widget-dialog__header";let o=document.createElement("button");o.className="recur-widget-dialog__close",o.innerHTML="×",o.type="button",o.setAttribute("aria-label","Close"),o.onclick=()=>{c(),l("recur:close",{})},a.appendChild(o);let s=document.createElement("iframe");s.className="recur-widget-dialog__iframe",s.src=e,s.setAttribute("allow","payment"),s.setAttribute("title","Recur Checkout"),i.appendChild(a),i.appendChild(s),t.appendChild(i),document.body.appendChild(t),u=t,g=s,t.showModal(),document.body.style.overflow="hidden",t.addEventListener("cancel",w=>{w.preventDefault(),c(),l("recur:close",{})}),window.addEventListener("message",f)}function c(){u&&(u.close(),u.remove(),u=null),g=null,document.body.style.overflow="",window.removeEventListener("message",f)}function f(e){if(!e.origin.includes("recur.tw")&&!e.origin.includes("localhost"))return;let{type:t,data:i}=e.data||{};switch(t){case"RECUR_PAYMENT_SUCCESS":c(),l("recur:success",i);break;case"RECUR_PAYMENT_ERROR":l("recur:error",i);break;case"RECUR_PAYMENT_CANCEL":c(),l("recur:close",{});break;case"RECUR_RESIZE":g&&i?.height&&(g.style.height=`${Math.min(i.height+56,window.innerHeight*.9)}px`);break}}function l(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t}))}async function h(){if(!(!r||!n)){n.setAttribute("data-loading","true");try{let e=await U(),t=new URL(`${r.embedUrl}/checkout`);t.searchParams.set("id",e.id),t.searchParams.set("key",r.key),t.searchParams.set("client_secret",e.clientSecret),S(t.toString())}catch(e){console.error("[Recur Widget] Error:",e),l("recur:error",{message:e instanceof Error?e.message:"Unknown error"})}finally{n.setAttribute("data-loading","false")}}}var b={open(){h()},close(){c()},show(){n&&(n.style.display="flex")},hide(){n&&(n.style.display="none")},destroy(){c(),n&&(n.remove(),n=null);let e=document.getElementById("recur-widget-styles");e&&e.remove()}};function m(){r=_(),r&&(M(),R(),A())}window.RecurWidget=b;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",m):m();var W=b;return C(L);})();
|
|
132
140
|
/* Recur Widget - https://recur.tw */
|