UNPKG

onfido-sdk-ui

Version:

JavaScript SDK view layer for Onfido identity verification

83 lines (82 loc) 2.43 kB
var d = Object.defineProperty; var h = (i, t, e) => t in i ? d(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e; var o = (i, t, e) => (h(i, typeof t != "symbol" ? t + "" : t, e), e); class l { constructor() { this.eventListener = {}; } addEventListener(t, e) { return this.eventListener[t] = this.eventListener[t] || [], this.eventListener[t].push(e), this; } removeEventListener(t, e) { const n = this.eventListener[t]; if (n) { let s; for (; (s = n.indexOf(e)) !== -1; ) n.splice(s, 1); } } trigger(t, e) { (this.eventListener[t] || []).forEach((n) => { n == null || n(e); }); } } const v = "v14"; window.OnfidoDistribution = { name: "NPM" }; class c extends l { constructor() { super(...arguments); o(this, "_handle"); o(this, "_handleSetCallbacks", []); } _setHandle(e) { this._handle = e, this._handleSetCallbacks.forEach((n) => n(e)), this._handleSetCallbacks = [], Object.entries(this.eventListener).forEach(([n, s]) => { e.addEventListener(n, s); }), this.eventListener = {}; } addEventListener(e, n) { return this._handle ? (this._handle.addEventListener(e, n), this) : super.addEventListener(e, n); } removeEventListener(e, n) { if (this._handle) return this._handle.removeEventListener(e, n), this; super.removeEventListener(e, n); } async tearDown() { var e; if (this._handle) await ((e = this._handle) == null ? void 0 : e.tearDown()); else return this._handleSetCallbacks.push(() => { this.tearDown(); }), Promise.resolve(); } get version() { var e; return (e = this._handle) == null ? void 0 : e.version; } } const a = (i) => `v${(i || v).replace(/^v/, "")}`, r = { init(i) { const t = new c(); return import(/* webpackIgnore: true */ /* @vite-ignore */ i.sdkUrl || `https://sdk.onfido.com/${a(i.version)}/Onfido.js`).then((n) => { const { Onfido: s } = n; t._setHandle(s.init(i)); }).catch((n) => { var s; t.trigger("error", { error: n }), (s = i.onError) == null || s.call(i, n); }), t; } }; Object.defineProperty(r, "environment", { get: () => window == null ? void 0 : window.Onfido.environment, set: (i) => { window.Onfido = window.Onfido || {}, window.Onfido.environment = i; } }); const L = r; export { L as Onfido, a as prefixVersion };