zoom.mjs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*!
  2. * reveal.js Zoom plugin
  3. */
  4. const c = {
  5. id: "zoom",
  6. init: function(n) {
  7. n.getRevealElement().addEventListener("mousedown", function(o) {
  8. var l = /Linux/.test(window.navigator.platform) ? "ctrl" : "alt", f = (n.getConfig().zoomKey ? n.getConfig().zoomKey : l) + "Key", m = n.getConfig().zoomLevel ? n.getConfig().zoomLevel : 2;
  9. o[f] && !n.isOverview() && (o.preventDefault(), r.to({
  10. x: o.clientX,
  11. y: o.clientY,
  12. scale: m,
  13. pan: !1
  14. }));
  15. });
  16. },
  17. destroy: () => {
  18. r.reset();
  19. }
  20. }, h = () => c;
  21. /*!
  22. * zoom.js 0.3 (modified for use with reveal.js)
  23. * http://lab.hakim.se/zoom-js
  24. * MIT licensed
  25. *
  26. * Copyright (C) 2011-2014 Hakim El Hattab, http://hakim.se
  27. */
  28. var r = function() {
  29. var n = 1, o = 0, l = 0, f = -1, m = -1, u = "transform" in document.body.style;
  30. u && (document.body.style.transition = "transform 0.8s ease"), document.addEventListener("keyup", function(e) {
  31. n !== 1 && e.keyCode === 27 && r.out();
  32. }), document.addEventListener("mousemove", function(e) {
  33. n !== 1 && (o = e.clientX, l = e.clientY);
  34. });
  35. function y(e, t) {
  36. var i = s();
  37. if (e.width = e.width || 1, e.height = e.height || 1, e.x -= (window.innerWidth - e.width * t) / 2, e.y -= (window.innerHeight - e.height * t) / 2, u)
  38. if (t === 1)
  39. document.body.style.transform = "";
  40. else {
  41. var d = i.x + "px " + i.y + "px", w = "translate(" + -e.x + "px," + -e.y + "px) scale(" + t + ")";
  42. document.body.style.transformOrigin = d, document.body.style.transform = w;
  43. }
  44. else
  45. t === 1 ? (document.body.style.position = "", document.body.style.left = "", document.body.style.top = "", document.body.style.width = "", document.body.style.height = "", document.body.style.zoom = "") : (document.body.style.position = "relative", document.body.style.left = -(i.x + e.x) / t + "px", document.body.style.top = -(i.y + e.y) / t + "px", document.body.style.width = t * 100 + "%", document.body.style.height = t * 100 + "%", document.body.style.zoom = t);
  46. n = t, document.documentElement.classList && (n !== 1 ? document.documentElement.classList.add("zoomed") : document.documentElement.classList.remove("zoomed"));
  47. }
  48. function a() {
  49. var e = 0.12, t = window.innerWidth * e, i = window.innerHeight * e, d = s();
  50. l < i ? window.scroll(d.x, d.y - (1 - l / i) * (14 / n)) : l > window.innerHeight - i && window.scroll(d.x, d.y + (1 - (window.innerHeight - l) / i) * (14 / n)), o < t ? window.scroll(d.x - (1 - o / t) * (14 / n), d.y) : o > window.innerWidth - t && window.scroll(d.x + (1 - (window.innerWidth - o) / t) * (14 / n), d.y);
  51. }
  52. function s() {
  53. return {
  54. x: window.scrollX !== void 0 ? window.scrollX : window.pageXOffset,
  55. y: window.scrollY !== void 0 ? window.scrollY : window.pageYOffset
  56. };
  57. }
  58. return {
  59. /**
  60. * Zooms in on either a rectangle or HTML element.
  61. *
  62. * @param {Object} options
  63. * - element: HTML element to zoom in on
  64. * OR
  65. * - x/y: coordinates in non-transformed space to zoom in on
  66. * - width/height: the portion of the screen to zoom in on
  67. * - scale: can be used instead of width/height to explicitly set scale
  68. */
  69. to: function(e) {
  70. if (n !== 1)
  71. r.out();
  72. else {
  73. if (e.x = e.x || 0, e.y = e.y || 0, e.element) {
  74. var t = 20, i = e.element.getBoundingClientRect();
  75. e.x = i.left - t, e.y = i.top - t, e.width = i.width + t * 2, e.height = i.height + t * 2;
  76. }
  77. e.width !== void 0 && e.height !== void 0 && (e.scale = Math.max(Math.min(window.innerWidth / e.width, window.innerHeight / e.height), 1)), e.scale > 1 && (e.x *= e.scale, e.y *= e.scale, y(e, e.scale), e.pan !== !1 && (f = setTimeout(function() {
  78. m = setInterval(a, 1e3 / 60);
  79. }, 800)));
  80. }
  81. },
  82. /**
  83. * Resets the document zoom state to its default.
  84. */
  85. out: function() {
  86. clearTimeout(f), clearInterval(m), y({ x: 0, y: 0 }, 1), n = 1;
  87. },
  88. // Alias
  89. magnify: function(e) {
  90. this.to(e);
  91. },
  92. reset: function() {
  93. this.out();
  94. },
  95. zoomLevel: function() {
  96. return n;
  97. }
  98. };
  99. }();
  100. export {
  101. h as default
  102. };