@entry-ui/utilities 0.5.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.
- package/dist/chunk-YFUOSM2Q.js +2 -0
- package/dist/chunk-YFUOSM2Q.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/scroll-into-view-if-needed/index.d.ts +66 -0
- package/dist/scroll-into-view-if-needed/index.js +2 -0
- package/dist/scroll-into-view-if-needed/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { hasWindow } from './has-window/index.js';
|
|
|
10
10
|
export { isHTMLElement } from './is-html-element/index.js';
|
|
11
11
|
export { isValidNumber } from './is-valid-number/index.js';
|
|
12
12
|
export { PossibleStyle, mergeStyles } from './merge-styles/index.js';
|
|
13
|
+
export { HTMLElementWithScrollIntoViewIfNeeded, ScrollIntoViewIfNeededParams, scrollIntoViewIfNeeded } from './scroll-into-view-if-needed/index.js';
|
|
13
14
|
export { visuallyHiddenInputStyle } from './visually-hidden-input-style/index.js';
|
|
14
15
|
export { visuallyHiddenStyle } from './visually-hidden-style/index.js';
|
|
15
16
|
export { wait } from './wait/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as mergeStyles}from'./chunk-NBN5PUZ6.js';export{a as
|
|
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,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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|