@elliemae/ds-hooks-fontsize-detector 3.80.0-next.54 → 3.80.0-next.56

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.
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var DSHooksFontsizeDetector_exports = {};
30
30
  __export(DSHooksFontsizeDetector_exports, {
31
+ UseFontSizeDetectorWithSchema: () => UseFontSizeDetectorWithSchema,
31
32
  useFontSizeDetector: () => useFontSizeDetector
32
33
  });
33
34
  module.exports = __toCommonJS(DSHooksFontsizeDetector_exports);
@@ -35,7 +36,9 @@ var React = __toESM(require("react"));
35
36
  var import_jsx_runtime = require("react/jsx-runtime");
36
37
  var import_lodash_es = require("lodash-es");
37
38
  var import_react = __toESM(require("react"));
39
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
38
40
  var import_constants = require("./constants/index.js");
41
+ var import_react_desc_prop_types = require("./react-desc-prop-types.js");
39
42
  var import_utils = require("./utils.js");
40
43
  const FontDetectorElement = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
41
44
  "p",
@@ -108,4 +111,7 @@ const useFontSizeDetector = () => {
108
111
  isSmall: ratio > import_constants.BREAKPOINTS.small
109
112
  };
110
113
  };
114
+ useFontSizeDetector.displayName = "useFontSizeDetector";
115
+ const UseFontSizeDetectorWithSchema = (0, import_ds_props_helpers.describe)(useFontSizeDetector);
116
+ UseFontSizeDetectorWithSchema.returnType = import_react_desc_prop_types.UseFontSizeDetectorReturnType;
111
117
  //# sourceMappingURL=DSHooksFontsizeDetector.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/DSHooksFontsizeDetector.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable react-hooks/exhaustive-deps */\nimport { debounce } from 'lodash-es';\nimport React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { BREAKPOINTS, FONT_DETECTOR_UID } from './constants/index.js';\nimport { type DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';\nimport { appendComponentIfNotExist } from './utils.js';\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst FontDetectorElement = (): JSX.Element => (\n <p\n aria-hidden=\"true\"\n id={FONT_DETECTOR_UID}\n data-testid={FONT_DETECTOR_UID}\n style={{\n margin: 0,\n color: 'transparent',\n position: 'absolute',\n }}\n >\n &nbsp;\n </p>\n);\n\nconst useResizeObserver = (ref: HTMLElement | null): number => {\n const [dimensions, setDimensions] = React.useState<number>(0);\n\n useEffect(() => {\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.height));\n });\n });\n if (ref) {\n resizeObserver.observe(ref);\n }\n\n return () => {\n if (ref) {\n resizeObserver.unobserve(ref);\n }\n };\n }, [ref]);\n return dimensions;\n};\n\nconst useFontSizeDetector = (): DSHooksFontsizeDetectorT.UseFontSizeDetectorT => {\n const [ref, setRef] = useState<HTMLElement | null>(null);\n const [parentWidth, setParentWidth] = useState<number>(document.documentElement.clientWidth);\n const fontHeight = useResizeObserver(ref);\n\n useEffect(() => {\n const retrieveElement = async () => {\n const elementAppended = await appendComponentIfNotExist({\n Component: FontDetectorElement,\n uidSelector: FONT_DETECTOR_UID,\n tagName: 'font-size',\n });\n setRef(elementAppended);\n };\n retrieveElement().catch(() => {});\n }, []);\n\n const ratio = useMemo(() => Math.floor(parentWidth / (fontHeight || 1)), [fontHeight, parentWidth]);\n\n const viewPortChange = useCallback(\n debounce(() => {\n setParentWidth(document.documentElement.clientWidth);\n }, 200),\n [],\n );\n\n useEffect(() => {\n window.addEventListener('resize', viewPortChange);\n return () => {\n window.removeEventListener('resize', viewPortChange);\n };\n }, [viewPortChange]);\n return {\n ratio,\n fontHeight,\n documentWidthRatio: parentWidth,\n isLarge: ratio <= BREAKPOINTS.large,\n isMedium: ratio > BREAKPOINTS.large && ratio <= BREAKPOINTS.medimum,\n isSmall: ratio > BREAKPOINTS.small,\n };\n};\n\nexport { useFontSizeDetector };\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADUrB;AATF,uBAAyB;AACzB,mBAAiE;AACjE,uBAA+C;AAE/C,mBAA0C;AAI1C,MAAM,sBAAsB,MAC1B;AAAA,EAAC;AAAA;AAAA,IACC,eAAY;AAAA,IACZ,IAAI;AAAA,IACJ,eAAa;AAAA,IACb,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,IACD;AAAA;AAED;AAGF,MAAM,oBAAoB,CAAC,QAAoC;AAC7D,QAAM,CAAC,YAAY,aAAa,IAAI,aAAAA,QAAM,SAAiB,CAAC;AAE5D,8BAAU,MAAM;AACd,UAAM,iBAAiB,IAAI,eAAe,CAAC,YAA8C;AACvF,cAAQ,QAAQ,CAAC,UAAU;AACzB,sBAAc,KAAK,KAAK,MAAM,YAAY,MAAM,CAAC;AAAA,MACnD,CAAC;AAAA,IACH,CAAC;AACD,QAAI,KAAK;AACP,qBAAe,QAAQ,GAAG;AAAA,IAC5B;AAEA,WAAO,MAAM;AACX,UAAI,KAAK;AACP,uBAAe,UAAU,GAAG;AAAA,MAC9B;AAAA,IACF;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACR,SAAO;AACT;AAEA,MAAM,sBAAsB,MAAqD;AAC/E,QAAM,CAAC,KAAK,MAAM,QAAI,uBAA6B,IAAI;AACvD,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAiB,SAAS,gBAAgB,WAAW;AAC3F,QAAM,aAAa,kBAAkB,GAAG;AAExC,8BAAU,MAAM;AACd,UAAM,kBAAkB,YAAY;AAClC,YAAM,kBAAkB,UAAM,wCAA0B;AAAA,QACtD,WAAW;AAAA,QACX,aAAa;AAAA,QACb,SAAS;AAAA,MACX,CAAC;AACD,aAAO,eAAe;AAAA,IACxB;AACA,oBAAgB,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAAA,EAClC,GAAG,CAAC,CAAC;AAEL,QAAM,YAAQ,sBAAQ,MAAM,KAAK,MAAM,eAAe,cAAc,EAAE,GAAG,CAAC,YAAY,WAAW,CAAC;AAElG,QAAM,qBAAiB;AAAA,QACrB,2BAAS,MAAM;AACb,qBAAe,SAAS,gBAAgB,WAAW;AAAA,IACrD,GAAG,GAAG;AAAA,IACN,CAAC;AAAA,EACH;AAEA,8BAAU,MAAM;AACd,WAAO,iBAAiB,UAAU,cAAc;AAChD,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,cAAc;AAAA,IACrD;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AACnB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,IACpB,SAAS,SAAS,6BAAY;AAAA,IAC9B,UAAU,QAAQ,6BAAY,SAAS,SAAS,6BAAY;AAAA,IAC5D,SAAS,QAAQ,6BAAY;AAAA,EAC/B;AACF;",
