Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/rating

Package Overview
Dependencies
Maintainers
1
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/rating - npm Package Compare versions

Comparing version 0.0.0-dev-20220412122925 to 0.0.0-dev-20220412160604

2

dist/index.js

@@ -1,2 +0,2 @@

var y=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var D=e=>y(e,"__esModule",{value:!0});var F=(e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!N.call(e,r)&&(n||r!=="default")&&y(e,r,{get:()=>t[r],enumerable:!(o=O(t,r))||o.enumerable});return e};var W=(e=>(t,n)=>e&&e.get(t)||(n=_(D({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var K={};F(K,{connect:()=>R,machine:()=>V});var d=e=>e?"":void 0;function b(e){let t=new Set;function n(o){let r=globalThis.requestAnimationFrame(o);t.add(()=>globalThis.cancelAnimationFrame(r))}return n(()=>n(e)),function(){t.forEach(function(o){o()})}}var G=(()=>{let e=0;return()=>(e++,e.toString(36))})();function E(e){var t;return(t=e==null?void 0:e.ownerDocument.defaultView)!=null?t:window}function x(e){var t;return(t=e.nativeEvent)!=null?t:e}function Y(e,t){var n;let{type:o,property:r}=t,a=E(e)[o==="input"?"HTMLInputElement":"HTMLTextAreaElement"].prototype;return(n=Object.getOwnPropertyDescriptor(a,r))!=null?n:{}}function L(e,t){var n;let o=E(e);if(!(e instanceof o.HTMLInputElement))return;(n=Y(e,{type:"input",property:"value"}).set)==null||n.call(e,t);let r=new o.Event("input",{bubbles:!0});e.dispatchEvent(r)}var Z=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");var k={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft",Home:"End",End:"Home"},U={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"};function P(e,t={}){var n;let{dir:o="ltr",orientation:r="horizontal"}=t,{key:a}=e;return a=(n=U[a])!=null?n:a,o==="rtl"&&r==="horizontal"&&a in k&&(a=k[a]),a}var Q=(()=>{let e=0;return()=>(e++,e.toString(36))})(),z=e=>Array.isArray(e),X=e=>!(e==null||typeof e!="object"||z(e)),j=e=>X(e)&&"touches"in e;var q={pageX:0,pageY:0,clientX:0,clientY:0};function A(e,t="page"){let n=j(e)?e.touches[0]||e.changedTouches[0]||q:e;return{x:n[`${t}X`],y:n[`${t}Y`]}}function T(e,t){let n=e.x-t.offsetLeft-t.clientLeft+t.scrollLeft,o=e.y-t.offsetTop-t.clientTop+t.scrollTop;return{point:{x:n,y:o},progress:{x:n/t.offsetWidth,y:o/t.offsetHeight}}}function B(e){return{button:e,label:e,input:e,output:e,element:e}}var I=B(e=>e);var M=e=>e;var ne=(()=>{let e=0;return()=>(e++,e.toString(36))})();var S=e=>e.button===0;var i={getDoc:e=>{var t;return(t=e.doc)!=null?t:document},getRootId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.root)!=null?n:`rating-${e.uid}`},getLabelId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.label)!=null?n:`rating-${e.uid}-label`},getInputId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.input)!=null?n:`rating-${e.uid}-input`},getItemGroupId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.itemGroup)!=null?n:`rating-${e.uid}-item-group`},getItemId:(e,t)=>{var n,o,r;return(r=(o=(n=e.ids)==null?void 0:n.item)==null?void 0:o.call(n,t))!=null?r:`rating-${e.uid}-star-${t}`},getItemGroupEl:e=>i.getDoc(e).getElementById(i.getItemGroupId(e)),getRadioEl:e=>{var t;return(t=i.getItemGroupEl(e))==null?void 0:t.querySelector(`[role=radio][aria-posinset='${Math.ceil(e.value)}']`)},getActiveEl:e=>i.getDoc(e).activeElement,getInputEl:e=>i.getDoc(e).getElementById(i.getInputId(e)),dispatchChangeEvent:e=>{let t=i.getInputEl(e);t&&L(t,e.value)}};function R(e,t,n=I){let o=e.context.isInteractive,r=e.context.value,a=e.context.disabled,C=e.context.messages,w={isHovering:e.context.isHovering,value:r,hoveredValue:e.context.hoveredValue,size:e.context.max,sizeArray:Array.from({length:e.context.max}).map((l,s)=>s+1),getRatingState(l){let s=e.context.isHovering?e.context.hoveredValue:e.context.value,c=Math.ceil(s)===l,p=l<=s||c,m=c&&Math.abs(s-l)===.5;return{isEqual:c,isValueEmpty:e.context.value===-1,isHighlighted:p,isHalf:m,isChecked:c||e.context.value===-1&&l===1}},rootProps:n.element({dir:e.context.dir,"data-part":"root",id:i.getRootId(e.context)}),inputProps:n.input({"data-part":"input",name:e.context.name,type:"text",hidden:!0,id:i.getInputId(e.context),value:e.context.value}),labelProps:n.element({"data-part":"label",id:i.getLabelId(e.context),"data-disabled":d(a)}),itemGroupProps:n.element({id:i.getItemGroupId(e.context),"data-part":"item-group",role:"radiogroup","aria-orientation":"horizontal","aria-labelledby":i.getLabelId(e.context),tabIndex:e.context.readonly?0:-1,"data-disabled":d(a),onPointerMove(){!o||t("GROUP_POINTER_OVER")},onPointerLeave(){!o||t("GROUP_POINTER_LEAVE")}}),getItemProps({index:l}){let{isHalf:s,isHighlighted:c,isChecked:p}=w.getRatingState(l),m=C.ratingValueText(l);return n.element({"data-part":"item",id:i.getItemId(e.context,l.toString()),role:"radio",tabIndex:a?void 0:p?0:-1,"aria-roledescription":"rating","aria-label":m,"aria-disabled":a,"data-disabled":d(a),"aria-readonly":e.context.readonly,"aria-setsize":e.context.max,"aria-checked":p,"aria-posinset":l,"data-highlighted":d(c),"data-half":d(s),onPointerDown(u){if(!o)return;let f=x(u);S(f)&&u.preventDefault()},onPointerMove(u){if(!o)return;let f=A(M(u)),{progress:g}=T(f,u.currentTarget),h=g.x<.5;t({type:"POINTER_OVER",index:l,isMidway:h})},onKeyDown(u){if(!o)return;let f={ArrowLeft(){t("ARROW_LEFT")},ArrowRight(){t("ARROW_RIGHT")},ArrowUp(){t("ARROW_LEFT")},ArrowDown(){t("ARROW_LEFT")},Space(){t({type:"SPACE",value:l})},Home(){t("HOME")},End(){t("END")}},g=P(u,e.context),h=f[g];h&&(u.preventDefault(),h(u))},onClick(){!o||t("CLICK")},onFocus(){!o||t("FOCUS")},onBlur(){!o||t("BLUR")}})}};return w}var v=require("@zag-js/core");var V=(0,v.createMachine)({id:"rating-machine",initial:"unknown",context:{name:"rating",max:5,dir:"ltr",uid:"",value:-1,initialValue:-1,hoveredValue:-1,disabled:!1,readonly:!1,messages:{ratingValueText:e=>`${e} stars`}},created:["roundValueIfNeeded"],watch:{allowHalf:["roundValueIfNeeded"],value:["invokeOnChange","dispatchChangeEvent"]},computed:{isInteractive:e=>!(e.disabled||e.readonly),isHovering:e=>e.hoveredValue>-1},states:{unknown:{on:{SETUP:{target:"idle",actions:["setupDocument","checkValue"]}}},idle:{entry:"clearHoveredValue",on:{GROUP_POINTER_OVER:"hover",FOCUS:"focus"}},focus:{on:{POINTER_OVER:{actions:"setHoveredValue"},GROUP_POINTER_LEAVE:{actions:"clearHoveredValue"},BLUR:"idle",SPACE:{guard:"isValueEmpty",actions:["setValue"]},CLICK:{actions:["setValue","focusActiveRadio"]},ARROW_LEFT:{actions:["setPrevValue","focusActiveRadio"]},ARROW_RIGHT:{actions:["setNextValue","focusActiveRadio"]},HOME:{actions:["setValueToMin","focusActiveRadio"]},END:{actions:["setValueToMax","focusActiveRadio"]}}},hover:{on:{POINTER_OVER:{actions:"setHoveredValue"},GROUP_POINTER_LEAVE:[{guard:"isRadioFocused",target:"focus",actions:"clearHoveredValue"},{target:"idle",actions:"clearHoveredValue"}],CLICK:{actions:["setValue","focusActiveRadio"]}}}}},{guards:{isInteractive:e=>!(e.disabled||e.readonly),isHoveredValueEmpty:e=>e.hoveredValue===-1,isValueEmpty:e=>e.value<=0,isRadioFocused:e=>{var t;return!!((t=i.getItemGroupEl(e))==null?void 0:t.contains(i.getActiveEl(e)))}},actions:{checkValue(e){e.initialValue=e.value},setupDocument(e,t){t.doc&&(e.doc=(0,v.ref)(t.doc)),e.uid=t.id},clearHoveredValue(e){e.hoveredValue=-1},focusActiveRadio(e){b(()=>{var t;return(t=i.getRadioEl(e))==null?void 0:t.focus()})},setPrevValue(e){let t=e.allowHalf?.5:1;e.value=Math.max(0,e.value-t)},setNextValue(e){let t=e.allowHalf?.5:1,n=e.value===-1?0:e.value;e.value=Math.min(e.max,n+t)},setValueToMin(e){e.value=1},setValueToMax(e){e.value=e.max},setValue(e,t){var n;e.value=(n=t.value)!=null?n:e.hoveredValue},setHoveredValue(e,t){let n=e.allowHalf&&t.isMidway,o=n?.5:0;e.dir==="rtl"&&(o=n?0:.5);let r=t.index-o;e.hoveredValue=r},dispatchChangeEvent(e,t){t.type!=="SETUP"&&i.dispatchChangeEvent(e)},invokeOnChange(e,t){var n;t.type!=="SETUP"&&((n=e.onChange)==null||n.call(e,{value:e.value}))},invokeOnHover(e){var t;(t=e.onHover)==null||t.call(e,{value:e.hoveredValue})},roundValueIfNeeded(e){e.allowHalf||(e.value=Math.round(e.value))}}});module.exports=W(K);
var y=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var D=e=>y(e,"__esModule",{value:!0});var F=(e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!N.call(e,r)&&(n||r!=="default")&&y(e,r,{get:()=>t[r],enumerable:!(o=O(t,r))||o.enumerable});return e};var W=(e=>(t,n)=>e&&e.get(t)||(n=_(D({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var K={};F(K,{connect:()=>R,machine:()=>V});var d=e=>e?"":void 0;function b(e){let t=new Set;function n(o){let r=globalThis.requestAnimationFrame(o);t.add(()=>globalThis.cancelAnimationFrame(r))}return n(()=>n(e)),function(){t.forEach(function(o){o()})}}var G=(()=>{let e=0;return()=>(e++,e.toString(36))})();function E(e){var t;return(t=e==null?void 0:e.ownerDocument.defaultView)!=null?t:window}function x(e){var t;return(t=e.nativeEvent)!=null?t:e}function Y(e,t){var n;let{type:o,property:r}=t,a=E(e)[o==="input"?"HTMLInputElement":"HTMLTextAreaElement"].prototype;return(n=Object.getOwnPropertyDescriptor(a,r))!=null?n:{}}function L(e,t){var n;let o=E(e);if(!(e instanceof o.HTMLInputElement))return;(n=Y(e,{type:"input",property:"value"}).set)==null||n.call(e,t);let r=new o.Event("input",{bubbles:!0});e.dispatchEvent(r)}var Z=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");var k={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft",Home:"End",End:"Home"},U={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"};function P(e,t={}){var n;let{dir:o="ltr",orientation:r="horizontal"}=t,{key:a}=e;return a=(n=U[a])!=null?n:a,o==="rtl"&&r==="horizontal"&&a in k&&(a=k[a]),a}var Q=(()=>{let e=0;return()=>(e++,e.toString(36))})(),z=e=>Array.isArray(e),X=e=>!(e==null||typeof e!="object"||z(e)),j=e=>X(e)&&"touches"in e;var q={pageX:0,pageY:0,clientX:0,clientY:0};function A(e,t="page"){let n=j(e)?e.touches[0]||e.changedTouches[0]||q:e;return{x:n[`${t}X`],y:n[`${t}Y`]}}function T(e,t){let n=e.x-t.offsetLeft-t.clientLeft+t.scrollLeft,o=e.y-t.offsetTop-t.clientTop+t.scrollTop;return{point:{x:n,y:o},progress:{x:n/t.offsetWidth,y:o/t.offsetHeight}}}function B(e){return{button:e,label:e,input:e,output:e,element:e}}var I=B(e=>e);var M=e=>e;var ne=(()=>{let e=0;return()=>(e++,e.toString(36))})();var S=e=>e.button===0;var i={getDoc:e=>{var t;return(t=e.doc)!=null?t:document},getRootId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.root)!=null?n:`rating-${e.uid}`},getLabelId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.label)!=null?n:`rating-${e.uid}-label`},getInputId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.input)!=null?n:`rating-${e.uid}-input`},getItemGroupId:e=>{var t,n;return(n=(t=e.ids)==null?void 0:t.itemGroup)!=null?n:`rating-${e.uid}-item-group`},getItemId:(e,t)=>{var n,o,r;return(r=(o=(n=e.ids)==null?void 0:n.item)==null?void 0:o.call(n,t))!=null?r:`rating-${e.uid}-star-${t}`},getItemGroupEl:e=>i.getDoc(e).getElementById(i.getItemGroupId(e)),getRadioEl:e=>{var t;return(t=i.getItemGroupEl(e))==null?void 0:t.querySelector(`[role=radio][aria-posinset='${Math.ceil(e.value)}']`)},getActiveEl:e=>i.getDoc(e).activeElement,getInputEl:e=>i.getDoc(e).getElementById(i.getInputId(e)),dispatchChangeEvent:e=>{let t=i.getInputEl(e);t&&L(t,e.value)}};function R(e,t,n=I){let o=e.context.isInteractive,r=e.context.value,a=e.context.disabled,C=e.context.messages,w={isHovering:e.context.isHovering,value:r,hoveredValue:e.context.hoveredValue,size:e.context.max,sizeArray:Array.from({length:e.context.max}).map((l,s)=>s+1),getRatingState(l){let s=e.context.isHovering?e.context.hoveredValue:e.context.value,c=Math.ceil(s)===l,p=l<=s||c,m=c&&Math.abs(s-l)===.5;return{isEqual:c,isValueEmpty:e.context.value===-1,isHighlighted:p,isHalf:m,isChecked:c||e.context.value===-1&&l===1}},rootProps:n.element({dir:e.context.dir,"data-part":"root",id:i.getRootId(e.context)}),inputProps:n.input({"data-part":"input",name:e.context.name,type:"text",hidden:!0,id:i.getInputId(e.context),value:e.context.value}),labelProps:n.element({"data-part":"label",id:i.getLabelId(e.context),"data-disabled":d(a)}),itemGroupProps:n.element({id:i.getItemGroupId(e.context),"data-part":"item-group",role:"radiogroup","aria-orientation":"horizontal","aria-labelledby":i.getLabelId(e.context),tabIndex:e.context.readonly?0:-1,"data-disabled":d(a),onPointerMove(){!o||t("GROUP_POINTER_OVER")},onPointerLeave(){!o||t("GROUP_POINTER_LEAVE")}}),getItemProps({index:l}){let{isHalf:s,isHighlighted:c,isChecked:p}=w.getRatingState(l),m=C.ratingValueText(l);return n.element({"data-part":"item",id:i.getItemId(e.context,l.toString()),role:"radio",tabIndex:a?void 0:p?0:-1,"aria-roledescription":"rating","aria-label":m,"aria-disabled":a,"data-disabled":d(a),"aria-readonly":e.context.readonly,"aria-setsize":e.context.max,"aria-checked":p,"aria-posinset":l,"data-highlighted":d(c),"data-half":d(s),onPointerDown(u){if(!o)return;let f=x(u);S(f)&&u.preventDefault()},onPointerMove(u){if(!o)return;let f=A(M(u)),{progress:g}=T(f,u.currentTarget),h=g.x<.5;t({type:"POINTER_OVER",index:l,isMidway:h})},onKeyDown(u){if(!o)return;let f={ArrowLeft(){t("ARROW_LEFT")},ArrowRight(){t("ARROW_RIGHT")},ArrowUp(){t("ARROW_LEFT")},ArrowDown(){t("ARROW_LEFT")},Space(){t({type:"SPACE",value:l})},Home(){t("HOME")},End(){t("END")}},g=P(u,e.context),h=f[g];h&&(u.preventDefault(),h(u))},onClick(){!o||t("CLICK")},onFocus(){!o||t("FOCUS")},onBlur(){!o||t("BLUR")}})}};return w}var v=require("@zag-js/core");var V=(0,v.createMachine)({id:"rating",initial:"unknown",context:{name:"rating",max:5,dir:"ltr",uid:"",value:-1,initialValue:-1,hoveredValue:-1,disabled:!1,readonly:!1,messages:{ratingValueText:e=>`${e} stars`}},created:["roundValueIfNeeded"],watch:{allowHalf:["roundValueIfNeeded"],value:["invokeOnChange","dispatchChangeEvent"]},computed:{isInteractive:e=>!(e.disabled||e.readonly),isHovering:e=>e.hoveredValue>-1},states:{unknown:{on:{SETUP:{target:"idle",actions:["setupDocument","checkValue"]}}},idle:{entry:"clearHoveredValue",on:{GROUP_POINTER_OVER:"hover",FOCUS:"focus"}},focus:{on:{POINTER_OVER:{actions:"setHoveredValue"},GROUP_POINTER_LEAVE:{actions:"clearHoveredValue"},BLUR:"idle",SPACE:{guard:"isValueEmpty",actions:["setValue"]},CLICK:{actions:["setValue","focusActiveRadio"]},ARROW_LEFT:{actions:["setPrevValue","focusActiveRadio"]},ARROW_RIGHT:{actions:["setNextValue","focusActiveRadio"]},HOME:{actions:["setValueToMin","focusActiveRadio"]},END:{actions:["setValueToMax","focusActiveRadio"]}}},hover:{on:{POINTER_OVER:{actions:"setHoveredValue"},GROUP_POINTER_LEAVE:[{guard:"isRadioFocused",target:"focus",actions:"clearHoveredValue"},{target:"idle",actions:"clearHoveredValue"}],CLICK:{actions:["setValue","focusActiveRadio"]}}}}},{guards:{isInteractive:e=>!(e.disabled||e.readonly),isHoveredValueEmpty:e=>e.hoveredValue===-1,isValueEmpty:e=>e.value<=0,isRadioFocused:e=>{var t;return!!((t=i.getItemGroupEl(e))==null?void 0:t.contains(i.getActiveEl(e)))}},actions:{checkValue(e){e.initialValue=e.value},setupDocument(e,t){t.doc&&(e.doc=(0,v.ref)(t.doc)),e.uid=t.id},clearHoveredValue(e){e.hoveredValue=-1},focusActiveRadio(e){b(()=>{var t;return(t=i.getRadioEl(e))==null?void 0:t.focus()})},setPrevValue(e){let t=e.allowHalf?.5:1;e.value=Math.max(0,e.value-t)},setNextValue(e){let t=e.allowHalf?.5:1,n=e.value===-1?0:e.value;e.value=Math.min(e.max,n+t)},setValueToMin(e){e.value=1},setValueToMax(e){e.value=e.max},setValue(e,t){var n;e.value=(n=t.value)!=null?n:e.hoveredValue},setHoveredValue(e,t){let n=e.allowHalf&&t.isMidway,o=n?.5:0;e.dir==="rtl"&&(o=n?0:.5);let r=t.index-o;e.hoveredValue=r},dispatchChangeEvent(e,t){t.type!=="SETUP"&&i.dispatchChangeEvent(e)},invokeOnChange(e,t){var n;t.type!=="SETUP"&&((n=e.onChange)==null||n.call(e,{value:e.value}))},invokeOnHover(e){var t;(t=e.onHover)==null||t.call(e,{value:e.hoveredValue})},roundValueIfNeeded(e){e.allowHalf||(e.value=Math.round(e.value))}}});module.exports=W(K);
//# sourceMappingURL=index.js.map
{
"name": "@zag-js/rating",
"version": "0.0.0-dev-20220412122925",
"version": "0.0.0-dev-20220412160604",
"description": "Core logic for the rating widget implemented as a state machine",

@@ -32,8 +32,8 @@ "keywords": [

"dependencies": {
"@zag-js/core": "^0.0.0-dev-20220412122925",
"@zag-js/dom-utils": "^0.0.0-dev-20220412122925",
"@zag-js/rect-utils": "^0.0.0-dev-20220412122925",
"@zag-js/types": "^0.0.0-dev-20220412122925",
"@zag-js/utils": "^0.0.0-dev-20220412122925"
"@zag-js/core": "^0.0.0-dev-20220412160604",
"@zag-js/dom-utils": "^0.0.0-dev-20220412160604",
"@zag-js/rect-utils": "^0.0.0-dev-20220412160604",
"@zag-js/types": "^0.0.0-dev-20220412160604",
"@zag-js/utils": "^0.0.0-dev-20220412160604"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc