@zag-js/radio-group 1.47.0 → 1.48.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.
@@ -1,91 +1,53 @@
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/radio-group.dom.ts
21
- var radio_group_dom_exports = {};
22
- __export(radio_group_dom_exports, {
23
- getFirstEnabledAndCheckedInputEl: () => getFirstEnabledAndCheckedInputEl,
24
- getFirstEnabledInputEl: () => getFirstEnabledInputEl,
25
- getIndicatorEl: () => getIndicatorEl,
26
- getIndicatorId: () => getIndicatorId,
27
- getInputEls: () => getInputEls,
28
- getItemControlId: () => getItemControlId,
29
- getItemHiddenInputEl: () => getItemHiddenInputEl,
30
- getItemHiddenInputId: () => getItemHiddenInputId,
31
- getItemId: () => getItemId,
32
- getItemLabelId: () => getItemLabelId,
33
- getLabelId: () => getLabelId,
34
- getOffsetRect: () => getOffsetRect,
35
- getRadioEl: () => getRadioEl,
36
- getRectById: () => getRectById,
37
- getRootEl: () => getRootEl,
38
- getRootId: () => getRootId
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
39
4
  });
40
- module.exports = __toCommonJS(radio_group_dom_exports);
41
- var import_dom_query = require("@zag-js/dom-query");
42
- var getRootId = (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`;
43
- var getLabelId = (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`;
44
- var getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`;
45
- var getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`;
46
- var getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`;
47
- var getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`;
48
- var getIndicatorId = (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`;
49
- var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
50
- var getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
51
- var getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
52
- var getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
53
- var getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
54
- var getInputEls = (ctx) => {
55
- const selector = `input[type=radio]${(0, import_dom_query.getByOwnerId)(getRootId(ctx))}`;
56
- return (0, import_dom_query.queryAll)(getRootEl(ctx), selector);
5
+ let _zag_js_dom_query = require("@zag-js/dom-query");
6
+ // src/radio-group.dom.ts
7
+ const getRootId = (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`;
8
+ const getLabelId = (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`;
9
+ const getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`;
10
+ const getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`;
11
+ const getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`;
12
+ const getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`;
13
+ const getIndicatorId = (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`;
14
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
15
+ const getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
16
+ const getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
17
+ const getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
18
+ const getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
19
+ const getInputEls = (ctx) => {
20
+ const selector = `input[type=radio]${(0, _zag_js_dom_query.getByOwnerId)(getRootId(ctx))}`;
21
+ return (0, _zag_js_dom_query.queryAll)(getRootEl(ctx), selector);
57
22
  };
58
- var getRadioEl = (ctx, value) => {
59
- if (!value) return;
60
- return ctx.getById(getItemId(ctx, value));
23
+ const getRadioEl = (ctx, value) => {
24
+ if (!value) return;
25
+ return ctx.getById(getItemId(ctx, value));
61
26
  };
62
- var getOffsetRect = (el) => ({
63
- x: el?.offsetLeft ?? 0,
64
- y: el?.offsetTop ?? 0,
65
- width: el?.offsetWidth ?? 0,
66
- height: el?.offsetHeight ?? 0
27
+ const getOffsetRect = (el) => ({
28
+ x: el?.offsetLeft ?? 0,
29
+ y: el?.offsetTop ?? 0,
30
+ width: el?.offsetWidth ?? 0,
31
+ height: el?.offsetHeight ?? 0
67
32
  });
68
- var getRectById = (ctx, id) => {
69
- const radioEl = ctx.getById(getItemId(ctx, id));
70
- if (!radioEl) return;
71
- return getOffsetRect(radioEl);
33
+ const getRectById = (ctx, id) => {
34
+ const radioEl = ctx.getById(getItemId(ctx, id));
35
+ if (!radioEl) return;
36
+ return getOffsetRect(radioEl);
72
37
  };
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- getFirstEnabledAndCheckedInputEl,
76
- getFirstEnabledInputEl,
77
- getIndicatorEl,
78
- getIndicatorId,
79
- getInputEls,
80
- getItemControlId,
81
- getItemHiddenInputEl,
82
- getItemHiddenInputId,
83
- getItemId,
84
- getItemLabelId,
85
- getLabelId,
86
- getOffsetRect,
87
- getRadioEl,
88
- getRectById,
89
- getRootEl,
90
- getRootId
91
- });
38
+ exports.getFirstEnabledAndCheckedInputEl = getFirstEnabledAndCheckedInputEl;
39
+ exports.getFirstEnabledInputEl = getFirstEnabledInputEl;
40
+ exports.getIndicatorEl = getIndicatorEl;
41
+ exports.getIndicatorId = getIndicatorId;
42
+ exports.getInputEls = getInputEls;
43
+ exports.getItemControlId = getItemControlId;
44
+ exports.getItemHiddenInputEl = getItemHiddenInputEl;
45
+ exports.getItemHiddenInputId = getItemHiddenInputId;
46
+ exports.getItemId = getItemId;
47
+ exports.getItemLabelId = getItemLabelId;
48
+ exports.getLabelId = getLabelId;
49
+ exports.getOffsetRect = getOffsetRect;
50
+ exports.getRadioEl = getRadioEl;
51
+ exports.getRectById = getRectById;
52
+ exports.getRootEl = getRootEl;
53
+ exports.getRootId = getRootId;
@@ -1,51 +1,34 @@
1
- // src/radio-group.dom.ts
2
1
  import { getByOwnerId, queryAll } from "@zag-js/dom-query";
3
- var getRootId = (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`;
4
- var getLabelId = (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`;
5
- var getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`;
6
- var getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`;
7
- var getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`;
8
- var getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`;
9
- var getIndicatorId = (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`;
10
- var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
11
- var getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
12
- var getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
13
- var getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
14
- var getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
15
- var getInputEls = (ctx) => {
16
- const selector = `input[type=radio]${getByOwnerId(getRootId(ctx))}`;
17
- return queryAll(getRootEl(ctx), selector);
2
+ // src/radio-group.dom.ts
3
+ const getRootId = (ctx) => ctx.ids?.root ?? `radio-group:${ctx.id}`;
4
+ const getLabelId = (ctx) => ctx.ids?.label ?? `radio-group:${ctx.id}:label`;
5
+ const getItemId = (ctx, value) => ctx.ids?.item?.(value) ?? `radio-group:${ctx.id}:radio:${value}`;
6
+ const getItemHiddenInputId = (ctx, value) => ctx.ids?.itemHiddenInput?.(value) ?? `radio-group:${ctx.id}:radio:input:${value}`;
7
+ const getItemControlId = (ctx, value) => ctx.ids?.itemControl?.(value) ?? `radio-group:${ctx.id}:radio:control:${value}`;
8
+ const getItemLabelId = (ctx, value) => ctx.ids?.itemLabel?.(value) ?? `radio-group:${ctx.id}:radio:label:${value}`;
9
+ const getIndicatorId = (ctx) => ctx.ids?.indicator ?? `radio-group:${ctx.id}:indicator`;
10
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
11
+ const getItemHiddenInputEl = (ctx, value) => ctx.getById(getItemHiddenInputId(ctx, value));
12
+ const getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
13
+ const getFirstEnabledInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled)");
14
+ const getFirstEnabledAndCheckedInputEl = (ctx) => getRootEl(ctx)?.querySelector("input:not(:disabled):checked");
15
+ const getInputEls = (ctx) => {
16
+ const selector = `input[type=radio]${getByOwnerId(getRootId(ctx))}`;
17
+ return queryAll(getRootEl(ctx), selector);
18
18
  };
19
- var getRadioEl = (ctx, value) => {
20
- if (!value) return;
21
- return ctx.getById(getItemId(ctx, value));
19
+ const getRadioEl = (ctx, value) => {
20
+ if (!value) return;
21
+ return ctx.getById(getItemId(ctx, value));
22
22
  };
23
- var getOffsetRect = (el) => ({
24
- x: el?.offsetLeft ?? 0,
25
- y: el?.offsetTop ?? 0,
26
- width: el?.offsetWidth ?? 0,
27
- height: el?.offsetHeight ?? 0
23
+ const getOffsetRect = (el) => ({
24
+ x: el?.offsetLeft ?? 0,
25
+ y: el?.offsetTop ?? 0,
26
+ width: el?.offsetWidth ?? 0,
27
+ height: el?.offsetHeight ?? 0
28
28
  });
29
- var getRectById = (ctx, id) => {
30
- const radioEl = ctx.getById(getItemId(ctx, id));
31
- if (!radioEl) return;
32
- return getOffsetRect(radioEl);
33
- };
34
- export {
35
- getFirstEnabledAndCheckedInputEl,
36
- getFirstEnabledInputEl,
37
- getIndicatorEl,
38
- getIndicatorId,
39
- getInputEls,
40
- getItemControlId,
41
- getItemHiddenInputEl,
42
- getItemHiddenInputId,
43
- getItemId,
44
- getItemLabelId,
45
- getLabelId,
46
- getOffsetRect,
47
- getRadioEl,
48
- getRectById,
49
- getRootEl,
50
- getRootId
29
+ const getRectById = (ctx, id) => {
30
+ const radioEl = ctx.getById(getItemId(ctx, id));
31
+ if (!radioEl) return;
32
+ return getOffsetRect(radioEl);
51
33
  };
34
+ export { getFirstEnabledAndCheckedInputEl, getFirstEnabledInputEl, getIndicatorEl, getIndicatorId, getInputEls, getItemControlId, getItemHiddenInputEl, getItemHiddenInputId, getItemId, getItemLabelId, getLabelId, getOffsetRect, getRadioEl, getRectById, getRootEl, getRootId };
@@ -1,7 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { RadioGroupSchema } from './radio-group.types.mjs';
3
- import '@zag-js/types';
4
-
5
- declare const machine: _zag_js_core.Machine<RadioGroupSchema>;
6
-
7
- export { machine };
1
+ import { RadioGroupSchema } from "./radio-group.types.mjs";
2
+ export declare const machine: import("@zag-js/core").Machine<RadioGroupSchema>;
@@ -1,7 +1,2 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { RadioGroupSchema } from './radio-group.types.js';
3
- import '@zag-js/types';
4
-
5
- declare const machine: _zag_js_core.Machine<RadioGroupSchema>;
6
-
7
- export { machine };
1
+ import { RadioGroupSchema } from "./radio-group.types.js";
2
+ export declare const machine: import("@zag-js/core").Machine<RadioGroupSchema>;
@@ -1,219 +1,157 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/radio-group.machine.ts
31
- var radio_group_machine_exports = {};
32
- __export(radio_group_machine_exports, {
33
- machine: () => machine
34
- });
35
- module.exports = __toCommonJS(radio_group_machine_exports);
36
- var import_core = require("@zag-js/core");
37
- var import_dom_query = require("@zag-js/dom-query");
38
- var import_focus_visible = require("@zag-js/focus-visible");
39
- var dom = __toESM(require("./radio-group.dom.js"));
40
- var { not } = (0, import_core.createGuards)();
41
- var machine = (0, import_core.createMachine)({
42
- props({ props }) {
43
- return {
44
- orientation: "vertical",
45
- ...props
46
- };
47
- },
48
- initialState() {
49
- return "idle";
50
- },
51
- context({ prop, bindable }) {
52
- return {
53
- value: bindable(() => ({
54
- defaultValue: prop("defaultValue"),
55
- value: prop("value"),
56
- onChange(value) {
57
- prop("onValueChange")?.({ value });
58
- }
59
- })),
60
- activeValue: bindable(() => ({
61
- defaultValue: null
62
- })),
63
- focusedValue: bindable(() => ({
64
- defaultValue: null
65
- })),
66
- focusVisibleValue: bindable(() => ({
67
- defaultValue: null
68
- })),
69
- hoveredValue: bindable(() => ({
70
- defaultValue: null
71
- })),
72
- indicatorRect: bindable(() => ({
73
- defaultValue: null
74
- })),
75
- animateIndicator: bindable(() => ({
76
- defaultValue: false
77
- })),
78
- fieldsetDisabled: bindable(() => ({
79
- defaultValue: false
80
- })),
81
- ssr: bindable(() => ({
82
- defaultValue: true
83
- }))
84
- };
85
- },
86
- refs() {
87
- return {
88
- indicatorCleanup: null,
89
- focusVisibleValue: null,
90
- prevValue: null
91
- };
92
- },
93
- computed: {
94
- isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled")
95
- },
96
- entry: ["syncPrevValue", "syncIndicatorRect", "syncSsr"],
97
- exit: ["cleanupObserver"],
98
- effects: ["trackFormControlState", "trackFocusVisible"],
99
- watch({ track, action, context }) {
100
- track([() => context.get("value")], () => {
101
- action(["syncIndicatorAnimation", "syncIndicatorRect", "syncInputElements"]);
102
- });
103
- },
104
- on: {
105
- SET_VALUE: [
106
- {
107
- guard: not("isTrusted"),
108
- actions: ["setValue", "dispatchChangeEvent"]
109
- },
110
- {
111
- actions: ["setValue"]
112
- }
113
- ],
114
- SET_HOVERED: {
115
- actions: ["setHovered"]
116
- },
117
- SET_ACTIVE: {
118
- actions: ["setActive"]
119
- },
120
- SET_FOCUSED: {
121
- actions: ["setFocused"]
122
- },
123
- INDICATOR_TRANSITION_END: {
124
- actions: ["clearIndicatorAnimation"]
125
- }
126
- },
127
- states: {
128
- idle: {}
129
- },
130
- implementations: {
131
- guards: {
132
- isTrusted: ({ event }) => !!event.isTrusted
133
- },
134
- effects: {
135
- trackFormControlState({ context, scope }) {
136
- return (0, import_dom_query.trackFormControl)(dom.getRootEl(scope), {
137
- onFieldsetDisabledChange(disabled) {
138
- context.set("fieldsetDisabled", disabled);
139
- },
140
- onFormReset() {
141
- context.set("value", context.initial("value"));
142
- }
143
- });
144
- },
145
- trackFocusVisible({ scope }) {
146
- return (0, import_focus_visible.trackFocusVisible)({ root: scope.getRootNode?.() });
147
- }
148
- },
149
- actions: {
150
- setValue({ context, event }) {
151
- context.set("value", event.value);
152
- },
153
- setHovered({ context, event }) {
154
- context.set("hoveredValue", event.value);
155
- },
156
- setActive({ context, event }) {
157
- context.set("activeValue", event.value);
158
- },
159
- setFocused({ context, event }) {
160
- context.set("focusedValue", event.value);
161
- const focusVisibleValue = event.value != null && event.focusVisible ? event.value : null;
162
- context.set("focusVisibleValue", focusVisibleValue);
163
- },
164
- syncPrevValue({ context, refs }) {
165
- refs.set("prevValue", context.get("value"));
166
- },
167
- syncIndicatorAnimation({ context, refs }) {
168
- const prevValue = refs.get("prevValue");
169
- const nextValue = context.get("value");
170
- const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
171
- context.set("animateIndicator", animate);
172
- refs.set("prevValue", nextValue);
173
- },
174
- clearIndicatorAnimation({ context }) {
175
- context.set("animateIndicator", false);
176
- },
177
- syncInputElements({ context, scope }) {
178
- const inputs = dom.getInputEls(scope);
179
- inputs.forEach((input) => {
180
- input.checked = input.value === context.get("value");
181
- });
182
- },
183
- cleanupObserver({ refs }) {
184
- refs.get("indicatorCleanup")?.();
185
- },
186
- syncSsr({ context }) {
187
- context.set("ssr", false);
188
- },
189
- syncIndicatorRect({ context, scope, refs }) {
190
- refs.get("indicatorCleanup")?.();
191
- if (!dom.getIndicatorEl(scope)) return;
192
- const value = context.get("value");
193
- const radioEl = dom.getRadioEl(scope, value);
194
- if (value == null || !radioEl) {
195
- context.set("indicatorRect", null);
196
- return;
197
- }
198
- const exec = () => {
199
- context.set("indicatorRect", dom.getOffsetRect(radioEl));
200
- };
201
- exec();
202
- const indicatorCleanup = import_dom_query.resizeObserverBorderBox.observe(radioEl, exec);
203
- refs.set("indicatorCleanup", indicatorCleanup);
204
- },
205
- dispatchChangeEvent({ context, scope }) {
206
- const inputEls = dom.getInputEls(scope);
207
- inputEls.forEach((inputEl) => {
208
- const checked = inputEl.value === context.get("value");
209
- if (checked === inputEl.checked) return;
210
- (0, import_dom_query.dispatchInputCheckedEvent)(inputEl, { checked });
211
- });
212
- }
213
- }
214
- }
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
215
4
  });
216
- // Annotate the CommonJS export names for ESM import in node:
217
- 0 && (module.exports = {
218
- machine
5
+ const require_radio_group_dom = require("./radio-group.dom.js");
6
+ let _zag_js_dom_query = require("@zag-js/dom-query");
7
+ let _zag_js_focus_visible = require("@zag-js/focus-visible");
8
+ let _zag_js_core = require("@zag-js/core");
9
+ // src/radio-group.machine.ts
10
+ const { not } = (0, _zag_js_core.createGuards)();
11
+ const machine = (0, _zag_js_core.createMachine)({
12
+ props({ props }) {
13
+ return {
14
+ orientation: "vertical",
15
+ ...props
16
+ };
17
+ },
18
+ initialState() {
19
+ return "idle";
20
+ },
21
+ context({ prop, bindable }) {
22
+ return {
23
+ value: bindable(() => ({
24
+ defaultValue: prop("defaultValue"),
25
+ value: prop("value"),
26
+ onChange(value) {
27
+ prop("onValueChange")?.({ value });
28
+ }
29
+ })),
30
+ activeValue: bindable(() => ({ defaultValue: null })),
31
+ focusedValue: bindable(() => ({ defaultValue: null })),
32
+ focusVisibleValue: bindable(() => ({ defaultValue: null })),
33
+ hoveredValue: bindable(() => ({ defaultValue: null })),
34
+ indicatorRect: bindable(() => ({ defaultValue: null })),
35
+ animateIndicator: bindable(() => ({ defaultValue: false })),
36
+ fieldsetDisabled: bindable(() => ({ defaultValue: false })),
37
+ ssr: bindable(() => ({ defaultValue: true }))
38
+ };
39
+ },
40
+ refs() {
41
+ return {
42
+ indicatorCleanup: null,
43
+ focusVisibleValue: null,
44
+ prevValue: null
45
+ };
46
+ },
47
+ computed: { isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled") },
48
+ entry: [
49
+ "syncPrevValue",
50
+ "syncIndicatorRect",
51
+ "syncSsr"
52
+ ],
53
+ exit: ["cleanupObserver"],
54
+ effects: ["trackFormControlState", "trackFocusVisible"],
55
+ watch({ track, action, context }) {
56
+ track([() => context.get("value")], () => {
57
+ action([
58
+ "syncIndicatorAnimation",
59
+ "syncIndicatorRect",
60
+ "syncInputElements"
61
+ ]);
62
+ });
63
+ },
64
+ on: {
65
+ SET_VALUE: [{
66
+ guard: not("isTrusted"),
67
+ actions: ["setValue", "dispatchChangeEvent"]
68
+ }, { actions: ["setValue"] }],
69
+ SET_HOVERED: { actions: ["setHovered"] },
70
+ SET_ACTIVE: { actions: ["setActive"] },
71
+ SET_FOCUSED: { actions: ["setFocused"] },
72
+ INDICATOR_TRANSITION_END: { actions: ["clearIndicatorAnimation"] }
73
+ },
74
+ states: { idle: {} },
75
+ implementations: {
76
+ guards: { isTrusted: ({ event }) => !!event.isTrusted },
77
+ effects: {
78
+ trackFormControlState({ context, scope }) {
79
+ return (0, _zag_js_dom_query.trackFormControl)(require_radio_group_dom.getRootEl(scope), {
80
+ onFieldsetDisabledChange(disabled) {
81
+ context.set("fieldsetDisabled", disabled);
82
+ },
83
+ onFormReset() {
84
+ context.set("value", context.initial("value"));
85
+ }
86
+ });
87
+ },
88
+ trackFocusVisible({ scope }) {
89
+ return (0, _zag_js_focus_visible.trackFocusVisible)({ root: scope.getRootNode?.() });
90
+ }
91
+ },
92
+ actions: {
93
+ setValue({ context, event }) {
94
+ context.set("value", event.value);
95
+ },
96
+ setHovered({ context, event }) {
97
+ context.set("hoveredValue", event.value);
98
+ },
99
+ setActive({ context, event }) {
100
+ context.set("activeValue", event.value);
101
+ },
102
+ setFocused({ context, event }) {
103
+ context.set("focusedValue", event.value);
104
+ const focusVisibleValue = event.value != null && event.focusVisible ? event.value : null;
105
+ context.set("focusVisibleValue", focusVisibleValue);
106
+ },
107
+ syncPrevValue({ context, refs }) {
108
+ refs.set("prevValue", context.get("value"));
109
+ },
110
+ syncIndicatorAnimation({ context, refs }) {
111
+ const prevValue = refs.get("prevValue");
112
+ const nextValue = context.get("value");
113
+ const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
114
+ context.set("animateIndicator", animate);
115
+ refs.set("prevValue", nextValue);
116
+ },
117
+ clearIndicatorAnimation({ context }) {
118
+ context.set("animateIndicator", false);
119
+ },
120
+ syncInputElements({ context, scope }) {
121
+ require_radio_group_dom.getInputEls(scope).forEach((input) => {
122
+ input.checked = input.value === context.get("value");
123
+ });
124
+ },
125
+ cleanupObserver({ refs }) {
126
+ refs.get("indicatorCleanup")?.();
127
+ },
128
+ syncSsr({ context }) {
129
+ context.set("ssr", false);
130
+ },
131
+ syncIndicatorRect({ context, scope, refs }) {
132
+ refs.get("indicatorCleanup")?.();
133
+ if (!require_radio_group_dom.getIndicatorEl(scope)) return;
134
+ const value = context.get("value");
135
+ const radioEl = require_radio_group_dom.getRadioEl(scope, value);
136
+ if (value == null || !radioEl) {
137
+ context.set("indicatorRect", null);
138
+ return;
139
+ }
140
+ const exec = () => {
141
+ context.set("indicatorRect", require_radio_group_dom.getOffsetRect(radioEl));
142
+ };
143
+ exec();
144
+ const indicatorCleanup = _zag_js_dom_query.resizeObserverBorderBox.observe(radioEl, exec);
145
+ refs.set("indicatorCleanup", indicatorCleanup);
146
+ },
147
+ dispatchChangeEvent({ context, scope }) {
148
+ require_radio_group_dom.getInputEls(scope).forEach((inputEl) => {
149
+ const checked = inputEl.value === context.get("value");
150
+ if (checked === inputEl.checked) return;
151
+ (0, _zag_js_dom_query.dispatchInputCheckedEvent)(inputEl, { checked });
152
+ });
153
+ }
154
+ }
155
+ }
219
156
  });
157
+ exports.machine = machine;