@entry-ui/utilities 0.4.0 → 0.6.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.
Files changed (41) hide show
  1. package/dist/chunk-5BI2X7JA.js +2 -0
  2. package/dist/chunk-5BI2X7JA.js.map +1 -0
  3. package/dist/{chunk-JW4DI4Q2.js → chunk-BVBN4VWU.js} +2 -2
  4. package/dist/{chunk-JW4DI4Q2.js.map → chunk-BVBN4VWU.js.map} +1 -1
  5. package/dist/chunk-H2U5U7XY.js +2 -0
  6. package/dist/chunk-H2U5U7XY.js.map +1 -0
  7. package/dist/chunk-KSDRQLOI.js +2 -0
  8. package/dist/chunk-KSDRQLOI.js.map +1 -0
  9. package/dist/chunk-RZEIOZGJ.js +2 -0
  10. package/dist/chunk-RZEIOZGJ.js.map +1 -0
  11. package/dist/chunk-TJWADQ7V.js +2 -0
  12. package/dist/chunk-TJWADQ7V.js.map +1 -0
  13. package/dist/chunk-V3434ODU.js +2 -0
  14. package/dist/chunk-V3434ODU.js.map +1 -0
  15. package/dist/chunk-YFUOSM2Q.js +2 -0
  16. package/dist/chunk-YFUOSM2Q.js.map +1 -0
  17. package/dist/clamp/index.js +1 -1
  18. package/dist/get-computed-style/index.d.ts +17 -0
  19. package/dist/get-computed-style/index.js +2 -0
  20. package/dist/get-computed-style/index.js.map +1 -0
  21. package/dist/get-css-dimensions/index.d.ts +42 -0
  22. package/dist/get-css-dimensions/index.js +2 -0
  23. package/dist/get-css-dimensions/index.js.map +1 -0
  24. package/dist/get-hidden-element-height/index.d.ts +23 -0
  25. package/dist/get-hidden-element-height/index.js +2 -0
  26. package/dist/get-hidden-element-height/index.js.map +1 -0
  27. package/dist/get-window/index.d.ts +20 -0
  28. package/dist/get-window/index.js +2 -0
  29. package/dist/get-window/index.js.map +1 -0
  30. package/dist/has-window/index.d.ts +17 -0
  31. package/dist/has-window/index.js +2 -0
  32. package/dist/has-window/index.js.map +1 -0
  33. package/dist/index.d.ts +7 -0
  34. package/dist/index.js +1 -1
  35. package/dist/is-html-element/index.d.ts +25 -0
  36. package/dist/is-html-element/index.js +2 -0
  37. package/dist/is-html-element/index.js.map +1 -0
  38. package/dist/scroll-into-view-if-needed/index.d.ts +66 -0
  39. package/dist/scroll-into-view-if-needed/index.js +2 -0
  40. package/dist/scroll-into-view-if-needed/index.js.map +1 -0
  41. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ import {a}from'./chunk-H2U5U7XY.js';var m=t=>a(t).getComputedStyle(t);export{m as a};//# sourceMappingURL=chunk-5BI2X7JA.js.map
