@whop/embedded-components-vanilla-js 0.0.5-beta.3 → 0.0.5-beta.5
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/package.json +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -52
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -28
- package/dist/index.mjs.map +0 -1
- package/dist/lib/index.d.ts +0 -484
- package/dist/pure.d.ts +0 -6
- package/dist/pure.js +0 -29
- package/dist/pure.js.map +0 -1
- package/dist/pure.mjs +0 -6
- package/dist/pure.mjs.map +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -19
- package/dist/types.js.map +0 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/url.d.ts +0 -4
- package/dist/url.js +0 -27
- package/dist/url.js.map +0 -1
- package/dist/url.mjs +0 -3
- package/dist/url.mjs.map +0 -1
- package/dist/util.d.ts +0 -8
- package/dist/util.js +0 -122
- package/dist/util.js.map +0 -1
- package/dist/util.mjs +0 -97
- package/dist/util.mjs.map +0 -1
package/package.json
CHANGED
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var index_exports = {};
|
|
20
|
-
__export(index_exports, {
|
|
21
|
-
loadWhopElements: () => loadWhopElements
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(index_exports);
|
|
24
|
-
var import_util = require("./util");
|
|
25
|
-
let whopElementsPromise;
|
|
26
|
-
let loadCalled = false;
|
|
27
|
-
const getWhopElementsPromise = () => {
|
|
28
|
-
if (whopElementsPromise) {
|
|
29
|
-
return whopElementsPromise;
|
|
30
|
-
}
|
|
31
|
-
whopElementsPromise = (0, import_util.loadScript)().catch((error) => {
|
|
32
|
-
whopElementsPromise = null;
|
|
33
|
-
if (error instanceof Error) {
|
|
34
|
-
return Promise.reject(error);
|
|
35
|
-
} else {
|
|
36
|
-
return Promise.reject(
|
|
37
|
-
new Error("Failed to load WhopElements", { cause: error })
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return whopElementsPromise;
|
|
42
|
-
};
|
|
43
|
-
Promise.resolve().then(() => getWhopElementsPromise()).catch((error) => {
|
|
44
|
-
if (!loadCalled) {
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const loadWhopElements = async (...args) => {
|
|
48
|
-
loadCalled = true;
|
|
49
|
-
const maybeWhopElements = await getWhopElementsPromise();
|
|
50
|
-
return (0, import_util.initWhopElements)(maybeWhopElements, args);
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { WhopElementsConstructor } from \"./types\";\nimport type { LoadWhopElements } from \"./util\";\nimport { initWhopElements, loadScript } from \"./util\";\n\nlet whopElementsPromise: Promise<WhopElementsConstructor | null> | null;\nlet loadCalled = false;\n\nconst getWhopElementsPromise: () => Promise<WhopElementsConstructor | null> =\n\t() => {\n\t\tif (whopElementsPromise) {\n\t\t\treturn whopElementsPromise;\n\t\t}\n\n\t\twhopElementsPromise = loadScript().catch((error) => {\n\t\t\t// clear cache on error\n\t\t\twhopElementsPromise = null;\n\t\t\tif (error instanceof Error) {\n\t\t\t\treturn Promise.reject(error);\n\t\t\t} else {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error(\"Failed to load WhopElements\", { cause: error }),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t\treturn whopElementsPromise;\n\t};\n\n// eagerly load the script\nPromise.resolve()\n\t.then(() => getWhopElementsPromise())\n\t.catch((error) => {\n\t\tif (!loadCalled) {\n\t\t\tconsole.warn(error);\n\t\t}\n\t});\n\nexport const loadWhopElements: LoadWhopElements = async (...args) => {\n\tloadCalled = true;\n\n\tconst maybeWhopElements = await getWhopElementsPromise();\n\treturn initWhopElements(maybeWhopElements, args);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAA6C;AAE7C,IAAI;AACJ,IAAI,aAAa;AAEjB,MAAM,yBACL,MAAM;AACL,MAAI,qBAAqB;AACxB,WAAO;AAAA,EACR;AAEA,4BAAsB,wBAAW,EAAE,MAAM,CAAC,UAAU;AAEnD,0BAAsB;AACtB,QAAI,iBAAiB,OAAO;AAC3B,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC5B,OAAO;AACN,aAAO,QAAQ;AAAA,QACd,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACD,SAAO;AACR;AAGD,QAAQ,QAAQ,EACd,KAAK,MAAM,uBAAuB,CAAC,EACnC,MAAM,CAAC,UAAU;AACjB,MAAI,CAAC,YAAY;AAAA,EAEjB;AACD,CAAC;AAEK,MAAM,mBAAqC,UAAU,SAAS;AACpE,eAAa;AAEb,QAAM,oBAAoB,MAAM,uBAAuB;AACvD,aAAO,8BAAiB,mBAAmB,IAAI;AAChD;","names":[]}
|
package/dist/index.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { initWhopElements, loadScript } from "./util.mjs";
|
|
2
|
-
let whopElementsPromise;
|
|
3
|
-
let loadCalled = false;
|
|
4
|
-
const getWhopElementsPromise = ()=>{
|
|
5
|
-
if (whopElementsPromise) {
|
|
6
|
-
return whopElementsPromise;
|
|
7
|
-
}
|
|
8
|
-
whopElementsPromise = loadScript().catch((error)=>{
|
|
9
|
-
whopElementsPromise = null;
|
|
10
|
-
if (error instanceof Error) {
|
|
11
|
-
return Promise.reject(error);
|
|
12
|
-
} else {
|
|
13
|
-
return Promise.reject(new Error("Failed to load WhopElements", {
|
|
14
|
-
cause: error
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return whopElementsPromise;
|
|
19
|
-
};
|
|
20
|
-
Promise.resolve().then(()=>getWhopElementsPromise()).catch((error)=>{
|
|
21
|
-
if (!loadCalled) {}
|
|
22
|
-
});
|
|
23
|
-
const loadWhopElements = async (...args)=>{
|
|
24
|
-
loadCalled = true;
|
|
25
|
-
const maybeWhopElements = await getWhopElementsPromise();
|
|
26
|
-
return initWhopElements(maybeWhopElements, args);
|
|
27
|
-
};
|
|
28
|
-
export { loadWhopElements };
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { WhopElementsConstructor } from \"./types\";\nimport type { LoadWhopElements } from \"./util\";\nimport { initWhopElements, loadScript } from \"./util\";\n\nlet whopElementsPromise: Promise<WhopElementsConstructor | null> | null;\nlet loadCalled = false;\n\nconst getWhopElementsPromise: () => Promise<WhopElementsConstructor | null> =\n\t() => {\n\t\tif (whopElementsPromise) {\n\t\t\treturn whopElementsPromise;\n\t\t}\n\n\t\twhopElementsPromise = loadScript().catch((error) => {\n\t\t\t// clear cache on error\n\t\t\twhopElementsPromise = null;\n\t\t\tif (error instanceof Error) {\n\t\t\t\treturn Promise.reject(error);\n\t\t\t} else {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error(\"Failed to load WhopElements\", { cause: error }),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t\treturn whopElementsPromise;\n\t};\n\n// eagerly load the script\nPromise.resolve()\n\t.then(() => getWhopElementsPromise())\n\t.catch((error) => {\n\t\tif (!loadCalled) {\n\t\t\tconsole.warn(error);\n\t\t}\n\t});\n\nexport const loadWhopElements: LoadWhopElements = async (...args) => {\n\tloadCalled = true;\n\n\tconst maybeWhopElements = await getWhopElementsPromise();\n\treturn initWhopElements(maybeWhopElements, args);\n};\n"],"mappings":"AAEA,SAAS,kBAAkB,kBAAkB;AAE7C,IAAI;AACJ,IAAI,aAAa;AAEjB,MAAM,yBACL,MAAM;AACL,MAAI,qBAAqB;AACxB,WAAO;AAAA,EACR;AAEA,wBAAsB,WAAW,EAAE,MAAM,CAAC,UAAU;AAEnD,0BAAsB;AACtB,QAAI,iBAAiB,OAAO;AAC3B,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC5B,OAAO;AACN,aAAO,QAAQ;AAAA,QACd,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACD,SAAO;AACR;AAGD,QAAQ,QAAQ,EACd,KAAK,MAAM,uBAAuB,CAAC,EACnC,MAAM,CAAC,UAAU;AACjB,MAAI,CAAC,YAAY;AAAA,EAEjB;AACD,CAAC;AAEK,MAAM,mBAAqC,UAAU,SAAS;AACpE,eAAa;AAEb,QAAM,oBAAoB,MAAM,uBAAuB;AACvD,SAAO,iBAAiB,mBAAmB,IAAI;AAChD;","names":[]}
|
package/dist/lib/index.d.ts
DELETED
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
declare const locales: readonly ["en"];
|
|
2
|
-
type I18nSupportedLocale = (typeof locales)[number];
|
|
3
|
-
|
|
4
|
-
type CSSValue = string;
|
|
5
|
-
type CSSProps = Record<string, CSSValue>;
|
|
6
|
-
type Classes = Record<string, CSSProps>;
|
|
7
|
-
type Variables = Record<`--${string}`, string>;
|
|
8
|
-
type AccentColor = "ruby" | "blue" | "red" | "yellow" | "green" | "gray" | "tomato" | "crimson" | "pink" | "plum" | "purple" | "violet" | "iris" | "cyan" | "teal" | "jade" | "grass" | "brown" | "orange" | "indigo" | "sky" | "mint" | "amber" | "lime" | "lemon" | "magenta" | "gold" | "bronze";
|
|
9
|
-
type Theme = {
|
|
10
|
-
appearance?: "light" | "dark";
|
|
11
|
-
accentColor?: AccentColor;
|
|
12
|
-
grayColor?: "gray" | "mauve" | "slate" | "sage" | "olive" | "sand" | "auto";
|
|
13
|
-
dangerColor?: "ruby" | "red" | "tomato";
|
|
14
|
-
warningColor?: "yellow" | "amber";
|
|
15
|
-
successColor?: "green" | "teal" | "jade" | "grass";
|
|
16
|
-
infoColor?: "sky" | "blue";
|
|
17
|
-
};
|
|
18
|
-
type Appearance = {
|
|
19
|
-
variables?: Variables | null;
|
|
20
|
-
classes?: Classes | null;
|
|
21
|
-
theme?: Theme | null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
interface EmbeddableElement {
|
|
25
|
-
mount: (element: HTMLElement | `#${string}`) => void;
|
|
26
|
-
unmount: () => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type ListenerSignature<L> = {
|
|
30
|
-
[E in keyof L]: (...args: any[]) => any;
|
|
31
|
-
};
|
|
32
|
-
type DefaultListener = Record<string, (...args: any[]) => any>;
|
|
33
|
-
declare const TypedEmitter: new <L extends ListenerSignature<L> = DefaultListener>() => TypedEmitterType<L>;
|
|
34
|
-
type TypedEmitter<L extends ListenerSignature<L> = DefaultListener> = InstanceType<typeof TypedEmitter<L>>;
|
|
35
|
-
declare class TypedEmitterType<L extends ListenerSignature<L> = DefaultListener> {
|
|
36
|
-
static defaultMaxListeners: number;
|
|
37
|
-
addListener<U extends keyof L>(event: U, listener: L[U]): this;
|
|
38
|
-
prependListener<U extends keyof L>(event: U, listener: L[U]): this;
|
|
39
|
-
prependOnceListener<U extends keyof L>(event: U, listener: L[U]): this;
|
|
40
|
-
removeListener<U extends keyof L>(event: U, listener: L[U]): this;
|
|
41
|
-
removeAllListeners(event?: keyof L): this;
|
|
42
|
-
once<U extends keyof L>(event: U, listener: L[U]): this;
|
|
43
|
-
on<U extends keyof L>(event: U, listener: L[U]): this;
|
|
44
|
-
off<U extends keyof L>(event: U, listener: L[U]): this;
|
|
45
|
-
emit<U extends keyof L>(event: U, ...args: Parameters<L[U]>): boolean;
|
|
46
|
-
eventNames<U extends keyof L>(): U[];
|
|
47
|
-
listenerCount(type: keyof L): number;
|
|
48
|
-
listeners<U extends keyof L>(type: U): L[U][];
|
|
49
|
-
rawListeners<U extends keyof L>(type: U): L[U][];
|
|
50
|
-
getMaxListeners(): number;
|
|
51
|
-
setMaxListeners(n: number): this;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface WhopElement<ElementOptions, ElementEvents extends ListenerSignature<ElementEvents> & {
|
|
55
|
-
snapshot: (snapshot: ElementSnapshot) => void;
|
|
56
|
-
}, ElementSnapshot> extends TypedEmitter<ElementEvents>, EmbeddableElement {
|
|
57
|
-
options: ElementOptions;
|
|
58
|
-
state: "loading" | "ready";
|
|
59
|
-
updateOptions: (options: Partial<ElementOptions>) => void;
|
|
60
|
-
getSnapshot: () => ElementSnapshot;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface BalanceElementEvents {
|
|
64
|
-
error: (error: unknown) => void;
|
|
65
|
-
ready: (element: BalanceElement) => void;
|
|
66
|
-
optionsUpdated: (options: BalanceElementOptions) => void;
|
|
67
|
-
snapshot: (snapshot: BalanceElementSnapshot) => void;
|
|
68
|
-
showTotalBalanceBreakdown: (ev: CustomEvent<BalanceElement>) => void;
|
|
69
|
-
showPendingBalanceBreakdown: (ev: CustomEvent<BalanceElement>) => void;
|
|
70
|
-
showRegularReserveBalanceBreakdown: (ev: CustomEvent<BalanceElement>) => void;
|
|
71
|
-
showBnplReserveBalanceBreakdown: (ev: CustomEvent<BalanceElement>) => void;
|
|
72
|
-
}
|
|
73
|
-
interface BalanceElementOptions {
|
|
74
|
-
hidePendingBalance?: boolean;
|
|
75
|
-
onReady?: (element: BalanceElement) => void;
|
|
76
|
-
onShowTotalBalanceBreakdown?: (ev: CustomEvent<BalanceElement>) => void;
|
|
77
|
-
onShowPendingBalanceBreakdown?: (ev: CustomEvent<BalanceElement>) => void;
|
|
78
|
-
onShowRegularReserveBalanceBreakdown?: (ev: CustomEvent<BalanceElement>) => void;
|
|
79
|
-
onShowBnplReserveBalanceBreakdown?: (ev: CustomEvent<BalanceElement>) => void;
|
|
80
|
-
}
|
|
81
|
-
interface BalanceElementSnapshot {
|
|
82
|
-
state: "loading" | "ready";
|
|
83
|
-
}
|
|
84
|
-
type BalanceElement = WhopElement<BalanceElementOptions, BalanceElementEvents, BalanceElementSnapshot>;
|
|
85
|
-
|
|
86
|
-
interface BnplReserveBalanceBreakdownElementEvents {
|
|
87
|
-
error: (error: unknown) => void;
|
|
88
|
-
ready: (element: BnplReserveBalanceBreakdownElement) => void;
|
|
89
|
-
optionsUpdated: (options: BnplReserveBalanceBreakdownElementOptions) => void;
|
|
90
|
-
close: (ev: CustomEvent) => void;
|
|
91
|
-
snapshot: (snapshot: BnplReserveBalanceBreakdownElementSnapshot) => void;
|
|
92
|
-
}
|
|
93
|
-
interface BnplReserveBalanceBreakdownElementOptions {
|
|
94
|
-
onReady?: (element: BnplReserveBalanceBreakdownElement) => void;
|
|
95
|
-
onClose?: (ev: CustomEvent) => void;
|
|
96
|
-
}
|
|
97
|
-
interface BnplReserveBalanceBreakdownElementSnapshot {
|
|
98
|
-
state: "loading" | "ready";
|
|
99
|
-
}
|
|
100
|
-
type BnplReserveBalanceBreakdownElement = WhopElement<BnplReserveBalanceBreakdownElementOptions, BnplReserveBalanceBreakdownElementEvents, BnplReserveBalanceBreakdownElementSnapshot>;
|
|
101
|
-
|
|
102
|
-
interface ChangeAccountCountryElementEvents {
|
|
103
|
-
error: (error: unknown) => void;
|
|
104
|
-
ready: (element: ChangeAccountCountryElement) => void;
|
|
105
|
-
optionsUpdated: (options: ChangeAccountCountryElementOptions) => void;
|
|
106
|
-
close: (ev: CustomEvent) => void;
|
|
107
|
-
snapshot: (snapshot: ChangeAccountCountryElementSnapshot) => void;
|
|
108
|
-
countryChanged: (ev: CustomEvent<{
|
|
109
|
-
country: string;
|
|
110
|
-
}>) => void;
|
|
111
|
-
}
|
|
112
|
-
interface ChangeAccountCountryElementOptions {
|
|
113
|
-
onReady?: (element: ChangeAccountCountryElement) => void;
|
|
114
|
-
onClose?: (ev: CustomEvent) => void;
|
|
115
|
-
onCountryChanged?: (ev: CustomEvent<{
|
|
116
|
-
country: string;
|
|
117
|
-
}>) => void;
|
|
118
|
-
}
|
|
119
|
-
interface ChangeAccountCountryElementSnapshot {
|
|
120
|
-
state: "loading" | "ready";
|
|
121
|
-
}
|
|
122
|
-
type ChangeAccountCountryElement = WhopElement<ChangeAccountCountryElementOptions, ChangeAccountCountryElementEvents, ChangeAccountCountryElementSnapshot>;
|
|
123
|
-
|
|
124
|
-
interface GenerateWithdrawalReceiptElementEvents {
|
|
125
|
-
error: (error: unknown) => void;
|
|
126
|
-
ready: (element: GenerateWithdrawalReceiptElement) => void;
|
|
127
|
-
optionsUpdated: (options: GenerateWithdrawalReceiptElementOptions) => void;
|
|
128
|
-
snapshot: (snapshot: GenerateWithdrawalReceiptElementSnapshot) => void;
|
|
129
|
-
close: (ev: CustomEvent) => void;
|
|
130
|
-
receiptRequested: (ev: CustomEvent) => void;
|
|
131
|
-
}
|
|
132
|
-
interface GenerateWithdrawalReceiptElementOptions {
|
|
133
|
-
withdrawalId: string;
|
|
134
|
-
onReady?: (element: GenerateWithdrawalReceiptElement) => void;
|
|
135
|
-
onClose?: (ev: CustomEvent) => void;
|
|
136
|
-
onReceiptRequested?: (ev: CustomEvent) => void;
|
|
137
|
-
}
|
|
138
|
-
interface GenerateWithdrawalReceiptElementSnapshot {
|
|
139
|
-
state: "loading" | "ready";
|
|
140
|
-
}
|
|
141
|
-
type GenerateWithdrawalReceiptElement = WhopElement<GenerateWithdrawalReceiptElementOptions, GenerateWithdrawalReceiptElementEvents, GenerateWithdrawalReceiptElementSnapshot>;
|
|
142
|
-
|
|
143
|
-
interface PendingBalanceBreakdownElementEvents {
|
|
144
|
-
error: (error: unknown) => void;
|
|
145
|
-
ready: (element: PendingBalanceBreakdownElement) => void;
|
|
146
|
-
optionsUpdated: (options: PendingBalanceBreakdownElementOptions) => void;
|
|
147
|
-
close: (ev: CustomEvent) => void;
|
|
148
|
-
snapshot: (snapshot: PendingBalanceBreakdownElementSnapshot) => void;
|
|
149
|
-
}
|
|
150
|
-
interface PendingBalanceBreakdownElementOptions {
|
|
151
|
-
onReady?: (element: PendingBalanceBreakdownElement) => void;
|
|
152
|
-
onClose?: (ev: CustomEvent) => void;
|
|
153
|
-
}
|
|
154
|
-
interface PendingBalanceBreakdownElementSnapshot {
|
|
155
|
-
state: "loading" | "ready";
|
|
156
|
-
}
|
|
157
|
-
type PendingBalanceBreakdownElement = WhopElement<PendingBalanceBreakdownElementOptions, PendingBalanceBreakdownElementEvents, PendingBalanceBreakdownElementSnapshot>;
|
|
158
|
-
|
|
159
|
-
interface RegularReserveBalanceBreakdownElementEvents {
|
|
160
|
-
error: (error: unknown) => void;
|
|
161
|
-
ready: (element: RegularReserveBalanceBreakdownElement) => void;
|
|
162
|
-
optionsUpdated: (options: RegularReserveBalanceBreakdownElementOptions) => void;
|
|
163
|
-
close: (ev: CustomEvent) => void;
|
|
164
|
-
snapshot: (snapshot: RegularReserveBalanceBreakdownElementSnapshot) => void;
|
|
165
|
-
}
|
|
166
|
-
interface RegularReserveBalanceBreakdownElementOptions {
|
|
167
|
-
onReady?: (element: RegularReserveBalanceBreakdownElement) => void;
|
|
168
|
-
onClose?: (ev: CustomEvent) => void;
|
|
169
|
-
}
|
|
170
|
-
interface RegularReserveBalanceBreakdownElementSnapshot {
|
|
171
|
-
state: "loading" | "ready";
|
|
172
|
-
}
|
|
173
|
-
type RegularReserveBalanceBreakdownElement = WhopElement<RegularReserveBalanceBreakdownElementOptions, RegularReserveBalanceBreakdownElementEvents, RegularReserveBalanceBreakdownElementSnapshot>;
|
|
174
|
-
|
|
175
|
-
interface ResetAccountElementEvents {
|
|
176
|
-
error: (error: unknown) => void;
|
|
177
|
-
ready: (element: ResetAccountElement) => void;
|
|
178
|
-
optionsUpdated: (options: ResetAccountElementOptions) => void;
|
|
179
|
-
close: (ev: CustomEvent) => void;
|
|
180
|
-
snapshot: (snapshot: ResetAccountElementSnapshot) => void;
|
|
181
|
-
reset: (ev: CustomEvent) => void;
|
|
182
|
-
}
|
|
183
|
-
interface ResetAccountElementOptions {
|
|
184
|
-
onReady?: (element: ResetAccountElement) => void;
|
|
185
|
-
onClose?: (ev: CustomEvent) => void;
|
|
186
|
-
onReset?: (ev: CustomEvent) => void;
|
|
187
|
-
}
|
|
188
|
-
interface ResetAccountElementSnapshot {
|
|
189
|
-
state: "loading" | "ready";
|
|
190
|
-
}
|
|
191
|
-
type ResetAccountElement = WhopElement<ResetAccountElementOptions, ResetAccountElementEvents, ResetAccountElementSnapshot>;
|
|
192
|
-
|
|
193
|
-
type StatusBannerType = "compliance-required" | "compliance-pending" | "kyc-success" | "kyc-error" | "kyc-pending" | "kyc-warning" | "information-required" | "awaiting-review" | "request-approved" | null;
|
|
194
|
-
interface StatusBannerElementEvents {
|
|
195
|
-
error: (error: unknown) => void;
|
|
196
|
-
ready: (element: StatusBannerElement) => void;
|
|
197
|
-
optionsUpdated: (options: StatusBannerElementOptions) => void;
|
|
198
|
-
snapshot: (snapshot: StatusBannerElementSnapshot) => void;
|
|
199
|
-
verifyClick: (ev: CustomEvent<StatusBannerElement>) => void;
|
|
200
|
-
bannerChange: (ev: CustomEvent<StatusBannerElement>, bannerType: StatusBannerType) => void;
|
|
201
|
-
}
|
|
202
|
-
interface StatusBannerElementOptions {
|
|
203
|
-
onReady?: (element: StatusBannerElement) => void;
|
|
204
|
-
onVerifyClick?: (ev: CustomEvent<StatusBannerElement>) => void;
|
|
205
|
-
onBannerChange?: (ev: CustomEvent<StatusBannerElement>, bannerType: StatusBannerType) => void;
|
|
206
|
-
}
|
|
207
|
-
interface StatusBannerElementSnapshot {
|
|
208
|
-
state: "loading" | "ready";
|
|
209
|
-
bannerType: StatusBannerType;
|
|
210
|
-
}
|
|
211
|
-
type StatusBannerElement = WhopElement<StatusBannerElementOptions, StatusBannerElementEvents, StatusBannerElementSnapshot>;
|
|
212
|
-
|
|
213
|
-
interface TotalBalanceBreakdownElementEvents {
|
|
214
|
-
error: (error: unknown) => void;
|
|
215
|
-
ready: (element: TotalBalanceBreakdownElement) => void;
|
|
216
|
-
optionsUpdated: (options: TotalBalanceBreakdownElementOptions) => void;
|
|
217
|
-
close: (ev: CustomEvent) => void;
|
|
218
|
-
snapshot: (snapshot: TotalBalanceBreakdownElementSnapshot) => void;
|
|
219
|
-
}
|
|
220
|
-
interface TotalBalanceBreakdownElementOptions {
|
|
221
|
-
onReady?: (element: TotalBalanceBreakdownElement) => void;
|
|
222
|
-
onClose?: (ev: CustomEvent) => void;
|
|
223
|
-
}
|
|
224
|
-
interface TotalBalanceBreakdownElementSnapshot {
|
|
225
|
-
state: "loading" | "ready";
|
|
226
|
-
}
|
|
227
|
-
type TotalBalanceBreakdownElement = WhopElement<TotalBalanceBreakdownElementOptions, TotalBalanceBreakdownElementEvents, TotalBalanceBreakdownElementSnapshot>;
|
|
228
|
-
|
|
229
|
-
interface VerifyElementEvents {
|
|
230
|
-
error: (error: unknown) => void;
|
|
231
|
-
ready: (element: VerifyElement) => void;
|
|
232
|
-
optionsUpdated: (options: VerifyElementOptions) => void;
|
|
233
|
-
close: (ev: CustomEvent) => void;
|
|
234
|
-
snapshot: (snapshot: VerifyElementSnapshot) => void;
|
|
235
|
-
verificationSubmitted: (ev: CustomEvent<VerifyElement>) => void;
|
|
236
|
-
}
|
|
237
|
-
interface VerifyElementOptions {
|
|
238
|
-
includeControls?: boolean;
|
|
239
|
-
onReady?: (element: VerifyElement) => void;
|
|
240
|
-
onVerificationSubmitted?: (ev: CustomEvent<VerifyElement>) => void;
|
|
241
|
-
onClose?: (ev: CustomEvent) => void;
|
|
242
|
-
}
|
|
243
|
-
interface VerifyElementSnapshot {
|
|
244
|
-
state: "loading" | "ready";
|
|
245
|
-
}
|
|
246
|
-
type VerifyElement = WhopElement<VerifyElementOptions, VerifyElementEvents, VerifyElementSnapshot>;
|
|
247
|
-
|
|
248
|
-
interface WithdrawButtonElementEvents {
|
|
249
|
-
error: (error: unknown) => void;
|
|
250
|
-
ready: (element: WithdrawButtonElement) => void;
|
|
251
|
-
optionsUpdated: (options: WithdrawButtonElementOptions) => void;
|
|
252
|
-
verify: (ev: CustomEvent<WithdrawButtonElement>) => void;
|
|
253
|
-
withdraw: (ev: CustomEvent<WithdrawButtonElement>) => void;
|
|
254
|
-
snapshot: (snapshot: WithdrawButtonElementSnapshot) => void;
|
|
255
|
-
verificationSubmitted: (ev: CustomEvent<WithdrawButtonElement>) => void;
|
|
256
|
-
withdrawalRequested: (ev: CustomEvent<WithdrawButtonElement>) => void;
|
|
257
|
-
}
|
|
258
|
-
interface WithdrawButtonElementOptions {
|
|
259
|
-
hidePendingBalance?: boolean;
|
|
260
|
-
onReady?: (element: WithdrawButtonElement) => void;
|
|
261
|
-
onVerificationSubmitted?: (ev: CustomEvent<WithdrawButtonElement>) => void;
|
|
262
|
-
onWithdrawalRequested?: (ev: CustomEvent<WithdrawButtonElement>) => void;
|
|
263
|
-
size?: "1" | "2" | "3" | "4";
|
|
264
|
-
variant?: "solid" | "soft" | "surface" | "ghost" | "classic";
|
|
265
|
-
color?: AccentColor;
|
|
266
|
-
highContrast?: boolean;
|
|
267
|
-
}
|
|
268
|
-
interface WithdrawButtonElementSnapshot {
|
|
269
|
-
state: "loading" | "ready";
|
|
270
|
-
}
|
|
271
|
-
type WithdrawButtonElement = WhopElement<WithdrawButtonElementOptions, WithdrawButtonElementEvents, WithdrawButtonElementSnapshot>;
|
|
272
|
-
|
|
273
|
-
interface WithdrawElementEvents {
|
|
274
|
-
error: (error: unknown) => void;
|
|
275
|
-
ready: (element: WithdrawElement) => void;
|
|
276
|
-
optionsUpdated: (options: WithdrawElementOptions) => void;
|
|
277
|
-
snapshot: (snapshot: WithdrawElementSnapshot) => void;
|
|
278
|
-
close: (ev: CustomEvent) => void;
|
|
279
|
-
withdraw: (ev: CustomEvent) => void;
|
|
280
|
-
}
|
|
281
|
-
interface WithdrawElementOptions {
|
|
282
|
-
onReady?: (element: WithdrawElement) => void;
|
|
283
|
-
onWithdraw?: (ev: CustomEvent) => void;
|
|
284
|
-
onClose?: (ev: CustomEvent) => void;
|
|
285
|
-
}
|
|
286
|
-
interface WithdrawElementSnapshot {
|
|
287
|
-
state: "loading" | "ready";
|
|
288
|
-
}
|
|
289
|
-
type WithdrawElement = WhopElement<WithdrawElementOptions, WithdrawElementEvents, WithdrawElementSnapshot>;
|
|
290
|
-
|
|
291
|
-
interface WithdrawalBreakdownElementEvents {
|
|
292
|
-
error: (error: unknown) => void;
|
|
293
|
-
ready: (element: WithdrawalBreakdownElement) => void;
|
|
294
|
-
optionsUpdated: (options: WithdrawalBreakdownElementOptions) => void;
|
|
295
|
-
close: (ev: CustomEvent) => void;
|
|
296
|
-
snapshot: (snapshot: WithdrawalBreakdownElementSnapshot) => void;
|
|
297
|
-
}
|
|
298
|
-
interface WithdrawalBreakdownElementOptions {
|
|
299
|
-
withdrawalId: string;
|
|
300
|
-
onReady?: (element: WithdrawalBreakdownElement) => void;
|
|
301
|
-
onClose?: (ev: CustomEvent) => void;
|
|
302
|
-
}
|
|
303
|
-
interface WithdrawalBreakdownElementSnapshot {
|
|
304
|
-
state: "loading" | "ready";
|
|
305
|
-
}
|
|
306
|
-
type WithdrawalBreakdownElement = WhopElement<WithdrawalBreakdownElementOptions, WithdrawalBreakdownElementEvents, WithdrawalBreakdownElementSnapshot>;
|
|
307
|
-
|
|
308
|
-
interface WithdrawalsElementEvents {
|
|
309
|
-
error: (error: unknown) => void;
|
|
310
|
-
ready: (element: WithdrawalsElement) => void;
|
|
311
|
-
optionsUpdated: (options: WithdrawalsElementOptions) => void;
|
|
312
|
-
snapshot: (snapshot: WithdrawalsElementSnapshot) => void;
|
|
313
|
-
showWithdrawalBreakdown: (ev: CustomEvent<{
|
|
314
|
-
withdrawalId: string;
|
|
315
|
-
}>) => void;
|
|
316
|
-
showGenerateWithdrawalReceipt: (ev: CustomEvent<{
|
|
317
|
-
withdrawalId: string;
|
|
318
|
-
}>) => void;
|
|
319
|
-
}
|
|
320
|
-
interface WithdrawalsElementOptions {
|
|
321
|
-
onReady?: (element: WithdrawalsElement) => void;
|
|
322
|
-
}
|
|
323
|
-
interface WithdrawalsElementSnapshot {
|
|
324
|
-
state: "loading" | "ready";
|
|
325
|
-
}
|
|
326
|
-
type WithdrawalsElement = WhopElement<WithdrawalsElementOptions, WithdrawalsElementEvents, WithdrawalsElementSnapshot>;
|
|
327
|
-
|
|
328
|
-
interface ModalContainer {
|
|
329
|
-
modalContainer: HTMLElement;
|
|
330
|
-
mount: () => void;
|
|
331
|
-
close: () => void;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/** elements types */
|
|
335
|
-
|
|
336
|
-
type GetToken = (opts: {
|
|
337
|
-
abortSignal: AbortSignal;
|
|
338
|
-
}) => Promise<string | null> | string | null;
|
|
339
|
-
interface PayoutsSessionOptions {
|
|
340
|
-
/**
|
|
341
|
-
* The token to use for the session. If a function is provided, it will be called and awaited to get the token.
|
|
342
|
-
* When a function is provided, the token will be refreshed automatically before it expires.
|
|
343
|
-
*
|
|
344
|
-
* if a string is provided, it will be used as the token and not refreshed automatically. However you can update the token at runtime by
|
|
345
|
-
* calling `updateOptions` with a new token.
|
|
346
|
-
*
|
|
347
|
-
* @example
|
|
348
|
-
* ```ts
|
|
349
|
-
* // with a static token
|
|
350
|
-
* async function createPayoutsSession() {
|
|
351
|
-
* const token = await fetch("/api/token")
|
|
352
|
-
* .then(res => res.json())
|
|
353
|
-
* .then(data => data.token)
|
|
354
|
-
* return new PayoutsSession({ token })
|
|
355
|
-
* }
|
|
356
|
-
*
|
|
357
|
-
* // with a dynamic function
|
|
358
|
-
* function createPayoutsSession() {
|
|
359
|
-
* return new PayoutsSession({
|
|
360
|
-
* token: () => {
|
|
361
|
-
* return await fetch("/api/token")
|
|
362
|
-
* .then(res => res.json())
|
|
363
|
-
* .then(data => data.token)
|
|
364
|
-
* }
|
|
365
|
-
* })
|
|
366
|
-
* }
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
token: string | Promise<string | null> | null | GetToken;
|
|
370
|
-
/**
|
|
371
|
-
* The currency to use in the Elements
|
|
372
|
-
*
|
|
373
|
-
* @default "USD"
|
|
374
|
-
*/
|
|
375
|
-
currency?: string;
|
|
376
|
-
/**
|
|
377
|
-
* The company ID to use in the Elements
|
|
378
|
-
*/
|
|
379
|
-
companyId: string;
|
|
380
|
-
/**
|
|
381
|
-
* URL to redirect to after identity verification is completed.
|
|
382
|
-
* This must be an absolute URL (e.g., "https://yourapp.com/callback").
|
|
383
|
-
* Localhost URLs will not work - use ngrok for local development.
|
|
384
|
-
*/
|
|
385
|
-
redirectUrl: string;
|
|
386
|
-
}
|
|
387
|
-
interface ExpandedPayoutsSessionOptions extends PayoutsSessionOptions {
|
|
388
|
-
}
|
|
389
|
-
interface PayoutsSessionEvents {
|
|
390
|
-
optionsUpdated: (options: ExpandedPayoutsSessionOptions) => void;
|
|
391
|
-
tokenRefreshed: (token: string) => void;
|
|
392
|
-
tokenRefreshError: (error: unknown) => void;
|
|
393
|
-
error: (error: unknown) => void;
|
|
394
|
-
ready: () => void;
|
|
395
|
-
}
|
|
396
|
-
type PayoutsSessionElements = {
|
|
397
|
-
"balance-element": [BalanceElementOptions, BalanceElement];
|
|
398
|
-
"withdraw-button-element": [
|
|
399
|
-
WithdrawButtonElementOptions,
|
|
400
|
-
WithdrawButtonElement
|
|
401
|
-
];
|
|
402
|
-
"withdraw-element": [WithdrawElementOptions, WithdrawElement];
|
|
403
|
-
"verify-element": [VerifyElementOptions, VerifyElement];
|
|
404
|
-
"withdrawals-element": [WithdrawalsElementOptions, WithdrawalsElement];
|
|
405
|
-
"withdrawal-breakdown-element": [
|
|
406
|
-
WithdrawalBreakdownElementOptions,
|
|
407
|
-
WithdrawalBreakdownElement
|
|
408
|
-
];
|
|
409
|
-
"change-account-country-element": [
|
|
410
|
-
ChangeAccountCountryElementOptions,
|
|
411
|
-
ChangeAccountCountryElement
|
|
412
|
-
];
|
|
413
|
-
"reset-account-element": [ResetAccountElementOptions, ResetAccountElement];
|
|
414
|
-
"regular-reserve-balance-breakdown-element": [
|
|
415
|
-
RegularReserveBalanceBreakdownElementOptions,
|
|
416
|
-
RegularReserveBalanceBreakdownElement
|
|
417
|
-
];
|
|
418
|
-
"bnpl-reserve-balance-breakdown-element": [
|
|
419
|
-
BnplReserveBalanceBreakdownElementOptions,
|
|
420
|
-
BnplReserveBalanceBreakdownElement
|
|
421
|
-
];
|
|
422
|
-
"total-balance-breakdown-element": [
|
|
423
|
-
TotalBalanceBreakdownElementOptions,
|
|
424
|
-
TotalBalanceBreakdownElement
|
|
425
|
-
];
|
|
426
|
-
"pending-balance-breakdown-element": [
|
|
427
|
-
PendingBalanceBreakdownElementOptions,
|
|
428
|
-
PendingBalanceBreakdownElement
|
|
429
|
-
];
|
|
430
|
-
"generate-withdrawal-receipt-element": [
|
|
431
|
-
GenerateWithdrawalReceiptElementOptions,
|
|
432
|
-
GenerateWithdrawalReceiptElement
|
|
433
|
-
];
|
|
434
|
-
"status-banner-element": [StatusBannerElementOptions, StatusBannerElement];
|
|
435
|
-
};
|
|
436
|
-
interface PayoutsSession extends TypedEmitter<PayoutsSessionEvents> {
|
|
437
|
-
token: Promise<string | null>;
|
|
438
|
-
updateOptions: (options: Partial<PayoutsSessionOptions>) => void;
|
|
439
|
-
destroy: () => void;
|
|
440
|
-
createElement<T extends keyof PayoutsSessionElements>(type: T | {
|
|
441
|
-
type: T;
|
|
442
|
-
}, options: PayoutsSessionElements[T][0]): PayoutsSessionElements[T][1];
|
|
443
|
-
showWithdrawModal: <Force extends boolean = false>(options: WithdrawElementOptions | ((modal: ModalContainer) => WithdrawElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
444
|
-
showVerifyModal: <Force extends boolean = false>(options: VerifyElementOptions | ((modal: ModalContainer) => VerifyElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
445
|
-
showWithdrawalBreakdownModal: <Force extends boolean = false>(options: WithdrawalBreakdownElementOptions | ((modal: ModalContainer) => WithdrawalBreakdownElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
446
|
-
showChangeAccountCountryModal: <Force extends boolean = false>(options: ChangeAccountCountryElementOptions | ((modal: ModalContainer) => ChangeAccountCountryElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
447
|
-
showResetAccountModal: <Force extends boolean = false>(options: ResetAccountElementOptions | ((modal: ModalContainer) => ResetAccountElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
448
|
-
showTotalBalanceBreakdownModal: <Force extends boolean = false>(options: TotalBalanceBreakdownElementOptions | ((modal: ModalContainer) => TotalBalanceBreakdownElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
449
|
-
showPendingBalanceBreakdownModal: <Force extends boolean = false>(options: PendingBalanceBreakdownElementOptions | ((modal: ModalContainer) => PendingBalanceBreakdownElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
450
|
-
showRegularReserveBalanceBreakdownModal: <Force extends boolean = false>(options: RegularReserveBalanceBreakdownElementOptions | ((modal: ModalContainer) => RegularReserveBalanceBreakdownElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
451
|
-
showBnplReserveBalanceBreakdownModal: <Force extends boolean = false>(options: BnplReserveBalanceBreakdownElementOptions | ((modal: ModalContainer) => BnplReserveBalanceBreakdownElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
452
|
-
showGenerateWithdrawalReceiptModal: <Force extends boolean = false>(options: GenerateWithdrawalReceiptElementOptions | ((modal: ModalContainer) => GenerateWithdrawalReceiptElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
declare global {
|
|
456
|
-
interface Window {
|
|
457
|
-
WhopElements: WhopElementsConstructor;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
type WhopElementsOptions = {
|
|
461
|
-
/**
|
|
462
|
-
* Customize the appearance of the Whop embedded Elements
|
|
463
|
-
*/
|
|
464
|
-
appearance?: Appearance;
|
|
465
|
-
/**
|
|
466
|
-
* This locale to use in the Elements
|
|
467
|
-
*
|
|
468
|
-
* @default "en"
|
|
469
|
-
*/
|
|
470
|
-
locale?: I18nSupportedLocale;
|
|
471
|
-
};
|
|
472
|
-
type WhopElementsConstructor = {
|
|
473
|
-
new (options?: WhopElementsOptions): WhopElements;
|
|
474
|
-
};
|
|
475
|
-
interface WhopElements extends TypedEmitter<WhopElementsEvents> {
|
|
476
|
-
createPayoutsSession: (options: PayoutsSessionOptions) => PayoutsSession;
|
|
477
|
-
updateOptions: (options: Partial<WhopElementsOptions>) => void;
|
|
478
|
-
options: WhopElementsOptions;
|
|
479
|
-
}
|
|
480
|
-
interface WhopElementsEvents {
|
|
481
|
-
optionsUpdated: (options: WhopElementsOptions) => void;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
export type { Appearance, BalanceElement, BalanceElementOptions, BalanceElementSnapshot, BnplReserveBalanceBreakdownElement, BnplReserveBalanceBreakdownElementOptions, BnplReserveBalanceBreakdownElementSnapshot, ChangeAccountCountryElement, ChangeAccountCountryElementOptions, ChangeAccountCountryElementSnapshot, ExpandedPayoutsSessionOptions, GenerateWithdrawalReceiptElement, GenerateWithdrawalReceiptElementOptions, GenerateWithdrawalReceiptElementSnapshot, GetToken, I18nSupportedLocale, PayoutsSession, PayoutsSessionEvents, PayoutsSessionOptions, PendingBalanceBreakdownElement, PendingBalanceBreakdownElementOptions, PendingBalanceBreakdownElementSnapshot, RegularReserveBalanceBreakdownElement, RegularReserveBalanceBreakdownElementOptions, RegularReserveBalanceBreakdownElementSnapshot, ResetAccountElement, ResetAccountElementOptions, ResetAccountElementSnapshot, StatusBannerElement, StatusBannerElementOptions, StatusBannerElementSnapshot, StatusBannerType, TotalBalanceBreakdownElement, TotalBalanceBreakdownElementOptions, TotalBalanceBreakdownElementSnapshot, VerifyElement, VerifyElementOptions, VerifyElementSnapshot, WhopElement, WhopElements, WhopElementsConstructor, WhopElementsEvents, WhopElementsOptions, WithdrawButtonElement, WithdrawButtonElementOptions, WithdrawElement, WithdrawElementOptions, WithdrawElementSnapshot, WithdrawalBreakdownElement, WithdrawalBreakdownElementOptions, WithdrawalBreakdownElementSnapshot, WithdrawalsElement, WithdrawalsElementOptions, WithdrawalsElementSnapshot };
|
package/dist/pure.d.ts
DELETED
package/dist/pure.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var pure_exports = {};
|
|
20
|
-
__export(pure_exports, {
|
|
21
|
-
loadWhopElements: () => loadWhopElements
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(pure_exports);
|
|
24
|
-
var import_util = require("./util");
|
|
25
|
-
const loadWhopElements = async (...args) => {
|
|
26
|
-
const maybeWhopElements = await (0, import_util.loadScript)();
|
|
27
|
-
return (0, import_util.initWhopElements)(maybeWhopElements, args);
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=pure.js.map
|
package/dist/pure.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pure.ts"],"sourcesContent":["import type { LoadWhopElements } from \"./util\";\nimport { initWhopElements, loadScript } from \"./util\";\n\nexport const loadWhopElements: LoadWhopElements = async (...args) => {\n\tconst maybeWhopElements = await loadScript();\n\n\treturn initWhopElements(maybeWhopElements, args);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA6C;AAEtC,MAAM,mBAAqC,UAAU,SAAS;AACpE,QAAM,oBAAoB,UAAM,wBAAW;AAE3C,aAAO,8BAAiB,mBAAmB,IAAI;AAChD;","names":[]}
|
package/dist/pure.mjs
DELETED
package/dist/pure.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pure.ts"],"sourcesContent":["import type { LoadWhopElements } from \"./util\";\nimport { initWhopElements, loadScript } from \"./util\";\n\nexport const loadWhopElements: LoadWhopElements = async (...args) => {\n\tconst maybeWhopElements = await loadScript();\n\n\treturn initWhopElements(maybeWhopElements, args);\n};\n"],"mappings":"AACA,SAAS,kBAAkB,kBAAkB;AAEtC,MAAM,mBAAqC,UAAU,SAAS;AACpE,QAAM,oBAAoB,MAAM,WAAW;AAE3C,SAAO,iBAAiB,mBAAmB,IAAI;AAChD;","names":[]}
|
package/dist/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './lib';
|
package/dist/types.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var types_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(types_exports);
|
|
18
|
-
__reExport(types_exports, require("./lib"), module.exports);
|
|
19
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export * from \"./lib\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,kBAAd;","names":[]}
|
package/dist/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./lib";
|
package/dist/types.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export * from \"./lib\";\n"],"mappings":"AAAA,cAAc;","names":[]}
|
package/dist/url.d.ts
DELETED
package/dist/url.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var url_exports = {};
|
|
20
|
-
__export(url_exports, {
|
|
21
|
-
ORIGIN: () => ORIGIN,
|
|
22
|
-
SCRIPT_URL: () => SCRIPT_URL
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(url_exports);
|
|
25
|
-
const ORIGIN = "https://0-0-5-beta-3.elements.whop.com/";
|
|
26
|
-
const SCRIPT_URL = new URL(`/release/elements.js`, ORIGIN).toString();
|
|
27
|
-
//# sourceMappingURL=url.js.map
|
package/dist/url.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/url.ts"],"sourcesContent":["declare const _ELEMENTS_ORIGIN: string;\n\nexport const ORIGIN = _ELEMENTS_ORIGIN;\nexport const SCRIPT_URL = new URL(`/release/elements.js`, ORIGIN).toString();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,SAAS;AACf,MAAM,aAAa,IAAI,IAAI,wBAAwB,MAAM,EAAE,SAAS;","names":[]}
|
package/dist/url.mjs
DELETED
package/dist/url.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/url.ts"],"sourcesContent":["declare const _ELEMENTS_ORIGIN: string;\n\nexport const ORIGIN = _ELEMENTS_ORIGIN;\nexport const SCRIPT_URL = new URL(`/release/elements.js`, ORIGIN).toString();\n"],"mappings":"AAEO,MAAM,SAAS;AACf,MAAM,aAAa,IAAI,IAAI,wBAAwB,MAAM,EAAE,SAAS;","names":[]}
|
package/dist/util.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { WhopElementsConstructor, WhopElements } from './lib';
|
|
2
|
-
|
|
3
|
-
type LoadWhopElements = (...args: ConstructorParameters<WhopElementsConstructor>) => Promise<WhopElements | null>;
|
|
4
|
-
declare const findScript: () => HTMLScriptElement | null;
|
|
5
|
-
declare const loadScript: () => Promise<WhopElementsConstructor | null>;
|
|
6
|
-
declare const initWhopElements: (maybeWhopElements: WhopElementsConstructor | null, args: ConstructorParameters<WhopElementsConstructor>) => WhopElements | null;
|
|
7
|
-
|
|
8
|
-
export { type LoadWhopElements, findScript, initWhopElements, loadScript };
|
package/dist/util.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var util_exports = {};
|
|
20
|
-
__export(util_exports, {
|
|
21
|
-
findScript: () => findScript,
|
|
22
|
-
initWhopElements: () => initWhopElements,
|
|
23
|
-
loadScript: () => loadScript
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(util_exports);
|
|
26
|
-
var import_url = require("./url");
|
|
27
|
-
const isWhopElementsScriptURL = (url) => {
|
|
28
|
-
const result = url.startsWith(import_url.ORIGIN) && url.endsWith("/elements.js");
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
const findScript = () => {
|
|
32
|
-
const scripts = document.querySelectorAll(
|
|
33
|
-
`script[src^="${import_url.ORIGIN}"]`
|
|
34
|
-
);
|
|
35
|
-
for (const script of scripts) {
|
|
36
|
-
if (!script || !isWhopElementsScriptURL(script.src)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
return script;
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
};
|
|
43
|
-
const injectScript = () => {
|
|
44
|
-
const script = document.createElement("script");
|
|
45
|
-
script.src = import_url.SCRIPT_URL;
|
|
46
|
-
const headOrBody = document.head || document.body;
|
|
47
|
-
if (!headOrBody) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
"Expected document.body not to be null. WhopElements requires a <body> element."
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
headOrBody.appendChild(script);
|
|
53
|
-
return script;
|
|
54
|
-
};
|
|
55
|
-
let whopElementsPromise = null;
|
|
56
|
-
let onErrorListener = null;
|
|
57
|
-
let onLoadListener = null;
|
|
58
|
-
const onError = (reject) => (cause) => {
|
|
59
|
-
reject(new Error("Failed to load WhopElements", { cause }));
|
|
60
|
-
};
|
|
61
|
-
const onLoad = (resolve, reject) => () => {
|
|
62
|
-
if (window.WhopElements) {
|
|
63
|
-
resolve(window.WhopElements);
|
|
64
|
-
} else {
|
|
65
|
-
reject(new Error("WhopElements not available"));
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const loadScript = () => {
|
|
69
|
-
if (whopElementsPromise !== null) {
|
|
70
|
-
return whopElementsPromise;
|
|
71
|
-
}
|
|
72
|
-
whopElementsPromise = new Promise((resolve, reject) => {
|
|
73
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
74
|
-
resolve(null);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (window.WhopElements) {
|
|
78
|
-
resolve(window.WhopElements);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
let script = findScript();
|
|
83
|
-
if (!script) {
|
|
84
|
-
script = injectScript();
|
|
85
|
-
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
86
|
-
script.removeEventListener("load", onLoadListener);
|
|
87
|
-
script.removeEventListener("error", onErrorListener);
|
|
88
|
-
script.parentNode?.removeChild(script);
|
|
89
|
-
script = injectScript();
|
|
90
|
-
}
|
|
91
|
-
onLoadListener = onLoad(resolve, reject);
|
|
92
|
-
onErrorListener = onError(reject);
|
|
93
|
-
script.addEventListener("load", onLoadListener);
|
|
94
|
-
script.addEventListener("error", onErrorListener);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (error instanceof Error) {
|
|
97
|
-
reject(error);
|
|
98
|
-
} else {
|
|
99
|
-
reject(new Error("Failed to load WhopElements", { cause: error }));
|
|
100
|
-
}
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
return whopElementsPromise.catch((error) => {
|
|
105
|
-
whopElementsPromise = null;
|
|
106
|
-
if (error instanceof Error) {
|
|
107
|
-
return Promise.reject(error);
|
|
108
|
-
} else {
|
|
109
|
-
return Promise.reject(
|
|
110
|
-
new Error("Failed to load WhopElements", { cause: error })
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
const initWhopElements = (maybeWhopElements, args) => {
|
|
116
|
-
if (maybeWhopElements === null) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
const WhopElements = maybeWhopElements;
|
|
120
|
-
return new WhopElements(...args);
|
|
121
|
-
};
|
|
122
|
-
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/util.ts"],"sourcesContent":["import type { WhopElements, WhopElementsConstructor } from \"./types\";\nimport { ORIGIN, SCRIPT_URL } from \"./url\";\n\nexport type LoadWhopElements = (\n\t...args: ConstructorParameters<WhopElementsConstructor>\n) => Promise<WhopElements | null>;\n\nconst isWhopElementsScriptURL = (url: string): boolean => {\n\tconst result = url.startsWith(ORIGIN) && url.endsWith(\"/elements.js\");\n\treturn result;\n};\n\nexport const findScript = (): HTMLScriptElement | null => {\n\tconst scripts = document.querySelectorAll<HTMLScriptElement>(\n\t\t`script[src^=\"${ORIGIN}\"]`,\n\t);\n\n\tfor (const script of scripts) {\n\t\tif (!script || !isWhopElementsScriptURL(script.src)) {\n\t\t\tcontinue;\n\t\t}\n\t\treturn script;\n\t}\n\treturn null;\n};\n\nconst injectScript = (): HTMLScriptElement => {\n\tconst script = document.createElement(\"script\");\n\tscript.src = SCRIPT_URL;\n\n\tconst headOrBody = document.head || document.body;\n\n\tif (!headOrBody) {\n\t\tthrow new Error(\n\t\t\t\"Expected document.body not to be null. WhopElements requires a <body> element.\",\n\t\t);\n\t}\n\n\theadOrBody.appendChild(script);\n\n\treturn script;\n};\n\nlet whopElementsPromise: Promise<WhopElementsConstructor | null> | null = null;\n\nlet onErrorListener: ((cause?: unknown) => void) | null = null;\nlet onLoadListener: (() => void) | null = null;\n\nconst onError = (reject: (reason?: unknown) => void) => (cause?: unknown) => {\n\treject(new Error(\"Failed to load WhopElements\", { cause }));\n};\n\nconst onLoad =\n\t(\n\t\tresolve: (\n\t\t\tvalue:\n\t\t\t\t| WhopElementsConstructor\n\t\t\t\t| PromiseLike<WhopElementsConstructor | null>\n\t\t\t\t| null,\n\t\t) => void,\n\t\treject: (reason?: unknown) => void,\n\t) =>\n\t() => {\n\t\tif (window.WhopElements) {\n\t\t\tresolve(window.WhopElements);\n\t\t} else {\n\t\t\treject(new Error(\"WhopElements not available\"));\n\t\t}\n\t};\n\nexport const loadScript = (): Promise<WhopElementsConstructor | null> => {\n\tif (whopElementsPromise !== null) {\n\t\treturn whopElementsPromise;\n\t}\n\n\twhopElementsPromise = new Promise((resolve, reject) => {\n\t\tif (typeof window === \"undefined\" || typeof document === \"undefined\") {\n\t\t\tresolve(null);\n\t\t\treturn;\n\t\t}\n\n\t\tif (window.WhopElements) {\n\t\t\tresolve(window.WhopElements);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tlet script = findScript();\n\n\t\t\tif (!script) {\n\t\t\t\tscript = injectScript();\n\t\t\t} else if (\n\t\t\t\tscript &&\n\t\t\t\tonLoadListener !== null &&\n\t\t\t\tonErrorListener !== null\n\t\t\t) {\n\t\t\t\t// remove event listeners\n\t\t\t\tscript.removeEventListener(\"load\", onLoadListener);\n\t\t\t\tscript.removeEventListener(\"error\", onErrorListener);\n\n\t\t\t\t// if script exists, but we are reloading due to an error,\n\t\t\t\t// reload script to trigger 'load' event\n\t\t\t\tscript.parentNode?.removeChild(script);\n\t\t\t\tscript = injectScript();\n\t\t\t}\n\n\t\t\tonLoadListener = onLoad(resolve, reject);\n\t\t\tonErrorListener = onError(reject);\n\t\t\tscript.addEventListener(\"load\", onLoadListener);\n\t\t\tscript.addEventListener(\"error\", onErrorListener);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\treject(error);\n\t\t\t} else {\n\t\t\t\treject(new Error(\"Failed to load WhopElements\", { cause: error }));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t});\n\n\treturn whopElementsPromise.catch((error) => {\n\t\twhopElementsPromise = null;\n\t\tif (error instanceof Error) {\n\t\t\treturn Promise.reject(error);\n\t\t} else {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew Error(\"Failed to load WhopElements\", { cause: error }),\n\t\t\t);\n\t\t}\n\t});\n};\n\nexport const initWhopElements = (\n\tmaybeWhopElements: WhopElementsConstructor | null,\n\targs: ConstructorParameters<WhopElementsConstructor>,\n): WhopElements | null => {\n\tif (maybeWhopElements === null) {\n\t\treturn null;\n\t}\n\tconst WhopElements = maybeWhopElements;\n\n\treturn new WhopElements(...args);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAmC;AAMnC,MAAM,0BAA0B,CAAC,QAAyB;AACzD,QAAM,SAAS,IAAI,WAAW,iBAAM,KAAK,IAAI,SAAS,cAAc;AACpE,SAAO;AACR;AAEO,MAAM,aAAa,MAAgC;AACzD,QAAM,UAAU,SAAS;AAAA,IACxB,gBAAgB,iBAAM;AAAA,EACvB;AAEA,aAAW,UAAU,SAAS;AAC7B,QAAI,CAAC,UAAU,CAAC,wBAAwB,OAAO,GAAG,GAAG;AACpD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAEA,MAAM,eAAe,MAAyB;AAC7C,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AAEb,QAAM,aAAa,SAAS,QAAQ,SAAS;AAE7C,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,aAAW,YAAY,MAAM;AAE7B,SAAO;AACR;AAEA,IAAI,sBAAsE;AAE1E,IAAI,kBAAsD;AAC1D,IAAI,iBAAsC;AAE1C,MAAM,UAAU,CAAC,WAAuC,CAAC,UAAoB;AAC5E,SAAO,IAAI,MAAM,+BAA+B,EAAE,MAAM,CAAC,CAAC;AAC3D;AAEA,MAAM,SACL,CACC,SAMA,WAED,MAAM;AACL,MAAI,OAAO,cAAc;AACxB,YAAQ,OAAO,YAAY;AAAA,EAC5B,OAAO;AACN,WAAO,IAAI,MAAM,4BAA4B,CAAC;AAAA,EAC/C;AACD;AAEM,MAAM,aAAa,MAA+C;AACxE,MAAI,wBAAwB,MAAM;AACjC,WAAO;AAAA,EACR;AAEA,wBAAsB,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtD,QAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aAAa;AACrE,cAAQ,IAAI;AACZ;AAAA,IACD;AAEA,QAAI,OAAO,cAAc;AACxB,cAAQ,OAAO,YAAY;AAC3B;AAAA,IACD;AAEA,QAAI;AACH,UAAI,SAAS,WAAW;AAExB,UAAI,CAAC,QAAQ;AACZ,iBAAS,aAAa;AAAA,MACvB,WACC,UACA,mBAAmB,QACnB,oBAAoB,MACnB;AAED,eAAO,oBAAoB,QAAQ,cAAc;AACjD,eAAO,oBAAoB,SAAS,eAAe;AAInD,eAAO,YAAY,YAAY,MAAM;AACrC,iBAAS,aAAa;AAAA,MACvB;AAEA,uBAAiB,OAAO,SAAS,MAAM;AACvC,wBAAkB,QAAQ,MAAM;AAChC,aAAO,iBAAiB,QAAQ,cAAc;AAC9C,aAAO,iBAAiB,SAAS,eAAe;AAAA,IACjD,SAAS,OAAO;AACf,UAAI,iBAAiB,OAAO;AAC3B,eAAO,KAAK;AAAA,MACb,OAAO;AACN,eAAO,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC,CAAC;AAAA,MAClE;AACA;AAAA,IACD;AAAA,EACD,CAAC;AAED,SAAO,oBAAoB,MAAM,CAAC,UAAU;AAC3C,0BAAsB;AACtB,QAAI,iBAAiB,OAAO;AAC3B,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC5B,OAAO;AACN,aAAO,QAAQ;AAAA,QACd,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAEO,MAAM,mBAAmB,CAC/B,mBACA,SACyB;AACzB,MAAI,sBAAsB,MAAM;AAC/B,WAAO;AAAA,EACR;AACA,QAAM,eAAe;AAErB,SAAO,IAAI,aAAa,GAAG,IAAI;AAChC;","names":[]}
|
package/dist/util.mjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { ORIGIN, SCRIPT_URL } from "./url.mjs";
|
|
2
|
-
const isWhopElementsScriptURL = (url)=>{
|
|
3
|
-
const result = url.startsWith(ORIGIN) && url.endsWith("/elements.js");
|
|
4
|
-
return result;
|
|
5
|
-
};
|
|
6
|
-
const findScript = ()=>{
|
|
7
|
-
const scripts = document.querySelectorAll(`script[src^="${ORIGIN}"]`);
|
|
8
|
-
for (const script of scripts){
|
|
9
|
-
if (!script || !isWhopElementsScriptURL(script.src)) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
return script;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
const injectScript = ()=>{
|
|
17
|
-
const script = document.createElement("script");
|
|
18
|
-
script.src = SCRIPT_URL;
|
|
19
|
-
const headOrBody = document.head || document.body;
|
|
20
|
-
if (!headOrBody) {
|
|
21
|
-
throw new Error("Expected document.body not to be null. WhopElements requires a <body> element.");
|
|
22
|
-
}
|
|
23
|
-
headOrBody.appendChild(script);
|
|
24
|
-
return script;
|
|
25
|
-
};
|
|
26
|
-
let whopElementsPromise = null;
|
|
27
|
-
let onErrorListener = null;
|
|
28
|
-
let onLoadListener = null;
|
|
29
|
-
const onError = (reject)=>(cause)=>{
|
|
30
|
-
reject(new Error("Failed to load WhopElements", {
|
|
31
|
-
cause
|
|
32
|
-
}));
|
|
33
|
-
};
|
|
34
|
-
const onLoad = (resolve, reject)=>()=>{
|
|
35
|
-
if (window.WhopElements) {
|
|
36
|
-
resolve(window.WhopElements);
|
|
37
|
-
} else {
|
|
38
|
-
reject(new Error("WhopElements not available"));
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const loadScript = ()=>{
|
|
42
|
-
if (whopElementsPromise !== null) {
|
|
43
|
-
return whopElementsPromise;
|
|
44
|
-
}
|
|
45
|
-
whopElementsPromise = new Promise((resolve, reject)=>{
|
|
46
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
47
|
-
resolve(null);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (window.WhopElements) {
|
|
51
|
-
resolve(window.WhopElements);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
let script = findScript();
|
|
56
|
-
if (!script) {
|
|
57
|
-
script = injectScript();
|
|
58
|
-
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
59
|
-
script.removeEventListener("load", onLoadListener);
|
|
60
|
-
script.removeEventListener("error", onErrorListener);
|
|
61
|
-
script.parentNode?.removeChild(script);
|
|
62
|
-
script = injectScript();
|
|
63
|
-
}
|
|
64
|
-
onLoadListener = onLoad(resolve, reject);
|
|
65
|
-
onErrorListener = onError(reject);
|
|
66
|
-
script.addEventListener("load", onLoadListener);
|
|
67
|
-
script.addEventListener("error", onErrorListener);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
if (error instanceof Error) {
|
|
70
|
-
reject(error);
|
|
71
|
-
} else {
|
|
72
|
-
reject(new Error("Failed to load WhopElements", {
|
|
73
|
-
cause: error
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return whopElementsPromise.catch((error)=>{
|
|
80
|
-
whopElementsPromise = null;
|
|
81
|
-
if (error instanceof Error) {
|
|
82
|
-
return Promise.reject(error);
|
|
83
|
-
} else {
|
|
84
|
-
return Promise.reject(new Error("Failed to load WhopElements", {
|
|
85
|
-
cause: error
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const initWhopElements = (maybeWhopElements, args)=>{
|
|
91
|
-
if (maybeWhopElements === null) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
const WhopElements = maybeWhopElements;
|
|
95
|
-
return new WhopElements(...args);
|
|
96
|
-
};
|
|
97
|
-
export { findScript, initWhopElements, loadScript };
|
package/dist/util.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/util.ts"],"sourcesContent":["import type { WhopElements, WhopElementsConstructor } from \"./types\";\nimport { ORIGIN, SCRIPT_URL } from \"./url\";\n\nexport type LoadWhopElements = (\n\t...args: ConstructorParameters<WhopElementsConstructor>\n) => Promise<WhopElements | null>;\n\nconst isWhopElementsScriptURL = (url: string): boolean => {\n\tconst result = url.startsWith(ORIGIN) && url.endsWith(\"/elements.js\");\n\treturn result;\n};\n\nexport const findScript = (): HTMLScriptElement | null => {\n\tconst scripts = document.querySelectorAll<HTMLScriptElement>(\n\t\t`script[src^=\"${ORIGIN}\"]`,\n\t);\n\n\tfor (const script of scripts) {\n\t\tif (!script || !isWhopElementsScriptURL(script.src)) {\n\t\t\tcontinue;\n\t\t}\n\t\treturn script;\n\t}\n\treturn null;\n};\n\nconst injectScript = (): HTMLScriptElement => {\n\tconst script = document.createElement(\"script\");\n\tscript.src = SCRIPT_URL;\n\n\tconst headOrBody = document.head || document.body;\n\n\tif (!headOrBody) {\n\t\tthrow new Error(\n\t\t\t\"Expected document.body not to be null. WhopElements requires a <body> element.\",\n\t\t);\n\t}\n\n\theadOrBody.appendChild(script);\n\n\treturn script;\n};\n\nlet whopElementsPromise: Promise<WhopElementsConstructor | null> | null = null;\n\nlet onErrorListener: ((cause?: unknown) => void) | null = null;\nlet onLoadListener: (() => void) | null = null;\n\nconst onError = (reject: (reason?: unknown) => void) => (cause?: unknown) => {\n\treject(new Error(\"Failed to load WhopElements\", { cause }));\n};\n\nconst onLoad =\n\t(\n\t\tresolve: (\n\t\t\tvalue:\n\t\t\t\t| WhopElementsConstructor\n\t\t\t\t| PromiseLike<WhopElementsConstructor | null>\n\t\t\t\t| null,\n\t\t) => void,\n\t\treject: (reason?: unknown) => void,\n\t) =>\n\t() => {\n\t\tif (window.WhopElements) {\n\t\t\tresolve(window.WhopElements);\n\t\t} else {\n\t\t\treject(new Error(\"WhopElements not available\"));\n\t\t}\n\t};\n\nexport const loadScript = (): Promise<WhopElementsConstructor | null> => {\n\tif (whopElementsPromise !== null) {\n\t\treturn whopElementsPromise;\n\t}\n\n\twhopElementsPromise = new Promise((resolve, reject) => {\n\t\tif (typeof window === \"undefined\" || typeof document === \"undefined\") {\n\t\t\tresolve(null);\n\t\t\treturn;\n\t\t}\n\n\t\tif (window.WhopElements) {\n\t\t\tresolve(window.WhopElements);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tlet script = findScript();\n\n\t\t\tif (!script) {\n\t\t\t\tscript = injectScript();\n\t\t\t} else if (\n\t\t\t\tscript &&\n\t\t\t\tonLoadListener !== null &&\n\t\t\t\tonErrorListener !== null\n\t\t\t) {\n\t\t\t\t// remove event listeners\n\t\t\t\tscript.removeEventListener(\"load\", onLoadListener);\n\t\t\t\tscript.removeEventListener(\"error\", onErrorListener);\n\n\t\t\t\t// if script exists, but we are reloading due to an error,\n\t\t\t\t// reload script to trigger 'load' event\n\t\t\t\tscript.parentNode?.removeChild(script);\n\t\t\t\tscript = injectScript();\n\t\t\t}\n\n\t\t\tonLoadListener = onLoad(resolve, reject);\n\t\t\tonErrorListener = onError(reject);\n\t\t\tscript.addEventListener(\"load\", onLoadListener);\n\t\t\tscript.addEventListener(\"error\", onErrorListener);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\treject(error);\n\t\t\t} else {\n\t\t\t\treject(new Error(\"Failed to load WhopElements\", { cause: error }));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t});\n\n\treturn whopElementsPromise.catch((error) => {\n\t\twhopElementsPromise = null;\n\t\tif (error instanceof Error) {\n\t\t\treturn Promise.reject(error);\n\t\t} else {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew Error(\"Failed to load WhopElements\", { cause: error }),\n\t\t\t);\n\t\t}\n\t});\n};\n\nexport const initWhopElements = (\n\tmaybeWhopElements: WhopElementsConstructor | null,\n\targs: ConstructorParameters<WhopElementsConstructor>,\n): WhopElements | null => {\n\tif (maybeWhopElements === null) {\n\t\treturn null;\n\t}\n\tconst WhopElements = maybeWhopElements;\n\n\treturn new WhopElements(...args);\n};\n"],"mappings":"AACA,SAAS,QAAQ,kBAAkB;AAMnC,MAAM,0BAA0B,CAAC,QAAyB;AACzD,QAAM,SAAS,IAAI,WAAW,MAAM,KAAK,IAAI,SAAS,cAAc;AACpE,SAAO;AACR;AAEO,MAAM,aAAa,MAAgC;AACzD,QAAM,UAAU,SAAS;AAAA,IACxB,gBAAgB,MAAM;AAAA,EACvB;AAEA,aAAW,UAAU,SAAS;AAC7B,QAAI,CAAC,UAAU,CAAC,wBAAwB,OAAO,GAAG,GAAG;AACpD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAEA,MAAM,eAAe,MAAyB;AAC7C,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AAEb,QAAM,aAAa,SAAS,QAAQ,SAAS;AAE7C,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,aAAW,YAAY,MAAM;AAE7B,SAAO;AACR;AAEA,IAAI,sBAAsE;AAE1E,IAAI,kBAAsD;AAC1D,IAAI,iBAAsC;AAE1C,MAAM,UAAU,CAAC,WAAuC,CAAC,UAAoB;AAC5E,SAAO,IAAI,MAAM,+BAA+B,EAAE,MAAM,CAAC,CAAC;AAC3D;AAEA,MAAM,SACL,CACC,SAMA,WAED,MAAM;AACL,MAAI,OAAO,cAAc;AACxB,YAAQ,OAAO,YAAY;AAAA,EAC5B,OAAO;AACN,WAAO,IAAI,MAAM,4BAA4B,CAAC;AAAA,EAC/C;AACD;AAEM,MAAM,aAAa,MAA+C;AACxE,MAAI,wBAAwB,MAAM;AACjC,WAAO;AAAA,EACR;AAEA,wBAAsB,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtD,QAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aAAa;AACrE,cAAQ,IAAI;AACZ;AAAA,IACD;AAEA,QAAI,OAAO,cAAc;AACxB,cAAQ,OAAO,YAAY;AAC3B;AAAA,IACD;AAEA,QAAI;AACH,UAAI,SAAS,WAAW;AAExB,UAAI,CAAC,QAAQ;AACZ,iBAAS,aAAa;AAAA,MACvB,WACC,UACA,mBAAmB,QACnB,oBAAoB,MACnB;AAED,eAAO,oBAAoB,QAAQ,cAAc;AACjD,eAAO,oBAAoB,SAAS,eAAe;AAInD,eAAO,YAAY,YAAY,MAAM;AACrC,iBAAS,aAAa;AAAA,MACvB;AAEA,uBAAiB,OAAO,SAAS,MAAM;AACvC,wBAAkB,QAAQ,MAAM;AAChC,aAAO,iBAAiB,QAAQ,cAAc;AAC9C,aAAO,iBAAiB,SAAS,eAAe;AAAA,IACjD,SAAS,OAAO;AACf,UAAI,iBAAiB,OAAO;AAC3B,eAAO,KAAK;AAAA,MACb,OAAO;AACN,eAAO,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC,CAAC;AAAA,MAClE;AACA;AAAA,IACD;AAAA,EACD,CAAC;AAED,SAAO,oBAAoB,MAAM,CAAC,UAAU;AAC3C,0BAAsB;AACtB,QAAI,iBAAiB,OAAO;AAC3B,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC5B,OAAO;AACN,aAAO,QAAQ;AAAA,QACd,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAEO,MAAM,mBAAmB,CAC/B,mBACA,SACyB;AACzB,MAAI,sBAAsB,MAAM;AAC/B,WAAO;AAAA,EACR;AACA,QAAM,eAAe;AAErB,SAAO,IAAI,aAAa,GAAG,IAAI;AAChC;","names":[]}
|