@usersnap/browser
Version:
[](https://www.usersnap.com?utm_medium=referral&utm_source=npm&utm_campaign=npm_package)
34 lines (33 loc) • 1 kB
JavaScript
function u() {
return `usersnapCallback_${Math.random().toString().slice(2)}`;
}
function s(e, n, t) {
return new Promise((i, d) => {
const r = u();
if (e) {
const l = t ? `&n=${t}` : "", w = `https://widget.usersnap.com/${n}/load/${e}?onload=${r}${l}`;
if (!window[r]) {
window[r] = (p) => (delete window[r], i(p));
const o = document.createElement("script");
o.defer = !0, o.nonce = t, o.onerror = () => {
d("Failed to load the widget: Wrong API key or paused project");
}, o.src = w, document.head.appendChild(o);
}
}
});
}
const a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
async function m(e, n) {
if (!e)
throw new Error("Missing api key");
return a.has(e) || a.set(e, s(e, "global", n)), await a.get(e);
}
async function f(e, n) {
if (!e)
throw new Error("Missing api key");
return c.has(e) || c.set(e, s(e, "embed", n)), await c.get(e);
}
export {
f as loadEmbed,
m as loadSpace
};