@egjs/flicking 4.12.1-beta.5 → 4.13.0

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.12.1-beta.5
7
+ version: 4.13.0
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -1094,6 +1094,9 @@ version: 4.12.1-beta.5
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) {
@@ -1405,41 +1408,53 @@ version: 4.12.1-beta.5
1405
1408
  * Copyright (c) 2015 NAVER Corp.
1406
1409
  * egjs projects are licensed under the MIT license
1407
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
+ */
1408
1415
  var AutoResizer = /*#__PURE__*/function () {
1416
+ /** */
1409
1417
  function AutoResizer(flicking) {
1410
1418
  var _this = this;
1419
+ this._onResizeWrapper = function () {
1420
+ _this._onResize([]);
1421
+ };
1411
1422
  this._onResize = function (entries) {
1412
1423
  var flicking = _this._flicking;
1413
1424
  var resizeDebounce = flicking.resizeDebounce;
1414
1425
  var maxResizeDebounce = flicking.maxResizeDebounce;
1415
- if (entries.length) {
1416
- var resizeEntryInfo = entries[0].contentRect;
1426
+ var resizedViewportElement = flicking.element;
1427
+ // 현재 구현에서 리사이즈 옵저빙 대상은 패널과 뷰포트 2개만 존재.
1428
+ // 아래는 뷰포트만 변경되었을 때 동작해야하는 로직이 있으므로 아래와 같이 조건문을 건다.
1429
+ // 패널 쪽에서는 리사이즈 감지에 resizeObserver를 사용하지 않는 경우가 없으므로 이 조건은 곧 뷰포트만 리사이즈가 된 경우를 의미한다.
1430
+ var isResizedViewportOnly = entries.find(function (e) {
1431
+ return e.target === flicking.element;
1432
+ }) && entries.length === 1;
1433
+ // 참고: resizeObserver를 사용하지 않은 경우에는 entries.length가 0으로 오는데 이 경우에는 그냥 항상 리사이즈가 진행되도록 한다.
1434
+ // (vw, vh 등을 사용하는 경우 이상 동작이 발생할 여지가 있기 때문이다)
1435
+ if (isResizedViewportOnly) {
1436
+ // resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
1417
1437
  var beforeSize = {
1418
1438
  width: flicking.viewport.width,
1419
1439
  height: flicking.viewport.height
1420
1440
  };
1421
- ({
1422
- width: resizeEntryInfo.width,
1423
- height: resizeEntryInfo.height
1424
- });
1425
- var new_afterSize = {
1441
+ var afterSize = {
1426
1442
  width: getElementSize({
1427
- el: entries[0].target,
1443
+ el: resizedViewportElement,
1428
1444
  horizontal: true,
1429
1445
  useFractionalSize: _this._flicking.useFractionalSize,
1430
1446
  useOffset: false,
1431
- style: getStyle(entries[0].target)
1447
+ style: getStyle(resizedViewportElement)
1432
1448
  }),
1433
1449
  height: getElementSize({
1434
- el: entries[0].target,
1450
+ el: resizedViewportElement,
1435
1451
  horizontal: false,
1436
1452
  useFractionalSize: _this._flicking.useFractionalSize,
1437
1453
  useOffset: false,
1438
- style: getStyle(entries[0].target)
1454
+ style: getStyle(resizedViewportElement)
1439
1455
  })
1440
1456
  };
1441
- // resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
1442
- if (beforeSize.height === new_afterSize.height && beforeSize.width === new_afterSize.width) {
1457
+ if (beforeSize.height === afterSize.height && beforeSize.width === afterSize.width) {
1443
1458
  return;
1444
1459
  }
1445
1460
  }
@@ -1491,7 +1506,6 @@ version: 4.12.1-beta.5
1491
1506
  configurable: true
1492
1507
  });
1493
1508
  __proto.enable = function () {
1494
- var _this = this;
1495
1509
  var flicking = this._flicking;
1496
1510
  var viewport = flicking.viewport;
1497
1511
  if (this._enabled) {
@@ -1499,32 +1513,55 @@ version: 4.12.1-beta.5
1499
1513
  }
1500
1514
  if (flicking.useResizeObserver && !!window.ResizeObserver) {
1501
1515
  var viewportSizeNot0 = viewport.width !== 0 || viewport.height !== 0;
1502
- var resizeObserver = viewportSizeNot0 ? new ResizeObserver(function (entries) {
1503
- return _this._skipFirstResize(entries);
1504
- }) : new ResizeObserver(function (entries) {
1505
- return _this._onResize(entries);
1506
- });
1507
- resizeObserver.observe(flicking.viewport.element);
1516
+ var resizeObserver = viewportSizeNot0 ? new ResizeObserver(this._skipFirstResize) : new ResizeObserver(this._onResize);
1508
1517
  this._resizeObserver = resizeObserver;
1518
+ this.observe(flicking.viewport.element);
1519
+ if (flicking.observePanelResize) {
1520
+ this.observePanels();
1521
+ }
1509
1522
  } else {
1510
- window.addEventListener("resize", function () {
1511
- return _this._onResize([]);
1512
- });
1523
+ window.addEventListener("resize", this._onResizeWrapper);
1513
1524
  }
1514
1525
  this._enabled = true;
1515
1526
  return this;
1516
1527
  };
1517
- __proto.disable = function () {
1528
+ __proto.observePanels = function () {
1529
+ var _this = this;
1530
+ this._flicking.panels.forEach(function (panel) {
1531
+ _this.observe(panel.element);
1532
+ });
1533
+ return this;
1534
+ };
1535
+ __proto.unobservePanels = function () {
1518
1536
  var _this = this;
1537
+ this._flicking.panels.forEach(function (panel) {
1538
+ _this.unobserve(panel.element);
1539
+ });
1540
+ return this;
1541
+ };
1542
+ __proto.observe = function (element) {
1543
+ var resizeObserver = this._resizeObserver;
1544
+ if (!resizeObserver) return this;
1545
+ resizeObserver.observe(element);
1546
+ return this;
1547
+ };
1548
+ __proto.unobserve = function (element) {
1549
+ var resizeObserver = this._resizeObserver;
1550
+ if (!resizeObserver) return this;
1551
+ resizeObserver.unobserve(element);
1552
+ if (this._flicking.observePanelResize) {
1553
+ this.unobservePanels();
1554
+ }
1555
+ return this;
1556
+ };
1557
+ __proto.disable = function () {
1519
1558
  if (!this._enabled) return this;
1520
1559
  var resizeObserver = this._resizeObserver;
1521
1560
  if (resizeObserver) {
1522
1561
  resizeObserver.disconnect();
1523
1562
  this._resizeObserver = null;
1524
1563
  } else {
1525
- window.removeEventListener("resize", function () {
1526
- return _this._onResize([]);
1527
- });
1564
+ window.removeEventListener("resize", this._onResizeWrapper);
1528
1565
  }
1529
1566
  this._enabled = false;
1530
1567
  return this;
@@ -9984,6 +10021,18 @@ version: 4.12.1-beta.5
9984
10021
  var activePanel = control.activePanel;
9985
10022
  // Update camera & control
9986
10023
  this._updateCameraAndControl();
10024
+ if (flicking.autoResize && flicking.useResizeObserver) {
10025
+ panelsAdded.forEach(function (panel) {
10026
+ if (panel.element) {
10027
+ flicking.autoResizer.observe(panel.element);
10028
+ }
10029
+ });
10030
+ panelsRemoved.forEach(function (panel) {
10031
+ if (panel.element) {
10032
+ flicking.autoResizer.unobserve(panel.element);
10033
+ }
10034
+ });
10035
+ }
9987
10036
  void this.render();
9988
10037
  if (!flicking.animating) {
9989
10038
  if (!activePanel || activePanel.removed) {
@@ -11275,16 +11324,18 @@ version: 4.12.1-beta.5
11275
11324
  useResizeObserver = _9 === void 0 ? true : _9,
11276
11325
  _10 = _b.resizeDebounce,
11277
11326
  resizeDebounce = _10 === void 0 ? 0 : _10,
11278
- _11 = _b.maxResizeDebounce,
11279
- maxResizeDebounce = _11 === void 0 ? 100 : _11,
11280
- _12 = _b.useFractionalSize,
11281
- useFractionalSize = _12 === void 0 ? false : _12,
11282
- _13 = _b.externalRenderer,
11283
- externalRenderer = _13 === void 0 ? null : _13,
11284
- _14 = _b.renderExternal,
11285
- renderExternal = _14 === void 0 ? null : _14,
11286
- _15 = _b.optimizeSizeUpdate,
11287
- optimizeSizeUpdate = _15 === void 0 ? false : _15;
11327
+ _11 = _b.observePanelResize,
11328
+ observePanelResize = _11 === void 0 ? false : _11,
11329
+ _12 = _b.maxResizeDebounce,
11330
+ maxResizeDebounce = _12 === void 0 ? 100 : _12,
11331
+ _13 = _b.useFractionalSize,
11332
+ useFractionalSize = _13 === void 0 ? false : _13,
11333
+ _14 = _b.externalRenderer,
11334
+ externalRenderer = _14 === void 0 ? null : _14,
11335
+ _15 = _b.renderExternal,
11336
+ renderExternal = _15 === void 0 ? null : _15,
11337
+ _16 = _b.optimizeSizeUpdate,
11338
+ optimizeSizeUpdate = _16 === void 0 ? false : _16;
11288
11339
  var _this = _super.call(this) || this;
11289
11340
  // Internal states
11290
11341
  _this._initialized = false;
@@ -11325,6 +11376,7 @@ version: 4.12.1-beta.5
11325
11376
  _this._useResizeObserver = useResizeObserver;
11326
11377
  _this._resizeDebounce = resizeDebounce;
11327
11378
  _this._maxResizeDebounce = maxResizeDebounce;
11379
+ _this._observePanelResize = observePanelResize;
11328
11380
  _this._useFractionalSize = useFractionalSize;
11329
11381
  _this._externalRenderer = externalRenderer;
11330
11382
  _this._renderExternal = renderExternal;
@@ -11409,6 +11461,19 @@ version: 4.12.1-beta.5
11409
11461
  enumerable: false,
11410
11462
  configurable: true
11411
11463
  });
11464
+ Object.defineProperty(__proto, "autoResizer", {
11465
+ /**
11466
+ * {@link AutoResizer} instance of the Flicking
11467
+ * @ko 현재 Flicking에 활성화된 {@link AutoResizer} 인스턴스
11468
+ * @internal
11469
+ * @readonly
11470
+ */
11471
+ get: function () {
11472
+ return this._autoResizer;
11473
+ },
11474
+ enumerable: false,
11475
+ configurable: true
11476
+ });
11412
11477
  Object.defineProperty(__proto, "initialized", {
11413
11478
  // Internal States
11414
11479
  /**
@@ -12282,6 +12347,9 @@ version: 4.12.1-beta.5
12282
12347
  // OTHERS
12283
12348
  set: function (val) {
12284
12349
  this._autoResize = val;
12350
+ if (!this._initialized) {
12351
+ return;
12352
+ }
12285
12353
  if (val) {
12286
12354
  this._autoResizer.enable();
12287
12355
  } else {
@@ -12304,13 +12372,38 @@ version: 4.12.1-beta.5
12304
12372
  },
12305
12373
  set: function (val) {
12306
12374
  this._useResizeObserver = val;
12307
- if (this._autoResize) {
12375
+ if (this._initialized && this._autoResize) {
12308
12376
  this._autoResizer.enable();
12309
12377
  }
12310
12378
  },
12311
12379
  enumerable: false,
12312
12380
  configurable: true
12313
12381
  });
12382
+ Object.defineProperty(__proto, "observePanelResize", {
12383
+ /**
12384
+ * Whether to use {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver} to observe the size of the panel element
12385
+ * This is only available when `useResizeObserver` is enabled.
12386
+ * This option garantees that the resize event is triggered when the size of the panel element is changed.
12387
+ * @ko 이 옵션을 활성화할 경우, {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver}를 사용하여 패널 엘리먼트의 크기를 추적합니다.
12388
+ * 이 옵션은 `useResizeObserver` 옵션이 활성화된 경우에만 사용할 수 있습니다.
12389
+ * 이 옵션은 패널 엘리먼트의 크기가 변경될 경우 resize 이벤트가 발생하도록 보장합니다.
12390
+ */
12391
+ get: function () {
12392
+ return this._observePanelResize;
12393
+ },
12394
+ set: function (val) {
12395
+ this._observePanelResize = val;
12396
+ if (this._initialized && this._autoResize) {
12397
+ if (val) {
12398
+ this._autoResizer.observePanels();
12399
+ } else {
12400
+ this._autoResizer.unobservePanels();
12401
+ }
12402
+ }
12403
+ },
12404
+ enumerable: false,
12405
+ configurable: true
12406
+ });
12314
12407
  Object.defineProperty(__proto, "resizeDebounce", {
12315
12408
  /**
12316
12409
  * Delays size recalculation from `autoResize` by the given time in milisecond.
@@ -12392,6 +12485,30 @@ version: 4.12.1-beta.5
12392
12485
  enumerable: false,
12393
12486
  configurable: true
12394
12487
  });
12488
+ Object.defineProperty(__proto, "optimizeSizeUpdate", {
12489
+ /**
12490
+ * This option works only when autoResize is set to true.
12491
+ * By default, autoResize listens to changes in both the viewport's width and height, updating all panel sizes accordingly.
12492
+ * When optimizeSizeUpdate is enabled, the update behavior is optimized based on the flicking direction:
12493
+ * If direction is "horizontal", only changes in width will trigger panel size updates.
12494
+ * If direction is "vertical", only changes in height will do so.
12495
+ * 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.
12496
+ * @ko optimizeSizeUpdate는 autoResize가 true일 때만 동작합니다.
12497
+ * 기본적으로 autoResize는 뷰포트의 width와 height 변화를 모두 감지하여 패널들의 사이즈를 업데이트합니다.
12498
+ * 이 옵션을 활성화하면 플리킹 방향에 따라 필요한 차원(horizontal → width, vertical → height)에 대해서만 사이즈를 업데이트합니다.
12499
+ * 내부 패널의 높이가 서로 다를 때, 플리킹 중 과도한 리사이징으로 인한 깜빡임 현상을 줄이는 데 유용합니다.
12500
+ * @type {boolean}
12501
+ * @default false
12502
+ */
12503
+ get: function () {
12504
+ return this._optimizeSizeUpdate;
12505
+ },
12506
+ set: function (val) {
12507
+ this._optimizeSizeUpdate = val;
12508
+ },
12509
+ enumerable: false,
12510
+ configurable: true
12511
+ });
12395
12512
  /**
12396
12513
  * Initialize Flicking and move to the default index
12397
12514
  * This is automatically called on Flicking's constructor when `autoInit` is true(default)
@@ -12850,7 +12967,7 @@ version: 4.12.1-beta.5
12850
12967
  if (!(this.horizontal && viewport.width !== prevWidth || !this.horizontal && viewport.height !== prevHeight)) return [3 /*break*/, 2];
12851
12968
  return [4 /*yield*/, renderer.forceRenderAllPanels()];
12852
12969
  case 1:
12853
- _a.sent(); // Render all panel elements, to update sizes
12970
+ _a.sent();
12854
12971
  _a.label = 2;
12855
12972
  case 2:
12856
12973
  return [3 /*break*/, 5];
@@ -13023,7 +13140,7 @@ version: 4.12.1-beta.5
13023
13140
  __proto._createCamera = function () {
13024
13141
  if (this._circular && this._bound) {
13025
13142
  // eslint-disable-next-line no-console
13026
- console.warn('"circular" and "bound" option cannot be used together, ignoring bound.');
13143
+ console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
13027
13144
  }
13028
13145
  return new Camera$1(this, {
13029
13146
  align: this._align
@@ -13033,7 +13150,7 @@ version: 4.12.1-beta.5
13033
13150
  var externalRenderer = this._externalRenderer;
13034
13151
  if (this._virtual && this._panelsPerView <= 0) {
13035
13152
  // eslint-disable-next-line no-console
13036
- console.warn('"virtual" and "panelsPerView" option should be used together, ignoring virtual.');
13153
+ console.warn("\"virtual\" and \"panelsPerView\" option should be used together, ignoring virtual.");
13037
13154
  }
13038
13155
  return externalRenderer ? externalRenderer : this._renderExternal ? this._createExternalRenderer() : this._createVanillaRenderer();
13039
13156
  };
@@ -13115,7 +13232,7 @@ version: 4.12.1-beta.5
13115
13232
  * Flicking.VERSION; // ex) 4.0.0
13116
13233
  * ```
13117
13234
  */
13118
- Flicking.VERSION = "4.12.1-beta.5";
13235
+ Flicking.VERSION = "4.13.0";
13119
13236
  return Flicking;
13120
13237
  }(Component);
13121
13238