@necto/dom 1.6.10 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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?e.ownerDocument:"undefined"!=typeof document?document:void 0}function s(e){if(e&&"window"in e&&e.window===e)return e;const t=c(e);return t?.defaultView?t.defaultView:"undefined"!=typeof window?window:void 0}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{ALL_ARIA_PROPS:()=>J,ARIA_PROPS_SET:()=>Q,AriaProps:()=>z,HTMLElements:()=>U,createStyleElement:()=>L,disableTextSelection:()=>W,focusWithoutScrolling:()=>h,getActiveElement:()=>w,getContainmentRect:()=>P,getEventTarget:()=>y,getOwnerDocument:()=>c,getOwnerWindow:()=>s,getScrollableElements:()=>v,getStyleMap:()=>T,hasAriaPrefix:()=>Y,injectStyle:()=>A,injectSvgDimensions:()=>ee,isAriaAttribute:()=>X,isElementType:()=>ne,isNode:()=>p,isShadowRoot:()=>m,isSvgContent:()=>Z.isSvg,isSvgElement:()=>te,isSvgFast:()=>Z.isSvgFast,nodeContains:()=>g,removeStyleElement:()=>O,restoreTextSelection:()=>B,runAfterTransition:()=>D,scrollIntoView:()=>a,scrollIntoViewport:()=>d,supportsPreventScroll:()=>f,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 u=null;function f(){if(null==u){u=!1;try{if("undefined"==typeof document)return!1;document.createElement("div").focus({get preventScroll(){return u=!0,!0}})}catch{}}return u}function a(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,u=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(u||f){let t=e.scrollLeft;if("start"===r||"nearest"===r&&u)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 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,t=!0)=>{if(e||(e="undefined"!=typeof document?document:void 0),!e)return null;if(!t)return e.activeElement;let n=e.activeElement;for(;n&&"shadowRoot"in n&&n.shadowRoot?.activeElement;)n=n.shadowRoot.activeElement;return n};function y(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function h(e){if(f())e.focus({preventScroll:!0});else{const t=v(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}function v(e){let t=e.parentNode;const n=Array.from({length:0}),o="undefined"!=typeof document?document.scrollingElement||document.documentElement:null;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 S="necto-style-id",b="necto-style",E=new WeakMap;function T(e){let t=E.get(e);return t||(t=new Map,E.set(e,t)),t}function L(e,t={}){const{id:n=b,insertionPoint:o}=t,r=o?c(o):"undefined"!=typeof document?document:void 0;if(!r)return null;const i=r.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute(S,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 c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:L(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 O(e){e.remove()}function P(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?c(t):"undefined"!=typeof document?document:void 0,n=t?s(t):"undefined"!=typeof window?window:void 0;return e&&n?{top:0,left:0,bottom:n.innerHeight||e.documentElement.clientHeight,right:n.innerWidth||e.documentElement.clientWidth}:{top:0,left:0,bottom:0,right:0}}}var R=new Map,M=new Set;function C(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 M)e();M.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",C),e.addEventListener("transitionend",N))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function D(e){requestAnimationFrame(()=>{for(const[e]of R)"isConnected"in e&&!e.isConnected&&R.delete(e);0===R.size?e():M.add(e)})}var x,k=require("@necto/constants"),I=()=>k.DOM.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),U=new Proxy({},{get:(e,t,n)=>(x||(x=I()),Reflect.get(x,t,n)),ownKeys:()=>(x||(x=I()),Reflect.ownKeys(x)),getOwnPropertyDescriptor:(e,t)=>(x||(x=I()),Object.getOwnPropertyDescriptor(x,t))}),j=require("@necto/platform"),_="",H="default",V=new WeakMap;function W(e){if((0,j.isIOS)()){if("default"===H){const t=c(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(_=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";V.has(e)||(V.set(e,t[n]??""),t[n]="none")}}function B(e){if((0,j.isIOS)()){if("disabled"!==H)return;H="restoring",setTimeout(()=>{D(()=>{if("restoring"===H){const t=c(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=_||""),_="",H="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&V.has(e)){const t=V.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),V.delete(e)}}var $,q,G,F=require("@necto/constants"),K=()=>{$||($=F.DOM.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),q=F.DOM.ARIA_ATTRIBUTES,G=new Set(q))},z=new Proxy({},{get:(e,t,n)=>(K(),Reflect.get($,t,n)),ownKeys:()=>(K(),Reflect.ownKeys($)),getOwnPropertyDescriptor:(e,t)=>(K(),Object.getOwnPropertyDescriptor($,t))}),J=new Proxy([],{get:(e,t,n)=>(K(),Reflect.get(q,t,n))}),Q=new Proxy(new Set,{get:(e,t,n)=>(K(),Reflect.get(G,t,n))}),X=e=>(K(),G.has(e)),Y=e=>e.startsWith("aria-"),Z=require("@necto/file");function ee(e,t="100%",n="100%"){return e.replace(/<svg([^>]*)>/,`<svg$1 width="${t}" height="${n}">`)}function te(e){return e instanceof SVGElement}function ne(e,t){return e.tagName.toLowerCase()===t.toLowerCase()}
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?e.ownerDocument:"undefined"!=typeof document?document:void 0}function s(e){if(e&&"window"in e&&e.window===e)return e;const t=c(e);return t?.defaultView?t.defaultView:"undefined"!=typeof window?window:void 0}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{HTMLElements:()=>R,disableTextSelection:()=>x,focusWithoutScrolling:()=>w,getActiveElement:()=>p,getContainmentRect:()=>T,getEventTarget:()=>g,getOwnerDocument:()=>c,getOwnerWindow:()=>s,injectStyle:()=>E,isNode:()=>a,nodeContains:()=>m,restoreTextSelection:()=>U,runAfterTransition:()=>N,scrollIntoView:()=>f,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 d=null;function f(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,d=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(d||f){let t=e.scrollLeft;if("start"===r||"nearest"===r&&d)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 u(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function a(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:u(o)?o.host:o.parentNode}return!1}var p=(e,t=!0)=>{if(e||(e="undefined"!=typeof document?document:void 0),!e)return null;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 w(e){if(function(){if(null==d){d=!1;try{if("undefined"==typeof document)return!1;document.createElement("div").focus({get preventScroll(){return d=!0,!0}})}catch{}}return d}())e.focus({preventScroll:!0});else{const t=function(e){let t=e.parentNode;const n=Array.from({length:0}),o="undefined"!=typeof document?document.scrollingElement||document.documentElement:null;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 y="necto-style-id",h="necto-style",b=new WeakMap;function v(e,t={}){const{id:n=h,insertionPoint:o}=t,r=o?c(o):"undefined"!=typeof document?document:void 0;if(!r)return null;const i=r.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute(y,n),i.textContent=e,o?r.head.insertBefore(i,o):r.head.appendChild(i),i}function E(e,t={}){const{id:n=h,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=function(e){let t=b.get(e);return t||(t=new Map,b.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:v(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 T(e,t){if(e&&a(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=t?c(t):"undefined"!=typeof document?document:void 0,n=t?s(t):"undefined"!=typeof window?window:void 0;return e&&n?{top:0,left:0,bottom:n.innerHeight||e.documentElement.clientHeight,right:n.innerWidth||e.documentElement.clientWidth}:{top:0,left:0,bottom:0,right:0}}}var S=new Map,L=new Set;function O(e){if(!("propertyName"in e)||!e.target)return;let t=S.get(e.target);t||(t=new Set,S.set(e.target,t),e.target.addEventListener("transitioncancel",M,{once:!0})),t.add(e.propertyName)}function M(e){if(!("propertyName"in e)||!e.target)return;const t=S.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",M),S.delete(e.target)),0===S.size)){for(const e of L)e();L.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",O),e.addEventListener("transitionend",M))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function N(e){requestAnimationFrame(()=>{for(const[e]of S)"isConnected"in e&&!e.isConnected&&S.delete(e);0===S.size?e():L.add(e)})}var C,P=require("@necto/constants"),A=()=>P.DOM.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),R=new Proxy({},{get:(e,t,n)=>(C||(C=A()),Reflect.get(C,t,n)),ownKeys:()=>(C||(C=A()),Reflect.ownKeys(C)),getOwnPropertyDescriptor:(e,t)=>(C||(C=A()),Object.getOwnPropertyDescriptor(C,t))}),k=require("@necto/platform"),D="",H="default",j=new WeakMap;function x(e){if((0,k.isIOS)()){if("default"===H){const t=c(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 U(e){if((0,k.isIOS)()){if("disabled"!==H)return;H="restoring",setTimeout(()=>{N(()=>{if("restoring"===H){const t=c(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)}}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { FocusableElement, HTMLElementsMap } from '@necto/types';
2
- import { DOM } from '@necto/constants';
3
- export { isSvg as isSvgContent, isSvgFast } from '@necto/file';
4
2
 
5
3
  /**
6
4
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -22,22 +20,6 @@ declare function getOwnerDocument(el: Element | null | undefined): Document | un
22
20
  /** Returns the window object that owns an element. Returns undefined during SSR. */
23
21
  declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): (Window & typeof global) | undefined;
24
22
 
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
23
  /**
42
24
  * Scrolls an element into view within a scrollable container.
43
25
  *
@@ -49,23 +31,6 @@ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLEleme
49
31
  block?: ScrollLogicalPosition;
50
32
  inline?: ScrollLogicalPosition;
51
33
  }): 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
34
 
70
35
  /**
71
36
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -79,32 +44,6 @@ declare function nodeContains(node: Node | null | undefined, otherNode: Node | n
79
44
  declare const getActiveElement: (doc?: Document | ShadowRoot, supportShadowDOM?: boolean) => Element | null;
80
45
  declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
81
46
 
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
47
  /**
109
48
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
110
49
  * licensed under the Apache License, Version 2.0.
@@ -127,14 +66,6 @@ interface ScrollableElement {
127
66
  * @param {FocusableElement} element - The element to focus.
128
67
  */
129
68
  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
69
 
139
70
  /**
140
71
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -147,11 +78,6 @@ interface CreateStyleElementOptions {
147
78
  id?: string;
148
79
  insertionPoint?: HTMLElement | null;
149
80
  }
150
- interface StyleEntry {
151
- element: HTMLStyleElement | null;
152
- count: number;
153
- }
154
- type StyleMap = Map<string, StyleEntry>;
155
81
  interface InjectStyleOptions extends CreateStyleElementOptions {
156
82
  window?: Window | null;
157
83
  }
@@ -164,10 +90,7 @@ interface InjectStyleOptions extends CreateStyleElementOptions {
164
90
  *
165
91
  */
166
92
 
167
- declare function getStyleMap(targetWindow: Window): StyleMap;
168
- declare function createStyleElement(css: string, options?: CreateStyleElementOptions): HTMLStyleElement;
169
93
  declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
170
- declare function removeStyleElement(element: HTMLStyleElement): void;
171
94
 
172
95
  /**
173
96
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -221,25 +144,6 @@ declare function runAfterTransition(callback: () => void): void;
221
144
  */
222
145
  declare const HTMLElements: HTMLElementsMap;
223
146
 
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
147
  /**
244
148
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
245
149
  * licensed under the Apache License, Version 2.0.
@@ -281,97 +185,4 @@ declare function disableTextSelection(target?: Element): void;
281
185
  */
282
186
  declare function restoreTextSelection(target?: Element): void;
283
187
 
284
- /**
285
- * Copyright (c) Corinvo, LLC. and affiliates.
286
- *
287
- * This source code is licensed under the MIT license found in the
288
- * LICENSE file in the root directory of this source tree.
289
- *
290
- */
291
-
292
- /**
293
- * Type representing valid ARIA attribute values (e.g., 'aria-pressed', 'aria-disabled').
294
- */
295
- type AriaAttribute = (typeof DOM.ARIA_ATTRIBUTES)[number];
296
-
297
- /**
298
- * Copyright (c) Corinvo, LLC. and affiliates.
299
- *
300
- * This source code is licensed under the MIT license found in the
301
- * LICENSE file in the root directory of this source tree.
302
- *
303
- */
304
- /**
305
- * All valid ARIA attribute names as constants.
306
- * Use: AriaProps.Pressed → 'aria-pressed'
307
- *
308
- * @example
309
- * ```tsx
310
- * import { AriaProps } from '@necto/dom';
311
- *
312
- * const props = {
313
- * [AriaProps.Pressed]: isSelected,
314
- * [AriaProps.Disabled]: isDisabled
315
- * };
316
- * ```
317
- */
318
- declare const AriaProps: Record<string, string>;
319
- /**
320
- * Array of all ARIA attribute values.
321
- * Useful for filterDOMProps or validation.
322
- *
323
- * @example
324
- * ```ts
325
- * filterDOMProps(props, {
326
- * extraAllowedProps: new Set([...ALLOWED_EXTERNAL_PROPS, ...ALL_ARIA_PROPS])
327
- * });
328
- * ```
329
- */
330
- declare const ALL_ARIA_PROPS: readonly string[];
331
- /**
332
- * Set of all ARIA attribute values for O(1) lookup.
333
- */
334
- declare const ARIA_PROPS_SET: Set<string>;
335
- /**
336
- * Checks if a string is a valid ARIA attribute.
337
- * @param prop - The property name to check.
338
- * @returns True if the property is a valid ARIA attribute.
339
- *
340
- * @example
341
- * ```ts
342
- * isAriaAttribute('aria-pressed'); // true
343
- * isAriaAttribute('aria-invalid'); // true
344
- * isAriaAttribute('data-foo'); // false
345
- * isAriaAttribute('onClick'); // false
346
- * ```
347
- */
348
- declare const isAriaAttribute: (prop: string) => boolean;
349
- /**
350
- * Checks if a string starts with 'aria-' prefix.
351
- * This is a quick check that doesn't validate against the full list.
352
- * @param prop - The property name to check.
353
- * @returns True if the property starts with 'aria-'.
354
- */
355
- declare const hasAriaPrefix: (prop: string) => boolean;
356
-
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 };
188
+ export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, injectStyle, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { FocusableElement, HTMLElementsMap } from '@necto/types';
2
- import { DOM } from '@necto/constants';
3
- export { isSvg as isSvgContent, isSvgFast } from '@necto/file';
4
2
 
5
3
  /**
6
4
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -22,22 +20,6 @@ declare function getOwnerDocument(el: Element | null | undefined): Document | un
22
20
  /** Returns the window object that owns an element. Returns undefined during SSR. */
23
21
  declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): (Window & typeof global) | undefined;
24
22
 
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
23
  /**
42
24
  * Scrolls an element into view within a scrollable container.
43
25
  *
@@ -49,23 +31,6 @@ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLEleme
49
31
  block?: ScrollLogicalPosition;
50
32
  inline?: ScrollLogicalPosition;
51
33
  }): 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
34
 
70
35
  /**
71
36
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -79,32 +44,6 @@ declare function nodeContains(node: Node | null | undefined, otherNode: Node | n
79
44
  declare const getActiveElement: (doc?: Document | ShadowRoot, supportShadowDOM?: boolean) => Element | null;
80
45
  declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
81
46
 
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
47
  /**
109
48
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
110
49
  * licensed under the Apache License, Version 2.0.
@@ -127,14 +66,6 @@ interface ScrollableElement {
127
66
  * @param {FocusableElement} element - The element to focus.
128
67
  */
129
68
  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
69
 
139
70
  /**
140
71
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -147,11 +78,6 @@ interface CreateStyleElementOptions {
147
78
  id?: string;
148
79
  insertionPoint?: HTMLElement | null;
149
80
  }
150
- interface StyleEntry {
151
- element: HTMLStyleElement | null;
152
- count: number;
153
- }
154
- type StyleMap = Map<string, StyleEntry>;
155
81
  interface InjectStyleOptions extends CreateStyleElementOptions {
156
82
  window?: Window | null;
157
83
  }
@@ -164,10 +90,7 @@ interface InjectStyleOptions extends CreateStyleElementOptions {
164
90
  *
165
91
  */
166
92
 
167
- declare function getStyleMap(targetWindow: Window): StyleMap;
168
- declare function createStyleElement(css: string, options?: CreateStyleElementOptions): HTMLStyleElement;
169
93
  declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
170
- declare function removeStyleElement(element: HTMLStyleElement): void;
171
94
 
172
95
  /**
173
96
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -221,25 +144,6 @@ declare function runAfterTransition(callback: () => void): void;
221
144
  */
222
145
  declare const HTMLElements: HTMLElementsMap;
223
146
 
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
147
  /**
244
148
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
245
149
  * licensed under the Apache License, Version 2.0.
@@ -281,97 +185,4 @@ declare function disableTextSelection(target?: Element): void;
281
185
  */
282
186
  declare function restoreTextSelection(target?: Element): void;
283
187
 
284
- /**
285
- * Copyright (c) Corinvo, LLC. and affiliates.
286
- *
287
- * This source code is licensed under the MIT license found in the
288
- * LICENSE file in the root directory of this source tree.
289
- *
290
- */
291
-
292
- /**
293
- * Type representing valid ARIA attribute values (e.g., 'aria-pressed', 'aria-disabled').
294
- */
295
- type AriaAttribute = (typeof DOM.ARIA_ATTRIBUTES)[number];
296
-
297
- /**
298
- * Copyright (c) Corinvo, LLC. and affiliates.
299
- *
300
- * This source code is licensed under the MIT license found in the
301
- * LICENSE file in the root directory of this source tree.
302
- *
303
- */
304
- /**
305
- * All valid ARIA attribute names as constants.
306
- * Use: AriaProps.Pressed → 'aria-pressed'
307
- *
308
- * @example
309
- * ```tsx
310
- * import { AriaProps } from '@necto/dom';
311
- *
312
- * const props = {
313
- * [AriaProps.Pressed]: isSelected,
314
- * [AriaProps.Disabled]: isDisabled
315
- * };
316
- * ```
317
- */
318
- declare const AriaProps: Record<string, string>;
319
- /**
320
- * Array of all ARIA attribute values.
321
- * Useful for filterDOMProps or validation.
322
- *
323
- * @example
324
- * ```ts
325
- * filterDOMProps(props, {
326
- * extraAllowedProps: new Set([...ALLOWED_EXTERNAL_PROPS, ...ALL_ARIA_PROPS])
327
- * });
328
- * ```
329
- */
330
- declare const ALL_ARIA_PROPS: readonly string[];
331
- /**
332
- * Set of all ARIA attribute values for O(1) lookup.
333
- */
334
- declare const ARIA_PROPS_SET: Set<string>;
335
- /**
336
- * Checks if a string is a valid ARIA attribute.
337
- * @param prop - The property name to check.
338
- * @returns True if the property is a valid ARIA attribute.
339
- *
340
- * @example
341
- * ```ts
342
- * isAriaAttribute('aria-pressed'); // true
343
- * isAriaAttribute('aria-invalid'); // true
344
- * isAriaAttribute('data-foo'); // false
345
- * isAriaAttribute('onClick'); // false
346
- * ```
347
- */
348
- declare const isAriaAttribute: (prop: string) => boolean;
349
- /**
350
- * Checks if a string starts with 'aria-' prefix.
351
- * This is a quick check that doesn't validate against the full list.
352
- * @param prop - The property name to check.
353
- * @returns True if the property starts with 'aria-'.
354
- */
355
- declare const hasAriaPrefix: (prop: string) => boolean;
356
-
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 };
188
+ export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, injectStyle, 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?e.ownerDocument:"undefined"!=typeof document?document:void 0}function n(e){if(e&&"window"in e&&e.window===e)return e;const n=t(e);return n?.defaultView?n.defaultView:"undefined"!=typeof window?window:void 0}var o=null;function r(){if(null==o){o=!1;try{if("undefined"==typeof document)return!1;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,f=l.left<i.left,d=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||d){let t=e.scrollLeft;if("start"===r||"nearest"===r&&f)t=e.scrollLeft+(l.left-i.left);else if("end"===r||"nearest"===r&&d)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 f(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 d=(e,t=!0)=>{if(e||(e="undefined"!=typeof document?document:void 0),!e)return null;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 a(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="undefined"!=typeof document?document.scrollingElement||document.documentElement:null;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 w(e){let t=g.get(e);return t||(t=new Map,g.set(e,t)),t}function y(e,n={}){const{id:o=p,insertionPoint:r}=n,i=r?t(r):"undefined"!=typeof document?document:void 0;if(!i)return null;const 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 h(e,t={}){const{id:n=p,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=w(o),l=`${n}:${e}`;let c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:y(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 v(e){e.remove()}function b(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):"undefined"!=typeof document?document:void 0,r=o?n(o):"undefined"!=typeof window?window:void 0;return e&&r?{top:0,left:0,bottom:r.innerHeight||e.documentElement.clientHeight,right:r.innerWidth||e.documentElement.clientWidth}:{top:0,left:0,bottom:0,right:0}}}var E=new Map,T=new Set;function S(e){if(!("propertyName"in e)||!e.target)return;let t=E.get(e.target);t||(t=new Set,E.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=E.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",L),E.delete(e.target)),0===E.size)){for(const e of T)e();T.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 R(e){requestAnimationFrame(()=>{for(const[e]of E)"isConnected"in e&&!e.isConnected&&E.delete(e);0===E.size?e():T.add(e)})}import{DOM as A}from"@necto/constants";var C,N=()=>A.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),M=new Proxy({},{get:(e,t,n)=>(C||(C=N()),Reflect.get(C,t,n)),ownKeys:()=>(C||(C=N()),Reflect.ownKeys(C)),getOwnPropertyDescriptor:(e,t)=>(C||(C=N()),Object.getOwnPropertyDescriptor(C,t))});import{isIOS as P}from"@necto/platform";var k="",U="default",O=new WeakMap;function D(e){if(P()){if("default"===U){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(k=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",U="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";O.has(e)||(O.set(e,t[n]??""),t[n]="none")}}function x(e){if(P()){if("disabled"!==U)return;U="restoring",setTimeout(()=>{R(()=>{if("restoring"===U){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=k||""),k="",U="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&O.has(e)){const t=O.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),O.delete(e)}}import{DOM as H}from"@necto/constants";var V,W,B,I=()=>{V||(V=H.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),W=H.ARIA_ATTRIBUTES,B=new Set(W))},$=new Proxy({},{get:(e,t,n)=>(I(),Reflect.get(V,t,n)),ownKeys:()=>(I(),Reflect.ownKeys(V)),getOwnPropertyDescriptor:(e,t)=>(I(),Object.getOwnPropertyDescriptor(V,t))}),G=new Proxy([],{get:(e,t,n)=>(I(),Reflect.get(W,t,n))}),_=new Proxy(new Set,{get:(e,t,n)=>(I(),Reflect.get(B,t,n))}),j=e=>(I(),B.has(e)),K=e=>e.startsWith("aria-");import{isSvg as z,isSvgFast as F}from"@necto/file";function q(e,t="100%",n="100%"){return e.replace(/<svg([^>]*)>/,`<svg$1 width="${t}" height="${n}">`)}function J(e){return e instanceof SVGElement}function Q(e,t){return e.tagName.toLowerCase()===t.toLowerCase()}export{G as ALL_ARIA_PROPS,_ as ARIA_PROPS_SET,$ as AriaProps,M as HTMLElements,y as createStyleElement,D as disableTextSelection,a as focusWithoutScrolling,d as getActiveElement,b as getContainmentRect,u as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,m as getScrollableElements,w as getStyleMap,K as hasAriaPrefix,h as injectStyle,q as injectSvgDimensions,j as isAriaAttribute,Q as isElementType,s as isNode,c as isShadowRoot,z as isSvgContent,J as isSvgElement,F as isSvgFast,f as nodeContains,v as removeStyleElement,x as restoreTextSelection,R as runAfterTransition,i as scrollIntoView,l as scrollIntoViewport,r as supportsPreventScroll,e as toPx};
1
+ function e(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function t(e){return e?.ownerDocument?e.ownerDocument:"undefined"!=typeof document?document:void 0}function n(e){if(e&&"window"in e&&e.window===e)return e;const n=t(e);return n?.defaultView?n.defaultView:"undefined"!=typeof window?window:void 0}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,d=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(d||f){let t=e.scrollLeft;if("start"===r||"nearest"===r&&d)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 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,t=!0)=>{if(e||(e="undefined"!=typeof document?document:void 0),!e)return null;if(!t)return e.activeElement;let n=e.activeElement;for(;n&&"shadowRoot"in n&&n.shadowRoot?.activeElement;)n=n.shadowRoot.activeElement;return n};function d(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function f(e){if(function(){if(null==o){o=!1;try{if("undefined"==typeof document)return!1;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="undefined"!=typeof document?document.scrollingElement||document.documentElement:null;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 u="necto-style",a=new WeakMap;function m(e,n={}){const{id:o=u,insertionPoint:r}=n,i=r?t(r):"undefined"!=typeof document?document:void 0;if(!i)return null;const 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=u,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=function(e){let t=a.get(e);return t||(t=new Map,a.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):"undefined"!=typeof document?document:void 0,r=o?n(o):"undefined"!=typeof window?window:void 0;return e&&r?{top:0,left:0,bottom:r.innerHeight||e.documentElement.clientHeight,right:r.innerWidth||e.documentElement.clientWidth}:{top:0,left:0,bottom:0,right:0}}}var w=new Map,y=new Set;function h(e){if(!("propertyName"in e)||!e.target)return;let t=w.get(e.target);t||(t=new Set,w.set(e.target,t),e.target.addEventListener("transitioncancel",v,{once:!0})),t.add(e.propertyName)}function v(e){if(!("propertyName"in e)||!e.target)return;const t=w.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",v),w.delete(e.target)),0===w.size)){for(const e of y)e();y.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",h),e.addEventListener("transitionend",v))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function E(e){requestAnimationFrame(()=>{for(const[e]of w)"isConnected"in e&&!e.isConnected&&w.delete(e);0===w.size?e():y.add(e)})}import{DOM as b}from"@necto/constants";var T,L=()=>b.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),S=new Proxy({},{get:(e,t,n)=>(T||(T=L()),Reflect.get(T,t,n)),ownKeys:()=>(T||(T=L()),Reflect.ownKeys(T)),getOwnPropertyDescriptor:(e,t)=>(T||(T=L()),Object.getOwnPropertyDescriptor(T,t))});import{isIOS as N}from"@necto/platform";var M="",C="default",k=new WeakMap;function R(e){if(N()){if("default"===C){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(M=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",C="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";k.has(e)||(k.set(e,t[n]??""),t[n]="none")}}function A(e){if(N()){if("disabled"!==C)return;C="restoring",setTimeout(()=>{E(()=>{if("restoring"===C){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=M||""),M="",C="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&k.has(e)){const t=k.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),k.delete(e)}}export{S as HTMLElements,R as disableTextSelection,f as focusWithoutScrolling,s as getActiveElement,g as getContainmentRect,d as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,p as injectStyle,l as isNode,c as nodeContains,A as restoreTextSelection,E 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.6.10",
3
+ "version": "1.7.0",
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",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "html-tags": "^4.0.0",
28
+ "@necto/platform": "1.5.1",
28
29
  "@necto/constants": "1.4.4",
29
- "@necto/file": "1.0.0",
30
30
  "@necto/types": "1.3.1",
31
- "@necto/platform": "1.5.1"
31
+ "@necto/file": "1.0.0"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup --minify terser"