@cartridge/controller 0.6.0 → 0.7.1
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/.turbo/turbo-build$colon$deps.log +52 -76
- package/.turbo/turbo-build.log +53 -77
- package/dist/controller.cjs +860 -0
- package/dist/controller.cjs.map +1 -0
- package/dist/controller.d.cts +33 -0
- package/dist/controller.d.ts +4 -4
- package/dist/controller.js +84 -68
- package/dist/controller.js.map +1 -1
- package/dist/index.cjs +2200 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.js +161 -7601
- package/dist/index.js.map +1 -1
- package/dist/lookup.cjs +59 -0
- package/dist/lookup.cjs.map +1 -0
- package/dist/lookup.d.cts +4 -0
- package/dist/lookup.js +7 -7
- package/dist/lookup.js.map +1 -1
- package/dist/{provider.js → node/index.cjs} +499 -25
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +56 -0
- package/dist/node/index.d.ts +56 -0
- package/dist/{telegram/provider.js → node/index.js} +354 -135
- package/dist/node/index.js.map +1 -0
- package/dist/{policies.d.ts → policies-DD1aPjQ4.d.cts} +6 -4
- package/dist/policies-DD1aPjQ4.d.ts +21 -0
- package/dist/{types-CVnDQVqD.d.ts → provider-ap1C1ypF.d.cts} +27 -10
- package/dist/provider-ap1C1ypF.d.ts +201 -0
- package/dist/session/{provider.js → index.cjs} +82 -73
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/{provider.d.ts → index.d.cts} +6 -3
- package/dist/session/index.d.ts +37 -8
- package/dist/session/index.js +47 -64
- package/dist/session/index.js.map +1 -1
- package/package.json +35 -16
- package/src/controller.ts +43 -15
- package/src/iframe/base.ts +1 -11
- package/src/node/account.ts +72 -0
- package/src/node/backend.ts +159 -0
- package/src/node/index.ts +4 -0
- package/src/node/provider.ts +178 -0
- package/src/node/server.ts +89 -0
- package/src/session/account.ts +1 -1
- package/src/session/provider.ts +0 -16
- package/src/types.ts +3 -6
- package/tsconfig.json +2 -1
- package/dist/__tests__/parseChainId.test.d.ts +0 -2
- package/dist/__tests__/parseChainId.test.js +0 -89
- package/dist/__tests__/parseChainId.test.js.map +0 -1
- package/dist/account.d.ts +0 -38
- package/dist/account.js +0 -110
- package/dist/account.js.map +0 -1
- package/dist/constants.d.ts +0 -5
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +0 -1
- package/dist/errors.d.ts +0 -5
- package/dist/errors.js +0 -11
- package/dist/errors.js.map +0 -1
- package/dist/icon.d.ts +0 -3
- package/dist/icon.js +0 -6
- package/dist/icon.js.map +0 -1
- package/dist/iframe/base.d.ts +0 -5
- package/dist/iframe/base.js +0 -126
- package/dist/iframe/base.js.map +0 -1
- package/dist/iframe/index.d.ts +0 -5
- package/dist/iframe/index.js +0 -188
- package/dist/iframe/index.js.map +0 -1
- package/dist/iframe/keychain.d.ts +0 -5
- package/dist/iframe/keychain.js +0 -147
- package/dist/iframe/keychain.js.map +0 -1
- package/dist/iframe/profile.d.ts +0 -5
- package/dist/iframe/profile.js +0 -167
- package/dist/iframe/profile.js.map +0 -1
- package/dist/index.d-BbTUPBeO.d.ts +0 -68
- package/dist/mutex.d.ts +0 -14
- package/dist/mutex.js +0 -22
- package/dist/mutex.js.map +0 -1
- package/dist/policies.js +0 -26
- package/dist/policies.js.map +0 -1
- package/dist/provider.d.ts +0 -24
- package/dist/provider.js.map +0 -1
- package/dist/session/account.d.ts +0 -37
- package/dist/session/account.js +0 -94
- package/dist/session/account.js.map +0 -1
- package/dist/session/backend.d.ts +0 -60
- package/dist/session/backend.js +0 -39
- package/dist/session/backend.js.map +0 -1
- package/dist/session/provider.js.map +0 -1
- package/dist/telegram/backend.d.ts +0 -33
- package/dist/telegram/backend.js +0 -40
- package/dist/telegram/backend.js.map +0 -1
- package/dist/telegram/provider.d.ts +0 -27
- package/dist/telegram/provider.js.map +0 -1
- package/dist/types.d.ts +0 -5
- package/dist/types.js +0 -13
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -19
- package/dist/utils.js +0 -141
- package/dist/utils.js.map +0 -1
package/dist/iframe/base.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// src/iframe/base.ts
|
|
2
|
-
import { connectToChild } from "@cartridge/penpal";
|
|
3
|
-
var IFrame = class {
|
|
4
|
-
url;
|
|
5
|
-
iframe;
|
|
6
|
-
container;
|
|
7
|
-
onClose;
|
|
8
|
-
constructor({
|
|
9
|
-
id,
|
|
10
|
-
url,
|
|
11
|
-
preset,
|
|
12
|
-
theme,
|
|
13
|
-
colorMode,
|
|
14
|
-
onClose,
|
|
15
|
-
onConnect,
|
|
16
|
-
methods = {}
|
|
17
|
-
}) {
|
|
18
|
-
if (typeof document === "undefined") {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (theme) {
|
|
22
|
-
url.searchParams.set("theme", theme);
|
|
23
|
-
}
|
|
24
|
-
if (preset) {
|
|
25
|
-
url.searchParams.set("preset", preset);
|
|
26
|
-
}
|
|
27
|
-
if (colorMode) {
|
|
28
|
-
url.searchParams.set("colorMode", colorMode);
|
|
29
|
-
}
|
|
30
|
-
this.url = url;
|
|
31
|
-
const iframe = document.createElement("iframe");
|
|
32
|
-
iframe.src = url.toString();
|
|
33
|
-
iframe.id = id;
|
|
34
|
-
iframe.style.border = "none";
|
|
35
|
-
iframe.sandbox.add("allow-forms");
|
|
36
|
-
iframe.sandbox.add("allow-popups");
|
|
37
|
-
iframe.sandbox.add("allow-scripts");
|
|
38
|
-
iframe.sandbox.add("allow-same-origin");
|
|
39
|
-
iframe.allow = "publickey-credentials-create *; publickey-credentials-get *; clipboard-write";
|
|
40
|
-
if (!!document.hasStorageAccess) {
|
|
41
|
-
iframe.sandbox.add("allow-storage-access-by-user-activation");
|
|
42
|
-
}
|
|
43
|
-
const container = document.createElement("div");
|
|
44
|
-
container.id = "controller";
|
|
45
|
-
container.style.position = "fixed";
|
|
46
|
-
container.style.height = "100%";
|
|
47
|
-
container.style.width = "100%";
|
|
48
|
-
container.style.top = "0";
|
|
49
|
-
container.style.left = "0";
|
|
50
|
-
container.style.zIndex = "10000";
|
|
51
|
-
container.style.backgroundColor = "rgba(0,0,0,0.6)";
|
|
52
|
-
container.style.display = "flex";
|
|
53
|
-
container.style.alignItems = "center";
|
|
54
|
-
container.style.justifyContent = "center";
|
|
55
|
-
container.style.visibility = "hidden";
|
|
56
|
-
container.style.opacity = "0";
|
|
57
|
-
container.style.transition = "opacity 0.2s ease";
|
|
58
|
-
container.appendChild(iframe);
|
|
59
|
-
this.iframe = iframe;
|
|
60
|
-
this.container = container;
|
|
61
|
-
connectToChild({
|
|
62
|
-
iframe: this.iframe,
|
|
63
|
-
methods: { close: () => this.close(), ...methods }
|
|
64
|
-
}).promise.then(onConnect);
|
|
65
|
-
this.resize();
|
|
66
|
-
window.addEventListener("resize", () => this.resize());
|
|
67
|
-
const observer = new MutationObserver(() => {
|
|
68
|
-
const existingController2 = document.getElementById("controller");
|
|
69
|
-
if (document.body) {
|
|
70
|
-
if (id === "controller-keychain" && !existingController2 || id === "controller-profile") {
|
|
71
|
-
document.body.appendChild(container);
|
|
72
|
-
observer.disconnect();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
observer.observe(document.documentElement, {
|
|
77
|
-
childList: true,
|
|
78
|
-
subtree: true
|
|
79
|
-
});
|
|
80
|
-
const existingController = document.getElementById("controller");
|
|
81
|
-
if (document.body) {
|
|
82
|
-
if (id === "controller-keychain" && !existingController || id === "controller-profile") {
|
|
83
|
-
document.body.appendChild(container);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
this.onClose = onClose;
|
|
87
|
-
}
|
|
88
|
-
open() {
|
|
89
|
-
if (!this.container) return;
|
|
90
|
-
document.body.style.overflow = "hidden";
|
|
91
|
-
this.container.style.visibility = "visible";
|
|
92
|
-
this.container.style.opacity = "1";
|
|
93
|
-
}
|
|
94
|
-
close() {
|
|
95
|
-
if (!this.container) return;
|
|
96
|
-
this.onClose?.();
|
|
97
|
-
document.body.style.overflow = "auto";
|
|
98
|
-
this.container.style.visibility = "hidden";
|
|
99
|
-
this.container.style.opacity = "0";
|
|
100
|
-
}
|
|
101
|
-
sendBackward() {
|
|
102
|
-
if (!this.container) return;
|
|
103
|
-
this.container.style.zIndex = "9999";
|
|
104
|
-
}
|
|
105
|
-
sendForward() {
|
|
106
|
-
if (!this.container) return;
|
|
107
|
-
this.container.style.zIndex = "10000";
|
|
108
|
-
}
|
|
109
|
-
resize() {
|
|
110
|
-
if (!this.iframe) return;
|
|
111
|
-
this.iframe.style.userSelect = "none";
|
|
112
|
-
if (window.innerWidth < 768) {
|
|
113
|
-
this.iframe.style.height = "100%";
|
|
114
|
-
this.iframe.style.width = "100%";
|
|
115
|
-
this.iframe.style.borderRadius = "0";
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
this.iframe.style.height = "600px";
|
|
119
|
-
this.iframe.style.width = "432px";
|
|
120
|
-
this.iframe.style.borderRadius = "8px";
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
export {
|
|
124
|
-
IFrame
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=base.js.map
|
package/dist/iframe/base.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/iframe/base.ts"],"sourcesContent":["import { AsyncMethodReturns, connectToChild } from \"@cartridge/penpal\";\nimport { ControllerOptions, Modal } from \"../types\";\n\nexport type IFrameOptions<CallSender> = Omit<\n ConstructorParameters<typeof IFrame>[0],\n \"id\" | \"url\" | \"onConnect\"\n> & {\n url?: string;\n onConnect: (child: AsyncMethodReturns<CallSender>) => void;\n};\n\nexport class IFrame<CallSender extends {}> implements Modal {\n url?: URL;\n private iframe?: HTMLIFrameElement;\n private container?: HTMLDivElement;\n private onClose?: () => void;\n\n constructor({\n id,\n url,\n preset,\n theme,\n colorMode,\n onClose,\n onConnect,\n methods = {},\n }: Pick<ControllerOptions, \"theme\" | \"preset\" | \"colorMode\"> & {\n id: string;\n url: URL;\n onClose?: () => void;\n onConnect: (child: AsyncMethodReturns<CallSender>) => void;\n methods?: { [key: string]: (...args: any[]) => void };\n }) {\n if (typeof document === \"undefined\") {\n return;\n }\n\n if (theme) {\n url.searchParams.set(\"theme\", theme);\n }\n\n if (preset) {\n url.searchParams.set(\"preset\", preset);\n }\n\n if (colorMode) {\n url.searchParams.set(\"colorMode\", colorMode);\n }\n\n this.url = url;\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = url.toString();\n iframe.id = id;\n iframe.style.border = \"none\";\n iframe.sandbox.add(\"allow-forms\");\n iframe.sandbox.add(\"allow-popups\");\n iframe.sandbox.add(\"allow-scripts\");\n iframe.sandbox.add(\"allow-same-origin\");\n iframe.allow =\n \"publickey-credentials-create *; publickey-credentials-get *; clipboard-write\";\n if (!!document.hasStorageAccess) {\n iframe.sandbox.add(\"allow-storage-access-by-user-activation\");\n }\n\n const container = document.createElement(\"div\");\n container.id = \"controller\";\n container.style.position = \"fixed\";\n container.style.height = \"100%\";\n container.style.width = \"100%\";\n container.style.top = \"0\";\n container.style.left = \"0\";\n container.style.zIndex = \"10000\";\n container.style.backgroundColor = \"rgba(0,0,0,0.6)\";\n container.style.display = \"flex\";\n container.style.alignItems = \"center\";\n container.style.justifyContent = \"center\";\n container.style.visibility = \"hidden\";\n container.style.opacity = \"0\";\n container.style.transition = \"opacity 0.2s ease\";\n container.appendChild(iframe);\n\n this.iframe = iframe;\n this.container = container;\n\n connectToChild<CallSender>({\n iframe: this.iframe,\n methods: { close: () => this.close(), ...methods },\n }).promise.then(onConnect);\n\n this.resize();\n window.addEventListener(\"resize\", () => this.resize());\n\n const observer = new MutationObserver(() => {\n const existingController = document.getElementById(\"controller\");\n if (document.body) {\n if (\n (id === \"controller-keychain\" && !existingController) ||\n id === \"controller-profile\"\n ) {\n document.body.appendChild(container);\n observer.disconnect();\n }\n }\n });\n\n observer.observe(document.documentElement, {\n childList: true,\n subtree: true,\n });\n\n const existingController = document.getElementById(\"controller\");\n if (document.body) {\n if (\n (id === \"controller-keychain\" && !existingController) ||\n id === \"controller-profile\"\n ) {\n document.body.appendChild(container);\n }\n }\n\n this.onClose = onClose;\n }\n\n open() {\n if (!this.container) return;\n document.body.style.overflow = \"hidden\";\n\n this.container.style.visibility = \"visible\";\n this.container.style.opacity = \"1\";\n }\n\n close() {\n if (!this.container) return;\n this.onClose?.();\n\n document.body.style.overflow = \"auto\";\n\n this.container.style.visibility = \"hidden\";\n this.container.style.opacity = \"0\";\n }\n\n sendBackward() {\n if (!this.container) return;\n this.container.style.zIndex = \"9999\";\n }\n\n sendForward() {\n if (!this.container) return;\n this.container.style.zIndex = \"10000\";\n }\n\n private resize() {\n if (!this.iframe) return;\n\n this.iframe.style.userSelect = \"none\";\n\n if (window.innerWidth < 768) {\n this.iframe.style.height = \"100%\";\n this.iframe.style.width = \"100%\";\n this.iframe.style.borderRadius = \"0\";\n return;\n }\n\n this.iframe.style.height = \"600px\";\n this.iframe.style.width = \"432px\";\n this.iframe.style.borderRadius = \"8px\";\n }\n}\n"],"mappings":";AAAA,SAA6B,sBAAsB;AAW5C,IAAM,SAAN,MAAqD;AAAA,EAC1D;AAAA,EACQ;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,EACb,GAMG;AACD,QAAI,OAAO,aAAa,aAAa;AACnC;AAAA,IACF;AAEA,QAAI,OAAO;AACT,UAAI,aAAa,IAAI,SAAS,KAAK;AAAA,IACrC;AAEA,QAAI,QAAQ;AACV,UAAI,aAAa,IAAI,UAAU,MAAM;AAAA,IACvC;AAEA,QAAI,WAAW;AACb,UAAI,aAAa,IAAI,aAAa,SAAS;AAAA,IAC7C;AAEA,SAAK,MAAM;AAEX,UAAM,SAAS,SAAS,cAAc,Q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,SAAS,iBAAiB;AAAA,MACzC,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAED,UAAM,qBAAqB,SAAS,eAAe,YAAY;AAC/D,QAAI,SAAS,MAAM;AACjB,UACG,OAAO,yBAAyB,CAAC,sBAClC,OAAO,sBACP;AACA,iBAAS,KAAK,YAAY,SAAS;AAAA,MACrC;AAAA,IACF;AAEA,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,OAAO;AACL,QAAI,CAAC,KAAK,UAAW;AACrB,aAAS,KAAK,MAAM,WAAW;AAE/B,SAAK,UAAU,MAAM,aAAa;AAClC,SAAK,UAAU,MAAM,UAAU;AAAA,EACjC;AAAA,EAEA,QAAQ;AACN,QAAI,CAAC,KAAK,UAAW;AACrB,SAAK,UAAU;AAEf,aAAS,KAAK,MAAM,WAAW;AAE/B,SAAK,UAAU,MAAM,aAAa;AAClC,SAAK,UAAU,MAAM,UAAU;AAAA,EACjC;AAAA,EAEA,eAAe;AACb,QAAI,CAAC,KAAK,UAAW;AACrB,SAAK,UAAU,MAAM,SAAS;AAAA,EAChC;AAAA,EAEA,cAAc;AACZ,QAAI,CAAC,KAAK,UAAW;AACrB,SAAK,UAAU,MAAM,SAAS;AAAA,EAChC;AAAA,EAEQ,SAAS;AACf,QAAI,CAAC,KAAK,OAAQ;AAElB,SAAK,OAAO,MAAM,aAAa;AAE/B,QAAI,OAAO,aAAa,KAAK;AAC3B,WAAK,OAAO,MAAM,SAAS;AAC3B,WAAK,OAAO,MAAM,QAAQ;AAC1B,WAAK,OAAO,MAAM,eAAe;AACjC;AAAA,IACF;AAEA,SAAK,OAAO,MAAM,SAAS;AAC3B,SAAK,OAAO,MAAM,QAAQ;AAC1B,SAAK,OAAO,MAAM,eAAe;AAAA,EACnC;AACF;","names":["existingController"]}
|
package/dist/iframe/index.d.ts
DELETED
package/dist/iframe/index.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
// src/iframe/base.ts
|
|
2
|
-
import { connectToChild } from "@cartridge/penpal";
|
|
3
|
-
var IFrame = class {
|
|
4
|
-
url;
|
|
5
|
-
iframe;
|
|
6
|
-
container;
|
|
7
|
-
onClose;
|
|
8
|
-
constructor({
|
|
9
|
-
id,
|
|
10
|
-
url,
|
|
11
|
-
preset,
|
|
12
|
-
theme,
|
|
13
|
-
colorMode,
|
|
14
|
-
onClose,
|
|
15
|
-
onConnect,
|
|
16
|
-
methods = {}
|
|
17
|
-
}) {
|
|
18
|
-
if (typeof document === "undefined") {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (theme) {
|
|
22
|
-
url.searchParams.set("theme", theme);
|
|
23
|
-
}
|
|
24
|
-
if (preset) {
|
|
25
|
-
url.searchParams.set("preset", preset);
|
|
26
|
-
}
|
|
27
|
-
if (colorMode) {
|
|
28
|
-
url.searchParams.set("colorMode", colorMode);
|
|
29
|
-
}
|
|
30
|
-
this.url = url;
|
|
31
|
-
const iframe = document.createElement("iframe");
|
|
32
|
-
iframe.src = url.toString();
|
|
33
|
-
iframe.id = id;
|
|
34
|
-
iframe.style.border = "none";
|
|
35
|
-
iframe.sandbox.add("allow-forms");
|
|
36
|
-
iframe.sandbox.add("allow-popups");
|
|
37
|
-
iframe.sandbox.add("allow-scripts");
|
|
38
|
-
iframe.sandbox.add("allow-same-origin");
|
|
39
|
-
iframe.allow = "publickey-credentials-create *; publickey-credentials-get *; clipboard-write";
|
|
40
|
-
if (!!document.hasStorageAccess) {
|
|
41
|
-
iframe.sandbox.add("allow-storage-access-by-user-activation");
|
|
42
|
-
}
|
|
43
|
-
const container = document.createElement("div");
|
|
44
|
-
container.id = "controller";
|
|
45
|
-
container.style.position = "fixed";
|
|
46
|
-
container.style.height = "100%";
|
|
47
|
-
container.style.width = "100%";
|
|
48
|
-
container.style.top = "0";
|
|
49
|
-
container.style.left = "0";
|
|
50
|
-
container.style.zIndex = "10000";
|
|
51
|
-
container.style.backgroundColor = "rgba(0,0,0,0.6)";
|
|
52
|
-
container.style.display = "flex";
|
|
53
|
-
container.style.alignItems = "center";
|
|
54
|
-
container.style.justifyContent = "center";
|
|
55
|
-
container.style.visibility = "hidden";
|
|
56
|
-
container.style.opacity = "0";
|
|
57
|
-
container.style.transition = "opacity 0.2s ease";
|
|
58
|
-
container.appendChild(iframe);
|
|
59
|
-
this.iframe = iframe;
|
|
60
|
-
this.container = container;
|
|
61
|
-
connectToChild({
|
|
62
|
-
iframe: this.iframe,
|
|
63
|
-
methods: { close: () => this.close(), ...methods }
|
|
64
|
-
}).promise.then(onConnect);
|
|
65
|
-
this.resize();
|
|
66
|
-
window.addEventListener("resize", () => this.resize());
|
|
67
|
-
const observer = new MutationObserver(() => {
|
|
68
|
-
const existingController2 = document.getElementById("controller");
|
|
69
|
-
if (document.body) {
|
|
70
|
-
if (id === "controller-keychain" && !existingController2 || id === "controller-profile") {
|
|
71
|
-
document.body.appendChild(container);
|
|
72
|
-
observer.disconnect();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
observer.observe(document.documentElement, {
|
|
77
|
-
childList: true,
|
|
78
|
-
subtree: true
|
|
79
|
-
});
|
|
80
|
-
const existingController = document.getElementById("controller");
|
|
81
|
-
if (document.body) {
|
|
82
|
-
if (id === "controller-keychain" && !existingController || id === "controller-profile") {
|
|
83
|
-
document.body.appendChild(container);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
this.onClose = onClose;
|
|
87
|
-
}
|
|
88
|
-
open() {
|
|
89
|
-
if (!this.container) return;
|
|
90
|
-
document.body.style.overflow = "hidden";
|
|
91
|
-
this.container.style.visibility = "visible";
|
|
92
|
-
this.container.style.opacity = "1";
|
|
93
|
-
}
|
|
94
|
-
close() {
|
|
95
|
-
if (!this.container) return;
|
|
96
|
-
this.onClose?.();
|
|
97
|
-
document.body.style.overflow = "auto";
|
|
98
|
-
this.container.style.visibility = "hidden";
|
|
99
|
-
this.container.style.opacity = "0";
|
|
100
|
-
}
|
|
101
|
-
sendBackward() {
|
|
102
|
-
if (!this.container) return;
|
|
103
|
-
this.container.style.zIndex = "9999";
|
|
104
|
-
}
|
|
105
|
-
sendForward() {
|
|
106
|
-
if (!this.container) return;
|
|
107
|
-
this.container.style.zIndex = "10000";
|
|
108
|
-
}
|
|
109
|
-
resize() {
|
|
110
|
-
if (!this.iframe) return;
|
|
111
|
-
this.iframe.style.userSelect = "none";
|
|
112
|
-
if (window.innerWidth < 768) {
|
|
113
|
-
this.iframe.style.height = "100%";
|
|
114
|
-
this.iframe.style.width = "100%";
|
|
115
|
-
this.iframe.style.borderRadius = "0";
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
this.iframe.style.height = "600px";
|
|
119
|
-
this.iframe.style.width = "432px";
|
|
120
|
-
this.iframe.style.borderRadius = "8px";
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// src/constants.ts
|
|
125
|
-
var KEYCHAIN_URL = "https://x.cartridge.gg";
|
|
126
|
-
var PROFILE_URL = "https://profile.cartridge.gg";
|
|
127
|
-
|
|
128
|
-
// src/iframe/keychain.ts
|
|
129
|
-
var KeychainIFrame = class extends IFrame {
|
|
130
|
-
constructor({ url, policies, ...iframeOptions }) {
|
|
131
|
-
const _url = new URL(url ?? KEYCHAIN_URL);
|
|
132
|
-
if (policies) {
|
|
133
|
-
_url.searchParams.set(
|
|
134
|
-
"policies",
|
|
135
|
-
encodeURIComponent(JSON.stringify(policies))
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
super({
|
|
139
|
-
...iframeOptions,
|
|
140
|
-
id: "controller-keychain",
|
|
141
|
-
url: _url
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/iframe/profile.ts
|
|
147
|
-
var ProfileIFrame = class extends IFrame {
|
|
148
|
-
constructor({
|
|
149
|
-
profileUrl,
|
|
150
|
-
rpcUrl,
|
|
151
|
-
version,
|
|
152
|
-
username,
|
|
153
|
-
slot,
|
|
154
|
-
namespace,
|
|
155
|
-
tokens,
|
|
156
|
-
...iframeOptions
|
|
157
|
-
}) {
|
|
158
|
-
const _profileUrl = (profileUrl || PROFILE_URL).replace(/\/$/, "");
|
|
159
|
-
let _url = new URL(
|
|
160
|
-
slot ? namespace ? `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
|
|
161
|
-
slot
|
|
162
|
-
)}&ns=${encodeURIComponent(namespace)}` : `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
|
|
163
|
-
slot
|
|
164
|
-
)}` : `${_profileUrl}/account/${username}`
|
|
165
|
-
);
|
|
166
|
-
if (version) {
|
|
167
|
-
_url.searchParams.set("v", encodeURIComponent(version));
|
|
168
|
-
}
|
|
169
|
-
_url.searchParams.set("rpcUrl", encodeURIComponent(rpcUrl));
|
|
170
|
-
if (tokens?.erc20) {
|
|
171
|
-
_url.searchParams.set(
|
|
172
|
-
"erc20",
|
|
173
|
-
encodeURIComponent(tokens.erc20.toString())
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
super({
|
|
177
|
-
...iframeOptions,
|
|
178
|
-
id: "controller-profile",
|
|
179
|
-
url: _url
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
export {
|
|
184
|
-
IFrame,
|
|
185
|
-
KeychainIFrame,
|
|
186
|
-
ProfileIFrame
|
|
187
|
-
};
|
|
188
|
-
//# sourceMappingURL=index.js.map
|
package/dist/iframe/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/iframe/base.ts","../../src/constants.ts","../../src/iframe/keychain.ts","../../src/iframe/profile.ts"],"sourcesContent":["import { AsyncMethodReturns, connectToChild } from \"@cartridge/penpal\";\nimport { ControllerOptions, Modal } from \"../types\";\n\nexport type IFrameOptions<CallSender> = Omit<\n ConstructorParameters<typeof IFrame>[0],\n \"id\" | \"url\" | \"onConnect\"\n> & {\n url?: string;\n onConnect: (child: AsyncMethodReturns<CallSender>) => void;\n};\n\nexport class IFrame<CallSender extends {}> implements Modal {\n url?: URL;\n private iframe?: HTMLIFrameElement;\n private container?: HTMLDivElement;\n private onClose?: () => void;\n\n constructor({\n id,\n url,\n preset,\n theme,\n colorMode,\n onClose,\n onConnect,\n methods = {},\n }: Pick<ControllerOptions, \"theme\" | \"preset\" | \"colorMode\"> & {\n id: string;\n url: URL;\n onClose?: () => void;\n onConnect: (child: AsyncMethodReturns<CallSender>) => void;\n methods?: { [key: string]: (...args: any[]) => void };\n }) {\n if (typeof document === \"undefined\") {\n return;\n }\n\n if (theme) {\n url.searchParams.set(\"theme\", theme);\n }\n\n if (preset) {\n url.searchParams.set(\"preset\", preset);\n }\n\n if (colorMode) {\n url.searchParams.set(\"colorMode\", colorMode);\n }\n\n this.url = url;\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = url.toString();\n iframe.id = id;\n iframe.style.border = \"none\";\n iframe.sandbox.add(\"allow-forms\");\n iframe.sandbox.add(\"allow-popups\");\n iframe.sandbox.add(\"allow-scripts\");\n iframe.sandbox.add(\"allow-same-origin\");\n iframe.allow =\n \"publickey-credentials-create *; publickey-credentials-get *; clipboard-write\";\n if (!!document.hasStorageAccess) {\n iframe.sandbox.add(\"allow-storage-access-by-user-activation\");\n }\n\n const container = document.createElement(\"div\");\n container.id = \"controller\";\n container.style.position = \"fixed\";\n container.style.height = \"100%\";\n container.style.width = \"100%\";\n container.style.top = \"0\";\n container.style.left = \"0\";\n container.style.zIndex = \"10000\";\n container.style.backgroundColor = \"rgba(0,0,0,0.6)\";\n container.style.display = \"flex\";\n container.style.alignItems = \"center\";\n container.style.justifyContent = \"center\";\n container.style.visibility = \"hidden\";\n container.style.opacity = \"0\";\n container.style.transition = \"opacity 0.2s ease\";\n container.appendChild(iframe);\n\n this.iframe = iframe;\n this.container = container;\n\n connectToChild<CallSender>({\n iframe: this.iframe,\n methods: { close: () => this.close(), ...methods },\n }).promise.then(onConnect);\n\n this.resize();\n window.addEventListener(\"resize\", () => this.resize());\n\n const observer = new MutationObserver(() => {\n const existingController = document.getElementById(\"controller\");\n if (document.body) {\n if (\n (id === \"controller-keychain\" && !existingController) ||\n id === \"controller-profile\"\n ) {\n document.body.appendChild(container);\n observer.disconnect();\n }\n }\n });\n\n observer.observe(document.documentElement, {\n childList: true,\n subtree: true,\n });\n\n const existingController = document.getElementById(\"controller\");\n if (document.body) {\n if (\n (id === \"controller-keychain\" && !existingController) ||\n id === \"controller-profile\"\n ) {\n document.body.appendChild(container);\n }\n }\n\n this.onClose = onClose;\n }\n\n open() {\n if (!this.container) return;\n document.body.style.overflow = \"hidden\";\n\n this.container.style.visibility = \"visible\";\n this.container.style.opacity = \"1\";\n }\n\n close() {\n if (!this.container) return;\n this.onClose?.();\n\n document.body.style.overflow = \"auto\";\n\n this.container.style.visibility = \"hidden\";\n this.container.style.opacity = \"0\";\n }\n\n sendBackward() {\n if (!this.container) return;\n this.container.style.zIndex = \"9999\";\n }\n\n sendForward() {\n if (!this.container) return;\n this.container.style.zIndex = \"10000\";\n }\n\n private resize() {\n if (!this.iframe) return;\n\n this.iframe.style.userSelect = \"none\";\n\n if (window.innerWidth < 768) {\n this.iframe.style.height = \"100%\";\n this.iframe.style.width = \"100%\";\n this.iframe.style.borderRadius = \"0\";\n return;\n }\n\n this.iframe.style.height = \"600px\";\n this.iframe.style.width = \"432px\";\n this.iframe.style.borderRadius = \"8px\";\n }\n}\n","export const KEYCHAIN_URL = \"https://x.cartridge.gg\";\nexport const PROFILE_URL = \"https://profile.cartridge.gg\";\nexport const API_URL = \"https://api.cartridge.gg\";\n","import { KEYCHAIN_URL } from \"../constants\";\nimport { Keychain, KeychainOptions } from \"../types\";\nimport { IFrame, IFrameOptions } from \"./base\";\n\ntype KeychainIframeOptions = IFrameOptions<Keychain> & KeychainOptions;\n\nexport class KeychainIFrame extends IFrame<Keychain> {\n constructor({ url, policies, ...iframeOptions }: KeychainIframeOptions) {\n const _url = new URL(url ?? KEYCHAIN_URL);\n\n if (policies) {\n _url.searchParams.set(\n \"policies\",\n encodeURIComponent(JSON.stringify(policies)),\n );\n }\n\n super({\n ...iframeOptions,\n id: \"controller-keychain\",\n url: _url,\n });\n }\n}\n","import { PROFILE_URL } from \"../constants\";\nimport { Profile, ProfileOptions } from \"../types\";\nimport { IFrame, IFrameOptions } from \"./base\";\n\nexport type ProfileIFrameOptions = IFrameOptions<Profile> &\n ProfileOptions & {\n rpcUrl: string;\n version?: string;\n username: string;\n slot?: string;\n namespace?: string;\n };\n\nexport class ProfileIFrame extends IFrame<Profile> {\n constructor({\n profileUrl,\n rpcUrl,\n version,\n username,\n slot,\n namespace,\n tokens,\n ...iframeOptions\n }: ProfileIFrameOptions) {\n const _profileUrl = (profileUrl || PROFILE_URL).replace(/\\/$/, \"\");\n let _url = new URL(\n slot\n ? namespace\n ? `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(\n slot,\n )}&ns=${encodeURIComponent(namespace)}`\n : `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(\n slot,\n )}`\n : `${_profileUrl}/account/${username}`,\n );\n\n if (version) {\n _url.searchParams.set(\"v\", encodeURIComponent(version));\n }\n\n _url.searchParams.set(\"rpcUrl\", encodeURIComponent(rpcUrl));\n\n if (tokens?.erc20) {\n _url.searchParams.set(\n \"erc20\",\n encodeURIComponent(tokens.erc20.toString()),\n );\n }\n\n super({\n ...iframeOptions,\n id: \"controller-profile\",\n url: _url,\n });\n }\n}\n"],"mappings":";AAAA,SAA6B,sBAAsB;AAW5C,IAAM,SAAN,MAAqD;AAAA,EAC1D;AAAA,EACQ;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,EACb,GAMG;AACD,QAAI,OAAO,aAAa,aAAa;AACnC;AAAA,IACF;AAEA,QAAI,OAAO;AACT,UAAI,a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AAA,MACH,IAAI;AAAA,MACJ,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACF;","names":["existingController"]}
|
package/dist/iframe/keychain.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// src/constants.ts
|
|
2
|
-
var KEYCHAIN_URL = "https://x.cartridge.gg";
|
|
3
|
-
|
|
4
|
-
// src/iframe/base.ts
|
|
5
|
-
import { connectToChild } from "@cartridge/penpal";
|
|
6
|
-
var IFrame = class {
|
|
7
|
-
url;
|
|
8
|
-
iframe;
|
|
9
|
-
container;
|
|
10
|
-
onClose;
|
|
11
|
-
constructor({
|
|
12
|
-
id,
|
|
13
|
-
url,
|
|
14
|
-
preset,
|
|
15
|
-
theme,
|
|
16
|
-
colorMode,
|
|
17
|
-
onClose,
|
|
18
|
-
onConnect,
|
|
19
|
-
methods = {}
|
|
20
|
-
}) {
|
|
21
|
-
if (typeof document === "undefined") {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (theme) {
|
|
25
|
-
url.searchParams.set("theme", theme);
|
|
26
|
-
}
|
|
27
|
-
if (preset) {
|
|
28
|
-
url.searchParams.set("preset", preset);
|
|
29
|
-
}
|
|
30
|
-
if (colorMode) {
|
|
31
|
-
url.searchParams.set("colorMode", colorMode);
|
|
32
|
-
}
|
|
33
|
-
this.url = url;
|
|
34
|
-
const iframe = document.createElement("iframe");
|
|
35
|
-
iframe.src = url.toString();
|
|
36
|
-
iframe.id = id;
|
|
37
|
-
iframe.style.border = "none";
|
|
38
|
-
iframe.sandbox.add("allow-forms");
|
|
39
|
-
iframe.sandbox.add("allow-popups");
|
|
40
|
-
iframe.sandbox.add("allow-scripts");
|
|
41
|
-
iframe.sandbox.add("allow-same-origin");
|
|
42
|
-
iframe.allow = "publickey-credentials-create *; publickey-credentials-get *; clipboard-write";
|
|
43
|
-
if (!!document.hasStorageAccess) {
|
|
44
|
-
iframe.sandbox.add("allow-storage-access-by-user-activation");
|
|
45
|
-
}
|
|
46
|
-
const container = document.createElement("div");
|
|
47
|
-
container.id = "controller";
|
|
48
|
-
container.style.position = "fixed";
|
|
49
|
-
container.style.height = "100%";
|
|
50
|
-
container.style.width = "100%";
|
|
51
|
-
container.style.top = "0";
|
|
52
|
-
container.style.left = "0";
|
|
53
|
-
container.style.zIndex = "10000";
|
|
54
|
-
container.style.backgroundColor = "rgba(0,0,0,0.6)";
|
|
55
|
-
container.style.display = "flex";
|
|
56
|
-
container.style.alignItems = "center";
|
|
57
|
-
container.style.justifyContent = "center";
|
|
58
|
-
container.style.visibility = "hidden";
|
|
59
|
-
container.style.opacity = "0";
|
|
60
|
-
container.style.transition = "opacity 0.2s ease";
|
|
61
|
-
container.appendChild(iframe);
|
|
62
|
-
this.iframe = iframe;
|
|
63
|
-
this.container = container;
|
|
64
|
-
connectToChild({
|
|
65
|
-
iframe: this.iframe,
|
|
66
|
-
methods: { close: () => this.close(), ...methods }
|
|
67
|
-
}).promise.then(onConnect);
|
|
68
|
-
this.resize();
|
|
69
|
-
window.addEventListener("resize", () => this.resize());
|
|
70
|
-
const observer = new MutationObserver(() => {
|
|
71
|
-
const existingController2 = document.getElementById("controller");
|
|
72
|
-
if (document.body) {
|
|
73
|
-
if (id === "controller-keychain" && !existingController2 || id === "controller-profile") {
|
|
74
|
-
document.body.appendChild(container);
|
|
75
|
-
observer.disconnect();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
observer.observe(document.documentElement, {
|
|
80
|
-
childList: true,
|
|
81
|
-
subtree: true
|
|
82
|
-
});
|
|
83
|
-
const existingController = document.getElementById("controller");
|
|
84
|
-
if (document.body) {
|
|
85
|
-
if (id === "controller-keychain" && !existingController || id === "controller-profile") {
|
|
86
|
-
document.body.appendChild(container);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
this.onClose = onClose;
|
|
90
|
-
}
|
|
91
|
-
open() {
|
|
92
|
-
if (!this.container) return;
|
|
93
|
-
document.body.style.overflow = "hidden";
|
|
94
|
-
this.container.style.visibility = "visible";
|
|
95
|
-
this.container.style.opacity = "1";
|
|
96
|
-
}
|
|
97
|
-
close() {
|
|
98
|
-
if (!this.container) return;
|
|
99
|
-
this.onClose?.();
|
|
100
|
-
document.body.style.overflow = "auto";
|
|
101
|
-
this.container.style.visibility = "hidden";
|
|
102
|
-
this.container.style.opacity = "0";
|
|
103
|
-
}
|
|
104
|
-
sendBackward() {
|
|
105
|
-
if (!this.container) return;
|
|
106
|
-
this.container.style.zIndex = "9999";
|
|
107
|
-
}
|
|
108
|
-
sendForward() {
|
|
109
|
-
if (!this.container) return;
|
|
110
|
-
this.container.style.zIndex = "10000";
|
|
111
|
-
}
|
|
112
|
-
resize() {
|
|
113
|
-
if (!this.iframe) return;
|
|
114
|
-
this.iframe.style.userSelect = "none";
|
|
115
|
-
if (window.innerWidth < 768) {
|
|
116
|
-
this.iframe.style.height = "100%";
|
|
117
|
-
this.iframe.style.width = "100%";
|
|
118
|
-
this.iframe.style.borderRadius = "0";
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
this.iframe.style.height = "600px";
|
|
122
|
-
this.iframe.style.width = "432px";
|
|
123
|
-
this.iframe.style.borderRadius = "8px";
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// src/iframe/keychain.ts
|
|
128
|
-
var KeychainIFrame = class extends IFrame {
|
|
129
|
-
constructor({ url, policies, ...iframeOptions }) {
|
|
130
|
-
const _url = new URL(url ?? KEYCHAIN_URL);
|
|
131
|
-
if (policies) {
|
|
132
|
-
_url.searchParams.set(
|
|
133
|
-
"policies",
|
|
134
|
-
encodeURIComponent(JSON.stringify(policies))
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
super({
|
|
138
|
-
...iframeOptions,
|
|
139
|
-
id: "controller-keychain",
|
|
140
|
-
url: _url
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
export {
|
|
145
|
-
KeychainIFrame
|
|
146
|
-
};
|
|
147
|
-
//# sourceMappingURL=keychain.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants.ts","../../src/iframe/base.ts","../../src/iframe/keychain.ts"],"sourcesContent":["export const KEYCHAIN_URL = \"https://x.cartridge.gg\";\nexport const PROFILE_URL = \"https://profile.cartridge.gg\";\nexport const API_URL = \"https://api.cartridge.gg\";\n","import { AsyncMethodReturns, connectToChild } from \"@cartridge/penpal\";\nimport { ControllerOptions, Modal } from \"../types\";\n\nexport type IFrameOptions<CallSender> = Omit<\n ConstructorParameters<typeof IFrame>[0],\n \"id\" | \"url\" | \"onConnect\"\n> & {\n url?: string;\n onConnect: (child: AsyncMethodReturns<CallSender>) => void;\n};\n\nexport class IFrame<CallSender extends {}> implements Modal {\n url?: URL;\n private iframe?: HTMLIFrameElement;\n private container?: HTMLDivElement;\n private onClose?: () => void;\n\n constructor({\n id,\n url,\n preset,\n theme,\n colorMode,\n onClose,\n onConnect,\n methods = {},\n }: Pick<ControllerOptions, \"theme\" | \"preset\" | \"colorMode\"> & {\n id: string;\n url: URL;\n onClose?: () => void;\n onConnect: (child: AsyncMethodReturns<CallSender>) => void;\n methods?: { [key: string]: (...args: any[]) => void };\n }) {\n if (typeof document === \"undefined\") {\n return;\n }\n\n if (theme) {\n url.searchParams.set(\"theme\", theme);\n }\n\n if (preset) {\n url.searchParams.set(\"preset\", preset);\n }\n\n if (colorMode) {\n url.searchParams.set(\"colorMode\", colorMode);\n }\n\n this.url = url;\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = url.toString();\n iframe.id = id;\n iframe.style.border = \"none\";\n iframe.sandbox.add(\"allow-forms\");\n iframe.sandbox.add(\"allow-popups\");\n iframe.sandbox.add(\"allow-scripts\");\n iframe.sandbox.add(\"allow-same-origin\");\n iframe.allow =\n \"publickey-credentials-create *; publickey-credentials-get *; clipboard-write\";\n if (!!document.hasStorageAccess) {\n iframe.sandbox.add(\"allow-storage-access-by-user-activation\");\n }\n\n const container = document.createElement(\"div\");\n container.id = \"controller\";\n container.style.position = \"fixed\";\n container.style.height = \"100%\";\n container.style.width = \"100%\";\n container.style.top = \"0\";\n container.style.left = \"0\";\n container.style.zIndex = \"10000\";\n container.style.backgroundColor = \"rgba(0,0,0,0.6)\";\n container.style.display = \"flex\";\n container.style.alignItems = \"center\";\n container.style.justifyContent = \"center\";\n container.style.visibility = \"hidden\";\n container.style.opacity = \"0\";\n container.style.transition = \"opacity 0.2s ease\";\n container.appendChild(iframe);\n\n this.iframe = iframe;\n this.container = container;\n\n connectToChild<CallSender>({\n iframe: this.iframe,\n methods: { close: () => this.close(), ...methods },\n }).promise.then(onConnect);\n\n this.resize();\n window.addEventListener(\"resize\", () => this.resize());\n\n const observer = new MutationObserver(() => {\n const existingController = document.getElementById(\"controller\");\n if (document.body) {\n if (\n (id === \"controller-keychain\" && !existingController) ||\n id === \"controller-profile\"\n ) {\n document.body.appendChild(container);\n observer.disconnect();\n }\n }\n });\n\n observer.observe(document.documentElement, {\n childList: true,\n subtree: true,\n });\n\n const existingController = document.getElementById(\"controller\");\n if (document.body) {\n if (\n (id === \"controller-keychain\" && !existingController) ||\n id === \"controller-profile\"\n ) {\n document.body.appendChild(container);\n }\n }\n\n this.onClose = onClose;\n }\n\n open() {\n if (!this.container) return;\n document.body.style.overflow = \"hidden\";\n\n this.container.style.visibility = \"visible\";\n this.container.style.opacity = \"1\";\n }\n\n close() {\n if (!this.container) return;\n this.onClose?.();\n\n document.body.style.overflow = \"auto\";\n\n this.container.style.visibility = \"hidden\";\n this.container.style.opacity = \"0\";\n }\n\n sendBackward() {\n if (!this.container) return;\n this.container.style.zIndex = \"9999\";\n }\n\n sendForward() {\n if (!this.container) return;\n this.container.style.zIndex = \"10000\";\n }\n\n private resize() {\n if (!this.iframe) return;\n\n this.iframe.style.userSelect = \"none\";\n\n if (window.innerWidth < 768) {\n this.iframe.style.height = \"100%\";\n this.iframe.style.width = \"100%\";\n this.iframe.style.borderRadius = \"0\";\n return;\n }\n\n this.iframe.style.height = \"600px\";\n this.iframe.style.width = \"432px\";\n this.iframe.style.borderRadius = \"8px\";\n }\n}\n","import { KEYCHAIN_URL } from \"../constants\";\nimport { Keychain, KeychainOptions } from \"../types\";\nimport { IFrame, IFrameOptions } from \"./base\";\n\ntype KeychainIframeOptions = IFrameOptions<Keychain> & KeychainOptions;\n\nexport class KeychainIFrame extends IFrame<Keychain> {\n constructor({ url, policies, ...iframeOptions }: KeychainIframeOptions) {\n const _url = new URL(url ?? KEYCHAIN_URL);\n\n if (policies) {\n _url.searchParams.set(\n \"policies\",\n encodeURIComponent(JSON.stringify(policies)),\n );\n }\n\n super({\n ...iframeOptions,\n id: \"controller-keychain\",\n url: _url,\n });\n }\n}\n"],"mappings":";AAAO,IAAM,eAAe;;;ACA5B,SAA6B,sBAAsB;AAW5C,IAAM,SAAN,MAAqD;AAAA,EAC1D;AAAA,EACQ;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,EACb,GAMG;AACD,QAAI,OAAO,aAAa,aAAa;AACnC;AAAA,IACF;AAEA,QAAI,OAAO;AACT,UAAI,aAAa,IAAI,SAAS,KAAK;AAAA,IACrC;AAEA,QAAI,QAAQ;AACV,UAAI,aAAa,IAAI,UAAU,MAAM;AAAA,IACvC;AAEA,QAAI,WAAW;AACb,UAAI,aAAa,IAAI,aAAa,SAAS;AAAA,IAC7C;AAEA,SAAK,MAAM;AAEX,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM,IAAI,SAAS;AAC1B,WAAO,KAAK;AACZ,WAAO,MAAM,SAAS;AACtB,WAAO,QAAQ,IAAI,aAAa;AAChC,WAAO,QAAQ,IAAI,cAAc;AACjC,WAAO,QAAQ,IAAI,eAAe;AAClC,WAAO,QAAQ,IAAI,mBAAmB;AACtC,WAAO,QACL;A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