@data-slot/toggle 0.2.31 → 0.2.33
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
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);function t(t,r={}){let i=r.defaultPressed??(0,e.getDataBool)(t,`defaultPressed`)??!1,a=r.disabled??(0,e.getDataBool)(t,`disabled`)??!1,o=r.onPressedChange,s=i,c=[],l=()=>t.hasAttribute(`disabled`)||t.getAttribute(`aria-disabled`)===`true`,u=(n,r=!1)=>{s===n&&!r||(s=n,(0,e.setAria)(t,`pressed`,s),t.dataset.state=s?`on`:`off`,r||((0,e.emit)(t,`toggle:change`,{pressed:s}),o?.(s)))};return a&&(t.tagName===`BUTTON`&&t.setAttribute(`disabled`,``),t.setAttribute(`aria-disabled`,`true`)),t.tagName===`BUTTON`&&!t.hasAttribute(`type`)&&t.setAttribute(`type`,`button`),u(s,!0),c.push((0,e.on)(t,`click`,()=>{l()||u(!s)})),c.push((0,e.on)(t,`toggle:set`,e=>{if(l())return;let t=e.detail,n;typeof t==`boolean`?n=t:t?.value===void 0?t?.pressed!==void 0&&(n=t.pressed):n=t.value,typeof n==`boolean`&&u(n)})),{toggle:()=>u(!s),press:()=>u(!0),release:()=>u(!1),get pressed(){return s},destroy:()=>{c.forEach(e=>e()),c.length=0,n.delete(t)}}}const n=new WeakSet;function r(r=document){let i=[];for(let a of(0,e.getRoots)(r,`toggle`))n.has(a)||(n.add(a),i.push(t(a)));return i}exports.create=r,exports.createToggle=t;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{emit as e,getDataBool as t,getRoots as n,on as r,setAria as i}from"@data-slot/core";function a(n,a={}){let s=a.defaultPressed??t(n,`defaultPressed`)??!1,c=a.disabled??t(n,`disabled`)??!1,l=a.onPressedChange,u=s,d=[],f=()=>n.hasAttribute(`disabled`)||n.getAttribute(`aria-disabled`)===`true`,p=(t,r=!1)=>{u===t&&!r||(u=t,i(n,`pressed`,u),n.dataset.state=u?`on`:`off`,r||(e(n,`toggle:change`,{pressed:u}),l?.(u)))};return c&&(n.tagName===`BUTTON`&&n.setAttribute(`disabled`,``),n.setAttribute(`aria-disabled`,`true`)),n.tagName===`BUTTON`&&!n.hasAttribute(`type`)&&n.setAttribute(`type`,`button`),p(u,!0),d.push(r(n,`click`,()=>{f()||p(!u)})),d.push(r(n,`toggle:set`,e=>{if(f())return;let t=e.detail,n;typeof t==`boolean`?n=t:t?.value===void 0?t?.pressed!==void 0&&(n=t.pressed):n=t.value,typeof n==`boolean`&&p(n)})),{toggle:()=>p(!u),press:()=>p(!0),release:()=>p(!1),get pressed(){return u},destroy:()=>{d.forEach(e=>e()),d.length=0,o.delete(n)}}}const o=new WeakSet;function s(e=document){let t=[];for(let r of n(e,`toggle`))
|
|
1
|
+
import{emit as e,getDataBool as t,getRoots as n,on as r,setAria as i}from"@data-slot/core";function a(n,a={}){let s=a.defaultPressed??t(n,`defaultPressed`)??!1,c=a.disabled??t(n,`disabled`)??!1,l=a.onPressedChange,u=s,d=[],f=()=>n.hasAttribute(`disabled`)||n.getAttribute(`aria-disabled`)===`true`,p=(t,r=!1)=>{u===t&&!r||(u=t,i(n,`pressed`,u),n.dataset.state=u?`on`:`off`,r||(e(n,`toggle:change`,{pressed:u}),l?.(u)))};return c&&(n.tagName===`BUTTON`&&n.setAttribute(`disabled`,``),n.setAttribute(`aria-disabled`,`true`)),n.tagName===`BUTTON`&&!n.hasAttribute(`type`)&&n.setAttribute(`type`,`button`),p(u,!0),d.push(r(n,`click`,()=>{f()||p(!u)})),d.push(r(n,`toggle:set`,e=>{if(f())return;let t=e.detail,n;typeof t==`boolean`?n=t:t?.value===void 0?t?.pressed!==void 0&&(n=t.pressed):n=t.value,typeof n==`boolean`&&p(n)})),{toggle:()=>p(!u),press:()=>p(!0),release:()=>p(!1),get pressed(){return u},destroy:()=>{d.forEach(e=>e()),d.length=0,o.delete(n)}}}const o=new WeakSet;function s(e=document){let t=[];for(let r of n(e,`toggle`))o.has(r)||(o.add(r),t.push(a(r)));return t}export{s as create,a as createToggle};
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|