@egjs/flicking 4.12.0-beta.1 → 4.12.0-beta.3

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.1
7
+ version: 4.12.0-beta.3
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.1
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"
@@ -751,6 +753,26 @@ version: 4.12.0-beta.1
751
753
  obj.__proto__ = proto;
752
754
  return obj;
753
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
+ };
754
776
 
755
777
  var Utils = {
756
778
  __proto__: null,
@@ -782,7 +804,9 @@ version: 4.12.0-beta.1
782
804
  circulateIndex: circulateIndex,
783
805
  range: range,
784
806
  getElementSize: getElementSize,
785
- setPrototypeOf: setPrototypeOf
807
+ setPrototypeOf: setPrototypeOf,
808
+ camelize: camelize,
809
+ getDataAttributes: getDataAttributes
786
810
  };
787
811
 
788
812
  /*
@@ -7967,7 +7991,7 @@ version: 4.12.0-beta.1
7967
7991
  * Flicking.VERSION; // ex) 4.0.0
7968
7992
  * ```
7969
7993
  */
7970
- Flicking.VERSION = "4.12.0-beta.1";
7994
+ Flicking.VERSION = "4.12.0-beta.3";
7971
7995
  return Flicking;
7972
7996
  }(Component);
7973
7997
 
@@ -7984,7 +8008,6 @@ version: 4.12.0-beta.1
7984
8008
  var CrossFlicking = /*#__PURE__*/function (_super) {
7985
8009
  __extends(CrossFlicking, _super);
7986
8010
  // Options Setter
7987
- // UI / LAYOUT
7988
8011
  // public set align(val: FlickingOptions["align"]) {
7989
8012
  // this._align = val;
7990
8013
  // }
@@ -8057,18 +8080,53 @@ version: 4.12.0-beta.1
8057
8080
  }
8058
8081
  };
8059
8082
  // Internal states
8060
- _this._verticalState = [];
8083
+ _this._verticalState = _this._createVerticalState();
8061
8084
  _this._moveDirection = null;
8062
8085
  _this._nextIndex = 0;
8063
8086
  // Bind options
8064
8087
  _this._verticalOptions = verticalOptions;
8065
- return _this;
8066
8088
  // Create core components
8067
- // this._viewport = new Viewport(this, getElement(root));
8089
+ _this._verticalFlicking = _this._createVerticalFlicking();
8090
+ return _this;
8068
8091
  }
8069
8092
  var __proto = CrossFlicking.prototype;
