@necto/dom 1.7.1 → 1.7.3

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/README.md CHANGED
@@ -0,0 +1,19 @@
1
+ <div align="center">
2
+ <a href="https://necto.dev">
3
+ <img alt="Necto Logo" src="https://avatars.githubusercontent.com/u/158605331?s=100&v=4">
4
+ </a>
5
+
6
+ <h2>Necto - DOM Library</h2>
7
+
8
+ <p>Necto's library for providing helpers and tools to interact with the DOM.</p>
9
+
10
+ <a aria-label="Corinvo" href="https://corinvo.github.io">
11
+ <img src="https://img.shields.io/badge/Made%20by-Corinvo-black.svg?style=for-the-badge&color=black">
12
+ </a>
13
+ <a href="https://www.npmjs.com/package/@necto/dom">
14
+ <img alt="NPM version" src="https://img.shields.io/npm/v/@necto/dom.svg?style=for-the-badge">
15
+ </a>
16
+ <a aria-label="License" href="https://github.com/corinvo/necto/blob/main/LICENSE">
17
+ <img src="https://img.shields.io/badge/License-MIT-97CA25.svg?style=for-the-badge">
18
+ </a>
19
+ </div>
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??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-");
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:null}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:null}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(i,{ALL_ARIA_PROPS:()=>W,ARIA_PROPS_SET:()=>j,AriaProps:()=>I,HTMLElements:()=>N,disableTextSelection:()=>D,focusWithoutScrolling:()=>y,getActiveElement:()=>g,getContainmentRect:()=>v,getEventTarget:()=>w,getOwnerDocument:()=>c,getOwnerWindow:()=>s,hasAriaPrefix:()=>V,injectStyle:()=>S,isAriaAttribute:()=>B,isNode:()=>m,nodeContains:()=>p,restoreTextSelection:()=>H,runAfterTransition:()=>P,scrollIntoView:()=>f,supportsPreventScroll:()=>d,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 d(){if(null==u&&(u=!1,"undefined"!=typeof document))try{document.createElement("div").focus({get preventScroll(){return u=!0,!0}})}catch{}return u}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,u=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(u||d){let t=e.scrollLeft;if("start"===r||"nearest"===r&&u)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 a(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}function m(e){return null!==e&&"object"==typeof e&&"nodeType"in e&&"number"==typeof e.nodeType}function p(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??null:a(o)?o.host:o.parentNode}return!1}var g=(e=("undefined"!=typeof document?document:null),t=!0)=>{if(!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 w(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function y(e){if(d())e.focus({preventScroll:!0});else{let t=e.parentNode;const n=[],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}),e.focus();for(const{element:e,scrollTop:t,scrollLeft:o}of n)e.scrollTop=t,e.scrollLeft=o}}var h="necto-style-id",T="necto-style",b=new WeakMap;function E(e,t={}){const{id:n=T,insertionPoint:o}=t,r=o?c(o):"undefined"!=typeof document?document:null;if(!r)return null;const i=r.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute(h,n),i.textContent=e,o?r.head.insertBefore(i,o):r.head.appendChild(i),i}function S(e,t={}){const{id:n=T,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:E(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,t){if(e&&m(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:null,n=t?s(t):"undefined"!=typeof window?window:null;return{top:0,left:0,bottom:n?.innerHeight||e?.documentElement?.clientHeight||0,right:n?.innerWidth||e?.documentElement?.clientWidth||0}}}var A=new Map,L=new Set;function O(e){if(!("propertyName"in e)||!e.target)return;let t=A.get(e.target);t||(t=new Set,A.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=A.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",M),A.delete(e.target)),0===A.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 P(e){requestAnimationFrame(()=>{for(const[e]of A)"isConnected"in e&&!e.isConnected&&A.delete(e);0===A.size?e():L.add(e)})}var R=require("@necto/constants"),N=R.DOM.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{}),C=require("@necto/platform"),U="",_="default",k=new WeakMap;function D(e){if((0,C.isIOS)()){if("default"===_){const t=c(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(U=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",_="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 H(e){if((0,C.isIOS)()){if("disabled"!==_)return;_="restoring",setTimeout(()=>{P(()=>{if("restoring"===_){const t=c(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=U||""),U="",_="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)}}var x=require("@necto/constants"),I=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),{}),W=x.DOM.ARIA_ATTRIBUTES,j=new Set(W),B=e=>j.has(e),V=e=>e.startsWith("aria-");
package/dist/index.d.cts CHANGED
@@ -21,6 +21,22 @@ declare function getOwnerDocument(el: Element | null | undefined): Document;
21
21
  /** Returns the window object that owns an element */
22
22
  declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): Window & typeof global;
23
23
 
24
+ /**
25
+ * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
26
+ * licensed under the Apache License, Version 2.0.
27
+ * Copyright (c) Adobe. All rights reserved.
28
+ * See: https://github.com/adobe/react-spectrum
29
+ *
30
+ * Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
31
+ *
32
+ * This file contains code licensed under:
33
+ * - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
34
+ * - The Apache License, Version 2.0 for portions from Adobe.
35
+ *
36
+ * Modifications have been made to adapt the code for use in this project.
37
+ */
38
+ /** Detects if the browser supports the preventScroll option in focus() */
39
+ declare function supportsPreventScroll(): boolean;
24
40
  /**
25
41
  * Scrolls an element into view within a scrollable container.
26
42
  *
@@ -63,8 +79,6 @@ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: bo
63
79
  /**
64
80
  * Focuses the given element without causing the page to scroll.
65
81
  * Uses the native preventScroll option if supported, otherwise manually restores scroll positions.
66
- *
67
- * @param {FocusableElement} element - The element to focus.
68
82
  */
69
83
  declare function focusWithoutScrolling(element: FocusableElement): void;
70
84
 
@@ -140,6 +154,25 @@ declare function runAfterTransition(callback: () => void): void;
140
154
 
141
155
  declare const HTMLElements: HTMLElementsMap;
142
156
 
157
+ /**
158
+ * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
159
+ * licensed under the Apache License, Version 2.0.
160
+ * Copyright (c) Adobe. All rights reserved.
161
+ * See: https://github.com/adobe/react-spectrum
162
+ *
163
+ * Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
164
+ *
165
+ * This file contains code licensed under:
166
+ * - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
167
+ * - The Apache License, Version 2.0 for portions from Adobe.
168
+ *
169
+ * Modifications have been made to adapt the code for use in this project.
170
+ */
171
+ /**
172
+ * Text selection state
173
+ */
174
+ type TextSelectionStates = 'default' | 'disabled' | 'restoring';
175
+
143
176
  /**
144
177
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
145
178
  * licensed under the Apache License, Version 2.0.
@@ -254,4 +287,4 @@ declare const isAriaAttribute: (prop: string) => boolean;
254
287
  */
255
288
  declare const hasAriaPrefix: (prop: string) => boolean;
256
289
 
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 };
290
+ export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, type ContainmentRect, HTMLElements, type TextSelectionStates, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, hasAriaPrefix, injectStyle, isAriaAttribute, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, supportsPreventScroll, toPx };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,22 @@ declare function getOwnerDocument(el: Element | null | undefined): Document;
21
21
  /** Returns the window object that owns an element */
