nanopop.mjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*! NanoPop 2.4.2 MIT | https://github.com/Simonwep/nanopop */
  2. const N = "2.4.2", I = {
  3. variantFlipOrder: { start: "sme", middle: "mse", end: "ems" },
  4. positionFlipOrder: { top: "tbrl", right: "rltb", bottom: "btrl", left: "lrbt" },
  5. position: "bottom",
  6. margin: 8,
  7. padding: 0
  8. }, J = (n, i, m) => {
  9. const {
  10. container: r,
  11. arrow: a,
  12. margin: e,
  13. padding: l,
  14. position: V,
  15. variantFlipOrder: C,
  16. positionFlipOrder: M
  17. } = {
  18. container: document.documentElement.getBoundingClientRect(),
  19. ...I,
  20. ...m
  21. }, { left: F, top: K } = i.style;
  22. i.style.left = "0", i.style.top = "0";
  23. const t = n.getBoundingClientRect(), o = i.getBoundingClientRect(), P = {
  24. t: t.top - o.height - e,
  25. b: t.bottom + e,
  26. r: t.right + e,
  27. l: t.left - o.width - e
  28. }, R = {
  29. vs: t.left,
  30. vm: t.left + t.width / 2 - o.width / 2,
  31. ve: t.left + t.width - o.width,
  32. hs: t.top,
  33. hm: t.bottom - t.height / 2 - o.height / 2,
  34. he: t.bottom - o.height
  35. }, [$, E = "middle"] = V.split("-"), L = M[$], j = C[E], { top: y, left: x, bottom: B, right: O } = r;
  36. for (const c of L) {
  37. const s = c === "t" || c === "b";
  38. let p = P[c];
  39. const [d, g] = s ? ["top", "left"] : ["left", "top"], [u, v] = s ? [o.height, o.width] : [o.width, o.height], [z, T] = s ? [B, O] : [O, B], [H, k] = s ? [y, x] : [x, y];
  40. if (!(p < H || p + u + l > z))
  41. for (const b of j) {
  42. let f = R[(s ? "v" : "h") + b];
  43. if (!(f < k || f + v + l > T)) {
  44. if (f -= o[g], p -= o[d], i.style[g] = `${f}px`, i.style[d] = `${p}px`, a) {
  45. const w = s ? t.width / 2 : t.height / 2, h = v / 2, S = w > h, q = {
  46. s: S ? h : w,
  47. m: h,
  48. e: S ? h : v - w
  49. }, A = {
  50. t: u,
  51. b: 0,
  52. r: 0,
  53. l: u
  54. }, D = f + q[b], G = p + A[c];
  55. a.style[g] = `${D}px`, a.style[d] = `${G}px`;
  56. }
  57. return c + b;
  58. }
  59. }
  60. }
  61. return i.style.left = F, i.style.top = K, null;
  62. }, Q = (n, i, m) => {
  63. const r = typeof n == "object" && !(n instanceof HTMLElement) ? n : { reference: n, popper: i, ...m };
  64. return {
  65. /**
  66. * Repositions the current popper.
  67. * @param options Optional options which get merged with the current ones.
  68. */
  69. update(a = r) {
  70. const { reference: e, popper: l } = Object.assign(r, a);
  71. if (!l || !e)
  72. throw new Error("Popper- or reference-element missing.");
  73. return J(e, l, r);
  74. }
  75. };
  76. };
  77. export {
  78. Q as createPopper,
  79. I as defaults,
  80. J as reposition,
  81. N as version
  82. };
  83. //# sourceMappingURL=nanopop.mjs.map