pds-dev-kit-web-test 2.2.86 → 2.2.87

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.
@@ -1,3 +1,4 @@
1
+ import { RefObject } from 'react';
1
2
  import type { DynamicLayoutProps } from '../../../../../../../DynamicLayout/types';
2
- declare const useMaxFontAdjustment: (ref: any, defaultSize: string, mode: DynamicLayoutProps['mode']) => number;
3
+ declare const useMaxFontAdjustment: (ref: RefObject<HTMLDivElement>, defaultSize: string, mode: DynamicLayoutProps['mode']) => number;
3
4
  export default useMaxFontAdjustment;
@@ -4,19 +4,28 @@ var react_1 = require("react");
4
4
  var DEFAULT_BASE_FONT = 16;
5
5
  var useMaxFontAdjustment = function (ref, defaultSize, mode) {
6
6
  var _a = (0, react_1.useState)(DEFAULT_BASE_FONT), fontSize = _a[0], setFontSize = _a[1];
7
+ var ogRef = (0, react_1.useRef)(0);
7
8
  (0, react_1.useEffect)(function () {
8
9
  if (mode !== 'PREVIEW') {
9
10
  return;
10
11
  }
11
12
  if (!ref.current)
12
13
  return;
14
+ if (fontSize === 16) {
15
+ var boxHeight = ref.current.clientHeight;
16
+ var contentHeight = ref.current.children[0].children[0].clientHeight;
17
+ var percent = (contentHeight / boxHeight) * 100;
18
+ ogRef.current = percent;
19
+ }
13
20
  var resizeObserver = new ResizeObserver(function (callback) {
14
21
  var object = callback[0];
15
- var height = object.contentRect.height;
22
+ var height = object.target.clientHeight;
16
23
  var contentHeight = object.target.children[0].children[0].clientHeight;
24
+ var p = (contentHeight / height) * 100;
17
25
  var isOverflow = contentHeight > height;
18
- if (isOverflow) {
19
- setFontSize(function (prev) { return prev - 0.3; });
26
+ var hasContentGap = p > ogRef.current;
27
+ if (isOverflow || hasContentGap) {
28
+ setFontSize(function (prev) { return Number((prev - 0.3).toFixed(3)); });
20
29
  // setFontSize((prev) => {
21
30
  // const value = parseEmToNumber(prev);
22
31
  // if (value === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pds-dev-kit-web-test",
3
- "version": "2.2.86",
3
+ "version": "2.2.87",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "dist/index.js",