1 |
|
2 | "use strict";
|
3 |
|
4 | const { SvelteComponent, append, assign, attr, binding_callbacks, compute_rest_props, create_slot, detach, element, exclude_internal_props, get_spread_update, init, insert, noop, safe_not_equal, set_attributes, space, transition_in, transition_out, update_slot } = require("svelte/internal");
|
5 | const { onMount, onDestroy, afterUpdate, createEventDispatcher, tick, beforeUpdate } = require("svelte");
|
6 | const { getParams } = require("./get-params");
|
7 | const { initSwiper, mountSwiper } = require("./init-swiper");
|
8 | const { needsScrollbar, needsNavigation, needsPagination, uniqueClasses, extend } = require("./utils");
|
9 | const { getChangedParams } = require("./get-changed-params");
|
10 | const { updateSwiper } = require("./update-swiper");
|
11 | const get_container_end_slot_changes = dirty => ({ virtualData: dirty & 512 });
|
12 | const get_container_end_slot_context = ctx => ({ virtualData: ctx[9] });
|
13 | const get_wrapper_end_slot_changes = dirty => ({ virtualData: dirty & 512 });
|
14 | const get_wrapper_end_slot_context = ctx => ({ virtualData: ctx[9] });
|
15 | const get_default_slot_changes = dirty => ({ virtualData: dirty & 512 });
|
16 | const get_default_slot_context = ctx => ({ virtualData: ctx[9] });
|
17 | const get_wrapper_start_slot_changes = dirty => ({ virtualData: dirty & 512 });
|
18 | const get_wrapper_start_slot_context = ctx => ({ virtualData: ctx[9] });
|
19 | const get_container_start_slot_changes = dirty => ({ virtualData: dirty & 512 });
|
20 | const get_container_start_slot_context = ctx => ({ virtualData: ctx[9] });
|
21 |
|
22 |
|
23 | function create_if_block_2(ctx) {
|
24 | let div0;
|
25 | let t;
|
26 | let div1;
|
27 |
|
28 | return {
|
29 | c() {
|
30 | div0 = element("div");
|
31 | t = space();
|
32 | div1 = element("div");
|
33 | attr(div0, "class", "swiper-button-prev");
|
34 | attr(div1, "class", "swiper-button-next");
|
35 | },
|
36 | m(target, anchor) {
|
37 | insert(target, div0, anchor);
|
38 | ctx[13](div0);
|
39 | insert(target, t, anchor);
|
40 | insert(target, div1, anchor);
|
41 | ctx[14](div1);
|
42 | },
|
43 | p: noop,
|
44 | d(detaching) {
|
45 | if (detaching) detach(div0);
|
46 | ctx[13](null);
|
47 | if (detaching) detach(t);
|
48 | if (detaching) detach(div1);
|
49 | ctx[14](null);
|
50 | }
|
51 | };
|
52 | }
|
53 |
|
54 |
|
55 | function create_if_block_1(ctx) {
|
56 | let div;
|
57 |
|
58 | return {
|
59 | c() {
|
60 | div = element("div");
|
61 | attr(div, "class", "swiper-scrollbar");
|
62 | },
|
63 | m(target, anchor) {
|
64 | insert(target, div, anchor);
|
65 | ctx[15](div);
|
66 | },
|
67 | p: noop,
|
68 | d(detaching) {
|
69 | if (detaching) detach(div);
|
70 | ctx[15](null);
|
71 | }
|
72 | };
|
73 | }
|
74 |
|
75 |
|
76 | function create_if_block(ctx) {
|
77 | let div;
|
78 |
|
79 | return {
|
80 | c() {
|
81 | div = element("div");
|
82 | attr(div, "class", "swiper-pagination");
|
83 | },
|
84 | m(target, anchor) {
|
85 | insert(target, div, anchor);
|
86 | ctx[16](div);
|
87 | },
|
88 | p: noop,
|
89 | d(detaching) {
|
90 | if (detaching) detach(div);
|
91 | ctx[16](null);
|
92 | }
|
93 | };
|
94 | }
|
95 |
|
96 | function create_fragment(ctx) {
|
97 | let div1;
|
98 | let t0;
|
99 | let show_if_2 = needsNavigation( ctx[2]);
|
100 | let t1;
|
101 | let show_if_1 = needsScrollbar( ctx[2]);
|
102 | let t2;
|
103 | let show_if = needsPagination( ctx[2]);
|
104 | let t3;
|
105 | let div0;
|
106 | let t4;
|
107 | let t5;
|
108 | let t6;
|
109 | let div1_class_value;
|
110 | let current;
|
111 | const container_start_slot_template = ctx[12]["container-start"];
|
112 | const container_start_slot = create_slot(container_start_slot_template, ctx, ctx[11], get_container_start_slot_context);
|
113 | let if_block0 = show_if_2 && create_if_block_2(ctx);
|
114 | let if_block1 = show_if_1 && create_if_block_1(ctx);
|
115 | let if_block2 = show_if && create_if_block(ctx);
|
116 | const wrapper_start_slot_template = ctx[12]["wrapper-start"];
|
117 | const wrapper_start_slot = create_slot(wrapper_start_slot_template, ctx, ctx[11], get_wrapper_start_slot_context);
|
118 | const default_slot_template = ctx[12].default;
|
119 | const default_slot = create_slot(default_slot_template, ctx, ctx[11], get_default_slot_context);
|
120 | const wrapper_end_slot_template = ctx[12]["wrapper-end"];
|
121 | const wrapper_end_slot = create_slot(wrapper_end_slot_template, ctx, ctx[11], get_wrapper_end_slot_context);
|
122 | const container_end_slot_template = ctx[12]["container-end"];
|
123 | const container_end_slot = create_slot(container_end_slot_template, ctx, ctx[11], get_container_end_slot_context);
|
124 |
|
125 | let div1_levels = [
|
126 | {
|
127 | class: div1_class_value = uniqueClasses(`${/*containerClasses*/ ctx[1]}${/*className*/ ctx[0] ? ` ${/*className*/ ctx[0]}` : ""}`)
|
128 | },
|
129 | ctx[3]
|
130 | ];
|
131 |
|
132 | let div1_data = {};
|
133 |
|
134 | for (let i = 0; i < div1_levels.length; i += 1) {
|
135 | div1_data = assign(div1_data, div1_levels[i]);
|
136 | }
|
137 |
|
138 | return {
|
139 | c() {
|
140 | div1 = element("div");
|
141 | if (container_start_slot) container_start_slot.c();
|
142 | t0 = space();
|
143 | if (if_block0) if_block0.c();
|
144 | t1 = space();
|
145 | if (if_block1) if_block1.c();
|
146 | t2 = space();
|
147 | if (if_block2) if_block2.c();
|
148 | t3 = space();
|
149 | div0 = element("div");
|
150 | if (wrapper_start_slot) wrapper_start_slot.c();
|
151 | t4 = space();
|
152 | if (default_slot) default_slot.c();
|
153 | t5 = space();
|
154 | if (wrapper_end_slot) wrapper_end_slot.c();
|
155 | t6 = space();
|
156 | if (container_end_slot) container_end_slot.c();
|
157 | attr(div0, "class", "swiper-wrapper");
|
158 | set_attributes(div1, div1_data);
|
159 | },
|
160 | m(target, anchor) {
|
161 | insert(target, div1, anchor);
|
162 |
|
163 | if (container_start_slot) {
|
164 | container_start_slot.m(div1, null);
|
165 | }
|
166 |
|
167 | append(div1, t0);
|
168 | if (if_block0) if_block0.m(div1, null);
|
169 | append(div1, t1);
|
170 | if (if_block1) if_block1.m(div1, null);
|
171 | append(div1, t2);
|
172 | if (if_block2) if_block2.m(div1, null);
|
173 | append(div1, t3);
|
174 | append(div1, div0);
|
175 |
|
176 | if (wrapper_start_slot) {
|
177 | wrapper_start_slot.m(div0, null);
|
178 | }
|
179 |
|
180 | append(div0, t4);
|
181 |
|
182 | if (default_slot) {
|
183 | default_slot.m(div0, null);
|
184 | }
|
185 |
|
186 | append(div0, t5);
|
187 |
|
188 | if (wrapper_end_slot) {
|
189 | wrapper_end_slot.m(div0, null);
|
190 | }
|
191 |
|
192 | append(div1, t6);
|
193 |
|
194 | if (container_end_slot) {
|
195 | container_end_slot.m(div1, null);
|
196 | }
|
197 |
|
198 | ctx[17](div1);
|
199 | current = true;
|
200 | },
|
201 | p(ctx, [dirty]) {
|
202 | if (container_start_slot) {
|
203 | if (container_start_slot.p && dirty & 2560) {
|
204 | update_slot(container_start_slot, container_start_slot_template, ctx, ctx[11], dirty, get_container_start_slot_changes, get_container_start_slot_context);
|
205 | }
|
206 | }
|
207 |
|
208 | if (dirty & 4) show_if_2 = needsNavigation( ctx[2]);
|
209 |
|
210 | if (show_if_2) {
|
211 | if (if_block0) {
|
212 | if_block0.p(ctx, dirty);
|
213 | } else {
|
214 | if_block0 = create_if_block_2(ctx);
|
215 | if_block0.c();
|
216 | if_block0.m(div1, t1);
|
217 | }
|
218 | } else if (if_block0) {
|
219 | if_block0.d(1);
|
220 | if_block0 = null;
|
221 | }
|
222 |
|
223 | if (dirty & 4) show_if_1 = needsScrollbar( ctx[2]);
|
224 |
|
225 | if (show_if_1) {
|
226 | if (if_block1) {
|
227 | if_block1.p(ctx, dirty);
|
228 | } else {
|
229 | if_block1 = create_if_block_1(ctx);
|
230 | if_block1.c();
|
231 | if_block1.m(div1, t2);
|
232 | }
|
233 | } else if (if_block1) {
|
234 | if_block1.d(1);
|
235 | if_block1 = null;
|
236 | }
|
237 |
|
238 | if (dirty & 4) show_if = needsPagination( ctx[2]);
|
239 |
|
240 | if (show_if) {
|
241 | if (if_block2) {
|
242 | if_block2.p(ctx, dirty);
|
243 | } else {
|
244 | if_block2 = create_if_block(ctx);
|
245 | if_block2.c();
|
246 | if_block2.m(div1, t3);
|
247 | }
|
248 | } else if (if_block2) {
|
249 | if_block2.d(1);
|
250 | if_block2 = null;
|
251 | }
|
252 |
|
253 | if (wrapper_start_slot) {
|
254 | if (wrapper_start_slot.p && dirty & 2560) {
|
255 | update_slot(wrapper_start_slot, wrapper_start_slot_template, ctx, ctx[11], dirty, get_wrapper_start_slot_changes, get_wrapper_start_slot_context);
|
256 | }
|
257 | }
|
258 |
|
259 | if (default_slot) {
|
260 | if (default_slot.p && dirty & 2560) {
|
261 | update_slot(default_slot, default_slot_template, ctx, ctx[11], dirty, get_default_slot_changes, get_default_slot_context);
|
262 | }
|
263 | }
|
264 |
|
265 | if (wrapper_end_slot) {
|
266 | if (wrapper_end_slot.p && dirty & 2560) {
|
267 | update_slot(wrapper_end_slot, wrapper_end_slot_template, ctx, ctx[11], dirty, get_wrapper_end_slot_changes, get_wrapper_end_slot_context);
|
268 | }
|
269 | }
|
270 |
|
271 | if (container_end_slot) {
|
272 | if (container_end_slot.p && dirty & 2560) {
|
273 | update_slot(container_end_slot, container_end_slot_template, ctx, ctx[11], dirty, get_container_end_slot_changes, get_container_end_slot_context);
|
274 | }
|
275 | }
|
276 |
|
277 | set_attributes(div1, div1_data = get_spread_update(div1_levels, [
|
278 | (!current || dirty & 3 && div1_class_value !== (div1_class_value = uniqueClasses(`${/*containerClasses*/ ctx[1]}${/*className*/ ctx[0] ? ` ${/*className*/ ctx[0]}` : ""}`))) && { class: div1_class_value },
|
279 | dirty & 8 && ctx[3]
|
280 | ]));
|
281 | },
|
282 | i(local) {
|
283 | if (current) return;
|
284 | transition_in(container_start_slot, local);
|
285 | transition_in(wrapper_start_slot, local);
|
286 | transition_in(default_slot, local);
|
287 | transition_in(wrapper_end_slot, local);
|
288 | transition_in(container_end_slot, local);
|
289 | current = true;
|
290 | },
|
291 | o(local) {
|
292 | transition_out(container_start_slot, local);
|
293 | transition_out(wrapper_start_slot, local);
|
294 | transition_out(default_slot, local);
|
295 | transition_out(wrapper_end_slot, local);
|
296 | transition_out(container_end_slot, local);
|
297 | current = false;
|
298 | },
|
299 | d(detaching) {
|
300 | if (detaching) detach(div1);
|
301 | if (container_start_slot) container_start_slot.d(detaching);
|
302 | if (if_block0) if_block0.d();
|
303 | if (if_block1) if_block1.d();
|
304 | if (if_block2) if_block2.d();
|
305 | if (wrapper_start_slot) wrapper_start_slot.d(detaching);
|
306 | if (default_slot) default_slot.d(detaching);
|
307 | if (wrapper_end_slot) wrapper_end_slot.d(detaching);
|
308 | if (container_end_slot) container_end_slot.d(detaching);
|
309 | ctx[17](null);
|
310 | }
|
311 | };
|
312 | }
|
313 |
|
314 | function instance($$self, $$props, $$invalidate) {
|
315 | const omit_props_names = ["class","swiper"];
|
316 | let $$restProps = compute_rest_props($$props, omit_props_names);
|
317 | let { $$slots: slots = {}, $$scope } = $$props;
|
318 | const dispatch = createEventDispatcher();
|
319 | let { class: className = undefined } = $$props;
|
320 | let containerClasses = "swiper-container";
|
321 | let breakpointChanged = false;
|
322 | let swiperInstance = null;
|
323 | let oldPassedParams = null;
|
324 | let paramsData;
|
325 | let swiperParams;
|
326 | let passedParams;
|
327 | let restProps;
|
328 | let swiperEl = null;
|
329 | let prevEl = null;
|
330 | let nextEl = null;
|
331 | let scrollbarEl = null;
|
332 | let paginationEl = null;
|
333 | let virtualData = { slides: [] };
|
334 |
|
335 | function swiper() {
|
336 | return swiperInstance;
|
337 | }
|
338 |
|
339 | const setVirtualData = data => {
|
340 | $$invalidate(9, virtualData = data);
|
341 |
|
342 | tick().then(() => {
|
343 | swiperInstance.$wrapperEl.children(".swiper-slide").each(el => {
|
344 | if (el.onSwiper) el.onSwiper(swiperInstance);
|
345 | });
|
346 |
|
347 | swiperInstance.updateSlides();
|
348 | swiperInstance.updateProgress();
|
349 | swiperInstance.updateSlidesClasses();
|
350 |
|
351 | if (swiperInstance.lazy && swiperInstance.params.lazy.enabled) {
|
352 | swiperInstance.lazy.load();
|
353 | }
|
354 | });
|
355 | };
|
356 |
|
357 | const calcParams = () => {
|
358 | paramsData = getParams($$restProps);
|
359 | $$invalidate(2, swiperParams = paramsData.params);
|
360 | passedParams = paramsData.passedParams;
|
361 | $$invalidate(3, restProps = paramsData.rest);
|
362 | };
|
363 |
|
364 | calcParams();
|
365 | oldPassedParams = passedParams;
|
366 |
|
367 | const onBeforeBreakpoint = () => {
|
368 | breakpointChanged = true;
|
369 | };
|
370 |
|
371 | swiperParams.onAny = (event, ...args) => {
|
372 | dispatch(event, [args]);
|
373 | };
|
374 |
|
375 | Object.assign(swiperParams.on, {
|
376 | _beforeBreakpoint: onBeforeBreakpoint,
|
377 | _containerClasses(_swiper, classes) {
|
378 | $$invalidate(1, containerClasses = classes);
|
379 | }
|
380 | });
|
381 |
|
382 | swiperInstance = initSwiper(swiperParams);
|
383 |
|
384 | if (swiperInstance.virtual && swiperInstance.params.virtual.enabled) {
|
385 | const extendWith = {
|
386 | cache: false,
|
387 | renderExternal: data => {
|
388 | setVirtualData(data);
|
389 |
|
390 | if (swiperParams.virtual && swiperParams.virtual.renderExternal) {
|
391 | swiperParams.virtual.renderExternal(data);
|
392 | }
|
393 | },
|
394 | renderExternalUpdate: false
|
395 | };
|
396 |
|
397 | extend(swiperInstance.params.virtual, extendWith);
|
398 | extend(swiperInstance.originalParams.virtual, extendWith);
|
399 | }
|
400 |
|
401 | onMount(() => {
|
402 | if (!swiperEl) return;
|
403 |
|
404 | mountSwiper(
|
405 | {
|
406 | el: swiperEl,
|
407 | nextEl,
|
408 | prevEl,
|
409 | paginationEl,
|
410 | scrollbarEl,
|
411 | swiper: swiperInstance
|
412 | },
|
413 | swiperParams
|
414 | );
|
415 |
|
416 | dispatch("swiper", [swiperInstance]);
|
417 | if (swiperParams.virtual) return;
|
418 |
|
419 | swiperInstance.slides.each(el => {
|
420 | if (el.onSwiper) el.onSwiper(swiperInstance);
|
421 | });
|
422 | });
|
423 |
|
424 | afterUpdate(() => {
|
425 | if (!swiperInstance) return;
|
426 | calcParams();
|
427 | const changedParams = getChangedParams(passedParams, oldPassedParams);
|
428 |
|
429 | if ((changedParams.length || breakpointChanged) && swiperInstance && !swiperInstance.destroyed) {
|
430 | updateSwiper(swiperInstance, passedParams, changedParams);
|
431 | }
|
432 |
|
433 | breakpointChanged = false;
|
434 | oldPassedParams = passedParams;
|
435 | });
|
436 |
|
437 | onDestroy(() => {
|
438 | if (typeof window !== "undefined" && swiperInstance && !swiperInstance.destroyed) {
|
439 | swiperInstance.destroy(true, false);
|
440 | }
|
441 | });
|
442 |
|
443 | function div0_binding($$value) {
|
444 | binding_callbacks[$$value ? "unshift" : "push"](() => {
|
445 | prevEl = $$value;
|
446 | $$invalidate(5, prevEl);
|
447 | });
|
448 | }
|
449 |
|
450 | function div1_binding($$value) {
|
451 | binding_callbacks[$$value ? "unshift" : "push"](() => {
|
452 | nextEl = $$value;
|
453 | $$invalidate(6, nextEl);
|
454 | });
|
455 | }
|
456 |
|
457 | function div_binding($$value) {
|
458 | binding_callbacks[$$value ? "unshift" : "push"](() => {
|
459 | scrollbarEl = $$value;
|
460 | $$invalidate(7, scrollbarEl);
|
461 | });
|
462 | }
|
463 |
|
464 | function div_binding_1($$value) {
|
465 | binding_callbacks[$$value ? "unshift" : "push"](() => {
|
466 | paginationEl = $$value;
|
467 | $$invalidate(8, paginationEl);
|
468 | });
|
469 | }
|
470 |
|
471 | function div1_binding_1($$value) {
|
472 | binding_callbacks[$$value ? "unshift" : "push"](() => {
|
473 | swiperEl = $$value;
|
474 | $$invalidate(4, swiperEl);
|
475 | });
|
476 | }
|
477 |
|
478 | $$self.$$set = $$new_props => {
|
479 | $$props = assign(assign({}, $$props), exclude_internal_props($$new_props));
|
480 | $$invalidate(27, $$restProps = compute_rest_props($$props, omit_props_names));
|
481 | if ("class" in $$new_props) $$invalidate(0, className = $$new_props.class);
|
482 | if ("$$scope" in $$new_props) $$invalidate(11, $$scope = $$new_props.$$scope);
|
483 | };
|
484 |
|
485 | return [
|
486 | className,
|
487 | containerClasses,
|
488 | swiperParams,
|
489 | restProps,
|
490 | swiperEl,
|
491 | prevEl,
|
492 | nextEl,
|
493 | scrollbarEl,
|
494 | paginationEl,
|
495 | virtualData,
|
496 | swiper,
|
497 | $$scope,
|
498 | slots,
|
499 | div0_binding,
|
500 | div1_binding,
|
501 | div_binding,
|
502 | div_binding_1,
|
503 | div1_binding_1
|
504 | ];
|
505 | }
|
506 |
|
507 | class Swiper extends SvelteComponent {
|
508 | constructor(options) {
|
509 | super();
|
510 | init(this, options, instance, create_fragment, safe_not_equal, { class: 0, swiper: 10 });
|
511 | }
|
512 |
|
513 | get swiper() {
|
514 | return this.$$.ctx[10];
|
515 | }
|
516 | }
|
517 |
|
518 | exports.default = Swiper; |
\ | No newline at end of file |