1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = void 0;
|
5 |
|
6 | var _dom = _interopRequireDefault(require("../../utils/dom"));
|
7 |
|
8 | var _utils = require("../../utils/utils");
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
13 |
|
14 | var Cube = {
|
15 | setTranslate: function setTranslate() {
|
16 | var swiper = this;
|
17 | var $el = swiper.$el,
|
18 | $wrapperEl = swiper.$wrapperEl,
|
19 | slides = swiper.slides,
|
20 | swiperWidth = swiper.width,
|
21 | swiperHeight = swiper.height,
|
22 | rtl = swiper.rtlTranslate,
|
23 | swiperSize = swiper.size,
|
24 | browser = swiper.browser;
|
25 | var params = swiper.params.cubeEffect;
|
26 | var isHorizontal = swiper.isHorizontal();
|
27 | var isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
28 | var wrapperRotate = 0;
|
29 | var $cubeShadowEl;
|
30 |
|
31 | if (params.shadow) {
|
32 | if (isHorizontal) {
|
33 | $cubeShadowEl = $wrapperEl.find('.swiper-cube-shadow');
|
34 |
|
35 | if ($cubeShadowEl.length === 0) {
|
36 | $cubeShadowEl = (0, _dom.default)('<div class="swiper-cube-shadow"></div>');
|
37 | $wrapperEl.append($cubeShadowEl);
|
38 | }
|
39 |
|
40 | $cubeShadowEl.css({
|
41 | height: swiperWidth + "px"
|
42 | });
|
43 | } else {
|
44 | $cubeShadowEl = $el.find('.swiper-cube-shadow');
|
45 |
|
46 | if ($cubeShadowEl.length === 0) {
|
47 | $cubeShadowEl = (0, _dom.default)('<div class="swiper-cube-shadow"></div>');
|
48 | $el.append($cubeShadowEl);
|
49 | }
|
50 | }
|
51 | }
|
52 |
|
53 | for (var i = 0; i < slides.length; i += 1) {
|
54 | var $slideEl = slides.eq(i);
|
55 | var slideIndex = i;
|
56 |
|
57 | if (isVirtual) {
|
58 | slideIndex = parseInt($slideEl.attr('data-swiper-slide-index'), 10);
|
59 | }
|
60 |
|
61 | var slideAngle = slideIndex * 90;
|
62 | var round = Math.floor(slideAngle / 360);
|
63 |
|
64 | if (rtl) {
|
65 | slideAngle = -slideAngle;
|
66 | round = Math.floor(-slideAngle / 360);
|
67 | }
|
68 |
|
69 | var progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
|
70 | var tx = 0;
|
71 | var ty = 0;
|
72 | var tz = 0;
|
73 |
|
74 | if (slideIndex % 4 === 0) {
|
75 | tx = -round * 4 * swiperSize;
|
76 | tz = 0;
|
77 | } else if ((slideIndex - 1) % 4 === 0) {
|
78 | tx = 0;
|
79 | tz = -round * 4 * swiperSize;
|
80 | } else if ((slideIndex - 2) % 4 === 0) {
|
81 | tx = swiperSize + round * 4 * swiperSize;
|
82 | tz = swiperSize;
|
83 | } else if ((slideIndex - 3) % 4 === 0) {
|
84 | tx = -swiperSize;
|
85 | tz = 3 * swiperSize + swiperSize * 4 * round;
|
86 | }
|
87 |
|
88 | if (rtl) {
|
89 | tx = -tx;
|
90 | }
|
91 |
|
92 | if (!isHorizontal) {
|
93 | ty = tx;
|
94 | tx = 0;
|
95 | }
|
96 |
|
97 | var transform = "rotateX(" + (isHorizontal ? 0 : -slideAngle) + "deg) rotateY(" + (isHorizontal ? slideAngle : 0) + "deg) translate3d(" + tx + "px, " + ty + "px, " + tz + "px)";
|
98 |
|
99 | if (progress <= 1 && progress > -1) {
|
100 | wrapperRotate = slideIndex * 90 + progress * 90;
|
101 | if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90;
|
102 | }
|
103 |
|
104 | $slideEl.transform(transform);
|
105 |
|
106 | if (params.slideShadows) {
|
107 |
|
108 | var shadowBefore = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
|
109 | var shadowAfter = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
|
110 |
|
111 | if (shadowBefore.length === 0) {
|
112 | shadowBefore = (0, _dom.default)("<div class=\"swiper-slide-shadow-" + (isHorizontal ? 'left' : 'top') + "\"></div>");
|
113 | $slideEl.append(shadowBefore);
|
114 | }
|
115 |
|
116 | if (shadowAfter.length === 0) {
|
117 | shadowAfter = (0, _dom.default)("<div class=\"swiper-slide-shadow-" + (isHorizontal ? 'right' : 'bottom') + "\"></div>");
|
118 | $slideEl.append(shadowAfter);
|
119 | }
|
120 |
|
121 | if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
|
122 | if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
|
123 | }
|
124 | }
|
125 |
|
126 | $wrapperEl.css({
|
127 | '-webkit-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
|
128 | '-moz-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
|
129 | '-ms-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
|
130 | 'transform-origin': "50% 50% -" + swiperSize / 2 + "px"
|
131 | });
|
132 |
|
133 | if (params.shadow) {
|
134 | if (isHorizontal) {
|
135 | $cubeShadowEl.transform("translate3d(0px, " + (swiperWidth / 2 + params.shadowOffset) + "px, " + -swiperWidth / 2 + "px) rotateX(90deg) rotateZ(0deg) scale(" + params.shadowScale + ")");
|
136 | } else {
|
137 | var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
|
138 | var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
|
139 | var scale1 = params.shadowScale;
|
140 | var scale2 = params.shadowScale / multiplier;
|
141 | var offset = params.shadowOffset;
|
142 | $cubeShadowEl.transform("scale3d(" + scale1 + ", 1, " + scale2 + ") translate3d(0px, " + (swiperHeight / 2 + offset) + "px, " + -swiperHeight / 2 / scale2 + "px) rotateX(-90deg)");
|
143 | }
|
144 | }
|
145 |
|
146 | var zFactor = browser.isSafari || browser.isWebView ? -swiperSize / 2 : 0;
|
147 | $wrapperEl.transform("translate3d(0px,0," + zFactor + "px) rotateX(" + (swiper.isHorizontal() ? 0 : wrapperRotate) + "deg) rotateY(" + (swiper.isHorizontal() ? -wrapperRotate : 0) + "deg)");
|
148 | },
|
149 | setTransition: function setTransition(duration) {
|
150 | var swiper = this;
|
151 | var $el = swiper.$el,
|
152 | slides = swiper.slides;
|
153 | slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
|
154 |
|
155 | if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) {
|
156 | $el.find('.swiper-cube-shadow').transition(duration);
|
157 | }
|
158 | }
|
159 | };
|
160 | var _default = {
|
161 | name: 'effect-cube',
|
162 | params: {
|
163 | cubeEffect: {
|
164 | slideShadows: true,
|
165 | shadow: true,
|
166 | shadowOffset: 20,
|
167 | shadowScale: 0.94
|
168 | }
|
169 | },
|
170 | create: function create() {
|
171 | var swiper = this;
|
172 | (0, _utils.bindModuleMethods)(swiper, {
|
173 | cubeEffect: _extends({}, Cube)
|
174 | });
|
175 | },
|
176 | on: {
|
177 | beforeInit: function beforeInit(swiper) {
|
178 | if (swiper.params.effect !== 'cube') return;
|
179 | swiper.classNames.push(swiper.params.containerModifierClass + "cube");
|
180 | swiper.classNames.push(swiper.params.containerModifierClass + "3d");
|
181 | var overwriteParams = {
|
182 | slidesPerView: 1,
|
183 | slidesPerColumn: 1,
|
184 | slidesPerGroup: 1,
|
185 | watchSlidesProgress: true,
|
186 | resistanceRatio: 0,
|
187 | spaceBetween: 0,
|
188 | centeredSlides: false,
|
189 | virtualTranslate: true
|
190 | };
|
191 | (0, _utils.extend)(swiper.params, overwriteParams);
|
192 | (0, _utils.extend)(swiper.originalParams, overwriteParams);
|
193 | },
|
194 | setTranslate: function setTranslate(swiper) {
|
195 | if (swiper.params.effect !== 'cube') return;
|
196 | swiper.cubeEffect.setTranslate();
|
197 | },
|
198 | setTransition: function setTransition(swiper, duration) {
|
199 | if (swiper.params.effect !== 'cube') return;
|
200 | swiper.cubeEffect.setTransition(duration);
|
201 | }
|
202 | }
|
203 | };
|
204 | exports.default = _default; |
\ | No newline at end of file |