@necto/dom 1.6.11 → 1.7.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -126
- package/dist/index.d.ts +6 -126
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i={};function l(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function c(e){return e?.ownerDocument
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i={};function l(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function c(e){return e?.ownerDocument??document}function s(e){return e&&"window"in e&&e.window===e?e:c(e).defaultView||window}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{ALL_ARIA_PROPS:()=>I,ARIA_PROPS_SET:()=>W,AriaProps:()=>D,HTMLElements:()=>P,disableTextSelection:()=>k,focusWithoutScrolling:()=>h,getActiveElement:()=>p,getContainmentRect:()=>S,getEventTarget:()=>g,getOwnerDocument:()=>c,getOwnerWindow:()=>s,hasAriaPrefix:()=>B,injectStyle:()=>E,isAriaAttribute:()=>j,isNode:()=>d,nodeContains:()=>m,restoreTextSelection:()=>H,runAfterTransition:()=>M,scrollIntoView:()=>u,toPx:()=>l}),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=null;function u(e,t,n){const{block:o="nearest",inline:r="nearest"}=n??{},i=e.getBoundingClientRect(),l=t.getBoundingClientRect(),c=l.top<i.top,s=l.bottom>i.bottom,a=l.left<i.left,u=l.right>i.right;if(c||s){let t=e.scrollTop;if("start"===o||"nearest"===o&&c)t=e.scrollTop+(l.top-i.top);else if("end"===o||"nearest"===o&&s)t=e.scrollTop+(l.bottom-i.bottom);else if("center"===o){const n=i.top+i.height/2,o=l.top+l.height/2;t=e.scrollTop+(o-n)}e.scrollTop=t}if(a||u){let t=e.scrollLeft;if("start"===r||"nearest"===r&&a)t=e.scrollLeft+(l.left-i.left);else if("end"===r||"nearest"===r&&u)t=e.scrollLeft+(l.right-i.right);else if("center"===r){const n=i.left+i.width/2,o=l.left+l.width/2;t=e.scrollLeft+(o-n)}e.scrollLeft=t}}function f(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function d(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function m(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:f(o)?o.host:o.parentNode}return!1}var p=(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 g(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function h(e){if(function(){if(null==a){a=!1;try{document.createElement("div").focus({get preventScroll(){return a=!0,!0}})}catch{}}return a}())e.focus({preventScroll:!0});else{const t=function(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;o instanceof HTMLElement&&n.push({element:o,scrollTop:o.scrollTop,scrollLeft:o.scrollLeft});return n}(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}var w="necto-style-id",y="necto-style",T=new WeakMap;function b(e,t={}){const{id:n=y,insertionPoint:o}=t,r=o?c(o):document,i=r.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute(w,n),i.textContent=e,o?r.head.insertBefore(i,o):r.head.appendChild(i),i}function E(e,t={}){const{id:n=y,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=function(e){let t=T.get(e);return t||(t=new Map,T.set(e,t)),t}(o),l=`${n}:${e}`;let c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:b(e,{id:n,insertionPoint:r}),count:1},i.set(l,c)),()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}function S(e,t){if(e&&d(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=t?c(t):document,n=t?s(t):window;return{top:0,left:0,bottom:n.innerHeight||e.documentElement.clientHeight,right:n.innerWidth||e.documentElement.clientWidth}}}var v=new Map,A=new Set;function L(e){if(!("propertyName"in e)||!e.target)return;let t=v.get(e.target);t||(t=new Set,v.set(e.target,t),e.target.addEventListener("transitioncancel",O,{once:!0})),t.add(e.propertyName)}function O(e){if(!("propertyName"in e)||!e.target)return;const t=v.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",O),v.delete(e.target)),0===v.size)){for(const e of A)e();A.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",L),e.addEventListener("transitionend",O))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function M(e){requestAnimationFrame(()=>{for(const[e]of v)"isConnected"in e&&!e.isConnected&&v.delete(e);0===v.size?e():A.add(e)})}var R=require("@necto/constants"),P=R.DOM.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),N=require("@necto/platform"),C="",U="default",_=new WeakMap;function k(e){if((0,N.isIOS)()){if("default"===U){const t=c(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(C=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",U="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";_.has(e)||(_.set(e,t[n]??""),t[n]="none")}}function H(e){if((0,N.isIOS)()){if("disabled"!==U)return;U="restoring",setTimeout(()=>{M(()=>{if("restoring"===U){const t=c(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=C||""),C="",U="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&_.has(e)){const 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"),_.delete(e)}}var x=require("@necto/constants"),D=x.DOM.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),I=x.DOM.ARIA_ATTRIBUTES,W=new Set(I),j=e=>W.has(e),B=e=>e.startsWith("aria-");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FocusableElement, HTMLElementsMap } from '@necto/types';
|
|
2
2
|
import { DOM } from '@necto/constants';
|
|
3
|
-
export { isSvg as isSvgContent, isSvgFast } from '@necto/file';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -17,27 +16,11 @@ declare function toPx(value?: number | string): string | undefined;
|
|
|
17
16
|
* This source code is licensed under the MIT license found in the
|
|
18
17
|
* LICENSE file in the root directory of this source tree.
|
|
19
18
|
*/
|
|
20
|
-
/** Returns the ownerDocument of an element, or the global document
|
|
21
|
-
declare function getOwnerDocument(el: Element | null | undefined): Document
|
|
22
|
-
/** Returns the window object that owns an element
|
|
23
|
-
declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined):
|
|
19
|
+
/** Returns the ownerDocument of an element, or the global document */
|
|
20
|
+
declare function getOwnerDocument(el: Element | null | undefined): Document;
|
|
21
|
+
/** Returns the window object that owns an element */
|
|
22
|
+
declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): Window & typeof global;
|
|
24
23
|
|
|
25
|
-
/**
|
|
26
|
-
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
27
|
-
* licensed under the Apache License, Version 2.0.
|
|
28
|
-
* Copyright (c) Adobe. All rights reserved.
|
|
29
|
-
* See: https://github.com/adobe/react-spectrum
|
|
30
|
-
*
|
|
31
|
-
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
32
|
-
*
|
|
33
|
-
* This file contains code licensed under:
|
|
34
|
-
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
35
|
-
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
36
|
-
*
|
|
37
|
-
* Modifications have been made to adapt the code for use in this project.
|
|
38
|
-
*/
|
|
39
|
-
/** Detects if the browser supports the preventScroll option in focus() */
|
|
40
|
-
declare function supportsPreventScroll(): boolean;
|
|
41
24
|
/**
|
|
42
25
|
* Scrolls an element into view within a scrollable container.
|
|
43
26
|
*
|
|
@@ -49,23 +32,6 @@ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLEleme
|
|
|
49
32
|
block?: ScrollLogicalPosition;
|
|
50
33
|
inline?: ScrollLogicalPosition;
|
|
51
34
|
}): void;
|
|
52
|
-
/**
|
|
53
|
-
* Scrolls an element into the viewport if it's not already visible.
|
|
54
|
-
*
|
|
55
|
-
* @param element - The element to scroll into viewport.
|
|
56
|
-
* @param options - Optional options for scrolling behavior.
|
|
57
|
-
*/
|
|
58
|
-
declare function scrollIntoViewport(element: HTMLElement, options?: {
|
|
59
|
-
containingElement?: HTMLElement | null;
|
|
60
|
-
}): void;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
64
|
-
*
|
|
65
|
-
* This source code is licensed under the MIT license found in the
|
|
66
|
-
* LICENSE file in the root directory of this source tree.
|
|
67
|
-
*/
|
|
68
|
-
declare function isShadowRoot(node: Node | null): node is ShadowRoot;
|
|
69
35
|
|
|
70
36
|
/**
|
|
71
37
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -76,35 +42,9 @@ declare function isShadowRoot(node: Node | null): node is ShadowRoot;
|
|
|
76
42
|
*/
|
|
77
43
|
declare function isNode(value: unknown): value is Node;
|
|
78
44
|
declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
|
|
79
|
-
declare const getActiveElement: (doc?: Document
|
|
45
|
+
declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
|
|
80
46
|
declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
|
|
81
47
|
|
|
82
|
-
/**
|
|
83
|
-
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
84
|
-
* licensed under the Apache License, Version 2.0.
|
|
85
|
-
* Copyright (c) Adobe. All rights reserved.
|
|
86
|
-
* See: https://github.com/adobe/react-spectrum
|
|
87
|
-
*
|
|
88
|
-
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
89
|
-
*
|
|
90
|
-
* This file contains code licensed under:
|
|
91
|
-
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
92
|
-
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
93
|
-
*
|
|
94
|
-
* Modifications have been made to adapt the code for use in this project.
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Represents an element with scroll position information.
|
|
98
|
-
*/
|
|
99
|
-
interface ScrollableElement {
|
|
100
|
-
/** The HTML element that is scrollable. */
|
|
101
|
-
element: HTMLElement;
|
|
102
|
-
/** The vertical scroll position of the element. */
|
|
103
|
-
scrollTop: number;
|
|
104
|
-
/** The horizontal scroll position of the element. */
|
|
105
|
-
scrollLeft: number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
48
|
/**
|
|
109
49
|
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
110
50
|
* licensed under the Apache License, Version 2.0.
|
|
@@ -127,14 +67,6 @@ interface ScrollableElement {
|
|
|
127
67
|
* @param {FocusableElement} element - The element to focus.
|
|
128
68
|
*/
|
|
129
69
|
declare function focusWithoutScrolling(element: FocusableElement): void;
|
|
130
|
-
/**
|
|
131
|
-
* Returns a list of all scrollable ancestor elements for a given element,
|
|
132
|
-
* including the root scrolling element.
|
|
133
|
-
*
|
|
134
|
-
* @param {FocusableElement} element - The element whose scrollable ancestors are to be found.
|
|
135
|
-
* @returns {ScrollableElement[]} An array of scrollable elements with their scroll positions.
|
|
136
|
-
*/
|
|
137
|
-
declare function getScrollableElements(element: FocusableElement): ScrollableElement[];
|
|
138
70
|
|
|
139
71
|
/**
|
|
140
72
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -147,11 +79,6 @@ interface CreateStyleElementOptions {
|
|
|
147
79
|
id?: string;
|
|
148
80
|
insertionPoint?: HTMLElement | null;
|
|
149
81
|
}
|
|
150
|
-
interface StyleEntry {
|
|
151
|
-
element: HTMLStyleElement | null;
|
|
152
|
-
count: number;
|
|
153
|
-
}
|
|
154
|
-
type StyleMap = Map<string, StyleEntry>;
|
|
155
82
|
interface InjectStyleOptions extends CreateStyleElementOptions {
|
|
156
83
|
window?: Window | null;
|
|
157
84
|
}
|
|
@@ -164,10 +91,7 @@ interface InjectStyleOptions extends CreateStyleElementOptions {
|
|
|
164
91
|
*
|
|
165
92
|
*/
|
|
166
93
|
|
|
167
|
-
declare function getStyleMap(targetWindow: Window): StyleMap;
|
|
168
|
-
declare function createStyleElement(css: string, options?: CreateStyleElementOptions): HTMLStyleElement;
|
|
169
94
|
declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
|
|
170
|
-
declare function removeStyleElement(element: HTMLStyleElement): void;
|
|
171
95
|
|
|
172
96
|
/**
|
|
173
97
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -214,32 +138,8 @@ declare function runAfterTransition(callback: () => void): void;
|
|
|
214
138
|
*
|
|
215
139
|
*/
|
|
216
140
|
|
|
217
|
-
/**
|
|
218
|
-
* Lazily-initialized mapping of capitalized HTML tag names to their original tag names.
|
|
219
|
-
* Deferred to avoid module initialization order issues when bundlers split
|
|
220
|
-
* `@necto/constants` and `@necto/dom` into separate chunks.
|
|
221
|
-
*/
|
|
222
141
|
declare const HTMLElements: HTMLElementsMap;
|
|
223
142
|
|
|
224
|
-
/**
|
|
225
|
-
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
226
|
-
* licensed under the Apache License, Version 2.0.
|
|
227
|
-
* Copyright (c) Adobe. All rights reserved.
|
|
228
|
-
* See: https://github.com/adobe/react-spectrum
|
|
229
|
-
*
|
|
230
|
-
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
231
|
-
*
|
|
232
|
-
* This file contains code licensed under:
|
|
233
|
-
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
234
|
-
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
235
|
-
*
|
|
236
|
-
* Modifications have been made to adapt the code for use in this project.
|
|
237
|
-
*/
|
|
238
|
-
/**
|
|
239
|
-
* Text selection state
|
|
240
|
-
*/
|
|
241
|
-
type TextSelectionStates = 'default' | 'disabled' | 'restoring';
|
|
242
|
-
|
|
243
143
|
/**
|
|
244
144
|
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
245
145
|
* licensed under the Apache License, Version 2.0.
|
|
@@ -354,24 +254,4 @@ declare const isAriaAttribute: (prop: string) => boolean;
|
|
|
354
254
|
*/
|
|
355
255
|
declare const hasAriaPrefix: (prop: string) => boolean;
|
|
356
256
|
|
|
357
|
-
|
|
358
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
359
|
-
*
|
|
360
|
-
* This source code is licensed under the MIT license found in the
|
|
361
|
-
* LICENSE file in the root directory of this source tree.
|
|
362
|
-
*/
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Injects width and height attributes into an SVG string
|
|
366
|
-
*/
|
|
367
|
-
declare function injectSvgDimensions(svg: string, width?: string | number, height?: string | number): string;
|
|
368
|
-
/**
|
|
369
|
-
* Checks if an element is an SVG element
|
|
370
|
-
*/
|
|
371
|
-
declare function isSvgElement(element: Element): element is SVGElement;
|
|
372
|
-
/**
|
|
373
|
-
* Checks if an element is a specific HTML element type
|
|
374
|
-
*/
|
|
375
|
-
declare function isElementType<K extends keyof HTMLElementTagNameMap>(element: Element, tagName: K): element is HTMLElementTagNameMap[K];
|
|
376
|
-
|
|
377
|
-
export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, type ContainmentRect, type CreateStyleElementOptions, HTMLElements, type InjectStyleOptions, type ScrollableElement, type StyleEntry, type StyleMap, type TextSelectionStates, createStyleElement, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, getScrollableElements, getStyleMap, hasAriaPrefix, injectStyle, injectSvgDimensions, isAriaAttribute, isElementType, isNode, isShadowRoot, isSvgElement, nodeContains, removeStyleElement, restoreTextSelection, runAfterTransition, scrollIntoView, scrollIntoViewport, supportsPreventScroll, toPx };
|
|
257
|
+
export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, hasAriaPrefix, injectStyle, isAriaAttribute, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FocusableElement, HTMLElementsMap } from '@necto/types';
|
|
2
2
|
import { DOM } from '@necto/constants';
|
|
3
|
-
export { isSvg as isSvgContent, isSvgFast } from '@necto/file';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -17,27 +16,11 @@ declare function toPx(value?: number | string): string | undefined;
|
|
|
17
16
|
* This source code is licensed under the MIT license found in the
|
|
18
17
|
* LICENSE file in the root directory of this source tree.
|
|
19
18
|
*/
|
|
20
|
-
/** Returns the ownerDocument of an element, or the global document
|
|
21
|
-
declare function getOwnerDocument(el: Element | null | undefined): Document
|
|
22
|
-
/** Returns the window object that owns an element
|
|
23
|
-
declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined):
|
|
19
|
+
/** Returns the ownerDocument of an element, or the global document */
|
|
20
|
+
declare function getOwnerDocument(el: Element | null | undefined): Document;
|
|
21
|
+
/** Returns the window object that owns an element */
|
|
22
|
+
declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): Window & typeof global;
|
|
24
23
|
|
|
25
|
-
/**
|
|
26
|
-
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
27
|
-
* licensed under the Apache License, Version 2.0.
|
|
28
|
-
* Copyright (c) Adobe. All rights reserved.
|
|
29
|
-
* See: https://github.com/adobe/react-spectrum
|
|
30
|
-
*
|
|
31
|
-
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
32
|
-
*
|
|
33
|
-
* This file contains code licensed under:
|
|
34
|
-
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
35
|
-
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
36
|
-
*
|
|
37
|
-
* Modifications have been made to adapt the code for use in this project.
|
|
38
|
-
*/
|
|
39
|
-
/** Detects if the browser supports the preventScroll option in focus() */
|
|
40
|
-
declare function supportsPreventScroll(): boolean;
|
|
41
24
|
/**
|
|
42
25
|
* Scrolls an element into view within a scrollable container.
|
|
43
26
|
*
|
|
@@ -49,23 +32,6 @@ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLEleme
|
|
|
49
32
|
block?: ScrollLogicalPosition;
|
|
50
33
|
inline?: ScrollLogicalPosition;
|
|
51
34
|
}): void;
|
|
52
|
-
/**
|
|
53
|
-
* Scrolls an element into the viewport if it's not already visible.
|
|
54
|
-
*
|
|
55
|
-
* @param element - The element to scroll into viewport.
|
|
56
|
-
* @param options - Optional options for scrolling behavior.
|
|
57
|
-
*/
|
|
58
|
-
declare function scrollIntoViewport(element: HTMLElement, options?: {
|
|
59
|
-
containingElement?: HTMLElement | null;
|
|
60
|
-
}): void;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
64
|
-
*
|
|
65
|
-
* This source code is licensed under the MIT license found in the
|
|
66
|
-
* LICENSE file in the root directory of this source tree.
|
|
67
|
-
*/
|
|
68
|
-
declare function isShadowRoot(node: Node | null): node is ShadowRoot;
|
|
69
35
|
|
|
70
36
|
/**
|
|
71
37
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -76,35 +42,9 @@ declare function isShadowRoot(node: Node | null): node is ShadowRoot;
|
|
|
76
42
|
*/
|
|
77
43
|
declare function isNode(value: unknown): value is Node;
|
|
78
44
|
declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
|
|
79
|
-
declare const getActiveElement: (doc?: Document
|
|
45
|
+
declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
|
|
80
46
|
declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
|
|
81
47
|
|
|
82
|
-
/**
|
|
83
|
-
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
84
|
-
* licensed under the Apache License, Version 2.0.
|
|
85
|
-
* Copyright (c) Adobe. All rights reserved.
|
|
86
|
-
* See: https://github.com/adobe/react-spectrum
|
|
87
|
-
*
|
|
88
|
-
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
89
|
-
*
|
|
90
|
-
* This file contains code licensed under:
|
|
91
|
-
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
92
|
-
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
93
|
-
*
|
|
94
|
-
* Modifications have been made to adapt the code for use in this project.
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Represents an element with scroll position information.
|
|
98
|
-
*/
|
|
99
|
-
interface ScrollableElement {
|
|
100
|
-
/** The HTML element that is scrollable. */
|
|
101
|
-
element: HTMLElement;
|
|
102
|
-
/** The vertical scroll position of the element. */
|
|
103
|
-
scrollTop: number;
|
|
104
|
-
/** The horizontal scroll position of the element. */
|
|
105
|
-
scrollLeft: number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
48
|
/**
|
|
109
49
|
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
110
50
|
* licensed under the Apache License, Version 2.0.
|
|
@@ -127,14 +67,6 @@ interface ScrollableElement {
|
|
|
127
67
|
* @param {FocusableElement} element - The element to focus.
|
|
128
68
|
*/
|
|
129
69
|
declare function focusWithoutScrolling(element: FocusableElement): void;
|
|
130
|
-
/**
|
|
131
|
-
* Returns a list of all scrollable ancestor elements for a given element,
|
|
132
|
-
* including the root scrolling element.
|
|
133
|
-
*
|
|
134
|
-
* @param {FocusableElement} element - The element whose scrollable ancestors are to be found.
|
|
135
|
-
* @returns {ScrollableElement[]} An array of scrollable elements with their scroll positions.
|
|
136
|
-
*/
|
|
137
|
-
declare function getScrollableElements(element: FocusableElement): ScrollableElement[];
|
|
138
70
|
|
|
139
71
|
/**
|
|
140
72
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -147,11 +79,6 @@ interface CreateStyleElementOptions {
|
|
|
147
79
|
id?: string;
|
|
148
80
|
insertionPoint?: HTMLElement | null;
|
|
149
81
|
}
|
|
150
|
-
interface StyleEntry {
|
|
151
|
-
element: HTMLStyleElement | null;
|
|
152
|
-
count: number;
|
|
153
|
-
}
|
|
154
|
-
type StyleMap = Map<string, StyleEntry>;
|
|
155
82
|
interface InjectStyleOptions extends CreateStyleElementOptions {
|
|
156
83
|
window?: Window | null;
|
|
157
84
|
}
|
|
@@ -164,10 +91,7 @@ interface InjectStyleOptions extends CreateStyleElementOptions {
|
|
|
164
91
|
*
|
|
165
92
|
*/
|
|
166
93
|
|
|
167
|
-
declare function getStyleMap(targetWindow: Window): StyleMap;
|
|
168
|
-
declare function createStyleElement(css: string, options?: CreateStyleElementOptions): HTMLStyleElement;
|
|
169
94
|
declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
|
|
170
|
-
declare function removeStyleElement(element: HTMLStyleElement): void;
|
|
171
95
|
|
|
172
96
|
/**
|
|
173
97
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -214,32 +138,8 @@ declare function runAfterTransition(callback: () => void): void;
|
|
|
214
138
|
*
|
|
215
139
|
*/
|
|
216
140
|
|
|
217
|
-
/**
|
|
218
|
-
* Lazily-initialized mapping of capitalized HTML tag names to their original tag names.
|
|
219
|
-
* Deferred to avoid module initialization order issues when bundlers split
|
|
220
|
-
* `@necto/constants` and `@necto/dom` into separate chunks.
|
|
221
|
-
*/
|
|
222
141
|
declare const HTMLElements: HTMLElementsMap;
|
|
223
142
|
|
|
224
|
-
/**
|
|
225
|
-
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
226
|
-
* licensed under the Apache License, Version 2.0.
|
|
227
|
-
* Copyright (c) Adobe. All rights reserved.
|
|
228
|
-
* See: https://github.com/adobe/react-spectrum
|
|
229
|
-
*
|
|
230
|
-
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
231
|
-
*
|
|
232
|
-
* This file contains code licensed under:
|
|
233
|
-
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
234
|
-
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
235
|
-
*
|
|
236
|
-
* Modifications have been made to adapt the code for use in this project.
|
|
237
|
-
*/
|
|
238
|
-
/**
|
|
239
|
-
* Text selection state
|
|
240
|
-
*/
|
|
241
|
-
type TextSelectionStates = 'default' | 'disabled' | 'restoring';
|
|
242
|
-
|
|
243
143
|
/**
|
|
244
144
|
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
245
145
|
* licensed under the Apache License, Version 2.0.
|
|
@@ -354,24 +254,4 @@ declare const isAriaAttribute: (prop: string) => boolean;
|
|
|
354
254
|
*/
|
|
355
255
|
declare const hasAriaPrefix: (prop: string) => boolean;
|
|
356
256
|
|
|
357
|
-
|
|
358
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
359
|
-
*
|
|
360
|
-
* This source code is licensed under the MIT license found in the
|
|
361
|
-
* LICENSE file in the root directory of this source tree.
|
|
362
|
-
*/
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Injects width and height attributes into an SVG string
|
|
366
|
-
*/
|
|
367
|
-
declare function injectSvgDimensions(svg: string, width?: string | number, height?: string | number): string;
|
|
368
|
-
/**
|
|
369
|
-
* Checks if an element is an SVG element
|
|
370
|
-
*/
|
|
371
|
-
declare function isSvgElement(element: Element): element is SVGElement;
|
|
372
|
-
/**
|
|
373
|
-
* Checks if an element is a specific HTML element type
|
|
374
|
-
*/
|
|
375
|
-
declare function isElementType<K extends keyof HTMLElementTagNameMap>(element: Element, tagName: K): element is HTMLElementTagNameMap[K];
|
|
376
|
-
|
|
377
|
-
export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, type ContainmentRect, type CreateStyleElementOptions, HTMLElements, type InjectStyleOptions, type ScrollableElement, type StyleEntry, type StyleMap, type TextSelectionStates, createStyleElement, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, getScrollableElements, getStyleMap, hasAriaPrefix, injectStyle, injectSvgDimensions, isAriaAttribute, isElementType, isNode, isShadowRoot, isSvgElement, nodeContains, removeStyleElement, restoreTextSelection, runAfterTransition, scrollIntoView, scrollIntoViewport, supportsPreventScroll, toPx };
|
|
257
|
+
export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, hasAriaPrefix, injectStyle, isAriaAttribute, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function t(e){return e?.ownerDocument
|
|
1
|
+
function e(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function t(e){return e?.ownerDocument??document}function n(e){return e&&"window"in e&&e.window===e?e:t(e).defaultView||window}var o=null;function r(e,t,n){const{block:o="nearest",inline:r="nearest"}=n??{},i=e.getBoundingClientRect(),l=t.getBoundingClientRect(),c=l.top<i.top,s=l.bottom>i.bottom,f=l.left<i.left,a=l.right>i.right;if(c||s){let t=e.scrollTop;if("start"===o||"nearest"===o&&c)t=e.scrollTop+(l.top-i.top);else if("end"===o||"nearest"===o&&s)t=e.scrollTop+(l.bottom-i.bottom);else if("center"===o){const n=i.top+i.height/2,o=l.top+l.height/2;t=e.scrollTop+(o-n)}e.scrollTop=t}if(f||a){let t=e.scrollLeft;if("start"===r||"nearest"===r&&f)t=e.scrollLeft+(l.left-i.left);else if("end"===r||"nearest"===r&&a)t=e.scrollLeft+(l.right-i.right);else if("center"===r){const n=i.left+i.width/2,o=l.left+l.width/2;t=e.scrollLeft+(o-n)}e.scrollLeft=t}}function i(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function l(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function c(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:i(o)?o.host:o.parentNode}return!1}var s=(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 f(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function a(e){if(function(){if(null==o){o=!1;try{document.createElement("div").focus({get preventScroll(){return o=!0,!0}})}catch{}}return o}())e.focus({preventScroll:!0});else{const t=function(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;o instanceof HTMLElement&&n.push({element:o,scrollTop:o.scrollTop,scrollLeft:o.scrollLeft});return n}(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}var d="necto-style",u=new WeakMap;function m(e,n={}){const{id:o=d,insertionPoint:r}=n,i=r?t(r):document,l=i.createElement("style");return l.setAttribute("type","text/css"),l.setAttribute("necto-style-id",o),l.textContent=e,r?i.head.insertBefore(l,r):i.head.appendChild(l),l}function p(e,t={}){const{id:n=d,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=function(e){let t=u.get(e);return t||(t=new Map,u.set(e,t)),t}(o),l=`${n}:${e}`;let c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:m(e,{id:n,insertionPoint:r}),count:1},i.set(l,c)),()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}function g(e,o){if(e&&l(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=o?t(o):document,r=o?n(o):window;return{top:0,left:0,bottom:r.innerHeight||e.documentElement.clientHeight,right:r.innerWidth||e.documentElement.clientWidth}}}var h=new Map,w=new Set;function y(e){if(!("propertyName"in e)||!e.target)return;let t=h.get(e.target);t||(t=new Set,h.set(e.target,t),e.target.addEventListener("transitioncancel",E,{once:!0})),t.add(e.propertyName)}function E(e){if(!("propertyName"in e)||!e.target)return;const t=h.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",E),h.delete(e.target)),0===h.size)){for(const e of w)e();w.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",y),e.addEventListener("transitionend",E))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function T(e){requestAnimationFrame(()=>{for(const[e]of h)"isConnected"in e&&!e.isConnected&&h.delete(e);0===h.size?e():w.add(e)})}import{DOM as b}from"@necto/constants";var v=b.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{});import{isIOS as S}from"@necto/platform";var L="",A="default",M=new WeakMap;function N(e){if(S()){if("default"===A){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(L=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",A="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";M.has(e)||(M.set(e,t[n]??""),t[n]="none")}}function C(e){if(S()){if("disabled"!==A)return;A="restoring",setTimeout(()=>{T(()=>{if("restoring"===A){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=L||""),L="",A="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&M.has(e)){const t=M.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),M.delete(e)}}import{DOM as R}from"@necto/constants";var U=R.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),k=R.ARIA_ATTRIBUTES,H=new Set(k),W=e=>H.has(e),B=e=>e.startsWith("aria-");export{k as ALL_ARIA_PROPS,H as ARIA_PROPS_SET,U as AriaProps,v as HTMLElements,N as disableTextSelection,a as focusWithoutScrolling,s as getActiveElement,g as getContainmentRect,f as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,B as hasAriaPrefix,p as injectStyle,W as isAriaAttribute,l as isNode,c as nodeContains,C as restoreTextSelection,T as runAfterTransition,r as scrollIntoView,e as toPx};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@necto/dom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"html-tags": "^4.0.0",
|
|
28
28
|
"@necto/constants": "1.4.4",
|
|
29
|
-
"@necto/file": "1.0.0",
|
|
30
29
|
"@necto/types": "1.3.1",
|
|
30
|
+
"@necto/file": "1.0.0",
|
|
31
31
|
"@necto/platform": "1.5.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|