@egjs/flicking 4.12.0-beta.0 → 4.12.0-beta.10

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/flicking.js CHANGED
@@ -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.0-beta.0
7
+ version: 4.12.0-beta.10
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready')) :
@@ -387,6 +387,8 @@ version: 4.12.0-beta.0
387
387
  STRICT: "strict"
388
388
  };
389
389
  var CLASS = {
390
+ VIEWPORT: "flicking-viewport",
391
+ CAMERA: "flicking-camera",
390
392
  VERTICAL: "vertical",
391
393
  HIDDEN: "flicking-hidden",
392
394
  DEFAULT_VIRTUAL: "flicking-panel"
@@ -413,6 +415,17 @@ version: 4.12.0-beta.0
413
415
  LTR: "ltr",
414
416
  RTL: "rtl"
415
417
  };
418
+ /**
419
+ * An object that contains the direction that {@link Flicking} is moving
420
+ * @ko {@link Flicking}이 움직이는 방향을 담고 있는 객체
421
+ * @type {object}
422
+ * @property {"horizontal"} HORIZONTAL horizontal<ko>수평 방향</ko>
423
+ * @property {"vertical"} VERTICAL vertical<ko>수직 방향</ko>
424
+ */
425
+ var MOVE_DIRECTION = {
426
+ HORIZONTAL: "horizontal",
427
+ VERTICAL: "vertical"
428
+ };
416
429
 
417
430
  var Constants = {
418
431
  __proto__: null,
@@ -423,6 +436,7 @@ version: 4.12.0-beta.0
423
436
  CLASS: CLASS,
424
437
  CIRCULAR_FALLBACK: CIRCULAR_FALLBACK,
425
438
  ORDER: ORDER,
439
+ MOVE_DIRECTION: MOVE_DIRECTION,
426
440
  ERROR_CODE: CODE
427
441
  };
428
442
 
@@ -739,6 +753,26 @@ version: 4.12.0-beta.0
739
753
  obj.__proto__ = proto;
740
754
  return obj;
741
755
  };
756
+ var camelize = function (str) {
757
+ return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
758
+ return letter.toUpperCase();
759
+ });
760
+ };
761
+ var getDataAttributes = function (element, attributePrefix) {
762
+ var dataAttributes = {};
763
+ var attributes = element.attributes;
764
+ var length = attributes.length;
765
+ for (var i = 0; i < length; ++i) {
766
+ var attribute = attributes[i];
767
+ var name_1 = attribute.name,
768
+ value = attribute.value;
769
+ if (name_1.indexOf(attributePrefix) === -1) {
770
+ continue;
771
+ }
772
+ dataAttributes[camelize(name_1.replace(attributePrefix, ""))] = value;
773
+ }
774
+ return dataAttributes;
775
+ };
742
776
 
743
777
  var Utils = {
744
778
  __proto__: null,
@@ -770,7 +804,9 @@ version: 4.12.0-beta.0
770
804
  circulateIndex: circulateIndex,
771
805
  range: range,
772
806
  getElementSize: getElementSize,
773
- setPrototypeOf: setPrototypeOf
807
+ setPrototypeOf: setPrototypeOf,
808
+ camelize: camelize,
809
+ getDataAttributes: getDataAttributes
774
810
  };
775
811
 
776
812
  /*
@@ -3779,6 +3815,7 @@ version: 4.12.0-beta.0
3779
3815
  var _this = this;
3780
3816
  var _b = (_a === void 0 ? {} : _a).align,
3781
3817
  align = _b === void 0 ? ALIGN.CENTER : _b;
3818
+ this._lookedOffset = 0;
3782
3819
  this._checkTranslateSupport = function () {
3783
3820
  var e_1, _a;
3784
3821
  var transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
@@ -4138,6 +4175,8 @@ version: 4.12.0-beta.0
4138
4175
  */
