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

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.
@@ -32,6 +32,7 @@ class Camera {
32
32
  private _mode: CameraMode;
33
33
  private _el: HTMLElement;
34
34
  private _transform: string;
35
+ private _lookedOffset = 0;
35
36
  private _position: number;
36
37
  private _alignPos: number;
37
38
  private _offset: number;
@@ -292,6 +293,8 @@ class Camera {
292
293
  * @return {this}
293
294
  */
294
295
  public lookAt(pos: number): void {
296
+ const prevOffset = this._offset;
297
+ const isChangedOffset = this._lookedOffset !== prevOffset;
295
298
  const flicking = getFlickingAttached(this._flicking);
296
299
  const prevPos = this._position;
297
300
 
@@ -304,7 +307,12 @@ class Camera {
304
307
  if (toggled) {
305
308
  void flicking.renderer.render().then(() => {
306
309
  this.updateOffset();
310
+ this._lookedOffset = this._offset;
307
311
  });
312
+ } else if (isChangedOffset) {
313
+ // sync offset for renderOnlyVisible on resize
314
+ this.updateOffset();
315
+ this._lookedOffset = this._offset;
308
316
  } else {
309
317
  this.applyTransform();
310
318
  }
@@ -502,8 +510,8 @@ class Camera {
502
510
  }
503
511
 
504
512
  /**
505
- * Update Viewport's height to active panel's height
506
- * @ko 현재 선택된 패널의 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
513
+ * Update Viewport's height to visible panel's max height
514
+ * @ko 현재 활성화된 패널과 보이는 패널의 최대 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
507
515
  * @throws {FlickingError}
508
516
  * {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
509
517
  * <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
@@ -513,11 +521,22 @@ class Camera {
513
521
  public updateAdaptiveHeight() {
514
522
  const flicking = getFlickingAttached(this._flicking);
515
523
  const activePanel = flicking.control.activePanel;
524
+ const visiblePanels = flicking.visiblePanels;
525
+
526
+ const selectedPanels = [...visiblePanels];
527
+
528
+ if (activePanel) {
529
+ selectedPanels.push(activePanel);
530
+ }
531
+
532
+ if (!flicking.horizontal || !flicking.adaptive || !selectedPanels.length) return;
533
+
534
+
535
+ const maxHeight = Math.max(...selectedPanels.map(panel => panel.height));
516
536
 
517
- if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
518
537
 
519
538
  flicking.viewport.setSize({
520
- height: activePanel.height
539
+ height: maxHeight
521
540
  });
522
541
  }
523
542
 
@@ -599,6 +618,7 @@ class Camera {
599
618
 
600
619
  private _resetInternalValues() {
601
620
  this._position = 0;
621
+ this._lookedOffset = 0;
602
622
  this._alignPos = 0;
603
623
  this._offset = 0;
604
624
  this._circularOffset = 0;
@@ -94,6 +94,8 @@ export const MOVE_TYPE = {
94
94
  } as const;
95
95
 
96
96
  export const CLASS = {
97
+ VIEWPORT: "flicking-viewport",
98
+ CAMERA: "flicking-camera",
97
99
  VERTICAL: "vertical",
98
100
  HIDDEN: "flicking-hidden",
99
101
  DEFAULT_VIRTUAL: "flicking-panel"
@@ -39,6 +39,10 @@ class HoldingState extends State {
39
39
 
40
40
  const inputEvent = axesEvent.inputEvent as { offsetX: number; offsetY: number };
41
41
 
42
+ if (!inputEvent) {
43
+ return;
44
+ }
45
+
42
46
  const offset = flicking.horizontal
43
47
  ? inputEvent.offsetX
44
48
  : inputEvent.offsetY;
@@ -321,6 +321,10 @@ class Panel {
321
321
  useFractionalSize
322
322
  } = flicking;
323
323
 
324
+ if (!el) {
325
+ return this;
326
+ }
327
+
324
328
  if (cached) {
325
329
  this._size = cached.size;
326
330
  this._margin = { ...cached.margin };
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import Flicking from "./Flicking";
6
6
  import type { FlickingOptions, FlickingEvents } from "./Flicking";
7
+ import type { CrossFlickingOptions } from "./CrossFlicking";
7
8
 
8
9
  export * from "./CrossFlicking";
9
10
 
@@ -17,6 +18,6 @@ export * from "./utils";
17
18
 
18
19
  export * from "./type/event";
19
20
  export * from "./type/external";
20
- export type { FlickingOptions, FlickingEvents };
21
+ export type { FlickingOptions, FlickingEvents, CrossFlickingOptions };
21
22
 
22
23
  export default Flicking;
package/src/utils.ts CHANGED
@@ -349,3 +349,24 @@ export const setPrototypeOf = Object.setPrototypeOf || ((obj, proto) => {
349
349
  obj.__proto__ = proto;
350
350
  return obj;
351
351
  });
352
+
353
+ export const camelize = (str: string): string => {
354
+ return str.replace(/[\s-_]([a-z])/g, (all, letter) => letter.toUpperCase());
355
+ };
356
+
357
+ export const getDataAttributes = (element: HTMLElement, attributePrefix: string): Record<string, string> => {
358
+ const dataAttributes: Record<string, string> = {};
359
+ const attributes = element.attributes;
360
+ const length = attributes.length;
361
+
362
+ for (let i = 0; i < length; ++i) {
363
+ const attribute = attributes[i];
364
+ const { name, value } = attribute;
365
+ if (name.indexOf(attributePrefix) === -1) {
366
+ continue;
367
+ }
368
+ dataAttributes[camelize(name.replace(attributePrefix, ""))] = value;
369
+ }
370
+
371
+ return dataAttributes;
372
+ };