@julseb-lib/react 1.0.46 → 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/index.cjs +65 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -11
- package/dist/index.d.ts +15 -11
- package/dist/index.js +65 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2499,48 +2499,75 @@ var usePagination = ({
|
|
|
2499
2499
|
|
|
2500
2500
|
// src/lib/hooks/useTextLineCount.tsx
|
|
2501
2501
|
var import_react14 = require("react");
|
|
2502
|
-
var useTextLineCount = (text,
|
|
2503
|
-
const [
|
|
2504
|
-
const
|
|
2502
|
+
var useTextLineCount = (text, fontSize = 16) => {
|
|
2503
|
+
const [visualLines, setVisualLines] = (0, import_react14.useState)(1);
|
|
2504
|
+
const elementRef = (0, import_react14.useRef)(
|
|
2505
|
+
null
|
|
2506
|
+
);
|
|
2505
2507
|
const measureLines = (0, import_react14.useCallback)(() => {
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
+
const element = elementRef.current;
|
|
2509
|
+
if (!element || !text) {
|
|
2510
|
+
setVisualLines(1);
|
|
2511
|
+
return;
|
|
2508
2512
|
}
|
|
2509
|
-
const
|
|
2510
|
-
const
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
+
const computedStyle = getComputedStyle(element);
|
|
2514
|
+
const paddingLeft = parseInt(computedStyle.paddingLeft) || 0;
|
|
2515
|
+
const paddingRight = parseInt(computedStyle.paddingRight) || 0;
|
|
2516
|
+
const borderLeft = parseInt(computedStyle.borderLeftWidth) || 0;
|
|
2517
|
+
const borderRight = parseInt(computedStyle.borderRightWidth) || 0;
|
|
2518
|
+
const actualWidth = element.offsetWidth - paddingLeft - paddingRight - borderLeft - borderRight;
|
|
2519
|
+
if (actualWidth <= 0) {
|
|
2520
|
+
setVisualLines(1);
|
|
2513
2521
|
return;
|
|
2514
2522
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2523
|
+
try {
|
|
2524
|
+
const hiddenDiv = document.createElement("div");
|
|
2525
|
+
hiddenDiv.style.position = "absolute";
|
|
2526
|
+
hiddenDiv.style.visibility = "hidden";
|
|
2527
|
+
hiddenDiv.style.height = "auto";
|
|
2528
|
+
hiddenDiv.style.width = `${actualWidth}px`;
|
|
2529
|
+
hiddenDiv.style.fontSize = computedStyle.fontSize || `${fontSize}px`;
|
|
2530
|
+
hiddenDiv.style.fontFamily = computedStyle.fontFamily || "system-ui";
|
|
2531
|
+
hiddenDiv.style.lineHeight = computedStyle.lineHeight || "1.2";
|
|
2532
|
+
hiddenDiv.style.wordWrap = "break-word";
|
|
2533
|
+
hiddenDiv.style.whiteSpace = "pre-wrap";
|
|
2534
|
+
hiddenDiv.style.padding = "0";
|
|
2535
|
+
hiddenDiv.style.margin = "0";
|
|
2536
|
+
hiddenDiv.style.border = "none";
|
|
2537
|
+
document.body.appendChild(hiddenDiv);
|
|
2538
|
+
hiddenDiv.textContent = text;
|
|
2539
|
+
const elementHeight = hiddenDiv.offsetHeight;
|
|
2540
|
+
const lineHeight = parseInt(getComputedStyle(hiddenDiv).lineHeight) || fontSize * 1.2;
|
|
2541
|
+
const calculatedLines = Math.max(
|
|
2542
|
+
1,
|
|
2543
|
+
Math.round(elementHeight / lineHeight)
|
|
2544
|
+
);
|
|
2545
|
+
document.body.removeChild(hiddenDiv);
|
|
2546
|
+
setVisualLines(calculatedLines);
|
|
2547
|
+
} catch (error) {
|
|
2548
|
+
console.warn("Element line count measurement failed:", error);
|
|
2549
|
+
setVisualLines(text.split("\n").length);
|
|
2550
|
+
}
|
|
2551
|
+
}, [text, fontSize]);
|
|
2540
2552
|
(0, import_react14.useEffect)(() => {
|
|
2541
|
-
measureLines
|
|
2553
|
+
const timer = setTimeout(measureLines, 50);
|
|
2554
|
+
return () => clearTimeout(timer);
|
|
2542
2555
|
}, [measureLines]);
|
|
2543
|
-
|
|
2556
|
+
(0, import_react14.useEffect)(() => {
|
|
2557
|
+
const element = elementRef.current;
|
|
2558
|
+
if (!element) return;
|
|
2559
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
2560
|
+
measureLines();
|
|
2561
|
+
});
|
|
2562
|
+
resizeObserver.observe(element);
|
|
2563
|
+
return () => {
|
|
2564
|
+
resizeObserver.disconnect();
|
|
2565
|
+
};
|
|
2566
|
+
}, [measureLines]);
|
|
2567
|
+
return {
|
|
2568
|
+
visualLines,
|
|
2569
|
+
elementRef
|
|
2570
|
+
};
|
|
2544
2571
|
};
|
|
2545
2572
|
|
|
2546
2573
|
// src/lib/hooks/useTouchScreen.tsx
|
|
@@ -69962,9 +69989,9 @@ var PageLayout = ({
|
|
|
69962
69989
|
}) => {
|
|
69963
69990
|
return /* @__PURE__ */ (0, import_jsx_runtime370.jsxs)(import_jsx_runtime370.Fragment, { children: [
|
|
69964
69991
|
meta && /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Meta, { ...meta }),
|
|
69965
|
-
(0, import_react118.isValidElement)(header) ? header : /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Header, { ...header }),
|
|
69992
|
+
header && ((0, import_react118.isValidElement)(header) ? header : /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Header, { ...header })),
|
|
69966
69993
|
!noWrapper ? /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Wrapper, { ...wrapperProps, children: !noMain ? /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Main, { ...mainProps, children }) : children }) : children,
|
|
69967
|
-
(0, import_react118.isValidElement)(footer) ? footer : /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Footer, { ...footer })
|
|
69994
|
+
footer && ((0, import_react118.isValidElement)(footer) ? footer : /* @__PURE__ */ (0, import_jsx_runtime370.jsx)(Footer, { ...footer }))
|
|
69968
69995
|
] });
|
|
69969
69996
|
};
|
|
69970
69997
|
|