@egjs/flicking 4.13.2-beta.0 → 4.13.2-beta.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.
@@ -4,7 +4,7 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.13.2-beta.0
7
+ version: 4.13.2-beta.1
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -1094,6 +1094,9 @@ version: 4.13.2-beta.0
1094
1094
  };
1095
1095
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1096
1096
  var getStyle = function (el) {
1097
+ if (!el) {
1098
+ return {};
1099
+ }
1097
1100
  return window.getComputedStyle(el) || el.currentStyle;
1098
1101
  };
1099
1102
  var setSize = function (el, _a) {
@@ -1401,13 +1404,59 @@ version: 4.13.2-beta.0
1401
1404
  return Viewport;
1402
1405
  }();
1403
1406
 
1407
+ /*
1408
+ * Copyright (c) 2015 NAVER Corp.
1409
+ * egjs projects are licensed under the MIT license
1410
+ */
1411
+ /**
1412
+ * A component that detects size change and trigger resize method when the autoResize option is used
1413
+ * @ko autoResize 옵션을 사용할 때 크기 변화를 감지하고 Flicking의 resize를 호출하는 컴포넌트
1414
+ */
1404
1415
  var AutoResizer = /*#__PURE__*/function () {
1405
1416
  function AutoResizer(flicking) {
1406
1417
  var _this = this;
1407
- this._onResize = function () {
1418
+ this._onResizeWrapper = function () {
1419
+ _this._onResize([]);
1420
+ };
1421
+ this._onResize = function (entries) {
1408
1422
  var flicking = _this._flicking;
1409
1423
  var resizeDebounce = flicking.resizeDebounce;
1410
1424
  var maxResizeDebounce = flicking.maxResizeDebounce;
1425
+ var resizedViewportElement = flicking.element;
1426
+ // 현재 구현에서 리사이즈 옵저빙 대상은 패널과 뷰포트 2개만 존재.
1427
+ // 아래는 뷰포트만 변경되었을 때 동작해야하는 로직이 있으므로 아래와 같이 조건문을 건다.
1428
+ // 패널 쪽에서는 리사이즈 감지에 resizeObserver를 사용하지 않는 경우가 없으므로 이 조건은 곧 뷰포트만 리사이즈가 된 경우를 의미한다.
1429
+ var isResizedViewportOnly = entries.find(function (e) {
1430
+ return e.target === flicking.element;
1431
+ }) && entries.length === 1;
1432
+ // 참고: resizeObserver를 사용하지 않은 경우에는 entries.length가 0으로 오는데 이 경우에는 그냥 항상 리사이즈가 진행되도록 한다.
1433
+ // (vw, vh 등을 사용하는 경우 이상 동작이 발생할 여지가 있기 때문이다)
1434
+ if (isResizedViewportOnly) {
1435
+ // resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
1436
+ var beforeSize = {
1437
+ width: flicking.viewport.width,
1438
+ height: flicking.viewport.height
1439
+ };
1440
+ var afterSize = {
1441
+ width: getElementSize({
1442
+ el: resizedViewportElement,
1443
+ horizontal: true,
1444
+ useFractionalSize: _this._flicking.useFractionalSize,
1445
+ useOffset: false,
1446
+ style: getStyle(resizedViewportElement)
1447
+ }),
1448
+ height: getElementSize({
1449
+ el: resizedViewportElement,
1450
+ horizontal: false,
1451
+ useFractionalSize: _this._flicking.useFractionalSize,
1452
+ useOffset: false,
1453
+ style: getStyle(resizedViewportElement)
1454
+ })
1455
+ };
1456
+ if (beforeSize.height === afterSize.height && beforeSize.width === afterSize.width) {
1457
+ return;
1458
+ }
1459
+ }
1411
1460
  if (resizeDebounce <= 0) {
1412
1461
  void flicking.resize();
1413
1462
  } else {
@@ -1433,12 +1482,12 @@ version: 4.13.2-beta.0
1433
1482
  // eslint-disable-next-line @typescript-eslint/member-ordering
1434
1483
  this._skipFirstResize = function () {
1435
1484
  var isFirstResize = true;
1436
- return function () {
1485
+ return function (entries) {
1437
1486
  if (isFirstResize) {
1438
1487
  isFirstResize = false;
1439
1488
  return;
1440
1489
  }
1441
- _this._onResize();
1490
+ _this._onResize(entries);
1442
1491
  };
1443
1492
  }();
1444
1493
  this._flicking = flicking;
@@ -1464,14 +1513,46 @@ version: 4.13.2-beta.0
1464
1513
  if (flicking.useResizeObserver && !!window.ResizeObserver) {
1465
1514
  var viewportSizeNot0 = viewport.width !== 0 || viewport.height !== 0;
1466
1515
  var resizeObserver = viewportSizeNot0 ? new ResizeObserver(this._skipFirstResize) : new ResizeObserver(this._onResize);
1467
- resizeObserver.observe(flicking.viewport.element);
1468
1516
  this._resizeObserver = resizeObserver;
1517
+ this.observe(flicking.viewport.element);
1518
+ if (flicking.observePanelResize) {
1519
+ this.observePanels();
1520
+ }
1469
1521
  } else {
1470
- window.addEventListener("resize", this._onResize);
1522
+ window.addEventListener("resize", this._onResizeWrapper);
1471
1523
  }
1472
1524
  this._enabled = true;
1473
1525
  return this;
1474
1526
  };
1527
+ __proto.observePanels = function () {
1528
+ var _this = this;
1529
+ this._flicking.panels.forEach(function (panel) {
1530
+ _this.observe(panel.element);
1531
+ });
1532
+ return this;
1533
+ };
1534
+ __proto.unobservePanels = function () {
1535
+ var _this = this;
1536
+ this._flicking.panels.forEach(function (panel) {
1537
+ _this.unobserve(panel.element);
1538
+ });
1539
+ return this;
1540
+ };
1541
+ __proto.observe = function (element) {
1542
+ var resizeObserver = this._resizeObserver;
1543
+ if (!resizeObserver) return this;
1544
+ resizeObserver.observe(element);
1545
+ return this;
1546
+ };
1547
+ __proto.unobserve = function (element) {
1548
+ var resizeObserver = this._resizeObserver;
1549
+ if (!resizeObserver) return this;
1550
+ resizeObserver.unobserve(element);
1551
+ if (this._flicking.observePanelResize) {
1552
+ this.unobservePanels();
1553
+ }
1554
+ return this;
1555
+ };
1475
1556
  __proto.disable = function () {
1476
1557
  if (!this._enabled) return this;
1477
1558
  var resizeObserver = this._resizeObserver;
@@ -1479,7 +1560,7 @@ version: 4.13.2-beta.0
1479
1560
  resizeObserver.disconnect();
1480
1561
  this._resizeObserver = null;
1481
1562
  } else {
1482
- window.removeEventListener("resize", this._onResize);
1563
+ window.removeEventListener("resize", this._onResizeWrapper);
1483
1564
  }
1484
1565
  this._enabled = false;
1485
1566
  return this;
@@ -7143,11 +7224,7 @@ version: 4.13.2-beta.0
7143
7224
  if (snapDelta >= snapThreshold && snapDelta > 0) {
7144
7225
  // Move to anchor at position
7145
7226
  targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
7146
- // const targetPanel = targetAnchor.panel;
7147
- // const nextPosition = this._getPosition(targetPanel, DIRECTION.NEXT);
7148
- // const prevPosition = this._getPosition(targetPanel, DIRECTION.PREV);
7149
- // targetPosition = Math.abs(camera.position - nextPosition) < Math.abs(camera.position - prevPosition) ? nextPosition : prevPosition;
7150
- } else if (absPosDelta >= flicking.threshold && absPosDelta > 0 && anchorAtCamera === activeAnchor) {
7227
+ } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
7151
7228
  // Move to the adjacent panel
7152
7229
  targetAnchor = this._findAdjacentAnchor(position, posDelta, anchorAtCamera);
7153
7230
  } else {
@@ -7175,7 +7252,6 @@ version: 4.13.2-beta.0
7175
7252
  if (!anchorAtCamera || !anchorAtPosition) {
7176
7253
  throw new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE);
7177
7254
  }
7178
- // console.log("_findSnappedAnchor", anchorAtPosition);
7179
7255
  if (!isFinite(count)) {
7180
7256
  return anchorAtPosition;
7181
7257
  }
@@ -7617,7 +7693,10 @@ version: 4.13.2-beta.0
7617
7693
  };
7618
7694
  __proto.findAnchorIncludePosition = function (position) {
7619
7695
  var anchors = this._flicking.camera.anchorPoints;
7620
- return anchors.reduce(function (nearest, anchor) {
7696
+ var anchorsIncludingPosition = anchors.filter(function (anchor) {
7697
+ return anchor.panel.includePosition(position, true);
7698
+ });
7699
+ return anchorsIncludingPosition.reduce(function (nearest, anchor) {
7621
7700
  if (!nearest) return anchor;
7622
7701
  return Math.abs(nearest.position - position) < Math.abs(anchor.position - position) ? nearest : anchor;
7623
7702
  }, null);
@@ -9956,6 +10035,18 @@ version: 4.13.2-beta.0
9956
10035
  var activePanel = control.activePanel;
9957
10036
  // Update camera & control
9958
10037
  this._updateCameraAndControl();
10038
+ if (flicking.autoResize && flicking.useResizeObserver) {
10039
+ panelsAdded.forEach(function (panel) {
10040
+ if (panel.element) {
10041
+ flicking.autoResizer.observe(panel.element);
10042
+ }
10043
+ });
10044
+ panelsRemoved.forEach(function (panel) {
10045
+ if (panel.element) {
10046
+ flicking.autoResizer.unobserve(panel.element);
10047
+ }
10048
+ });
10049
+ }
9959
10050
  void this.render();
9960
10051
  if (!flicking.animating) {
9961
10052
  if (!activePanel || activePanel.removed) {
@@ -11247,18 +11338,23 @@ version: 4.13.2-beta.0
11247
11338
  useResizeObserver = _9 === void 0 ? true : _9,
11248
11339
  _10 = _b.resizeDebounce,
11249
11340
  resizeDebounce = _10 === void 0 ? 0 : _10,
11250
- _11 = _b.maxResizeDebounce,
11251
- maxResizeDebounce = _11 === void 0 ? 100 : _11,
11252
- _12 = _b.useFractionalSize,
11253
- useFractionalSize = _12 === void 0 ? false : _12,
11254
- _13 = _b.externalRenderer,
11255
- externalRenderer = _13 === void 0 ? null : _13,
11256
- _14 = _b.renderExternal,
11257
- renderExternal = _14 === void 0 ? null : _14;
11341
+ _11 = _b.observePanelResize,
11342
+ observePanelResize = _11 === void 0 ? false : _11,
11343
+ _12 = _b.maxResizeDebounce,
11344
+ maxResizeDebounce = _12 === void 0 ? 100 : _12,
11345
+ _13 = _b.useFractionalSize,
11346
+ useFractionalSize = _13 === void 0 ? false : _13,
11347
+ _14 = _b.externalRenderer,
11348
+ externalRenderer = _14 === void 0 ? null : _14,
11349
+ _15 = _b.renderExternal,
11350
+ renderExternal = _15 === void 0 ? null : _15,
11351
+ _16 = _b.optimizeSizeUpdate,
11352
+ optimizeSizeUpdate = _16 === void 0 ? false : _16;
11258
11353
  var _this = _super.call(this) || this;
11259
11354
  // Internal states
11260
11355
  _this._initialized = false;
11261
11356
  _this._plugins = [];
11357
+ _this._isResizing = false;
11262
11358
  // Bind options
11263
11359
  _this._align = align;
11264
11360
  _this._defaultIndex = defaultIndex;
@@ -11294,9 +11390,11 @@ version: 4.13.2-beta.0
11294
11390
  _this._useResizeObserver = useResizeObserver;
11295
11391
  _this._resizeDebounce = resizeDebounce;
11296
11392
  _this._maxResizeDebounce = maxResizeDebounce;
11393
+ _this._observePanelResize = observePanelResize;
11297
11394
  _this._useFractionalSize = useFractionalSize;
11298
11395
  _this._externalRenderer = externalRenderer;
11299
11396
  _this._renderExternal = renderExternal;
11397
+ _this._optimizeSizeUpdate = optimizeSizeUpdate;
11300
11398
  // Create core components
11301
11399
  _this._viewport = new Viewport(_this, getElement(root));
11302
11400
  _this._autoResizer = new AutoResizer(_this);
@@ -11377,6 +11475,19 @@ version: 4.13.2-beta.0
11377
11475
  enumerable: false,
11378
11476
  configurable: true
11379
11477
  });
11478
+ Object.defineProperty(__proto, "autoResizer", {
11479
+ /**
11480
+ * {@link AutoResizer} instance of the Flicking
11481
+ * @ko 현재 Flicking에 활성화된 {@link AutoResizer} 인스턴스
11482
+ * @internal
11483
+ * @readonly
11484
+ */
11485
+ get: function () {
11486
+ return this._autoResizer;
11487
+ },
11488
+ enumerable: false,
11489
+ configurable: true
11490
+ });
11380
11491
  Object.defineProperty(__proto, "initialized", {
11381
11492
  // Internal States
11382
11493
  /**
@@ -12250,6 +12361,9 @@ version: 4.13.2-beta.0
12250
12361
  // OTHERS
12251
12362
  set: function (val) {
12252
12363
  this._autoResize = val;
12364
+ if (!this._initialized) {
12365
+ return;
12366
+ }
12253
12367
  if (val) {
12254
12368
  this._autoResizer.enable();
12255
12369
  } else {
@@ -12272,13 +12386,38 @@ version: 4.13.2-beta.0
12272
12386
  },
12273
12387
  set: function (val) {
12274
12388
  this._useResizeObserver = val;
12275
- if (this._autoResize) {
12389
+ if (this._initialized && this._autoResize) {
12276
12390
  this._autoResizer.enable();
12277
12391
  }
12278
12392
  },
12279
12393
  enumerable: false,
12280
12394
  configurable: true
12281
12395
  });
12396
+ Object.defineProperty(__proto, "observePanelResize", {
12397
+ /**
12398
+ * Whether to use {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver} to observe the size of the panel element
12399
+ * This is only available when `useResizeObserver` is enabled.
12400
+ * This option garantees that the resize event is triggered when the size of the panel element is changed.
12401
+ * @ko 이 옵션을 활성화할 경우, {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver}를 사용하여 패널 엘리먼트의 크기를 추적합니다.
12402
+ * 이 옵션은 `useResizeObserver` 옵션이 활성화된 경우에만 사용할 수 있습니다.
12403
+ * 이 옵션은 패널 엘리먼트의 크기가 변경될 경우 resize 이벤트가 발생하도록 보장합니다.
12404
+ */
12405
+ get: function () {
12406
+ return this._observePanelResize;
12407
+ },
12408
+ set: function (val) {
12409
+ this._observePanelResize = val;
12410
+ if (this._initialized && this._autoResize) {
12411
+ if (val) {
12412
+ this._autoResizer.observePanels();
12413
+ } else {
12414
+ this._autoResizer.unobservePanels();
12415
+ }
12416
+ }
12417
+ },
12418
+ enumerable: false,
12419
+ configurable: true
12420
+ });
12282
12421
  Object.defineProperty(__proto, "resizeDebounce", {
12283
12422
  /**
12284
12423
  * Delays size recalculation from `autoResize` by the given time in milisecond.
@@ -12360,6 +12499,30 @@ version: 4.13.2-beta.0
12360
12499
  enumerable: false,
12361
12500
  configurable: true
12362
12501
  });
12502
+ Object.defineProperty(__proto, "optimizeSizeUpdate", {
12503
+ /**
12504
+ * This option works only when autoResize is set to true.
12505
+ * By default, autoResize listens to changes in both the viewport's width and height, updating all panel sizes accordingly.
12506
+ * When optimizeSizeUpdate is enabled, the update behavior is optimized based on the flicking direction:
12507
+ * If direction is "horizontal", only changes in width will trigger panel size updates.
12508
+ * If direction is "vertical", only changes in height will do so.
12509
+ * This option is useful when panel heights vary and unwanted flickering occurs due to frequent size recalculations during flicking. Enabling optimizeSizeUpdate prevents unnecessary updates and helps maintain visual stability.
12510
+ * @ko optimizeSizeUpdate는 autoResize가 true일 때만 동작합니다.
12511
+ * 기본적으로 autoResize는 뷰포트의 width와 height 변화를 모두 감지하여 패널들의 사이즈를 업데이트합니다.
12512
+ * 이 옵션을 활성화하면 플리킹 방향에 따라 필요한 차원(horizontal → width, vertical → height)에 대해서만 사이즈를 업데이트합니다.
12513
+ * 내부 패널의 높이가 서로 다를 때, 플리킹 중 과도한 리사이징으로 인한 깜빡임 현상을 줄이는 데 유용합니다.
12514
+ * @type {boolean}
12515
+ * @default false
12516
+ */
12517
+ get: function () {
12518
+ return this._optimizeSizeUpdate;
12519
+ },
12520
+ set: function (val) {
12521
+ this._optimizeSizeUpdate = val;
12522
+ },
12523
+ enumerable: false,
12524
+ configurable: true
12525
+ });
12363
12526
  /**
12364
12527
  * Initialize Flicking and move to the default index
12365
12528
  * This is automatically called on Flicking's constructor when `autoInit` is true(default)
@@ -12798,6 +12961,8 @@ version: 4.13.2-beta.0
12798
12961
  return __generator(this, function (_a) {
12799
12962
  switch (_a.label) {
12800
12963
  case 0:
12964
+ if (this._isResizing) return [2 /*return*/];
12965
+ this._isResizing = true;
12801
12966
  viewport = this._viewport;
12802
12967
  renderer = this._renderer;
12803
12968
  camera = this._camera;
@@ -12812,9 +12977,20 @@ version: 4.13.2-beta.0
12812
12977
  element: viewport.element
12813
12978
  }));
12814
12979
  viewport.resize();
12980
+ if (!this._optimizeSizeUpdate) return [3 /*break*/, 3];
12981
+ if (!(this.horizontal && viewport.width !== prevWidth || !this.horizontal && viewport.height !== prevHeight)) return [3 /*break*/, 2];
12815
12982
  return [4 /*yield*/, renderer.forceRenderAllPanels()];
12816
12983
  case 1:
12984
+ _a.sent();
12985
+ _a.label = 2;
12986
+ case 2:
12987
+ return [3 /*break*/, 5];
12988
+ case 3:
12989
+ return [4 /*yield*/, renderer.forceRenderAllPanels()];
12990
+ case 4:
12817
12991
  _a.sent(); // Render all panel elements, to update sizes
12992
+ _a.label = 5;
12993
+ case 5:
12818
12994
  if (!this._initialized) {
12819
12995
  return [2 /*return*/];
12820
12996
  }
@@ -12827,7 +13003,7 @@ version: 4.13.2-beta.0
12827
13003
  camera.updatePanelOrder();
12828
13004
  camera.updateOffset();
12829
13005
  return [4 /*yield*/, renderer.render()];
12830
- case 2:
13006
+ case 6:
12831
13007
  _a.sent();
12832
13008
  if (!this._initialized) {
12833
13009
  return [2 /*return*/];
@@ -12850,6 +13026,7 @@ version: 4.13.2-beta.0
12850
13026
  sizeChanged: sizeChanged,
12851
13027
  element: viewport.element
12852
13028
  }));
13029
+ this._isResizing = false;
12853
13030
  return [2 /*return*/];
12854
13031
  }
12855
13032
  });
@@ -13069,7 +13246,7 @@ version: 4.13.2-beta.0
13069
13246
  * Flicking.VERSION; // ex) 4.0.0
13070
13247
  * ```
13071
13248
  */
13072
- Flicking.VERSION = "4.13.2-beta.0";
13249
+ Flicking.VERSION = "4.13.2-beta.1";
13073
13250
  return Flicking;
13074
13251
  }(Component);
13075
13252