769fac8a2225d5a259b4b2a7c5993f6056ad5eadb23ff50fa1db910968c4533f82c1ed1bfc20304d5b8e37f79e12152acc8d7c596cd31faebb5fdec8c3271d 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { LTR, RTL, HORIZONTAL, FORWARD, BACKWARD, RTL_OFFSET_POS_DESC, RTL_OFFSET_NAG, RTL_OFFSET_POS_ASC } from './defaults.mjs';
  2. const getScrollDir = (prev, cur) => prev < cur ? FORWARD : BACKWARD;
  3. const isHorizontal = (dir) => dir === LTR || dir === RTL || dir === HORIZONTAL;
  4. const isRTL = (dir) => dir === RTL;
  5. let cachedRTLResult = null;
  6. function getRTLOffsetType(recalculate = false) {
  7. if (cachedRTLResult === null || recalculate) {
  8. const outerDiv = document.createElement("div");
  9. const outerStyle = outerDiv.style;
  10. outerStyle.width = "50px";
  11. outerStyle.height = "50px";
  12. outerStyle.overflow = "scroll";
  13. outerStyle.direction = "rtl";
  14. const innerDiv = document.createElement("div");
  15. const innerStyle = innerDiv.style;
  16. innerStyle.width = "100px";
  17. innerStyle.height = "100px";
  18. outerDiv.appendChild(innerDiv);
  19. document.body.appendChild(outerDiv);
  20. if (outerDiv.scrollLeft > 0) {
  21. cachedRTLResult = RTL_OFFSET_POS_DESC;
  22. } else {
  23. outerDiv.scrollLeft = 1;
  24. if (outerDiv.scrollLeft === 0) {
  25. cachedRTLResult = RTL_OFFSET_NAG;
  26. } else {
  27. cachedRTLResult = RTL_OFFSET_POS_ASC;
  28. }
  29. }
  30. document.body.removeChild(outerDiv);
  31. return cachedRTLResult;
  32. }
  33. return cachedRTLResult;
  34. }
  35. function renderThumbStyle({ move, size, bar }, layout) {
  36. const style = {};
  37. const translate = `translate${bar.axis}(${move}px)`;
  38. style[bar.size] = size;
  39. style.transform = translate;
  40. if (layout === "horizontal") {
  41. style.height = "100%";
  42. } else {
  43. style.width = "100%";
  44. }
  45. return style;
  46. }
  47. export { getRTLOffsetType, getScrollDir, isHorizontal, isRTL, renderThumbStyle };
  48. //# sourceMappingURL=utils.mjs.map