4139
4176
  __proto.lookAt = function (pos) {
4140
4177
  var _this = this;
4178
+ var prevOffset = this._offset;
4179
+ var isChangedOffset = this._lookedOffset !== prevOffset;
4141
4180
  var flicking = getFlickingAttached(this._flicking);
4142
4181
  var prevPos = this._position;
4143
4182
  this._position = pos;
@@ -4148,7 +4187,12 @@ version: 4.12.0-beta.0
4148
4187
  if (toggled) {
4149
4188
  void flicking.renderer.render().then(function () {
4150
4189
  _this.updateOffset();
4190
+ _this._lookedOffset = _this._offset;
4151
4191
  });
4192
+ } else if (isChangedOffset) {
4193
+ // sync offset for renderOnlyVisible on resize
4194
+ this.updateOffset();
4195
+ this._lookedOffset = this._offset;
4152
4196
  } else {
4153
4197
  this.applyTransform();
4154
4198
  }
@@ -4323,8 +4367,8 @@ version: 4.12.0-beta.0
4323
4367
  return this;
4324
4368
  };
4325
4369
  /**
4326
- * Update Viewport's height to active panel's height
4327
- * @ko 현재 선택된 패널의 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
4370
+ * Update Viewport's height to visible panel's max height
4371
+ * @ko 현재 활성화된 패널과 보이는 패널의 최대 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
4328
4372
  * @throws {FlickingError}
4329
4373
  * {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
4330
4374
  * <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
@@ -4334,9 +4378,17 @@ version: 4.12.0-beta.0
4334
4378
  __proto.updateAdaptiveHeight = function () {
4335
4379
  var flicking = getFlickingAttached(this._flicking);
4336
4380
  var activePanel = flicking.control.activePanel;
4337
- if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
4381
+ var visiblePanels = flicking.visiblePanels;
4382
+ var selectedPanels = __spread(visiblePanels);
4383
+ if (activePanel) {
4384
+ selectedPanels.push(activePanel);
4385
+ }
4386
+ if (!flicking.horizontal || !flicking.adaptive || !selectedPanels.length) return;
4387
+ var maxHeight = Math.max.apply(Math, __spread(selectedPanels.map(function (panel) {
4388
+ return panel.height;
4389
+ })));
4338
4390
  flicking.viewport.setSize({
4339
- height: activePanel.height
4391
+ height: maxHeight
4340
4392
  });
4341
4393
  };
4342
4394
  /**
@@ -4407,6 +4459,7 @@ version: 4.12.0-beta.0
4407
4459
  };
4408
4460
  __proto._resetInternalValues = function () {
4409
4461
  this._position = 0;
4462
+ this._lookedOffset = 0;
4410
4463
  this._alignPos = 0;
4411
4464
  this._offset = 0;
4412
4465
  this._circularOffset = 0;
@@ -7955,10 +8008,342 @@ version: 4.12.0-beta.0
7955
8008
  * Flicking.VERSION; // ex) 4.0.0
7956
8009
  * ```
7957
8010
  */
7958
- Flicking.VERSION = "4.12.0-beta.0";
8011
+ Flicking.VERSION = "4.12.0-beta.10";
7959
8012
  return Flicking;
7960
8013
  }(Component);
7961
8014
 
