@necto/dom 1.7.3 → 1.9.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 +1 -1
- package/dist/index.d.cts +3 -11
- package/dist/index.d.ts +3 -11
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
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: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:()=>
|
|
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:()=>x,HTMLElements:()=>N,disableTextSelection:()=>k,focusWithoutScrolling:()=>y,getActiveElement:()=>g,getContainmentRect:()=>v,getEventTarget:()=>w,getOwnerDocument:()=>c,getOwnerWindow:()=>s,hasAriaPrefix:()=>V,injectStyle:()=>S,isAriaAttribute:()=>B,isNode:()=>m,nodeContains:()=>p,restoreTextSelection:()=>D,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=new WeakMap;function b(){return`ncto-<:${Math.random().toString(36).slice(2,9)}:>`}function E(e,t={}){const{id:n,internalId:o,insertionPoint:r}=t,i=r?c(r):"undefined"!=typeof document?document:null;if(!i)return null;const l=i.createElement("style");return l.setAttribute("type","text/css"),l.setAttribute(h,o??b()),n&&(l.id=n),l.textContent=e,r?i.head.insertBefore(l,r):i.head.appendChild(l),l}function S(e,t={}){const{id:n,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??"necto"}:${e}`;let c=i.get(l);if(c)c.element&&(c.element.textContent=e,c.count++);else{c={element:E(e,{id:n,internalId:b(),insertionPoint:r}),count:1},i.set(l,c)}return()=>{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="",I="default",_=new WeakMap;function k(e){if((0,C.isIOS)()){if("default"===I){const t=c(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(U=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",I="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 D(e){if((0,C.isIOS)()){if("disabled"!==I)return;I="restoring",setTimeout(()=>{P(()=>{if("restoring"===I){const t=c(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=U||""),U="",I="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 H=require("@necto/constants"),x=H.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=H.DOM.ARIA_ATTRIBUTES,j=new Set(W),B=e=>j.has(e),V=e=>e.startsWith("aria-");
|
package/dist/index.d.cts
CHANGED
|
@@ -82,19 +82,11 @@ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: bo
|
|
|
82
82
|
*/
|
|
83
83
|
declare function focusWithoutScrolling(element: FocusableElement): void;
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
88
|
-
* This source code is licensed under the MIT license found in the
|
|
89
|
-
* LICENSE file in the root directory of this source tree.
|
|
90
|
-
*
|
|
91
|
-
*/
|
|
92
|
-
interface CreateStyleElementOptions {
|
|
85
|
+
interface InjectStyleOptions {
|
|
86
|
+
/** User-facing HTML `id` attribute on the `<style>` element. */
|
|
93
87
|
id?: string;
|
|
94
|
-
insertionPoint?: HTMLElement | null;
|
|
95
|
-
}
|
|
96
|
-
interface InjectStyleOptions extends CreateStyleElementOptions {
|
|
97
88
|
window?: Window | null;
|
|
89
|
+
insertionPoint?: HTMLElement | null;
|
|
98
90
|
}
|
|
99
91
|
|
|
100
92
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -82,19 +82,11 @@ declare function getEventTarget<T extends Event>(event: T, supportShadowDOM?: bo
|
|
|
82
82
|
*/
|
|
83
83
|
declare function focusWithoutScrolling(element: FocusableElement): void;
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
88
|
-
* This source code is licensed under the MIT license found in the
|
|
89
|
-
* LICENSE file in the root directory of this source tree.
|
|
90
|
-
*
|
|
91
|
-
*/
|
|
92
|
-
interface CreateStyleElementOptions {
|
|
85
|
+
interface InjectStyleOptions {
|
|
86
|
+
/** User-facing HTML `id` attribute on the `<style>` element. */
|
|
93
87
|
id?: string;
|
|
94
|
-
insertionPoint?: HTMLElement | null;
|
|
95
|
-
}
|
|
96
|
-
interface InjectStyleOptions extends CreateStyleElementOptions {
|
|
97
88
|
window?: Window | null;
|
|
89
|
+
insertionPoint?: HTMLElement | null;
|
|
98
90
|
}
|
|
99
91
|
|
|
100
92
|
/**
|
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: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
|
|
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 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,d=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(d||u){let t=e.scrollLeft;if("start"===r||"nearest"===r&&d)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 l(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:l(o)?o.host:o.parentNode}return!1}var d=(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 u(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=new WeakMap;function m(){return`ncto-<:${Math.random().toString(36).slice(2,9)}:>`}function p(e,n={}){const{id:o,internalId:r,insertionPoint:i}=n,l=i?t(i):"undefined"!=typeof document?document:null;if(!l)return null;const c=l.createElement("style");return c.setAttribute("type","text/css"),c.setAttribute("necto-style-id",r??m()),o&&(c.id=o),c.textContent=e,i?l.head.insertBefore(c,i):l.head.appendChild(c),c}function g(e,t={}){const{id:n,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??"necto"}:${e}`;let c=i.get(l);if(c)c.element&&(c.element.textContent=e,c.count++);else{c={element:p(e,{id:n,internalId:m(),insertionPoint:r}),count:1},i.set(l,c)}return()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}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 S}from"@necto/constants";var v=S.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,v as HTMLElements,C as disableTextSelection,f as focusWithoutScrolling,d as getActiveElement,w as getContainmentRect,u 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,i as scrollIntoView,r as supportsPreventScroll,e as toPx};
|