8070
- Object.defineProperty(__proto, "verticalOptions", {
8093
+ Object.defineProperty(__proto, "verticalFlicking", {
8071
8094
  // Components
8095
+ /**
8096
+ * {@link Control} instance of the Flicking
8097
+ * @ko 현재 Flicking에 활성화된 {@link Control} 인스턴스
8098
+ * @type {Control}
8099
+ * @default SnapControl
8100
+ * @readonly
8101
+ * @see Control
8102
+ * @see SnapControl
8103
+ * @see FreeControl
8104
+ */
8105
+ get: function () {
8106
+ return this._verticalFlicking;
8107
+ },
8108
+ enumerable: false,
8109
+ configurable: true
8110
+ });
8111
+ Object.defineProperty(__proto, "verticalState", {
8112
+ // Internal States
8113
+ /**
8114
+ * Whether Flicking's {@link Flicking#init init()} is called.
8115
+ * This is `true` when {@link Flicking#init init()} is called, and is `false` after calling {@link Flicking#destroy destroy()}.
8116
+ * @ko Flicking의 {@link Flicking#init init()}이 호출되었는지를 나타내는 멤버 변수.
8117
+ * 이 값은 {@link Flicking#init init()}이 호출되었으면 `true`로 변하고, {@link Flicking#destroy destroy()}호출 이후에 다시 `false`로 변경됩니다.
8118
+ * @type {boolean}
8119
+ * @default false
8120
+ * @readonly
8121
+ */
8122
+ get: function () {
8123
+ return this._verticalState;
8124
+ },
8125
+ enumerable: false,
8126
+ configurable: true
8127
+ });
8128
+ Object.defineProperty(__proto, "verticalOptions", {
8129
+ // Options Getter
8072
8130
  /**
8073
8131
  * Change active panel index on mouse/touch hold while animating.
8074
8132
  * `index` of the `willChange`/`willRestore` event will be used as new index.
@@ -8095,37 +8153,102 @@ version: 4.12.0-beta.1
8095
8153
  __proto.init = function () {
8096
8154
  var _this = this;
8097
8155
  return _super.prototype.init.call(this).then(function () {
8098
- // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8099
- // camera.children들에 대해 갯수 세기
8100
- var verticalPanels = "";
8101
- _this._verticalState = _this.camera.children.reduce(function (state, child) {
8156
+ return _this._addComponentEvents();
8157
+ });
8158
+ };
8159
+ __proto._addComponentEvents = function () {
8160
+ var _this = this;
8161
+ this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
8162
+ this.on(EVENTS.MOVE, this._onHorizontalMove);
8163
+ this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
8164
+ this._verticalFlicking.forEach(function (flicking) {
8165
+ flicking.on(EVENTS.HOLD_START, _this._onVerticalHoldStart);
8166
+ flicking.on(EVENTS.MOVE, _this._onVerticalMove);
8167
+ flicking.on(EVENTS.MOVE_END, _this._onVerticalMoveEnd);
8168
+ flicking.on(EVENTS.CHANGED, _this._onVerticalChanged);
8169
+ });
8170
+ };
8171
+ __proto._createVerticalState = function () {
8172
+ var _this = this;
8173
+ // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8174
+ // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
8175
+ // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
8176
+ var cameraEl = this.camera.element;
8177
+ var panels = toArray(cameraEl.children);
8178
+ var verticalState;
8179
+ var verticalPanels = "";
8180
+ // check data attribute exists
8181
+ var groupKeys = [];
8182
+ var groupPanels = {};
8183
+ var verticalCamera = document.createElement("div");
8184
+ verticalCamera.classList.add(CLASS.CAMERA);
8185
+ panels.forEach(function (panel) {
8186
+ var groupKey = getDataAttributes(panel, "data-flicking-").groupkey;
8187
+ if (groupKey && !includes(groupKeys, groupKey)) {
8188
+ groupKeys.push(groupKey);
8189
+ groupPanels[groupKey] = [panel];
8190
+ } else if (groupKey) {
8191
+ groupPanels[groupKey].push(panel);
8192
+ }
8193
+ return groupKey;
8194
+ });
8195
+ if (groupKeys.length) {
8196
+ panels.forEach(function () {
8197
+ return _this.remove(0);
8198
+ });
8199
+ verticalState = groupKeys.reduce(function (state, key) {
8102
8200
  var start = state.length ? +state[state.length - 1].end + 1 : 0;
8103
- verticalPanels += child.children[0].innerHTML;
8201
+ var element = groupPanels[key].reduce(function (el, panel) {
8202
+ verticalPanels += panel.outerHTML;
8203
+ el.appendChild(panel);
8204
+ return el;
8205
+ }, document.createElement("div"));
8104
8206
  return __spread(state, [{
8207
+ key: key,
8105
8208
  start: start,
8106
- end: start + child.children[0].children.length - 1,
8107
- element: child
8209
+ end: start + groupPanels[key].length - 1,
8210
+ element: element
8108
8211
  }]);
8109
8212
  }, []);
8110
- _this.camera.children.forEach(function (child) {
8111
- child.children[0].innerHTML = verticalPanels;
8213
+ verticalCamera.innerHTML = verticalPanels;
8214
+ cameraEl.innerHTML = "";
8215
+ groupKeys.forEach(function () {
8216
+ var panel = document.createElement("div");
8217
+ panel.classList.add(CLASS.VIEWPORT, CLASS.VERTICAL);
8218
+ panel.innerHTML = verticalCamera.outerHTML;
8219
+ _this.append(panel);
8112
8220
  });
8113
- _this._verticalFlicking = _this.camera.children.map(function (child, i) {
8114
- return new Flicking(child, __assign(__assign({}, _this.verticalOptions), {
8115
- horizontal: false,
8116
- panelsPerView: 1,
8117
- defaultIndex: _this._verticalState[i].start
8118
- }));
8119
- });
8120
- _this.on(EVENTS.HOLD_START, _this._onHorizontalHoldStart);
8121
- _this.on(EVENTS.MOVE, _this._onHorizontalMove);
8122
- _this.on(EVENTS.MOVE_END, _this._onHorizontalMoveEnd);
8123
- _this._verticalFlicking.forEach(function (child) {
8124
- child.on(EVENTS.HOLD_START, _this._onVerticalHoldStart);
8125
- child.on(EVENTS.MOVE, _this._onVerticalMove);
8126
- child.on(EVENTS.MOVE_END, _this._onVerticalMoveEnd);
8127
- child.on(EVENTS.CHANGED, _this._onVerticalChanged);
8221
+ } else {
8222
+ verticalState = panels.reduce(function (state, panel, i) {
8223
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8224
+ verticalPanels += panel.innerHTML;
8225
+ return __spread(state, [{
8226
+ key: i.toString(),
8227
+ start: start,
8228
+ end: start + panel.children.length - 1,
8229
+ element: panel
8230
+ }]);
8231
+ }, []);
8232
+ verticalCamera.innerHTML = verticalPanels;
8233
+ panels.forEach(function (panel) {
8234
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8235
+ if (!panel.classList.contains(className)) {
8236
+ panel.classList.add(className);
8237
+ }
8238
+ });
8239
+ panel.innerHTML = verticalCamera.outerHTML;
8128
8240
  });
8241
+ }
8242
+ return verticalState;
8243
+ };
8244
+ __proto._createVerticalFlicking = function () {
8245
+ var _this = this;
8246
+ return this.camera.children.map(function (panel, i) {
8247
+ return new Flicking(panel, __assign(__assign({}, _this.verticalOptions), {
8248
+ horizontal: false,
8249
+ panelsPerView: 1,
8250
+ defaultIndex: _this._verticalState[i].start
8251
+ }));
8129
8252
  });
8130
8253
  };
8131
8254
  __proto._syncToCategory = function (index, outerIndex) {