4
+ "sourcesContent": ["/* eslint-disable react-hooks/exhaustive-deps */\nimport { debounce } from 'lodash-es';\nimport React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { BREAKPOINTS, FONT_DETECTOR_UID } from './constants/index.js';\nimport { type DSHooksFontsizeDetectorT, UseFontSizeDetectorReturnType } from './react-desc-prop-types.js';\nimport { appendComponentIfNotExist } from './utils.js';\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst FontDetectorElement = (): JSX.Element => (\n <p\n aria-hidden=\"true\"\n id={FONT_DETECTOR_UID}\n data-testid={FONT_DETECTOR_UID}\n style={{\n margin: 0,\n color: 'transparent',\n position: 'absolute',\n }}\n >\n &nbsp;\n </p>\n);\n\nconst useResizeObserver = (ref: HTMLElement | null): number => {\n const [dimensions, setDimensions] = React.useState<number>(0);\n\n useEffect(() => {\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.height));\n });\n });\n if (ref) {\n resizeObserver.observe(ref);\n }\n\n return () => {\n if (ref) {\n resizeObserver.unobserve(ref);\n }\n };\n }, [ref]);\n return dimensions;\n};\n\nconst useFontSizeDetector = (): DSHooksFontsizeDetectorT.UseFontSizeDetectorT => {\n const [ref, setRef] = useState<HTMLElement | null>(null);\n const [parentWidth, setParentWidth] = useState<number>(document.documentElement.clientWidth);\n const fontHeight = useResizeObserver(ref);\n\n useEffect(() => {\n const retrieveElement = async () => {\n const elementAppended = await appendComponentIfNotExist({\n Component: FontDetectorElement,\n uidSelector: FONT_DETECTOR_UID,\n tagName: 'font-size',\n });\n setRef(elementAppended);\n };\n retrieveElement().catch(() => {});\n }, []);\n\n const ratio = useMemo(() => Math.floor(parentWidth / (fontHeight || 1)), [fontHeight, parentWidth]);\n\n const viewPortChange = useCallback(\n debounce(() => {\n setParentWidth(document.documentElement.clientWidth);\n }, 200),\n [],\n );\n\n useEffect(() => {\n window.addEventListener('resize', viewPortChange);\n return () => {\n window.removeEventListener('resize', viewPortChange);\n };\n }, [viewPortChange]);\n return {\n ratio,\n fontHeight,\n documentWidthRatio: parentWidth,\n isLarge: ratio <= BREAKPOINTS.large,\n isMedium: ratio > BREAKPOINTS.large && ratio <= BREAKPOINTS.medimum,\n isSmall: ratio > BREAKPOINTS.small,\n };\n};\n\nuseFontSizeDetector.displayName = 'useFontSizeDetector';\nconst UseFontSizeDetectorWithSchema = describe(useFontSizeDetector);\n\nUseFontSizeDetectorWithSchema.returnType = UseFontSizeDetectorReturnType;\n\nexport { useFontSizeDetector, UseFontSizeDetectorWithSchema };\n", "import *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,IACxB;AACA,oBAAgB,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAAA,EAClC,GAAG,CAAC,CAAC;AAEL,QAAM,YAAQ,sBAAQ,MAAM,KAAK,MAAM,eAAe,cAAc,EAAE,GAAG,CAAC,YAAY,WAAW,CAAC;AAElG,QAAM,qBAAiB;AAAA,QACrB,2BAAS,MAAM;AACb,qBAAe,SAAS,gBAAgB,WAAW;AAAA,IACrD,GAAG,GAAG;AAAA,IACN,CAAC;AAAA,EACH;AAEA,8BAAU,MAAM;AACd,WAAO,iBAAiB,UAAU,cAAc;AAChD,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,cAAc;AAAA,IACrD;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AACnB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,IACpB,SAAS,SAAS,6BAAY;AAAA,IAC9B,UAAU,QAAQ,6BAAY,SAAS,SAAS,6BAAY;AAAA,IAC5D,SAAS,QAAQ,6BAAY;AAAA,EAC/B;AACF;AAEA,oBAAoB,cAAc;AAClC,MAAM,oCAAgC,kCAAS,mBAAmB;AAElE,8BAA8B,aAAa;",
6
6
  "names": ["React"]
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var index_exports = {};
30
30
  __export(index_exports, {
31
31
  FONT_DETECTOR_UID: () => import_constants.FONT_DETECTOR_UID,
32
+ UseFontSizeDetectorWithSchema: () => import_DSHooksFontsizeDetector.UseFontSizeDetectorWithSchema,
32
33
  useFontSizeDetector: () => import_DSHooksFontsizeDetector.useFontSizeDetector
33
34
  });
34
35
  module.exports = __toCommonJS(index_exports);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["// this is a workaround to typescript error TS2742\n// https://github.com/microsoft/TypeScript/issues/47663\nexport { useFontSizeDetector } from './DSHooksFontsizeDetector.js';\nexport { FONT_DETECTOR_UID } from './constants/index.js';\nexport type { DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,qCAAoC;AACpC,uBAAkC;",
4
+ "sourcesContent": ["// this is a workaround to typescript error TS2742\n// https://github.com/microsoft/TypeScript/issues/47663\nexport { useFontSizeDetector, UseFontSizeDetectorWithSchema } from './DSHooksFontsizeDetector.js';\nexport { FONT_DETECTOR_UID } from './constants/index.js';\nexport type { DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,qCAAmE;AACnE,uBAAkC;",
6
6
  "names": []
7
7
  }
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
8
12
  var __copyProps = (to, from, except, desc) => {
9
13
  if (from && typeof from === "object" || typeof from === "function") {
10
14
  for (let key of __getOwnPropNames(from))
@@ -23,6 +27,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
27
  ));
24
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
29
  var react_desc_prop_types_exports = {};
30
+ __export(react_desc_prop_types_exports, {
31
+ UseFontSizeDetectorReturnType: () => UseFontSizeDetectorReturnType
32
+ });
26
33
  module.exports = __toCommonJS(react_desc_prop_types_exports);
27
34
  var React = __toESM(require("react"));
35
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
36
+ const UseFontSizeDetectorReturnType = {
37
+ ratio: import_ds_props_helpers.PropTypes.number.description(
38
+ "The document width divided by the height of the detector element, rounded down. The larger the user font size, the lower the ratio."
39
+ ).isRequired,
40
+ fontHeight: import_ds_props_helpers.PropTypes.number.description(
41
+ "Height in pixels of the hidden detector element, which tracks the font size the user has chosen."
42
+ ).isRequired,
43
+ documentWidthRatio: import_ds_props_helpers.PropTypes.number.description(
44
+ "Width in pixels of the document. It is updated, debounced, when the viewport is resized."
45
+ ).isRequired,
46
+ isLarge: import_ds_props_helpers.PropTypes.bool.description("True when the ratio is at or below the large breakpoint (30).").isRequired,
47
+ isMedium: import_ds_props_helpers.PropTypes.bool.description(
48
+ "True when the ratio is above the large breakpoint (30) and at or below the medium breakpoint (40)."
49
+ ).isRequired,
50
+ isSmall: import_ds_props_helpers.PropTypes.bool.description("True when the ratio is above the small breakpoint (60).").isRequired
51
+ };
28
52
  //# sourceMappingURL=react-desc-prop-types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/react-desc-prop-types.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export declare namespace DSHooksFontsizeDetectorT {\n export interface UseFontSizeDetectorT {\n ratio: number;\n fontHeight: number;\n documentWidthRatio: number;\n isSmall: boolean;\n isMedium: boolean;\n isLarge: boolean;\n }\n}\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;ACAA,YAAuB;",
4
+ "sourcesContent": ["import { PropTypes } from '@elliemae/ds-props-helpers';\n\nexport declare namespace DSHooksFontsizeDetectorT {\n export interface UseFontSizeDetectorT {\n ratio: number;\n fontHeight: number;\n documentWidthRatio: number;\n isSmall: boolean;\n isMedium: boolean;\n isLarge: boolean;\n }\n}\n\nexport const UseFontSizeDetectorReturnType = {\n ratio: PropTypes.number.description(\n 'The document width divided by the height of the detector element, rounded down. The larger the user font size, the lower the ratio.',\n ).isRequired,\n fontHeight: PropTypes.number.description(\n 'Height in pixels of the hidden detector element, which tracks the font size the user has chosen.',\n ).isRequired,\n documentWidthRatio: PropTypes.number.description(\n 'Width in pixels of the document. It is updated, debounced, when the viewport is resized.',\n ).isRequired,\n isLarge: PropTypes.bool.description('True when the ratio is at or below the large breakpoint (30).').isRequired,\n isMedium: PropTypes.bool.description(\n 'True when the ratio is above the large breakpoint (30) and at or below the medium breakpoint (40).',\n ).isRequired,\n isSmall: PropTypes.bool.description('True when the ratio is above the small breakpoint (60).').isRequired,\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAA0B;AAanB,MAAM,gCAAgC;AAAA,EAC3C,OAAO,kCAAU,OAAO;AAAA,IACtB;AAAA,EACF,EAAE;AAAA,EACF,YAAY,kCAAU,OAAO;AAAA,IAC3B;AAAA,EACF,EAAE;AAAA,EACF,oBAAoB,kCAAU,OAAO;AAAA,IACnC;AAAA,EACF,EAAE;AAAA,EACF,SAAS,kCAAU,KAAK,YAAY,+DAA+D,EAAE;AAAA,EACrG,UAAU,kCAAU,KAAK;AAAA,IACvB;AAAA,EACF,EAAE;AAAA,EACF,SAAS,kCAAU,KAAK,YAAY,yDAAyD,EAAE;AACjG;",
6
6
  "names": []
7
7
  }
@@ -2,7 +2,9 @@ import * as React from "react";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { debounce } from "lodash-es";
4
4
  import React2, { useCallback, useEffect, useMemo, useState } from "react";
5
+ import { describe } from "@elliemae/ds-props-helpers";
5
6
  import { BREAKPOINTS, FONT_DETECTOR_UID } from "./constants/index.js";
7
+ import { UseFontSizeDetectorReturnType } from "./react-desc-prop-types.js";
6
8
  import { appendComponentIfNotExist } from "./utils.js";
7
9
  const FontDetectorElement = () => /* @__PURE__ */ jsx(
8
10
  "p",
@@ -75,7 +77,11 @@ const useFontSizeDetector = () => {
75
77
  isSmall: ratio > BREAKPOINTS.small
76
78
  };
77
79
  };
80
+ useFontSizeDetector.displayName = "useFontSizeDetector";
81
+ const UseFontSizeDetectorWithSchema = describe(useFontSizeDetector);
82
+ UseFontSizeDetectorWithSchema.returnType = UseFontSizeDetectorReturnType;
78
83
  export {
84
+ UseFontSizeDetectorWithSchema,
79
85
  useFontSizeDetector
80
86
  };
81
87
  //# sourceMappingURL=DSHooksFontsizeDetector.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSHooksFontsizeDetector.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react-hooks/exhaustive-deps */\nimport { debounce } from 'lodash-es';\nimport React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { BREAKPOINTS, FONT_DETECTOR_UID } from './constants/index.js';\nimport { type DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';\nimport { appendComponentIfNotExist } from './utils.js';\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst FontDetectorElement = (): JSX.Element => (\n <p\n aria-hidden=\"true\"\n id={FONT_DETECTOR_UID}\n data-testid={FONT_DETECTOR_UID}\n style={{\n margin: 0,\n color: 'transparent',\n position: 'absolute',\n }}\n >\n &nbsp;\n </p>\n);\n\nconst useResizeObserver = (ref: HTMLElement | null): number => {\n const [dimensions, setDimensions] = React.useState<number>(0);\n\n useEffect(() => {\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.height));\n });\n });\n if (ref) {\n resizeObserver.observe(ref);\n }\n\n return () => {\n if (ref) {\n resizeObserver.unobserve(ref);\n }\n };\n }, [ref]);\n return dimensions;\n};\n\nconst useFontSizeDetector = (): DSHooksFontsizeDetectorT.UseFontSizeDetectorT => {\n const [ref, setRef] = useState<HTMLElement | null>(null);\n const [parentWidth, setParentWidth] = useState<number>(document.documentElement.clientWidth);\n const fontHeight = useResizeObserver(ref);\n\n useEffect(() => {\n const retrieveElement = async () => {\n const elementAppended = await appendComponentIfNotExist({\n Component: FontDetectorElement,\n uidSelector: FONT_DETECTOR_UID,\n tagName: 'font-size',\n });\n setRef(elementAppended);\n };\n retrieveElement().catch(() => {});\n }, []);\n\n const ratio = useMemo(() => Math.floor(parentWidth / (fontHeight || 1)), [fontHeight, parentWidth]);\n\n const viewPortChange = useCallback(\n debounce(() => {\n setParentWidth(document.documentElement.clientWidth);\n }, 200),\n [],\n );\n\n useEffect(() => {\n window.addEventListener('resize', viewPortChange);\n return () => {\n window.removeEventListener('resize', viewPortChange);\n };\n }, [viewPortChange]);\n return {\n ratio,\n fontHeight,\n documentWidthRatio: parentWidth,\n isLarge: ratio <= BREAKPOINTS.large,\n isMedium: ratio > BREAKPOINTS.large && ratio <= BREAKPOINTS.medimum,\n isSmall: ratio > BREAKPOINTS.small,\n };\n};\n\nexport { useFontSizeDetector };\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACUrB;AATF,SAAS,gBAAgB;AACzB,OAAOA,UAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAS,aAAa,yBAAyB;AAE/C,SAAS,iCAAiC;AAI1C,MAAM,sBAAsB,MAC1B;AAAA,EAAC;AAAA;AAAA,IACC,eAAY;AAAA,IACZ,IAAI;AAAA,IACJ,eAAa;AAAA,IACb,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,IACD;AAAA;AAED;AAGF,MAAM,oBAAoB,CAAC,QAAoC;AAC7D,QAAM,CAAC,YAAY,aAAa,IAAIA,OAAM,SAAiB,CAAC;AAE5D,YAAU,M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AY;AAAA,IAC9B,UAAU,QAAQ,YAAY,SAAS,SAAS,YAAY;AAAA,IAC5D,SAAS,QAAQ,YAAY;AAAA,EAC/B;AACF;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react-hooks/exhaustive-deps */\nimport { debounce } from 'lodash-es';\nimport React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { BREAKPOINTS, FONT_DETECTOR_UID } from './constants/index.js';\nimport { type DSHooksFontsizeDetectorT, UseFontSizeDetectorReturnType } from './react-desc-prop-types.js';\nimport { appendComponentIfNotExist } from './utils.js';\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst FontDetectorElement = (): JSX.Element => (\n <p\n aria-hidden=\"true\"\n id={FONT_DETECTOR_UID}\n data-testid={FONT_DETECTOR_UID}\n style={{\n margin: 0,\n color: 'transparent',\n position: 'absolute',\n }}\n >\n &nbsp;\n </p>\n);\n\nconst useResizeObserver = (ref: HTMLElement | null): number => {\n const [dimensions, setDimensions] = React.useState<number>(0);\n\n useEffect(() => {\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.height));\n });\n });\n if (ref) {\n resizeObserver.observe(ref);\n }\n\n return () => {\n if (ref) {\n resizeObserver.unobserve(ref);\n }\n };\n }, [ref]);\n return dimensions;\n};\n\nconst useFontSizeDetector = (): DSHooksFontsizeDetectorT.UseFontSizeDetectorT => {\n const [ref, setRef] = useState<HTMLElement | null>(null);\n const [parentWidth, setParentWidth] = useState<number>(document.documentElement.clientWidth);\n const fontHeight = useResizeObserver(ref);\n\n useEffect(() => {\n const retrieveElement = async () => {\n const elementAppended = await appendComponentIfNotExist({\n Component: FontDetectorElement,\n uidSelector: FONT_DETECTOR_UID,\n tagName: 'font-size',\n });\n setRef(elementAppended);\n };\n retrieveElement().catch(() => {});\n }, []);\n\n const ratio = useMemo(() => Math.floor(parentWidth / (fontHeight || 1)), [fontHeight, parentWidth]);\n\n const viewPortChange = useCallback(\n debounce(() => {\n setParentWidth(document.documentElement.clientWidth);\n }, 200),\n [],\n );\n\n useEffect(() => {\n window.addEventListener('resize', viewPortChange);\n return () => {\n window.removeEventListener('resize', viewPortChange);\n };\n }, [viewPortChange]);\n return {\n ratio,\n fontHeight,\n documentWidthRatio: parentWidth,\n isLarge: ratio <= BREAKPOINTS.large,\n isMedium: ratio > BREAKPOINTS.large && ratio <= BREAKPOINTS.medimum,\n isSmall: ratio > BREAKPOINTS.small,\n };\n};\n\nuseFontSizeDetector.displayName = 'useFontSizeDetector';\nconst UseFontSizeDetectorWithSchema = describe(useFontSizeDetector);\n\nUseFontSizeDetectorWithSchema.returnType = UseFontSizeDetectorReturnType;\n\nexport { useFontSizeDetector, UseFontSizeDetectorWithSchema };\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACWrB;AAVF,SAAS,gBAAgB;AACzB,OAAOA,UAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAS,gBAAgB;AACzB,SAAS,aAAa,yBAAyB;AAC/C,SAAwC,qCAAqC;AAC7E,SAAS,iCAAiC;AAI1C,MAAM,sBAAsB,MAC1B;AAAA,EAAC;AAAA;AAAA,IACC,eAAY;AAAA,IACZ,IAAI;AAAA,IACJ,eAAa;AAAA,IACb,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,IACD;AAAA;AAED;AAGF,MAAM,oBAAoB,CAAC,QAAoC;AAC7D,QAAM,CAAC,YAAY,aAAa,IAAIA,OAAM,SAAiB,CAAC;AAE5D,YAAU,MAAM;AACd,UAAM,iBAAiB,IAAI,eAAe,CAAC,YAA8C;AACvF,cAAQ,QAAQ,CAAC,UAAU;AACzB,sBAAc,KAAK,KAAK,MAAM,YAAY,MAAM,CAAC;AAAA,MACnD,CAAC;AAAA,IACH,CAA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E,8BAA8B,aAAa;",
6
6
  "names": ["React"]
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as React from "react";
2
- import { useFontSizeDetector } from "./DSHooksFontsizeDetector.js";
2
+ import { useFontSizeDetector, UseFontSizeDetectorWithSchema } from "./DSHooksFontsizeDetector.js";
3
3
  import { FONT_DETECTOR_UID } from "./constants/index.js";
4
4
  export {
5
5
  FONT_DETECTOR_UID,
6
+ UseFontSizeDetectorWithSchema,
6
7
  useFontSizeDetector
7
8
  };
8
9
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "// this is a workaround to typescript error TS2742\n// https://github.com/microsoft/TypeScript/issues/47663\nexport { useFontSizeDetector } from './DSHooksFontsizeDetector.js';\nexport { FONT_DETECTOR_UID } from './constants/index.js';\nexport type { DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "// this is a workaround to typescript error TS2742\n// https://github.com/microsoft/TypeScript/issues/47663\nexport { useFontSizeDetector, UseFontSizeDetectorWithSchema } from './DSHooksFontsizeDetector.js';\nexport { FONT_DETECTOR_UID } from './constants/index.js';\nexport type { DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,qBAAqB,qCAAqC;AACnE,SAAS,yBAAyB;",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,22 @@
1
1
  import * as React from "react";
2
+ import { PropTypes } from "@elliemae/ds-props-helpers";
3
+ const UseFontSizeDetectorReturnType = {
4
+ ratio: PropTypes.number.description(
5
+ "The document width divided by the height of the detector element, rounded down. The larger the user font size, the lower the ratio."
6
+ ).isRequired,
7
+ fontHeight: PropTypes.number.description(
8
+ "Height in pixels of the hidden detector element, which tracks the font size the user has chosen."
9
+ ).isRequired,
10
+ documentWidthRatio: PropTypes.number.description(
11
+ "Width in pixels of the document. It is updated, debounced, when the viewport is resized."
12
+ ).isRequired,
13
+ isLarge: PropTypes.bool.description("True when the ratio is at or below the large breakpoint (30).").isRequired,
14
+ isMedium: PropTypes.bool.description(
15
+ "True when the ratio is above the large breakpoint (30) and at or below the medium breakpoint (40)."
16
+ ).isRequired,
17
+ isSmall: PropTypes.bool.description("True when the ratio is above the small breakpoint (60).").isRequired
18
+ };
19
+ export {
20
+ UseFontSizeDetectorReturnType
21
+ };
2
22
  //# sourceMappingURL=react-desc-prop-types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n"],
5
- "mappings": "AAAA,YAAY,WAAW;",
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/react-desc-prop-types.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from '@elliemae/ds-props-helpers';\n\nexport declare namespace DSHooksFontsizeDetectorT {\n export interface UseFontSizeDetectorT {\n ratio: number;\n fontHeight: number;\n documentWidthRatio: number;\n isSmall: boolean;\n isMedium: boolean;\n isLarge: boolean;\n }\n}\n\nexport const UseFontSizeDetectorReturnType = {\n ratio: PropTypes.number.description(\n 'The document width divided by the height of the detector element, rounded down. The larger the user font size, the lower the ratio.',\n ).isRequired,\n fontHeight: PropTypes.number.description(\n 'Height in pixels of the hidden detector element, which tracks the font size the user has chosen.',\n ).isRequired,\n documentWidthRatio: PropTypes.number.description(\n 'Width in pixels of the document. It is updated, debounced, when the viewport is resized.',\n ).isRequired,\n isLarge: PropTypes.bool.description('True when the ratio is at or below the large breakpoint (30).').isRequired,\n isMedium: PropTypes.bool.description(\n 'True when the ratio is above the large breakpoint (30) and at or below the medium breakpoint (40).',\n ).isRequired,\n isSmall: PropTypes.bool.description('True when the ratio is above the small breakpoint (60).').isRequired,\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,iBAAiB;AAanB,MAAM,gCAAgC;AAAA,EAC3C,OAAO,UAAU,OAAO;AAAA,IACtB;AAAA,EACF,EAAE;AAAA,EACF,YAAY,UAAU,OAAO;AAAA,IAC3B;AAAA,EACF,EAAE;AAAA,EACF,oBAAoB,UAAU,OAAO;AAAA,IACnC;AAAA,EACF,EAAE;AAAA,EACF,SAAS,UAAU,KAAK,YAAY,+DAA+D,EAAE;AAAA,EACrG,UAAU,UAAU,KAAK;AAAA,IACvB;AAAA,EACF,EAAE;AAAA,EACF,SAAS,UAAU,KAAK,YAAY,yDAAyD,EAAE;AACjG;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,7 @@
1
1
  import { type DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';
2
- declare const useFontSizeDetector: () => DSHooksFontsizeDetectorT.UseFontSizeDetectorT;
3
- export { useFontSizeDetector };
2
+ declare const useFontSizeDetector: {
3
+ (): DSHooksFontsizeDetectorT.UseFontSizeDetectorT;
4
+ displayName: string;
5
+ };
6
+ declare const UseFontSizeDetectorWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<unknown>;
7
+ export { useFontSizeDetector, UseFontSizeDetectorWithSchema };
@@ -1,3 +1,3 @@
1
- export { useFontSizeDetector } from './DSHooksFontsizeDetector.js';
1
+ export { useFontSizeDetector, UseFontSizeDetectorWithSchema } from './DSHooksFontsizeDetector.js';
2
2
  export { FONT_DETECTOR_UID } from './constants/index.js';
3
3
  export type { DSHooksFontsizeDetectorT } from './react-desc-prop-types.js';
@@ -8,3 +8,11 @@ export declare namespace DSHooksFontsizeDetectorT {
8
8
  isLarge: boolean;
9
9
  }
10
10
  }
11
+ export declare const UseFontSizeDetectorReturnType: {
12
+ ratio: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").ReactDescT;
13
+ fontHeight: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").ReactDescT;
14
+ documentWidthRatio: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").ReactDescT;
15
+ isLarge: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").ReactDescT;
16
+ isMedium: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").ReactDescT;
17
+ isSmall: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").ReactDescT;
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-hooks-fontsize-detector",
3
- "version": "3.80.0-next.54",
3
+ "version": "3.80.0-next.56",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Hooks Fontsize Detector",
6
6
  "files": [
@@ -35,8 +35,11 @@
35
35
  "reportFile": "tests.xml",
36
36
  "indent": 4
37
37
  },
38
+ "dependencies": {
39
+ "@elliemae/ds-props-helpers": "3.80.0-next.56"
40
+ },
38
41
  "devDependencies": {
39
- "@elliemae/ds-monorepo-devops": "3.80.0-next.54",
42
+ "@elliemae/ds-monorepo-devops": "3.80.0-next.56",
40
43
  "@types/react": "^18.0.0",
41
44
  "jest": "^30.0.0"
42
45
  },