@necto/dom 1.9.0 → 1.9.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 +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- 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:()=>
|
|
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:()=>x,ARIA_PROPS_SET:()=>I,AriaProps:()=>H,HTMLElements:()=>R,disableTextSelection:()=>_,focusWithoutScrolling:()=>y,getActiveElement:()=>g,getContainmentRect:()=>E,getEventTarget:()=>w,getOwnerDocument:()=>c,getOwnerWindow:()=>s,hasAriaPrefix:()=>j,injectStyle:()=>b,isAriaAttribute:()=>W,isNode:()=>m,nodeContains:()=>p,restoreTextSelection:()=>k,runAfterTransition:()=>O,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="data-style-id",T=new WeakMap;function b(e,t={}){const{id:n,insertionPoint:o,window:r=("undefined"!=typeof window?window:null)}=t;if(!r||!e)return()=>{};let i=T.get(r);i||(i=new Map,T.set(r,i));const l=`${n??"necto"}:${e}`;let s=i.get(l);if(s)s.element&&(s.element.textContent=e,s.count++);else{const t=o?c(o):"undefined"!=typeof document?document:null;if(!t)return()=>{};const r=`necto-<:${Math.random().toString(36).slice(2,9)}:>`,u=t.createElement("style");u.setAttribute("type","text/css"),u.setAttribute(h,r),n&&(u.id=n),u.textContent=e,o?t.head.insertBefore(u,o):t.head.appendChild(u),s={element:u,count:1},i.set(l,s)}return()=>{const e=i.get(l);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(l)))}}function E(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 S=new Map,v=new Set;function A(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",L,{once:!0})),t.add(e.propertyName)}function L(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",L),S.delete(e.target)),0===S.size)){for(const e of v)e();v.clear()}}if("undefined"!=typeof window&&"undefined"!=typeof document){const e=()=>{const e=document.body;e&&(e.addEventListener("transitionrun",A),e.addEventListener("transitionend",L))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function O(e){requestAnimationFrame(()=>{for(const[e]of S)"isConnected"in e&&!e.isConnected&&S.delete(e);0===S.size?e():v.add(e)})}var M=require("@necto/constants"),R=M.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"),P="",C="default",U=new WeakMap;function _(e){if((0,N.isIOS)()){if("default"===C){const t=c(e);void 0!==t?.documentElement?.style.webkitUserSelect&&(P=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none",C="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";U.has(e)||(U.set(e,t[n]??""),t[n]="none")}}function k(e){if((0,N.isIOS)()){if("disabled"!==C)return;C="restoring",setTimeout(()=>{O(()=>{if("restoring"===C){const t=c(e);"none"===t?.documentElement?.style.webkitUserSelect&&(t.documentElement.style.webkitUserSelect=P||""),P="",C="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&U.has(e)){const t=U.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),U.delete(e)}}var D=require("@necto/constants"),H=D.DOM.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),x=D.DOM.ARIA_ATTRIBUTES,I=new Set(x),W=e=>I.has(e),j=e=>e.startsWith("aria-");
|
package/dist/index.d.cts
CHANGED
|
@@ -97,6 +97,14 @@ interface InjectStyleOptions {
|
|
|
97
97
|
*
|
|
98
98
|
*/
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Injects a CSS string into the document head as a `<style>` element.
|
|
102
|
+
* Deduplicates by id + css content, reference-counted, and auto-removes when all consumers unmount.
|
|
103
|
+
*
|
|
104
|
+
* @param css - The CSS string to inject.
|
|
105
|
+
* @param options - Configuration options (id, window, insertionPoint).
|
|
106
|
+
* @returns A cleanup function that decrements the reference count and removes the style when no longer needed.
|
|
107
|
+
*/
|
|
100
108
|
declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
|
|
101
109
|
|
|
102
110
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -97,6 +97,14 @@ interface InjectStyleOptions {
|
|
|
97
97
|
*
|
|
98
98
|
*/
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Injects a CSS string into the document head as a `<style>` element.
|
|
102
|
+
* Deduplicates by id + css content, reference-counted, and auto-removes when all consumers unmount.
|
|
103
|
+
*
|
|
104
|
+
* @param css - The CSS string to inject.
|
|
105
|
+
* @param options - Configuration options (id, window, insertionPoint).
|
|
106
|
+
* @returns A cleanup function that decrements the reference count and removes the style when no longer needed.
|
|
107
|
+
*/
|
|
100
108
|
declare function injectStyle(css: string, options?: InjectStyleOptions): () => void;
|
|
101
109
|
|
|
102
110
|
/**
|
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 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,d=i.left<l.left,f=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(d||f){let t=e.scrollLeft;if("start"===r||"nearest"===r&&d)t=e.scrollLeft+(i.left-l.left);else if("end"===r||"nearest"===r&&f)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 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 f(e,t=!0){return t&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}function u(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(e,n={}){const{id:o,insertionPoint:r,window:l=("undefined"!=typeof window?window:null)}=n;if(!l||!e)return()=>{};let i=a.get(l);i||(i=new Map,a.set(l,i));const c=`${o??"necto"}:${e}`;let s=i.get(c);if(s)s.element&&(s.element.textContent=e,s.count++);else{const n=r?t(r):"undefined"!=typeof document?document:null;if(!n)return()=>{};const l=`necto-<:${Math.random().toString(36).slice(2,9)}:>`,d=n.createElement("style");d.setAttribute("type","text/css"),d.setAttribute("data-style-id",l),o&&(d.id=o),d.textContent=e,r?n.head.insertBefore(d,r):n.head.appendChild(d),s={element:d,count:1},i.set(c,s)}return()=>{const e=i.get(c);e?.element&&(e.count--,e.count<1&&(e.element.remove(),e.element=null,i.delete(c)))}}function p(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 g=new Map,w=new Set;function h(e){if(!("propertyName"in e)||!e.target)return;let t=g.get(e.target);t||(t=new Set,g.set(e.target,t),e.target.addEventListener("transitioncancel",y,{once:!0})),t.add(e.propertyName)}function y(e){if(!("propertyName"in e)||!e.target)return;const t=g.get(e.target);if(t&&(t.delete(e.propertyName),0===t.size&&(e.target.removeEventListener("transitioncancel",y),g.delete(e.target)),0===g.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",h),e.addEventListener("transitionend",y))};"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function E(e){requestAnimationFrame(()=>{for(const[e]of g)"isConnected"in e&&!e.isConnected&&g.delete(e);0===g.size?e():w.add(e)})}import{DOM as T}from"@necto/constants";var b=T.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 v="",L="default",A=new WeakMap;function M(e){if(S()){if("default"===L){const n=t(e);void 0!==n?.documentElement?.style.webkitUserSelect&&(v=n.documentElement.style.webkitUserSelect,n.documentElement.style.webkitUserSelect="none",L="disabled")}}else if(e instanceof HTMLElement||e instanceof SVGElement){const t=e.style,n="userSelect"in t?"userSelect":"webkitUserSelect";A.has(e)||(A.set(e,t[n]??""),t[n]="none")}}function N(e){if(S()){if("disabled"!==L)return;L="restoring",setTimeout(()=>{E(()=>{if("restoring"===L){const n=t(e);"none"===n?.documentElement?.style.webkitUserSelect&&(n.documentElement.style.webkitUserSelect=v||""),v="",L="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&A.has(e)){const t=A.get(e)??"",n=e.style,o="userSelect"in n?"userSelect":"webkitUserSelect";"none"===n[o]&&(n[o]=t),""===e.getAttribute("style")?.trim()&&e.removeAttribute("style"),A.delete(e)}}import{DOM as C}from"@necto/constants";var R=C.ARIA_ATTRIBUTES.reduce((e,t)=>(e[(e=>{const t=e.replace("aria-","");return t.charAt(0).toUpperCase()+t.slice(1)})(t)]=t,e),{}),U=C.ARIA_ATTRIBUTES,k=new Set(U),H=e=>k.has(e),W=e=>e.startsWith("aria-");export{U as ALL_ARIA_PROPS,k as ARIA_PROPS_SET,R as AriaProps,b as HTMLElements,M as disableTextSelection,u as focusWithoutScrolling,d as getActiveElement,p as getContainmentRect,f as getEventTarget,t as getOwnerDocument,n as getOwnerWindow,W as hasAriaPrefix,m as injectStyle,H as isAriaAttribute,c as isNode,s as nodeContains,N as restoreTextSelection,E as runAfterTransition,l as scrollIntoView,r as supportsPreventScroll,e as toPx};
|