@necto/dom 1.7.0 → 1.7.2

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,{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)}}
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i={};function l(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function c(e){return e?.ownerDocument??document}function s(e){return e&&"window"in e&&e.window===e?e:c(e).defaultView||window}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{ALL_ARIA_PROPS:()=>I,ARIA_PROPS_SET:()=>W,AriaProps:()=>D,HTMLElements:()=>P,disableTextSelection:()=>k,focusWithoutScrolling:()=>h,getActiveElement:()=>p,getContainmentRect:()=>S,getEventTarget:()=>g,getOwnerDocument:()=>c,getOwnerWindow:()=>s,hasAriaPrefix:()=>B,injectStyle:()=>E,isAriaAttribute:()=>j,isNode:()=>d,nodeContains:()=>m,restoreTextSelection:()=>H,runAfterTransition:()=>M,scrollIntoView:()=>u,toPx:()=>l}),module.exports=(e=i,((e,i,l,c)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let s of o(i))r.call(e,s)||s===l||t(e,s,{get:()=>i[s],enumerable:!(c=n(i,s))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a=null;function u(e,t,n){const{block:o="nearest",inline:r="nearest"}=n??{},i=e.getBoundingClientRect(),l=t.getBoundingClientRect(),c=l.top<i.top,s=l.bottom>i.bottom,a=l.left<i.left,u=l.right>i.right;if(c||s){let t=e.scrollTop;if("start"===o||"nearest"===o&&c)t=e.scrollTop+(l.top-i.top);else if("end"===o||"nearest"===o&&s)t=e.scrollTop+(l.bottom-i.bottom);else if("center"===o){const n=i.top+i.height/2,o=l.top+l.height/2;t=e.scrollTop+(o-n)}e.scrollTop=t}if(a||u){let t=e.scrollLeft;if("start"===r||"nearest"===r&&a)t=e.scrollLeft+(l.left-i.left);else if("end"===r||"nearest"===r&&u)t=e.scrollLeft+(l.right-i.right);else if("center"===r){const n=i.left+i.width/2,o=l.left+l.width/2;t=e.scrollLeft+(o-n)}e.scrollLeft=t}}function f(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function d(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function m(e,t,n=!0){if(!e||!t)return!1;if(!n)return e.contains(t);let o=t;for(;o;){if(o===e)return!0;o=o instanceof Element&&"SLOT"===o.tagName&&o.assignedSlot?o.assignedSlot.parentNode:f(o)?o.host:o.parentNode}return!1}var p=(e=document,t=!0)=>{if(!t)return e.activeElement;let n=e.activeElement;for(;n&&"shadowRoot"in n&&n.shadowRoot?.activeElement;)n=n.shadowRoot.activeElement;return n};function g(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function h(e){if(function(){if(null==a){a=!1;try{document.createElement("div").focus({get preventScroll(){return a=!0,!0}})}catch{}}return a}())e.focus({preventScroll:!0});else{const t=function(e){let t=e.parentNode;const n=Array.from({length:0}),o=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==o;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;o instanceof HTMLElement&&n.push({element:o,scrollTop:o.scrollTop,scrollLeft:o.scrollLeft});return n}(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}var w="necto-style-id",y="necto-style",T=new WeakMap;function b(e,t={}){const{id:n=y,insertionPoint:o}=t,r=o?c(o):document,i=r.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute(w,n),i.textContent=e,o?r.head.insertBefore(i,o):r.head.appendChild(i),i}function E(e,t={}){const{id:n=y,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=function(e){let t=T.get(e);return t||(t=new Map,T.set(e,t)),t}(o),l=`${n}:${e}`;let c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:b(e,{id:n,insertionPoint:r}),count:1},i.set(l,c)),()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}function S(e,t){if(e&&d(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=t?c(t):document,n=t?s(t):window;return{top:0,left:0,bottom:n.innerHeight||e.documentElement.clientHeight,right:n.innerWidth||e.documentElement.clientWidth}}}var v=new Map,A=new Set;function L(e){if(!("propertyName"in e)||!e.target)return;let t=v.get(e.target);t||(t=new Set,v.set(e.target,t),e.target.addEventListener("transitioncancel",O,{once:!0})),t.add(e.propertyName)}function O(e){if(!("propertyName"in e)||!e.target)return;const t=v.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",O),v.delete(e.target)),0===v.size)){for(const e of A)e();A.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",L),e.addEventListener("transitionend",O))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function M(e){requestAnimationFrame(()=>{for(const[e]of v)"isConnected"in e&&!e.isConnected&&v.delete(e);0===v.size?e():A.add(e)})}var R=require("@necto/constants"),P=R.DOM.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),N=require("@necto/platform"),C="",U="default",_=new WeakMap;function k(e){if((0,N.isIOS)()){if("default"===U){const t=c(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(C=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",U="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";_.has(e)||(_.set(e,t[n]??""),t[n]="none")}}function H(e){if((0,N.isIOS)()){if("disabled"!==U)return;U="restoring",setTimeout(()=>{M(()=>{if("restoring"===U){const t=c(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=C||""),C="",U="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&_.has(e)){const t=_.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),_.delete(e)}}var x=require("@necto/constants"),D=x.DOM.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),I=x.DOM.ARIA_ATTRIBUTES,W=new Set(I),j=e=>W.has(e),B=e=>e.startsWith("aria-");
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { FocusableElement, HTMLElementsMap } from '@necto/types';
2
+ import { DOM } from '@necto/constants';
2
3
 
3
4
  /**
4
5
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -15,10 +16,10 @@ declare function toPx(value?: number | string): string | undefined;
15
16
  * This source code is licensed under the MIT license found in the
16
17
  * LICENSE file in the root directory of this source tree.
17
18
  */
18
- /** Returns the ownerDocument of an element, or the global document. Returns undefined during SSR. */
19
- declare function getOwnerDocument(el: Element | null | undefined): Document | undefined;
20
- /** Returns the window object that owns an element. Returns undefined during SSR. */
21
- declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): (Window & typeof global) | undefined;
19
+ /** Returns the ownerDocument of an element, or the global document */
20
+ declare function getOwnerDocument(el: Element | null | undefined): Document;
21
+ /** Returns the window object that owns an element */
22
+ declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): Window & typeof global;
22
23
 
23
24
  /**
24
25
  * Scrolls an element into view within a scrollable container.
@@ -41,7 +42,7 @@ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLEleme
41
42
  */
42
43
  declare function isNode(value: unknown): value is Node;
43
44
  declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
44
- declare const getActiveElement: (doc?: Document | ShadowRoot, supportShadowDOM?: boolean) => Element | null;
45
+ declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
45
46
  declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
46
47
 
47
48
  /**
@@ -137,11 +138,6 @@ declare function runAfterTransition(callback: () => void): void;
137
138
  *
138
139
  */
139
140
 
140
- /**
141
- * Lazily-initialized mapping of capitalized HTML tag names to their original tag names.
142
- * Deferred to avoid module initialization order issues when bundlers split
143
- * `@necto/constants` and `@necto/dom` into separate chunks.
144
- */
145
141
  declare const HTMLElements: HTMLElementsMap;
146
142
 
147
143
  /**
@@ -185,4 +181,77 @@ declare function disableTextSelection(target?: Element): void;
185
181
  */
186
182
  declare function restoreTextSelection(target?: Element): void;
187
183
 
188
- export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, injectStyle, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
184
+ /**
185
+ * Copyright (c) Corinvo, LLC. and affiliates.
186
+ *
187
+ * This source code is licensed under the MIT license found in the
188
+ * LICENSE file in the root directory of this source tree.
189
+ *
190
+ */
191
+
192
+ /**
193
+ * Type representing valid ARIA attribute values (e.g., 'aria-pressed', 'aria-disabled').
194
+ */
195
+ type AriaAttribute = (typeof DOM.ARIA_ATTRIBUTES)[number];
196
+
197
+ /**
198
+ * Copyright (c) Corinvo, LLC. and affiliates.
199
+ *
200
+ * This source code is licensed under the MIT license found in the
201
+ * LICENSE file in the root directory of this source tree.
202
+ *
203
+ */
204
+ /**
205
+ * All valid ARIA attribute names as constants.
206
+ * Use: AriaProps.Pressed → 'aria-pressed'
207
+ *
208
+ * @example
209
+ * ```tsx
210
+ * import { AriaProps } from '@necto/dom';
211
+ *
212
+ * const props = {
213
+ * [AriaProps.Pressed]: isSelected,
214
+ * [AriaProps.Disabled]: isDisabled
215
+ * };
216
+ * ```
217
+ */
218
+ declare const AriaProps: Record<string, string>;
219
+ /**
220
+ * Array of all ARIA attribute values.
221
+ * Useful for filterDOMProps or validation.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * filterDOMProps(props, {
226
+ * extraAllowedProps: new Set([...ALLOWED_EXTERNAL_PROPS, ...ALL_ARIA_PROPS])
227
+ * });
228
+ * ```
229
+ */
230
+ declare const ALL_ARIA_PROPS: readonly string[];
231
+ /**
232
+ * Set of all ARIA attribute values for O(1) lookup.
233
+ */
234
+ declare const ARIA_PROPS_SET: Set<string>;
235
+ /**
236
+ * Checks if a string is a valid ARIA attribute.
237
+ * @param prop - The property name to check.
238
+ * @returns True if the property is a valid ARIA attribute.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * isAriaAttribute('aria-pressed'); // true
243
+ * isAriaAttribute('aria-invalid'); // true
244
+ * isAriaAttribute('data-foo'); // false
245
+ * isAriaAttribute('onClick'); // false
246
+ * ```
247
+ */
248
+ declare const isAriaAttribute: (prop: string) => boolean;
249
+ /**
250
+ * Checks if a string starts with 'aria-' prefix.
251
+ * This is a quick check that doesn't validate against the full list.
252
+ * @param prop - The property name to check.
253
+ * @returns True if the property starts with 'aria-'.
254
+ */
255
+ declare const hasAriaPrefix: (prop: string) => boolean;
256
+
257
+ export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, hasAriaPrefix, injectStyle, isAriaAttribute, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { FocusableElement, HTMLElementsMap } from '@necto/types';
2
+ import { DOM } from '@necto/constants';
2
3
 
3
4
  /**
4
5
  * Copyright (c) Corinvo, LLC. and affiliates.
@@ -15,10 +16,10 @@ declare function toPx(value?: number | string): string | undefined;
15
16
  * This source code is licensed under the MIT license found in the
16
17
  * LICENSE file in the root directory of this source tree.
17
18
  */
18
- /** Returns the ownerDocument of an element, or the global document. Returns undefined during SSR. */
19
- declare function getOwnerDocument(el: Element | null | undefined): Document | undefined;
20
- /** Returns the window object that owns an element. Returns undefined during SSR. */
21
- declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): (Window & typeof global) | undefined;
19
+ /** Returns the ownerDocument of an element, or the global document */
20
+ declare function getOwnerDocument(el: Element | null | undefined): Document;
21
+ /** Returns the window object that owns an element */
22
+ declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): Window & typeof global;
22
23
 
23
24
  /**
24
25
  * Scrolls an element into view within a scrollable container.
@@ -41,7 +42,7 @@ declare function scrollIntoView(scrollContainer: HTMLElement, element: HTMLEleme
41
42
  */
42
43
  declare function isNode(value: unknown): value is Node;
43
44
  declare function nodeContains(node: Node | null | undefined, otherNode: Node | null | undefined, supportShadowDOM?: boolean): boolean;
44
- declare const getActiveElement: (doc?: Document | ShadowRoot, supportShadowDOM?: boolean) => Element | null;
45
+ declare const getActiveElement: (doc?: Document, supportShadowDOM?: boolean) => Element | null;
45
46
  declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: boolean): Element;
46
47
 
47
48
  /**
@@ -137,11 +138,6 @@ declare function runAfterTransition(callback: () => void): void;
137
138
  *
138
139
  */
139
140
 
140
- /**
141
- * Lazily-initialized mapping of capitalized HTML tag names to their original tag names.
142
- * Deferred to avoid module initialization order issues when bundlers split
143
- * `@necto/constants` and `@necto/dom` into separate chunks.
144
- */
145
141
  declare const HTMLElements: HTMLElementsMap;
146
142
 
147
143
  /**
@@ -185,4 +181,77 @@ declare function disableTextSelection(target?: Element): void;
185
181
  */
186
182
  declare function restoreTextSelection(target?: Element): void;
187
183
 
188
- export { HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, injectStyle, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
184
+ /**
185
+ * Copyright (c) Corinvo, LLC. and affiliates.
186
+ *
187
+ * This source code is licensed under the MIT license found in the
188
+ * LICENSE file in the root directory of this source tree.
189
+ *
190
+ */
191
+
192
+ /**
193
+ * Type representing valid ARIA attribute values (e.g., 'aria-pressed', 'aria-disabled').
194
+ */
195
+ type AriaAttribute = (typeof DOM.ARIA_ATTRIBUTES)[number];
196
+
197
+ /**
198
+ * Copyright (c) Corinvo, LLC. and affiliates.
199
+ *
200
+ * This source code is licensed under the MIT license found in the
201
+ * LICENSE file in the root directory of this source tree.
202
+ *
203
+ */
204
+ /**
205
+ * All valid ARIA attribute names as constants.
206
+ * Use: AriaProps.Pressed → 'aria-pressed'
207
+ *
208
+ * @example
209
+ * ```tsx
210
+ * import { AriaProps } from '@necto/dom';
211
+ *
212
+ * const props = {
213
+ * [AriaProps.Pressed]: isSelected,
214
+ * [AriaProps.Disabled]: isDisabled
215
+ * };
216
+ * ```
217
+ */
218
+ declare const AriaProps: Record<string, string>;
219
+ /**
220
+ * Array of all ARIA attribute values.
221
+ * Useful for filterDOMProps or validation.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * filterDOMProps(props, {
226
+ * extraAllowedProps: new Set([...ALLOWED_EXTERNAL_PROPS, ...ALL_ARIA_PROPS])
227
+ * });
228
+ * ```
229
+ */
230
+ declare const ALL_ARIA_PROPS: readonly string[];
231
+ /**
232
+ * Set of all ARIA attribute values for O(1) lookup.
233
+ */
234
+ declare const ARIA_PROPS_SET: Set<string>;
235
+ /**
236
+ * Checks if a string is a valid ARIA attribute.
237
+ * @param prop - The property name to check.
238
+ * @returns True if the property is a valid ARIA attribute.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * isAriaAttribute('aria-pressed'); // true
243
+ * isAriaAttribute('aria-invalid'); // true
244
+ * isAriaAttribute('data-foo'); // false
245
+ * isAriaAttribute('onClick'); // false
246
+ * ```
247
+ */
248
+ declare const isAriaAttribute: (prop: string) => boolean;
249
+ /**
250
+ * Checks if a string starts with 'aria-' prefix.
251
+ * This is a quick check that doesn't validate against the full list.
252
+ * @param prop - The property name to check.
253
+ * @returns True if the property starts with 'aria-'.
254
+ */
255
+ declare const hasAriaPrefix: (prop: string) => boolean;
256
+
257
+ export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, HTMLElements, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, hasAriaPrefix, injectStyle, isAriaAttribute, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, toPx };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- function e(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function t(e){return e?.ownerDocument?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};
1
+ function e(e){if(void 0!==e)return"number"==typeof e?`${e}px`:e}function t(e){return e?.ownerDocument??document}function n(e){return e&&"window"in e&&e.window===e?e:t(e).defaultView||window}var o=null;function r(e,t,n){const{block:o="nearest",inline:r="nearest"}=n??{},i=e.getBoundingClientRect(),l=t.getBoundingClientRect(),c=l.top<i.top,s=l.bottom>i.bottom,f=l.left<i.left,a=l.right>i.right;if(c||s){let t=e.scrollTop;if("start"===o||"nearest"===o&&c)t=e.scrollTop+(l.top-i.top);else if("end"===o||"nearest"===o&&s)t=e.scrollTop+(l.bottom-i.bottom);else if("center"===o){const n=i.top+i.height/2,o=l.top+l.height/2;t=e.scrollTop+(o-n)}e.scrollTop=t}if(f||a){let t=e.scrollLeft;if("start"===r||"nearest"===r&&f)t=e.scrollLeft+(l.left-i.left);else if("end"===r||"nearest"===r&&a)t=e.scrollLeft+(l.right-i.right);else if("center"===r){const n=i.left+i.width/2,o=l.left+l.width/2;t=e.scrollLeft+(o-n)}e.scrollLeft=t}}function i(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function l(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function c(e,t,n=!0){if(!e||!t)return!1;if(!n)return e.contains(t);let o=t;for(;o;){if(o===e)return!0;o=o instanceof Element&&"SLOT"===o.tagName&&o.assignedSlot?o.assignedSlot.parentNode:i(o)?o.host:o.parentNode}return!1}var s=(e=document,t=!0)=>{if(!t)return e.activeElement;let n=e.activeElement;for(;n&&"shadowRoot"in n&&n.shadowRoot?.activeElement;)n=n.shadowRoot.activeElement;return n};function f(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function a(e){if(function(){if(null==o){o=!1;try{document.createElement("div").focus({get preventScroll(){return o=!0,!0}})}catch{}}return o}())e.focus({preventScroll:!0});else{const t=function(e){let t=e.parentNode;const n=Array.from({length:0}),o=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==o;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;o instanceof HTMLElement&&n.push({element:o,scrollTop:o.scrollTop,scrollLeft:o.scrollLeft});return n}(e);e.focus();for(const{element:e,scrollTop:n,scrollLeft:o}of t)e.scrollTop=n,e.scrollLeft=o}}var d="necto-style",u=new WeakMap;function m(e,n={}){const{id:o=d,insertionPoint:r}=n,i=r?t(r):document,l=i.createElement("style");return l.setAttribute("type","text/css"),l.setAttribute("necto-style-id",o),l.textContent=e,r?i.head.insertBefore(l,r):i.head.appendChild(l),l}function p(e,t={}){const{id:n=d,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const i=function(e){let t=u.get(e);return t||(t=new Map,u.set(e,t)),t}(o),l=`${n}:${e}`;let c=i.get(l);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:m(e,{id:n,insertionPoint:r}),count:1},i.set(l,c)),()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}function g(e,o){if(e&&l(e)){const t=e.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}{const e=o?t(o):document,r=o?n(o):window;return{top:0,left:0,bottom:r.innerHeight||e.documentElement.clientHeight,right:r.innerWidth||e.documentElement.clientWidth}}}var h=new Map,w=new Set;function y(e){if(!("propertyName"in e)||!e.target)return;let t=h.get(e.target);t||(t=new Set,h.set(e.target,t),e.target.addEventListener("transitioncancel",E,{once:!0})),t.add(e.propertyName)}function E(e){if(!("propertyName"in e)||!e.target)return;const t=h.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",E),h.delete(e.target)),0===h.size)){for(const e of w)e();w.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",y),e.addEventListener("transitionend",E))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function T(e){requestAnimationFrame(()=>{for(const[e]of h)"isConnected"in e&&!e.isConnected&&h.delete(e);0===h.size?e():w.add(e)})}import{DOM as b}from"@necto/constants";var v=b.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{});import{isIOS as S}from"@necto/platform";var L="",A="default",M=new WeakMap;function N(e){if(S()){if("default"===A){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(L=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",A="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";M.has(e)||(M.set(e,t[n]??""),t[n]="none")}}function C(e){if(S()){if("disabled"!==A)return;A="restoring",setTimeout(()=>{T(()=>{if("restoring"===A){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=L||""),L="",A="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&M.has(e)){const t=M.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),M.delete(e)}}import{DOM as R}from"@necto/constants";var U=R.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),k=R.ARIA_ATTRIBUTES,H=new Set(k),W=e=>H.has(e),B=e=>e.startsWith("aria-");export{k as ALL_ARIA_PROPS,H as ARIA_PROPS_SET,U as AriaProps,v as HTMLElements,N as disableTextSelection,a as focusWithoutScrolling,s as getActiveElement,g as getContainmentRect,f as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,B as hasAriaPrefix,p as injectStyle,W as isAriaAttribute,l as isNode,c as nodeContains,C as restoreTextSelection,T as runAfterTransition,r as scrollIntoView,e as toPx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@necto/dom",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
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,9 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "html-tags": "^4.0.0",
28
- "@necto/platform": "1.5.1",
29
28
  "@necto/constants": "1.4.4",
30
29
  "@necto/types": "1.3.1",
31
- "@necto/file": "1.0.0"
30
+ "@necto/platform": "1.5.1"
32
31
  },
33
32
  "scripts": {
34
33
  "build": "tsup --minify terser"