@klappay/one 1.0.0 → 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.
- package/README.md +5 -2
- package/dist/index.global.js +3 -3
- package/dist/index.js +17 -6
- package/dist/react/index.js +10 -1
- package/logo.png +0 -0
- package/package.json +37 -21
package/README.md
CHANGED
|
@@ -74,8 +74,11 @@ function Checkout() {
|
|
|
74
74
|
|
|
75
75
|
## Documentation
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
Full docs, guides, and framework examples: **https://js-one.klappay.com**
|
|
78
|
+
(built from `docs/` in this repository — `docs/getting-started.md` for a
|
|
79
|
+
full walkthrough and `docs/protocol.md` for the popup/iframe embed and
|
|
80
|
+
`postMessage` contract this package implements against). Runnable example
|
|
81
|
+
apps live in [`examples/`](./examples).
|
|
79
82
|
|
|
80
83
|
## License
|
|
81
84
|
|
package/dist/index.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var KlappayOne=(()=>{var f=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var
|
|
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 b(e){return e===null||e.closed}var
|
|
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(){customElements.get(
|
|
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
|
@@ -310,7 +310,9 @@ function isVariant(value) {
|
|
|
310
310
|
function isSize(value) {
|
|
311
311
|
return SIZES.includes(value);
|
|
312
312
|
}
|
|
313
|
-
var
|
|
313
|
+
var KlappayButtonBase = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
314
|
+
};
|
|
315
|
+
var KlappayButtonElement = class _KlappayButtonElement extends KlappayButtonBase {
|
|
314
316
|
static get observedAttributes() {
|
|
315
317
|
return ["variant", "size"];
|
|
316
318
|
}
|
|
@@ -336,10 +338,16 @@ var KlappayButtonElement = class _KlappayButtonElement extends HTMLElement {
|
|
|
336
338
|
const value = this.getAttribute("variant") ?? "";
|
|
337
339
|
return isVariant(value) ? value : DEFAULT_VARIANT;
|
|
338
340
|
}
|
|
341
|
+
set variant(value) {
|
|
342
|
+
this.setAttribute("variant", value);
|
|
343
|
+
}
|
|
339
344
|
get size() {
|
|
340
345
|
const value = this.getAttribute("size") ?? "";
|
|
341
346
|
return isSize(value) ? value : DEFAULT_SIZE;
|
|
342
347
|
}
|
|
348
|
+
set size(value) {
|
|
349
|
+
this.setAttribute("size", value);
|
|
350
|
+
}
|
|
343
351
|
#applyVariant() {
|
|
344
352
|
this.#button.setAttribute("data-variant", this.variant);
|
|
345
353
|
}
|
|
@@ -414,6 +422,7 @@ var KlappayButtonElement = class _KlappayButtonElement extends HTMLElement {
|
|
|
414
422
|
}
|
|
415
423
|
};
|
|
416
424
|
function registerKlappayButton() {
|
|
425
|
+
if (typeof customElements === "undefined") return;
|
|
417
426
|
if (!customElements.get(KLAPPAY_BUTTON_TAG)) {
|
|
418
427
|
customElements.define(KLAPPAY_BUTTON_TAG, KlappayButtonElement);
|
|
419
428
|
}
|
|
@@ -421,12 +430,14 @@ function registerKlappayButton() {
|
|
|
421
430
|
|
|
422
431
|
// src/index.ts
|
|
423
432
|
registerKlappayButton();
|
|
424
|
-
if (document
|
|
425
|
-
document.
|
|
426
|
-
|
|
427
|
-
|
|
433
|
+
if (typeof document !== "undefined") {
|
|
434
|
+
if (document.readyState === "loading") {
|
|
435
|
+
document.addEventListener("DOMContentLoaded", () => wireExisting());
|
|
436
|
+
} else {
|
|
437
|
+
wireExisting();
|
|
438
|
+
}
|
|
439
|
+
observeNewElements();
|
|
428
440
|
}
|
|
429
|
-
observeNewElements();
|
|
430
441
|
export {
|
|
431
442
|
configure,
|
|
432
443
|
createKlappayOne
|
package/dist/react/index.js
CHANGED
|
@@ -246,7 +246,9 @@ function isVariant(value) {
|
|
|
246
246
|
function isSize(value) {
|
|
247
247
|
return SIZES.includes(value);
|
|
248
248
|
}
|
|
249
|
-
var
|
|
249
|
+
var KlappayButtonBase = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
250
|
+
};
|
|
251
|
+
var KlappayButtonElement = class _KlappayButtonElement extends KlappayButtonBase {
|
|
250
252
|
static get observedAttributes() {
|
|
251
253
|
return ["variant", "size"];
|
|
252
254
|
}
|
|
@@ -272,10 +274,16 @@ var KlappayButtonElement = class _KlappayButtonElement extends HTMLElement {
|
|
|
272
274
|
const value = this.getAttribute("variant") ?? "";
|
|
273
275
|
return isVariant(value) ? value : DEFAULT_VARIANT;
|
|
274
276
|
}
|
|
277
|
+
set variant(value) {
|
|
278
|
+
this.setAttribute("variant", value);
|
|
279
|
+
}
|
|
275
280
|
get size() {
|
|
276
281
|
const value = this.getAttribute("size") ?? "";
|
|
277
282
|
return isSize(value) ? value : DEFAULT_SIZE;
|
|
278
283
|
}
|
|
284
|
+
set size(value) {
|
|
285
|
+
this.setAttribute("size", value);
|
|
286
|
+
}
|
|
279
287
|
#applyVariant() {
|
|
280
288
|
this.#button.setAttribute("data-variant", this.variant);
|
|
281
289
|
}
|
|
@@ -350,6 +358,7 @@ var KlappayButtonElement = class _KlappayButtonElement extends HTMLElement {
|
|
|
350
358
|
}
|
|
351
359
|
};
|
|
352
360
|
function registerKlappayButton() {
|
|
361
|
+
if (typeof customElements === "undefined") return;
|
|
353
362
|
if (!customElements.get(KLAPPAY_BUTTON_TAG)) {
|
|
354
363
|
customElements.define(KLAPPAY_BUTTON_TAG, KlappayButtonElement);
|
|
355
364
|
}
|
package/logo.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klappay/one",
|
|
3
|
-
"version": "1.0.
|
|
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
|
-
"keywords": [
|
|
6
|
+
"keywords": [
|
|
7
|
+
"klap",
|
|
8
|
+
"klappay",
|
|
9
|
+
"payments",
|
|
10
|
+
"crypto",
|
|
11
|
+
"web3",
|
|
12
|
+
"widget"
|
|
13
|
+
],
|
|
7
14
|
"repository": {
|
|
8
15
|
"type": "git",
|
|
9
16
|
"url": "git+https://github.com/klappay/klap-one-js.git"
|
|
@@ -11,9 +18,12 @@
|
|
|
11
18
|
"engines": {
|
|
12
19
|
"node": ">=24"
|
|
13
20
|
},
|
|
14
|
-
"packageManager": "pnpm@10.33.0",
|
|
15
21
|
"type": "module",
|
|
16
|
-
"sideEffects": [
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./dist/index.js",
|
|
24
|
+
"./dist/index.global.js",
|
|
25
|
+
"./dist/react/index.js"
|
|
26
|
+
],
|
|
17
27
|
"main": "./dist/index.js",
|
|
18
28
|
"types": "./dist/index.d.ts",
|
|
19
29
|
"exports": {
|
|
@@ -26,23 +36,15 @@
|
|
|
26
36
|
"import": "./dist/react/index.js"
|
|
27
37
|
}
|
|
28
38
|
},
|
|
29
|
-
"files": [
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"README.md",
|
|
43
|
+
"logo.png"
|
|
44
|
+
],
|
|
30
45
|
"publishConfig": {
|
|
31
46
|
"access": "public"
|
|
32
47
|
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"build": "rm -rf dist && tsup",
|
|
35
|
-
"dev": "tsup --watch",
|
|
36
|
-
"typecheck": "tsc --noEmit",
|
|
37
|
-
"lint": "biome check .",
|
|
38
|
-
"lint:fix": "biome check --write .",
|
|
39
|
-
"format": "biome format --write .",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"changeset": "changeset",
|
|
42
|
-
"version": "changeset version",
|
|
43
|
-
"release": "pnpm build && changeset publish",
|
|
44
|
-
"prepare": "husky"
|
|
45
|
-
},
|
|
46
48
|
"peerDependencies": {
|
|
47
49
|
"react": ">=18"
|
|
48
50
|
},
|
|
@@ -64,9 +66,23 @@
|
|
|
64
66
|
"react": "^18.3.0",
|
|
65
67
|
"tsup": "^8.3.0",
|
|
66
68
|
"typescript": "^5.6.0",
|
|
69
|
+
"vitepress": "^1.6.4",
|
|
70
|
+
"vitepress-plugin-llms": "^1.13.4",
|
|
67
71
|
"vitest": "^3.2.6"
|
|
68
72
|
},
|
|
69
|
-
"
|
|
70
|
-
"
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "rm -rf dist && tsup",
|
|
75
|
+
"dev": "tsup --watch",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
77
|
+
"lint": "biome check .",
|
|
78
|
+
"lint:fix": "biome check --write .",
|
|
79
|
+
"format": "biome format --write .",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"docs:dev": "vitepress dev docs",
|
|
82
|
+
"docs:build": "vitepress build docs",
|
|
83
|
+
"docs:preview": "vitepress preview docs",
|
|
84
|
+
"changeset": "changeset",
|
|
85
|
+
"version": "changeset version",
|
|
86
|
+
"release": "pnpm build && changeset publish"
|
|
71
87
|
}
|
|
72
|
-
}
|
|
88
|
+
}
|