@egjs/flicking-plugins 4.6.0 → 4.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugins.js CHANGED
@@ -4,7 +4,7 @@ name: @egjs/flicking-plugins
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking-plugins
7
- version: 4.6.0
7
+ version: 4.7.1
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@egjs/flicking')) :
@@ -156,8 +156,11 @@ version: 4.6.0
156
156
  var progress = panel.outsetProgress;
157
157
  var el = panel.element;
158
158
  var target = selector ? el.querySelector(selector) : el;
159
- var opacity = Math.min(1, Math.max(0, 1 - Math.abs(progress * scale)));
160
- target.style.opacity = "" + opacity;
159
+
160
+ if (target) {
161
+ var opacity = Math.min(1, Math.max(0, 1 - Math.abs(progress * scale)));
162
+ target.style.opacity = "" + opacity;
163
+ }
161
164
  });
162
165
  };
163
166
 
@@ -401,12 +404,61 @@ version: 4.6.0
401
404
 
402
405
  this._playing = true;
403
406
  this._timerId = window.setTimeout(function () {
407
+ var _a, _b;
408
+
409
+ var animationDuration = _this._animationDuration || flicking$1.duration;
410
+ var moveType = flicking$1.moveType; // for freeScroll
411
+
412
+ if (moveType === flicking.MOVE_TYPE.FREE_SCROLL || (moveType === null || moveType === void 0 ? void 0 : moveType[0]) === flicking.MOVE_TYPE.FREE_SCROLL) {
413
+ var range = flicking$1.camera.range;
414
+ var cameraPosition = flicking$1.camera.position;
415
+ var currentPanel = flicking$1.currentPanel;
416
+ var prevPanel = currentPanel.prev();
417
+ var nextPanel = currentPanel.next();
418
+ var currentPosition = currentPanel.position;
419
+ var nextPosition = (_a = nextPanel === null || nextPanel === void 0 ? void 0 : nextPanel.position) !== null && _a !== void 0 ? _a : range.max;
420
+ var prevPosition = (_b = prevPanel === null || prevPanel === void 0 ? void 0 : prevPanel.position) !== null && _b !== void 0 ? _b : range.min; // circular: prev (last) > cur (0) => prev(-1) < cur(0)
421
+
422
+ if (prevPosition > currentPosition) {
423
+ prevPosition = range.min - (range.max - prevPosition);
424
+ } // current (last) > next (0)
425
+
426
+
427
+ if (nextPosition < currentPosition) {
428
+ nextPosition += range.max;
429
+ }
430
+
431
+ if (direction === flicking.DIRECTION.NEXT) {
432
+ // prev - cur - camera - next
433
+ var size = nextPosition - currentPosition;
434
+ var restSize = nextPosition - cameraPosition;
435
+
436
+ if (cameraPosition < currentPosition) {
437
+ // prev - camera - cur - next
438
+ restSize = nextPosition - cameraPosition;
439
+ }
440
+
441
+ animationDuration *= restSize / size;
442
+ } else {
443
+ // prev - caemra - cur - next
444
+ var size = currentPosition - prevPosition;
445
+ var restSize = cameraPosition - prevPosition;
446
+
447
+ if (cameraPosition > currentPosition) {
448
+ // prev - cur - camera - next
449
+ restSize = cameraPosition - prevPosition;
450
+ }
451
+
452
+ animationDuration *= restSize / size;
453
+ }
454
+ }
455
+
404
456
  if (direction === flicking.DIRECTION.NEXT) {
405
- flicking$1.next(_this._animationDuration).catch(function () {
457
+ flicking$1.next(animationDuration).catch(function () {
406
458
  return void 0;
407
459
  });
408
460
  } else {
409
- flicking$1.prev(_this._animationDuration).catch(function () {
461
+ flicking$1.prev(animationDuration).catch(function () {
410
462
  return void 0;
411
463
  });
412
464
  }
@@ -1199,6 +1251,39 @@ version: 4.6.0
1199
1251
  this._wrapper = wrapper;
1200
1252
  }
1201
1253
 
1254
+ var __proto = Renderer.prototype;
1255
+
1256
+ __proto._createBulletFromString = function (html, index) {
1257
+ var range = document.createRange();
1258
+ var frag = range.createContextualFragment(html);
1259
+ var bullet = frag.firstChild;
1260
+
1261
+ this._addBulletEvents(bullet, index);
1262
+
1263
+ return bullet;
1264
+ };
1265
+
1266
+ __proto._addBulletEvents = function (bullet, index) {
1267
+ var _this = this;
1268
+
1269
+ var anchorPoints = this._flicking.camera.anchorPoints;
1270
+ var panelIndex = anchorPoints[index].panel.index;
1271
+ bullet.addEventListener(BROWSER.MOUSE_DOWN, function (e) {
1272
+ e.stopPropagation();
1273
+ });
1274
+ bullet.addEventListener(BROWSER.TOUCH_START, function (e) {
1275
+ e.stopPropagation();
1276
+ }, {
1277
+ passive: true
1278
+ });
1279
+ bullet.addEventListener(BROWSER.CLICK, function () {
1280
+ _this._flicking.moveTo(panelIndex).catch(function (err) {
1281
+ if (err instanceof flicking.FlickingError) return;
1282
+ throw err;
1283
+ });
1284
+ });
1285
+ };
1286
+
1202
1287
  return Renderer;
1203
1288
  }();
1204
1289
 
@@ -1210,64 +1295,112 @@ version: 4.6.0
1210
1295
  function BulletRenderer() {
1211
1296
  var _this = _super !== null && _super.apply(this, arguments) || this;
1212
1297
 
1213
- _this._childs = [];
1298
+ _this._bullets = [];
1299
+ _this._prevIndex = -1;
1214
1300
  return _this;
1215
1301
  }
1216
1302
 
1217
1303
  var __proto = BulletRenderer.prototype;
1304
+ Object.defineProperty(__proto, "_bulletClass", {
1305
+ get: function () {
1306
+ var pagination = this._pagination;
1307
+ return pagination.classPrefix + "-" + PAGINATION.BULLET_SUFFIX;
1308
+ },
1309
+ enumerable: false,
1310
+ configurable: true
1311
+ });
1312
+ Object.defineProperty(__proto, "_activeClass", {
1313
+ get: function () {
1314
+ var pagination = this._pagination;
1315
+ return pagination.classPrefix + "-" + PAGINATION.BULLET_ACTIVE_SUFFIX;
1316
+ },
1317
+ enumerable: false,
1318
+ configurable: true
1319
+ });
1320
+
1321
+ __proto.destroy = function () {
1322
+ this._bullets = [];
1323
+ this._prevIndex = -1;
1324
+ };
1218
1325
 
1219
1326
  __proto.render = function () {
1220
- var flicking$1 = this._flicking;
1327
+ var _this = this;
1328
+
1329
+ var flicking = this._flicking;
1221
1330
  var pagination = this._pagination;
1331
+ var wrapper = this._wrapper;
1332
+ var bulletClass = this._bulletClass;
1333
+ var activeClass = this._activeClass;
1222
1334
  var renderBullet = pagination.renderBullet;
1335
+ var renderActiveBullet = pagination.renderActiveBullet;
1223
1336
  var bulletWrapperClass = pagination.classPrefix + "-" + PAGINATION.BULLET_WRAPPER_SUFFIX;
1224
- var bulletClass = pagination.classPrefix + "-" + PAGINATION.BULLET_SUFFIX;
1225
- var bulletActiveClass = pagination.classPrefix + "-" + PAGINATION.BULLET_ACTIVE_SUFFIX;
1226
- var anchorPoints = flicking$1.camera.anchorPoints;
1227
- var wrapper = this._wrapper;
1337
+ var anchorPoints = flicking.camera.anchorPoints;
1228
1338
  addClass(wrapper, bulletWrapperClass);
1229
- wrapper.innerHTML = anchorPoints.map(function (_, index) {
1230
- return renderBullet(bulletClass, index);
1339
+ wrapper.innerHTML = anchorPoints.map(function (anchorPoint, index) {
1340
+ if (renderActiveBullet && anchorPoint.panel.index === flicking.index) {
1341
+ return renderActiveBullet(bulletClass, index);
1342
+ } else {
1343
+ return renderBullet(bulletClass, index);
1344
+ }
1231
1345
  }).join("\n");
1232
1346
  var bullets = [].slice.call(wrapper.children);
1233
1347
  bullets.forEach(function (bullet, index) {
1234
1348
  var anchorPoint = anchorPoints[index];
1235
1349
 
1236
- if (anchorPoint.panel.index === flicking$1.index) {
1237
- addClass(bullet, bulletActiveClass);
1350
+ if (anchorPoint.panel.index === flicking.index) {
1351
+ addClass(bullet, activeClass);
1352
+ _this._prevIndex = index;
1238
1353
  }
1239
1354
 
1240
- bullet.addEventListener(BROWSER.MOUSE_DOWN, function (e) {
1241
- e.stopPropagation();
1242
- });
1243
- bullet.addEventListener(BROWSER.TOUCH_START, function (e) {
1244
- e.stopPropagation();
1245
- }, {
1246
- passive: true
1247
- });
1248
- bullet.addEventListener(BROWSER.CLICK, function () {
1249
- flicking$1.moveTo(anchorPoint.panel.index).catch(function (err) {
1250
- if (err instanceof flicking.FlickingError) return;
1251
- throw err;
1252
- });
1253
- });
1355
+ _this._addBulletEvents(bullet, index);
1254
1356
  });
1255
- this._childs = bullets;
1357
+ this._bullets = bullets;
1256
1358
  };
1257
1359
 
1258
1360
  __proto.update = function (index) {
1259
1361
  var flicking = this._flicking;
1260
1362
  var pagination = this._pagination;
1261
- var bullets = this._childs;
1262
- var activeClass = pagination.classPrefix + "-" + PAGINATION.BULLET_ACTIVE_SUFFIX;
1363
+ var wrapper = this._wrapper;
1364
+ var bullets = this._bullets;
1365
+ var bulletClass = this._bulletClass;
1366
+ var activeClass = this._activeClass;
1367
+ var prevIndex = this._prevIndex;
1263
1368
  var anchorPoints = flicking.camera.anchorPoints;
1369
+ var renderBullet = pagination.renderBullet;
1370
+ var renderActiveBullet = pagination.renderActiveBullet;
1264
1371
  if (anchorPoints.length <= 0) return;
1265
- bullets.forEach(function (bullet) {
1266
- removeClass(bullet, activeClass);
1267
- });
1268
1372
  var anchorOffset = anchorPoints[0].panel.index;
1269
- var activeBullet = bullets[index - anchorOffset];
1270
- addClass(activeBullet, activeClass);
1373
+ var activeBulletIndex = index - anchorOffset;
1374
+ if (prevIndex === activeBulletIndex) return;
1375
+
1376
+ if (renderActiveBullet) {
1377
+ var prevBullet = bullets[prevIndex];
1378
+
1379
+ if (prevBullet) {
1380
+ var newBullet = this._createBulletFromString(renderBullet(bulletClass, prevIndex), prevIndex);
1381
+
1382
+ prevBullet.parentElement.replaceChild(newBullet, prevBullet);
1383
+ bullets[prevIndex] = newBullet;
1384
+ }
1385
+
1386
+ var activeBullet = bullets[activeBulletIndex];
1387
+
1388
+ var newActiveBullet = this._createBulletFromString(renderActiveBullet(bulletClass + " " + activeClass, activeBulletIndex), activeBulletIndex);
1389
+
1390
+ wrapper.replaceChild(newActiveBullet, activeBullet);
1391
+ bullets[activeBulletIndex] = newActiveBullet;
1392
+ } else {
1393
+ var activeBullet = bullets[activeBulletIndex];
1394
+ var prevBullet = bullets[prevIndex];
1395
+
1396
+ if (prevBullet) {
1397
+ removeClass(prevBullet, activeClass);
1398
+ }
1399
+
1400
+ addClass(activeBullet, activeClass);
1401
+ }
1402
+
1403
+ this._prevIndex = activeBulletIndex;
1271
1404
  };
1272
1405
 
1273
1406
  return BulletRenderer;
@@ -1279,11 +1412,20 @@ version: 4.6.0
1279
1412
  __extends(FractionRenderer, _super);
1280
1413
 
1281
1414
  function FractionRenderer() {
1282
- return _super !== null && _super.apply(this, arguments) || this;
1415
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1416
+
1417
+ _this._prevIndex = -1;
1418
+ _this._prevTotal = -1;
1419
+ return _this;
1283
1420
  }
1284
1421
 
1285
1422
  var __proto = FractionRenderer.prototype;
1286
1423
 
1424
+ __proto.destroy = function () {
1425
+ this._prevIndex = -1;
1426
+ this._prevTotal = -1;
1427
+ };
1428
+
1287
1429
  __proto.render = function () {
1288
1430
  var flicking = this._flicking;
1289
1431
  var wrapper = this._wrapper;
@@ -1300,14 +1442,18 @@ version: 4.6.0
1300
1442
  var flicking = this._flicking;
1301
1443
  var wrapper = this._wrapper;
1302
1444
  var pagination = this._pagination;
1303
- var fractionCurrentClass = pagination.classPrefix + "-" + PAGINATION.FRACTION_CURRENT_SUFFIX;
1304
- var fractionTotalClass = pagination.classPrefix + "-" + PAGINATION.FRACTION_TOTAL_SUFFIX;
1305
- var currentWrapper = wrapper.querySelector("." + fractionCurrentClass);
1306
- var totalWrapper = wrapper.querySelector("." + fractionTotalClass);
1307
1445
  var anchorPoints = flicking.camera.anchorPoints;
1308
1446
  var currentIndex = anchorPoints.length > 0 ? index - anchorPoints[0].panel.index + 1 : 0;
1447
+ var anchorCount = anchorPoints.length;
1448
+ if (currentIndex === this._prevIndex && anchorCount === this._prevTotal) return;
1449
+ var fractionCurrentSelector = "." + pagination.classPrefix + "-" + PAGINATION.FRACTION_CURRENT_SUFFIX;
1450
+ var fractionTotalSelector = "." + pagination.classPrefix + "-" + PAGINATION.FRACTION_TOTAL_SUFFIX;
1451
+ var currentWrapper = wrapper.querySelector(fractionCurrentSelector);
1452
+ var totalWrapper = wrapper.querySelector(fractionTotalSelector);
1309
1453
  currentWrapper.innerHTML = pagination.fractionCurrentFormat(currentIndex);
1310
- totalWrapper.innerHTML = pagination.fractionTotalFormat(anchorPoints.length);
1454
+ totalWrapper.innerHTML = pagination.fractionTotalFormat(anchorCount);
1455
+ this._prevIndex = currentIndex;
1456
+ this._prevTotal = anchorCount;
1311
1457
  };
1312
1458
 
1313
1459
  return FractionRenderer;
@@ -1340,12 +1486,21 @@ version: 4.6.0
1340
1486
 
1341
1487
  var __proto = ScrollBulletRenderer.prototype;
1342
1488
 
1489
+ __proto.destroy = function () {
1490
+ this._bullets = [];
1491
+ this._bulletSize = 0;
1492
+ this._previousIndex = -1;
1493
+ this._sliderIndex = -1;
1494
+ };
1495
+
1343
1496
  __proto.render = function () {
1497
+ var _this = this;
1498
+
1344
1499
  var wrapper = this._wrapper;
1345
- var flicking$1 = this._flicking;
1500
+ var flicking = this._flicking;
1346
1501
  var pagination = this._pagination;
1347
1502
  var renderBullet = pagination.renderBullet;
1348
- var anchorPoints = flicking$1.camera.anchorPoints;
1503
+ var anchorPoints = flicking.camera.anchorPoints;
1349
1504
  var dynamicWrapperClass = pagination.classPrefix + "-" + PAGINATION.SCROLL_WRAPPER_SUFFIX;
1350
1505
  var bulletClass = pagination.classPrefix + "-" + PAGINATION.BULLET_SUFFIX;
1351
1506
  var sliderClass = pagination.classPrefix + "-" + PAGINATION.SCROLL_SLIDER_SUFFIX;
@@ -1360,21 +1515,7 @@ version: 4.6.0
1360
1515
  }).join("\n");
1361
1516
  var bullets = [].slice.call(sliderEl.children);
1362
1517
  bullets.forEach(function (bullet, index) {
1363
- var anchorPoint = anchorPoints[index];
1364
- bullet.addEventListener(BROWSER.MOUSE_DOWN, function (e) {
1365
- e.stopPropagation();
1366
- });
1367
- bullet.addEventListener(BROWSER.TOUCH_START, function (e) {
1368
- e.stopPropagation();
1369
- }, {
1370
- passive: true
1371
- });
1372
- bullet.addEventListener(BROWSER.CLICK, function () {
1373
- flicking$1.moveTo(anchorPoint.panel.index).catch(function (err) {
1374
- if (err instanceof flicking.FlickingError) return;
1375
- throw err;
1376
- });
1377
- });
1518
+ _this._addBulletEvents(bullet, index);
1378
1519
  });
1379
1520
  if (bullets.length <= 0) return;
1380
1521
  var bulletStyle = getComputedStyle(bullets[0]);
@@ -1382,6 +1523,7 @@ version: 4.6.0
1382
1523
  wrapper.style.width = bulletSize * pagination.bulletCount + "px";
1383
1524
  this._bullets = bullets;
1384
1525
  this._bulletSize = bulletSize;
1526
+ this._previousIndex = -1;
1385
1527
  this.update(this._flicking.index);
1386
1528
  window.requestAnimationFrame(function () {
1387
1529
  removeClass(wrapper, uninitClass);
@@ -1393,10 +1535,13 @@ version: 4.6.0
1393
1535
  var flicking$1 = this._flicking;
1394
1536
  var bullets = this._bullets;
1395
1537
  var prevIndex = this._previousIndex;
1538
+ var renderBullet = pagination.renderBullet;
1539
+ var renderActiveBullet = pagination.renderActiveBullet;
1396
1540
  var anchorPoints = flicking$1.camera.anchorPoints;
1397
1541
  var anchorOffset = anchorPoints[0].panel.index;
1398
1542
  var activeIndex = index - anchorOffset;
1399
1543
  if (anchorPoints.length <= 0) return;
1544
+ var bulletClass = pagination.classPrefix + "-" + PAGINATION.BULLET_SUFFIX;
1400
1545
  var bulletActiveClass = pagination.classPrefix + "-" + PAGINATION.BULLET_ACTIVE_SUFFIX;
1401
1546
  var prevClassPrefix = pagination.classPrefix + "-" + PAGINATION.SCROLL_PREV_SUFFIX;
1402
1547
  var nextClassPrefix = pagination.classPrefix + "-" + PAGINATION.SCROLL_NEXT_SUFFIX;
@@ -1411,6 +1556,27 @@ version: 4.6.0
1411
1556
 
1412
1557
  var prevClassRegex = new RegExp("^" + prevClassPrefix);
1413
1558
  var nextClassRegex = new RegExp("^" + nextClassPrefix);
1559
+
1560
+ if (renderActiveBullet) {
1561
+ var prevBullet = bullets[prevIndex];
1562
+
1563
+ if (prevBullet) {
1564
+ var newBullet = this._createBulletFromString(renderBullet(bulletClass, prevIndex), prevIndex);
1565
+
1566
+ prevBullet.parentElement.replaceChild(newBullet, prevBullet);
1567
+ bullets[prevIndex] = newBullet;
1568
+ }
1569
+
1570
+ var activeBullet = bullets[activeIndex];
1571
+
1572
+ if (activeBullet) {
1573
+ var newActiveBullet = this._createBulletFromString(renderActiveBullet(bulletClass, activeIndex), activeIndex);
1574
+
1575
+ activeBullet.parentElement.replaceChild(newActiveBullet, activeBullet);
1576
+ bullets[activeIndex] = newActiveBullet;
1577
+ }
1578
+ }
1579
+
1414
1580
  bullets.forEach(function (bullet, idx) {
1415
1581
  var indexOffset = idx - activeIndex;
1416
1582
  var classList = bullet.className.split(" ");
@@ -1470,22 +1636,24 @@ version: 4.6.0
1470
1636
  renderBullet = _h === void 0 ? function (className) {
1471
1637
  return "<span class=\"" + className + "\"></span>";
1472
1638
  } : _h,
1473
- _j = _b.renderFraction,
1474
- renderFraction = _j === void 0 ? function (currentClass, totalClass) {
1639
+ _j = _b.renderActiveBullet,
1640
+ renderActiveBullet = _j === void 0 ? null : _j,
1641
+ _k = _b.renderFraction,
1642
+ renderFraction = _k === void 0 ? function (currentClass, totalClass) {
1475
1643
  return "<span class=\"" + currentClass + "\"></span>/<span class=\"" + totalClass + "\"></span>";
1476
- } : _j,
1477
- _k = _b.fractionCurrentFormat,
1478
- fractionCurrentFormat = _k === void 0 ? function (index) {
1479
- return index.toString();
1480
1644
  } : _k,
1481
- _l = _b.fractionTotalFormat,
1482
- fractionTotalFormat = _l === void 0 ? function (index) {
1645
+ _l = _b.fractionCurrentFormat,
1646
+ fractionCurrentFormat = _l === void 0 ? function (index) {
1483
1647
  return index.toString();
1484
1648
  } : _l,
1485
- _m = _b.scrollOnChange,
1486
- scrollOnChange = _m === void 0 ? function (index, ctx) {
1649
+ _m = _b.fractionTotalFormat,
1650
+ fractionTotalFormat = _m === void 0 ? function (index) {
1651
+ return index.toString();
1652
+ } : _m,
1653
+ _o = _b.scrollOnChange,
1654
+ scrollOnChange = _o === void 0 ? function (index, ctx) {
1487
1655
  return ctx.moveTo(index);
1488
- } : _m;
1656
+ } : _o;
1489
1657
  /* Internal Values */
1490
1658
 
1491
1659
 
@@ -1507,6 +1675,7 @@ version: 4.6.0
1507
1675
  this._classPrefix = classPrefix;
1508
1676
  this._bulletCount = bulletCount;
1509
1677
  this._renderBullet = renderBullet;
1678
+ this._renderActiveBullet = renderActiveBullet;
1510
1679
  this._renderFraction = renderFraction;
1511
1680
  this._fractionCurrentFormat = fractionCurrentFormat;
1512
1681
  this._fractionTotalFormat = fractionTotalFormat;
@@ -1571,6 +1740,16 @@ version: 4.6.0
1571
1740
  enumerable: false,
1572
1741
  configurable: true
1573
1742
  });
1743
+ Object.defineProperty(__proto, "renderActiveBullet", {
1744
+ get: function () {
1745
+ return this._renderActiveBullet;
1746
+ },
1747
+ set: function (val) {
1748
+ this._renderActiveBullet = val;
1749
+ },
1750
+ enumerable: false,
1751
+ configurable: true
1752
+ });
1574
1753
  Object.defineProperty(__proto, "renderFraction", {
1575
1754
  get: function () {
1576
1755
  return this._renderFraction;
@@ -1653,6 +1832,8 @@ version: 4.6.0
1653
1832
  flicking$1.off(flicking.EVENTS.WILL_RESTORE, this._onIndexChange);
1654
1833
  flicking$1.off(flicking.EVENTS.PANEL_CHANGE, this.update);
1655
1834
 
1835
+ this._renderer.destroy();
1836
+
1656
1837
  this._removeAllChilds();
1657
1838
 
1658
1839
  this._flicking = null;