@entry-ui/utilities 0.5.0 → 0.7.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-P7NW64IN.js +2 -0
- package/dist/chunk-P7NW64IN.js.map +1 -0
- package/dist/chunk-YFUOSM2Q.js +2 -0
- package/dist/chunk-YFUOSM2Q.js.map +1 -0
- package/dist/copy-to-clipboard/index.d.ts +75 -0
- package/dist/copy-to-clipboard/index.js +2 -0
- package/dist/copy-to-clipboard/index.js.map +1 -0
- package/dist/index.d.ts +2 -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 n=async a=>{let{value:p,onSuccess:e,onError:r}=a,t=document.defaultView||window;try{if(!t.navigator.clipboard?.writeText){r?.({type:"NOT_SUPPORTED"});return}await t.navigator.clipboard.writeText(p),e?.();}catch(o){let i=o instanceof Error?o.message:String(o);r?.({type:"COPY_FAILED",message:i});}};export{n as a};//# sourceMappingURL=chunk-P7NW64IN.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-P7NW64IN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/copy-to-clipboard/copy-to-clipboard.ts"],"names":["copyToClipboard","params","value","onSuccess","onError","win","error","message"],"mappings":"AAqBO,IAAMA,CAAAA,CAAkB,MAAOC,CAAAA,EAAkC,CACtE,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,SAAA,CAAAC,CAAAA,CAAW,OAAA,CAAAC,CAAQ,EAAIH,CAAAA,CAEhCI,CAAAA,CAAM,QAAA,CAAS,WAAA,EAAe,MAAA,CAEpC,GAAI,CACF,GAAI,CAACA,CAAAA,CAAI,SAAA,CAAU,SAAA,EAAW,SAAA,CAAW,CACvCD,CAAAA,GAAU,CAAE,KAAM,eAAgB,CAAC,CAAA,CACnC,MACF,CAEA,MAAMC,CAAAA,CAAI,SAAA,CAAU,SAAA,CAAU,SAAA,CAAUH,CAAK,CAAA,CAC7CC,CAAAA,KACF,CAAA,MAASG,CAAAA,CAAO,CACd,IAAMC,CAAAA,CAAUD,CAAAA,YAAiB,KAAA,CAAQA,CAAAA,CAAM,OAAA,CAAU,MAAA,CAAOA,CAAK,CAAA,CACrEF,CAAAA,GAAU,CAAE,IAAA,CAAM,aAAA,CAAe,OAAA,CAAAG,CAAQ,CAAC,EAC5C,CACF","file":"chunk-P7NW64IN.js","sourcesContent":["import type { CopyToClipboardParams } from './copy-to-clipboard.types';\n\n/**\n * Asynchronously transfers text to the system clipboard using the Clipboard API.\n *\n * This utility provides a structured wrapper around `navigator.clipboard.writeText`,\n * offering specific error types to distinguish between unsupported environments\n * and runtime failures.\n *\n * This function expects a browser environment where `window` or\n * `document` is globally available.\n *\n * @example\n * ```ts\n * copyToClipboard({\n * \tvalue: \"Hello World\",\n * \tonSuccess: () => console.log(\"Text copied!\"),\n * \tonError: (err) => console.error(`Copy failed: ${err.type}, ${err.message}`),\n * });\n * ```\n */\nexport const copyToClipboard = async (params: CopyToClipboardParams) => {\n const { value, onSuccess, onError } = params;\n\n const win = document.defaultView || window;\n\n try {\n if (!win.navigator.clipboard?.writeText) {\n onError?.({ type: 'NOT_SUPPORTED' });\n return;\n }\n\n await win.navigator.clipboard.writeText(value);\n onSuccess?.();\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n onError?.({ type: 'COPY_FAILED', message });\n }\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"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a structured error object returned when a clipboard operation fails.
|
|
3
|
+
*
|
|
4
|
+
* This interface provides a uniform error shape to distinguish between
|
|
5
|
+
* environment-level limitations and unexpected runtime failures,
|
|
6
|
+
* allowing consumers to handle each case appropriately.
|
|
7
|
+
*/
|
|
8
|
+
interface ClipboardError {
|
|
9
|
+
/**
|
|
10
|
+
* The classification of the failure.
|
|
11
|
+
* - `"NOT_SUPPORTED"`: The browser lacks `navigator.clipboard.writeText` support.
|
|
12
|
+
* - `"COPY_FAILED"`: The operation was rejected (e.g., lack of permissions).
|
|
13
|
+
*/
|
|
14
|
+
type: 'NOT_SUPPORTED' | 'COPY_FAILED';
|
|
15
|
+
/**
|
|
16
|
+
* A descriptive message detailing the cause of the failure.
|
|
17
|
+
* This field is populated exclusively when the error `type` is `"COPY_FAILED"`,
|
|
18
|
+
* typically containing the message from the native `Error` object.
|
|
19
|
+
*/
|
|
20
|
+
message?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Configuration object for the `copyToClipboard` utility.
|
|
24
|
+
*
|
|
25
|
+
* This interface encapsulates the parameters required to perform a clipboard write operation.
|
|
26
|
+
* It allows the caller to define custom behavior for both successful data persistence
|
|
27
|
+
* and potential browser-level restrictions or runtime failures through dedicated
|
|
28
|
+
* callback handlers.
|
|
29
|
+
*/
|
|
30
|
+
interface CopyToClipboardParams {
|
|
31
|
+
/**
|
|
32
|
+
* The plaintext string to be transferred to the system clipboard.
|
|
33
|
+
* This value is processed as a standard UTF-16 string by the Clipboard API.
|
|
34
|
+
*/
|
|
35
|
+
value: string;
|
|
36
|
+
/**
|
|
37
|
+
* An optional callback executed immediately after the value has been successfully
|
|
38
|
+
* written to the clipboard. Use this to trigger UI feedback like "Copied!" toasts
|
|
39
|
+
* or success state updates.
|
|
40
|
+
*
|
|
41
|
+
* @default undefined
|
|
42
|
+
*/
|
|
43
|
+
onSuccess?: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* An optional callback executed when the copy operation fails or is not supported.
|
|
46
|
+
* It provides structured error information to distinguish between environment
|
|
47
|
+
* limitations (`"NOT_SUPPORTED"`) and unexpected runtime rejections (`"COPY_FAILED"`).
|
|
48
|
+
*
|
|
49
|
+
* @default undefined
|
|
50
|
+
*/
|
|
51
|
+
onError?: (error: ClipboardError) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Asynchronously transfers text to the system clipboard using the Clipboard API.
|
|
56
|
+
*
|
|
57
|
+
* This utility provides a structured wrapper around `navigator.clipboard.writeText`,
|
|
58
|
+
* offering specific error types to distinguish between unsupported environments
|
|
59
|
+
* and runtime failures.
|
|
60
|
+
*
|
|
61
|
+
* This function expects a browser environment where `window` or
|
|
62
|
+
* `document` is globally available.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* copyToClipboard({
|
|
67
|
+
* value: "Hello World",
|
|
68
|
+
* onSuccess: () => console.log("Text copied!"),
|
|
69
|
+
* onError: (err) => console.error(`Copy failed: ${err.type}, ${err.message}`),
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare const copyToClipboard: (params: CopyToClipboardParams) => Promise<void>;
|
|
74
|
+
|
|
75
|
+
export { type ClipboardError, type CopyToClipboardParams, copyToClipboard };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AddEventListenerOnceParams, AllEventMaps, addEventListenerOnce } from './add-event-listener-once/index.js';
|
|
2
2
|
export { ClampParams, clamp } from './clamp/index.js';
|
|
3
|
+
export { ClipboardError, CopyToClipboardParams, copyToClipboard } from './copy-to-clipboard/index.js';
|
|
3
4
|
export { ErrorParams, error } from './error/index.js';
|
|
4
5
|
export { FailParams, fail } from './fail/index.js';
|
|
5
6
|
export { getComputedStyle } from './get-computed-style/index.js';
|
|
@@ -10,6 +11,7 @@ export { hasWindow } from './has-window/index.js';
|
|
|
10
11
|
export { isHTMLElement } from './is-html-element/index.js';
|
|
11
12
|
export { isValidNumber } from './is-valid-number/index.js';
|
|
12
13
|
export { PossibleStyle, mergeStyles } from './merge-styles/index.js';
|
|
14
|
+
export { HTMLElementWithScrollIntoViewIfNeeded, ScrollIntoViewIfNeededParams, scrollIntoViewIfNeeded } from './scroll-into-view-if-needed/index.js';
|
|
13
15
|
export { visuallyHiddenInputStyle } from './visually-hidden-input-style/index.js';
|
|
14
16
|
export { visuallyHiddenStyle } from './visually-hidden-style/index.js';
|
|
15
17
|
export { wait } from './wait/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as
|
|
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 getHiddenElementHeight}from'./chunk-RZEIOZGJ.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 addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as clamp}from'./chunk-BVBN4VWU.js';export{a as isValidNumber}from'./chunk-TAV72HQS.js';export{a as copyToClipboard}from'./chunk-P7NW64IN.js';export{a as error}from'./chunk-GG6DRWSS.js';export{a as fail}from'./chunk-O4WYO5SA.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"}
|