@data-slot/core 0.2.26 → 0.2.28
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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],n=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],r=new WeakMap;function i(e,t,n){if(typeof process<`u`&&process.env?.NODE_ENV===`production`)return;let i=r.get(e);i||(i=new Set,r.set(e,i)),!i.has(t)&&(i.add(t),console.warn(`[@data-slot] ${n}`))}function a(e){let t=`data-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}`,n=`data-${e}`;return t===n?[t]:[t,n]}function o(e,t){for(let n of a(t))if(e.hasAttribute(n))return e.getAttribute(n);return null}function s(e,t){return a(t).some(t=>e.hasAttribute(t))}const c=new Set([``,`true`,`1`,`yes`]),l=new Set([`false`,`0`,`no`]);function u(e,t){if(!s(e,t))return;let n=o(e,t);if(n===null)return;let r=n.toLowerCase();if(c.has(r))return!0;if(l.has(r))return!1;i(e,t,`Invalid boolean value "${n}" for data-${t}. Expected: true/false/1/0/yes/no or empty.`)}function d(e,t){let n=o(e,t);if(n===null||n===``)return;let r=Number(n);if(Number.isNaN(r)||!Number.isFinite(r)){i(e,t,`Invalid number value "${n}" for data-${t}.`);return}return r}function f(e,t){if(s(e,t))return o(e,t)??void 0}function p(e,t,n){let r=o(e,t);if(r!==null){if(n.includes(r))return r;i(e,t,`Invalid value "${r}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}let m=0;const
|
|
1
|
+
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],n=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],r=new WeakMap;function i(e,t,n){if(typeof process<`u`&&process.env?.NODE_ENV===`production`)return;let i=r.get(e);i||(i=new Set,r.set(e,i)),!i.has(t)&&(i.add(t),console.warn(`[@data-slot] ${n}`))}function a(e){let t=`data-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}`,n=`data-${e}`;return t===n?[t]:[t,n]}function o(e,t){for(let n of a(t))if(e.hasAttribute(n))return e.getAttribute(n);return null}function s(e,t){return a(t).some(t=>e.hasAttribute(t))}const c=new Set([``,`true`,`1`,`yes`]),l=new Set([`false`,`0`,`no`]);function u(e,t){if(!s(e,t))return;let n=o(e,t);if(n===null)return;let r=n.toLowerCase();if(c.has(r))return!0;if(l.has(r))return!1;i(e,t,`Invalid boolean value "${n}" for data-${t}. Expected: true/false/1/0/yes/no or empty.`)}function d(e,t){let n=o(e,t);if(n===null||n===``)return;let r=Number(n);if(Number.isNaN(r)||!Number.isFinite(r)){i(e,t,`Invalid number value "${n}" for data-${t}.`);return}return r}function f(e,t){if(s(e,t))return o(e,t)??void 0}function p(e,t,n){let r=o(e,t);if(r!==null){if(n.includes(r))return r;i(e,t,`Invalid value "${r}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}const m=new WeakMap;function h(e,t){return g(e,t,new Set)}function g(e,t,n){if(!t)return!1;let r=t instanceof Element?t:t.parentElement;if(!r)return!1;if(e.contains(r))return!0;let i=r;for(;i;){let t=m.get(i);if(t&&!n.has(t)&&(n.add(t),g(e,t,n)))return!0;i=i.parentElement}return!1}function _(e,t,n){if(n.portaled)return;let r=(t.ownerDocument??document)?.body;r&&(n.originalParent=e.parentNode,n.originalNextSibling=e.nextSibling,m.set(e,t),r.appendChild(e),n.portaled=!0)}function v(e,t){if(!t.portaled)return;m.delete(e);let n=t.originalParent,r=t.originalNextSibling;n&&n.isConnected?r&&r.parentNode===n?n.insertBefore(e,r):n.appendChild(e):e.remove(),t.portaled=!1,t.originalParent=null,t.originalNextSibling=null}let y=0;const b=(e,t)=>e.id||=`${t}-${++y}`,x=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},S=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,b(t,`title`)),n&&e.setAttribute(`aria-describedby`,b(n,`desc`))};function C(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const w=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n})),T=(...e)=>t=>{for(let n of e){if(t.defaultPrevented)break;n?.(t)}};let E=0,D=``,O=``;function k(){if(E===0){let e=document.documentElement;D=e.style.overflow,O=e.style.scrollbarGutter,e.style.overflow=`hidden`,e.style.scrollbarGutter=`stable`}E++}function A(){if(E=Math.max(0,E-1),E===0){let e=document.documentElement;e.style.overflow=D,e.style.scrollbarGutter=O}}exports.composeHandlers=T,exports.containsWithPortals=h,exports.emit=w,exports.ensureId=b,exports.getDataBool=u,exports.getDataEnum=p,exports.getDataNumber=d,exports.getDataString=f,exports.getPart=e,exports.getParts=t,exports.getRoots=n,exports.linkLabelledBy=S,exports.lockScroll=k,exports.on=C,exports.portalToBody=_,exports.restorePortal=v,exports.setAria=x,exports.unlockScroll=A;
|
package/dist/index.d.cts
CHANGED
|
@@ -36,6 +36,16 @@ declare function getDataString(el: Element, key: string): string | undefined;
|
|
|
36
36
|
* - Absent or invalid → undefined
|
|
37
37
|
*/
|
|
38
38
|
declare function getDataEnum<T extends string>(el: Element, key: string, allowed: readonly T[]): T | undefined;
|
|
39
|
+
/** Check if target is inside root, including portaled descendants.
|
|
40
|
+
* Follows chained portal ownership for nested portals. */
|
|
41
|
+
declare function containsWithPortals(root: Element, target: Node | null): boolean;
|
|
42
|
+
interface PortalState {
|
|
43
|
+
originalParent: ParentNode | null;
|
|
44
|
+
originalNextSibling: ChildNode | null;
|
|
45
|
+
portaled: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare function portalToBody(el: Element, originRoot: Element, state: PortalState): void;
|
|
48
|
+
declare function restorePortal(el: Element, state: PortalState): void;
|
|
39
49
|
//#endregion
|
|
40
50
|
//#region src/aria.d.ts
|
|
41
51
|
/**
|
|
@@ -89,4 +99,4 @@ declare function unlockScroll(): void;
|
|
|
89
99
|
*/
|
|
90
100
|
|
|
91
101
|
//#endregion
|
|
92
|
-
export { composeHandlers, emit, ensureId, getDataBool, getDataEnum, getDataNumber, getDataString, getPart, getParts, getRoots, linkLabelledBy, lockScroll, on, setAria, unlockScroll };
|
|
102
|
+
export { type PortalState, composeHandlers, containsWithPortals, emit, ensureId, getDataBool, getDataEnum, getDataNumber, getDataString, getPart, getParts, getRoots, linkLabelledBy, lockScroll, on, portalToBody, restorePortal, setAria, unlockScroll };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,16 @@ declare function getDataString(el: Element, key: string): string | undefined;
|
|
|
36
36
|
* - Absent or invalid → undefined
|
|
37
37
|
*/
|
|
38
38
|
declare function getDataEnum<T extends string>(el: Element, key: string, allowed: readonly T[]): T | undefined;
|
|
39
|
+
/** Check if target is inside root, including portaled descendants.
|
|
40
|
+
* Follows chained portal ownership for nested portals. */
|
|
41
|
+
declare function containsWithPortals(root: Element, target: Node | null): boolean;
|
|
42
|
+
interface PortalState {
|
|
43
|
+
originalParent: ParentNode | null;
|
|
44
|
+
originalNextSibling: ChildNode | null;
|
|
45
|
+
portaled: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare function portalToBody(el: Element, originRoot: Element, state: PortalState): void;
|
|
48
|
+
declare function restorePortal(el: Element, state: PortalState): void;
|
|
39
49
|
//#endregion
|
|
40
50
|
//#region src/aria.d.ts
|
|
41
51
|
/**
|
|
@@ -89,4 +99,4 @@ declare function unlockScroll(): void;
|
|
|
89
99
|
*/
|
|
90
100
|
|
|
91
101
|
//#endregion
|
|
92
|
-
export { composeHandlers, emit, ensureId, getDataBool, getDataEnum, getDataNumber, getDataString, getPart, getParts, getRoots, linkLabelledBy, lockScroll, on, setAria, unlockScroll };
|
|
102
|
+
export { type PortalState, composeHandlers, containsWithPortals, emit, ensureId, getDataBool, getDataEnum, getDataNumber, getDataString, getPart, getParts, getRoots, linkLabelledBy, lockScroll, on, portalToBody, restorePortal, setAria, unlockScroll };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],n=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],r=new WeakMap;function i(e,t,n){if(typeof process<`u`&&process.env?.NODE_ENV===`production`)return;let i=r.get(e);i||(i=new Set,r.set(e,i)),!i.has(t)&&(i.add(t),console.warn(`[@data-slot] ${n}`))}function a(e){let t=`data-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}`,n=`data-${e}`;return t===n?[t]:[t,n]}function o(e,t){for(let n of a(t))if(e.hasAttribute(n))return e.getAttribute(n);return null}function s(e,t){return a(t).some(t=>e.hasAttribute(t))}const c=new Set([``,`true`,`1`,`yes`]),l=new Set([`false`,`0`,`no`]);function u(e,t){if(!s(e,t))return;let n=o(e,t);if(n===null)return;let r=n.toLowerCase();if(c.has(r))return!0;if(l.has(r))return!1;i(e,t,`Invalid boolean value "${n}" for data-${t}. Expected: true/false/1/0/yes/no or empty.`)}function d(e,t){let n=o(e,t);if(n===null||n===``)return;let r=Number(n);if(Number.isNaN(r)||!Number.isFinite(r)){i(e,t,`Invalid number value "${n}" for data-${t}.`);return}return r}function f(e,t){if(s(e,t))return o(e,t)??void 0}function p(e,t,n){let r=o(e,t);if(r!==null){if(n.includes(r))return r;i(e,t,`Invalid value "${r}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}let m=0;const
|
|
1
|
+
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],n=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],r=new WeakMap;function i(e,t,n){if(typeof process<`u`&&process.env?.NODE_ENV===`production`)return;let i=r.get(e);i||(i=new Set,r.set(e,i)),!i.has(t)&&(i.add(t),console.warn(`[@data-slot] ${n}`))}function a(e){let t=`data-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}`,n=`data-${e}`;return t===n?[t]:[t,n]}function o(e,t){for(let n of a(t))if(e.hasAttribute(n))return e.getAttribute(n);return null}function s(e,t){return a(t).some(t=>e.hasAttribute(t))}const c=new Set([``,`true`,`1`,`yes`]),l=new Set([`false`,`0`,`no`]);function u(e,t){if(!s(e,t))return;let n=o(e,t);if(n===null)return;let r=n.toLowerCase();if(c.has(r))return!0;if(l.has(r))return!1;i(e,t,`Invalid boolean value "${n}" for data-${t}. Expected: true/false/1/0/yes/no or empty.`)}function d(e,t){let n=o(e,t);if(n===null||n===``)return;let r=Number(n);if(Number.isNaN(r)||!Number.isFinite(r)){i(e,t,`Invalid number value "${n}" for data-${t}.`);return}return r}function f(e,t){if(s(e,t))return o(e,t)??void 0}function p(e,t,n){let r=o(e,t);if(r!==null){if(n.includes(r))return r;i(e,t,`Invalid value "${r}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}const m=new WeakMap;function h(e,t){return g(e,t,new Set)}function g(e,t,n){if(!t)return!1;let r=t instanceof Element?t:t.parentElement;if(!r)return!1;if(e.contains(r))return!0;let i=r;for(;i;){let t=m.get(i);if(t&&!n.has(t)&&(n.add(t),g(e,t,n)))return!0;i=i.parentElement}return!1}function _(e,t,n){if(n.portaled)return;let r=(t.ownerDocument??document)?.body;r&&(n.originalParent=e.parentNode,n.originalNextSibling=e.nextSibling,m.set(e,t),r.appendChild(e),n.portaled=!0)}function v(e,t){if(!t.portaled)return;m.delete(e);let n=t.originalParent,r=t.originalNextSibling;n&&n.isConnected?r&&r.parentNode===n?n.insertBefore(e,r):n.appendChild(e):e.remove(),t.portaled=!1,t.originalParent=null,t.originalNextSibling=null}let y=0;const b=(e,t)=>e.id||=`${t}-${++y}`,x=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},S=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,b(t,`title`)),n&&e.setAttribute(`aria-describedby`,b(n,`desc`))};function C(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const w=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n})),T=(...e)=>t=>{for(let n of e){if(t.defaultPrevented)break;n?.(t)}};let E=0,D=``,O=``;function k(){if(E===0){let e=document.documentElement;D=e.style.overflow,O=e.style.scrollbarGutter,e.style.overflow=`hidden`,e.style.scrollbarGutter=`stable`}E++}function A(){if(E=Math.max(0,E-1),E===0){let e=document.documentElement;e.style.overflow=D,e.style.scrollbarGutter=O}}export{T as composeHandlers,h as containsWithPortals,w as emit,b as ensureId,u as getDataBool,p as getDataEnum,d as getDataNumber,f as getDataString,e as getPart,t as getParts,n as getRoots,S as linkLabelledBy,k as lockScroll,C as on,_ as portalToBody,v as restorePortal,x as setAria,A as unlockScroll};
|