8015
+ var SIDE_EVENTS = {
8016
+ HOLD_START: "sideHoldStart",
8017
+ HOLD_END: "sideHoldEnd",
8018
+ MOVE_START: "sideMoveStart",
8019
+ MOVE: "sideMove",
8020
+ MOVE_END: "sideMoveEnd",
8021
+ WILL_CHANGE: "sideWillChange",
8022
+ CHANGED: "sideChanged"
8023
+ };
8024
+ var CrossFlicking = /*#__PURE__*/function (_super) {
8025
+ __extends(CrossFlicking, _super);
8026
+ function CrossFlicking(root, options) {
8027
+ var _this = _super.call(this, root, options) || this;
8028
+ _this._syncToCategory = function (index, outerIndex) {
8029
+ if (_this._disableIndexSync) {
8030
+ return;
8031
+ }
8032
+ _this.stopAnimation();
8033
+ _this._sideFlicking.forEach(function (child, i) {
8034
+ var _a = _this._sideState[i],
8035
+ start = _a.start,
8036
+ end = _a.end;
8037
+ if (start <= index && end >= index && outerIndex !== i) {
8038
+ child.stopAnimation();
8039
+ void child.moveTo(index, 0);
8040
+ void _this.moveTo(i, 0);
8041
+ }
8042
+ });
8043
+ };
8044
+ _this._setDraggable = function (direction, draggable) {
8045
+ if (!_this._disableSlideOnHold) {
8046
+ return;
8047
+ }
8048
+ var dragThreshold = _this._originalDragThreshold;
8049
+ var threshold = draggable ? dragThreshold && dragThreshold >= 10 ? dragThreshold : 10 : Infinity;
8050
+ if (direction === MOVE_DIRECTION.HORIZONTAL === _this.horizontal) {
8051
+ _this.dragThreshold = threshold;
8052
+ } else if (direction === MOVE_DIRECTION.VERTICAL === _this.horizontal) {
8053
+ _this._sideFlicking.forEach(function (child) {
8054
+ child.dragThreshold = threshold;
8055
+ });
8056
+ }
8057
+ };
8058
+ _this._setPreviousSideIndex = function () {
8059
+ _this._sideFlicking.forEach(function (child, i) {
8060
+ var _a = _this._sideState[i],
8061
+ start = _a.start,
8062
+ end = _a.end;
8063
+ if (_this._preserveIndex) {
8064
+ if (_this._nextIndex !== i) {
8065
+ if (child.index < start) {
8066
+ child.stopAnimation();
8067
+ void child.moveTo(start, 0);
8068
+ } else if (child.index > end) {
8069
+ child.stopAnimation();
8070
+ void child.moveTo(end, 0);
8071
+ }
8072
+ }
8073
+ } else {
8074
+ if (_this._nextIndex !== i) {
8075
+ void child.moveTo(start, 0);
8076
+ }
8077
+ }
8078
+ });
8079
+ };
8080
+ _this._onHorizontalHoldStart = function () {
8081
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
8082
+ _this._moveDirection = null;
8083
+ };
8084
+ _this._onHorizontalMove = function (e) {
8085
+ if (e.isTrusted && !_this._moveDirection) {
8086
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, false);
8087
+ _this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
8088
+ }
8089
+ };
8090
+ _this._onHorizontalMoveEnd = function (e) {
8091
+ var visiblePanels = _this.visiblePanels;
8092
+ if (visiblePanels.length > 1) {
8093
+ _this._nextIndex = e.direction === "NEXT" ? visiblePanels[1].index : visiblePanels[0].index;
8094
+ } else {
8095
+ _this._nextIndex = visiblePanels[0].index;
8096
+ }
8097
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
8098
+ _this._moveDirection = null;
8099
+ // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
8100
+ requestAnimationFrame(function () {
8101
+ return _this._setPreviousSideIndex();
8102
+ });
8103
+ if (e.isTrusted) {
8104
+ _this._syncToCategory(_this._sideFlicking[_this._nextIndex].index, _this._nextIndex);
8105
+ }
8106
+ };
8107
+ _this._onSideHoldStart = function () {
8108
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
8109
+ _this._moveDirection = null;
8110
+ };
8111
+ _this._onSideMove = function (e) {
8112
+ if (e.isTrusted && !_this._moveDirection) {
8113
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, false);
8114
+ _this._moveDirection = MOVE_DIRECTION.VERTICAL;
8115
+ }
8116
+ };
8117
+ _this._onSideMoveEnd = function () {
8118
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
8119
+ _this._moveDirection = null;
8120
+ };
8121
+ _this._onSideChanged = function (e) {
8122
+ // If this.visiblePanels.length >= 2, it means that horizontal flicking is being dragged.
8123
+ // In this case, syncToCategory in _onHorizontalMoveEnd will fire after moving finishes, so we don't fire it here.
8124
+ if (_this.visiblePanels.length < 2 && _this._sideFlicking[_this.index] === e.currentTarget) {
8125
+ _this._syncToCategory(e.index, _this.index);
8126
+ }
8127
+ };
8128
+ var _a = options.sideOptions,
8129
+ sideOptions = _a === void 0 ? {} : _a,
8130
+ _b = options.preserveIndex,
8131
+ preserveIndex = _b === void 0 ? true : _b,
8132
+ _c = options.disableSlideOnHold,
8133
+ disableSlideOnHold = _c === void 0 ? true : _c,
8134
+ _d = options.disableIndexSync,
8135
+ disableIndexSync = _d === void 0 ? false : _d;
8136
+ // Internal states
8137
+ _this._moveDirection = null;
8138
+ _this._nextIndex = 0;
8139
+ _this._originalDragThreshold = _this.dragThreshold;
8140
+ // Bind options
8141
+ _this._sideOptions = sideOptions;
8142
+ _this._preserveIndex = preserveIndex;
8143
+ _this._disableSlideOnHold = disableSlideOnHold;
8144
+ _this._disableIndexSync = disableIndexSync;
8145
+ return _this;
8146
+ }
8147
+ var __proto = CrossFlicking.prototype;
8148
+ Object.defineProperty(__proto, "sideFlicking", {
8149
+ // Components
8150
+ get: function () {
8151
+ return this._sideFlicking;
8152
+ },
8153
+ enumerable: false,
8154
+ configurable: true
8155
+ });
8156
+ Object.defineProperty(__proto, "sideState", {
8157
+ get: function () {
8158
+ return this._sideState;
8159
+ },
8160
+ enumerable: false,
8161
+ configurable: true
8162
+ });
8163
+ Object.defineProperty(__proto, "sideOptions", {
8164
+ // Options Getter
8165
+ get: function () {
8166
+ return this._sideOptions;
8167
+ },
8168
+ // Options Setter
8169
+ set: function (val) {
8170
+ this._sideOptions = val;
8171
+ },
8172
+ enumerable: false,
8173
+ configurable: true
8174
+ });
8175
+ Object.defineProperty(__proto, "preserveIndex", {
8176
+ get: function () {
8177
+ return this._preserveIndex;
8178
+ },
8179
+ set: function (val) {
8180
+ this._preserveIndex = val;
8181
+ },
8182
+ enumerable: false,
8183
+ configurable: true
8184
+ });
8185
+ Object.defineProperty(__proto, "disableSlideOnHold", {
8186
+ get: function () {
8187
+ return this._disableSlideOnHold;
8188
+ },
8189
+ set: function (val) {
8190
+ this._disableSlideOnHold = val;
8191
+ },
8192
+ enumerable: false,
8193
+ configurable: true
8194
+ });
8195
+ Object.defineProperty(__proto, "disableIndexSync", {
8196
+ get: function () {
8197
+ return this._disableIndexSync;
8198
+ },
8199
+ set: function (val) {
8200
+ this._disableIndexSync = val;
8201
+ },
8202
+ enumerable: false,
8203
+ configurable: true
8204
+ });
8205
+ __proto.init = function () {
8206
+ var _this = this;
8207
+ return _super.prototype.init.call(this).then(function () {
8208
+ _this._sideState = _this._createSideState();
8209
+ _this._sideFlicking = _this._createSideFlicking();
8210
+ _this._addComponentEvents();
8211
+ });
8212
+ };
8213
+ __proto.destroy = function () {
8214
+ this._sideFlicking.forEach(function (flicking) {
8215
+ flicking.destroy();
8216
+ });
8217
+ _super.prototype.destroy.call(this);
8218
+ };
8219
+ __proto._addComponentEvents = function () {
8220
+ var _this = this;
8221
+ this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
8222
+ this.on(EVENTS.MOVE, this._onHorizontalMove);
8223
+ this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
8224
+ this._sideFlicking.forEach(function (flicking, mainIndex) {
8225
+ flicking.on(EVENTS.HOLD_START, _this._onSideHoldStart);
8226
+ flicking.on(EVENTS.MOVE, _this._onSideMove);
8227
+ flicking.on(EVENTS.MOVE_END, _this._onSideMoveEnd);
8228
+ flicking.on(EVENTS.CHANGED, _this._onSideChanged);
8229
+ Object.keys(SIDE_EVENTS).forEach(function (name) {
8230
+ flicking.on(EVENTS[name], function (event) {
8231
+ _this.trigger(new Component.ComponentEvent(SIDE_EVENTS[name], __assign({
8232
+ mainIndex: mainIndex
8233
+ }, event)));
8234
+ });
8235
+ });
8236
+ });
8237
+ };
8238
+ __proto._createSideState = function () {
8239
+ var viewportEl = this.element;
8240
+ var cameraEl = this.camera.element;
8241
+ var panels = toArray(cameraEl.children);
8242
+ var isCrossStructure = getDataAttributes(viewportEl, "data-cross-").structure;
8243
+ var sideState = [];
8244
+ if (!isCrossStructure) {
8245
+ var groupPanels = this._getGroupFromAttribute(panels);
8246
+ var groupKeys = Object.keys(groupPanels);
8247
+ if (groupKeys.length) {
8248
+ sideState = this._getSideStateFromGroup(groupPanels);
8249
+ this.remove(0, this.panelCount - groupKeys.length);
8250
+ } else {
8251
+ sideState = this._getSideStateFromPanels(panels);
8252
+ }
8253
+ this._createCrossStructure(sideState);
8254
+ } else {
8255
+ sideState = this._getSideStateFromCrossStructure(panels);
8256
+ }
8257
+ void this.resize();
8258
+ return sideState;
8259
+ };
8260
+ __proto._createCrossStructure = function (sideState) {
8261
+ var _this = this;
8262
+ var sideCamera = document.createElement("div");
8263
+ var sidePanels = "";
8264
+ sideCamera.classList.add(CLASS.CAMERA);
8265
+ sideState.forEach(function (state, i) {
8266
+ var panel = _this.camera.children[i];
8267
+ sidePanels += state.element.innerHTML;
8268
+ Array.from(panel.attributes).forEach(function (attribute) {
8269
+ return panel.removeAttribute(attribute.name);
8270
+ });
8271
+ });
8272
+ sideCamera.innerHTML = sidePanels;
8273
+ sideState.forEach(function (_, i) {
8274
+ var panel = _this.camera.children[i];
8275
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8276
+ if (!panel.classList.contains(className)) {
8277
+ panel.classList.add(className);
8278
+ }
8279
+ });
8280
+ panel.innerHTML = sideCamera.outerHTML;
8281
+ });
8282
+ this.element.setAttribute("data-cross-structure", "true");
8283
+ };
8284
+ __proto._getGroupFromAttribute = function (panels) {
8285
+ var groupKeys = [];
8286
+ var groupPanels = {};
8287
+ panels.forEach(function (panel) {
8288
+ var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
8289
+ if (groupKey && !includes(groupKeys, groupKey)) {
8290
+ groupKeys.push(groupKey);
8291
+ groupPanels[groupKey] = [panel];
8292
+ } else if (groupKey) {
8293
+ groupPanels[groupKey].push(panel);
8294
+ }
8295
+ });
8296
+ return groupPanels;
8297
+ };
8298
+ __proto._getSideStateFromGroup = function (groupPanels) {
8299
+ return Object.keys(groupPanels).reduce(function (state, key) {
8300
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8301
+ var element = groupPanels[key].reduce(function (el, panel) {
8302
+ el.innerHTML += panel.outerHTML;
8303
+ return el;
8304
+ }, document.createElement("div"));
8305
+ return __spread(state, [{
8306
+ key: key,
8307
+ start: start,
8308
+ end: start + groupPanels[key].length - 1,
8309
+ element: element
8310
+ }]);
8311
+ }, []);
8312
+ };
8313
+ __proto._getSideStateFromPanels = function (panels) {
8314
+ return panels.reduce(function (state, panel, i) {
8315
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8316
+ return __spread(state, [{
8317
+ key: i.toString(),
8318
+ start: start,
8319
+ end: start + panel.children.length - 1,
8320
+ element: panel
8321
+ }]);
8322
+ }, []);
8323
+ };
8324
+ __proto._getSideStateFromCrossStructure = function (panels) {
8325
+ var groupPanels = this._getGroupFromAttribute(panels);
8326
+ return this._getSideStateFromGroup(groupPanels);
8327
+ };
8328
+ __proto._createSideFlicking = function () {
8329
+ var _this = this;
8330
+ return this.sideState.map(function (state, i) {
8331
+ return new Flicking(_this.camera.children[i], __assign(__assign({}, _this.sideOptions), {
8332
+ horizontal: false,
8333
+ panelsPerView: 1,
8334
+ defaultIndex: state.start
8335
+ }));
8336
+ });
8337
+ };
8338
+ return CrossFlicking;
8339
+ }(Flicking);
8340
+
8341
+ var CrossFlicking$1 = {
8342
+ __proto__: null,
8343
+ SIDE_EVENTS: SIDE_EVENTS,
8344
+ CrossFlicking: CrossFlicking
8345
+ };
8346
+
7962
8347
  /*
7963
8348
  * Copyright (c) 2015 NAVER Corp.
7964
8349
  * egjs projects are licensed under the MIT license
@@ -8204,6 +8589,7 @@ version: 4.12.0-beta.0
8204
8589
  merge(Flicking, Constants);
8205
8590
  merge(Flicking, CFC);
8206
8591
  merge(Flicking, Utils);
8592
+ merge(Flicking, CrossFlicking$1);
8207
8593
 
8208
8594
  return Flicking;
8209
8595