ninegrid2 6.1012.0 → 6.1013.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.
@@ -121369,6 +121369,8 @@ customElements.define('nx-tab-page', nxTabPage);
121369
121369
 
121370
121370
  class nxSplitter extends HTMLElement {
121371
121371
  #mode;
121372
+ #originalPrevFlex;
121373
+ #originalNextFlex;
121372
121374
 
121373
121375
  constructor() {
121374
121376
  super();
@@ -121382,18 +121384,21 @@ class nxSplitter extends HTMLElement {
121382
121384
  #detectMode = (el) => {
121383
121385
  const prev = el.previousElementSibling;
121384
121386
  const next = el.nextElementSibling;
121387
+ if (!prev || !next) {
121388
+ this.#mode = this.classList.contains('h') ? "h" : "v";
121389
+ return;
121390
+ }
121385
121391
 
121386
- const prevRect = prev?.getBoundingClientRect();
121387
- const nextRect = next?.getBoundingClientRect();
121392
+ const prevRect = prev.getBoundingClientRect();
121393
+ const nextRect = next.getBoundingClientRect();
121388
121394
 
121389
121395
  if (this.classList.contains('h')) {
121390
121396
  this.#mode = "h";
121391
- }
121392
- else if (this.classList.contains('v')) {
121397
+ } else if (this.classList.contains('v')) {
121393
121398
  this.#mode = "v";
121394
- }
121395
- else {
121396
- this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
121399
+ } else {
121400
+ // 형제 요소의 위치를 비교하여 모드를 감지
121401
+ this.#mode = (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
121397
121402
  }
121398
121403
  };
121399
121404
 
@@ -121404,7 +121409,7 @@ class nxSplitter extends HTMLElement {
121404
121409
  const splitterRect = this.getBoundingClientRect();
121405
121410
  const isHorizontal = this.#mode === "h";
121406
121411
 
121407
- const clickOffset = isHorizontal
121412
+ isHorizontal
121408
121413
  ? e.clientX - splitterRect.left
121409
121414
  : e.clientY - splitterRect.top;
121410
121415
 
@@ -121432,109 +121437,61 @@ class nxSplitter extends HTMLElement {
121432
121437
 
121433
121438
  (parent.shadowRoot || parent).appendChild(dragBar);
121434
121439
 
121435
- const dragBarOffsetParent = dragBar.offsetParent;
121436
-
121437
- if (!dragBarOffsetParent) {
121438
- console.error("dragBar's offsetParent could not be determined. Ensure parent or an ancestor has a position property (e.g., relative).");
121439
- dragBar.remove();
121440
- return;
121441
- }
121442
-
121443
- const dragBarOffsetParentRect = dragBarOffsetParent.getBoundingClientRect();
121440
+ const parentRect = parent.getBoundingClientRect();
121444
121441
  const prevRect = prev.getBoundingClientRect();
121445
121442
  const nextRect = next.getBoundingClientRect();
121446
121443
 
121447
- let initialPosInOffsetParent;
121444
+ let dragBarPosInParent;
121448
121445
  if (isHorizontal) {
121449
- initialPosInOffsetParent = e.clientX - dragBarOffsetParentRect.left;
121446
+ dragBarPosInParent = e.clientX - parentRect.left;
121450
121447
  dragBar.style.top = "0";
121451
- dragBar.style.left = `${initialPosInOffsetParent}px`;
121448
+ dragBar.style.left = `${dragBarPosInParent}px`;
121452
121449
  dragBar.style.width = "1px";
121453
121450
  dragBar.style.height = "100%";
121454
121451
  } else {
121455
- initialPosInOffsetParent = e.clientY - dragBarOffsetParentRect.top;
121452
+ dragBarPosInParent = e.clientY - parentRect.top;
121456
121453
  dragBar.style.left = "0";
121457
- dragBar.style.top = `${initialPosInOffsetParent}px`;
121454
+ dragBar.style.top = `${dragBarPosInParent}px`;
121458
121455
  dragBar.style.height = "1px";
121459
121456
  dragBar.style.width = "100%";
121460
121457
  }
121461
121458
 
121462
- const minLimit = isHorizontal
121463
- ? prevRect.left - dragBarOffsetParentRect.left
121464
- : prevRect.top - dragBarOffsetParentRect.top;
121465
- const maxLimit = isHorizontal
121466
- ? nextRect.right - dragBarOffsetParentRect.left
121467
- : nextRect.bottom - dragBarOffsetParentRect.top;
121468
-
121459
+ const minLimit = isHorizontal ? prevRect.left - parentRect.left : prevRect.top - parentRect.top;
121460
+ const maxLimit = isHorizontal ? nextRect.right - parentRect.left : nextRect.bottom - parentRect.top;
121469
121461
 
121470
121462
  const onMove = moveEvent => {
121471
121463
  const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
121472
- const currentPosInOffsetParent = isHorizontal
121473
- ? clientPos - dragBarOffsetParentRect.left
121474
- : clientPos - dragBarOffsetParentRect.top;
121475
-
121476
- const clampedPos = Math.max(minLimit, Math.min(currentPosInOffsetParent, maxLimit));
121477
-
121464
+ const currentPosInParent = isHorizontal ? clientPos - parentRect.left : clientPos - parentRect.top;
121465
+ const clampedPos = Math.max(minLimit, Math.min(currentPosInParent, maxLimit));
121478
121466
  if (isHorizontal) {
121479
121467
  dragBar.style.left = `${clampedPos}px`;
121480
121468
  } else {
121481
121469
  dragBar.style.top = `${clampedPos}px`;
121482
121470
  }
121483
-
121484
- console.log(clampedPos);
121485
121471
  };
121486
121472
 
121487
- const onUp = (upEvent) => {
121473
+ const onUp = () => {
121488
121474
  window.removeEventListener("mousemove", onMove);
121489
121475
  window.removeEventListener("mouseup", onUp);
121490
121476
  dragBar.remove();
121491
121477
 
121492
- const finalDragBarPosInOffsetParent = isHorizontal
121478
+ const finalDragBarPosInParent = isHorizontal
121493
121479
  ? parseFloat(dragBar.style.left)
121494
121480
  : parseFloat(dragBar.style.top);
121495
121481
 
121496
- // ⭐⭐ offsetParentTotalSize 변수를 여기서 정의합니다 ⭐⭐
121497
- const offsetParentTotalSize = isHorizontal
121498
- ? dragBarOffsetParentRect.width
121499
- : dragBarOffsetParentRect.height;
121500
-
121482
+ const parentTotalSize = isHorizontal ? parentRect.width : parentRect.height;
121501
121483
  const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
121502
121484
 
121503
- // prev의 시작점 (offsetParent 기준)
121504
- const prevStartPosInOffsetParent = isHorizontal
121505
- ? prevRect.left - dragBarOffsetParentRect.left
121506
- : prevRect.top - dragBarOffsetParentRect.top;
121507
-
121508
- // prev의 새로운 크기 (dragBar의 왼쪽 위치 - prev의 왼쪽 위치)
121509
- let finalPrevSize = finalDragBarPosInOffsetParent - prevStartPosInOffsetParent;
121510
-
121511
- // next의 새로운 크기 (offsetParent의 전체 크기 - prev 크기 - 스플리터 두께)
121512
- // 이 방법이 전체 공간을 정확히 채우면서 오차를 마지막 패널에 몰아넣는 데 더 견고합니다.
121513
- const MIN_PANEL_SIZE_PX = 1;
121514
- finalPrevSize = Math.max(MIN_PANEL_SIZE_PX, finalPrevSize) - clickOffset;
121515
- let finalNextSize = Math.max(MIN_PANEL_SIZE_PX, offsetParentTotalSize - finalPrevSize - splitterThickness);
121516
-
121517
- // flex 속성 저장 및 복원
121518
- const originalPrevFlex = prev.style.flex;
121519
- const originalNextFlex = next.style.flex;
121485
+ const prevStartPosInParent = isHorizontal
121486
+ ? prevRect.left - parentRect.left
121487
+ : prevRect.top - parentRect.top;
121520
121488
 
121521
- // 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
121522
- prev.style.flex = "none";
121523
- next.style.flex = "none";
121489
+ const newPrevSize = finalDragBarPosInParent - prevStartPosInParent;
121490
+ const newNextSize = parentTotalSize - newPrevSize - splitterThickness;
121524
121491
 
121525
- console.log(finalPrevSize, finalNextSize, offsetParentTotalSize);
121526
-
121527
- if (isHorizontal) {
121528
- prev.style.width = `${finalPrevSize}px`;
121529
- next.style.width = `${finalNextSize}px`;
121530
- } else {
121531
- prev.style.height = `${finalPrevSize}px`;
121532
- next.style.height = `${finalNextSize}px`;
121533
- }
121534
-
121535
- // 작업 완료 후 원래 flex 값으로 복원
121536
- prev.style.flex = originalPrevFlex;
121537
- next.style.flex = originalNextFlex;
121492
+ // flex 속성 사용
121493
+ prev.style.flex = `0 0 ${newPrevSize}px`;
121494
+ next.style.flex = `0 0 ${newNextSize}px`;
121538
121495
  };
121539
121496
 
121540
121497
  window.addEventListener("mousemove", onMove);
@@ -121549,18 +121506,17 @@ class nxSplitter extends HTMLElement {
121549
121506
 
121550
121507
  const contents = this.innerHTML.trim();
121551
121508
  const gripClass = `grip-${this.#mode}`;
121552
- const gripTmpl = (contents === "") ? `<div class="${gripClass}"></div>`: `<div class="${gripClass}"></div><div class="inner-container">${contents}</div><div class="${gripClass}"></div>`;
121509
+ const gripTmpl = (contents === "") ? `<div class="${gripClass}"></div>` : `<div class="${gripClass}"></div><div class="inner-container">${contents}</div><div class="${gripClass}"></div>`;
121553
121510
 
121554
121511
  this.innerHTML = "";
121555
121512
  const htmlTmpl = document.createElement("template");
121556
121513
  htmlTmpl.innerHTML = `
121557
- <style>
121558
- @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxSplitter.css";
121559
- ${ninegrid.getCustomPath(this,"nxSplitter.css")}
121560
- </style>
121561
-
121562
- ${gripTmpl}
121563
- `;
121514
+ <style>
121515
+ @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxSplitter.css";
121516
+ ${ninegrid.getCustomPath(this,"nxSplitter.css")}
121517
+ </style>
121518
+ ${gripTmpl}
121519
+ `;
121564
121520
 
121565
121521
  this.shadowRoot.appendChild(htmlTmpl.content.cloneNode(true));
121566
121522
 
@@ -121573,62 +121529,32 @@ class nxSplitter extends HTMLElement {
121573
121529
  window.addEventListener("resize", () => this.#prepareLayout());
121574
121530
  };
121575
121531
 
121576
- #isLastSplitter = () => {
121577
- const parent = this.parentElement;
121578
- if (!parent) return false;
121579
-
121580
- const allSplitters = [...parent.querySelectorAll("nx-splitter")];
121581
- return allSplitters.at(-1) === this;
121582
- };
121583
-
121584
- #getSiblingSizeSum = () => {
121585
- const parent = this.parentElement;
121586
- if (!parent) return 0;
121587
-
121588
- const isHorizontal = this.#mode === "h";
121589
-
121590
- return Array.from(parent.children).reduce((sum, el) => {
121591
- const size = isHorizontal ? el.offsetWidth : el.offsetHeight;
121592
- return sum + size;
121593
- }, 0);
121594
- };
121595
-
121596
-
121597
121532
  #prepareLayout = () => {
121598
-
121599
121533
  const isHorizontal = this.#mode === "h";
121534
+ const parent = this.parentElement;
121600
121535
  const prev = this.previousElementSibling;
121601
121536
  const next = this.nextElementSibling;
121602
- const parent = this.parentElement;
121603
121537
  if (!prev || !next || !parent) return;
121604
121538
 
121605
- const currentTotal = this.#getSiblingSizeSum();
121606
- const nextTotal = isHorizontal
121607
- ? parent.getBoundingClientRect().width
121608
- : parent.getBoundingClientRect().height;
121609
-
121610
- const prevSize = isHorizontal ? prev.offsetWidth : prev.offsetHeight;
121611
- const nextSize = isHorizontal ? next.offsetWidth : next.offsetHeight;
121539
+ const parentRect = parent.getBoundingClientRect();
121540
+ const currentPrevSize = isHorizontal ? prev.getBoundingClientRect().width : prev.getBoundingClientRect().height;
121541
+ const currentNextSize = isHorizontal ? next.getBoundingClientRect().width : next.getBoundingClientRect().height;
121612
121542
 
121613
- const newPrevSize = nextTotal * prevSize / currentTotal;
121614
- const newNextSize = nextTotal * nextSize / currentTotal;
121543
+ const totalContentSize = Array.from(parent.children).reduce((sum, el) => {
121544
+ const rect = el.getBoundingClientRect();
121545
+ const size = isHorizontal ? rect.width : rect.height;
121546
+ return sum + size;
121547
+ }, 0);
121615
121548
 
121549
+ const totalParentSize = isHorizontal ? parentRect.width : parentRect.height;
121616
121550
 
121617
- if (isHorizontal) {
121618
- prev.style.width = `${newPrevSize}px`;
121551
+ // 리사이즈 시 비율 유지
121552
+ const newPrevSize = totalParentSize * (currentPrevSize / totalContentSize);
121553
+ const newNextSize = totalParentSize * (currentNextSize / totalContentSize);
121619
121554
 
121620
- if (this.#isLastSplitter()) {
121621
- next.style.width = `${newNextSize}px`;
121622
- }
121623
- } else {
121624
- prev.style.height = `${newPrevSize}px`;
121625
-
121626
- if (this.#isLastSplitter()) {
121627
- next.style.height = `${newNextSize}px`;
121628
- }
121629
- }
121555
+ prev.style.flex = `0 0 ${newPrevSize}px`;
121556
+ next.style.flex = `0 0 ${newNextSize}px`;
121630
121557
  };
121631
-
121632
121558
  }
121633
121559
 
121634
121560
  customElements.define("nx-splitter", nxSplitter);
@@ -121365,6 +121365,8 @@ customElements.define('nx-tab-page', nxTabPage);
121365
121365
 
121366
121366
  class nxSplitter extends HTMLElement {
121367
121367
  #mode;
121368
+ #originalPrevFlex;
121369
+ #originalNextFlex;
121368
121370
 
121369
121371
  constructor() {
121370
121372
  super();
@@ -121378,18 +121380,21 @@ class nxSplitter extends HTMLElement {
121378
121380
  #detectMode = (el) => {
121379
121381
  const prev = el.previousElementSibling;
121380
121382
  const next = el.nextElementSibling;
121383
+ if (!prev || !next) {
121384
+ this.#mode = this.classList.contains('h') ? "h" : "v";
121385
+ return;
121386
+ }
121381
121387
 
121382
- const prevRect = prev?.getBoundingClientRect();
121383
- const nextRect = next?.getBoundingClientRect();
121388
+ const prevRect = prev.getBoundingClientRect();
121389
+ const nextRect = next.getBoundingClientRect();
121384
121390
 
121385
121391
  if (this.classList.contains('h')) {
121386
121392
  this.#mode = "h";
121387
- }
121388
- else if (this.classList.contains('v')) {
121393
+ } else if (this.classList.contains('v')) {
121389
121394
  this.#mode = "v";
121390
- }
121391
- else {
121392
- this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
121395
+ } else {
121396
+ // 형제 요소의 위치를 비교하여 모드를 감지
121397
+ this.#mode = (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
121393
121398
  }
121394
121399
  };
121395
121400
 
@@ -121400,7 +121405,7 @@ class nxSplitter extends HTMLElement {
121400
121405
  const splitterRect = this.getBoundingClientRect();
121401
121406
  const isHorizontal = this.#mode === "h";
121402
121407
 
121403
- const clickOffset = isHorizontal
121408
+ isHorizontal
121404
121409
  ? e.clientX - splitterRect.left
121405
121410
  : e.clientY - splitterRect.top;
121406
121411
 
@@ -121428,109 +121433,61 @@ class nxSplitter extends HTMLElement {
121428
121433
 
121429
121434
  (parent.shadowRoot || parent).appendChild(dragBar);
121430
121435
 
121431
- const dragBarOffsetParent = dragBar.offsetParent;
121432
-
121433
- if (!dragBarOffsetParent) {
121434
- console.error("dragBar's offsetParent could not be determined. Ensure parent or an ancestor has a position property (e.g., relative).");
121435
- dragBar.remove();
121436
- return;
121437
- }
121438
-
121439
- const dragBarOffsetParentRect = dragBarOffsetParent.getBoundingClientRect();
121436
+ const parentRect = parent.getBoundingClientRect();
121440
121437
  const prevRect = prev.getBoundingClientRect();
121441
121438
  const nextRect = next.getBoundingClientRect();
121442
121439
 
121443
- let initialPosInOffsetParent;
121440
+ let dragBarPosInParent;
121444
121441
  if (isHorizontal) {
121445
- initialPosInOffsetParent = e.clientX - dragBarOffsetParentRect.left;
121442
+ dragBarPosInParent = e.clientX - parentRect.left;
121446
121443
  dragBar.style.top = "0";
121447
- dragBar.style.left = `${initialPosInOffsetParent}px`;
121444
+ dragBar.style.left = `${dragBarPosInParent}px`;
121448
121445
  dragBar.style.width = "1px";
121449
121446
  dragBar.style.height = "100%";
121450
121447
  } else {
121451
- initialPosInOffsetParent = e.clientY - dragBarOffsetParentRect.top;
121448
+ dragBarPosInParent = e.clientY - parentRect.top;
121452
121449
  dragBar.style.left = "0";
121453
- dragBar.style.top = `${initialPosInOffsetParent}px`;
121450
+ dragBar.style.top = `${dragBarPosInParent}px`;
121454
121451
  dragBar.style.height = "1px";
121455
121452
  dragBar.style.width = "100%";
121456
121453
  }
121457
121454
 
121458
- const minLimit = isHorizontal
121459
- ? prevRect.left - dragBarOffsetParentRect.left
121460
- : prevRect.top - dragBarOffsetParentRect.top;
121461
- const maxLimit = isHorizontal
121462
- ? nextRect.right - dragBarOffsetParentRect.left
121463
- : nextRect.bottom - dragBarOffsetParentRect.top;
121464
-
121455
+ const minLimit = isHorizontal ? prevRect.left - parentRect.left : prevRect.top - parentRect.top;
121456
+ const maxLimit = isHorizontal ? nextRect.right - parentRect.left : nextRect.bottom - parentRect.top;
121465
121457
 
121466
121458
  const onMove = moveEvent => {
121467
121459
  const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
121468
- const currentPosInOffsetParent = isHorizontal
121469
- ? clientPos - dragBarOffsetParentRect.left
121470
- : clientPos - dragBarOffsetParentRect.top;
121471
-
121472
- const clampedPos = Math.max(minLimit, Math.min(currentPosInOffsetParent, maxLimit));
121473
-
121460
+ const currentPosInParent = isHorizontal ? clientPos - parentRect.left : clientPos - parentRect.top;
121461
+ const clampedPos = Math.max(minLimit, Math.min(currentPosInParent, maxLimit));
121474
121462
  if (isHorizontal) {
121475
121463
  dragBar.style.left = `${clampedPos}px`;
121476
121464
  } else {
121477
121465
  dragBar.style.top = `${clampedPos}px`;
121478
121466
  }
121479
-
121480
- console.log(clampedPos);
121481
121467
  };
121482
121468
 
121483
- const onUp = (upEvent) => {
121469
+ const onUp = () => {
121484
121470
  window.removeEventListener("mousemove", onMove);
121485
121471
  window.removeEventListener("mouseup", onUp);
121486
121472
  dragBar.remove();
121487
121473
 
121488
- const finalDragBarPosInOffsetParent = isHorizontal
121474
+ const finalDragBarPosInParent = isHorizontal
121489
121475
  ? parseFloat(dragBar.style.left)
121490
121476
  : parseFloat(dragBar.style.top);
121491
121477
 
121492
- // ⭐⭐ offsetParentTotalSize 변수를 여기서 정의합니다 ⭐⭐
121493
- const offsetParentTotalSize = isHorizontal
121494
- ? dragBarOffsetParentRect.width
121495
- : dragBarOffsetParentRect.height;
121496
-
121478
+ const parentTotalSize = isHorizontal ? parentRect.width : parentRect.height;
121497
121479
  const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
121498
121480
 
121499
- // prev의 시작점 (offsetParent 기준)
121500
- const prevStartPosInOffsetParent = isHorizontal
121501
- ? prevRect.left - dragBarOffsetParentRect.left
121502
- : prevRect.top - dragBarOffsetParentRect.top;
121503
-
121504
- // prev의 새로운 크기 (dragBar의 왼쪽 위치 - prev의 왼쪽 위치)
121505
- let finalPrevSize = finalDragBarPosInOffsetParent - prevStartPosInOffsetParent;
121506
-
121507
- // next의 새로운 크기 (offsetParent의 전체 크기 - prev 크기 - 스플리터 두께)
121508
- // 이 방법이 전체 공간을 정확히 채우면서 오차를 마지막 패널에 몰아넣는 데 더 견고합니다.
121509
- const MIN_PANEL_SIZE_PX = 1;
121510
- finalPrevSize = Math.max(MIN_PANEL_SIZE_PX, finalPrevSize) - clickOffset;
121511
- let finalNextSize = Math.max(MIN_PANEL_SIZE_PX, offsetParentTotalSize - finalPrevSize - splitterThickness);
121512
-
121513
- // flex 속성 저장 및 복원
121514
- const originalPrevFlex = prev.style.flex;
121515
- const originalNextFlex = next.style.flex;
121481
+ const prevStartPosInParent = isHorizontal
121482
+ ? prevRect.left - parentRect.left
121483
+ : prevRect.top - parentRect.top;
121516
121484
 
121517
- // 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
121518
- prev.style.flex = "none";
121519
- next.style.flex = "none";
121485
+ const newPrevSize = finalDragBarPosInParent - prevStartPosInParent;
121486
+ const newNextSize = parentTotalSize - newPrevSize - splitterThickness;
121520
121487
 
121521
- console.log(finalPrevSize, finalNextSize, offsetParentTotalSize);
121522
-
121523
- if (isHorizontal) {
121524
- prev.style.width = `${finalPrevSize}px`;
121525
- next.style.width = `${finalNextSize}px`;
121526
- } else {
121527
- prev.style.height = `${finalPrevSize}px`;
121528
- next.style.height = `${finalNextSize}px`;
121529
- }
121530
-
121531
- // 작업 완료 후 원래 flex 값으로 복원
121532
- prev.style.flex = originalPrevFlex;
121533
- next.style.flex = originalNextFlex;
121488
+ // flex 속성 사용
121489
+ prev.style.flex = `0 0 ${newPrevSize}px`;
121490
+ next.style.flex = `0 0 ${newNextSize}px`;
121534
121491
  };
121535
121492
 
121536
121493
  window.addEventListener("mousemove", onMove);
@@ -121545,18 +121502,17 @@ class nxSplitter extends HTMLElement {
121545
121502
 
121546
121503
  const contents = this.innerHTML.trim();
121547
121504
  const gripClass = `grip-${this.#mode}`;
121548
- const gripTmpl = (contents === "") ? `<div class="${gripClass}"></div>`: `<div class="${gripClass}"></div><div class="inner-container">${contents}</div><div class="${gripClass}"></div>`;
121505
+ const gripTmpl = (contents === "") ? `<div class="${gripClass}"></div>` : `<div class="${gripClass}"></div><div class="inner-container">${contents}</div><div class="${gripClass}"></div>`;
121549
121506
 
121550
121507
  this.innerHTML = "";
121551
121508
  const htmlTmpl = document.createElement("template");
121552
121509
  htmlTmpl.innerHTML = `
121553
- <style>
121554
- @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxSplitter.css";
121555
- ${ninegrid.getCustomPath(this,"nxSplitter.css")}
121556
- </style>
121557
-
121558
- ${gripTmpl}
121559
- `;
121510
+ <style>
121511
+ @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxSplitter.css";
121512
+ ${ninegrid.getCustomPath(this,"nxSplitter.css")}
121513
+ </style>
121514
+ ${gripTmpl}
121515
+ `;
121560
121516
 
121561
121517
  this.shadowRoot.appendChild(htmlTmpl.content.cloneNode(true));
121562
121518
 
@@ -121569,62 +121525,32 @@ class nxSplitter extends HTMLElement {
121569
121525
  window.addEventListener("resize", () => this.#prepareLayout());
121570
121526
  };
121571
121527
 
121572
- #isLastSplitter = () => {
121573
- const parent = this.parentElement;
121574
- if (!parent) return false;
121575
-
121576
- const allSplitters = [...parent.querySelectorAll("nx-splitter")];
121577
- return allSplitters.at(-1) === this;
121578
- };
121579
-
121580
- #getSiblingSizeSum = () => {
121581
- const parent = this.parentElement;
121582
- if (!parent) return 0;
121583
-
121584
- const isHorizontal = this.#mode === "h";
121585
-
121586
- return Array.from(parent.children).reduce((sum, el) => {
121587
- const size = isHorizontal ? el.offsetWidth : el.offsetHeight;
121588
- return sum + size;
121589
- }, 0);
121590
- };
121591
-
121592
-
121593
121528
  #prepareLayout = () => {
121594
-
121595
121529
  const isHorizontal = this.#mode === "h";
121530
+ const parent = this.parentElement;
121596
121531
  const prev = this.previousElementSibling;
121597
121532
  const next = this.nextElementSibling;
121598
- const parent = this.parentElement;
121599
121533
  if (!prev || !next || !parent) return;
121600
121534
 
121601
- const currentTotal = this.#getSiblingSizeSum();
121602
- const nextTotal = isHorizontal
121603
- ? parent.getBoundingClientRect().width
121604
- : parent.getBoundingClientRect().height;
121605
-
121606
- const prevSize = isHorizontal ? prev.offsetWidth : prev.offsetHeight;
121607
- const nextSize = isHorizontal ? next.offsetWidth : next.offsetHeight;
121535
+ const parentRect = parent.getBoundingClientRect();
121536
+ const currentPrevSize = isHorizontal ? prev.getBoundingClientRect().width : prev.getBoundingClientRect().height;
121537
+ const currentNextSize = isHorizontal ? next.getBoundingClientRect().width : next.getBoundingClientRect().height;
121608
121538
 
121609
- const newPrevSize = nextTotal * prevSize / currentTotal;
121610
- const newNextSize = nextTotal * nextSize / currentTotal;
121539
+ const totalContentSize = Array.from(parent.children).reduce((sum, el) => {
121540
+ const rect = el.getBoundingClientRect();
121541
+ const size = isHorizontal ? rect.width : rect.height;
121542
+ return sum + size;
121543
+ }, 0);
121611
121544
 
121545
+ const totalParentSize = isHorizontal ? parentRect.width : parentRect.height;
121612
121546
 
121613
- if (isHorizontal) {
121614
- prev.style.width = `${newPrevSize}px`;
121547
+ // 리사이즈 시 비율 유지
121548
+ const newPrevSize = totalParentSize * (currentPrevSize / totalContentSize);
121549
+ const newNextSize = totalParentSize * (currentNextSize / totalContentSize);
121615
121550
 
121616
- if (this.#isLastSplitter()) {
121617
- next.style.width = `${newNextSize}px`;
121618
- }
121619
- } else {
121620
- prev.style.height = `${newPrevSize}px`;
121621
-
121622
- if (this.#isLastSplitter()) {
121623
- next.style.height = `${newNextSize}px`;
121624
- }
121625
- }
121551
+ prev.style.flex = `0 0 ${newPrevSize}px`;
121552
+ next.style.flex = `0 0 ${newNextSize}px`;
121626
121553
  };
121627
-
121628
121554
  }
121629
121555
 
121630
121556
  customElements.define("nx-splitter", nxSplitter);