@klappay/one 1.0.1 → 1.0.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.
@@ -1,4 +1,4 @@
1
- "use strict";var KlappayOne=(()=>{var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var o in t)y(e,o,{get:t[o],enumerable:!0})},H=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of B(t))!L.call(e,n)&&n!==o&&y(e,n,{get:()=>t[n],enumerable:!(a=M(t,n))||a.enumerable});return e};var $=e=>H(y({},"__esModule",{value:!0}),e);var re={};z(re,{configure:()=>P,createKlappayOne:()=>u});function q(e){return typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string"&&e.type.startsWith("klappay:")&&"requestId"in e&&typeof e.requestId=="string"}function m(e,t,o){let a=!1,n=setTimeout(()=>{a||o.onTimeout?.()},1e4);function i(r){if(r.origin!==e||!q(r.data)||r.data.requestId!==t)return;let s=r.data;switch(s.type){case"klappay:ready":a=!0,clearTimeout(n),o.onReady?.();return;case"klappay:success":o.onSuccess?.(s.result);return;case"klappay:error":o.onError?.(s.error);return;case"klappay:cancel":o.onCancel?.();return;case"klappay:resize":o.onResize?.(s.height);return}}return window.addEventListener("message",i),()=>{clearTimeout(n),window.removeEventListener("message",i)}}function h(e){let t=new URL("/id/",e.klapOneOrigin);return t.searchParams.set("chargeId",e.chargeId),t.searchParams.set("requestId",e.requestId),t.searchParams.set("returnOrigin",window.location.origin),e.locale&&t.searchParams.set("locale",e.locale),t.toString()}var D=/Android|iPhone|iPad|iPod/i;function A(e){return D.test(e)}function N(){return`
1
+ "use strict";var KlappayOne=(()=>{var f=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var o in t)f(e,o,{get:t[o],enumerable:!0})},H=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of B(t))!M.call(e,n)&&n!==o&&f(e,n,{get:()=>t[n],enumerable:!(a=z(t,n))||a.enumerable});return e};var $=e=>H(f({},"__esModule",{value:!0}),e);var re={};L(re,{configure:()=>P,createKlappayOne:()=>u});function q(e){return typeof e=="object"&&e!==null&&"type"in e&&typeof e.type=="string"&&e.type.startsWith("klappay:")&&"requestId"in e&&typeof e.requestId=="string"}function m(e,t,o){let a=!1,n=setTimeout(()=>{a||o.onTimeout?.()},1e4);function i(r){if(r.origin!==e||!q(r.data)||r.data.requestId!==t)return;let s=r.data;switch(s.type){case"klappay:ready":a=!0,clearTimeout(n),o.onReady?.();return;case"klappay:success":o.onSuccess?.(s.result);return;case"klappay:error":o.onError?.(s.error);return;case"klappay:cancel":o.onCancel?.();return;case"klappay:resize":o.onResize?.(s.height);return}}return window.addEventListener("message",i),()=>{clearTimeout(n),window.removeEventListener("message",i)}}function h(e){let t=new URL("/id/",e.klapOneOrigin);return t.searchParams.set("chargeId",e.chargeId),t.searchParams.set("requestId",e.requestId),t.searchParams.set("returnOrigin",window.location.origin),e.locale&&t.searchParams.set("locale",e.locale),t.toString()}var D=/Android|iPhone|iPad|iPod/i;function A(e){return D.test(e)}function N(){return`
2
2
  .backdrop {
3
3
  position: fixed;
4
4
  inset: 0;
@@ -18,7 +18,7 @@
18
18
  background: #000;
19
19
  transition: height 0.15s ease;
20
20
  }
21
- `}function O(e,t){let o=document.createElement("div"),a=o.attachShadow({mode:"open"}),n=document.createElement("style");n.textContent=N();let i=document.createElement("div");i.className="backdrop",i.addEventListener("click",s=>{s.target===i&&t()});let r=document.createElement("iframe");return r.className="frame",r.src=e,i.append(r),a.append(n,i),document.body.append(o),{close:()=>o.remove(),resize:s=>{r.style.height=`${s}px`}}}var G="klappay-one";function k(e){let t=window.screenX+(window.outerWidth-420)/2,o=window.screenY+(window.outerHeight-720)/2;return window.open(e,G,`width=420,height=720,left=${t},top=${o}`)}function E(e){return e===null||e.closed}var W={code:"POPUP_BLOCKED",message:"The Klappay One popup was blocked."},V={code:"FRAME_TIMEOUT",message:"The Klappay One popup did not respond in time."},F=500,x={};function P(e){x=e}function l(){return x}function Y(e){return e.mode??(A(navigator.userAgent)?"popup":"iframe")}function u(e){function t(){Y(e)==="popup"?o():a()}function o(){let n=crypto.randomUUID(),i=h({klapOneOrigin:e.origin,chargeId:e.chargeId,requestId:n,locale:e.locale}),r=k(i);if(E(r)){e.onError?.(W);return}let s=m(e.origin,n,{onReady:e.onReady,onSuccess:d=>{p(),e.onSuccess?.(d)},onError:d=>{p(),e.onError?.(d)},onCancel:()=>{p(),e.onCancel?.()},onTimeout:()=>{p(),e.onError?.(V)}}),f=setInterval(()=>{E(r)&&(p(),e.onCancel?.())},F);function p(){clearInterval(f),s()}}function a(){let n=crypto.randomUUID(),i=h({klapOneOrigin:e.origin,chargeId:e.chargeId,requestId:n,locale:e.locale}),r=!1;function s(c){r||(r=!0,d(),c())}let f=O(i,()=>s(()=>e.onCancel?.())),p=m(e.origin,n,{onReady:e.onReady,onSuccess:c=>s(()=>e.onSuccess?.(c)),onError:c=>s(()=>e.onError?.(c)),onCancel:()=>s(()=>e.onCancel?.()),onResize:c=>f.resize(c),onTimeout:()=>s(o)});function d(){p(),f.close()}}return{open:t}}var g="data-klappay-one",w="data-klappay-one-origin",j="data-klappay-one-locale",Z="data-klappay-one-mode",_="data-klappay-one-wired",b="data-klappay-one-busy";function v(e){e.hasAttribute(_)||(e.setAttribute(_,""),e.addEventListener("click",()=>{if(e.hasAttribute(b))return;let t=e.getAttribute(g);if(!t)return;let o=e.getAttribute(w)??l().origin;if(!o){console.error(`[${g}] has no origin \u2014 set ${w} or call KlappayOne.configure({ origin }).`);return}let a=e.getAttribute(j)??l().locale,n=e.getAttribute(Z);e.setAttribute(b,"");let i=()=>{e.removeAttribute(b)};u({chargeId:t,origin:o,locale:a,mode:n==="iframe"||n==="popup"?n:void 0,onSuccess:r=>{i(),e.dispatchEvent(new CustomEvent("success",{detail:r}))},onError:r=>{i(),e.dispatchEvent(new CustomEvent("error",{detail:r}))},onCancel:()=>{i(),e.dispatchEvent(new CustomEvent("cancel"))}}).open()}))}function I(e=document){for(let t of e.querySelectorAll(`[${g}]`))v(t)}function R(e=document.body){let t=new MutationObserver(o=>{for(let a of o)for(let n of a.addedNodes)if(n instanceof Element){n.hasAttribute(g)&&v(n);for(let i of n.querySelectorAll(`[${g}]`))v(i)}});return t.observe(e,{childList:!0,subtree:!0}),()=>t.disconnect()}var C="klappay-button",S=["white","yellow","black"],K=["sm","md","lg"],X="black",J="md",Q={sm:{height:"32px",fontSize:"13px",padding:"0 14px"},md:{height:"40px",fontSize:"14px",padding:"0 18px"},lg:{height:"48px",fontSize:"16px",padding:"0 24px"}},ee={white:{background:"#ffffff",color:"#111111",border:"1px solid #e5e5e5"},yellow:{background:"#f2b90c",color:"#111111",border:"none"},black:{background:"#111111",color:"#ffffff",border:"none"}};function te(e){return S.includes(e)}function ne(e){return K.includes(e)}var oe=typeof HTMLElement<"u"?HTMLElement:class{},T=class e extends oe{static get observedAttributes(){return["variant","size"]}#e;constructor(){super();let t=this.attachShadow({mode:"open"}),o=document.createElement("style");o.textContent=e.#r(),this.#e=document.createElement("button"),this.#e.type="button",this.#e.textContent="Pay with Klappay",this.#e.addEventListener("click",()=>this.#o()),t.append(o,this.#e),this.#t(),this.#n()}attributeChangedCallback(t){t==="variant"&&this.#t(),t==="size"&&this.#n()}get variant(){let t=this.getAttribute("variant")??"";return te(t)?t:X}get size(){let t=this.getAttribute("size")??"";return ne(t)?t:J}#t(){this.#e.setAttribute("data-variant",this.variant)}#n(){this.#e.setAttribute("data-size",this.size)}#o(){if(this.#e.disabled)return;let t=this.getAttribute("charge-id");if(!t){console.error("<klappay-button> is missing a required charge-id attribute.");return}let o=this.getAttribute("origin")??l().origin;if(!o){console.error("<klappay-button> has no origin \u2014 set the origin attribute or call KlappayOne.configure({ origin }).");return}let a=this.getAttribute("locale")??l().locale,n=this.getAttribute("mode");this.#e.disabled=!0;let i=()=>{this.#e.disabled=!1};u({chargeId:t,origin:o,locale:a,mode:n==="iframe"||n==="popup"?n:void 0,onSuccess:r=>{i(),this.dispatchEvent(new CustomEvent("success",{detail:r}))},onError:r=>{i(),this.dispatchEvent(new CustomEvent("error",{detail:r}))},onCancel:()=>{i(),this.dispatchEvent(new CustomEvent("cancel"))}}).open()}static#r(){let t=S.map(a=>{let{background:n,color:i,border:r}=ee[a];return`button[data-variant="${a}"] { background: var(--klappay-background, ${n}); color: var(--klappay-color, ${i}); border: ${r}; }`}).join(`
21
+ `}function O(e,t){let o=document.createElement("div"),a=o.attachShadow({mode:"open"}),n=document.createElement("style");n.textContent=N();let i=document.createElement("div");i.className="backdrop",i.addEventListener("click",s=>{s.target===i&&t()});let r=document.createElement("iframe");return r.className="frame",r.src=e,i.append(r),a.append(n,i),document.body.append(o),{close:()=>o.remove(),resize:s=>{r.style.height=`${s}px`}}}var G="klappay-one";function k(e){let t=window.screenX+(window.outerWidth-420)/2,o=window.screenY+(window.outerHeight-720)/2;return window.open(e,G,`width=420,height=720,left=${t},top=${o}`)}function b(e){return e===null||e.closed}var V={code:"POPUP_BLOCKED",message:"The Klappay One popup was blocked."},W={code:"FRAME_TIMEOUT",message:"The Klappay One popup did not respond in time."},F=500,x={};function P(e){x=e}function l(){return x}function Y(e){return e.mode??(A(navigator.userAgent)?"popup":"iframe")}function u(e){function t(){Y(e)==="popup"?o():a()}function o(){let n=crypto.randomUUID(),i=h({klapOneOrigin:e.origin,chargeId:e.chargeId,requestId:n,locale:e.locale}),r=k(i);if(b(r)){e.onError?.(V);return}let s=m(e.origin,n,{onReady:e.onReady,onSuccess:d=>{p(),e.onSuccess?.(d)},onError:d=>{p(),e.onError?.(d)},onCancel:()=>{p(),e.onCancel?.()},onTimeout:()=>{p(),e.onError?.(W)}}),y=setInterval(()=>{b(r)&&(p(),e.onCancel?.())},F);function p(){clearInterval(y),s()}}function a(){let n=crypto.randomUUID(),i=h({klapOneOrigin:e.origin,chargeId:e.chargeId,requestId:n,locale:e.locale}),r=!1;function s(c){r||(r=!0,d(),c())}let y=O(i,()=>s(()=>e.onCancel?.())),p=m(e.origin,n,{onReady:e.onReady,onSuccess:c=>s(()=>e.onSuccess?.(c)),onError:c=>s(()=>e.onError?.(c)),onCancel:()=>s(()=>e.onCancel?.()),onResize:c=>y.resize(c),onTimeout:()=>s(o)});function d(){p(),y.close()}}return{open:t}}var g="data-klappay-one",w="data-klappay-one-origin",j="data-klappay-one-locale",Z="data-klappay-one-mode",_="data-klappay-one-wired",E="data-klappay-one-busy";function v(e){e.hasAttribute(_)||(e.setAttribute(_,""),e.addEventListener("click",()=>{if(e.hasAttribute(E))return;let t=e.getAttribute(g);if(!t)return;let o=e.getAttribute(w)??l().origin;if(!o){console.error(`[${g}] has no origin \u2014 set ${w} or call KlappayOne.configure({ origin }).`);return}let a=e.getAttribute(j)??l().locale,n=e.getAttribute(Z);e.setAttribute(E,"");let i=()=>{e.removeAttribute(E)};u({chargeId:t,origin:o,locale:a,mode:n==="iframe"||n==="popup"?n:void 0,onSuccess:r=>{i(),e.dispatchEvent(new CustomEvent("success",{detail:r}))},onError:r=>{i(),e.dispatchEvent(new CustomEvent("error",{detail:r}))},onCancel:()=>{i(),e.dispatchEvent(new CustomEvent("cancel"))}}).open()}))}function I(e=document){for(let t of e.querySelectorAll(`[${g}]`))v(t)}function R(e=document.body){let t=new MutationObserver(o=>{for(let a of o)for(let n of a.addedNodes)if(n instanceof Element){n.hasAttribute(g)&&v(n);for(let i of n.querySelectorAll(`[${g}]`))v(i)}});return t.observe(e,{childList:!0,subtree:!0}),()=>t.disconnect()}var S="klappay-button",C=["white","yellow","black"],K=["sm","md","lg"],X="black",J="md",Q={sm:{height:"32px",fontSize:"13px",padding:"0 14px"},md:{height:"40px",fontSize:"14px",padding:"0 18px"},lg:{height:"48px",fontSize:"16px",padding:"0 24px"}},ee={white:{background:"#ffffff",color:"#111111",border:"1px solid #e5e5e5"},yellow:{background:"#f2b90c",color:"#111111",border:"none"},black:{background:"#111111",color:"#ffffff",border:"none"}};function te(e){return C.includes(e)}function ne(e){return K.includes(e)}var oe=typeof HTMLElement<"u"?HTMLElement:class{},T=class e extends oe{static get observedAttributes(){return["variant","size"]}#e;constructor(){super();let t=this.attachShadow({mode:"open"}),o=document.createElement("style");o.textContent=e.#r(),this.#e=document.createElement("button"),this.#e.type="button",this.#e.textContent="Pay with Klappay",this.#e.addEventListener("click",()=>this.#o()),t.append(o,this.#e),this.#t(),this.#n()}attributeChangedCallback(t){t==="variant"&&this.#t(),t==="size"&&this.#n()}get variant(){let t=this.getAttribute("variant")??"";return te(t)?t:X}set variant(t){this.setAttribute("variant",t)}get size(){let t=this.getAttribute("size")??"";return ne(t)?t:J}set size(t){this.setAttribute("size",t)}#t(){this.#e.setAttribute("data-variant",this.variant)}#n(){this.#e.setAttribute("data-size",this.size)}#o(){if(this.#e.disabled)return;let t=this.getAttribute("charge-id");if(!t){console.error("<klappay-button> is missing a required charge-id attribute.");return}let o=this.getAttribute("origin")??l().origin;if(!o){console.error("<klappay-button> has no origin \u2014 set the origin attribute or call KlappayOne.configure({ origin }).");return}let a=this.getAttribute("locale")??l().locale,n=this.getAttribute("mode");this.#e.disabled=!0;let i=()=>{this.#e.disabled=!1};u({chargeId:t,origin:o,locale:a,mode:n==="iframe"||n==="popup"?n:void 0,onSuccess:r=>{i(),this.dispatchEvent(new CustomEvent("success",{detail:r}))},onError:r=>{i(),this.dispatchEvent(new CustomEvent("error",{detail:r}))},onCancel:()=>{i(),this.dispatchEvent(new CustomEvent("cancel"))}}).open()}static#r(){let t=C.map(a=>{let{background:n,color:i,border:r}=ee[a];return`button[data-variant="${a}"] { background: var(--klappay-background, ${n}); color: var(--klappay-color, ${i}); border: ${r}; }`}).join(`
22
22
  `),o=K.map(a=>{let{height:n,fontSize:i,padding:r}=Q[a];return`button[data-size="${a}"] { height: var(--klappay-button-height, ${n}); font-size: ${i}; padding: ${r}; }`}).join(`
23
23
  `);return`
24
24
  button {
@@ -36,4 +36,4 @@
36
36
  button:disabled { opacity: 0.6; cursor: not-allowed; }
37
37
  ${t}
38
38
  ${o}
39
- `}};function U(){typeof customElements>"u"||customElements.get(C)||customElements.define(C,T)}U();typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>I()):I(),R());return $(re);})();
39
+ `}};function U(){typeof customElements>"u"||customElements.get(S)||customElements.define(S,T)}U();typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>I()):I(),R());return $(re);})();
package/dist/index.js CHANGED
@@ -338,10 +338,16 @@ var KlappayButtonElement = class _KlappayButtonElement extends KlappayButtonBase
338
338
  const value = this.getAttribute("variant") ?? "";
