PHP 7.4.33
Preview: controller.mjs Size: 6.65 KB
/var/www/sitesecurity.bitkit.dk/httpdocs/node_modules/swiper/modules/controller.mjs
import { n as nextTick, o as elementTransitionEnd } from '../shared/utils.mjs';

/* eslint no-bitwise: ["error", { "allow": [">>"] }] */
function Controller({
  swiper,
  extendParams,
  on
}) {
  extendParams({
    controller: {
      control: undefined,
      inverse: false,
      by: 'slide' // or 'container'
    }
  });

  swiper.controller = {
    control: undefined
  };
  function LinearSpline(x, y) {
    const binarySearch = function search() {
      let maxIndex;
      let minIndex;
      let guess;
      return (array, val) => {
        minIndex = -1;
        maxIndex = array.length;
        while (maxIndex - minIndex > 1) {
          guess = maxIndex + minIndex >> 1;
          if (array[guess] <= val) {
            minIndex = guess;
          } else {
            maxIndex = guess;
          }
        }
        return maxIndex;
      };
    }();
    this.x = x;
    this.y = y;
    this.lastIndex = x.length - 1;
    // Given an x value (x2), return the expected y2 value:
    // (x1,y1) is the known point before given value,
    // (x3,y3) is the known point after given value.
    let i1;
    let i3;
    this.interpolate = function interpolate(x2) {
      if (!x2) return 0;

      // Get the indexes of x1 and x3 (the array indexes before and after given x2):
      i3 = binarySearch(this.x, x2);
      i1 = i3 - 1;

      // We have our indexes i1 & i3, so we can calculate already:
      // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
      return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1];
    };
    return this;
  }
  function getInterpolateFunction(c) {
    swiper.controller.spline = swiper.params.loop ? new LinearSpline(swiper.slidesGrid, c.slidesGrid) : new LinearSpline(swiper.snapGrid, c.snapGrid);
  }
  function setTranslate(_t, byController) {
    const controlled = swiper.controller.control;
    let multiplier;
    let controlledTranslate;
    const Swiper = swiper.constructor;
    function setControlledTranslate(c) {
      if (c.destroyed) return;

      // this will create an Interpolate function based on the snapGrids
      // x is the Grid of the scrolled scroller and y will be the controlled scroller
      // it makes sense to create this only once and recall it for the interpolation
      // the function does a lot of value caching for performance
      const translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate;
      if (swiper.params.controller.by === 'slide') {
        getInterpolateFunction(c);
        // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
        // but it did not work out
        controlledTranslate = -swiper.controller.spline.interpolate(-translate);
      }
      if (!controlledTranslate || swiper.params.controller.by === 'container') {
        multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate());
        if (Number.isNaN(multiplier) || !Number.isFinite(multiplier)) {
          multiplier = 1;
        }
        controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate();
      }
      if (swiper.params.controller.inverse) {
        controlledTranslate = c.maxTranslate() - controlledTranslate;
      }
      c.updateProgress(controlledTranslate);
      c.setTranslate(controlledTranslate, swiper);
      c.updateActiveIndex();
      c.updateSlidesClasses();
    }
    if (Array.isArray(controlled)) {
      for (let i = 0; i < controlled.length; i += 1) {
        if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
          setControlledTranslate(controlled[i]);
        }
      }
    } else if (controlled instanceof Swiper && byController !== controlled) {
      setControlledTranslate(controlled);
    }
  }
  function setTransition(duration, byController) {
    const Swiper = swiper.constructor;
    const controlled = swiper.controller.control;
    let i;
    function setControlledTransition(c) {
      if (c.destroyed) return;
      c.setTransition(duration, swiper);
      if (duration !== 0) {
        c.transitionStart();
        if (c.params.autoHeight) {
          nextTick(() => {
            c.updateAutoHeight();
          });
        }
        elementTransitionEnd(c.wrapperEl, () => {
          if (!controlled) return;
          c.transitionEnd();
        });
      }
    }
    if (Array.isArray(controlled)) {
      for (i = 0; i < controlled.length; i += 1) {
        if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
          setControlledTransition(controlled[i]);
        }
      }
    } else if (controlled instanceof Swiper && byController !== controlled) {
      setControlledTransition(controlled);
    }
  }
  function removeSpline() {
    if (!swiper.controller.control) return;
    if (swiper.controller.spline) {
      swiper.controller.spline = undefined;
      delete swiper.controller.spline;
    }
  }
  on('beforeInit', () => {
    if (typeof window !== 'undefined' && (
    // eslint-disable-line
    typeof swiper.params.controller.control === 'string' || swiper.params.controller.control instanceof HTMLElement)) {
      const controlElements = typeof swiper.params.controller.control === 'string' ? [...document.querySelectorAll(swiper.params.controller.control)] : [swiper.params.controller.control];
      controlElements.forEach(controlElement => {
        if (!swiper.controller.control) swiper.controller.control = [];
        if (controlElement && controlElement.swiper) {
          swiper.controller.control.push(controlElement.swiper);
        } else if (controlElement) {
          const eventName = `${swiper.params.eventsPrefix}init`;
          const onControllerSwiper = e => {
            swiper.controller.control.push(e.detail[0]);
            swiper.update();
            controlElement.removeEventListener(eventName, onControllerSwiper);
          };
          controlElement.addEventListener(eventName, onControllerSwiper);
        }
      });
      return;
    }
    swiper.controller.control = swiper.params.controller.control;
  });
  on('update', () => {
    removeSpline();
  });
  on('resize', () => {
    removeSpline();
  });
  on('observerUpdate', () => {
    removeSpline();
  });
  on('setTranslate', (_s, translate, byController) => {
    if (!swiper.controller.control || swiper.controller.control.destroyed) return;
    swiper.controller.setTranslate(translate, byController);
  });
  on('setTransition', (_s, duration, byController) => {
    if (!swiper.controller.control || swiper.controller.control.destroyed) return;
    swiper.controller.setTransition(duration, byController);
  });
  Object.assign(swiper.controller, {
    setTranslate,
    setTransition
  });
}

export { Controller as default };

Directory Contents

Dirs: 0 × Files: 164
Name Size Perms Modified Actions
143 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
104 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
143 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
104 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
6.52 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
8.22 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
12.32 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:39
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.98 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
5.41 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
8.93 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.82 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.18 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
6.65 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
182 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
150 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
178 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
141 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.48 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.48 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.58 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
22 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
22 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.07 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.85 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.31 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
155 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
129 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
151 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
120 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.62 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.83 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.92 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.31 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1008 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.35 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
979 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.36 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.44 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
6.46 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
504 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
418 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
368 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
266 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.20 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.57 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.82 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
482 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
354 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
661 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
481 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.23 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.68 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.77 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
98 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
84 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
98 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
84 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.45 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.82 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
8.14 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
141 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
117 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
141 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
117 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.13 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.61 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
5.08 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.06 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.44 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.41 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.14 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.17 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.16 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.26 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
396 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.22 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.18 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.34 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.36 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.37 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.59 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.92 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.84 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
7.18 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
14.50 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.81 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.08 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.17 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.46 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.34 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.83 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
6.97 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
6.54 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
4.97 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
5.14 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.55 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
9.11 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
11.39 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
17.04 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.95 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.65 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.83 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.77 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.19 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.69 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.10 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
6.02 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
7.52 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
10.74 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
88 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
94 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
0 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.59 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
5.11 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
7.69 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
533 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
445 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
541 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
438 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
5.55 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
8.24 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
11.92 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
140 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
62 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
381 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
239 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
12.45 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
17.38 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
24.89 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).