22
22
  declare function getOwnerWindow(el: (Window & typeof global) | Element | null | undefined): Window & typeof global;
23
23
 
24
+ /**
25
+ * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
26
+ * licensed under the Apache License, Version 2.0.
27
+ * Copyright (c) Adobe. All rights reserved.
28
+ * See: https://github.com/adobe/react-spectrum
29
+ *
30
+ * Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
31
+ *
32
+ * This file contains code licensed under:
33
+ * - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
34
+ * - The Apache License, Version 2.0 for portions from Adobe.
35
+ *
36
+ * Modifications have been made to adapt the code for use in this project.
37
+ */
38
+ /** Detects if the browser supports the preventScroll option in focus() */
39
+ declare function supportsPreventScroll(): boolean;
24
40
  /**
25
41
  * Scrolls an element into view within a scrollable container.
26
42
  *
@@ -63,8 +79,6 @@ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: bo
63
79
  /**
64
80
  * Focuses the given element without causing the page to scroll.
65
81
  * Uses the native preventScroll option if supported, otherwise manually restores scroll positions.
66
- *
67
- * @param {FocusableElement} element - The element to focus.
68
82
  */
69
83
  declare function focusWithoutScrolling(element: FocusableElement): void;
70
84
 
@@ -140,6 +154,25 @@ declare function runAfterTransition(callback: () => void): void;
140
154
 
