@zag-js/color-picker 0.53.0 → 0.55.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.js CHANGED
@@ -1,2 +1,1430 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{anatomy:()=>anatomy,connect:()=>connect,machine:()=>machine,parse:()=>parse});module.exports=__toCommonJS(src_exports);var import_anatomy=require("@zag-js/anatomy");var anatomy=(0,import_anatomy.createAnatomy)("color-picker",["root","label","control","trigger","positioner","content","area","areaThumb","areaBackground","channelSlider","channelSliderTrack","channelSliderThumb","channelInput","transparencyGrid","swatchGroup","swatchTrigger","swatchIndicator","swatch","eyeDropperTrigger","formatTrigger","formatSelect"]);var parts=anatomy.build();var import_color_utils3=require("@zag-js/color-utils");var import_dom_event2=require("@zag-js/dom-event");var import_dom_query2=require("@zag-js/dom-query");var import_popper=require("@zag-js/popper");var import_dom_event=require("@zag-js/dom-event");var import_dom_query=require("@zag-js/dom-query");var dom=(0,import_dom_query.createScope)({getRootId:ctx=>ctx.ids?.root??`color-picker:${ctx.id}`,getLabelId:ctx=>ctx.ids?.label??`color-picker:${ctx.id}:label`,getHiddenInputId:ctx=>`color-picker:${ctx.id}:hidden-input`,getControlId:ctx=>ctx.ids?.control??`color-picker:${ctx.id}:control`,getTriggerId:ctx=>ctx.ids?.trigger??`color-picker:${ctx.id}:trigger`,getContentId:ctx=>ctx.ids?.content??`color-picker:${ctx.id}:content`,getPositionerId:ctx=>`color-picker:${ctx.id}:positioner`,getFormatSelectId:ctx=>`color-picker:${ctx.id}:format-select`,getAreaId:ctx=>ctx.ids?.area??`color-picker:${ctx.id}:area`,getAreaGradientId:ctx=>ctx.ids?.areaGradient??`color-picker:${ctx.id}:area-gradient`,getAreaThumbId:ctx=>ctx.ids?.areaThumb??`color-picker:${ctx.id}:area-thumb`,getChannelSliderId:(ctx,channel)=>ctx.ids?.channelSliderTrack?.(channel)??`color-picker:${ctx.id}:slider-track:${channel}`,getChannelSliderThumbId:(ctx,channel)=>ctx.ids?.channelSliderThumb?.(channel)??`color-picker:${ctx.id}:slider-thumb:${channel}`,getContentEl:ctx=>dom.getById(ctx,dom.getContentId(ctx)),getAreaThumbEl:ctx=>dom.getById(ctx,dom.getAreaThumbId(ctx)),getChannelSliderThumbEl:(ctx,channel)=>dom.getById(ctx,dom.getChannelSliderThumbId(ctx,channel)),getChannelInputEl:(ctx,channel)=>{return[...(0,import_dom_query.queryAll)(dom.getContentEl(ctx),`input[data-channel="${channel}"]`),...(0,import_dom_query.queryAll)(dom.getControlEl(ctx),`input[data-channel="${channel}"]`)]},getFormatSelectEl:ctx=>dom.getById(ctx,dom.getFormatSelectId(ctx)),getHiddenInputEl:ctx=>dom.getById(ctx,dom.getHiddenInputId(ctx)),getAreaEl:ctx=>dom.getById(ctx,dom.getAreaId(ctx)),getAreaValueFromPoint(ctx,point){const areaEl=dom.getAreaEl(ctx);if(!areaEl)return;const{percent}=(0,import_dom_event.getRelativePoint)(point,areaEl);return percent},getControlEl:ctx=>dom.getById(ctx,dom.getControlId(ctx)),getTriggerEl:ctx=>dom.getById(ctx,dom.getTriggerId(ctx)),getPositionerEl:ctx=>dom.getById(ctx,dom.getPositionerId(ctx)),getChannelSliderTrackEl:(ctx,channel)=>{return dom.getById(ctx,dom.getChannelSliderId(ctx,channel))},getChannelSliderValueFromPoint(ctx,point,channel){const trackEl=dom.getChannelSliderTrackEl(ctx,channel);if(!trackEl)return;const{percent}=(0,import_dom_event.getRelativePoint)(point,trackEl);return percent},getChannelInputEls:ctx=>{return[...(0,import_dom_query.queryAll)(dom.getContentEl(ctx),"input[data-channel]"),...(0,import_dom_query.queryAll)(dom.getControlEl(ctx),"input[data-channel]")]}});var import_color_utils=require("@zag-js/color-utils");function getChannelDisplayColor(color,channel){switch(channel){case"hue":return(0,import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);case"lightness":case"brightness":case"saturation":case"red":case"green":case"blue":return color.withChannelValue("alpha",1);case"alpha":{return color}default:throw new Error("Unknown color channel: "+channel)}}var import_color_utils2=require("@zag-js/color-utils");function getChannelValue(color,channel){if(channel==null)return"";if(channel==="hex"){return color.toString("hex")}if(channel==="css"){return color.toString("css")}if(channel in color){return color.getChannelValue(channel).toString()}const isHSL=color.getFormat()==="hsla";switch(channel){case"hue":return isHSL?color.toFormat("hsla").getChannelValue("hue").toString():color.toFormat("hsba").getChannelValue("hue").toString();case"saturation":return isHSL?color.toFormat("hsla").getChannelValue("saturation").toString():color.toFormat("hsba").getChannelValue("saturation").toString();case"lightness":return color.toFormat("hsla").getChannelValue("lightness").toString();case"brightness":return color.toFormat("hsba").getChannelValue("brightness").toString();case"red":case"green":case"blue":return color.toFormat("rgba").getChannelValue(channel).toString();default:return color.getChannelValue(channel).toString()}}function getChannelRange(color,channel){switch(channel){case"hex":const minColor=(0,import_color_utils2.parseColor)("#000000");const maxColor=(0,import_color_utils2.parseColor)("#FFFFFF");return{minValue:minColor.toHexInt(),maxValue:maxColor.toHexInt(),pageSize:10,step:1};case"css":return void 0;case"hue":case"saturation":case"lightness":return color.toFormat("hsla").getChannelRange(channel);case"brightness":return color.toFormat("hsba").getChannelRange(channel);case"red":case"green":case"blue":return color.toFormat("rgba").getChannelRange(channel);default:return color.getChannelRange(channel)}}function getSliderBackgroundDirection(orientation,dir){if(orientation==="vertical"){return"top"}else if(dir==="ltr"){return"right"}else{return"left"}}var getSliderBackground=props=>{const{channel,value,dir}=props;const bgDirection=getSliderBackgroundDirection(props.orientation,dir);const{minValue,maxValue}=value.getChannelRange(channel);switch(channel){case"hue":return`linear-gradient(to ${bgDirection}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;case"lightness":{let start=value.withChannelValue(channel,minValue).toString("css");let middle=value.withChannelValue(channel,(maxValue-minValue)/2).toString("css");let end=value.withChannelValue(channel,maxValue).toString("css");return`linear-gradient(to ${bgDirection}, ${start}, ${middle}, ${end})`}case"saturation":case"brightness":case"red":case"green":case"blue":case"alpha":{let start=value.withChannelValue(channel,minValue).toString("css");let end=value.withChannelValue(channel,maxValue).toString("css");return`linear-gradient(to ${bgDirection}, ${start}, ${end})`}default:throw new Error("Unknown color channel: "+channel)}};function connect(state,send,normalize){const value=state.context.value;const areaValue=state.context.areaValue;const valueAsString=state.context.valueAsString;const disabled=state.context.isDisabled;const interactive=state.context.isInteractive;const dragging=state.hasTag("dragging");const open=state.hasTag("open");const focused=state.hasTag("focused");const getAreaChannels=props=>{const channels=areaValue.getChannels();return{xChannel:props.xChannel??channels[1],yChannel:props.yChannel??channels[2]}};const currentPlacement=state.context.currentPlacement;const popperStyles=(0,import_popper.getPlacementStyles)({...state.context.positioning,placement:currentPlacement});function getSwatchTriggerState(props){const color=(0,import_color_utils3.normalizeColor)(props.value).toFormat(state.context.format);return{value:color,valueAsString:color.toString("hex"),checked:color.isEqual(value),disabled:props.disabled||!interactive}}return{dragging,open,valueAsString,value,setOpen(nextOpen){if(nextOpen===open)return;send({type:nextOpen?"OPEN":"CLOSE"})},setValue(value2){send({type:"VALUE.SET",value:(0,import_color_utils3.normalizeColor)(value2),src:"set-color"})},getChannelValue(channel){return getChannelValue(value,channel)},setChannelValue(channel,channelValue){const color=value.withChannelValue(channel,channelValue);send({type:"VALUE.SET",value:color,src:"set-channel"})},format:state.context.format,setFormat(format){const formatValue=value.toFormat(format);send({type:"VALUE.SET",value:formatValue,src:"set-format"})},alpha:value.getChannelValue("alpha"),setAlpha(alphaValue){const color=value.withChannelValue("alpha",alphaValue);send({type:"VALUE.SET",value:color,src:"set-alpha"})},rootProps:normalize.element({...parts.root.attrs,dir:state.context.dir,id:dom.getRootId(state.context),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),style:{"--value":value.toString("css")}}),labelProps:normalize.element({...parts.label.attrs,dir:state.context.dir,id:dom.getLabelId(state.context),htmlFor:dom.getHiddenInputId(state.context),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),"data-focus":(0,import_dom_query2.dataAttr)(focused),onClick(event){event.preventDefault();const inputEl=(0,import_dom_query2.query)(dom.getControlEl(state.context),"[data-channel=hex]");inputEl?.focus({preventScroll:true})}}),controlProps:normalize.element({...parts.control.attrs,id:dom.getControlId(state.context),dir:state.context.dir,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),"data-state":open?"open":"closed","data-focus":(0,import_dom_query2.dataAttr)(focused)}),triggerProps:normalize.button({...parts.trigger.attrs,id:dom.getTriggerId(state.context),dir:state.context.dir,disabled,"aria-label":`select color. current color is ${valueAsString}`,"aria-controls":dom.getContentId(state.context),"aria-labelledby":dom.getLabelId(state.context),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-readonly":(0,import_dom_query2.dataAttr)(state.context.readOnly),"data-placement":currentPlacement,"aria-expanded":(0,import_dom_query2.dataAttr)(open),"data-state":open?"open":"closed","data-focus":(0,import_dom_query2.dataAttr)(focused),type:"button",onClick(){if(!interactive)return;send({type:"TRIGGER.CLICK"})},onBlur(){if(!interactive)return;send({type:"TRIGGER.BLUR"})},style:{position:"relative"}}),positionerProps:normalize.element({...parts.positioner.attrs,id:dom.getPositionerId(state.context),dir:state.context.dir,style:popperStyles.floating}),contentProps:normalize.element({...parts.content.attrs,id:dom.getContentId(state.context),dir:state.context.dir,"data-placement":currentPlacement,"data-state":open?"open":"closed",hidden:!open}),getAreaProps(props={}){const{xChannel,yChannel}=getAreaChannels(props);const{areaStyles}=(0,import_color_utils3.getColorAreaGradient)(areaValue,{xChannel,yChannel,dir:state.context.dir});return normalize.element({...parts.area.attrs,id:dom.getAreaId(state.context),role:"group",onPointerDown(event){if(!interactive)return;if(!(0,import_dom_event2.isLeftClick)(event))return;if((0,import_dom_event2.isModifierKey)(event))return;const point=(0,import_dom_event2.getEventPoint)(event);const channel={xChannel,yChannel};send({type:"AREA.POINTER_DOWN",point,channel,id:"area"});event.preventDefault()},style:{position:"relative",touchAction:"none",forcedColorAdjust:"none",...areaStyles}})},getAreaBackgroundProps(props={}){const{xChannel,yChannel}=getAreaChannels(props);const{areaGradientStyles}=(0,import_color_utils3.getColorAreaGradient)(areaValue,{xChannel,yChannel,dir:state.context.dir});return normalize.element({...parts.areaBackground.attrs,id:dom.getAreaGradientId(state.context),style:{position:"relative",touchAction:"none",forcedColorAdjust:"none",...areaGradientStyles}})},getAreaThumbProps(props={}){const{xChannel,yChannel}=getAreaChannels(props);const channel={xChannel,yChannel};const xPercent=areaValue.getChannelValuePercent(xChannel);const yPercent=1-areaValue.getChannelValuePercent(yChannel);const xValue=areaValue.getChannelValue(xChannel);const yValue=areaValue.getChannelValue(yChannel);return normalize.element({...parts.areaThumb.attrs,id:dom.getAreaThumbId(state.context),dir:state.context.dir,tabIndex:disabled?void 0:0,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),role:"slider","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":xValue,"aria-label":`${xChannel} and ${yChannel}`,"aria-roledescription":"2d slider","aria-valuetext":`${xChannel} ${xValue}, ${yChannel} ${yValue}`,style:{position:"absolute",left:`${xPercent*100}%`,top:`${yPercent*100}%`,transform:"translate(-50%, -50%)",touchAction:"none",forcedColorAdjust:"none",background:areaValue.withChannelValue("alpha",1).toString("css")},onFocus(){if(!interactive)return;send({type:"AREA.FOCUS",id:"area",channel})},onKeyDown(event){if(event.defaultPrevented)return;if(!interactive)return;const step=(0,import_dom_event2.getEventStep)(event);const keyMap={ArrowUp(){send({type:"AREA.ARROW_UP",channel,step})},ArrowDown(){send({type:"AREA.ARROW_DOWN",channel,step})},ArrowLeft(){send({type:"AREA.ARROW_LEFT",channel,step})},ArrowRight(){send({type:"AREA.ARROW_RIGHT",channel,step})},PageUp(){send({type:"AREA.PAGE_UP",channel,step})},PageDown(){send({type:"AREA.PAGE_DOWN",channel,step})},Escape(event2){event2.stopPropagation()}};const exec=keyMap[(0,import_dom_event2.getEventKey)(event,state.context)];if(exec){exec(event);event.preventDefault()}}})},getTransparencyGridProps(props={}){const{size="12px"}=props;return normalize.element({...parts.transparencyGrid.attrs,style:{"--size":size,width:"100%",height:"100%",position:"absolute",backgroundColor:"#fff",backgroundImage:"conic-gradient(#eeeeee 0 25%, transparent 0 50%, #eeeeee 0 75%, transparent 0)",backgroundSize:"var(--size) var(--size)",inset:"0px",zIndex:"auto",pointerEvents:"none"}})},getChannelSliderProps(props){const{orientation="horizontal",channel}=props;return normalize.element({...parts.channelSlider.attrs,"data-channel":channel,"data-orientation":orientation,role:"presentation",onPointerDown(event){if(!interactive)return;if(!(0,import_dom_event2.isLeftClick)(event))return;if((0,import_dom_event2.isModifierKey)(event))return;const point=(0,import_dom_event2.getEventPoint)(event);send({type:"CHANNEL_SLIDER.POINTER_DOWN",channel,point,id:channel,orientation});event.preventDefault()},style:{position:"relative",touchAction:"none"}})},getChannelSliderTrackProps(props){const{orientation="horizontal",channel}=props;return normalize.element({...parts.channelSliderTrack.attrs,id:dom.getChannelSliderId(state.context,channel),role:"group","data-channel":channel,"data-orientation":orientation,style:{position:"relative",forcedColorAdjust:"none",backgroundImage:getSliderBackground({orientation,channel,dir:state.context.dir,value:areaValue})}})},getChannelSliderThumbProps(props){const{orientation="horizontal",channel}=props;const{minValue,maxValue,step:stepValue}=areaValue.getChannelRange(channel);const channelValue=areaValue.getChannelValue(channel);const offset=(channelValue-minValue)/(maxValue-minValue);const placementStyles=orientation==="horizontal"?{left:`${offset*100}%`,top:"50%"}:{top:`${offset*100}%`,left:"50%"};return normalize.element({...parts.channelSliderThumb.attrs,id:dom.getChannelSliderThumbId(state.context,channel),role:"slider","aria-label":channel,tabIndex:disabled?void 0:0,"data-channel":channel,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"data-orientation":orientation,"aria-disabled":(0,import_dom_query2.dataAttr)(disabled),"aria-orientation":orientation,"aria-valuemax":maxValue,"aria-valuemin":minValue,"aria-valuenow":channelValue,"aria-valuetext":`${channel} ${channelValue}`,style:{forcedColorAdjust:"none",position:"absolute",background:getChannelDisplayColor(areaValue,channel).toString("css"),...placementStyles},onFocus(){if(!interactive)return;send({type:"CHANNEL_SLIDER.FOCUS",channel})},onKeyDown(event){if(event.defaultPrevented)return;if(!interactive)return;const step=(0,import_dom_event2.getEventStep)(event)*stepValue;const keyMap={ArrowUp(){send({type:"CHANNEL_SLIDER.ARROW_UP",channel,step})},ArrowDown(){send({type:"CHANNEL_SLIDER.ARROW_DOWN",channel,step})},ArrowLeft(){send({type:"CHANNEL_SLIDER.ARROW_LEFT",channel,step})},ArrowRight(){send({type:"CHANNEL_SLIDER.ARROW_RIGHT",channel,step})},PageUp(){send({type:"CHANNEL_SLIDER.PAGE_UP",channel})},PageDown(){send({type:"CHANNEL_SLIDER.PAGE_DOWN",channel})},Home(){send({type:"CHANNEL_SLIDER.HOME",channel})},End(){send({type:"CHANNEL_SLIDER.END",channel})},Escape(event2){event2.stopPropagation()}};const exec=keyMap[(0,import_dom_event2.getEventKey)(event,state.context)];if(exec){exec(event);event.preventDefault()}}})},getChannelInputProps(props){const{channel}=props;const isTextField=channel==="hex"||channel==="css";const range=getChannelRange(value,channel);return normalize.input({...parts.channelInput.attrs,dir:state.context.dir,type:isTextField?"text":"number","data-channel":channel,"aria-label":channel,spellCheck:false,autoComplete:"off",disabled,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),readOnly:state.context.readOnly,defaultValue:getChannelValue(value,channel),min:range?.minValue,max:range?.maxValue,step:range?.step,onBeforeInput(event){if(isTextField||!interactive)return;const value2=event.currentTarget.value;if(value2.match(/[^0-9.]/g)){event.preventDefault()}},onFocus(event){if(!interactive)return;send({type:"CHANNEL_INPUT.FOCUS",channel});event.target.select()},onBlur(event){if(!interactive)return;const value2=isTextField?event.currentTarget.value:event.currentTarget.valueAsNumber;send({type:"CHANNEL_INPUT.BLUR",channel,value:value2,isTextField})},onKeyDown(event){if(event.defaultPrevented)return;if(!interactive)return;if(event.key==="Enter"){const value2=isTextField?event.currentTarget.value:event.currentTarget.valueAsNumber;send({type:"CHANNEL_INPUT.CHANGE",channel,value:value2,isTextField});event.preventDefault()}},style:{appearance:"none",WebkitAppearance:"none",MozAppearance:"textfield"}})},hiddenInputProps:normalize.input({type:"text",disabled,name:state.context.name,id:dom.getHiddenInputId(state.context),style:import_dom_query2.visuallyHiddenStyle,defaultValue:valueAsString}),eyeDropperTriggerProps:normalize.button({...parts.eyeDropperTrigger.attrs,type:"button",dir:state.context.dir,disabled,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"aria-label":"Pick a color from the screen",onClick(){if(!interactive)return;send("EYEDROPPER.CLICK")}}),swatchGroupProps:normalize.element({...parts.swatchGroup.attrs,role:"group"}),getSwatchTriggerState,getSwatchTriggerProps(props){const triggerState=getSwatchTriggerState(props);return normalize.button({...parts.swatchTrigger.attrs,disabled:triggerState.disabled,dir:state.context.dir,type:"button","aria-label":`select ${triggerState.valueAsString} as the color`,"data-state":triggerState.checked?"checked":"unchecked","data-value":triggerState.valueAsString,"data-disabled":(0,import_dom_query2.dataAttr)(triggerState.disabled),onClick(){if(triggerState.disabled)return;send({type:"SWATCH_TRIGGER.CLICK",value:triggerState.value})},style:{position:"relative"}})},getSwatchIndicatorProps(props){const triggerState=getSwatchTriggerState(props);return normalize.element({...parts.swatchIndicator.attrs,dir:state.context.dir,hidden:!triggerState.checked})},getSwatchProps(props){const{respectAlpha=true}=props;const triggerState=getSwatchTriggerState(props);return normalize.element({...parts.swatch.attrs,dir:state.context.dir,"data-state":triggerState.checked?"checked":"unchecked","data-value":triggerState.valueAsString,style:{position:"relative",background:triggerState.value.toString(respectAlpha?"css":"hex")}})},formatTriggerProps:normalize.button({...parts.formatTrigger.attrs,dir:state.context.dir,type:"button","aria-label":`change color format to ${getNextFormat(state.context.format)}`,onClick(event){if(event.currentTarget.disabled)return;const nextFormat=getNextFormat(state.context.format);send({type:"FORMAT.SET",format:nextFormat,src:"format-trigger"})}}),formatSelectProps:normalize.select({...parts.formatSelect.attrs,"aria-label":"change color format",dir:state.context.dir,defaultValue:state.context.format,disabled,onChange(event){const format=assertFormat(event.currentTarget.value);send({type:"FORMAT.SET",format,src:"format-select"})}})}}var formats=["hsba","hsla","rgba"];var formatRegex=new RegExp(`^(${formats.join("|")})$`);function getNextFormat(format){const index=formats.indexOf(format);return formats[index+1]??formats[0]}function assertFormat(format){if(formatRegex.test(format))return format;throw new Error(`Unsupported color format: ${format}`)}var import_color_utils5=require("@zag-js/color-utils");var import_core=require("@zag-js/core");var import_dismissable=require("@zag-js/dismissable");var import_dom_event3=require("@zag-js/dom-event");var import_dom_query3=require("@zag-js/dom-query");var import_form_utils=require("@zag-js/form-utils");var import_popper2=require("@zag-js/popper");var import_text_selection=require("@zag-js/text-selection");var import_utils=require("@zag-js/utils");var import_color_utils4=require("@zag-js/color-utils");var parse=colorString=>{return(0,import_color_utils4.parseColor)(colorString)};var{and}=import_core.guards;function machine(userContext){const ctx=(0,import_utils.compact)(userContext);return(0,import_core.createMachine)({id:"color-picker",initial:ctx.open?"open":"idle",context:{dir:"ltr",value:parse("#000000"),format:"rgba",disabled:false,closeOnSelect:false,...ctx,activeId:null,activeChannel:null,activeOrientation:null,fieldsetDisabled:false,restoreFocus:true,positioning:{...ctx.positioning,placement:"bottom"}},computed:{isRtl:ctx2=>ctx2.dir==="rtl",isDisabled:ctx2=>!!ctx2.disabled||ctx2.fieldsetDisabled,isInteractive:ctx2=>!(ctx2.isDisabled||ctx2.readOnly),valueAsString:ctx2=>ctx2.value.toString(ctx2.format),areaValue:ctx2=>{const format=ctx2.format.startsWith("hsl")?"hsla":"hsba";return ctx2.value.toFormat(format)}},activities:["trackFormControl"],watch:{value:["syncInputElements"],format:["syncFormatSelectElement"],open:["toggleVisibility"]},on:{"VALUE.SET":{actions:["setValue"]},"FORMAT.SET":{actions:["setFormat"]},"CHANNEL_INPUT.CHANGE":{actions:["setChannelColorFromInput"]},"EYEDROPPER.CLICK":{actions:["openEyeDropper"]}},states:{idle:{tags:["closed"],on:{"CONTROLLED.OPEN":{target:"open",actions:["setInitialFocus"]},OPEN:[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"TRIGGER.CLICK":[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"CHANNEL_INPUT.FOCUS":{target:"focused",actions:["setActiveChannel"]}}},focused:{tags:["closed","focused"],on:{"CONTROLLED.OPEN":{target:"open",actions:["setInitialFocus"]},OPEN:[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"TRIGGER.CLICK":[{guard:"isOpenControlled",actions:["invokeOnOpen"]},{target:"open",actions:["invokeOnOpen","setInitialFocus"]}],"CHANNEL_INPUT.FOCUS":{actions:["setActiveChannel"]},"CHANNEL_INPUT.BLUR":{target:"idle",actions:["setChannelColorFromInput"]},"TRIGGER.BLUR":{target:"idle"}}},open:{tags:["open"],activities:["trackPositioning","trackDismissableElement"],on:{"CONTROLLED.CLOSE":[{guard:"shouldRestoreFocus",target:"focused",actions:["setReturnFocus"]},{target:"idle"}],"TRIGGER.CLICK":[{guard:"isOpenControlled",actions:["invokeOnClose"]},{target:"idle",actions:["invokeOnClose"]}],"AREA.POINTER_DOWN":{target:"open:dragging",actions:["setActiveChannel","setAreaColorFromPoint","focusAreaThumb"]},"AREA.FOCUS":{actions:["setActiveChannel"]},"CHANNEL_SLIDER.POINTER_DOWN":{target:"open:dragging",actions:["setActiveChannel","setChannelColorFromPoint","focusChannelThumb"]},"CHANNEL_SLIDER.FOCUS":{actions:["setActiveChannel"]},"AREA.ARROW_LEFT":{actions:["decrementXChannel"]},"AREA.ARROW_RIGHT":{actions:["incrementXChannel"]},"AREA.ARROW_UP":{actions:["incrementYChannel"]},"AREA.ARROW_DOWN":{actions:["decrementYChannel"]},"AREA.PAGE_UP":{actions:["incrementXChannel"]},"AREA.PAGE_DOWN":{actions:["decrementXChannel"]},"CHANNEL_SLIDER.ARROW_LEFT":{actions:["decrementChannel"]},"CHANNEL_SLIDER.ARROW_RIGHT":{actions:["incrementChannel"]},"CHANNEL_SLIDER.ARROW_UP":{actions:["incrementChannel"]},"CHANNEL_SLIDER.ARROW_DOWN":{actions:["decrementChannel"]},"CHANNEL_SLIDER.PAGE_UP":{actions:["incrementChannel"]},"CHANNEL_SLIDER.PAGE_DOWN":{actions:["decrementChannel"]},"CHANNEL_SLIDER.HOME":{actions:["setChannelToMin"]},"CHANNEL_SLIDER.END":{actions:["setChannelToMax"]},"CHANNEL_INPUT.BLUR":{actions:["setChannelColorFromInput"]},INTERACT_OUTSIDE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{guard:"shouldRestoreFocus",target:"focused",actions:["invokeOnClose","setReturnFocus"]},{target:"idle",actions:["invokeOnClose"]}],CLOSE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{target:"idle",actions:["invokeOnClose"]}],"SWATCH_TRIGGER.CLICK":[{guard:and("isOpenControlled","closeOnSelect"),actions:["setValue","invokeOnClose"]},{guard:"closeOnSelect",target:"focused",actions:["setValue","invokeOnClose","setReturnFocus"]},{actions:["setValue"]}]}},"open:dragging":{tags:["open"],exit:["clearActiveChannel"],activities:["trackPointerMove","disableTextSelection","trackPositioning","trackDismissableElement"],on:{"CONTROLLED.CLOSE":[{guard:"shouldRestoreFocus",target:"focused",actions:["setReturnFocus"]},{target:"idle"}],"AREA.POINTER_MOVE":{actions:["setAreaColorFromPoint","focusAreaThumb"]},"AREA.POINTER_UP":{target:"open",actions:["invokeOnChangeEnd"]},"CHANNEL_SLIDER.POINTER_MOVE":{actions:["setChannelColorFromPoint","focusChannelThumb"]},"CHANNEL_SLIDER.POINTER_UP":{target:"open",actions:["invokeOnChangeEnd"]},INTERACT_OUTSIDE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{guard:"shouldRestoreFocus",target:"focused",actions:["invokeOnClose","setReturnFocus"]},{target:"idle",actions:["invokeOnClose"]}],CLOSE:[{guard:"isOpenControlled",actions:["invokeOnClose"]},{target:"idle",actions:["invokeOnClose"]}]}}}},{guards:{closeOnSelect:ctx2=>!!ctx2.closeOnSelect,isOpenControlled:ctx2=>!!ctx2["open.controlled"],shouldRestoreFocus:ctx2=>!!ctx2.restoreFocus},activities:{trackPositioning(ctx2){ctx2.currentPlacement=ctx2.positioning.placement;const anchorEl=dom.getTriggerEl(ctx2);const getPositionerEl=()=>dom.getPositionerEl(ctx2);return(0,import_popper2.getPlacement)(anchorEl,getPositionerEl,{...ctx2.positioning,defer:true,onComplete(data){ctx2.currentPlacement=data.placement}})},trackDismissableElement(ctx2,_evt,{send}){const getContentEl=()=>dom.getContentEl(ctx2);return(0,import_dismissable.trackDismissableElement)(getContentEl,{exclude:dom.getTriggerEl(ctx2),defer:true,onInteractOutside(event){ctx2.onInteractOutside?.(event);if(event.defaultPrevented)return;ctx2.restoreFocus=!(event.detail.focusable||event.detail.contextmenu)},onPointerDownOutside:ctx2.onPointerDownOutside,onFocusOutside:ctx2.onFocusOutside,onDismiss(){send({type:"INTERACT_OUTSIDE"})}})},trackFormControl(ctx2,_evt,{send,initialContext}){const inputEl=dom.getHiddenInputEl(ctx2);return(0,import_form_utils.trackFormControl)(inputEl,{onFieldsetDisabledChange(disabled){ctx2.fieldsetDisabled=disabled},onFormReset(){send({type:"VALUE.SET",value:initialContext.value,src:"form.reset"})}})},trackPointerMove(ctx2,_evt,{send}){return(0,import_dom_event3.trackPointerMove)(dom.getDoc(ctx2),{onPointerMove({point}){const type=ctx2.activeId==="area"?"AREA.POINTER_MOVE":"CHANNEL_SLIDER.POINTER_MOVE";send({type,point})},onPointerUp(){const type=ctx2.activeId==="area"?"AREA.POINTER_UP":"CHANNEL_SLIDER.POINTER_UP";send({type})}})},disableTextSelection(ctx2){return(0,import_text_selection.disableTextSelection)({doc:dom.getDoc(ctx2),target:dom.getContentEl(ctx2)})}},actions:{openEyeDropper(ctx2){const isSupported="EyeDropper"in dom.getWin(ctx2);if(!isSupported)return;const win=dom.getWin(ctx2);const picker=new win.EyeDropper;picker.open().then(({sRGBHex})=>{const format=ctx2.value.getFormat();const color=(0,import_color_utils5.parseColor)(sRGBHex).toFormat(format);set.value(ctx2,color);ctx2.onValueChangeEnd?.({value:ctx2.value,valueAsString:ctx2.valueAsString})}).catch(()=>void 0)},setActiveChannel(ctx2,evt){ctx2.activeId=evt.id;if(evt.channel)ctx2.activeChannel=evt.channel;if(evt.orientation)ctx2.activeOrientation=evt.orientation},clearActiveChannel(ctx2){ctx2.activeChannel=null;ctx2.activeId=null;ctx2.activeOrientation=null},setAreaColorFromPoint(ctx2,evt){const{xChannel,yChannel}=evt.channel||ctx2.activeChannel;const percent=dom.getAreaValueFromPoint(ctx2,evt.point);if(!percent)return;const xValue=ctx2.areaValue.getChannelPercentValue(xChannel,percent.x);const yValue=ctx2.areaValue.getChannelPercentValue(yChannel,1-percent.y);const color=ctx2.areaValue.withChannelValue(xChannel,xValue).withChannelValue(yChannel,yValue);set.value(ctx2,color)},setChannelColorFromPoint(ctx2,evt){const channel=evt.channel||ctx2.activeId;const percent=dom.getChannelSliderValueFromPoint(ctx2,evt.point,channel);if(!percent)return;const orientation=ctx2.activeOrientation||"horizontal";const channelPercent=orientation==="horizontal"?percent.x:percent.y;const value=ctx2.areaValue.getChannelPercentValue(channel,channelPercent);const color=ctx2.areaValue.withChannelValue(channel,value);set.value(ctx2,color)},setValue(ctx2,evt){set.value(ctx2,evt.value)},setFormat(ctx2,evt){set.format(ctx2,evt.format)},syncInputElements(ctx2){sync.inputs(ctx2)},invokeOnChangeEnd(ctx2){invoke.changeEnd(ctx2)},setChannelColorFromInput(ctx2,evt){const{channel,isTextField,value}=evt;const currentAlpha=ctx2.value.getChannelValue("alpha");let color;if(channel==="alpha"){let valueAsNumber=parseFloat(value);valueAsNumber=Number.isNaN(valueAsNumber)?currentAlpha:valueAsNumber;color=ctx2.value.withChannelValue("alpha",valueAsNumber)}else if(isTextField){color=(0,import_utils.tryCatch)(()=>parse(value).withChannelValue("alpha",currentAlpha),()=>ctx2.value)}else{const current=ctx2.value.toFormat(ctx2.format);const valueAsNumber=Number.isNaN(value)?current.getChannelValue(channel):value;color=current.withChannelValue(channel,valueAsNumber)}sync.inputs(ctx2,color);set.value(ctx2,color)},incrementChannel(ctx2,evt){const color=ctx2.value.incrementChannel(evt.channel,evt.step);set.value(ctx2,color)},decrementChannel(ctx2,evt){const color=ctx2.value.decrementChannel(evt.channel,evt.step);set.value(ctx2,color)},incrementXChannel(ctx2,evt){const{xChannel}=evt.channel;const color=ctx2.areaValue.incrementChannel(xChannel,evt.step);set.value(ctx2,color)},decrementXChannel(ctx2,evt){const{xChannel}=evt.channel;const color=ctx2.areaValue.decrementChannel(xChannel,evt.step);set.value(ctx2,color)},incrementYChannel(ctx2,evt){const{yChannel}=evt.channel;const color=ctx2.areaValue.incrementChannel(yChannel,evt.step);set.value(ctx2,color)},decrementYChannel(ctx2,evt){const{yChannel}=evt.channel;const color=ctx2.areaValue.decrementChannel(yChannel,evt.step);set.value(ctx2,color)},setChannelToMax(ctx2,evt){const range=ctx2.value.getChannelRange(evt.channel);const color=ctx2.value.withChannelValue(evt.channel,range.maxValue);set.value(ctx2,color)},setChannelToMin(ctx2,evt){const range=ctx2.value.getChannelRange(evt.channel);const color=ctx2.value.withChannelValue(evt.channel,range.minValue);set.value(ctx2,color)},focusAreaThumb(ctx2){(0,import_dom_query3.raf)(()=>{dom.getAreaThumbEl(ctx2)?.focus({preventScroll:true})})},focusChannelThumb(ctx2,evt){(0,import_dom_query3.raf)(()=>{dom.getChannelSliderThumbEl(ctx2,evt.channel)?.focus({preventScroll:true})})},setInitialFocus(ctx2){(0,import_dom_query3.raf)(()=>{const element=(0,import_dom_query3.getInitialFocus)({root:dom.getContentEl(ctx2),getInitialEl:ctx2.initialFocusEl});element?.focus({preventScroll:true})})},setReturnFocus(ctx2){(0,import_dom_query3.raf)(()=>{dom.getTriggerEl(ctx2)?.focus({preventScroll:true})})},syncFormatSelectElement(ctx2){sync.formatSelect(ctx2)},invokeOnOpen(ctx2){ctx2.onOpenChange?.({open:true})},invokeOnClose(ctx2){ctx2.onOpenChange?.({open:false})},toggleVisibility(ctx2,evt,{send}){send({type:ctx2.open?"CONTROLLED.OPEN":"CONTROLLED.CLOSE",previousEvent:evt})}},compareFns:{value:(a,b)=>a.isEqual(b)}})}var sync={inputs(ctx,color){const channelInputs=dom.getChannelInputEls(ctx);(0,import_dom_query3.raf)(()=>{channelInputs.forEach(inputEl=>{const channel=inputEl.dataset.channel;dom.setValue(inputEl,getChannelValue(color||ctx.value,channel))})})},formatSelect(ctx){const selectEl=dom.getFormatSelectEl(ctx);(0,import_dom_query3.raf)(()=>{dom.setValue(selectEl,ctx.format)})}};var invoke={changeEnd(ctx){const value=ctx.value.toFormat(ctx.format);ctx.onValueChangeEnd?.({value,valueAsString:ctx.valueAsString})},change(ctx){const value=ctx.value.toFormat(ctx.format);ctx.onValueChange?.({value,valueAsString:ctx.valueAsString});(0,import_form_utils.dispatchInputValueEvent)(dom.getHiddenInputEl(ctx),{value:ctx.valueAsString})},formatChange(ctx){ctx.onFormatChange?.({format:ctx.format})}};var set={value(ctx,color){if(!color||ctx.value.isEqual(color))return;ctx.value=color;invoke.change(ctx)},format(ctx,format){if(ctx.format===format)return;ctx.format=format;invoke.formatChange(ctx)}};0&&(module.exports={anatomy,connect,machine,parse});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ anatomy: () => anatomy,
24
+ connect: () => connect,
25
+ machine: () => machine,
26
+ parse: () => parse
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/color-picker.anatomy.ts
31
+ var import_anatomy = require("@zag-js/anatomy");
32
+ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
33
+ "root",
34
+ "label",
35
+ "control",
36
+ "trigger",
37
+ "positioner",
38
+ "content",
39
+ "area",
40
+ "areaThumb",
41
+ "areaBackground",
42
+ "channelSlider",
43
+ "channelSliderTrack",
44
+ "channelSliderThumb",
45
+ "channelInput",
46
+ "transparencyGrid",
47
+ "swatchGroup",
48
+ "swatchTrigger",
49
+ "swatchIndicator",
50
+ "swatch",
51
+ "eyeDropperTrigger",
52
+ "formatTrigger",
53
+ "formatSelect"
54
+ ]);
55
+ var parts = anatomy.build();
56
+
57
+ // src/color-picker.connect.ts
58
+ var import_color_utils3 = require("@zag-js/color-utils");
59
+ var import_dom_event2 = require("@zag-js/dom-event");
60
+ var import_dom_query2 = require("@zag-js/dom-query");
61
+ var import_popper = require("@zag-js/popper");
62
+
63
+ // src/color-picker.dom.ts
64
+ var import_dom_event = require("@zag-js/dom-event");
65
+ var import_dom_query = require("@zag-js/dom-query");
66
+ var dom = (0, import_dom_query.createScope)({
67
+ getRootId: (ctx) => ctx.ids?.root ?? `color-picker:${ctx.id}`,
68
+ getLabelId: (ctx) => ctx.ids?.label ?? `color-picker:${ctx.id}:label`,
69
+ getHiddenInputId: (ctx) => `color-picker:${ctx.id}:hidden-input`,
70
+ getControlId: (ctx) => ctx.ids?.control ?? `color-picker:${ctx.id}:control`,
71
+ getTriggerId: (ctx) => ctx.ids?.trigger ?? `color-picker:${ctx.id}:trigger`,
72
+ getContentId: (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`,
73
+ getPositionerId: (ctx) => `color-picker:${ctx.id}:positioner`,
74
+ getFormatSelectId: (ctx) => `color-picker:${ctx.id}:format-select`,
75
+ getAreaId: (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`,
76
+ getAreaGradientId: (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`,
77
+ getAreaThumbId: (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`,
78
+ getChannelSliderId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
79
+ getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
80
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
81
+ getAreaThumbEl: (ctx) => dom.getById(ctx, dom.getAreaThumbId(ctx)),
82
+ getChannelSliderThumbEl: (ctx, channel) => dom.getById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
83
+ getChannelInputEl: (ctx, channel) => {
84
+ return [
85
+ ...(0, import_dom_query.queryAll)(dom.getContentEl(ctx), `input[data-channel="${channel}"]`),
86
+ ...(0, import_dom_query.queryAll)(dom.getControlEl(ctx), `input[data-channel="${channel}"]`)
87
+ ];
88
+ },
89
+ getFormatSelectEl: (ctx) => dom.getById(ctx, dom.getFormatSelectId(ctx)),
90
+ getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
91
+ getAreaEl: (ctx) => dom.getById(ctx, dom.getAreaId(ctx)),
92
+ getAreaValueFromPoint(ctx, point) {
93
+ const areaEl = dom.getAreaEl(ctx);
94
+ if (!areaEl)
95
+ return;
96
+ const { percent } = (0, import_dom_event.getRelativePoint)(point, areaEl);
97
+ return percent;
98
+ },
99
+ getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
100
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
101
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
102
+ getChannelSliderTrackEl: (ctx, channel) => {
103
+ return dom.getById(ctx, dom.getChannelSliderId(ctx, channel));
104
+ },
105
+ getChannelSliderValueFromPoint(ctx, point, channel) {
106
+ const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
107
+ if (!trackEl)
108
+ return;
109
+ const { percent } = (0, import_dom_event.getRelativePoint)(point, trackEl);
110
+ return percent;
111
+ },
112
+ getChannelInputEls: (ctx) => {
113
+ return [
114
+ ...(0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]"),
115
+ ...(0, import_dom_query.queryAll)(dom.getControlEl(ctx), "input[data-channel]")
116
+ ];
117
+ }
118
+ });
119
+
120
+ // src/utils/get-channel-display-color.ts
121
+ var import_color_utils = require("@zag-js/color-utils");
122
+ function getChannelDisplayColor(color, channel) {
123
+ switch (channel) {
124
+ case "hue":
125
+ return (0, import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
126
+ case "lightness":
127
+ case "brightness":
128
+ case "saturation":
129
+ case "red":
130
+ case "green":
131
+ case "blue":
132
+ return color.withChannelValue("alpha", 1);
133
+ case "alpha": {
134
+ return color;
135
+ }
136
+ default:
137
+ throw new Error("Unknown color channel: " + channel);
138
+ }
139
+ }
140
+
141
+ // src/utils/get-channel-input-value.ts
142
+ var import_color_utils2 = require("@zag-js/color-utils");
143
+ function getChannelValue(color, channel) {
144
+ if (channel == null)
145
+ return "";
146
+ if (channel === "hex") {
147
+ return color.toString("hex");
148
+ }
149
+ if (channel === "css") {
150
+ return color.toString("css");
151
+ }
152
+ if (channel in color) {
153
+ return color.getChannelValue(channel).toString();
154
+ }
155
+ const isHSL = color.getFormat() === "hsla";
156
+ switch (channel) {
157
+ case "hue":
158
+ return isHSL ? color.toFormat("hsla").getChannelValue("hue").toString() : color.toFormat("hsba").getChannelValue("hue").toString();
159
+ case "saturation":
160
+ return isHSL ? color.toFormat("hsla").getChannelValue("saturation").toString() : color.toFormat("hsba").getChannelValue("saturation").toString();
161
+ case "lightness":
162
+ return color.toFormat("hsla").getChannelValue("lightness").toString();
163
+ case "brightness":
164
+ return color.toFormat("hsba").getChannelValue("brightness").toString();
165
+ case "red":
166
+ case "green":
167
+ case "blue":
168
+ return color.toFormat("rgba").getChannelValue(channel).toString();
169
+ default:
170
+ return color.getChannelValue(channel).toString();
171
+ }
172
+ }
173
+ function getChannelRange(color, channel) {
174
+ switch (channel) {
175
+ case "hex":
176
+ const minColor = (0, import_color_utils2.parseColor)("#000000");
177
+ const maxColor = (0, import_color_utils2.parseColor)("#FFFFFF");
178
+ return {
179
+ minValue: minColor.toHexInt(),
180
+ maxValue: maxColor.toHexInt(),
181
+ pageSize: 10,
182
+ step: 1
183
+ };
184
+ case "css":
185
+ return void 0;
186
+ case "hue":
187
+ case "saturation":
188
+ case "lightness":
189
+ return color.toFormat("hsla").getChannelRange(channel);
190
+ case "brightness":
191
+ return color.toFormat("hsba").getChannelRange(channel);
192
+ case "red":
193
+ case "green":
194
+ case "blue":
195
+ return color.toFormat("rgba").getChannelRange(channel);
196
+ default:
197
+ return color.getChannelRange(channel);
198
+ }
199
+ }
200
+
201
+ // src/utils/get-slider-background.ts
202
+ function getSliderBackgroundDirection(orientation, dir) {
203
+ if (orientation === "vertical") {
204
+ return "top";
205
+ } else if (dir === "ltr") {
206
+ return "right";
207
+ } else {
208
+ return "left";
209
+ }
210
+ }
211
+ var getSliderBackground = (props) => {
212
+ const { channel, value, dir } = props;
213
+ const bgDirection = getSliderBackgroundDirection(props.orientation, dir);
214
+ const { minValue, maxValue } = value.getChannelRange(channel);
215
+ switch (channel) {
216
+ case "hue":
217
+ return `linear-gradient(to ${bgDirection}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
218
+ case "lightness": {
219
+ let start = value.withChannelValue(channel, minValue).toString("css");
220
+ let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
221
+ let end = value.withChannelValue(channel, maxValue).toString("css");
222
+ return `linear-gradient(to ${bgDirection}, ${start}, ${middle}, ${end})`;
223
+ }
224
+ case "saturation":
225
+ case "brightness":
226
+ case "red":
227
+ case "green":
228
+ case "blue":
229
+ case "alpha": {
230
+ let start = value.withChannelValue(channel, minValue).toString("css");
231
+ let end = value.withChannelValue(channel, maxValue).toString("css");
232
+ return `linear-gradient(to ${bgDirection}, ${start}, ${end})`;
233
+ }
234
+ default:
235
+ throw new Error("Unknown color channel: " + channel);
236
+ }
237
+ };
238
+
239
+ // src/color-picker.connect.ts
240
+ function connect(state, send, normalize) {
241
+ const value = state.context.value;
242
+ const areaValue = state.context.areaValue;
243
+ const valueAsString = state.context.valueAsString;
244
+ const disabled = state.context.isDisabled;
245
+ const interactive = state.context.isInteractive;
246
+ const dragging = state.hasTag("dragging");
247
+ const open = state.hasTag("open");
248
+ const focused = state.hasTag("focused");
249
+ const getAreaChannels = (props) => {
250
+ const channels = areaValue.getChannels();
251
+ return {
252
+ xChannel: props.xChannel ?? channels[1],
253
+ yChannel: props.yChannel ?? channels[2]
254
+ };
255
+ };
256
+ const currentPlacement = state.context.currentPlacement;
257
+ const popperStyles = (0, import_popper.getPlacementStyles)({
258
+ ...state.context.positioning,
259
+ placement: currentPlacement
260
+ });
261
+ function getSwatchTriggerState(props) {
262
+ const color = (0, import_color_utils3.normalizeColor)(props.value).toFormat(state.context.format);
263
+ return {
264
+ value: color,
265
+ valueAsString: color.toString("hex"),
266
+ checked: color.isEqual(value),
267
+ disabled: props.disabled || !interactive
268
+ };
269
+ }
270
+ return {
271
+ dragging,
272
+ open,
273
+ valueAsString,
274
+ value,
275
+ setOpen(nextOpen) {
276
+ if (nextOpen === open)
277
+ return;
278
+ send({ type: nextOpen ? "OPEN" : "CLOSE" });
279
+ },
280
+ setValue(value2) {
281
+ send({ type: "VALUE.SET", value: (0, import_color_utils3.normalizeColor)(value2), src: "set-color" });
282
+ },
283
+ getChannelValue(channel) {
284
+ return getChannelValue(value, channel);
285
+ },
286
+ setChannelValue(channel, channelValue) {
287
+ const color = value.withChannelValue(channel, channelValue);
288
+ send({ type: "VALUE.SET", value: color, src: "set-channel" });
289
+ },
290
+ format: state.context.format,
291
+ setFormat(format) {
292
+ const formatValue = value.toFormat(format);
293
+ send({ type: "VALUE.SET", value: formatValue, src: "set-format" });
294
+ },
295
+ alpha: value.getChannelValue("alpha"),
296
+ setAlpha(alphaValue) {
297
+ const color = value.withChannelValue("alpha", alphaValue);
298
+ send({ type: "VALUE.SET", value: color, src: "set-alpha" });
299
+ },
300
+ getRootProps() {
301
+ return normalize.element({
302
+ ...parts.root.attrs,
303
+ dir: state.context.dir,
304
+ id: dom.getRootId(state.context),
305
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
306
+ "data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
307
+ style: {
308
+ "--value": value.toString("css")
309
+ }
310
+ });
311
+ },
312
+ getLabelProps() {
313
+ return normalize.element({
314
+ ...parts.label.attrs,
315
+ dir: state.context.dir,
316
+ id: dom.getLabelId(state.context),
317
+ htmlFor: dom.getHiddenInputId(state.context),
318
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
319
+ "data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
320
+ "data-focus": (0, import_dom_query2.dataAttr)(focused),
321
+ onClick(event) {
322
+ event.preventDefault();
323
+ const inputEl = (0, import_dom_query2.query)(dom.getControlEl(state.context), "[data-channel=hex]");
324
+ inputEl?.focus({ preventScroll: true });
325
+ }
326
+ });
327
+ },
328
+ getControlProps() {
329
+ return normalize.element({
330
+ ...parts.control.attrs,
331
+ id: dom.getControlId(state.context),
332
+ dir: state.context.dir,
333
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
334
+ "data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
335
+ "data-state": open ? "open" : "closed",
336
+ "data-focus": (0, import_dom_query2.dataAttr)(focused)
337
+ });
338
+ },
339
+ getTriggerProps() {
340
+ return normalize.button({
341
+ ...parts.trigger.attrs,
342
+ id: dom.getTriggerId(state.context),
343
+ dir: state.context.dir,
344
+ disabled,
345
+ "aria-label": `select color. current color is ${valueAsString}`,
346
+ "aria-controls": dom.getContentId(state.context),
347
+ "aria-labelledby": dom.getLabelId(state.context),
348
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
349
+ "data-readonly": (0, import_dom_query2.dataAttr)(state.context.readOnly),
350
+ "data-placement": currentPlacement,
351
+ "aria-expanded": (0, import_dom_query2.dataAttr)(open),
352
+ "data-state": open ? "open" : "closed",
353
+ "data-focus": (0, import_dom_query2.dataAttr)(focused),
354
+ type: "button",
355
+ onClick() {
356
+ if (!interactive)
357
+ return;
358
+ send({ type: "TRIGGER.CLICK" });
359
+ },
360
+ onBlur() {
361
+ if (!interactive)
362
+ return;
363
+ send({ type: "TRIGGER.BLUR" });
364
+ },
365
+ style: {
366
+ position: "relative"
367
+ }
368
+ });
369
+ },
370
+ getPositionerProps() {
371
+ return normalize.element({
372
+ ...parts.positioner.attrs,
373
+ id: dom.getPositionerId(state.context),
374
+ dir: state.context.dir,
375
+ style: popperStyles.floating
376
+ });
377
+ },
378
+ getContentProps() {
379
+ return normalize.element({
380
+ ...parts.content.attrs,
381
+ id: dom.getContentId(state.context),
382
+ dir: state.context.dir,
383
+ "data-placement": currentPlacement,
384
+ "data-state": open ? "open" : "closed",
385
+ hidden: !open
386
+ });
387
+ },
388
+ getAreaProps(props = {}) {
389
+ const { xChannel, yChannel } = getAreaChannels(props);
390
+ const { areaStyles } = (0, import_color_utils3.getColorAreaGradient)(areaValue, {
391
+ xChannel,
392
+ yChannel,
393
+ dir: state.context.dir
394
+ });
395
+ return normalize.element({
396
+ ...parts.area.attrs,
397
+ id: dom.getAreaId(state.context),
398
+ role: "group",
399
+ onPointerDown(event) {
400
+ if (!interactive)
401
+ return;
402
+ if (!(0, import_dom_event2.isLeftClick)(event))
403
+ return;
404
+ if ((0, import_dom_event2.isModifierKey)(event))
405
+ return;
406
+ const point = (0, import_dom_event2.getEventPoint)(event);
407
+ const channel = { xChannel, yChannel };
408
+ send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
409
+ event.preventDefault();
410
+ },
411
+ style: {
412
+ position: "relative",
413
+ touchAction: "none",
414
+ forcedColorAdjust: "none",
415
+ ...areaStyles
416
+ }
417
+ });
418
+ },
419
+ getAreaBackgroundProps(props = {}) {
420
+ const { xChannel, yChannel } = getAreaChannels(props);
421
+ const { areaGradientStyles } = (0, import_color_utils3.getColorAreaGradient)(areaValue, {
422
+ xChannel,
423
+ yChannel,
424
+ dir: state.context.dir
425
+ });
426
+ return normalize.element({
427
+ ...parts.areaBackground.attrs,
428
+ id: dom.getAreaGradientId(state.context),
429
+ style: {
430
+ position: "relative",
431
+ touchAction: "none",
432
+ forcedColorAdjust: "none",
433
+ ...areaGradientStyles
434
+ }
435
+ });
436
+ },
437
+ getAreaThumbProps(props = {}) {
438
+ const { xChannel, yChannel } = getAreaChannels(props);
439
+ const channel = { xChannel, yChannel };
440
+ const xPercent = areaValue.getChannelValuePercent(xChannel);
441
+ const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
442
+ const xValue = areaValue.getChannelValue(xChannel);
443
+ const yValue = areaValue.getChannelValue(yChannel);
444
+ return normalize.element({
445
+ ...parts.areaThumb.attrs,
446
+ id: dom.getAreaThumbId(state.context),
447
+ dir: state.context.dir,
448
+ tabIndex: disabled ? void 0 : 0,
449
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
450
+ role: "slider",
451
+ "aria-valuemin": 0,
452
+ "aria-valuemax": 100,
453
+ "aria-valuenow": xValue,
454
+ "aria-label": `${xChannel} and ${yChannel}`,
455
+ "aria-roledescription": "2d slider",
456
+ "aria-valuetext": `${xChannel} ${xValue}, ${yChannel} ${yValue}`,
457
+ style: {
458
+ position: "absolute",
459
+ left: `${xPercent * 100}%`,
460
+ top: `${yPercent * 100}%`,
461
+ transform: "translate(-50%, -50%)",
462
+ touchAction: "none",
463
+ forcedColorAdjust: "none",
464
+ background: areaValue.withChannelValue("alpha", 1).toString("css")
465
+ },
466
+ onFocus() {
467
+ if (!interactive)
468
+ return;
469
+ send({ type: "AREA.FOCUS", id: "area", channel });
470
+ },
471
+ onKeyDown(event) {
472
+ if (event.defaultPrevented)
473
+ return;
474
+ if (!interactive)
475
+ return;
476
+ const step = (0, import_dom_event2.getEventStep)(event);
477
+ const keyMap = {
478
+ ArrowUp() {
479
+ send({ type: "AREA.ARROW_UP", channel, step });
480
+ },
481
+ ArrowDown() {
482
+ send({ type: "AREA.ARROW_DOWN", channel, step });
483
+ },
484
+ ArrowLeft() {
485
+ send({ type: "AREA.ARROW_LEFT", channel, step });
486
+ },
487
+ ArrowRight() {
488
+ send({ type: "AREA.ARROW_RIGHT", channel, step });
489
+ },
490
+ PageUp() {
491
+ send({ type: "AREA.PAGE_UP", channel, step });
492
+ },
493
+ PageDown() {
494
+ send({ type: "AREA.PAGE_DOWN", channel, step });
495
+ },
496
+ Escape(event2) {
497
+ event2.stopPropagation();
498
+ }
499
+ };
500
+ const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
501
+ if (exec) {
502
+ exec(event);
503
+ event.preventDefault();
504
+ }
505
+ }
506
+ });
507
+ },
508
+ getTransparencyGridProps(props = {}) {
509
+ const { size = "12px" } = props;
510
+ return normalize.element({
511
+ ...parts.transparencyGrid.attrs,
512
+ style: {
513
+ "--size": size,
514
+ width: "100%",
515
+ height: "100%",
516
+ position: "absolute",
517
+ backgroundColor: "#fff",
518
+ backgroundImage: "conic-gradient(#eeeeee 0 25%, transparent 0 50%, #eeeeee 0 75%, transparent 0)",
519
+ backgroundSize: "var(--size) var(--size)",
520
+ inset: "0px",
521
+ zIndex: "auto",
522
+ pointerEvents: "none"
523
+ }
524
+ });
525
+ },
526
+ getChannelSliderProps(props) {
527
+ const { orientation = "horizontal", channel } = props;
528
+ return normalize.element({
529
+ ...parts.channelSlider.attrs,
530
+ "data-channel": channel,
531
+ "data-orientation": orientation,
532
+ role: "presentation",
533
+ onPointerDown(event) {
534
+ if (!interactive)
535
+ return;
536
+ if (!(0, import_dom_event2.isLeftClick)(event))
537
+ return;
538
+ if ((0, import_dom_event2.isModifierKey)(event))
539
+ return;
540
+ const point = (0, import_dom_event2.getEventPoint)(event);
541
+ send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
542
+ event.preventDefault();
543
+ },
544
+ style: {
545
+ position: "relative",
546
+ touchAction: "none"
547
+ }
548
+ });
549
+ },
550
+ getChannelSliderTrackProps(props) {
551
+ const { orientation = "horizontal", channel } = props;
552
+ return normalize.element({
553
+ ...parts.channelSliderTrack.attrs,
554
+ id: dom.getChannelSliderId(state.context, channel),
555
+ role: "group",
556
+ "data-channel": channel,
557
+ "data-orientation": orientation,
558
+ style: {
559
+ position: "relative",
560
+ forcedColorAdjust: "none",
561
+ backgroundImage: getSliderBackground({
562
+ orientation,
563
+ channel,
564
+ dir: state.context.dir,
565
+ value: areaValue
566
+ })
567
+ }
568
+ });
569
+ },
570
+ getChannelSliderThumbProps(props) {
571
+ const { orientation = "horizontal", channel } = props;
572
+ const { minValue, maxValue, step: stepValue } = areaValue.getChannelRange(channel);
573
+ const channelValue = areaValue.getChannelValue(channel);
574
+ const offset = (channelValue - minValue) / (maxValue - minValue);
575
+ const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
576
+ return normalize.element({
577
+ ...parts.channelSliderThumb.attrs,
578
+ id: dom.getChannelSliderThumbId(state.context, channel),
579
+ role: "slider",
580
+ "aria-label": channel,
581
+ tabIndex: disabled ? void 0 : 0,
582
+ "data-channel": channel,
583
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
584
+ "data-orientation": orientation,
585
+ "aria-disabled": (0, import_dom_query2.dataAttr)(disabled),
586
+ "aria-orientation": orientation,
587
+ "aria-valuemax": maxValue,
588
+ "aria-valuemin": minValue,
589
+ "aria-valuenow": channelValue,
590
+ "aria-valuetext": `${channel} ${channelValue}`,
591
+ style: {
592
+ forcedColorAdjust: "none",
593
+ position: "absolute",
594
+ background: getChannelDisplayColor(areaValue, channel).toString("css"),
595
+ ...placementStyles
596
+ },
597
+ onFocus() {
598
+ if (!interactive)
599
+ return;
600
+ send({ type: "CHANNEL_SLIDER.FOCUS", channel });
601
+ },
602
+ onKeyDown(event) {
603
+ if (event.defaultPrevented)
604
+ return;
605
+ if (!interactive)
606
+ return;
607
+ const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
608
+ const keyMap = {
609
+ ArrowUp() {
610
+ send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
611
+ },
612
+ ArrowDown() {
613
+ send({ type: "CHANNEL_SLIDER.ARROW_DOWN", channel, step });
614
+ },
615
+ ArrowLeft() {
616
+ send({ type: "CHANNEL_SLIDER.ARROW_LEFT", channel, step });
617
+ },
618
+ ArrowRight() {
619
+ send({ type: "CHANNEL_SLIDER.ARROW_RIGHT", channel, step });
620
+ },
621
+ PageUp() {
622
+ send({ type: "CHANNEL_SLIDER.PAGE_UP", channel });
623
+ },
624
+ PageDown() {
625
+ send({ type: "CHANNEL_SLIDER.PAGE_DOWN", channel });
626
+ },
627
+ Home() {
628
+ send({ type: "CHANNEL_SLIDER.HOME", channel });
629
+ },
630
+ End() {
631
+ send({ type: "CHANNEL_SLIDER.END", channel });
632
+ },
633
+ Escape(event2) {
634
+ event2.stopPropagation();
635
+ }
636
+ };
637
+ const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
638
+ if (exec) {
639
+ exec(event);
640
+ event.preventDefault();
641
+ }
642
+ }
643
+ });
644
+ },
645
+ getChannelInputProps(props) {
646
+ const { channel } = props;
647
+ const isTextField = channel === "hex" || channel === "css";
648
+ const range = getChannelRange(value, channel);
649
+ return normalize.input({
650
+ ...parts.channelInput.attrs,
651
+ dir: state.context.dir,
652
+ type: isTextField ? "text" : "number",
653
+ "data-channel": channel,
654
+ "aria-label": channel,
655
+ spellCheck: false,
656
+ autoComplete: "off",
657
+ disabled,
658
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
659
+ readOnly: state.context.readOnly,
660
+ defaultValue: getChannelValue(value, channel),
661
+ min: range?.minValue,
662
+ max: range?.maxValue,
663
+ step: range?.step,
664
+ onBeforeInput(event) {
665
+ if (isTextField || !interactive)
666
+ return;
667
+ const value2 = event.currentTarget.value;
668
+ if (value2.match(/[^0-9.]/g)) {
669
+ event.preventDefault();
670
+ }
671
+ },
672
+ onFocus(event) {
673
+ if (!interactive)
674
+ return;
675
+ send({ type: "CHANNEL_INPUT.FOCUS", channel });
676
+ event.target.select();
677
+ },
678
+ onBlur(event) {
679
+ if (!interactive)
680
+ return;
681
+ const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
682
+ send({ type: "CHANNEL_INPUT.BLUR", channel, value: value2, isTextField });
683
+ },
684
+ onKeyDown(event) {
685
+ if (event.defaultPrevented)
686
+ return;
687
+ if (!interactive)
688
+ return;
689
+ if (event.key === "Enter") {
690
+ const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
691
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
692
+ event.preventDefault();
693
+ }
694
+ },
695
+ style: {
696
+ appearance: "none",
697
+ WebkitAppearance: "none",
698
+ MozAppearance: "textfield"
699
+ }
700
+ });
701
+ },
702
+ getHiddenInputProps() {
703
+ return normalize.input({
704
+ type: "text",
705
+ disabled,
706
+ name: state.context.name,
707
+ id: dom.getHiddenInputId(state.context),
708
+ style: import_dom_query2.visuallyHiddenStyle,
709
+ defaultValue: valueAsString
710
+ });
711
+ },
712
+ getEyeDropperTriggerProps() {
713
+ return normalize.button({
714
+ ...parts.eyeDropperTrigger.attrs,
715
+ type: "button",
716
+ dir: state.context.dir,
717
+ disabled,
718
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
719
+ "aria-label": "Pick a color from the screen",
720
+ onClick() {
721
+ if (!interactive)
722
+ return;
723
+ send("EYEDROPPER.CLICK");
724
+ }
725
+ });
726
+ },
727
+ getSwatchGroupProps() {
728
+ return normalize.element({
729
+ ...parts.swatchGroup.attrs,
730
+ role: "group"
731
+ });
732
+ },
733
+ getSwatchTriggerState,
734
+ getSwatchTriggerProps(props) {
735
+ const swatchState = getSwatchTriggerState(props);
736
+ return normalize.button({
737
+ ...parts.swatchTrigger.attrs,
738
+ disabled: swatchState.disabled,
739
+ dir: state.context.dir,
740
+ type: "button",
741
+ "aria-label": `select ${swatchState.valueAsString} as the color`,
742
+ "data-state": swatchState.checked ? "checked" : "unchecked",
743
+ "data-value": swatchState.valueAsString,
744
+ "data-disabled": (0, import_dom_query2.dataAttr)(swatchState.disabled),
745
+ onClick() {
746
+ if (swatchState.disabled)
747
+ return;
748
+ send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
749
+ },
750
+ style: {
751
+ position: "relative"
752
+ }
753
+ });
754
+ },
755
+ getSwatchIndicatorProps(props) {
756
+ const swatchState = getSwatchTriggerState(props);
757
+ return normalize.element({
758
+ ...parts.swatchIndicator.attrs,
759
+ dir: state.context.dir,
760
+ hidden: !swatchState.checked
761
+ });
762
+ },
763
+ getSwatchProps(props) {
764
+ const { respectAlpha = true } = props;
765
+ const swatchState = getSwatchTriggerState(props);
766
+ return normalize.element({
767
+ ...parts.swatch.attrs,
768
+ dir: state.context.dir,
769
+ "data-state": swatchState.checked ? "checked" : "unchecked",
770
+ "data-value": swatchState.valueAsString,
771
+ style: {
772
+ position: "relative",
773
+ background: swatchState.value.toString(respectAlpha ? "css" : "hex")
774
+ }
775
+ });
776
+ },
777
+ getFormatTriggerProps() {
778
+ return normalize.button({
779
+ ...parts.formatTrigger.attrs,
780
+ dir: state.context.dir,
781
+ type: "button",
782
+ "aria-label": `change color format to ${getNextFormat(state.context.format)}`,
783
+ onClick(event) {
784
+ if (event.currentTarget.disabled)
785
+ return;
786
+ const nextFormat = getNextFormat(state.context.format);
787
+ send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" });
788
+ }
789
+ });
790
+ },
791
+ getFormatSelectProps() {
792
+ return normalize.select({
793
+ ...parts.formatSelect.attrs,
794
+ "aria-label": "change color format",
795
+ dir: state.context.dir,
796
+ defaultValue: state.context.format,
797
+ disabled,
798
+ onChange(event) {
799
+ const format = assertFormat(event.currentTarget.value);
800
+ send({ type: "FORMAT.SET", format, src: "format-select" });
801
+ }
802
+ });
803
+ }
804
+ };
805
+ }
806
+ var formats = ["hsba", "hsla", "rgba"];
807
+ var formatRegex = new RegExp(`^(${formats.join("|")})$`);
808
+ function getNextFormat(format) {
809
+ const index = formats.indexOf(format);
810
+ return formats[index + 1] ?? formats[0];
811
+ }
812
+ function assertFormat(format) {
813
+ if (formatRegex.test(format))
814
+ return format;
815
+ throw new Error(`Unsupported color format: ${format}`);
816
+ }
817
+
818
+ // src/color-picker.machine.ts
819
+ var import_color_utils5 = require("@zag-js/color-utils");
820
+ var import_core = require("@zag-js/core");
821
+ var import_dismissable = require("@zag-js/dismissable");
822
+ var import_dom_event3 = require("@zag-js/dom-event");
823
+ var import_dom_query3 = require("@zag-js/dom-query");
824
+ var import_form_utils = require("@zag-js/form-utils");
825
+ var import_popper2 = require("@zag-js/popper");
826
+ var import_text_selection = require("@zag-js/text-selection");
827
+ var import_utils = require("@zag-js/utils");
828
+
829
+ // src/color-picker.parse.ts
830
+ var import_color_utils4 = require("@zag-js/color-utils");
831
+ var parse = (colorString) => {
832
+ return (0, import_color_utils4.parseColor)(colorString);
833
+ };
834
+
835
+ // src/color-picker.machine.ts
836
+ var { and } = import_core.guards;
837
+ function machine(userContext) {
838
+ const ctx = (0, import_utils.compact)(userContext);
839
+ return (0, import_core.createMachine)(
840
+ {
841
+ id: "color-picker",
842
+ initial: ctx.open ? "open" : "idle",
843
+ context: {
844
+ dir: "ltr",
845
+ value: parse("#000000"),
846
+ format: "rgba",
847
+ disabled: false,
848
+ closeOnSelect: false,
849
+ ...ctx,
850
+ activeId: null,
851
+ activeChannel: null,
852
+ activeOrientation: null,
853
+ fieldsetDisabled: false,
854
+ restoreFocus: true,
855
+ positioning: {
856
+ ...ctx.positioning,
857
+ placement: "bottom"
858
+ }
859
+ },
860
+ computed: {
861
+ isRtl: (ctx2) => ctx2.dir === "rtl",
862
+ isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled,
863
+ isInteractive: (ctx2) => !(ctx2.isDisabled || ctx2.readOnly),
864
+ valueAsString: (ctx2) => ctx2.value.toString(ctx2.format),
865
+ areaValue: (ctx2) => {
866
+ const format = ctx2.format.startsWith("hsl") ? "hsla" : "hsba";
867
+ return ctx2.value.toFormat(format);
868
+ }
869
+ },
870
+ activities: ["trackFormControl"],
871
+ watch: {
872
+ value: ["syncInputElements"],
873
+ format: ["syncFormatSelectElement"],
874
+ open: ["toggleVisibility"]
875
+ },
876
+ on: {
877
+ "VALUE.SET": {
878
+ actions: ["setValue"]
879
+ },
880
+ "FORMAT.SET": {
881
+ actions: ["setFormat"]
882
+ },
883
+ "CHANNEL_INPUT.CHANGE": {
884
+ actions: ["setChannelColorFromInput"]
885
+ },
886
+ "EYEDROPPER.CLICK": {
887
+ actions: ["openEyeDropper"]
888
+ }
889
+ },
890
+ states: {
891
+ idle: {
892
+ tags: ["closed"],
893
+ on: {
894
+ "CONTROLLED.OPEN": {
895
+ target: "open",
896
+ actions: ["setInitialFocus"]
897
+ },
898
+ OPEN: [
899
+ {
900
+ guard: "isOpenControlled",
901
+ actions: ["invokeOnOpen"]
902
+ },
903
+ {
904
+ target: "open",
905
+ actions: ["invokeOnOpen", "setInitialFocus"]
906
+ }
907
+ ],
908
+ "TRIGGER.CLICK": [
909
+ {
910
+ guard: "isOpenControlled",
911
+ actions: ["invokeOnOpen"]
912
+ },
913
+ {
914
+ target: "open",
915
+ actions: ["invokeOnOpen", "setInitialFocus"]
916
+ }
917
+ ],
918
+ "CHANNEL_INPUT.FOCUS": {
919
+ target: "focused",
920
+ actions: ["setActiveChannel"]
921
+ }
922
+ }
923
+ },
924
+ focused: {
925
+ tags: ["closed", "focused"],
926
+ on: {
927
+ "CONTROLLED.OPEN": {
928
+ target: "open",
929
+ actions: ["setInitialFocus"]
930
+ },
931
+ OPEN: [
932
+ {
933
+ guard: "isOpenControlled",
934
+ actions: ["invokeOnOpen"]
935
+ },
936
+ {
937
+ target: "open",
938
+ actions: ["invokeOnOpen", "setInitialFocus"]
939
+ }
940
+ ],
941
+ "TRIGGER.CLICK": [
942
+ {
943
+ guard: "isOpenControlled",
944
+ actions: ["invokeOnOpen"]
945
+ },
946
+ {
947
+ target: "open",
948
+ actions: ["invokeOnOpen", "setInitialFocus"]
949
+ }
950
+ ],
951
+ "CHANNEL_INPUT.FOCUS": {
952
+ actions: ["setActiveChannel"]
953
+ },
954
+ "CHANNEL_INPUT.BLUR": {
955
+ target: "idle",
956
+ actions: ["setChannelColorFromInput"]
957
+ },
958
+ "TRIGGER.BLUR": {
959
+ target: "idle"
960
+ }
961
+ }
962
+ },
963
+ open: {
964
+ tags: ["open"],
965
+ activities: ["trackPositioning", "trackDismissableElement"],
966
+ on: {
967
+ "CONTROLLED.CLOSE": [
968
+ {
969
+ guard: "shouldRestoreFocus",
970
+ target: "focused",
971
+ actions: ["setReturnFocus"]
972
+ },
973
+ {
974
+ target: "idle"
975
+ }
976
+ ],
977
+ "TRIGGER.CLICK": [
978
+ {
979
+ guard: "isOpenControlled",
980
+ actions: ["invokeOnClose"]
981
+ },
982
+ {
983
+ target: "idle",
984
+ actions: ["invokeOnClose"]
985
+ }
986
+ ],
987
+ "AREA.POINTER_DOWN": {
988
+ target: "open:dragging",
989
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
990
+ },
991
+ "AREA.FOCUS": {
992
+ actions: ["setActiveChannel"]
993
+ },
994
+ "CHANNEL_SLIDER.POINTER_DOWN": {
995
+ target: "open:dragging",
996
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
997
+ },
998
+ "CHANNEL_SLIDER.FOCUS": {
999
+ actions: ["setActiveChannel"]
1000
+ },
1001
+ "AREA.ARROW_LEFT": {
1002
+ actions: ["decrementXChannel"]
1003
+ },
1004
+ "AREA.ARROW_RIGHT": {
1005
+ actions: ["incrementXChannel"]
1006
+ },
1007
+ "AREA.ARROW_UP": {
1008
+ actions: ["incrementYChannel"]
1009
+ },
1010
+ "AREA.ARROW_DOWN": {
1011
+ actions: ["decrementYChannel"]
1012
+ },
1013
+ "AREA.PAGE_UP": {
1014
+ actions: ["incrementXChannel"]
1015
+ },
1016
+ "AREA.PAGE_DOWN": {
1017
+ actions: ["decrementXChannel"]
1018
+ },
1019
+ "CHANNEL_SLIDER.ARROW_LEFT": {
1020
+ actions: ["decrementChannel"]
1021
+ },
1022
+ "CHANNEL_SLIDER.ARROW_RIGHT": {
1023
+ actions: ["incrementChannel"]
1024
+ },
1025
+ "CHANNEL_SLIDER.ARROW_UP": {
1026
+ actions: ["incrementChannel"]
1027
+ },
1028
+ "CHANNEL_SLIDER.ARROW_DOWN": {
1029
+ actions: ["decrementChannel"]
1030
+ },
1031
+ "CHANNEL_SLIDER.PAGE_UP": {
1032
+ actions: ["incrementChannel"]
1033
+ },
1034
+ "CHANNEL_SLIDER.PAGE_DOWN": {
1035
+ actions: ["decrementChannel"]
1036
+ },
1037
+ "CHANNEL_SLIDER.HOME": {
1038
+ actions: ["setChannelToMin"]
1039
+ },
1040
+ "CHANNEL_SLIDER.END": {
1041
+ actions: ["setChannelToMax"]
1042
+ },
1043
+ "CHANNEL_INPUT.BLUR": {
1044
+ actions: ["setChannelColorFromInput"]
1045
+ },
1046
+ INTERACT_OUTSIDE: [
1047
+ {
1048
+ guard: "isOpenControlled",
1049
+ actions: ["invokeOnClose"]
1050
+ },
1051
+ {
1052
+ guard: "shouldRestoreFocus",
1053
+ target: "focused",
1054
+ actions: ["invokeOnClose", "setReturnFocus"]
1055
+ },
1056
+ {
1057
+ target: "idle",
1058
+ actions: ["invokeOnClose"]
1059
+ }
1060
+ ],
1061
+ CLOSE: [
1062
+ {
1063
+ guard: "isOpenControlled",
1064
+ actions: ["invokeOnClose"]
1065
+ },
1066
+ {
1067
+ target: "idle",
1068
+ actions: ["invokeOnClose"]
1069
+ }
1070
+ ],
1071
+ "SWATCH_TRIGGER.CLICK": [
1072
+ {
1073
+ guard: and("isOpenControlled", "closeOnSelect"),
1074
+ actions: ["setValue", "invokeOnClose"]
1075
+ },
1076
+ {
1077
+ guard: "closeOnSelect",
1078
+ target: "focused",
1079
+ actions: ["setValue", "invokeOnClose", "setReturnFocus"]
1080
+ },
1081
+ {
1082
+ actions: ["setValue"]
1083
+ }
1084
+ ]
1085
+ }
1086
+ },
1087
+ "open:dragging": {
1088
+ tags: ["open"],
1089
+ exit: ["clearActiveChannel"],
1090
+ activities: ["trackPointerMove", "disableTextSelection", "trackPositioning", "trackDismissableElement"],
1091
+ on: {
1092
+ "CONTROLLED.CLOSE": [
1093
+ {
1094
+ guard: "shouldRestoreFocus",
1095
+ target: "focused",
1096
+ actions: ["setReturnFocus"]
1097
+ },
1098
+ {
1099
+ target: "idle"
1100
+ }
1101
+ ],
1102
+ "AREA.POINTER_MOVE": {
1103
+ actions: ["setAreaColorFromPoint", "focusAreaThumb"]
1104
+ },
1105
+ "AREA.POINTER_UP": {
1106
+ target: "open",
1107
+ actions: ["invokeOnChangeEnd"]
1108
+ },
1109
+ "CHANNEL_SLIDER.POINTER_MOVE": {
1110
+ actions: ["setChannelColorFromPoint", "focusChannelThumb"]
1111
+ },
1112
+ "CHANNEL_SLIDER.POINTER_UP": {
1113
+ target: "open",
1114
+ actions: ["invokeOnChangeEnd"]
1115
+ },
1116
+ INTERACT_OUTSIDE: [
1117
+ {
1118
+ guard: "isOpenControlled",
1119
+ actions: ["invokeOnClose"]
1120
+ },
1121
+ {
1122
+ guard: "shouldRestoreFocus",
1123
+ target: "focused",
1124
+ actions: ["invokeOnClose", "setReturnFocus"]
1125
+ },
1126
+ {
1127
+ target: "idle",
1128
+ actions: ["invokeOnClose"]
1129
+ }
1130
+ ],
1131
+ CLOSE: [
1132
+ {
1133
+ guard: "isOpenControlled",
1134
+ actions: ["invokeOnClose"]
1135
+ },
1136
+ {
1137
+ target: "idle",
1138
+ actions: ["invokeOnClose"]
1139
+ }
1140
+ ]
1141
+ }
1142
+ }
1143
+ }
1144
+ },
1145
+ {
1146
+ guards: {
1147
+ closeOnSelect: (ctx2) => !!ctx2.closeOnSelect,
1148
+ isOpenControlled: (ctx2) => !!ctx2["open.controlled"],
1149
+ shouldRestoreFocus: (ctx2) => !!ctx2.restoreFocus
1150
+ },
1151
+ activities: {
1152
+ trackPositioning(ctx2) {
1153
+ ctx2.currentPlacement = ctx2.positioning.placement;
1154
+ const anchorEl = dom.getTriggerEl(ctx2);
1155
+ const getPositionerEl = () => dom.getPositionerEl(ctx2);
1156
+ return (0, import_popper2.getPlacement)(anchorEl, getPositionerEl, {
1157
+ ...ctx2.positioning,
1158
+ defer: true,
1159
+ onComplete(data) {
1160
+ ctx2.currentPlacement = data.placement;
1161
+ }
1162
+ });
1163
+ },
1164
+ trackDismissableElement(ctx2, _evt, { send }) {
1165
+ const getContentEl = () => dom.getContentEl(ctx2);
1166
+ return (0, import_dismissable.trackDismissableElement)(getContentEl, {
1167
+ exclude: dom.getTriggerEl(ctx2),
1168
+ defer: true,
1169
+ onInteractOutside(event) {
1170
+ ctx2.onInteractOutside?.(event);
1171
+ if (event.defaultPrevented)
1172
+ return;
1173
+ ctx2.restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
1174
+ },
1175
+ onPointerDownOutside: ctx2.onPointerDownOutside,
1176
+ onFocusOutside: ctx2.onFocusOutside,
1177
+ onDismiss() {
1178
+ send({ type: "INTERACT_OUTSIDE" });
1179
+ }
1180
+ });
1181
+ },
1182
+ trackFormControl(ctx2, _evt, { send, initialContext }) {
1183
+ const inputEl = dom.getHiddenInputEl(ctx2);
1184
+ return (0, import_form_utils.trackFormControl)(inputEl, {
1185
+ onFieldsetDisabledChange(disabled) {
1186
+ ctx2.fieldsetDisabled = disabled;
1187
+ },
1188
+ onFormReset() {
1189
+ send({ type: "VALUE.SET", value: initialContext.value, src: "form.reset" });
1190
+ }
1191
+ });
1192
+ },
1193
+ trackPointerMove(ctx2, _evt, { send }) {
1194
+ return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
1195
+ onPointerMove({ point }) {
1196
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
1197
+ send({ type, point });
1198
+ },
1199
+ onPointerUp() {
1200
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
1201
+ send({ type });
1202
+ }
1203
+ });
1204
+ },
1205
+ disableTextSelection(ctx2) {
1206
+ return (0, import_text_selection.disableTextSelection)({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
1207
+ }
1208
+ },
1209
+ actions: {
1210
+ openEyeDropper(ctx2) {
1211
+ const isSupported = "EyeDropper" in dom.getWin(ctx2);
1212
+ if (!isSupported)
1213
+ return;
1214
+ const win = dom.getWin(ctx2);
1215
+ const picker = new win.EyeDropper();
1216
+ picker.open().then(({ sRGBHex }) => {
1217
+ const format = ctx2.value.getFormat();
1218
+ const color = (0, import_color_utils5.parseColor)(sRGBHex).toFormat(format);
1219
+ set.value(ctx2, color);
1220
+ ctx2.onValueChangeEnd?.({ value: ctx2.value, valueAsString: ctx2.valueAsString });
1221
+ }).catch(() => void 0);
1222
+ },
1223
+ setActiveChannel(ctx2, evt) {
1224
+ ctx2.activeId = evt.id;
1225
+ if (evt.channel)
1226
+ ctx2.activeChannel = evt.channel;
1227
+ if (evt.orientation)
1228
+ ctx2.activeOrientation = evt.orientation;
1229
+ },
1230
+ clearActiveChannel(ctx2) {
1231
+ ctx2.activeChannel = null;
1232
+ ctx2.activeId = null;
1233
+ ctx2.activeOrientation = null;
1234
+ },
1235
+ setAreaColorFromPoint(ctx2, evt) {
1236
+ const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
1237
+ const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
1238
+ if (!percent)
1239
+ return;
1240
+ const xValue = ctx2.areaValue.getChannelPercentValue(xChannel, percent.x);
1241
+ const yValue = ctx2.areaValue.getChannelPercentValue(yChannel, 1 - percent.y);
1242
+ const color = ctx2.areaValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
1243
+ set.value(ctx2, color);
1244
+ },
1245
+ setChannelColorFromPoint(ctx2, evt) {
1246
+ const channel = evt.channel || ctx2.activeId;
1247
+ const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
1248
+ if (!percent)
1249
+ return;
1250
+ const orientation = ctx2.activeOrientation || "horizontal";
1251
+ const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
1252
+ const value = ctx2.areaValue.getChannelPercentValue(channel, channelPercent);
1253
+ const color = ctx2.areaValue.withChannelValue(channel, value);
1254
+ set.value(ctx2, color);
1255
+ },
1256
+ setValue(ctx2, evt) {
1257
+ set.value(ctx2, evt.value);
1258
+ },
1259
+ setFormat(ctx2, evt) {
1260
+ set.format(ctx2, evt.format);
1261
+ },
1262
+ syncInputElements(ctx2) {
1263
+ sync.inputs(ctx2);
1264
+ },
1265
+ invokeOnChangeEnd(ctx2) {
1266
+ invoke.changeEnd(ctx2);
1267
+ },
1268
+ setChannelColorFromInput(ctx2, evt) {
1269
+ const { channel, isTextField, value } = evt;
1270
+ const currentAlpha = ctx2.value.getChannelValue("alpha");
1271
+ let color;
1272
+ if (channel === "alpha") {
1273
+ let valueAsNumber = parseFloat(value);
1274
+ valueAsNumber = Number.isNaN(valueAsNumber) ? currentAlpha : valueAsNumber;
1275
+ color = ctx2.value.withChannelValue("alpha", valueAsNumber);
1276
+ } else if (isTextField) {
1277
+ color = (0, import_utils.tryCatch)(
1278
+ () => parse(value).withChannelValue("alpha", currentAlpha),
1279
+ () => ctx2.value
1280
+ );
1281
+ } else {
1282
+ const current = ctx2.value.toFormat(ctx2.format);
1283
+ const valueAsNumber = Number.isNaN(value) ? current.getChannelValue(channel) : value;
1284
+ color = current.withChannelValue(channel, valueAsNumber);
1285
+ }
1286
+ sync.inputs(ctx2, color);
1287
+ set.value(ctx2, color);
1288
+ },
1289
+ incrementChannel(ctx2, evt) {
1290
+ const color = ctx2.value.incrementChannel(evt.channel, evt.step);
1291
+ set.value(ctx2, color);
1292
+ },
1293
+ decrementChannel(ctx2, evt) {
1294
+ const color = ctx2.value.decrementChannel(evt.channel, evt.step);
1295
+ set.value(ctx2, color);
1296
+ },
1297
+ incrementXChannel(ctx2, evt) {
1298
+ const { xChannel } = evt.channel;
1299
+ const color = ctx2.areaValue.incrementChannel(xChannel, evt.step);
1300
+ set.value(ctx2, color);
1301
+ },
1302
+ decrementXChannel(ctx2, evt) {
1303
+ const { xChannel } = evt.channel;
1304
+ const color = ctx2.areaValue.decrementChannel(xChannel, evt.step);
1305
+ set.value(ctx2, color);
1306
+ },
1307
+ incrementYChannel(ctx2, evt) {
1308
+ const { yChannel } = evt.channel;
1309
+ const color = ctx2.areaValue.incrementChannel(yChannel, evt.step);
1310
+ set.value(ctx2, color);
1311
+ },
1312
+ decrementYChannel(ctx2, evt) {
1313
+ const { yChannel } = evt.channel;
1314
+ const color = ctx2.areaValue.decrementChannel(yChannel, evt.step);
1315
+ set.value(ctx2, color);
1316
+ },
1317
+ setChannelToMax(ctx2, evt) {
1318
+ const range = ctx2.value.getChannelRange(evt.channel);
1319
+ const color = ctx2.value.withChannelValue(evt.channel, range.maxValue);
1320
+ set.value(ctx2, color);
1321
+ },
1322
+ setChannelToMin(ctx2, evt) {
1323
+ const range = ctx2.value.getChannelRange(evt.channel);
1324
+ const color = ctx2.value.withChannelValue(evt.channel, range.minValue);
1325
+ set.value(ctx2, color);
1326
+ },
1327
+ focusAreaThumb(ctx2) {
1328
+ (0, import_dom_query3.raf)(() => {
1329
+ dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
1330
+ });
1331
+ },
1332
+ focusChannelThumb(ctx2, evt) {
1333
+ (0, import_dom_query3.raf)(() => {
1334
+ dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
1335
+ });
1336
+ },
1337
+ setInitialFocus(ctx2) {
1338
+ (0, import_dom_query3.raf)(() => {
1339
+ const element = (0, import_dom_query3.getInitialFocus)({
1340
+ root: dom.getContentEl(ctx2),
1341
+ getInitialEl: ctx2.initialFocusEl
1342
+ });
1343
+ element?.focus({ preventScroll: true });
1344
+ });
1345
+ },
1346
+ setReturnFocus(ctx2) {
1347
+ (0, import_dom_query3.raf)(() => {
1348
+ dom.getTriggerEl(ctx2)?.focus({ preventScroll: true });
1349
+ });
1350
+ },
1351
+ syncFormatSelectElement(ctx2) {
1352
+ sync.formatSelect(ctx2);
1353
+ },
1354
+ invokeOnOpen(ctx2) {
1355
+ ctx2.onOpenChange?.({ open: true });
1356
+ },
1357
+ invokeOnClose(ctx2) {
1358
+ ctx2.onOpenChange?.({ open: false });
1359
+ },
1360
+ toggleVisibility(ctx2, evt, { send }) {
1361
+ send({ type: ctx2.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: evt });
1362
+ }
1363
+ },
1364
+ compareFns: {
1365
+ value: (a, b) => a.isEqual(b)
1366
+ }
1367
+ }
1368
+ );
1369
+ }
1370
+ var sync = {
1371
+ // sync channel inputs
1372
+ inputs(ctx, color) {
1373
+ const channelInputs = dom.getChannelInputEls(ctx);
1374
+ (0, import_dom_query3.raf)(() => {
1375
+ channelInputs.forEach((inputEl) => {
1376
+ const channel = inputEl.dataset.channel;
1377
+ dom.setValue(inputEl, getChannelValue(color || ctx.value, channel));
1378
+ });
1379
+ });
1380
+ },
1381
+ // sync format select
1382
+ formatSelect(ctx) {
1383
+ const selectEl = dom.getFormatSelectEl(ctx);
1384
+ (0, import_dom_query3.raf)(() => {
1385
+ dom.setValue(selectEl, ctx.format);
1386
+ });
1387
+ }
1388
+ };
1389
+ var invoke = {
1390
+ changeEnd(ctx) {
1391
+ const value = ctx.value.toFormat(ctx.format);
1392
+ ctx.onValueChangeEnd?.({
1393
+ value,
1394
+ valueAsString: ctx.valueAsString
1395
+ });
1396
+ },
1397
+ change(ctx) {
1398
+ const value = ctx.value.toFormat(ctx.format);
1399
+ ctx.onValueChange?.({
1400
+ value,
1401
+ valueAsString: ctx.valueAsString
1402
+ });
1403
+ (0, import_form_utils.dispatchInputValueEvent)(dom.getHiddenInputEl(ctx), { value: ctx.valueAsString });
1404
+ },
1405
+ formatChange(ctx) {
1406
+ ctx.onFormatChange?.({ format: ctx.format });
1407
+ }
1408
+ };
1409
+ var set = {
1410
+ value(ctx, color) {
1411
+ if (!color || ctx.value.isEqual(color))
1412
+ return;
1413
+ ctx.value = color;
1414
+ invoke.change(ctx);
1415
+ },
1416
+ format(ctx, format) {
1417
+ if (ctx.format === format)
1418
+ return;
1419
+ ctx.format = format;
1420
+ invoke.formatChange(ctx);
1421
+ }
1422
+ };
1423
+ // Annotate the CommonJS export names for ESM import in node:
1424
+ 0 && (module.exports = {
1425
+ anatomy,
1426
+ connect,
1427
+ machine,
1428
+ parse
1429
+ });
2
1430
  //# sourceMappingURL=index.js.map