@necto/dom 1.4.5 → 1.5.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/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){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)}}
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 s(e){return e?.ownerDocument??document}function c(e){return e&&"window"in e&&e.window===e?e:s(e).defaultView||window}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{ALL_ARIA_PROPS:()=>$,ARIA_PROPS_SET:()=>q,AriaProps:()=>B,HTMLElements:()=>U,createStyleElement:()=>L,disableTextSelection:()=>x,focusWithoutScrolling:()=>S,getActiveElement:()=>w,getContainmentRect:()=>M,getEventTarget:()=>h,getOwnerDocument:()=>s,getOwnerWindow:()=>c,getScrollableElements:()=>y,getStyleMap:()=>T,hasAriaPrefix:()=>F,injectStyle:()=>A,injectSvgDimensions:()=>J,isAriaAttribute:()=>G,isElementType:()=>Q,isNode:()=>p,isShadowRoot:()=>m,isSvgContent:()=>z.isSvg,isSvgElement:()=>K,isSvgFast:()=>z.isSvgFast,nodeContains:()=>g,removeStyleElement:()=>O,restoreTextSelection:()=>W,runAfterTransition:()=>k,scrollIntoView:()=>f,scrollIntoViewport:()=>d,supportsPreventScroll:()=>u,toPx:()=>l}),module.exports=(e=i,((e,i,l,s)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of o(i))r.call(e,c)||c===l||t(e,c,{get:()=>i[c],enumerable:!(s=n(i,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a=null;function u(){if(null==a){a=!1;try{document.createElement("div").focus({get preventScroll(){return a=!0,!0}})}catch{}}return a}function f(e,t,n){const{block:o="nearest",inline:r="nearest"}=n??{},i=e.getBoundingClientRect(),l=t.getBoundingClientRect(),s=l.top<i.top,c=l.bottom>i.bottom,a=l.left<i.left,u=l.right>i.right;if(s||c){let t=e.scrollTop;if("start"===o||"nearest"===o&&s)t=e.scrollTop+(l.top-i.top);else if("end"===o||"nearest"===o&&c)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 d(e,t){const{containingElement:n}=t??{};e.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"}),n&&n.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"})}function m(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function p(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function g(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:m(o)?o.host:o.parentNode}return!1}var w=(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 h(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function S(e){if(u())e.focus({preventScroll:!0});else{const t=y(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}function y(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}var E="necto-style-id",b="necto-style",v=new WeakMap;function T(e){let t=v.get(e);return t||(t=new Map,v.set(e,t)),t}function L(e,t={}){const{id:n=b,insertionPoint:o}=t,r=o?s(o):document,i=r.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute(E,n),i.textContent=e,o?r.head.insertBefore(i,o):r.head.appendChild(i),i}function A(e,t={}){const{id:n=b,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=T(o),l=`${n}:${e}`;let s=i.get(l);return s?s.element&&(s.element.textContent=e,s.count++):(s={element:L(e,{id:n,insertionPoint:r}),count:1},i.set(l,s)),()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}function O(e){e.remove()}function M(e,t){if(e&&p(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=t?s(t):document,n=t?c(t):window;return{top:0,left:0,bottom:n.innerHeight||e.documentElement.clientHeight,right:n.innerWidth||e.documentElement.clientWidth}}}var R=new Map,C=new Set;function P(e){if(!("propertyName"in e)||!e.target)return;let t=R.get(e.target);t||(t=new Set,R.set(e.target,t),e.target.addEventListener("transitioncancel",N,{once:!0})),t.add(e.propertyName)}function N(e){if(!("propertyName"in e)||!e.target)return;const t=R.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",N),R.delete(e.target)),0===R.size)){for(const e of C)e();C.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",P),e.addEventListener("transitionend",N))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function k(e){requestAnimationFrame(()=>{for(const[e]of R)"isConnected"in e&&!e.isConnected&&R.delete(e);0===R.size?e():C.add(e)})}var I=require("@necto/constants"),U=I.DOM.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),_=require("@necto/platform"),D="",H="default",j=new WeakMap;function x(e){if((0,_.isIOS)()){if("default"===H){const t=s(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(D=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",H="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";j.has(e)||(j.set(e,t[n]??""),t[n]="none")}}function W(e){if((0,_.isIOS)()){if("disabled"!==H)return;H="restoring",setTimeout(()=>{k(()=>{if("restoring"===H){const t=s(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=D||""),D="",H="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&j.has(e)){const t=j.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),j.delete(e)}}var V=require("@necto/constants"),B=V.DOM.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),$=V.DOM.ARIA_ATTRIBUTES,q=new Set($),G=e=>q.has(e),F=e=>e.startsWith("aria-"),z=require("@necto/file");function J(e,t="100%",n="100%"){return e.replace(/<svg([^>]*)>/,`<svg$1 width="${t}" height="${n}">`)}function K(e){return e instanceof SVGElement}function Q(e,t){return e.tagName.toLowerCase()===t.toLowerCase()}
package/dist/index.d.cts CHANGED
@@ -1,16 +1,71 @@
1
1
  import { FocusableElement, HTMLElementsMap } from '@necto/types';
2
+ import { DOM } from '@necto/constants';
3
+ export { isSvg as isSvgContent, isSvgFast } from '@necto/file';
2
4
 
3
5
  /**
4
6
  * Copyright (c) Corinvo, LLC. and affiliates.
5
7
  *
6
8
  * This source code is licensed under the MIT license found in the
7
9
  * LICENSE file in the root directory of this source tree.
10
+ */
11
+ /** Converts a number to CSS pixels, passes strings through unchanged */
12
+ declare function toPx(value?: number | string): string | undefined;
13
+
14
+ /**
15
+ * Copyright (c) Corinvo, LLC. and affiliates.
8
16
  *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
9
19
  */
10
- declare function isNode(value: unknown): value is Node;
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;
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): Window & typeof global;
24
+
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
+ /**
42
+ * Scrolls an element into view within a scrollable container.
43
+ *
44
+ * @param scrollContainer - The scrollable container element.
45
+ * @param element - The element to scroll into view.
46
+ * @param options - Optional scroll behavior options.
47
+ */
48
+ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLElement, options?: {
49
+ block?: ScrollLogicalPosition;
50
+ inline?: ScrollLogicalPosition;
51
+ }): 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;
14
69
 
15
70
  /**
16
71
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -19,9 +74,25 @@ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: bo
19
74
  * LICENSE file in the root directory of this source tree.
20
75
  *
21
76
  */
22
- declare const getOwnerDocument: (el: Element | null | undefined) => Document;
23
- declare const getOwnerWindow: (el: (Window & typeof global) | Element | null | undefined) => Window & typeof global;
77
+ declare function isNode(value: unknown): value is Node;
78
+ declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
79
+ declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
80
+ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
24
81
 
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
+ */
25
96
  /**
26
97
  * Represents an element with scroll position information.
27
98
  */
@@ -66,25 +137,37 @@ declare function focusWithoutScrolling(element: FocusableElement): void;
66
137
  declare function getScrollableElements(element: FocusableElement): ScrollableElement[];
67
138
 
68
139
  /**
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.
140
+ * Copyright (c) Corinvo, LLC. and affiliates.
75
141
  *
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.
142
+ * This source code is licensed under the MIT license found in the
143
+ * LICENSE file in the root directory of this source tree.
79
144
  *
80
- * Modifications have been made to adapt the code for use in this project.
81
145
  */
146
+ interface CreateStyleElementOptions {
147
+ id?: string;
148
+ insertionPoint?: HTMLElement | null;
149
+ }
150
+ interface StyleEntry {
151
+ element: HTMLStyleElement | null;
152
+ count: number;
153
+ }
154
+ type StyleMap = Map<string, StyleEntry>;
155
+ interface InjectStyleOptions extends CreateStyleElementOptions {
156
+ window?: Window | null;
157
+ }
158
+
82
159
  /**
83
- * Detects if the browser supports the preventScroll option in the focus() method.
160
+ * Copyright (c) Corinvo, LLC. and affiliates.
161
+ *
162
+ * This source code is licensed under the MIT license found in the
163
+ * LICENSE file in the root directory of this source tree.
84
164
  *
85
- * @returns {boolean} True if preventScroll is supported, otherwise false.
86
165
  */
87
- declare function supportsPreventScroll(): boolean;
166
+
167
+ declare function getStyleMap(targetWindow: Window): StyleMap;
168
+ declare function createStyleElement(css: string, options?: CreateStyleElementOptions): HTMLStyleElement;
169
+ declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
170
+ declare function removeStyleElement(element: HTMLStyleElement): void;
88
171
 
89
172
  /**
90
173
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -93,12 +176,22 @@ declare function supportsPreventScroll(): boolean;
93
176
  * LICENSE file in the root directory of this source tree.
94
177
  *
95
178
  */
96
- declare function getContainmentRect(containment: Element | null | undefined, fallbackElement?: Element | null): {
179
+ interface ContainmentRect {
97
180
  top: number;
98
181
  left: number;
99
182
  bottom: number;
100
183
  right: number;
101
- };
184
+ }
185
+
186
+ /**
187
+ * Copyright (c) Corinvo, LLC. and affiliates.
188
+ *
189
+ * This source code is licensed under the MIT license found in the
190
+ * LICENSE file in the root directory of this source tree.
191
+ *
192
+ */
193
+
194
+ declare function getContainmentRect(containment: Element | null | undefined, fallbackElement?: Element | null): ContainmentRect;
102
195
 
103
196
  /**
104
197
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -113,8 +206,35 @@ declare function getContainmentRect(containment: Element | null | undefined, fal
113
206
  */
114
207
  declare function runAfterTransition(callback: () => void): void;
115
208
 
209
+ /**
210
+ * Copyright (c) Corinvo, LLC. and affiliates.
211
+ *
212
+ * This source code is licensed under the MIT license found in the
213
+ * LICENSE file in the root directory of this source tree.
214
+ *
215
+ */
216
+
116
217
  declare const HTMLElements: HTMLElementsMap;
117
218
 
219
+ /**
220
+ * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
221
+ * licensed under the Apache License, Version 2.0.
222
+ * Copyright (c) Adobe. All rights reserved.
223
+ * See: https://github.com/adobe/react-spectrum
224
+ *
225
+ * Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
226
+ *
227
+ * This file contains code licensed under:
228
+ * - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
229
+ * - The Apache License, Version 2.0 for portions from Adobe.
230
+ *
231
+ * Modifications have been made to adapt the code for use in this project.
232
+ */
233
+ /**
234
+ * Text selection state
235
+ */
236
+ type TextSelectionStates = 'default' | 'disabled' | 'restoring';
237
+
118
238
  /**
119
239
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
120
240
  * licensed under the Apache License, Version 2.0.
@@ -156,4 +276,97 @@ declare function disableTextSelection(target?: Element): void;
156
276
  */
157
277
  declare function restoreTextSelection(target?: Element): void;
158
278
 
159
- export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, getScrollableElements, isNode, nodeContains, restoreTextSelection, runAfterTransition, supportsPreventScroll };
279
+ /**
280
+ * Copyright (c) Corinvo, LLC. and affiliates.
281
+ *
282
+ * This source code is licensed under the MIT license found in the
283
+ * LICENSE file in the root directory of this source tree.
284
+ *
285
+ */
286
+
287
+ /**
288
+ * Type representing valid ARIA attribute values (e.g., 'aria-pressed', 'aria-disabled').
289
+ */
290
+ type AriaAttribute = (typeof DOM.ARIA_ATTRIBUTES)[number];
291
+
292
+ /**
293
+ * Copyright (c) Corinvo, LLC. and affiliates.
294
+ *
295
+ * This source code is licensed under the MIT license found in the
296
+ * LICENSE file in the root directory of this source tree.
297
+ *
298
+ */
299
+ /**
300
+ * All valid ARIA attribute names as constants.
301
+ * Use: AriaProps.Pressed → 'aria-pressed'
302
+ *
303
+ * @example
304
+ * ```tsx
305
+ * import { AriaProps } from '@necto/dom';
306
+ *
307
+ * const props = {
308
+ * [AriaProps.Pressed]: isSelected,
309
+ * [AriaProps.Disabled]: isDisabled
310
+ * };
311
+ * ```
312
+ */
313
+ declare const AriaProps: Record<string, string>;
314
+ /**
315
+ * Array of all ARIA attribute values.
316
+ * Useful for filterDOMProps or validation.
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * filterDOMProps(props, {
321
+ * extraAllowedProps: new Set([...ALLOWED_EXTERNAL_PROPS, ...ALL_ARIA_PROPS])
322
+ * });
323
+ * ```
324
+ */
325
+ declare const ALL_ARIA_PROPS: readonly string[];
326
+ /**
327
+ * Set of all ARIA attribute values for O(1) lookup.
328
+ */
329
+ declare const ARIA_PROPS_SET: Set<string>;
330
+ /**
331
+ * Checks if a string is a valid ARIA attribute.
332
+ * @param prop - The property name to check.
333
+ * @returns True if the property is a valid ARIA attribute.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * isAriaAttribute('aria-pressed'); // true
338
+ * isAriaAttribute('aria-invalid'); // true
339
+ * isAriaAttribute('data-foo'); // false
340
+ * isAriaAttribute('onClick'); // false
341
+ * ```
342
+ */
343
+ declare const isAriaAttribute: (prop: string) => boolean;
344
+ /**
345
+ * Checks if a string starts with 'aria-' prefix.
346
+ * This is a quick check that doesn't validate against the full list.
347
+ * @param prop - The property name to check.
348
+ * @returns True if the property starts with 'aria-'.
349
+ */
350
+ declare const hasAriaPrefix: (prop: string) => boolean;
351
+
352
+ /**
353
+ * Copyright (c) Corinvo, LLC. and affiliates.
354
+ *
355
+ * This source code is licensed under the MIT license found in the
356
+ * LICENSE file in the root directory of this source tree.
357
+ */
358
+
359
+ /**
360
+ * Injects width and height attributes into an SVG string
361
+ */
362
+ declare function injectSvgDimensions(svg: string, width?: string | number, height?: string | number): string;
363
+ /**
364
+ * Checks if an element is an SVG element
365
+ */
366
+ declare function isSvgElement(element: Element): element is SVGElement;
367
+ /**
368
+ * Checks if an element is a specific HTML element type
369
+ */
370
+ declare function isElementType<K extends keyof HTMLElementTagNameMap>(element: Element, tagName: K): element is HTMLElementTagNameMap[K];
371
+
372
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,71 @@
1
1
  import { FocusableElement, HTMLElementsMap } from '@necto/types';
2
+ import { DOM } from '@necto/constants';
3
+ export { isSvg as isSvgContent, isSvgFast } from '@necto/file';
2
4
 
3
5
  /**
4
6
  * Copyright (c) Corinvo, LLC. and affiliates.
5
7
  *
6
8
  * This source code is licensed under the MIT license found in the
7
9
  * LICENSE file in the root directory of this source tree.
10
+ */
11
+ /** Converts a number to CSS pixels, passes strings through unchanged */
12
+ declare function toPx(value?: number | string): string | undefined;
13
+
14
+ /**
15
+ * Copyright (c) Corinvo, LLC. and affiliates.
8
16
  *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
9
19
  */
10
- declare function isNode(value: unknown): value is Node;
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;
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): Window & typeof global;
24
+
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
+ /**
42
+ * Scrolls an element into view within a scrollable container.
43
+ *
44
+ * @param scrollContainer - The scrollable container element.
45
+ * @param element - The element to scroll into view.
46
+ * @param options - Optional scroll behavior options.
47
+ */
48
+ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLElement, options?: {
49
+ block?: ScrollLogicalPosition;
50
+ inline?: ScrollLogicalPosition;
51
+ }): 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;
14
69
 
15
70
  /**
16
71
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -19,9 +74,25 @@ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: bo
19
74
  * LICENSE file in the root directory of this source tree.
20
75
  *
21
76
  */
22
- declare const getOwnerDocument: (el: Element | null | undefined) => Document;
23
- declare const getOwnerWindow: (el: (Window & typeof global) | Element | null | undefined) => Window & typeof global;
77
+ declare function isNode(value: unknown): value is Node;
78
+ declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
79
+ declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
80
+ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
24
81
 
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
+ */
25
96
  /**
26
97
  * Represents an element with scroll position information.
27
98
  */
@@ -66,25 +137,37 @@ declare function focusWithoutScrolling(element: FocusableElement): void;
66
137
  declare function getScrollableElements(element: FocusableElement): ScrollableElement[];
67
138
 
68
139
  /**
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.
140
+ * Copyright (c) Corinvo, LLC. and affiliates.
75
141
  *
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.
142
+ * This source code is licensed under the MIT license found in the
143
+ * LICENSE file in the root directory of this source tree.
79
144
  *
80
- * Modifications have been made to adapt the code for use in this project.
81
145
  */
146
+ interface CreateStyleElementOptions {
147
+ id?: string;
148
+ insertionPoint?: HTMLElement | null;
149
+ }
150
+ interface StyleEntry {
151
+ element: HTMLStyleElement | null;
152
+ count: number;
153
+ }
154
+ type StyleMap = Map<string, StyleEntry>;
155
+ interface InjectStyleOptions extends CreateStyleElementOptions {
156
+ window?: Window | null;
157
+ }
158
+
82
159
  /**
83
- * Detects if the browser supports the preventScroll option in the focus() method.
160
+ * Copyright (c) Corinvo, LLC. and affiliates.
161
+ *
162
+ * This source code is licensed under the MIT license found in the
163
+ * LICENSE file in the root directory of this source tree.
84
164
  *
85
- * @returns {boolean} True if preventScroll is supported, otherwise false.
86
165
  */
87
- declare function supportsPreventScroll(): boolean;
166
+
167
+ declare function getStyleMap(targetWindow: Window): StyleMap;
168
+ declare function createStyleElement(css: string, options?: CreateStyleElementOptions): HTMLStyleElement;
169
+ declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
170
+ declare function removeStyleElement(element: HTMLStyleElement): void;
88
171
 
89
172
  /**
90
173
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -93,12 +176,22 @@ declare function supportsPreventScroll(): boolean;
93
176
  * LICENSE file in the root directory of this source tree.
94
177
  *
95
178
  */
96
- declare function getContainmentRect(containment: Element | null | undefined, fallbackElement?: Element | null): {
179
+ interface ContainmentRect {
97
180
  top: number;
98
181
  left: number;
99
182
  bottom: number;
100
183
  right: number;
101
- };
184
+ }
185
+
186
+ /**
187
+ * Copyright (c) Corinvo, LLC. and affiliates.
188
+ *
189
+ * This source code is licensed under the MIT license found in the
190
+ * LICENSE file in the root directory of this source tree.
191
+ *
192
+ */
193
+
194
+ declare function getContainmentRect(containment: Element | null | undefined, fallbackElement?: Element | null): ContainmentRect;
102
195
 
103
196
  /**
104
197
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -113,8 +206,35 @@ declare function getContainmentRect(containment: Element | null | undefined, fal
113
206
  */
114
207
  declare function runAfterTransition(callback: () => void): void;
115
208
 
209
+ /**
210
+ * Copyright (c) Corinvo, LLC. and affiliates.
211
+ *
212
+ * This source code is licensed under the MIT license found in the
213
+ * LICENSE file in the root directory of this source tree.
214
+ *
215
+ */
216
+
116
217
  declare const HTMLElements: HTMLElementsMap;
117
218
 
219
+ /**
220
+ * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
221
+ * licensed under the Apache License, Version 2.0.
222
+ * Copyright (c) Adobe. All rights reserved.
223
+ * See: https://github.com/adobe/react-spectrum
224
+ *
225
+ * Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
226
+ *
227
+ * This file contains code licensed under:
228
+ * - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
229
+ * - The Apache License, Version 2.0 for portions from Adobe.
230
+ *
231
+ * Modifications have been made to adapt the code for use in this project.
232
+ */
233
+ /**
234
+ * Text selection state
235
+ */
236
+ type TextSelectionStates = 'default' | 'disabled' | 'restoring';
237
+
118
238
  /**
119
239
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
120
240
  * licensed under the Apache License, Version 2.0.
@@ -156,4 +276,97 @@ declare function disableTextSelection(target?: Element): void;
156
276
  */
157
277
  declare function restoreTextSelection(target?: Element): void;
158
278
 
159
- export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, getScrollableElements, isNode, nodeContains, restoreTextSelection, runAfterTransition, supportsPreventScroll };
279
+ /**
280
+ * Copyright (c) Corinvo, LLC. and affiliates.
281
+ *
282
+ * This source code is licensed under the MIT license found in the
283
+ * LICENSE file in the root directory of this source tree.
284
+ *
285
+ */
286
+
287
+ /**
288
+ * Type representing valid ARIA attribute values (e.g., 'aria-pressed', 'aria-disabled').
289
+ */
290
+ type AriaAttribute = (typeof DOM.ARIA_ATTRIBUTES)[number];
291
+
292
+ /**
293
+ * Copyright (c) Corinvo, LLC. and affiliates.
294
+ *
295
+ * This source code is licensed under the MIT license found in the
296
+ * LICENSE file in the root directory of this source tree.
297
+ *
298
+ */
299
+ /**
300
+ * All valid ARIA attribute names as constants.
301
+ * Use: AriaProps.Pressed → 'aria-pressed'
302
+ *
303
+ * @example
304
+ * ```tsx
305
+ * import { AriaProps } from '@necto/dom';
306
+ *
307
+ * const props = {
308
+ * [AriaProps.Pressed]: isSelected,
309
+ * [AriaProps.Disabled]: isDisabled
310
+ * };
311
+ * ```
312
+ */
313
+ declare const AriaProps: Record<string, string>;
314
+ /**
315
+ * Array of all ARIA attribute values.
316
+ * Useful for filterDOMProps or validation.
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * filterDOMProps(props, {
321
+ * extraAllowedProps: new Set([...ALLOWED_EXTERNAL_PROPS, ...ALL_ARIA_PROPS])
322
+ * });
323
+ * ```
324
+ */
325
+ declare const ALL_ARIA_PROPS: readonly string[];
326
+ /**
327
+ * Set of all ARIA attribute values for O(1) lookup.
328
+ */
329
+ declare const ARIA_PROPS_SET: Set<string>;
330
+ /**
331
+ * Checks if a string is a valid ARIA attribute.
332
+ * @param prop - The property name to check.
333
+ * @returns True if the property is a valid ARIA attribute.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * isAriaAttribute('aria-pressed'); // true
338
+ * isAriaAttribute('aria-invalid'); // true
339
+ * isAriaAttribute('data-foo'); // false
340
+ * isAriaAttribute('onClick'); // false
341
+ * ```
342
+ */
343
+ declare const isAriaAttribute: (prop: string) => boolean;
344
+ /**
345
+ * Checks if a string starts with 'aria-' prefix.
346
+ * This is a quick check that doesn't validate against the full list.
347
+ * @param prop - The property name to check.
348
+ * @returns True if the property starts with 'aria-'.
349
+ */
350
+ declare const hasAriaPrefix: (prop: string) => boolean;
351
+
352
+ /**
353
+ * Copyright (c) Corinvo, LLC. and affiliates.
354
+ *
355
+ * This source code is licensed under the MIT license found in the
356
+ * LICENSE file in the root directory of this source tree.
357
+ */
358
+
359
+ /**
360
+ * Injects width and height attributes into an SVG string
361
+ */
362
+ declare function injectSvgDimensions(svg: string, width?: string | number, height?: string | number): string;
363
+ /**
364
+ * Checks if an element is an SVG element
365
+ */
366
+ declare function isSvgElement(element: Element): element is SVGElement;
367
+ /**
368
+ * Checks if an element is a specific HTML element type
369
+ */
370
+ declare function isElementType<K extends keyof HTMLElementTagNameMap>(element: Element, tagName: K): element is HTMLElementTagNameMap[K];
371
+
372
+ 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 };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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};
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(){if(null==o){o=!1;try{document.createElement("div").focus({get preventScroll(){return o=!0,!0}})}catch{}}return o}function i(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,f=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||f){let t=e.scrollLeft;if("start"===r||"nearest"===r&&a)t=e.scrollLeft+(l.left-i.left);else if("end"===r||"nearest"===r&&f)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 l(e,t){const{containingElement:n}=t??{};e.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"}),n&&n.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"})}function c(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function s(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function a(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:c(o)?o.host:o.parentNode}return!1}var f=(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}function d(e){if(r())e.focus({preventScroll:!0});else{const t=m(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}function m(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}var p="necto-style",g=new WeakMap;function h(e){let t=g.get(e);return t||(t=new Map,g.set(e,t)),t}function w(e,n={}){const{id:o=p,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 y(e,t={}){const{id:n=p,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=h(o),l=`${n}:${e}`;let c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:w(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 E(e){e.remove()}function T(e,o){if(e&&s(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 b=new Map,v=new Set;function S(e){if(!("propertyName"in e)||!e.target)return;let t=b.get(e.target);t||(t=new Set,b.set(e.target,t),e.target.addEventListener("transitioncancel",L,{once:!0})),t.add(e.propertyName)}function L(e){if(!("propertyName"in e)||!e.target)return;const t=b.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",L),b.delete(e.target)),0===b.size)){for(const e of v)e();v.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",S),e.addEventListener("transitionend",L))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function A(e){requestAnimationFrame(()=>{for(const[e]of b)"isConnected"in e&&!e.isConnected&&b.delete(e);0===b.size?e():v.add(e)})}import{DOM as C}from"@necto/constants";var N=C.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{});import{isIOS as M}from"@necto/platform";var k="",R="default",U=new WeakMap;function H(e){if(M()){if("default"===R){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(k=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",R="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";U.has(e)||(U.set(e,t[n]??""),t[n]="none")}}function W(e){if(M()){if("disabled"!==R)return;R="restoring",setTimeout(()=>{A(()=>{if("restoring"===R){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=k||""),k="",R="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&U.has(e)){const t=U.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),U.delete(e)}}import{DOM as B}from"@necto/constants";var I=B.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),V=B.ARIA_ATTRIBUTES,$=new Set(V),x=e=>$.has(e),D=e=>e.startsWith("aria-");import{isSvg as G,isSvgFast as O}from"@necto/file";function P(e,t="100%",n="100%"){return e.replace(/<svg([^>]*)>/,`<svg$1 width="${t}" height="${n}">`)}function _(e){return e instanceof SVGElement}function z(e,t){return e.tagName.toLowerCase()===t.toLowerCase()}export{V as ALL_ARIA_PROPS,$ as ARIA_PROPS_SET,I as AriaProps,N as HTMLElements,w as createStyleElement,H as disableTextSelection,d as focusWithoutScrolling,f as getActiveElement,T as getContainmentRect,u as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,m as getScrollableElements,h as getStyleMap,D as hasAriaPrefix,y as injectStyle,P as injectSvgDimensions,x as isAriaAttribute,z as isElementType,s as isNode,c as isShadowRoot,G as isSvgContent,_ as isSvgElement,O as isSvgFast,a as nodeContains,E as removeStyleElement,W as restoreTextSelection,A as runAfterTransition,i as scrollIntoView,l as scrollIntoViewport,r as supportsPreventScroll,e as toPx};
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@necto/dom",
3
- "version": "1.4.5",
3
+ "version": "1.5.0",
4
4
  "description": "Necto's library for providing helpers and tools to interact with the DOM.",
5
+ "scripts": {
6
+ "build": "tsup --minify terser"
7
+ },
5
8
  "author": "Corinvo OSS Team",
6
9
  "license": "MIT",
7
10
  "devDependencies": {
@@ -24,12 +27,10 @@
24
27
  }
25
28
  },
26
29
  "dependencies": {
27
- "html-tags": "^4.0.0",
28
- "@necto/constants": "1.4.3",
29
- "@necto/types": "1.3.0",
30
- "@necto/platform": "1.4.0"
31
- },
32
- "scripts": {
33
- "build": "tsup --minify terser"
30
+ "@necto/constants": "workspace:*",
31
+ "@necto/file": "workspace:*",
32
+ "@necto/types": "workspace:*",
33
+ "@necto/platform": "workspace:*",
34
+ "html-tags": "^4.0.0"
34
35
  }
35
- }
36
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.