141
155
  declare const HTMLElements: HTMLElementsMap;
142
156
 
157
+ /**
158
+ * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
159
+ * licensed under the Apache License, Version 2.0.
160
+ * Copyright (c) Adobe. All rights reserved.
161
+ * See: https://github.com/adobe/react-spectrum
162
+ *
163
+ * Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
164
+ *
165
+ * This file contains code licensed under:
166
+ * - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
167
+ * - The Apache License, Version 2.0 for portions from Adobe.
168
+ *
169
+ * Modifications have been made to adapt the code for use in this project.
170
+ */
171
+ /**
172
+ * Text selection state
173
+ */
174
+ type TextSelectionStates = 'default' | 'disabled' | 'restoring';
175
+
143
176
  /**
144
177
  * Portions of this file are based on code from the React Aria Spectrum library by Adobe,
145
178
  * licensed under the Apache License, Version 2.0.
@@ -254,4 +287,4 @@ declare const isAriaAttribute: (prop: string) => boolean;
254
287
  */
255
288
  declare const hasAriaPrefix: (prop: string) => boolean;
256
289
 
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 };
290
+ export { ALL_ARIA_PROPS, ARIA_PROPS_SET, type AriaAttribute, AriaProps, type ContainmentRect, HTMLElements, type TextSelectionStates, disableTextSelection, focusWithoutScrolling, getActiveElement, getContainmentRect, getEventTarget, getOwnerDocument, getOwnerWindow, hasAriaPrefix, injectStyle, isAriaAttribute, isNode, nodeContains, restoreTextSelection, runAfterTransition, scrollIntoView, supportsPreventScroll, 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??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};
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:null}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:null}var o=null;function r(){if(null==o&&(o=!1,"undefined"!=typeof document))try{document.createElement("div").focus({get preventScroll(){return o=!0,!0}})}catch{}return o}function l(e,t,n){const{block:o="nearest",inline:r="nearest"}=n??{},l=e.getBoundingClientRect(),i=t.getBoundingClientRect(),c=i.top<l.top,s=i.bottom>l.bottom,u=i.left<l.left,d=i.right>l.right;if(c||s){let t=e.scrollTop;if("start"===o||"nearest"===o&&c)t=e.scrollTop+(i.top-l.top);else if("end"===o||"nearest"===o&&s)t=e.scrollTop+(i.bottom-l.bottom);else if("center"===o){const n=l.top+l.height/2,o=i.top+i.height/2;t=e.scrollTop+(o-n)}e.scrollTop=t}if(u||d){let t=e.scrollLeft;if("start"===r||"nearest"===r&&u)t=e.scrollLeft+(i.left-l.left);else if("end"===r||"nearest"===r&&d)t=e.scrollLeft+(i.right-l.right);else if("center"===r){const n=l.left+l.width/2,o=i.left+i.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 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??null:i(o)?o.host:o.parentNode}return!1}var u=(e=("undefined"!=typeof document?document:null),t=!0)=>{if(!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(r())e.focus({preventScroll:!0});else{let t=e.parentNode;const n=[],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}),e.focus();for(const{element:e,scrollTop:t,scrollLeft:o}of n)e.scrollTop=t,e.scrollLeft=o}}var a="necto-style",m=new WeakMap;function p(e,n={}){const{id:o=a,insertionPoint:r}=n,l=r?t(r):"undefined"!=typeof document?document:null;if(!l)return null;const i=l.createElement("style");return i.setAttribute("type","text/css"),i.setAttribute("necto-style-id",o),i.textContent=e,r?l.head.insertBefore(i,r):l.head.appendChild(i),i}function g(e,t={}){const{id:n=a,window:o=("undefined"!=typeof window?window:null),insertionPoint:r}=t;if(!o||!e)return()=>{};const l=function(e){let t=m.get(e);return t||(t=new Map,m.set(e,t)),t}(o),i=`${n}:${e}`;let c=l.get(i);return c?c.element&&(c.element.textContent=e,c.count++):(c={element:p(e,{id:n,insertionPoint:r}),count:1},l.set(i,c)),()=>{const e=l.get(i);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,l.delete(i)))}}function w(e,o){if(e&&c(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:null,r=o?n(o):"undefined"!=typeof window?window:null;return{top:0,left:0,bottom:r?.innerHeight||e?.documentElement?.clientHeight||0,right:r?.innerWidth||e?.documentElement?.clientWidth||0}}}var h=new Map,y=new Set;function E(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",T,{once:!0})),t.add(e.propertyName)}function T(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",T),h.delete(e.target)),0===h.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",E),e.addEventListener("transitionend",T))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function b(e){requestAnimationFrame(()=>{for(const[e]of h)"isConnected"in e&&!e.isConnected&&h.delete(e);0===h.size?e():y.add(e)})}import{DOM as v}from"@necto/constants";var S=v.HTML_TAGS.reduce((e,t)=>{var n;return e[(n=t,n.charAt(0).toUpperCase()+n.slice(1))]=t,e},{});import{isIOS as L}from"@necto/platform";var A="",M="default",N=new WeakMap;function C(e){if(L()){if("default"===M){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(A=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",M="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";N.has(e)||(N.set(e,t[n]??""),t[n]="none")}}function R(e){if(L()){if("disabled"!==M)return;M="restoring",setTimeout(()=>{b(()=>{if("restoring"===M){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=A||""),A="",M="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&N.has(e)){const t=N.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),N.delete(e)}}import{DOM as U}from"@necto/constants";var k=U.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),H=U.ARIA_ATTRIBUTES,W=new Set(H),B=e=>W.has(e),D=e=>e.startsWith("aria-");export{H as ALL_ARIA_PROPS,W as ARIA_PROPS_SET,k as AriaProps,S as HTMLElements,C as disableTextSelection,f as focusWithoutScrolling,u as getActiveElement,w as getContainmentRect,d as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,D as hasAriaPrefix,g as injectStyle,B as isAriaAttribute,c as isNode,s as nodeContains,R as restoreTextSelection,b as runAfterTransition,l as scrollIntoView,r as supportsPreventScroll,e as toPx};
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@necto/dom",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
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",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/nectoutil/NodeKit",
10
+ "directory": "packages/@necto/necto-dom"
11
+ },
7
12
  "devDependencies": {
8
13
  "@types/node": "^22.14.1",
9
14
  "tsup": "^8.4.0"
@@ -25,9 +30,8 @@
25
30
  },
26
31
  "dependencies": {
27
32
  "html-tags": "^4.0.0",
28
- "@necto/constants": "1.4.4",
33
+ "@necto/constants": "1.4.5",
29
34
  "@necto/types": "1.3.1",
30
- "@necto/file": "1.0.0",
31
35
  "@necto/platform": "1.5.1"
32
36
  },
33
37
  "scripts": {