339
339
  return isVariant(value) ? value : DEFAULT_VARIANT;
340
340
  }
341
+ set variant(value) {
342
+ this.setAttribute("variant", value);
343
+ }
341
344
  get size() {
342
345
  const value = this.getAttribute("size") ?? "";
343
346
  return isSize(value) ? value : DEFAULT_SIZE;
344
347
  }
348
+ set size(value) {
349
+ this.setAttribute("size", value);
350
+ }
345
351
  #applyVariant() {
346
352
  this.#button.setAttribute("data-variant", this.variant);
347
353
  }
@@ -274,10 +274,16 @@ var KlappayButtonElement = class _KlappayButtonElement extends KlappayButtonBase
274
274
  const value = this.getAttribute("variant") ?? "";
275
275
  return isVariant(value) ? value : DEFAULT_VARIANT;
276
276
  }
277
+ set variant(value) {
278
+ this.setAttribute("variant", value);
279
+ }
277
280
  get size() {
278
281
  const value = this.getAttribute("size") ?? "";
279
282
  return isSize(value) ? value : DEFAULT_SIZE;
280
283
  }
284
+ set size(value) {
285
+ this.setAttribute("size", value);
286
+ }
281
287
  #applyVariant() {
282
288
  this.#button.setAttribute("data-variant", this.variant);
283
289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klappay/one",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "description": "Klappay One's embeddable payment button — opens the hosted identity/wallet popup (one-id) and relays the result via postMessage. Never touches a private key or a session token; framework-agnostic core with a thin React wrapper.",
6
6
  "keywords": [