@ninebone/util 1.0.44 โ†’ 1.0.48

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/nine-util.js CHANGED
@@ -9,7 +9,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
- var _name, _color, _Trace_instances, isTraceEnabled_fn, _a, _timer, _queue, _delay, _TaskDebouncer_instances, flush_fn, _request, _shift, _dialog, _init, _onMouseDown, _onTouchStart, _NineUxUtil_instances, prepare_fn, _mode, _isSiblingOnly, _detectMode, _startDrag, _init2, _prepareLayout, _requestLogin;
12
+ var _name, _color, _Trace_instances, isTraceEnabled_fn, _a, _timer, _queue, _delay, _TaskDebouncer_instances, flush_fn, _request, _shift, _dialog, _init, _onMouseDown, _onTouchStart, _NineUxUtil_instances, prepare_fn, _mode, _isSiblingOnly, _getPrevValidSibling, _getNextValidSibling, _detectMode, _startDrag, _init2, _prepareLayout, _requestLogin;
13
13
  import React from "react";
14
14
  import { createRoot } from "react-dom/client";
15
15
  const listeners = /* @__PURE__ */ new Set();
@@ -908,7 +908,6 @@ class nineDialog extends HTMLElement {
908
908
  connectedCallback() {
909
909
  const v = this.innerHTML;
910
910
  const titleText = this.getAttribute("subject") || "Details";
911
- trace$1.log(dialogStyles);
912
911
  this.innerHTML = `
913
912
  <style>${dialogStyles}</style>
914
913
 
@@ -1156,9 +1155,37 @@ class NineSplitter extends HTMLElement {
1156
1155
  if (attr === null) return false;
1157
1156
  return attr.toLowerCase() === "false" ? false : true;
1158
1157
  });
1158
+ // ๐ŸŽฏ ์‹ค์ œ๋กœ ํ™”๋ฉด์— ๋ณด์ด๋Š” ์ด์ „ ํ˜•์ œ ํŒจ๋„์„ ์ฐพ๋Š” ๋ฉ”์„œ๋“œ
1159
+ __privateAdd(this, _getPrevValidSibling, () => {
1160
+ let el = this.previousElementSibling;
1161
+ while (el) {
1162
+ if (el.tagName.toLowerCase() !== "nine-splitter") {
1163
+ const style = window.getComputedStyle(el);
1164
+ if (style.display !== "none") {
1165
+ return el;
1166
+ }
1167
+ }
1168
+ el = el.previousElementSibling;
1169
+ }
1170
+ return null;
1171
+ });
1172
+ // ๐ŸŽฏ ์‹ค์ œ๋กœ ํ™”๋ฉด์— ๋ณด์ด๋Š” ๋‹ค์Œ ํ˜•์ œ ํŒจ๋„์„ ์ฐพ๋Š” ๋ฉ”์„œ๋“œ
1173
+ __privateAdd(this, _getNextValidSibling, () => {
1174
+ let el = this.nextElementSibling;
1175
+ while (el) {
1176
+ if (el.tagName.toLowerCase() !== "nine-splitter") {
1177
+ const style = window.getComputedStyle(el);
1178
+ if (style.display !== "none") {
1179
+ return el;
1180
+ }
1181
+ }
1182
+ el = el.nextElementSibling;
1183
+ }
1184
+ return null;
1185
+ });
1159
1186
  __privateAdd(this, _detectMode, (el) => {
1160
- const prev = el.previousElementSibling;
1161
- const next = el.nextElementSibling;
1187
+ const prev = __privateGet(this, _getPrevValidSibling).call(this);
1188
+ const next = __privateGet(this, _getNextValidSibling).call(this);
1162
1189
  if (!prev || !next) {
1163
1190
  __privateSet(this, _mode, this.classList.contains("h") ? "h" : "v");
1164
1191
  return;
@@ -1190,8 +1217,8 @@ class NineSplitter extends HTMLElement {
1190
1217
  });
1191
1218
  const root = this.getRootNode({ composed: true });
1192
1219
  const parent = root instanceof ShadowRoot ? root.host : this.parentElement;
1193
- const prev = this.previousElementSibling;
1194
- const next = this.nextElementSibling;
1220
+ const prev = __privateGet(this, _getPrevValidSibling).call(this);
1221
+ const next = __privateGet(this, _getNextValidSibling).call(this);
1195
1222
  if (!parent || !prev || !next) {
1196
1223
  trace$1.warn("Spliter's parent or siblings not found.");
1197
1224
  return;
@@ -1313,7 +1340,7 @@ class NineSplitter extends HTMLElement {
1313
1340
  const htmlTmpl = document.createElement("template");
1314
1341
  htmlTmpl.innerHTML = `
1315
1342
  <style>
1316
- @import "https://cdn.jsdelivr.net/npm/@ninebone/util@${"1.0.44"}/dist/css/nine-util.css";
1343
+ @import "https://cdn.jsdelivr.net/npm/@ninebone/util@${"1.0.48"}/dist/css/nine-util.css";
1317
1344
  ${customImport}
1318
1345
  </style>
1319
1346
  ${gripTmpl}
@@ -1358,6 +1385,8 @@ class NineSplitter extends HTMLElement {
1358
1385
  }
1359
1386
  _mode = new WeakMap();
1360
1387
  _isSiblingOnly = new WeakMap();
1388
+ _getPrevValidSibling = new WeakMap();
1389
+ _getNextValidSibling = new WeakMap();
1361
1390
  _detectMode = new WeakMap();
1362
1391
  _startDrag = new WeakMap();
1363
1392
  _init2 = new WeakMap();
@@ -1857,9 +1886,9 @@ class NineUtil {
1857
1886
  return v + Array(n - String(v).length + 1).join(str || "0");
1858
1887
  });
1859
1888
  __publicField(this, "cut", (v, len) => {
1860
- var str = v;
1861
- var s = 0;
1862
- for (var i = 0; i < str.length; i++) {
1889
+ const str = v;
1890
+ let s = 0;
1891
+ for (let i = 0; i < str.length; i++) {
1863
1892
  s += str.charCodeAt(i) > 128 ? 2 : 1;
1864
1893
  if (s > len) return str.substring(0, i);
1865
1894
  }
@@ -1868,6 +1897,43 @@ class NineUtil {
1868
1897
  __publicField(this, "getByteLength", (v) => {
1869
1898
  return v.replace(/[\0-\x7f]|([0-\u07ff]|(.))/g, "$&$1$2").length;
1870
1899
  });
1900
+ __publicField(this, "oppositeColor", (bgColor, lightColor = "#ffffff", darkColor = "#000000") => {
1901
+ const color = bgColor && bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor || "ffffff";
1902
+ const r = parseInt(color.substring(0, 2), 16);
1903
+ const g = parseInt(color.substring(2, 4), 16);
1904
+ const b = parseInt(color.substring(4, 6), 16);
1905
+ if (isNaN(r) || isNaN(g) || isNaN(b)) return darkColor;
1906
+ const yuv = (r * 299 + g * 587 + b * 114) / 1e3;
1907
+ return yuv >= 128 ? darkColor : lightColor;
1908
+ });
1909
+ __publicField(this, "measureTextSize", (_text, _font = "12px sans-serif") => {
1910
+ if (typeof _text === "number") _text = _text + "";
1911
+ if (!_text) return { width: null, height: null };
1912
+ _text = _text.replaceAll("\n", "<br>");
1913
+ let canvas = document.body.querySelector("canvas#_nine_measure_canvas_");
1914
+ if (!canvas) {
1915
+ canvas = document.createElement("canvas");
1916
+ canvas.id = "_nine_measure_canvas_";
1917
+ canvas.style.cssText = "visibility: hidden;";
1918
+ document.body.appendChild(canvas);
1919
+ }
1920
+ const context = canvas.getContext("2d");
1921
+ context.font = _font;
1922
+ let w = 0;
1923
+ let h = 0;
1924
+ for (let v of _text.split("<br>")) {
1925
+ v = v.replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/ig, "");
1926
+ const metrics = context.measureText(v);
1927
+ w = Math.max(w, metrics.width);
1928
+ const ascent = metrics.fontBoundingBoxAscent || 10;
1929
+ const descent = metrics.fontBoundingBoxDescent || 3;
1930
+ h += ascent + descent;
1931
+ }
1932
+ return {
1933
+ width: w,
1934
+ height: h
1935
+ };
1936
+ });
1871
1937
  /**
1872
1938
  * ๐Ÿ”ฎ ์ดˆ๊ฐ„๋‹จ ๋งŒ๋Šฅ ๋“œ๋ž˜๊ทธ ํŒ์—… ์—”์ง„ (Promise/Then ๊ทœ๊ฒฉ)
1873
1939
  * @param {React.Component} ContentComponent - ํŒ์—… ๋‚ด๋ถ€์— ๋„์šธ ๋ฆฌ์•กํŠธ ์ปดํฌ๋„ŒํŠธ