@necto/dom 1.1.0 → 1.4.1
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/LICENSE +1 -1
- package/dist/index.d.mts +139 -1
- package/dist/index.d.ts +139 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +9 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FocusableElement, HTMLElementsMap } from '@necto/types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
3
5
|
*
|
|
@@ -7,6 +9,8 @@
|
|
|
7
9
|
*/
|
|
8
10
|
declare function isNode(value: unknown): value is Node;
|
|
9
11
|
declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
|
|
12
|
+
declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
|
|
13
|
+
declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -18,4 +22,138 @@ declare function nodeContains(node: Node | null | undefined, otherNode: Node | n
|
|
|
18
22
|
declare const getOwnerDocument: (el: Element | null | undefined) => Document;
|
|
19
23
|
declare const getOwnerWindow: (el: (Window & typeof global) | Element | null | undefined) => Window & typeof global;
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Represents an element with scroll position information.
|
|
27
|
+
*/
|
|
28
|
+
interface ScrollableElement {
|
|
29
|
+
/** The HTML element that is scrollable. */
|
|
30
|
+
element: HTMLElement;
|
|
31
|
+
/** The vertical scroll position of the element. */
|
|
32
|
+
scrollTop: number;
|
|
33
|
+
/** The horizontal scroll position of the element. */
|
|
34
|
+
scrollLeft: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
39
|
+
* licensed under the Apache License, Version 2.0.
|
|
40
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
41
|
+
* See: https://github.com/adobe/react-spectrum
|
|
42
|
+
*
|
|
43
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
44
|
+
*
|
|
45
|
+
* This file contains code licensed under:
|
|
46
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
47
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
48
|
+
*
|
|
49
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Focuses the given element without causing the page to scroll.
|
|
54
|
+
* Uses the native preventScroll option if supported, otherwise manually restores scroll positions.
|
|
55
|
+
*
|
|
56
|
+
* @param {FocusableElement} element - The element to focus.
|
|
57
|
+
*/
|
|
58
|
+
declare function focusWithoutScrolling(element: FocusableElement): void;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a list of all scrollable ancestor elements for a given element,
|
|
61
|
+
* including the root scrolling element.
|
|
62
|
+
*
|
|
63
|
+
* @param {FocusableElement} element - The element whose scrollable ancestors are to be found.
|
|
64
|
+
* @returns {ScrollableElement[]} An array of scrollable elements with their scroll positions.
|
|
65
|
+
*/
|
|
66
|
+
declare function getScrollableElements(element: FocusableElement): ScrollableElement[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
70
|
+
* licensed under the Apache License, Version 2.0.
|
|
71
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
72
|
+
* See: https://github.com/adobe/react-spectrum
|
|
73
|
+
*
|
|
74
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
75
|
+
*
|
|
76
|
+
* This file contains code licensed under:
|
|
77
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
78
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
79
|
+
*
|
|
80
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Detects if the browser supports the preventScroll option in the focus() method.
|
|
84
|
+
*
|
|
85
|
+
* @returns {boolean} True if preventScroll is supported, otherwise false.
|
|
86
|
+
*/
|
|
87
|
+
declare function supportsPreventScroll(): boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
91
|
+
*
|
|
92
|
+
* This source code is licensed under the MIT license found in the
|
|
93
|
+
* LICENSE file in the root directory of this source tree.
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
declare function getContainmentRect(containment: Element | null | undefined, fallbackElement?: Element | null): {
|
|
97
|
+
top: number;
|
|
98
|
+
left: number;
|
|
99
|
+
bottom: number;
|
|
100
|
+
right: number;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
105
|
+
*
|
|
106
|
+
* This source code is licensed under the MIT license found in the
|
|
107
|
+
* LICENSE file in the root directory of this source tree.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
* Runs a callback after all current transitions have finished.
|
|
112
|
+
* If no transitions are running, runs immediately.
|
|
113
|
+
*/
|
|
114
|
+
declare function runAfterTransition(callback: () => void): void;
|
|
115
|
+
|
|
116
|
+
declare const HTMLElements: HTMLElementsMap;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
120
|
+
* licensed under the Apache License, Version 2.0.
|
|
121
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
122
|
+
* See: https://github.com/adobe/react-spectrum
|
|
123
|
+
*
|
|
124
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
125
|
+
*
|
|
126
|
+
* This file contains code licensed under:
|
|
127
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
128
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
129
|
+
*
|
|
130
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
131
|
+
*/
|
|
132
|
+
/**
|
|
133
|
+
* Disables text selection for a given element, or for the entire document on iOS.
|
|
134
|
+
*
|
|
135
|
+
* On iOS, this sets `webkitUserSelect: 'none'` on the document element to prevent text selection globally,
|
|
136
|
+
* and restores the previous value when re-enabled. On other platforms, it sets `user-select: none` (or the appropriate
|
|
137
|
+
* vendor-prefixed property) on the provided element, and restores the previous value when re-enabled.
|
|
138
|
+
*
|
|
139
|
+
* This is useful for preventing unwanted text selection during press, drag, or other pointer interactions.
|
|
140
|
+
*
|
|
141
|
+
* @param {Element} [target] - The target element to disable text selection on. If omitted and running on iOS,
|
|
142
|
+
* disables selection on the entire document.
|
|
143
|
+
*/
|
|
144
|
+
declare function disableTextSelection(target?: Element): void;
|
|
145
|
+
/**
|
|
146
|
+
* Restores text selection for a given element, or for the entire document on iOS.
|
|
147
|
+
*
|
|
148
|
+
* On iOS, this restores the `webkitUserSelect` property on the document element to its previous value,
|
|
149
|
+
* after a short delay to avoid race conditions with pointer events. On other platforms, it restores the
|
|
150
|
+
* original `user-select` (or vendor-prefixed) property on the provided element if it was previously modified.
|
|
151
|
+
*
|
|
152
|
+
* This should be called after disabling text selection with `disableTextSelection` to re-enable normal selection behavior.
|
|
153
|
+
*
|
|
154
|
+
* @param {Element} [target] - The element to restore text selection on. If omitted and running on iOS,
|
|
155
|
+
* restores selection on the entire document.
|
|
156
|
+
*/
|
|
157
|
+
declare function restoreTextSelection(target?: Element): void;
|
|
158
|
+
|
|
159
|
+
export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, getScrollableElements, isNode, nodeContains, restoreTextSelection, runAfterTransition, supportsPreventScroll };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FocusableElement, HTMLElementsMap } from '@necto/types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
3
5
|
*
|
|
@@ -7,6 +9,8 @@
|
|
|
7
9
|
*/
|
|
8
10
|
declare function isNode(value: unknown): value is Node;
|
|
9
11
|
declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
|
|
12
|
+
declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
|
|
13
|
+
declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -18,4 +22,138 @@ declare function nodeContains(node: Node | null | undefined, otherNode: Node | n
|
|
|
18
22
|
declare const getOwnerDocument: (el: Element | null | undefined) => Document;
|
|
19
23
|
declare const getOwnerWindow: (el: (Window & typeof global) | Element | null | undefined) => Window & typeof global;
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Represents an element with scroll position information.
|
|
27
|
+
*/
|
|
28
|
+
interface ScrollableElement {
|
|
29
|
+
/** The HTML element that is scrollable. */
|
|
30
|
+
element: HTMLElement;
|
|
31
|
+
/** The vertical scroll position of the element. */
|
|
32
|
+
scrollTop: number;
|
|
33
|
+
/** The horizontal scroll position of the element. */
|
|
34
|
+
scrollLeft: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
39
|
+
* licensed under the Apache License, Version 2.0.
|
|
40
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
41
|
+
* See: https://github.com/adobe/react-spectrum
|
|
42
|
+
*
|
|
43
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
44
|
+
*
|
|
45
|
+
* This file contains code licensed under:
|
|
46
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
47
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
48
|
+
*
|
|
49
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Focuses the given element without causing the page to scroll.
|
|
54
|
+
* Uses the native preventScroll option if supported, otherwise manually restores scroll positions.
|
|
55
|
+
*
|
|
56
|
+
* @param {FocusableElement} element - The element to focus.
|
|
57
|
+
*/
|
|
58
|
+
declare function focusWithoutScrolling(element: FocusableElement): void;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a list of all scrollable ancestor elements for a given element,
|
|
61
|
+
* including the root scrolling element.
|
|
62
|
+
*
|
|
63
|
+
* @param {FocusableElement} element - The element whose scrollable ancestors are to be found.
|
|
64
|
+
* @returns {ScrollableElement[]} An array of scrollable elements with their scroll positions.
|
|
65
|
+
*/
|
|
66
|
+
declare function getScrollableElements(element: FocusableElement): ScrollableElement[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
70
|
+
* licensed under the Apache License, Version 2.0.
|
|
71
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
72
|
+
* See: https://github.com/adobe/react-spectrum
|
|
73
|
+
*
|
|
74
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
75
|
+
*
|
|
76
|
+
* This file contains code licensed under:
|
|
77
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
78
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
79
|
+
*
|
|
80
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Detects if the browser supports the preventScroll option in the focus() method.
|
|
84
|
+
*
|
|
85
|
+
* @returns {boolean} True if preventScroll is supported, otherwise false.
|
|
86
|
+
*/
|
|
87
|
+
declare function supportsPreventScroll(): boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
91
|
+
*
|
|
92
|
+
* This source code is licensed under the MIT license found in the
|
|
93
|
+
* LICENSE file in the root directory of this source tree.
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
declare function getContainmentRect(containment: Element | null | undefined, fallbackElement?: Element | null): {
|
|
97
|
+
top: number;
|
|
98
|
+
left: number;
|
|
99
|
+
bottom: number;
|
|
100
|
+
right: number;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
105
|
+
*
|
|
106
|
+
* This source code is licensed under the MIT license found in the
|
|
107
|
+
* LICENSE file in the root directory of this source tree.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
* Runs a callback after all current transitions have finished.
|
|
112
|
+
* If no transitions are running, runs immediately.
|
|
113
|
+
*/
|
|
114
|
+
declare function runAfterTransition(callback: () => void): void;
|
|
115
|
+
|
|
116
|
+
declare const HTMLElements: HTMLElementsMap;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
120
|
+
* licensed under the Apache License, Version 2.0.
|
|
121
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
122
|
+
* See: https://github.com/adobe/react-spectrum
|
|
123
|
+
*
|
|
124
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
125
|
+
*
|
|
126
|
+
* This file contains code licensed under:
|
|
127
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
128
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
129
|
+
*
|
|
130
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
131
|
+
*/
|
|
132
|
+
/**
|
|
133
|
+
* Disables text selection for a given element, or for the entire document on iOS.
|
|
134
|
+
*
|
|
135
|
+
* On iOS, this sets `webkitUserSelect: 'none'` on the document element to prevent text selection globally,
|
|
136
|
+
* and restores the previous value when re-enabled. On other platforms, it sets `user-select: none` (or the appropriate
|
|
137
|
+
* vendor-prefixed property) on the provided element, and restores the previous value when re-enabled.
|
|
138
|
+
*
|
|
139
|
+
* This is useful for preventing unwanted text selection during press, drag, or other pointer interactions.
|
|
140
|
+
*
|
|
141
|
+
* @param {Element} [target] - The target element to disable text selection on. If omitted and running on iOS,
|
|
142
|
+
* disables selection on the entire document.
|
|
143
|
+
*/
|
|
144
|
+
declare function disableTextSelection(target?: Element): void;
|
|
145
|
+
/**
|
|
146
|
+
* Restores text selection for a given element, or for the entire document on iOS.
|
|
147
|
+
*
|
|
148
|
+
* On iOS, this restores the `webkitUserSelect` property on the document element to its previous value,
|
|
149
|
+
* after a short delay to avoid race conditions with pointer events. On other platforms, it restores the
|
|
150
|
+
* original `user-select` (or vendor-prefixed) property on the provided element if it was previously modified.
|
|
151
|
+
*
|
|
152
|
+
* This should be called after disabling text selection with `disableTextSelection` to re-enable normal selection behavior.
|
|
153
|
+
*
|
|
154
|
+
* @param {Element} [target] - The element to restore text selection on. If omitted and running on iOS,
|
|
155
|
+
* restores selection on the entire document.
|
|
156
|
+
*/
|
|
157
|
+
declare function restoreTextSelection(target?: Element): void;
|
|
158
|
+
|
|
159
|
+
export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, getScrollableElements, isNode, nodeContains, restoreTextSelection, runAfterTransition, supportsPreventScroll };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i={};function
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i={};function l(e){return c(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function c(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function s(e,t,n=!0){if(!e||!t)return!1;if(!n)return e.contains(t);let o=t;for(;o;){if(o===e)return!0;o=o instanceof Element&&"SLOT"===o.tagName&&o.assignedSlot?o.assignedSlot.parentNode:l(o)?o.host:o.parentNode}return!1}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{HTMLElements:()=>L,disableTextSelection:()=>A,focusWithoutScrolling:()=>g,getActiveElement:()=>a,getContainmentRect:()=>E,getEventTarget:()=>u,getOwnerDocument:()=>d,getOwnerWindow:()=>f,getScrollableElements:()=>w,isNode:()=>c,nodeContains:()=>s,restoreTextSelection:()=>U,runAfterTransition:()=>v,supportsPreventScroll:()=>p}),module.exports=(e=i,((e,i,l,c)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let s of o(i))r.call(e,s)||s===l||t(e,s,{get:()=>i[s],enumerable:!(c=n(i,s))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a=(e=document,t=!0)=>{if(!t)return e.activeElement;let n=e.activeElement;for(;n&&"shadowRoot"in n&&n.shadowRoot?.activeElement;)n=n.shadowRoot.activeElement;return n};function u(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}var d=e=>e?.ownerDocument??document,f=e=>{if(e&&"window"in e&&e.window===e)return e;return d(e).defaultView||window},m=null;function p(){if(null==m){m=!1;try{document.createElement("div").focus({get preventScroll(){return m=!0,!0}})}catch{}}return m}function g(e){if(p())e.focus({preventScroll:!0});else{const t=w(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}function w(e){let t=e.parentNode;const n=Array.from({length:0}),o=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==o;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return o instanceof HTMLElement&&n.push({element:o,scrollTop:o.scrollTop,scrollLeft:o.scrollLeft}),n}function E(e,t){if(e&&c(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=t?d(t):document,n=t?f(t):window;return{top:0,left:0,bottom:n.innerHeight||e.documentElement.clientHeight,right:n.innerWidth||e.documentElement.clientWidth}}}var y=new Map,S=new Set;function h(e){if(!("propertyName"in e)||!e.target)return;let t=y.get(e.target);t||(t=new Set,y.set(e.target,t),e.target.addEventListener("transitioncancel",b,{once:!0})),t.add(e.propertyName)}function b(e){if(!("propertyName"in e)||!e.target)return;const t=y.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",b),y.delete(e.target)),0===y.size)){for(const e of S)e();S.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",h),e.addEventListener("transitionend",b))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function v(e){requestAnimationFrame((()=>{for(const[e]of y)"isConnected"in e&&!e.isConnected&&y.delete(e);0===y.size?e():S.add(e)}))}var T=require("@necto/constants"),L=T.DOM.HTML_TAGS.reduce(((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e}),{}),O=require("@necto/platform"),N="default",M="",H=new WeakMap;function A(e){if((0,O.isIOS)()){if("default"===N){const t=d(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(M=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",N="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";H.has(e)||(H.set(e,t[n]??""),t[n]="none")}}function U(e){if((0,O.isIOS)()){if("disabled"!==N)return;N="restoring",setTimeout((()=>{v((()=>{if("restoring"===N){const t=d(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=M||""),M="",N="default"}}))}),300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&H.has(e)){const t=H.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),H.delete(e)}}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(e){return t(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function t(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function n(t,n,o=!0){if(!t||!n)return!1;if(!o)return t.contains(n);let r=n;for(;r;){if(r===t)return!0;r=r instanceof Element&&"SLOT"===r.tagName&&r.assignedSlot?r.assignedSlot.parentNode:e(r)?r.host:r.parentNode}return!1}var o=(e=document,t=!0)=>{if(!t)return e.activeElement;let n=e.activeElement;for(;n&&"shadowRoot"in n&&n.shadowRoot?.activeElement;)n=n.shadowRoot.activeElement;return n};function r(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}var i=e=>e?.ownerDocument??document,l=e=>{if(e&&"window"in e&&e.window===e)return e;return i(e).defaultView||window},c=null;function s(){if(null==c){c=!1;try{document.createElement("div").focus({get preventScroll(){return c=!0,!0}})}catch{}}return c}function a(e){if(s())e.focus({preventScroll:!0});else{const t=d(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}function d(e){let t=e.parentNode;const n=Array.from({length:0}),o=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==o;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return o instanceof HTMLElement&&n.push({element:o,scrollTop:o.scrollTop,scrollLeft:o.scrollLeft}),n}function f(e,n){if(e&&t(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=n?i(n):document,t=n?l(n):window;return{top:0,left:0,bottom:t.innerHeight||e.documentElement.clientHeight,right:t.innerWidth||e.documentElement.clientWidth}}}var u=new Map,m=new Set;function p(e){if(!("propertyName"in e)||!e.target)return;let t=u.get(e.target);t||(t=new Set,u.set(e.target,t),e.target.addEventListener("transitioncancel",g,{once:!0})),t.add(e.propertyName)}function g(e){if(!("propertyName"in e)||!e.target)return;const t=u.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",g),u.delete(e.target)),0===u.size)){for(const e of m)e();m.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",p),e.addEventListener("transitionend",g))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function E(e){requestAnimationFrame((()=>{for(const[e]of u)"isConnected"in e&&!e.isConnected&&u.delete(e);0===u.size?e():m.add(e)}))}import{DOM as w}from"@necto/constants";var h=w.HTML_TAGS.reduce(((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e}),{});import{isIOS as y}from"@necto/platform";var S="default",v="",T=new WeakMap;function L(e){if(y()){if("default"===S){const t=i(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(v=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",S="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";T.has(e)||(T.set(e,t[n]??""),t[n]="none")}}function b(e){if(y()){if("disabled"!==S)return;S="restoring",setTimeout((()=>{E((()=>{if("restoring"===S){const t=i(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=v||""),v="",S="default"}}))}),300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&T.has(e)){const t=T.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),T.delete(e)}}export{h as HTMLElements,L as disableTextSelection,a as focusWithoutScrolling,o as getActiveElement,f as getContainmentRect,r as getEventTarget,i as getOwnerDocument,l as getOwnerWindow,d as getScrollableElements,t as isNode,n as nodeContains,b as restoreTextSelection,E as runAfterTransition,s as supportsPreventScroll};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@necto/dom",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Necto's library for providing helpers and tools to interact with the DOM.",
|
|
5
5
|
"author": "Corinvo OSS Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,9 +12,15 @@
|
|
|
12
12
|
"dist",
|
|
13
13
|
"README.md"
|
|
14
14
|
],
|
|
15
|
-
"types": "dist/index.d.ts",
|
|
16
|
-
"main": "./dist/index.
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
17
|
"module": "./dist/index.mjs",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"html-tags": "^4.0.0",
|
|
20
|
+
"@necto/constants": "1.4.1",
|
|
21
|
+
"@necto/types": "1.3.0",
|
|
22
|
+
"@necto/platform": "1.4.0"
|
|
23
|
+
},
|
|
18
24
|
"scripts": {
|
|
19
25
|
"build": "tsup --minify terser"
|
|
20
26
|
}
|