2
+ //# sourceMappingURL=chunk-5BI2X7JA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-computed-style/get-computed-style.ts"],"names":["getComputedStyle","element","getWindow"],"mappings":"oCAgBO,IAAMA,EAAoBC,CAAAA,EACxBC,CAAAA,CAAUD,CAAO,CAAA,CAAE,iBAAiBA,CAAO","file":"chunk-5BI2X7JA.js","sourcesContent":["import { getWindow } from '../get-window';\n\n/**\n * Retrieves the computed style properties for a specified HTML element.\n *\n * This function provides a reliable way to access an element's computed styles,\n * automatically resolving the correct window context. This ensures accurate\n * results even when the element is located within a different document context,\n * such as an iframe or a popup window.\n *\n * @example\n * ```ts\n * getComputedStyle(document.body);\n * // Returns: CSSStyleDeclaration object\n * ```\n */\nexport const getComputedStyle = (element: Element) => {\n return getWindow(element).getComputedStyle(element);\n};\n"]}
@@ -1,2 +1,2 @@
1
- import {a as a$1}from'./chunk-O4WYO5SA.js';import {a}from'./chunk-TAV72HQS.js';var s=r=>{let{value:m,min:e,max:i}=r;return a(m)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'value' parameter in 'clamp' utility.",`Expected a finite number, but received: ${m}`]}),a(e)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'min' parameter in 'clamp' utility.",`Expected a finite number, but received: ${e}`]}),a(i)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'max' parameter in 'clamp' utility.",`Expected a finite number, but received: ${i}`]}),e>i&&a$1({prefix:"[Entry UI Utilities]",messages:["Invalid range for 'clamp' utility.",`The 'min' parameter (${e}) must be less than or equal to the 'max' parameter (${i}).`]}),Math.min(i,Math.max(e,m))};export{s as a};//# sourceMappingURL=chunk-JW4DI4Q2.js.map
2
- //# sourceMappingURL=chunk-JW4DI4Q2.js.map
1
+ import {a}from'./chunk-TAV72HQS.js';import {a as a$1}from'./chunk-O4WYO5SA.js';var s=r=>{let{value:m,min:e,max:i}=r;return a(m)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'value' parameter in 'clamp' utility.",`Expected a finite number, but received: ${m}`]}),a(e)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'min' parameter in 'clamp' utility.",`Expected a finite number, but received: ${e}`]}),a(i)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'max' parameter in 'clamp' utility.",`Expected a finite number, but received: ${i}`]}),e>i&&a$1({prefix:"[Entry UI Utilities]",messages:["Invalid range for 'clamp' utility.",`The 'min' parameter (${e}) must be less than or equal to the 'max' parameter (${i}).`]}),Math.min(i,Math.max(e,m))};export{s as a};//# sourceMappingURL=chunk-BVBN4VWU.js.map
2
+ //# sourceMappingURL=chunk-BVBN4VWU.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/clamp/clamp.ts"],"names":["clamp","params","value","min","max","isValidNumber","fail"],"mappings":"+EA2BO,IAAMA,EAASC,CAAAA,EAAwB,CAC5C,GAAM,CAAE,KAAA,CAAAC,EAAO,GAAA,CAAAC,CAAAA,CAAK,GAAA,CAAAC,CAAI,EAAIH,CAAAA,CAE5B,OAAKI,EAAcH,CAAK,CAAA,EACtBI,IAAK,CACH,MAAA,CAAQ,sBAAA,CACR,QAAA,CAAU,CAAC,+CAAA,CAAiD,CAAA,wCAAA,EAA2CJ,CAAK,CAAA,CAAE,CAChH,CAAC,CAAA,CAGEG,CAAAA,CAAcF,CAAG,CAAA,EACpBG,GAAAA,CAAK,CACH,MAAA,CAAQ,sBAAA,CACR,SAAU,CAAC,6CAAA,CAA+C,2CAA2CH,CAAG,CAAA,CAAE,CAC5G,CAAC,EAGEE,CAAAA,CAAcD,CAAG,GACpBE,GAAAA,CAAK,CACH,OAAQ,sBAAA,CACR,QAAA,CAAU,CAAC,6CAAA,CAA+C,CAAA,wCAAA,EAA2CF,CAAG,CAAA,CAAE,CAC5G,CAAC,CAAA,CAGCD,CAAAA,CAAMC,GACRE,GAAAA,CAAK,CACH,MAAA,CAAQ,sBAAA,CACR,SAAU,CACR,oCAAA,CACA,wBAAwBH,CAAG,CAAA,qDAAA,EAAwDC,CAAG,CAAA,EAAA,CACxF,CACF,CAAC,CAAA,CAGI,IAAA,CAAK,IAAIA,CAAAA,CAAK,IAAA,CAAK,IAAID,CAAAA,CAAKD,CAAK,CAAC,CAC3C","file":"chunk-JW4DI4Q2.js","sourcesContent":["import type { ClampParams } from './clamp.types';\nimport { isValidNumber } from '../is-valid-number';\nimport { fail } from '../fail';\n\n/**\n * Clamps a number between a minimum and maximum value.\n *\n * This utility ensures that the returned value is restricted to a specified range.\n * If the input value is smaller than the minimum boundary, the minimum value is\n * returned. If it exceeds the maximum boundary, the maximum value is returned.\n *\n * This function will throw an error if:\n * - Any of the input parameters are not finite numbers.\n * - The `min` value is greater than the `max` value.\n *\n * @example\n * ```ts\n * clamp({ value: 150, min: 0, max: 100 });\n * // Returns: 100\n *\n * clamp({ value: -20, min: 0, max: 100 });\n * Returns: 0\n *\n * clamp({ value: 50, min: 0, max: 100 });\n * // Returns: 50\n * ```\n */\nexport const clamp = (params: ClampParams) => {\n const { value, min, max } = params;\n\n if (!isValidNumber(value)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'value' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${value}`],\n });\n }\n\n if (!isValidNumber(min)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'min' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${min}`],\n });\n }\n\n if (!isValidNumber(max)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'max' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${max}`],\n });\n }\n\n if (min > max) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [\n `Invalid range for 'clamp' utility.`,\n `The 'min' parameter (${min}) must be less than or equal to the 'max' parameter (${max}).`,\n ],\n });\n }\n\n return Math.min(max, Math.max(min, value));\n};\n"]}
1
+ {"version":3,"sources":["../src/clamp/clamp.ts"],"names":["clamp","params","value","min","max","isValidNumber","fail"],"mappings":"+EA2BO,IAAMA,EAASC,CAAAA,EAAwB,CAC5C,GAAM,CAAE,KAAA,CAAAC,EAAO,GAAA,CAAAC,CAAAA,CAAK,GAAA,CAAAC,CAAI,EAAIH,CAAAA,CAE5B,OAAKI,EAAcH,CAAK,CAAA,EACtBI,IAAK,CACH,MAAA,CAAQ,sBAAA,CACR,QAAA,CAAU,CAAC,+CAAA,CAAiD,CAAA,wCAAA,EAA2CJ,CAAK,CAAA,CAAE,CAChH,CAAC,CAAA,CAGEG,CAAAA,CAAcF,CAAG,CAAA,EACpBG,GAAAA,CAAK,CACH,MAAA,CAAQ,sBAAA,CACR,SAAU,CAAC,6CAAA,CAA+C,2CAA2CH,CAAG,CAAA,CAAE,CAC5G,CAAC,EAGEE,CAAAA,CAAcD,CAAG,GACpBE,GAAAA,CAAK,CACH,OAAQ,sBAAA,CACR,QAAA,CAAU,CAAC,6CAAA,CAA+C,CAAA,wCAAA,EAA2CF,CAAG,CAAA,CAAE,CAC5G,CAAC,CAAA,CAGCD,CAAAA,CAAMC,GACRE,GAAAA,CAAK,CACH,MAAA,CAAQ,sBAAA,CACR,SAAU,CACR,oCAAA,CACA,wBAAwBH,CAAG,CAAA,qDAAA,EAAwDC,CAAG,CAAA,EAAA,CACxF,CACF,CAAC,CAAA,CAGI,IAAA,CAAK,IAAIA,CAAAA,CAAK,IAAA,CAAK,IAAID,CAAAA,CAAKD,CAAK,CAAC,CAC3C","file":"chunk-BVBN4VWU.js","sourcesContent":["import type { ClampParams } from './clamp.types';\nimport { isValidNumber } from '../is-valid-number';\nimport { fail } from '../fail';\n\n/**\n * Clamps a number between a minimum and maximum value.\n *\n * This utility ensures that the returned value is restricted to a specified range.\n * If the input value is smaller than the minimum boundary, the minimum value is\n * returned. If it exceeds the maximum boundary, the maximum value is returned.\n *\n * This function will throw an error if:\n * - Any of the input parameters are not finite numbers.\n * - The `min` value is greater than the `max` value.\n *\n * @example\n * ```ts\n * clamp({ value: 150, min: 0, max: 100 });\n * // Returns: 100\n *\n * clamp({ value: -20, min: 0, max: 100 });\n * Returns: 0\n *\n * clamp({ value: 50, min: 0, max: 100 });\n * // Returns: 50\n * ```\n */\nexport const clamp = (params: ClampParams) => {\n const { value, min, max } = params;\n\n if (!isValidNumber(value)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'value' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${value}`],\n });\n }\n\n if (!isValidNumber(min)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'min' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${min}`],\n });\n }\n\n if (!isValidNumber(max)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'max' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${max}`],\n });\n }\n\n if (min > max) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [\n `Invalid range for 'clamp' utility.`,\n `The 'min' parameter (${min}) must be less than or equal to the 'max' parameter (${max}).`,\n ],\n });\n }\n\n return Math.min(max, Math.max(min, value));\n};\n"]}
@@ -0,0 +1,2 @@
1
+ var t=o=>o?.ownerDocument?.defaultView||window;export{t as a};//# sourceMappingURL=chunk-H2U5U7XY.js.map
2
+ //# sourceMappingURL=chunk-H2U5U7XY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-window/get-window.ts"],"names":["getWindow","node"],"mappings":"AAkBO,IAAMA,CAAAA,CAAaC,CAAAA,EACjBA,CAAAA,EAAM,aAAA,EAAe,WAAA,EAAe","file":"chunk-H2U5U7XY.js","sourcesContent":["/**\n * Retrieves the window object associated with a given DOM node, ensuring the correct execution context.\n *\n * This utility identifies the correct execution context (global window) for a specific\n * node. It is particularly useful when working with applications that utilize iframes\n * or multiple windows, as it ensures that window-level APIs and properties are\n * accessed from the node's owner document rather than the current top-level window.\n *\n * @example\n * ```ts\n * getWindow(document.getElementById(\"my-element\"));\n * // Returns: the window object where the element resides\n *\n * getWindow(null);\n * // Returns: the global window object as a fallback\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const getWindow = (node: any): typeof window => {\n return node?.ownerDocument?.defaultView || window;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import {a}from'./chunk-V3434ODU.js';import {a as a$1}from'./chunk-H2U5U7XY.js';var i=e=>a()?e instanceof HTMLElement||e instanceof a$1(e).HTMLElement:false;export{i as a};//# sourceMappingURL=chunk-KSDRQLOI.js.map
2
+ //# sourceMappingURL=chunk-KSDRQLOI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/is-html-element/is-html-element.ts"],"names":["isHTMLElement","value","hasWindow","getWindow"],"mappings":"+EAyBO,IAAMA,CAAAA,CAAiBC,CAAAA,EACvBC,CAAAA,EAAU,CAIRD,CAAAA,YAAiB,aAAeA,CAAAA,YAAiBE,GAAAA,CAAUF,CAAK,CAAA,CAAE,WAAA,CAHhE","file":"chunk-KSDRQLOI.js","sourcesContent":["import { hasWindow } from '../has-window';\nimport { getWindow } from '../get-window';\n\n/**\n * Verifies whether a given value is an instance of `HTMLElement`, with support for cross-realm environments.\n *\n * This utility provides a cross-realm safe check to determine if a value is a\n * standard HTML element. It first ensures a window environment is available\n * and then checks the instance against both the current global `HTMLElement`\n * and the `HTMLElement` constructor from the node's specific window context.\n * This prevents false negatives when elements are passed between different\n * frames or windows.\n *\n * @example\n * ```ts\n * isHTMLElement(document.createElement('div'));\n * // Returns: true\n *\n * isHTMLElement(null);\n * // Returns: false\n *\n * isHTMLElement(iframeElement.contentDocument.body);\n * // Returns: true (even if the instance comes from another window context)\n * ```\n */\nexport const isHTMLElement = (value: unknown): value is HTMLElement => {\n if (!hasWindow()) {\n return false;\n }\n\n return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import {a}from'./chunk-TJWADQ7V.js';var r=t=>{let e=t.cloneNode(true);e.setAttribute("aria-hidden","true"),Object.assign(e.style,{pointerEvents:"none",userSelect:"none",overflow:"visible",height:"auto",maxHeight:"none",opacity:"0",visibility:"hidden",display:"block",contentVisibility:"visible",transition:"none",animation:"none",position:"absolute",top:"-9999px"}),t.after(e);let{height:n}=a(e);return e.remove(),n};export{r as a};//# sourceMappingURL=chunk-RZEIOZGJ.js.map
2
+ //# sourceMappingURL=chunk-RZEIOZGJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-hidden-element-height/get-hidden-element-height.ts"],"names":["getHiddenElementHeight","element","cloneElement","height","getCssDimensions"],"mappings":"oCAsBO,IAAMA,CAAAA,CAA0BC,CAAAA,EAAyB,CAC9D,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,SAAA,CAAU,IAAI,CAAA,CAE3CC,CAAAA,CAAa,YAAA,CAAa,aAAA,CAAe,MAAM,CAAA,CAE/C,MAAA,CAAO,MAAA,CAAOA,CAAAA,CAAa,KAAA,CAAO,CAChC,aAAA,CAAe,MAAA,CACf,UAAA,CAAY,MAAA,CACZ,QAAA,CAAU,SAAA,CACV,MAAA,CAAQ,MAAA,CACR,SAAA,CAAW,OACX,OAAA,CAAS,GAAA,CACT,UAAA,CAAY,QAAA,CACZ,OAAA,CAAS,OAAA,CACT,iBAAA,CAAmB,SAAA,CACnB,UAAA,CAAY,MAAA,CACZ,SAAA,CAAW,MAAA,CACX,QAAA,CAAU,UAAA,CACV,GAAA,CAAK,SACP,CAAC,CAAA,CAEDD,CAAAA,CAAQ,KAAA,CAAMC,CAAY,CAAA,CAE1B,GAAM,CAAE,MAAA,CAAAC,CAAO,CAAA,CAAIC,CAAAA,CAAiBF,CAAY,CAAA,CAEhD,OAAAA,CAAAA,CAAa,MAAA,GAENC,CACT","file":"chunk-RZEIOZGJ.js","sourcesContent":["import { getCssDimensions } from '../get-css-dimensions';\n\n/**\n * Calculates the natural height of an element that is otherwise hidden from the layout.\n *\n * This function handles cases where an element's dimensions cannot be accurately measured\n * (e.g., when it is set to `display: none` and occupies no space in the document). It\n * works by creating an invisible, deep clone of the element and temporarily injecting\n * it into the DOM at a position far outside the visible viewport.\n *\n * The clone is styled to be non-interactive and layout-neutral by overriding its display,\n * positioning, and visibility properties. This ensures that its presence does not\n * interfere with the user experience, trigger unintended layout shifts, or affect\n * accessibility trees. Once the height is captured, the clone is immediately removed\n * from the document to maintain DOM cleanliness.\n *\n * @example\n * ```ts\n * getHiddenElementHeight(myHiddenElement);\n * // Returns: 42\n * ```\n */\nexport const getHiddenElementHeight = (element: HTMLElement) => {\n const cloneElement = element.cloneNode(true) as HTMLElement;\n\n cloneElement.setAttribute('aria-hidden', 'true');\n\n Object.assign(cloneElement.style, {\n pointerEvents: 'none',\n userSelect: 'none',\n overflow: 'visible',\n height: 'auto',\n maxHeight: 'none',\n opacity: '0',\n visibility: 'hidden',\n display: 'block',\n contentVisibility: 'visible',\n transition: 'none',\n animation: 'none',\n position: 'absolute',\n top: '-9999px',\n });\n\n element.after(cloneElement);\n\n const { height } = getCssDimensions(cloneElement);\n\n cloneElement.remove();\n\n return height;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import {a as a$1}from'./chunk-KSDRQLOI.js';import {a}from'./chunk-5BI2X7JA.js';var l=s=>{let o=a(s),t=parseFloat(o.width)||0,e=parseFloat(o.height)||0,i=a$1(s),n=i?s.offsetWidth:t,r=i?s.offsetHeight:e;return (Math.round(t)!==n||Math.round(e)!==r)&&(t=n,e=r),{width:t,height:e}};export{l as a};//# sourceMappingURL=chunk-TJWADQ7V.js.map
2
+ //# sourceMappingURL=chunk-TJWADQ7V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/get-css-dimensions/get-css-dimensions.ts"],"names":["getCssDimensions","element","css","getComputedStyle","width","height","hasOffset","isHTMLElement","offsetWidth","offsetHeight"],"mappings":"+EAoBO,IAAMA,CAAAA,CAAoBC,CAAAA,EAAkD,CACjF,IAAMC,CAAAA,CAAMC,EAAiBF,CAAO,CAAA,CAIhCG,CAAAA,CAAQ,UAAA,CAAWF,CAAAA,CAAI,KAAK,GAAK,CAAA,CACjCG,CAAAA,CAAS,UAAA,CAAWH,CAAAA,CAAI,MAAM,CAAA,EAAK,CAAA,CAEjCI,CAAAA,CAAYC,GAAAA,CAAcN,CAAO,CAAA,CACjCO,CAAAA,CAAcF,CAAAA,CAAYL,CAAAA,CAAQ,YAAcG,CAAAA,CAChDK,CAAAA,CAAeH,CAAAA,CAAYL,CAAAA,CAAQ,YAAA,CAAeI,CAAAA,CAGxD,QAFuB,IAAA,CAAK,KAAA,CAAMD,CAAK,CAAA,GAAMI,CAAAA,EAAe,IAAA,CAAK,MAAMH,CAAM,CAAA,GAAMI,CAAAA,IAGjFL,CAAAA,CAAQI,CAAAA,CACRH,CAAAA,CAASI,CAAAA,CAAAA,CAGJ,CACL,KAAA,CAAAL,CAAAA,CACA,MAAA,CAAAC,CACF,CACF","file":"chunk-TJWADQ7V.js","sourcesContent":["import type { GetCssDimensionsReturnValue } from './get-css-dimensions.types';\nimport { getComputedStyle } from '../get-computed-style';\nimport { isHTMLElement } from '../is-html-element';\n\n/**\n * Calculates the visual dimensions of an element, reconciling CSS styles with layout geometry.\n *\n * This utility determines the most accurate width and height of an element by\n * comparing its computed CSS values with its offset dimensions. It accounts for\n * edge cases where `getComputedStyle` might return inconsistent results, such as\n * in testing environments or when dealing with SVG elements. If a significant\n * discrepancy is detected between the CSS-defined size and the actual offset size,\n * it prioritizes the offset dimensions to ensure layout accuracy.\n *\n * @example\n * ```ts\n * getCssDimensions(myElement);\n * // Returns: { width: 150, height: 42 }\n * ```\n */\nexport const getCssDimensions = (element: Element): GetCssDimensionsReturnValue => {\n const css = getComputedStyle(element);\n\n // In testing environments, the `width` and `height` properties are empty\n // strings for SVG elements, returning NaN. Fallback to `0` in this case.\n let width = parseFloat(css.width) || 0;\n let height = parseFloat(css.height) || 0;\n\n const hasOffset = isHTMLElement(element);\n const offsetWidth = hasOffset ? element.offsetWidth : width;\n const offsetHeight = hasOffset ? element.offsetHeight : height;\n const shouldFallback = Math.round(width) !== offsetWidth || Math.round(height) !== offsetHeight;\n\n if (shouldFallback) {\n width = offsetWidth;\n height = offsetHeight;\n }\n\n return {\n width,\n height,\n };\n};\n"]}
@@ -0,0 +1,2 @@
1
+ var e=()=>typeof window<"u";export{e as a};//# sourceMappingURL=chunk-V3434ODU.js.map
2
+ //# sourceMappingURL=chunk-V3434ODU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/has-window/has-window.ts"],"names":["hasWindow"],"mappings":"AAcO,IAAMA,CAAAA,CAAY,IAChB,OAAO,MAAA,CAAW","file":"chunk-V3434ODU.js","sourcesContent":["/**\n * Checks whether the `window` object is defined in the current execution environment.\n *\n * This utility is primarily used to detect if the code is running in a browser\n * environment versus a server-side environment (like Node.js or during SSR).\n * It helps prevent \"window is not defined\" errors by ensuring browser-specific\n * APIs are only accessed when available.\n *\n * @example\n * ```ts\n * hasWindow()\n * // Returns: true if the window object is available, false otherwise\n * ```\n */\nexport const hasWindow = () => {\n return typeof window !== 'undefined';\n};\n"]}
@@ -0,0 +1,2 @@
1
+ var r=t=>{let{element:e,center:o=true}=t;"scrollIntoViewIfNeeded"in e?e.scrollIntoViewIfNeeded(o):e.scrollIntoView({behavior:"auto",block:o?"center":"nearest",inline:"nearest"});};export{r as a};//# sourceMappingURL=chunk-YFUOSM2Q.js.map
2
+ //# sourceMappingURL=chunk-YFUOSM2Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/scroll-into-view-if-needed/scroll-into-view-if-needed.ts"],"names":["scrollIntoViewIfNeeded","params","element","center"],"mappings":"AA0BO,IAAMA,CAAAA,CAA0BC,CAAAA,EAAyC,CAC9E,GAAM,CAAE,OAAA,CAAAC,CAAAA,CAAS,MAAA,CAAAC,CAAAA,CAAS,IAAK,CAAA,CAAIF,CAAAA,CAE/B,2BAA4BC,CAAAA,CACbA,CAAAA,CAER,sBAAA,CAAuBC,CAAM,CAAA,CAEtCD,CAAAA,CAAQ,cAAA,CAAe,CACrB,QAAA,CAAU,MAAA,CACV,KAAA,CAAOC,CAAAA,CAAS,QAAA,CAAW,SAAA,CAC3B,MAAA,CAAQ,SACV,CAAC,EAEL","file":"chunk-YFUOSM2Q.js","sourcesContent":["import type {\n ScrollIntoViewIfNeededParams,\n HTMLElementWithScrollIntoViewIfNeeded,\n} from './scroll-into-view-if-needed.types';\n\n/**\n * Ensures an element is visible in the viewport by scrolling to it only if necessary.\n *\n * This utility provides a unified interface for the non-standard `scrollIntoViewIfNeeded`\n * method (available in Chromium and WebKit) while providing a robust fallback to the\n * standard `scrollIntoView` API for other browsers. It is designed to prevent jarring\n * layout jumps by avoiding redundant scrolls if the element is already within the\n * user's visible area.\n *\n * The function allows for flexible positioning, enabling you to either center the\n * element within the viewport or use a minimal `\"nearest\"` alignment strategy to\n * reduce visual noise during navigation or search-in-page operations.\n *\n * @example\n * ```ts\n * scrollIntoViewIfNeeded({\n * element: document.querySelector(\"#target-element\"),\n * center: true\n * });\n * ```\n */\nexport const scrollIntoViewIfNeeded = (params: ScrollIntoViewIfNeededParams) => {\n const { element, center = true } = params;\n\n if ('scrollIntoViewIfNeeded' in element) {\n const _element = element as HTMLElementWithScrollIntoViewIfNeeded;\n\n _element.scrollIntoViewIfNeeded(center);\n } else {\n element.scrollIntoView({\n behavior: 'auto',\n block: center ? 'center' : 'nearest',\n inline: 'nearest',\n });\n }\n};\n"]}
@@ -1,2 +1,2 @@
1
- export{a as clamp}from'../chunk-JW4DI4Q2.js';import'../chunk-O4WYO5SA.js';import'../chunk-TAV72HQS.js';//# sourceMappingURL=index.js.map
1
+ export{a as clamp}from'../chunk-BVBN4VWU.js';import'../chunk-TAV72HQS.js';import'../chunk-O4WYO5SA.js';//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Retrieves the computed style properties for a specified HTML element.
3
+ *
4
+ * This function provides a reliable way to access an element's computed styles,
5
+ * automatically resolving the correct window context. This ensures accurate
6
+ * results even when the element is located within a different document context,
7
+ * such as an iframe or a popup window.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * getComputedStyle(document.body);
12
+ * // Returns: CSSStyleDeclaration object
13
+ * ```
14
+ */
15
+ declare const getComputedStyle: (element: Element) => CSSStyleDeclaration;
16
+
17
+ export { getComputedStyle };
@@ -0,0 +1,2 @@
1
+ export{a as getComputedStyle}from'../chunk-5BI2X7JA.js';import'../chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The geometric results of an element's dimension calculation.
3
+ *
4
+ * This interface represents the reconciled spatial measurements of a DOM element.
5
+ * It provides a normalized output that bridges the gap between computed CSS
6
+ * properties and actual layout geometry, ensuring consistency regardless of
7
+ * whether the element is a standard HTML component or an SVG.
8
+ */
9
+ interface GetCssDimensionsReturnValue {
10
+ /**
11
+ * The calculated horizontal size of the element in pixels.
12
+ * This value prioritizes the actual rendered offset width while falling back
13
+ * to computed CSS values where layout geometry is unavailable or inconsistent.
14
+ */
15
+ width: number;
16
+ /**
17
+ * The calculated vertical size of the element in pixels.
18
+ * Similar to the width, this property reflects the most accurate height
19
+ * by reconciling layout-driven dimensions with the styles defined in the CSS cascade.
20
+ */
21
+ height: number;
22
+ }
23
+
24
+ /**
25
+ * Calculates the visual dimensions of an element, reconciling CSS styles with layout geometry.
26
+ *
27
+ * This utility determines the most accurate width and height of an element by
28
+ * comparing its computed CSS values with its offset dimensions. It accounts for
29
+ * edge cases where `getComputedStyle` might return inconsistent results, such as
30
+ * in testing environments or when dealing with SVG elements. If a significant
31
+ * discrepancy is detected between the CSS-defined size and the actual offset size,
32
+ * it prioritizes the offset dimensions to ensure layout accuracy.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * getCssDimensions(myElement);
37
+ * // Returns: { width: 150, height: 42 }
38
+ * ```
39
+ */
40
+ declare const getCssDimensions: (element: Element) => GetCssDimensionsReturnValue;
41
+
42
+ export { type GetCssDimensionsReturnValue, getCssDimensions };
@@ -0,0 +1,2 @@
1
+ export{a as getCssDimensions}from'../chunk-TJWADQ7V.js';import'../chunk-KSDRQLOI.js';import'../chunk-V3434ODU.js';import'../chunk-5BI2X7JA.js';import'../chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Calculates the natural height of an element that is otherwise hidden from the layout.
3
+ *
4
+ * This function handles cases where an element's dimensions cannot be accurately measured
5
+ * (e.g., when it is set to `display: none` and occupies no space in the document). It
6
+ * works by creating an invisible, deep clone of the element and temporarily injecting
7
+ * it into the DOM at a position far outside the visible viewport.
8
+ *
9
+ * The clone is styled to be non-interactive and layout-neutral by overriding its display,
10
+ * positioning, and visibility properties. This ensures that its presence does not
11
+ * interfere with the user experience, trigger unintended layout shifts, or affect
12
+ * accessibility trees. Once the height is captured, the clone is immediately removed
13
+ * from the document to maintain DOM cleanliness.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * getHiddenElementHeight(myHiddenElement);
18
+ * // Returns: 42
19
+ * ```
20
+ */
21
+ declare const getHiddenElementHeight: (element: HTMLElement) => number;
22
+
23
+ export { getHiddenElementHeight };
@@ -0,0 +1,2 @@
1
+ export{a as getHiddenElementHeight}from'../chunk-RZEIOZGJ.js';import'../chunk-TJWADQ7V.js';import'../chunk-KSDRQLOI.js';import'../chunk-V3434ODU.js';import'../chunk-5BI2X7JA.js';import'../chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Retrieves the window object associated with a given DOM node, ensuring the correct execution context.
3
+ *
4
+ * This utility identifies the correct execution context (global window) for a specific
5
+ * node. It is particularly useful when working with applications that utilize iframes
6
+ * or multiple windows, as it ensures that window-level APIs and properties are
7
+ * accessed from the node's owner document rather than the current top-level window.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * getWindow(document.getElementById("my-element"));
12
+ * // Returns: the window object where the element resides
13
+ *
14
+ * getWindow(null);
15
+ * // Returns: the global window object as a fallback
16
+ * ```
17
+ */
18
+ declare const getWindow: (node: any) => typeof window;
19
+
20
+ export { getWindow };
@@ -0,0 +1,2 @@
1
+ export{a as getWindow}from'../chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Checks whether the `window` object is defined in the current execution environment.
3
+ *
4
+ * This utility is primarily used to detect if the code is running in a browser
5
+ * environment versus a server-side environment (like Node.js or during SSR).
6
+ * It helps prevent "window is not defined" errors by ensuring browser-specific
7
+ * APIs are only accessed when available.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * hasWindow()
12
+ * // Returns: true if the window object is available, false otherwise
13
+ * ```
14
+ */
15
+ declare const hasWindow: () => boolean;
16
+
17
+ export { hasWindow };
@@ -0,0 +1,2 @@
1
+ export{a as hasWindow}from'../chunk-V3434ODU.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/index.d.ts CHANGED
@@ -2,8 +2,15 @@ export { AddEventListenerOnceParams, AllEventMaps, addEventListenerOnce } from '
2
2
  export { ClampParams, clamp } from './clamp/index.js';
3
3
  export { ErrorParams, error } from './error/index.js';
4
4
  export { FailParams, fail } from './fail/index.js';
5
+ export { getComputedStyle } from './get-computed-style/index.js';
6
+ export { GetCssDimensionsReturnValue, getCssDimensions } from './get-css-dimensions/index.js';
7
+ export { getHiddenElementHeight } from './get-hidden-element-height/index.js';
8
+ export { getWindow } from './get-window/index.js';
9
+ export { hasWindow } from './has-window/index.js';
10
+ export { isHTMLElement } from './is-html-element/index.js';
5
11
  export { isValidNumber } from './is-valid-number/index.js';
6
12
  export { PossibleStyle, mergeStyles } from './merge-styles/index.js';
13
+ export { HTMLElementWithScrollIntoViewIfNeeded, ScrollIntoViewIfNeededParams, scrollIntoViewIfNeeded } from './scroll-into-view-if-needed/index.js';
7
14
  export { visuallyHiddenInputStyle } from './visually-hidden-input-style/index.js';
8
15
  export { visuallyHiddenStyle } from './visually-hidden-style/index.js';
9
16
  export { wait } from './wait/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export{a as visuallyHiddenStyle}from'./chunk-YRBGPPKC.js';export{a as wait}from'./chunk-OUZ54COH.js';export{a as warn}from'./chunk-6L6DIP5N.js';export{a as addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as clamp}from'./chunk-JW4DI4Q2.js';export{a as error}from'./chunk-GG6DRWSS.js';export{a as fail}from'./chunk-O4WYO5SA.js';export{a as isValidNumber}from'./chunk-TAV72HQS.js';export{a as mergeStyles}from'./chunk-NBN5PUZ6.js';export{a as visuallyHiddenInputStyle}from'./chunk-AYHMR4G2.js';//# sourceMappingURL=index.js.map
1
+ export{a as warn}from'./chunk-6L6DIP5N.js';export{a as mergeStyles}from'./chunk-NBN5PUZ6.js';export{a as scrollIntoViewIfNeeded}from'./chunk-YFUOSM2Q.js';export{a as visuallyHiddenInputStyle}from'./chunk-AYHMR4G2.js';export{a as visuallyHiddenStyle}from'./chunk-YRBGPPKC.js';export{a as wait}from'./chunk-OUZ54COH.js';export{a as addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as clamp}from'./chunk-BVBN4VWU.js';export{a as isValidNumber}from'./chunk-TAV72HQS.js';export{a as error}from'./chunk-GG6DRWSS.js';export{a as fail}from'./chunk-O4WYO5SA.js';export{a as getHiddenElementHeight}from'./chunk-RZEIOZGJ.js';export{a as getCssDimensions}from'./chunk-TJWADQ7V.js';export{a as isHTMLElement}from'./chunk-KSDRQLOI.js';export{a as hasWindow}from'./chunk-V3434ODU.js';export{a as getComputedStyle}from'./chunk-5BI2X7JA.js';export{a as getWindow}from'./chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Verifies whether a given value is an instance of `HTMLElement`, with support for cross-realm environments.
3
+ *
4
+ * This utility provides a cross-realm safe check to determine if a value is a
5
+ * standard HTML element. It first ensures a window environment is available
6
+ * and then checks the instance against both the current global `HTMLElement`
7
+ * and the `HTMLElement` constructor from the node's specific window context.
8
+ * This prevents false negatives when elements are passed between different
9
+ * frames or windows.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * isHTMLElement(document.createElement('div'));
14
+ * // Returns: true
15
+ *
16
+ * isHTMLElement(null);
17
+ * // Returns: false
18
+ *
19
+ * isHTMLElement(iframeElement.contentDocument.body);
20
+ * // Returns: true (even if the instance comes from another window context)
21
+ * ```
22
+ */
23
+ declare const isHTMLElement: (value: unknown) => value is HTMLElement;
24
+
25
+ export { isHTMLElement };
@@ -0,0 +1,2 @@
1
+ export{a as isHTMLElement}from'../chunk-KSDRQLOI.js';import'../chunk-V3434ODU.js';import'../chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Configuration object for the `scrollIntoViewIfNeeded` utility.
3
+ *
4
+ * This interface encapsulates the parameters required to ensure an element's visibility.
5
+ * It provides a structured way to pass the target element and visual alignment
6
+ * preferences, allowing the utility to choose between native Chromium/WebKit
7
+ * implementations or a standard CSSOM Scroll Customization fallback.
8
+ */
9
+ interface ScrollIntoViewIfNeededParams {
10
+ /**
11
+ * The DOM element to be brought into the visible area of the viewport.
12
+ * This is the primary target for the scroll operation, ensuring the element
13
+ * is accessible to the user's current line of sight.
14
+ */
15
+ element: HTMLElement;
16
+ /**
17
+ * Controls the positioning logic for the scroll alignment.
18
+ * When set to `true`, the utility attempts to place the element in the dead center
19
+ * of the viewport. When `false`, it uses the `"nearest"` alignment strategy,
20
+ * minimizing movement if the element is already partially visible.
21
+ *
22
+ * @default true
23
+ */
24
+ center?: boolean;
25
+ }
26
+ /**
27
+ * Type extension for the `HTMLElement` interface to include non-standard scroll methods.
28
+ *
29
+ * This interface is used for type casting and safety checks when interacting with
30
+ * browser-specific DOM APIs. It explicitly defines the `scrollIntoViewIfNeeded`
31
+ * method, which is natively supported in Chromium and WebKit-based engines but
32
+ * missing from the standard TypeScript `HTMLElement` definition.
33
+ */
34
+ interface HTMLElementWithScrollIntoViewIfNeeded extends HTMLElement {
35
+ /**
36
+ * A non-standard, Chromium and WebKit-specific method that scrolls the element
37
+ * into the visible area of the browser window only if it is not already within
38
+ * the current viewport.
39
+ */
40
+ scrollIntoViewIfNeeded: (centerIfNeeded?: boolean) => void;
41
+ }
42
+
43
+ /**
44
+ * Ensures an element is visible in the viewport by scrolling to it only if necessary.
45
+ *
46
+ * This utility provides a unified interface for the non-standard `scrollIntoViewIfNeeded`
47
+ * method (available in Chromium and WebKit) while providing a robust fallback to the
48
+ * standard `scrollIntoView` API for other browsers. It is designed to prevent jarring
49
+ * layout jumps by avoiding redundant scrolls if the element is already within the
50
+ * user's visible area.
51
+ *
52
+ * The function allows for flexible positioning, enabling you to either center the
53
+ * element within the viewport or use a minimal `"nearest"` alignment strategy to
54
+ * reduce visual noise during navigation or search-in-page operations.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * scrollIntoViewIfNeeded({
59
+ * element: document.querySelector("#target-element"),
60
+ * center: true
61
+ * });
62
+ * ```
63
+ */
64
+ declare const scrollIntoViewIfNeeded: (params: ScrollIntoViewIfNeededParams) => void;
65
+
66
+ export { type HTMLElementWithScrollIntoViewIfNeeded, type ScrollIntoViewIfNeededParams, scrollIntoViewIfNeeded };
@@ -0,0 +1,2 @@
1
+ export{a as scrollIntoViewIfNeeded}from'../chunk-YFUOSM2Q.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entry-ui/utilities",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/ZAHON/entry-ui/tree/main/packages/utilities#readme",