@adyen/adyen-document-viewer
Version:
Adyen Document Viewer
941 lines (940 loc) • 33.6 kB
JavaScript
var G, d, xe, E, le, $e, X, Ce, D = {}, Se = [], Ye = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, re = Array.isArray;
function C(e, t) {
for (var n in t)
e[n] = t[n];
return e;
}
function Ee(e) {
var t = e.parentNode;
t && t.removeChild(e);
}
function Pe(e, t, n) {
var o, _, r, c = {};
for (r in t)
r == "key" ? o = t[r] : r == "ref" ? _ = t[r] : c[r] = t[r];
if (arguments.length > 2 && (c.children = arguments.length > 3 ? G.call(arguments, 2) : n), typeof e == "function" && e.defaultProps != null)
for (r in e.defaultProps)
c[r] === void 0 && (c[r] = e.defaultProps[r]);
return M(e, c, o, _, null);
}
function M(e, t, n, o, _) {
var r = { type: e, props: t, key: n, ref: o, __k: null, __: null, __b: 0, __e: null, __d: void 0, __c: null, constructor: void 0, __v: _ ?? ++xe, __i: -1, __u: 0 };
return _ == null && d.vnode != null && d.vnode(r), r;
}
function Y(e) {
return e.children;
}
function W(e, t) {
this.props = e, this.context = t;
}
function L(e, t) {
if (t == null)
return e.__ ? L(e.__, e.__i + 1) : null;
for (var n; t < e.__k.length; t++)
if ((n = e.__k[t]) != null && n.__e != null)
return n.__e;
return typeof e.type == "function" ? L(e) : null;
}
function He(e) {
var t, n;
if ((e = e.__) != null && e.__c != null) {
for (e.__e = e.__c.base = null, t = 0; t < e.__k.length; t++)
if ((n = e.__k[t]) != null && n.__e != null) {
e.__e = e.__c.base = n.__e;
break;
}
return He(e);
}
}
function Z(e) {
(!e.__d && (e.__d = !0) && E.push(e) && !q.__r++ || le !== d.debounceRendering) && ((le = d.debounceRendering) || $e)(q);
}
function q() {
var e, t, n, o, _, r, c, s, a;
for (E.sort(X); e = E.shift(); )
e.__d && (t = E.length, o = void 0, r = (_ = (n = e).__v).__e, s = [], a = [], (c = n.__P) && ((o = C({}, _)).__v = _.__v + 1, d.vnode && d.vnode(o), _e(c, o, _, n.__n, c.ownerSVGElement !== void 0, 32 & _.__u ? [r] : null, s, r ?? L(_), !!(32 & _.__u), a), o.__.__k[o.__i] = o, Te(s, o, a), o.__e != r && He(o)), E.length > t && E.sort(X));
q.__r = 0;
}
function Le(e, t, n, o, _, r, c, s, a, l, p) {
var i, h, f, v, w, b = o && o.__k || Se, m = t.length;
for (n.__d = a, Ke(n, t, b), a = n.__d, i = 0; i < m; i++)
(f = n.__k[i]) != null && typeof f != "boolean" && typeof f != "function" && (h = f.__i === -1 ? D : b[f.__i] || D, f.__i = i, _e(e, f, h, _, r, c, s, a, l, p), v = f.__e, f.ref && h.ref != f.ref && (h.ref && ie(h.ref, null, f), p.push(f.ref, f.__c || v, f)), w == null && v != null && (w = v), 65536 & f.__u || h.__k === f.__k ? a = Ie(f, a, e) : typeof f.type == "function" && f.__d !== void 0 ? a = f.__d : v && (a = v.nextSibling), f.__d = void 0, f.__u &= -196609);
n.__d = a, n.__e = w;
}
function Ke(e, t, n) {
var o, _, r, c, s, a = t.length, l = n.length, p = l, i = 0;
for (e.__k = [], o = 0; o < a; o++)
(_ = e.__k[o] = (_ = t[o]) == null || typeof _ == "boolean" || typeof _ == "function" ? null : typeof _ == "string" || typeof _ == "number" || typeof _ == "bigint" || _.constructor == String ? M(null, _, null, null, _) : re(_) ? M(Y, { children: _ }, null, null, null) : _.constructor === void 0 && _.__b > 0 ? M(_.type, _.props, _.key, _.ref ? _.ref : null, _.__v) : _) != null ? (_.__ = e, _.__b = e.__b + 1, s = Je(_, n, c = o + i, p), _.__i = s, r = null, s !== -1 && (p--, (r = n[s]) && (r.__u |= 131072)), r == null || r.__v === null ? (s == -1 && i--, typeof _.type != "function" && (_.__u |= 65536)) : s !== c && (s === c + 1 ? i++ : s > c ? p > a - c ? i += s - c : i-- : i = s < c && s == c - 1 ? s - c : 0, s !== o + i && (_.__u |= 65536))) : (r = n[o]) && r.key == null && r.__e && (r.__e == e.__d && (e.__d = L(r)), ee(r, r, !1), n[o] = null, p--);
if (p)
for (o = 0; o < l; o++)
(r = n[o]) != null && !(131072 & r.__u) && (r.__e == e.__d && (e.__d = L(r)), ee(r, r));
}
function Ie(e, t, n) {
var o, _;
if (typeof e.type == "function") {
for (o = e.__k, _ = 0; o && _ < o.length; _++)
o[_] && (o[_].__ = e, t = Ie(o[_], t, n));
return t;
}
return e.__e != t && (n.insertBefore(e.__e, t || null), t = e.__e), t && t.nextSibling;
}
function Je(e, t, n, o) {
var _ = e.key, r = e.type, c = n - 1, s = n + 1, a = t[n];
if (a === null || a && _ == a.key && r === a.type)
return n;
if (o > (a != null && !(131072 & a.__u) ? 1 : 0))
for (; c >= 0 || s < t.length; ) {
if (c >= 0) {
if ((a = t[c]) && !(131072 & a.__u) && _ == a.key && r === a.type)
return c;
c--;
}
if (s < t.length) {
if ((a = t[s]) && !(131072 & a.__u) && _ == a.key && r === a.type)
return s;
s++;
}
}
return -1;
}
function ae(e, t, n) {
t[0] === "-" ? e.setProperty(t, n ?? "") : e[t] = n == null ? "" : typeof n != "number" || Ye.test(t) ? n : n + "px";
}
function V(e, t, n, o, _) {
var r;
e:
if (t === "style")
if (typeof n == "string")
e.style.cssText = n;
else {
if (typeof o == "string" && (e.style.cssText = o = ""), o)
for (t in o)
n && t in n || ae(e.style, t, "");
if (n)
for (t in n)
o && n[t] === o[t] || ae(e.style, t, n[t]);
}
else if (t[0] === "o" && t[1] === "n")
r = t !== (t = t.replace(/(PointerCapture)$|Capture$/, "$1")), t = t.toLowerCase() in e ? t.toLowerCase().slice(2) : t.slice(2), e.l || (e.l = {}), e.l[t + r] = n, n ? o ? n.u = o.u : (n.u = Date.now(), e.addEventListener(t, r ? fe : ue, r)) : e.removeEventListener(t, r ? fe : ue, r);
else {
if (_)
t = t.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
else if (t !== "width" && t !== "height" && t !== "href" && t !== "list" && t !== "form" && t !== "tabIndex" && t !== "download" && t !== "rowSpan" && t !== "colSpan" && t !== "role" && t in e)
try {
e[t] = n ?? "";
break e;
} catch {
}
typeof n == "function" || (n == null || n === !1 && t[4] !== "-" ? e.removeAttribute(t) : e.setAttribute(t, n));
}
}
function ue(e) {
var t = this.l[e.type + !1];
if (e.t) {
if (e.t <= t.u)
return;
} else
e.t = Date.now();
return t(d.event ? d.event(e) : e);
}
function fe(e) {
return this.l[e.type + !0](d.event ? d.event(e) : e);
}
function _e(e, t, n, o, _, r, c, s, a, l) {
var p, i, h, f, v, w, b, m, g, $, R, A, se, U, J, k = t.type;
if (t.constructor !== void 0)
return null;
128 & n.__u && (a = !!(32 & n.__u), r = [s = t.__e = n.__e]), (p = d.__b) && p(t);
e:
if (typeof k == "function")
try {
if (m = t.props, g = (p = k.contextType) && o[p.__c], $ = p ? g ? g.props.value : p.__ : o, n.__c ? b = (i = t.__c = n.__c).__ = i.__E : ("prototype" in k && k.prototype.render ? t.__c = i = new k(m, $) : (t.__c = i = new W(m, $), i.constructor = k, i.render = Xe), g && g.sub(i), i.props = m, i.state || (i.state = {}), i.context = $, i.__n = o, h = i.__d = !0, i.__h = [], i._sb = []), i.__s == null && (i.__s = i.state), k.getDerivedStateFromProps != null && (i.__s == i.state && (i.__s = C({}, i.__s)), C(i.__s, k.getDerivedStateFromProps(m, i.__s))), f = i.props, v = i.state, i.__v = t, h)
k.getDerivedStateFromProps == null && i.componentWillMount != null && i.componentWillMount(), i.componentDidMount != null && i.__h.push(i.componentDidMount);
else {
if (k.getDerivedStateFromProps == null && m !== f && i.componentWillReceiveProps != null && i.componentWillReceiveProps(m, $), !i.__e && (i.shouldComponentUpdate != null && i.shouldComponentUpdate(m, i.__s, $) === !1 || t.__v === n.__v)) {
for (t.__v !== n.__v && (i.props = m, i.state = i.__s, i.__d = !1), t.__e = n.__e, t.__k = n.__k, t.__k.forEach(function(O) {
O && (O.__ = t);
}), R = 0; R < i._sb.length; R++)
i.__h.push(i._sb[R]);
i._sb = [], i.__h.length && c.push(i);
break e;
}
i.componentWillUpdate != null && i.componentWillUpdate(m, i.__s, $), i.componentDidUpdate != null && i.__h.push(function() {
i.componentDidUpdate(f, v, w);
});
}
if (i.context = $, i.props = m, i.__P = e, i.__e = !1, A = d.__r, se = 0, "prototype" in k && k.prototype.render) {
for (i.state = i.__s, i.__d = !1, A && A(t), p = i.render(i.props, i.state, i.context), U = 0; U < i._sb.length; U++)
i.__h.push(i._sb[U]);
i._sb = [];
} else
do
i.__d = !1, A && A(t), p = i.render(i.props, i.state, i.context), i.state = i.__s;
while (i.__d && ++se < 25);
i.state = i.__s, i.getChildContext != null && (o = C(C({}, o), i.getChildContext())), h || i.getSnapshotBeforeUpdate == null || (w = i.getSnapshotBeforeUpdate(f, v)), Le(e, re(J = p != null && p.type === Y && p.key == null ? p.props.children : p) ? J : [J], t, n, o, _, r, c, s, a, l), i.base = t.__e, t.__u &= -161, i.__h.length && c.push(i), b && (i.__E = i.__ = null);
} catch (O) {
t.__v = null, a || r != null ? (t.__e = s, t.__u |= a ? 160 : 32, r[r.indexOf(s)] = null) : (t.__e = n.__e, t.__k = n.__k), d.__e(O, t, n);
}
else
r == null && t.__v === n.__v ? (t.__k = n.__k, t.__e = n.__e) : t.__e = Qe(n.__e, t, n, o, _, r, c, a, l);
(p = d.diffed) && p(t);
}
function Te(e, t, n) {
t.__d = void 0;
for (var o = 0; o < n.length; o++)
ie(n[o], n[++o], n[++o]);
d.__c && d.__c(t, e), e.some(function(_) {
try {
e = _.__h, _.__h = [], e.some(function(r) {
r.call(_);
});
} catch (r) {
d.__e(r, _.__v);
}
});
}
function Qe(e, t, n, o, _, r, c, s, a) {
var l, p, i, h, f, v, w, b = n.props, m = t.props, g = t.type;
if (g === "svg" && (_ = !0), r != null) {
for (l = 0; l < r.length; l++)
if ((f = r[l]) && "setAttribute" in f == !!g && (g ? f.localName === g : f.nodeType === 3)) {
e = f, r[l] = null;
break;
}
}
if (e == null) {
if (g === null)
return document.createTextNode(m);
e = _ ? document.createElementNS("http://www.w3.org/2000/svg", g) : document.createElement(g, m.is && m), r = null, s = !1;
}
if (g === null)
b === m || s && e.data === m || (e.data = m);
else {
if (r = r && G.call(e.childNodes), b = n.props || D, !s && r != null)
for (b = {}, l = 0; l < e.attributes.length; l++)
b[(f = e.attributes[l]).name] = f.value;
for (l in b)
f = b[l], l == "children" || (l == "dangerouslySetInnerHTML" ? i = f : l === "key" || l in m || V(e, l, null, f, _));
for (l in m)
f = m[l], l == "children" ? h = f : l == "dangerouslySetInnerHTML" ? p = f : l == "value" ? v = f : l == "checked" ? w = f : l === "key" || s && typeof f != "function" || b[l] === f || V(e, l, f, b[l], _);
if (p)
s || i && (p.__html === i.__html || p.__html === e.innerHTML) || (e.innerHTML = p.__html), t.__k = [];
else if (i && (e.innerHTML = ""), Le(e, re(h) ? h : [h], t, n, o, _ && g !== "foreignObject", r, c, r ? r[0] : n.__k && L(n, 0), s, a), r != null)
for (l = r.length; l--; )
r[l] != null && Ee(r[l]);
s || (l = "value", v !== void 0 && (v !== e[l] || g === "progress" && !v || g === "option" && v !== b[l]) && V(e, l, v, b[l], !1), l = "checked", w !== void 0 && w !== e[l] && V(e, l, w, b[l], !1));
}
return e;
}
function ie(e, t, n) {
try {
typeof e == "function" ? e(t) : e.current = t;
} catch (o) {
d.__e(o, n);
}
}
function ee(e, t, n) {
var o, _;
if (d.unmount && d.unmount(e), (o = e.ref) && (o.current && o.current !== e.__e || ie(o, null, t)), (o = e.__c) != null) {
if (o.componentWillUnmount)
try {
o.componentWillUnmount();
} catch (r) {
d.__e(r, t);
}
o.base = o.__P = null, e.__c = void 0;
}
if (o = e.__k)
for (_ = 0; _ < o.length; _++)
o[_] && ee(o[_], t, n || typeof e.type != "function");
n || e.__e == null || Ee(e.__e), e.__ = e.__e = e.__d = void 0;
}
function Xe(e, t, n) {
return this.constructor(e, n);
}
function Ze(e, t, n) {
var o, _, r, c;
d.__ && d.__(e, t), _ = (o = typeof n == "function") ? null : n && n.__k || t.__k, r = [], c = [], _e(t, e = (!o && n || t).__k = Pe(Y, null, [e]), _ || D, D, t.ownerSVGElement !== void 0, !o && n ? [n] : _ ? null : t.firstChild ? G.call(t.childNodes) : null, r, !o && n ? n : _ ? _.__e : t.firstChild, o, c), Te(r, e, c);
}
function Ae(e, t) {
var n = { __c: t = "__cC" + Ce++, __: e, Consumer: function(o, _) {
return o.children(_);
}, Provider: function(o) {
var _, r;
return this.getChildContext || (_ = [], (r = {})[t] = this, this.getChildContext = function() {
return r;
}, this.shouldComponentUpdate = function(c) {
this.props.value !== c.value && _.some(function(s) {
s.__e = !0, Z(s);
});
}, this.sub = function(c) {
_.push(c);
var s = c.componentWillUnmount;
c.componentWillUnmount = function() {
_.splice(_.indexOf(c), 1), s && s.call(c);
};
}), o.children;
} };
return n.Provider.__ = n.Consumer.contextType = n;
}
G = Se.slice, d = { __e: function(e, t, n, o) {
for (var _, r, c; t = t.__; )
if ((_ = t.__c) && !_.__)
try {
if ((r = _.constructor) && r.getDerivedStateFromError != null && (_.setState(r.getDerivedStateFromError(e)), c = _.__d), _.componentDidCatch != null && (_.componentDidCatch(e, o || {}), c = _.__d), c)
return _.__E = _;
} catch (s) {
e = s;
}
throw e;
} }, xe = 0, W.prototype.setState = function(e, t) {
var n;
n = this.__s != null && this.__s !== this.state ? this.__s : this.__s = C({}, this.state), typeof e == "function" && (e = e(C({}, n), this.props)), e && C(n, e), e != null && this.__v && (t && this._sb.push(t), Z(this));
}, W.prototype.forceUpdate = function(e) {
this.__v && (this.__e = !0, e && this.__h.push(e), Z(this));
}, W.prototype.render = Y, E = [], $e = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, X = function(e, t) {
return e.__v.__b - t.__v.__b;
}, q.__r = 0, Ce = 0;
var et = 0;
function u(e, t, n, o, _, r) {
var c, s, a = {};
for (s in t)
s == "ref" ? c = t[s] : a[s] = t[s];
var l = { type: e, props: a, key: n, ref: c, __k: null, __: null, __b: 0, __e: null, __d: void 0, __c: null, constructor: void 0, __v: --et, __i: -1, __u: 0, __source: _, __self: r };
if (typeof e == "function" && (c = e.defaultProps))
for (s in c)
a[s] === void 0 && (a[s] = c[s]);
return d.vnode && d.vnode(l), l;
}
function tt(e) {
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
var De = { exports: {} };
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
(function(e) {
(function() {
var t = {}.hasOwnProperty;
function n() {
for (var r = "", c = 0; c < arguments.length; c++) {
var s = arguments[c];
s && (r = _(r, o(s)));
}
return r;
}
function o(r) {
if (typeof r == "string" || typeof r == "number")
return r;
if (typeof r != "object")
return "";
if (Array.isArray(r))
return n.apply(null, r);
if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
return r.toString();
var c = "";
for (var s in r)
t.call(r, s) && r[s] && (c = _(c, s));
return c;
}
function _(r, c) {
return c ? r ? r + " " + c : r + c : r;
}
e.exports ? (n.default = n, e.exports = n) : window.classNames = n;
})();
})(De);
var nt = De.exports;
const x = /* @__PURE__ */ tt(nt);
var N = /* @__PURE__ */ ((e) => (e.Chapter = "chapter", e.Section = "section", e.Paragraph = "paragraph", e.Text = "text", e.Weblink = "weblink", e.List = "list", e.Table = "table", e.InternalReference = "internalReference", e))(N || {}), te = /* @__PURE__ */ ((e) => (e.Bold = "BOLD", e.Italic = "ITALIC", e))(te || {});
let de = Date.now();
const Re = (e = "id") => (de += 1, `${e}-${de}`);
var I, y, Q, pe, z = 0, Ue = [], F = [], he = d.__b, ve = d.__r, me = d.diffed, ye = d.__c, be = d.unmount;
function K(e, t) {
d.__h && d.__h(y, e, z || t), z = 0;
var n = y.__H || (y.__H = { __: [], __h: [] });
return e >= n.__.length && n.__.push({ __V: F }), n.__[e];
}
function T(e) {
return z = 1, ot(We, e);
}
function ot(e, t, n) {
var o = K(I++, 2);
if (o.t = e, !o.__c && (o.__ = [n ? n(t) : We(void 0, t), function(s) {
var a = o.__N ? o.__N[0] : o.__[0], l = o.t(a, s);
a !== l && (o.__N = [l, o.__[1]], o.__c.setState({}));
}], o.__c = y, !y.u)) {
var _ = function(s, a, l) {
if (!o.__c.__H)
return !0;
var p = o.__c.__H.__.filter(function(h) {
return h.__c;
});
if (p.every(function(h) {
return !h.__N;
}))
return !r || r.call(this, s, a, l);
var i = !1;
return p.forEach(function(h) {
if (h.__N) {
var f = h.__[0];
h.__ = h.__N, h.__N = void 0, f !== h.__[0] && (i = !0);
}
}), !(!i && o.__c.props === s) && (!r || r.call(this, s, a, l));
};
y.u = !0;
var r = y.shouldComponentUpdate, c = y.componentWillUpdate;
y.componentWillUpdate = function(s, a, l) {
if (this.__e) {
var p = r;
r = void 0, _(s, a, l), r = p;
}
c && c.call(this, s, a, l);
}, y.shouldComponentUpdate = _;
}
return o.__N || o.__;
}
function H(e, t) {
var n = K(I++, 3);
!d.__s && Me(n.__H, t) && (n.__ = e, n.i = t, y.__H.__h.push(n));
}
function rt(e) {
return z = 5, Oe(function() {
return { current: e };
}, []);
}
function Oe(e, t) {
var n = K(I++, 7);
return Me(n.__H, t) ? (n.__V = e(), n.i = t, n.__h = e, n.__V) : n.__;
}
function Ve(e) {
var t = y.context[e.__c], n = K(I++, 9);
return n.c = e, t ? (n.__ == null && (n.__ = !0, t.sub(y)), t.props.value) : e.__;
}
function _t() {
for (var e; e = Ue.shift(); )
if (e.__P && e.__H)
try {
e.__H.__h.forEach(B), e.__H.__h.forEach(ne), e.__H.__h = [];
} catch (t) {
e.__H.__h = [], d.__e(t, e.__v);
}
}
d.__b = function(e) {
y = null, he && he(e);
}, d.__r = function(e) {
ve && ve(e), I = 0;
var t = (y = e.__c).__H;
t && (Q === y ? (t.__h = [], y.__h = [], t.__.forEach(function(n) {
n.__N && (n.__ = n.__N), n.__V = F, n.__N = n.i = void 0;
})) : (t.__h.forEach(B), t.__h.forEach(ne), t.__h = [], I = 0)), Q = y;
}, d.diffed = function(e) {
me && me(e);
var t = e.__c;
t && t.__H && (t.__H.__h.length && (Ue.push(t) !== 1 && pe === d.requestAnimationFrame || ((pe = d.requestAnimationFrame) || it)(_t)), t.__H.__.forEach(function(n) {
n.i && (n.__H = n.i), n.__V !== F && (n.__ = n.__V), n.i = void 0, n.__V = F;
})), Q = y = null;
}, d.__c = function(e, t) {
t.some(function(n) {
try {
n.__h.forEach(B), n.__h = n.__h.filter(function(o) {
return !o.__ || ne(o);
});
} catch (o) {
t.some(function(_) {
_.__h && (_.__h = []);
}), t = [], d.__e(o, n.__v);
}
}), ye && ye(e, t);
}, d.unmount = function(e) {
be && be(e);
var t, n = e.__c;
n && n.__H && (n.__H.__.forEach(function(o) {
try {
B(o);
} catch (_) {
t = _;
}
}), n.__H = void 0, t && d.__e(t, n.__v));
};
var ge = typeof requestAnimationFrame == "function";
function it(e) {
var t, n = function() {
clearTimeout(o), ge && cancelAnimationFrame(t), setTimeout(e);
}, o = setTimeout(n, 100);
ge && (t = requestAnimationFrame(n));
}
function B(e) {
var t = y, n = e.__c;
typeof n == "function" && (e.__c = void 0, n()), y = t;
}
function ne(e) {
var t = y;
e.__c = e.__(), y = t;
}
function Me(e, t) {
return !e || e.length !== t.length || t.some(function(n, o) {
return n !== e[o];
});
}
function We(e, t) {
return typeof t == "function" ? t(e) : t;
}
const Fe = Ae(null);
function ct({
children: e,
className: t,
expand: n = !1,
type: o,
onExpandSection: _
}) {
const [r, c] = T([]), s = x("adv-accordion", t, {
"adv-accordion--container": o === "container"
});
return /* @__PURE__ */ u(Fe.Provider, { value: { expand: n, items: r, setItems: c, onExpandSection: _ }, children: /* @__PURE__ */ u("div", { className: s, children: e }) });
}
const we = {
1: "h1",
2: "h2"
};
function ce({ className: e, level: t, children: n }) {
const o = we[t] || we[1], _ = x("adv-heading", `adv-heading--${t}`, e);
return Pe(o, { className: _ }, n);
}
function P({ content: e, styles: t }) {
const n = x({
"adv-u-font-weight-semi-bold": t == null ? void 0 : t.includes(te.Bold),
"adv-u-font-italic": t == null ? void 0 : t.includes(te.Italic)
});
return /* @__PURE__ */ u("span", { className: n, children: e });
}
function st({ title: e, contentElements: t }) {
return /* @__PURE__ */ u("section", { className: "adv-u-margin-bottom-48", children: [
/* @__PURE__ */ u(ce, { level: 2, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ u(P, { content: e.content, styles: e.styles }) }),
/* @__PURE__ */ u(S, { contentElements: t, isTopLevel: !0 })
] });
}
const Be = Ae({
references: {},
addReference: () => {
}
});
function qe() {
const e = Ve(Be);
if (e === void 0)
throw new Error("useReferenceContext must be used within a ReferenceProvider");
return e;
}
const lt = (e) => new Promise((t) => {
setTimeout(t, e);
}), j = (e) => e ? `adyen-document-viewer-${e.replace(/[^\w-]/g, "").slice(0, 32)}` : void 0, ze = (e) => {
if (!e)
return null;
const t = e instanceof HTMLElement, n = t && window.getComputedStyle(e).overflowY;
return t && (n !== "visible" && n !== "hidden") ? e : ze(e.parentNode) ?? document.body;
};
const at = ({ onClick: e, label: t }) => /* @__PURE__ */ u("button", { className: "adv-link", type: "button", onClick: e, title: t, children: t });
function ut({
referencedLabel: e,
displayText: t
}) {
const n = t ? t.content : e, o = j(e) ?? "", { references: _ } = qe();
return /* @__PURE__ */ u(at, { onClick: async () => {
_ && o && _[o] && (_[o].openSection(), await lt(150));
const c = ze(document.getElementById(o)), s = c == null ? void 0 : c.querySelector(`#${o}`);
s == null || s.scrollIntoView({ behavior: "smooth" });
}, label: n });
}
function ft({ className: e, nested: t, ordered: n, noMarkers: o, children: _ }) {
const r = x([
"adv-list",
t && "adv-list--nested",
n && "adv-list--ordered",
o && "adv-list--no-markers",
e
]);
return /* @__PURE__ */ u("ul", { className: r, children: _ });
}
function dt({ className: e, children: t, noMarkers: n }) {
const o = x(["adv-list__item", n && "adv-list__item--no-markers", e]);
return /* @__PURE__ */ u("li", { className: o, children: t });
}
function je({ items: e, style: t }) {
return /* @__PURE__ */ u(ft, { ordered: t.ordered, children: e.map((n, o) => /* @__PURE__ */ u(dt, { children: [
/* @__PURE__ */ u(S, { contentElements: n.content }),
n.subList && /* @__PURE__ */ u(je, { style: n.subList.style, items: n.subList.items })
] }, o)) });
}
function pt({ isTopLevel: e, contentElements: t }) {
const n = x("adv-paragraph", {
"adv-u-margin-bottom-16": e
});
return /* @__PURE__ */ u("p", { className: n, children: /* @__PURE__ */ u(S, { contentElements: t }) });
}
function ht({
children: e,
collapsed: t = !1
}) {
const n = rt(null), [o, _] = T(t ? 0 : void 0);
return H(() => {
var r;
_(t ? 0 : (r = n.current) == null ? void 0 : r.scrollHeight);
}, [t]), /* @__PURE__ */ u(
"div",
{
className: "adv-collapsible-container",
"aria-hidden": t,
ref: n,
style: { height: o },
children: e
}
);
}
const vt = ({ className: e = "", name: t }) => {
const n = {
"chevron-up": /* @__PURE__ */ u("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 15 15", width: "15", height: "15", children: /* @__PURE__ */ u(
"path",
{
fillRule: "evenodd",
d: "M13 10a1 1 0 0 1-1.743.669L7.5 6.495 3.743 10.67a1 1 0 0 1-1.486-1.338l4.5-5a1 1 0 0 1 1.486 0l4.5 5a.998.998 0 0 1 .257.67z"
}
) }),
"chevron-down": /* @__PURE__ */ u("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 15 15", width: "15", height: "15", children: /* @__PURE__ */ u(
"path",
{
fillRule: "evenodd",
d: "M2 5a1 1 0 0 1 1.743-.669L7.5 8.505l3.757-4.174a1 1 0 0 1 1.486 1.338l-4.5 5a1 1 0 0 1-1.486 0l-4.5-5A.998.998 0 0 1 2 4.999z"
}
) })
};
return /* @__PURE__ */ u("i", { className: x("adv-icon", e), role: "img", "aria-hidden": !0, children: n[t] });
};
function mt() {
return Ve(Fe);
}
function yt({
children: e,
open: t = !1,
title: n = "",
onOpen: o = () => {
},
onClose: _ = () => {
}
}) {
const { expand: r, items: c, setItems: s, onExpandSection: a } = mt(), [l, p] = T(t), [i] = T(Re), h = () => {
const f = !l, v = [...c];
r ? (v.find((w) => w.id === i).isOpen = f, s(v)) : s(v.map((w) => ({ ...w, isOpen: w.id === i ? f : !1 })));
};
return H(() => {
s((f) => [...f, { id: i, isOpen: l }]);
}, []), H(() => {
p(t);
}, [t]), H(() => {
var f;
p(((f = c.find((v) => v.id === i)) == null ? void 0 : f.isOpen) ?? !1);
}, [c]), H(() => {
l ? (a == null || a(n), o()) : _();
}, [l]), /* @__PURE__ */ u("div", { className: "adv-accordion__item", children: [
/* @__PURE__ */ u("div", { role: "button", className: "adv-accordion__header", tabIndex: 0, onClick: h, children: [
/* @__PURE__ */ u(vt, { name: l ? "chevron-up" : "chevron-down", className: "adv-accordion__toggle" }),
/* @__PURE__ */ u("div", { className: "adv-accordion__title-wrapper", children: /* @__PURE__ */ u("div", { className: "adv-accordion__title", children: n }) })
] }),
/* @__PURE__ */ u(ht, { collapsed: !l, children: /* @__PURE__ */ u("div", { className: "adv-accordion__content", children: e }) })
] });
}
const Ge = (e) => {
if (typeof e != "object" || e === null)
return [];
const t = [];
"label" in e && typeof e.label == "string" && e.label !== "" && t.push(e.label);
for (const n in e) {
const o = e[n];
(Array.isArray(o) || typeof o == "object" && o !== null) && t.push(...Ge(o));
}
return t;
};
function bt({
title: e,
label: t,
isTopLevel: n,
contentElements: o
}) {
const [_, r] = T(!1), { addReference: c } = qe(), s = j(t);
return H(() => {
if (n) {
const a = Ge(o).map(j);
s && a.push(s), a.length && a.forEach((l) => {
c({ [l]: { openSection: () => r(!0) } });
});
}
}, []), n ? /* @__PURE__ */ u(
yt,
{
title: e.content,
open: _,
onOpen: () => {
r(!0);
},
onClose: () => {
r(!1);
},
children: /* @__PURE__ */ u("section", { className: "adv-section-box", id: s, children: /* @__PURE__ */ u(S, { contentElements: o }) })
}
) : /* @__PURE__ */ u("section", { id: s, children: [
/* @__PURE__ */ u(ce, { level: 2, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ u(P, { content: e.content, styles: e.styles }) }),
/* @__PURE__ */ u(S, { contentElements: o })
] });
}
function gt({
rows: e,
label: t,
captions: n,
titlePrefix: o,
title: _
}) {
const r = j(t);
return /* @__PURE__ */ u("div", { id: r, children: [
/* @__PURE__ */ u("div", { className: "adv-u-margin-y-8 adv-u-text-align-center", children: [
o && /* @__PURE__ */ u(P, { ...o }),
o && _ && " ",
_ && /* @__PURE__ */ u(P, { ..._ })
] }),
/* @__PURE__ */ u("table", { className: "adv-table adv-table--condensed", children: [
n && /* @__PURE__ */ u("caption", { children: /* @__PURE__ */ u(S, { contentElements: n }) }),
/* @__PURE__ */ u("tbody", { className: "adv-table__body", children: e.map((c, s) => /* @__PURE__ */ u("tr", { className: "adv-table__row", children: c.map((a, l) => /* @__PURE__ */ u("td", { className: "adv-table__cell", children: /* @__PURE__ */ u(S, { contentElements: a.elements }) }, l)) }, s)) })
] })
] });
}
const wt = ({
className: e,
children: t,
href: n,
underline: o,
inheritStyles: _,
onClick: r
}) => {
const c = x("adv-link", e, {
"adv-link--underline": o,
"adv-link--inherit": _
});
return /* @__PURE__ */ u(
"a",
{
href: n,
className: c,
target: "_blank",
rel: "noopener noreferrer",
onClick: r,
children: /* @__PURE__ */ u("span", { className: "adv-link__text", children: t })
}
);
}, kt = ({ url: e, displayText: t }) => /* @__PURE__ */ u(wt, { href: e, children: t ? /* @__PURE__ */ u(P, { ...t }) : e }), Nt = {
chapter: st,
section: bt,
paragraph: pt,
text: P,
weblink: kt,
list: je,
table: gt,
internalReference: ut,
breakline: "br"
}, xt = (e) => `key-${e}-${Re()}`, $t = (e, t) => {
if (!("type" in e))
return null;
switch (e.type) {
case N.Chapter:
return {
title: e.title,
contentElements: e.contentElements
};
case N.Section:
return {
isTopLevel: t,
title: e.title,
label: e.label,
contentElements: e.contentElements
};
case N.Paragraph:
return {
isTopLevel: t,
contentElements: e.contentElements
};
case N.Text:
return {
content: e.content,
styles: e.styles
};
case N.Weblink:
return {
url: e.url,
displayText: e.displayText
};
case N.List:
return {
items: e.items,
style: e.style
};
case N.Table:
return {
rows: e.rows,
label: e.label,
captions: e.captions,
titlePrefix: e.titlePrefix,
title: e.title
};
case N.InternalReference:
return {
referencedLabel: e.referencedLabel,
displayText: e.displayText
};
default:
return null;
}
};
function S({
contentElements: e,
isTopLevel: t = !1,
onExpandSection: n,
multiple: o
}) {
const _ = e.map((r) => {
if (!("type" in r))
return null;
const c = Nt[r.type];
return /* @__PURE__ */ u(c, { ...$t(r, t) }, xt(r.type));
});
return t ? /* @__PURE__ */ u(ct, { onExpandSection: n, expand: o, children: _ }) : /* @__PURE__ */ u("span", { children: _ });
}
function Ct({ children: e }) {
const [t, n] = T({}), o = Oe(
() => ({
addReference: (_) => {
n((r) => ({
...r,
..._
}));
},
references: t
}),
[t, n]
);
return /* @__PURE__ */ u(Be.Provider, { value: o, children: e });
}
function St({
document: e,
className: t,
onExpandSection: n,
multiple: o
}) {
const _ = x("adyen-document-viewer", t);
return /* @__PURE__ */ u(Ct, { children: /* @__PURE__ */ u("div", { className: _, children: [
/* @__PURE__ */ u(ce, { level: 1, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ u(P, { content: e.title.content, styles: e.title.styles }) }),
/* @__PURE__ */ u(
S,
{
contentElements: e.contentElements,
onExpandSection: n,
multiple: o,
isTopLevel: !0
}
)
] }) });
}
function ke(e) {
return "type" in e && e.type === N.Section;
}
function Ne(e) {
return "contentElements" in e && Array.isArray(e.contentElements);
}
function Et(e) {
return e.isTopLevel ? `${e.counter}` : `${e.prefix}${e.counter}`;
}
function Pt(e, t) {
return `${e} ${t}`;
}
function oe(e, t) {
if (ke(e)) {
const n = Et(t), o = {
...e,
title: {
...e.title,
content: Pt(n, e.title.content)
}
};
if (t.counter += 1, Ne(e)) {
let _ = 1;
o.contentElements = e.contentElements.map((r) => {
if (ke(r)) {
const c = {
prefix: `${n}.`,
counter: _,
isTopLevel: !1
};
return _ += 1, oe(r, c);
}
return r;
});
}
return o;
}
return Ne(e) ? {
...e,
contentElements: e.contentElements.map(
(n) => oe(n, t)
)
} : e;
}
function Ht(e) {
const t = { prefix: "", counter: 1, isTopLevel: !0 };
return {
...e,
contentElements: e.contentElements.map(
(n) => oe(n, t)
)
};
}
class Lt {
/**
* Initializes the library
* @param target - The target element (HTMLElement or querySelector string)
* @param options - Configuration options for AdyenDocumentViewer
*/
constructor(t, n = {}) {
if (typeof t == "object" && "nodeType" in t)
this.target = t;
else {
const o = window.document.querySelector(t);
if (o instanceof HTMLElement)
this.target = o;
else
throw new Error("Target element was not found");
}
this.options = {
onExpandSection: n.onExpandSection ?? void 0,
multiple: n.multiple ?? !1,
showSectionNumbering: n.showSectionNumbering ?? !1
};
}
/**
* Renders the document
* @param document - The JSON document
*/
render(t) {
const n = this.options.showSectionNumbering ? Ht(t) : t;
Ze(
/* @__PURE__ */ u(
St,
{
document: n,
onExpandSection: this.options.onExpandSection,
multiple: this.options.multiple
}
),
this.target
);
}
}
export {
Lt as default
};