@tamagui/switch-headless 1.110.5 → 1.111.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.
@@ -27,107 +27,11 @@ __export(useSwitch_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(useSwitch_exports);
29
29
  var import_jsx_runtime = require("react/jsx-runtime"), import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_helpers = require("@tamagui/helpers"), import_label = require("@tamagui/label"), import_use_previous = require("@tamagui/use-previous"), React = __toESM(require("react"));
30
- function _array_like_to_array(arr, len) {
31
- (len == null || len > arr.length) && (len = arr.length);
32
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
33
- return arr2;
34
- }
35
- function _array_with_holes(arr) {
36
- if (Array.isArray(arr)) return arr;
37
- }
38
- function _define_property(obj, key, value) {
39
- return key in obj ? Object.defineProperty(obj, key, {
40
- value,
41
- enumerable: !0,
42
- configurable: !0,
43
- writable: !0
44
- }) : obj[key] = value, obj;
45
- }
46
- function _iterable_to_array_limit(arr, i) {
47
- var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
48
- if (_i != null) {
49
- var _arr = [], _n = !0, _d = !1, _s, _e;
50
- try {
51
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
52
- ;
53
- } catch (err) {
54
- _d = !0, _e = err;
55
- } finally {
56
- try {
57
- !_n && _i.return != null && _i.return();
58
- } finally {
59
- if (_d) throw _e;
60
- }
61
- }
62
- return _arr;
63
- }
64
- }
65
- function _non_iterable_rest() {
66
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
67
- }
68
- function _object_spread(target) {
69
- for (var i = 1; i < arguments.length; i++) {
70
- var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
71
- typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
72
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
73
- }))), ownKeys2.forEach(function(key) {
74
- _define_property(target, key, source[key]);
75
- });
76
- }
77
- return target;
78
- }
79
- function ownKeys(object, enumerableOnly) {
80
- var keys = Object.keys(object);
81
- if (Object.getOwnPropertySymbols) {
82
- var symbols = Object.getOwnPropertySymbols(object);
83
- enumerableOnly && (symbols = symbols.filter(function(sym) {
84
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
85
- })), keys.push.apply(keys, symbols);
86
- }
87
- return keys;
88
- }
89
- function _object_spread_props(target, source) {
90
- return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
91
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
- }), target;
93
- }
94
- function _object_without_properties(source, excluded) {
95
- if (source == null) return {};
96
- var target = _object_without_properties_loose(source, excluded), key, i;
97
- if (Object.getOwnPropertySymbols) {
98
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
99
- for (i = 0; i < sourceSymbolKeys.length; i++)
100
- key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
101
- }
102
- return target;
103
- }
104
- function _object_without_properties_loose(source, excluded) {
105
- if (source == null) return {};
106
- var target = {}, sourceKeys = Object.keys(source), key, i;
107
- for (i = 0; i < sourceKeys.length; i++)
108
- key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
109
- return target;
110
- }
111
- function _sliced_to_array(arr, i) {
112
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
113
- }
114
- function _unsupported_iterable_to_array(o, minLen) {
115
- if (o) {
116
- if (typeof o == "string") return _array_like_to_array(o, minLen);
117
- var n = Object.prototype.toString.call(o).slice(8, -1);
118
- if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
119
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
120
- }
121
- }
122
30
  function getState(checked) {
123
31
  return checked ? "checked" : "unchecked";
124
32
  }
125
33
  var BubbleInput = function(props) {
126
- var control = props.control, checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, inputProps = _object_without_properties(props, [
127
- "control",
128
- "checked",
129
- "bubbles"
130
- ]), ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
34
+ var { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = (0, import_use_previous.usePrevious)(checked);
131
35
  return React.useEffect(function() {
132
36
  var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
133
37
  if (prevChecked !== checked && setChecked) {
@@ -141,40 +45,42 @@ var BubbleInput = function(props) {
141
45
  checked,
142
46
  bubbles
143
47
  ]), // @ts-ignore
144
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", _object_spread_props(_object_spread({
48
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
145
49
  type: "checkbox",
146
50
  "aria-hidden": !0,
147
- defaultChecked: checked
148
- }, inputProps), {
51
+ defaultChecked: checked,
52
+ ...inputProps,
149
53
  tabIndex: -1,
150
54
  ref,
151
- style: _object_spread_props(_object_spread({}, props.style), {
55
+ style: {
56
+ ...props.style,
152
57
  position: "absolute",
153
58
  pointerEvents: "none",
154
59
  opacity: 0,
155
60
  margin: 0
156
- })
157
- }));
61
+ }
62
+ });
158
63
  };
159
64
  function useSwitch(props, param, ref) {
160
- var _param = _sliced_to_array(param, 2), checked = _param[0], setChecked = _param[1], disabled = props.disabled, name = props.name, value = props.value, required = props.required, hasConsumerStoppedPropagationRef = React.useRef(!1), _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton), isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = (0, import_label.useLabelContext)(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
65
+ var [checked, setChecked] = param, { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = (0, import_compose_refs.useComposedRefs)(ref, setButton), isFormControl = import_constants.isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = (0, import_label.useLabelContext)(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
161
66
  return {
162
- switchProps: _object_spread_props(_object_spread({
67
+ switchProps: {
163
68
  role: "switch",
164
- "aria-checked": checked
165
- }, import_constants.isWeb ? {
166
- tabIndex: disabled ? void 0 : 0,
167
- "data-state": getState(checked),
168
- "data-disabled": disabled ? "" : void 0,
169
- disabled
170
- } : {}, props), {
69
+ "aria-checked": checked,
70
+ ...import_constants.isWeb ? {
71
+ tabIndex: disabled ? void 0 : 0,
72
+ "data-state": getState(checked),
73
+ "data-disabled": disabled ? "" : void 0,
74
+ disabled
75
+ } : {},
76
+ ...props,
171
77
  "aria-labelledby": ariaLabelledBy,
172
78
  onPress: (0, import_helpers.composeEventHandlers)(props.onPress, function(event) {
173
79
  setChecked(function(prevChecked) {
174
80
  return !prevChecked;
175
81
  }), import_constants.isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
176
82
  })
177
- }),
83
+ },
178
84
  switchRef: composedRefs,
179
85
  /**
180
86
  * insert as a sibling of your switch (should not be inside the switch)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/t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leInput", "props", "control", "bubbles", "inputProps", "ref", "React", "useRef", "prevChecked", "usePrevious", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "_jsx", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "useState", "button", "setButton", "composedRefs", "useComposedRefs", "isFormControl", "isWeb", "Boolean", "closest", "labelId", "useLabelContext", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "composeEventHandlers", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAAA,sBAAgC,kCAChC,mBAAsB,+BACtB,iBAAqC,6BACrC,eAAgC,2BAChC,sBAA4B,kCAC5B,QAAuB;AAmBvB,SAASA,SAASC,SAAoB;AACpC,SAAOA,UAAU,YAAY;AAC/B;AAWA,IAAMC,cAAc,SAACC,OAAAA;AACnB,MAAM,EAAEC,SAASH,SAASI,UAAU,IAAM,GAAGC,WAAAA,IAAeH,OACtDI,MAAMC,MAAMC,OAAyB,IAAA,GACrCC,kBAAcC,iCAAYV,OAAAA;AAGhCO,eAAMI,UAAU,WAAA;AACd,QAAMC,QAAQN,IAAIO,SACZC,aAAaC,OAAOC,iBAAiBC,WACrCC,aAAaC,OAAOC,yBACxBN,YACA,SAAA,GAEIO,aAAaH,WAAWI;AAC9B,QAAIb,gBAAgBT,WAAWqB,YAAY;AACzC,UAAME,QAAQ,IAAIC,MAAM,SAAS;QAAEpB;MAAQ,CAAA;AAC3CiB,iBAAWI,KAAKb,OAAOZ,OAAAA,GACvBY,MAAMc,cAAcH,KAAAA;IACtB;EACF,GAAG;IAACd;IAAaT;IAASI;GAAQ;EAIhC,uCAAAuB,KAACf,SAAAA;IACCgB,MAAK;IACLC,eAAW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"props", "control", "bubbles", "inputProps", "ref", "React", "useRef", "prevChecked", "usePrevious", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "_jsx", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "button", "setButton", "useState", "composedRefs", "useComposedRefs", "isFormControl", "isWeb", "Boolean", "closest", "labelId", "useLabelContext", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "composeEventHandlers", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
6
6
  }
@@ -0,0 +1,2 @@
1
+ export * from "./useSwitch.mjs";
2
+ //# sourceMappingURL=index.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -5,107 +5,11 @@ import { composeEventHandlers } from "@tamagui/helpers";
5
5
  import { useLabelContext } from "@tamagui/label";
6
6
  import { usePrevious } from "@tamagui/use-previous";
7
7
  import * as React from "react";
8
- function _array_like_to_array(arr, len) {
9
- (len == null || len > arr.length) && (len = arr.length);
10
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
11
- return arr2;
12
- }
13
- function _array_with_holes(arr) {
14
- if (Array.isArray(arr)) return arr;
15
- }
16
- function _define_property(obj, key, value) {
17
- return key in obj ? Object.defineProperty(obj, key, {
18
- value,
19
- enumerable: !0,
20
- configurable: !0,
21
- writable: !0
22
- }) : obj[key] = value, obj;
23
- }
24
- function _iterable_to_array_limit(arr, i) {
25
- var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
26
- if (_i != null) {
27
- var _arr = [], _n = !0, _d = !1, _s, _e;
28
- try {
29
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
30
- ;
31
- } catch (err) {
32
- _d = !0, _e = err;
33
- } finally {
34
- try {
35
- !_n && _i.return != null && _i.return();
36
- } finally {
37
- if (_d) throw _e;
38
- }
39
- }
40
- return _arr;
41
- }
42
- }
43
- function _non_iterable_rest() {
44
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
45
- }
46
- function _object_spread(target) {
47
- for (var i = 1; i < arguments.length; i++) {
48
- var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
49
- typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
50
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
51
- }))), ownKeys2.forEach(function(key) {
52
- _define_property(target, key, source[key]);
53
- });
54
- }
55
- return target;
56
- }
57
- function ownKeys(object, enumerableOnly) {
58
- var keys = Object.keys(object);
59
- if (Object.getOwnPropertySymbols) {
60
- var symbols = Object.getOwnPropertySymbols(object);
61
- enumerableOnly && (symbols = symbols.filter(function(sym) {
62
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
63
- })), keys.push.apply(keys, symbols);
64
- }
65
- return keys;
66
- }
67
- function _object_spread_props(target, source) {
68
- return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
69
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
70
- }), target;
71
- }
72
- function _object_without_properties(source, excluded) {
73
- if (source == null) return {};
74
- var target = _object_without_properties_loose(source, excluded), key, i;
75
- if (Object.getOwnPropertySymbols) {
76
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
77
- for (i = 0; i < sourceSymbolKeys.length; i++)
78
- key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
79
- }
80
- return target;
81
- }
82
- function _object_without_properties_loose(source, excluded) {
83
- if (source == null) return {};
84
- var target = {}, sourceKeys = Object.keys(source), key, i;
85
- for (i = 0; i < sourceKeys.length; i++)
86
- key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
87
- return target;
88
- }
89
- function _sliced_to_array(arr, i) {
90
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
91
- }
92
- function _unsupported_iterable_to_array(o, minLen) {
93
- if (o) {
94
- if (typeof o == "string") return _array_like_to_array(o, minLen);
95
- var n = Object.prototype.toString.call(o).slice(8, -1);
96
- if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
97
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
98
- }
99
- }
100
8
  function getState(checked) {
101
9
  return checked ? "checked" : "unchecked";
102
10
  }
103
11
  var BubbleInput = function(props) {
104
- var control = props.control, checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, inputProps = _object_without_properties(props, [
105
- "control",
106
- "checked",
107
- "bubbles"
108
- ]), ref = React.useRef(null), prevChecked = usePrevious(checked);
12
+ var { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = usePrevious(checked);
109
13
  return React.useEffect(function() {
110
14
  var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
111
15
  if (prevChecked !== checked && setChecked) {
@@ -119,40 +23,42 @@ var BubbleInput = function(props) {
119
23
  checked,
120
24
  bubbles
121
25
  ]), // @ts-ignore
122
- /* @__PURE__ */ _jsx("input", _object_spread_props(_object_spread({
26
+ /* @__PURE__ */ _jsx("input", {
123
27
  type: "checkbox",
124
28
  "aria-hidden": !0,
125
- defaultChecked: checked
126
- }, inputProps), {
29
+ defaultChecked: checked,
30
+ ...inputProps,
127
31
  tabIndex: -1,
128
32
  ref,
129
- style: _object_spread_props(_object_spread({}, props.style), {
33
+ style: {
34
+ ...props.style,
130
35
  position: "absolute",
131
36
  pointerEvents: "none",
132
37
  opacity: 0,
133
38
  margin: 0
134
- })
135
- }));
39
+ }
40
+ });
136
41
  };
137
42
  function useSwitch(props, param, ref) {
138
- var _param = _sliced_to_array(param, 2), checked = _param[0], setChecked = _param[1], disabled = props.disabled, name = props.name, value = props.value, required = props.required, hasConsumerStoppedPropagationRef = React.useRef(!1), _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
43
+ var [checked, setChecked] = param, { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
139
44
  return {
140
- switchProps: _object_spread_props(_object_spread({
45
+ switchProps: {
141
46
  role: "switch",
142
- "aria-checked": checked
143
- }, isWeb ? {
144
- tabIndex: disabled ? void 0 : 0,
145
- "data-state": getState(checked),
146
- "data-disabled": disabled ? "" : void 0,
147
- disabled
148
- } : {}, props), {
47
+ "aria-checked": checked,
48
+ ...isWeb ? {
49
+ tabIndex: disabled ? void 0 : 0,
50
+ "data-state": getState(checked),
51
+ "data-disabled": disabled ? "" : void 0,
52
+ disabled
53
+ } : {},
54
+ ...props,
149
55
  "aria-labelledby": ariaLabelledBy,
150
56
  onPress: composeEventHandlers(props.onPress, function(event) {
151
57
  setChecked(function(prevChecked) {
152
58
  return !prevChecked;
153
59
  }), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
154
60
  })
155
- }),
61
+ },
156
62
  switchRef: composedRefs,
157
63
  /**
158
64
  * insert as a sibling of your switch (should not be inside the switch)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/tamagui/code/ui/switch-headless/src/useSwitch.tsx"],
4
- "mappings": ";AAAA,SAASA,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,4BAA4B;AACrC,SAASC,uBAAuB;AAChC,SAASC,mBAAmB;AAC5B,YAAYC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBvB,SAASC,SAASC,SAAoB;AACpC,SAAOA,UAAU,YAAY;AAC/B;AAWA,IAAMC,cAAc,SAACC,OAAAA;AACnB,MAAQC,UAAoDD,MAApDC,SAASH,UAA2CE,MAA3CF,SAAAA,iBAA2CE,MAAlCE,SAAAA,UAAAA,mBAAAA,SAAU,KAAA,gBAASC,aAAAA,2BAAeH,OAAAA;IAApDC;IAASH;IAASI;MACpBE,MAAMR,MAAMS,OAAyB,IAAA,GACrCC,cAAcX,YAAYG,OAAAA;AAGhCF,eAAMW,UAAU,WAAA;AACd,QAAMC,QAAQJ,IAAIK,SACZC,aAAaC,OAAOC,iBAAiBC,WACrCC,aAAaC,OAAOC,yBACxBN,YACA,SAAA,GAEIO,aAAaH,WAAWI;AAC9B,QAAIZ,gBAAgBR,WAAWmB,YAAY;AACzC,UAAME,QAAQ,IAAIC,MAAM,SAAS;QAAElB;MAAQ,CAAA;AAC3Ce,iBAAWI,KAAKb,OAAOV,OAAAA,GACvBU,MAAMc,cAAcH,KAAAA;IACtB;EACF,GAAG;IAACb;IAAaR;IAASI;GAAQ;EAIhC,qBAACM,SAAAA,qB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AA;;IAEFC,WAAWb;;;;IAIXc,aACE/D,SAASkD,gBACP,qBAAC3C,aAAAA;MACCE,SAASsC;MACTrC,SAAS,CAACmC,iCAAiC5B;MAC3CyB;MACAC;MACArC;MACAsC;MACAH;;;;MAIAN,OAAO;QAAE6B,WAAW;MAAoB;SAExC;EACR;AACF;",
5
- "names": ["useComposedRefs", "isWeb", "composeEventHandlers", "useLabelContext", "usePrevious", "React", "getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "useRef", "prevChecked", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "useState", "button", "setButton", "composedRefs", "isFormControl", "Boolean", "closest", "labelId", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
4
+ "mappings": ";AAAA,SAASA,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,4BAA4B;AACrC,SAASC,uBAAuB;AAChC,SAASC,mBAAmB;AAC5B,YAAYC,WAAW;AAmBvB,SAASC,SAASC,SAAoB;AACpC,SAAOA,UAAU,YAAY;AAC/B;AAWA,IAAMC,cAAc,SAACC,OAAAA;AACnB,MAAM,EAAEC,SAASH,SAASI,UAAU,IAAM,GAAGC,WAAAA,IAAeH,OACtDI,MAAMR,MAAMS,OAAyB,IAAA,GACrCC,cAAcX,YAAYG,OAAAA;AAGhCF,eAAMW,UAAU,WAAA;AACd,QAAMC,QAAQJ,IAAIK,SACZC,aAAaC,OAAOC,iBAAiBC,WACrCC,aAAaC,OAAOC,yBACxBN,YACA,SAAA,GAEIO,aAAaH,WAAWI;AAC9B,QAAIZ,gBAAgBR,WAAWmB,YAAY;AACzC,UAAME,Q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kD,gBACP,qBAAC3C,aAAAA;MACCE,SAASqC;MACTpC,SAAS,CAACmC,iCAAiC5B;MAC3CyB;MACAC;MACArC;MACAsC;MACAH;;;;MAIAN,OAAO;QAAE6B,WAAW;MAAoB;SAExC;EACR;AACF;",
5
+ "names": ["useComposedRefs", "isWeb", "composeEventHandlers", "useLabelContext", "usePrevious", "React", "getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "useRef", "prevChecked", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "button", "setButton", "useState", "composedRefs", "isFormControl", "Boolean", "closest", "labelId", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
6
6
  }
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useComposedRefs } from "@tamagui/compose-refs";
3
+ import { isWeb } from "@tamagui/constants";
4
+ import { composeEventHandlers } from "@tamagui/helpers";
5
+ import { useLabelContext } from "@tamagui/label";
6
+ import { usePrevious } from "@tamagui/use-previous";
7
+ import * as React from "react";
8
+ function getState(checked) {
9
+ return checked ? "checked" : "unchecked";
10
+ }
11
+ var BubbleInput = function (props) {
12
+ var {
13
+ control,
14
+ checked,
15
+ bubbles = !0,
16
+ ...inputProps
17
+ } = props,
18
+ ref = React.useRef(null),
19
+ prevChecked = usePrevious(checked);
20
+ return React.useEffect(function () {
21
+ var input = ref.current,
22
+ inputProto = window.HTMLInputElement.prototype,
23
+ descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"),
24
+ setChecked = descriptor.set;
25
+ if (prevChecked !== checked && setChecked) {
26
+ var event = new Event("click", {
27
+ bubbles
28
+ });
29
+ setChecked.call(input, checked), input.dispatchEvent(event);
30
+ }
31
+ }, [prevChecked, checked, bubbles]),
32
+ // @ts-ignore
33
+ /* @__PURE__ */
34
+ _jsx("input", {
35
+ type: "checkbox",
36
+ "aria-hidden": !0,
37
+ defaultChecked: checked,
38
+ ...inputProps,
39
+ tabIndex: -1,
40
+ ref,
41
+ style: {
42
+ ...props.style,
43
+ position: "absolute",
44
+ pointerEvents: "none",
45
+ opacity: 0,
46
+ margin: 0
47
+ }
48
+ });
49
+ };
50
+ function useSwitch(props, param, ref) {
51
+ var [checked, setChecked] = param,
52
+ {
53
+ disabled,
54
+ name,
55
+ value,
56
+ required
57
+ } = props,
58
+ hasConsumerStoppedPropagationRef = React.useRef(!1),
59
+ [button, setButton] = React.useState(null),
60
+ composedRefs = useComposedRefs(ref, setButton),
61
+ isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1,
62
+ labelId = useLabelContext(button),
63
+ ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
64
+ return {
65
+ switchProps: {
66
+ role: "switch",
67
+ "aria-checked": checked,
68
+ ...(isWeb ? {
69
+ tabIndex: disabled ? void 0 : 0,
70
+ "data-state": getState(checked),
71
+ "data-disabled": disabled ? "" : void 0,
72
+ disabled
73
+ } : {}),
74
+ ...props,
75
+ "aria-labelledby": ariaLabelledBy,
76
+ onPress: composeEventHandlers(props.onPress, function (event) {
77
+ setChecked(function (prevChecked) {
78
+ return !prevChecked;
79
+ }), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
80
+ })
81
+ },
82
+ switchRef: composedRefs,
83
+ /**
84
+ * insert as a sibling of your switch (should not be inside the switch)
85
+ */
86
+ bubbleInput: isWeb && isFormControl ? /* @__PURE__ */_jsx(BubbleInput, {
87
+ control: button,
88
+ bubbles: !hasConsumerStoppedPropagationRef.current,
89
+ name,
90
+ value,
91
+ checked,
92
+ required,
93
+ disabled,
94
+ // We transform because the input is absolutely positioned but we have
95
+ // rendered it **after** the button. This pulls it back to sit on top
96
+ // of the button.
97
+ style: {
98
+ transform: "translateX(-100%)"
99
+ }
100
+ }) : null
101
+ };
102
+ }
103
+ export { useSwitch };
104
+ //# sourceMappingURL=useSwitch.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["jsx","_jsx","useComposedRefs","isWeb","composeEventHandlers","useLabelContext","usePrevious","React","getState","checked","BubbleInput","props","control","bubbles","inputProps","ref","useRef","prevChecked","useEffect","input","current","inputProto","window","HTMLInputElement","prototype","descriptor","Object","getOwnPropertyDescriptor","setChecked","set","event","Event","call","dispatchEvent","type","defaultChecked","tabIndex","style","position","pointerEvents","opacity","margin","useSwitch","param","disabled","name","value","required","hasConsumerStoppedPropagationRef","button","setButton","useState","composedRefs","isFormControl","closest","labelId","ariaLabelledBy","labeledBy","switchProps","role","onPress","isPropagationStopped","stopPropagation","switchRef","bubbleInput","transform"],"sources":["../../src/useSwitch.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,2BAAuB;AAChC,SAASC,eAAa;AACtB,SAASC,KAAA,4BAA4B;AACrC,SAASC,oBAAA,QAAuB;AAChC,SAASC,eAAA,QAAmB;AAC5B,SAAAC,WAAY,QAAW;AAuDnB,YAAAC,KAAA;AApCJ,SAASC,SAASC,OAAA,EAAsB;EACtC,OAAOA,OAAA,GAAU,YAAY;AAC/B;AAWA,IAAAC,WAAM,YAAAA,CAAeC,KAA4B;EAC/C;MAAMC,OAAE;MAAAH,OAAS;MAAAI,OAAS,KAAU;MAAA,GAAMC;IAAG,IAAWH,KAAI;IAAAI,GACtD,GAAAR,KAAM,CAAAS,MAAM,KAAyB;IAAIC,WACzC,GAAAX,WAAc,CAAAG,OAAY;EAGhC,OAAAF,KAAA,CAAMW,SAAA,CAAU,YAAM;IACpB,IAAAC,KAAM,GAAAJ,GAAQ,CAAAK,OAAI;MAAAC,UACZ,GAAAC,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EAAM;MACN,gBAAgBlD,OAAA;MAChB,IAAIN,KAAA,GACA;QACEiC,QAAA,EAAUQ,QAAA,GAAW,SAAY;QACjC,cAAcpC,QAAA,CAASC,OAAO;QAC9B,iBAAiBmC,QAAA,GAAW,KAAK;QACjCA;MACF,IACA,CAAC;MACL,GAAGjC,KAAA;MACH,mBAAmB6C,cAAA;MACnBI,OAAA,EAASxD,oBAAA,CAAqBO,KAAA,CAAMiD,OAAA,EAAS,UAAC9B,KAAiC;QAC7EF,UAAA,CAAW,UAACX,WAAiB;UAQ9B,QAAAA,WAAA;QACH,IAAAd,KAAA,IAAAkD,aAAA,KAAAL,gCAAA,CAAA5B,OAAA,GAAAU,KAAA,CAAA+B,oBAAA,IAAAb,gCAAA,CAAA5B,OAAA,IAAAU,KAAA,CAAAgC,eAAA;MACA;IAAW;IAAAC,SAAA,EAAAX,YAAA;IAAA;AAAA;AAMP;IAACY,WAAA,EAAA7D,KAAA,IAAAkD,aAAA,kBAAApD,IAAA,CAAAS,WAAA;MAAAE,OACC,EAAAqC,MAAS;MAAApC,OACT,GAAAmC,gCAAU,CAAA5B,OAAiC;MAAAyB,IAC3C;MAAAC,KACA;MAAArC,OACA;MAAAsC,QACA;MAAAH,QACA;MAAA;MAIwC;MAC1C;MAENP,KAAA;QACF4B,SAAA","ignoreList":[]}
@@ -5,107 +5,11 @@ import { composeEventHandlers } from "@tamagui/helpers";
5
5
  import { useLabelContext } from "@tamagui/label";
6
6
  import { usePrevious } from "@tamagui/use-previous";
7
7
  import * as React from "react";
8
- function _array_like_to_array(arr, len) {
9
- (len == null || len > arr.length) && (len = arr.length);
10
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
11
- return arr2;
12
- }
13
- function _array_with_holes(arr) {
14
- if (Array.isArray(arr)) return arr;
15
- }
16
- function _define_property(obj, key, value) {
17
- return key in obj ? Object.defineProperty(obj, key, {
18
- value,
19
- enumerable: !0,
20
- configurable: !0,
21
- writable: !0
22
- }) : obj[key] = value, obj;
23
- }
24
- function _iterable_to_array_limit(arr, i) {
25
- var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
26
- if (_i != null) {
27
- var _arr = [], _n = !0, _d = !1, _s, _e;
28
- try {
29
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
30
- ;
31
- } catch (err) {
32
- _d = !0, _e = err;
33
- } finally {
34
- try {
35
- !_n && _i.return != null && _i.return();
36
- } finally {
37
- if (_d) throw _e;
38
- }
39
- }
40
- return _arr;
41
- }
42
- }
43
- function _non_iterable_rest() {
44
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
45
- }
46
- function _object_spread(target) {
47
- for (var i = 1; i < arguments.length; i++) {
48
- var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
49
- typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
50
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
51
- }))), ownKeys2.forEach(function(key) {
52
- _define_property(target, key, source[key]);
53
- });
54
- }
55
- return target;
56
- }
57
- function ownKeys(object, enumerableOnly) {
58
- var keys = Object.keys(object);
59
- if (Object.getOwnPropertySymbols) {
60
- var symbols = Object.getOwnPropertySymbols(object);
61
- enumerableOnly && (symbols = symbols.filter(function(sym) {
62
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
63
- })), keys.push.apply(keys, symbols);
64
- }
65
- return keys;
66
- }
67
- function _object_spread_props(target, source) {
68
- return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
69
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
70
- }), target;
71
- }
72
- function _object_without_properties(source, excluded) {
73
- if (source == null) return {};
74
- var target = _object_without_properties_loose(source, excluded), key, i;
75
- if (Object.getOwnPropertySymbols) {
76
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
77
- for (i = 0; i < sourceSymbolKeys.length; i++)
78
- key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
79
- }
80
- return target;
81
- }
82
- function _object_without_properties_loose(source, excluded) {
83
- if (source == null) return {};
84
- var target = {}, sourceKeys = Object.keys(source), key, i;
85
- for (i = 0; i < sourceKeys.length; i++)
86
- key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
87
- return target;
88
- }
89
- function _sliced_to_array(arr, i) {
90
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
91
- }
92
- function _unsupported_iterable_to_array(o, minLen) {
93
- if (o) {
94
- if (typeof o == "string") return _array_like_to_array(o, minLen);
95
- var n = Object.prototype.toString.call(o).slice(8, -1);
96
- if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
97
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
98
- }
99
- }
100
8
  function getState(checked) {
101
9
  return checked ? "checked" : "unchecked";
102
10
  }
103
11
  var BubbleInput = function(props) {
104
- var control = props.control, checked = props.checked, _props_bubbles = props.bubbles, bubbles = _props_bubbles === void 0 ? !0 : _props_bubbles, inputProps = _object_without_properties(props, [
105
- "control",
106
- "checked",
107
- "bubbles"
108
- ]), ref = React.useRef(null), prevChecked = usePrevious(checked);
12
+ var { control, checked, bubbles = !0, ...inputProps } = props, ref = React.useRef(null), prevChecked = usePrevious(checked);
109
13
  return React.useEffect(function() {
110
14
  var input = ref.current, inputProto = window.HTMLInputElement.prototype, descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked"), setChecked = descriptor.set;
111
15
  if (prevChecked !== checked && setChecked) {
@@ -119,40 +23,42 @@ var BubbleInput = function(props) {
119
23
  checked,
120
24
  bubbles
121
25
  ]), // @ts-ignore
122
- /* @__PURE__ */ _jsx("input", _object_spread_props(_object_spread({
26
+ /* @__PURE__ */ _jsx("input", {
123
27
  type: "checkbox",
124
28
  "aria-hidden": !0,
125
- defaultChecked: checked
126
- }, inputProps), {
29
+ defaultChecked: checked,
30
+ ...inputProps,
127
31
  tabIndex: -1,
128
32
  ref,
129
- style: _object_spread_props(_object_spread({}, props.style), {
33
+ style: {
34
+ ...props.style,
130
35
  position: "absolute",
131
36
  pointerEvents: "none",
132
37
  opacity: 0,
133
38
  margin: 0
134
- })
135
- }));
39
+ }
40
+ });
136
41
  };
137
42
  function useSwitch(props, param, ref) {
138
- var _param = _sliced_to_array(param, 2), checked = _param[0], setChecked = _param[1], disabled = props.disabled, name = props.name, value = props.value, required = props.required, hasConsumerStoppedPropagationRef = React.useRef(!1), _React_useState = _sliced_to_array(React.useState(null), 2), button = _React_useState[0], setButton = _React_useState[1], composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
43
+ var [checked, setChecked] = param, { disabled, name, value, required } = props, hasConsumerStoppedPropagationRef = React.useRef(!1), [button, setButton] = React.useState(null), composedRefs = useComposedRefs(ref, setButton), isFormControl = isWeb ? button ? !!button.closest("form") : !0 : !1, labelId = useLabelContext(button), ariaLabelledBy = props["aria-labelledby"] || props.labeledBy || labelId;
139
44
  return {
140
- switchProps: _object_spread_props(_object_spread({
45
+ switchProps: {
141
46
  role: "switch",
142
- "aria-checked": checked
143
- }, isWeb ? {
144
- tabIndex: disabled ? void 0 : 0,
145
- "data-state": getState(checked),
146
- "data-disabled": disabled ? "" : void 0,
147
- disabled
148
- } : {}, props), {
47
+ "aria-checked": checked,
48
+ ...isWeb ? {
49
+ tabIndex: disabled ? void 0 : 0,
50
+ "data-state": getState(checked),
51
+ "data-disabled": disabled ? "" : void 0,
52
+ disabled
53
+ } : {},
54
+ ...props,
149
55
  "aria-labelledby": ariaLabelledBy,
150
56
  onPress: composeEventHandlers(props.onPress, function(event) {
151
57
  setChecked(function(prevChecked) {
152
58
  return !prevChecked;
153
59
  }), isWeb && isFormControl && (hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(), hasConsumerStoppedPropagationRef.current || event.stopPropagation());
154
60
  })
155
- }),
61
+ },
156
62
  switchRef: composedRefs,
157
63
  /**
158
64
  * insert as a sibling of your switch (should not be inside the switch)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/tamagui/code/ui/switch-headless/src/useSwitch.tsx"],
4
- "mappings": ";AAAA,SAASA,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,4BAA4B;AACrC,SAASC,uBAAuB;AAChC,SAASC,mBAAmB;AAC5B,YAAYC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBvB,SAASC,SAASC,SAAoB;AACpC,SAAOA,UAAU,YAAY;AAC/B;AAWA,IAAMC,cAAc,SAACC,OAAAA;AACnB,MAAQC,UAAoDD,MAApDC,SAASH,UAA2CE,MAA3CF,SAAAA,iBAA2CE,MAAlCE,SAAAA,UAAAA,mBAAAA,SAAU,KAAA,gBAASC,aAAAA,2BAAeH,OAAAA;IAApDC;IAASH;IAASI;MACpBE,MAAMR,MAAMS,OAAyB,IAAA,GACrCC,cAAcX,YAAYG,OAAAA;AAGhCF,eAAMW,UAAU,WAAA;AACd,QAAMC,QAAQJ,IAAIK,SACZC,aAAaC,OAAOC,iBAAiBC,WACrCC,aAAaC,OAAOC,yBACxBN,YACA,SAAA,GAEIO,aAAaH,WAAWI;AAC9B,QAAIZ,gBAAgBR,WAAWmB,YAAY;AACzC,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,qBAAqBO,MAAMmD,SAAS,SAAChC,OAAAA;AAC5CF,mBAAW,SAACX,aAAAA;iBAAgB,CAACA;YACzBd,SAASkD,kBACXL,iCAAiC5B,UAAUU,MAAMiC,qBAAoB,GAIhEf,iCAAiC5B,WAASU,MAAMkC,gBAAe;MAExE,CAAA;;IAEFC,WAAWb;;;;IAIXc,aACE/D,SAASkD,gBACP,qBAAC3C,aAAAA;MACCE,SAASsC;MACTrC,SAAS,CAACmC,iCAAiC5B;MAC3CyB;MACAC;MACArC;MACAsC;MACAH;;;;MAIAN,OAAO;QAAE6B,WAAW;MAAoB;SAExC;EACR;AACF;",
5
- "names": ["useComposedRefs", "isWeb", "composeEventHandlers", "useLabelContext", "usePrevious", "React", "getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "useRef", "prevChecked", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "useState", "button", "setButton", "composedRefs", "isFormControl", "Boolean", "closest", "labelId", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
4
+ "mappings": ";AAAA,SAASA,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,4BAA4B;AACrC,SAASC,uBAAuB;AAChC,SAASC,mBAAmB;AAC5B,YAAYC,WAAW;AAmBvB,SAASC,SAASC,SAAoB;AACpC,SAAOA,UAAU,YAAY;AAC/B;AAWA,IAAMC,cAAc,SAACC,OAAAA;AACnB,MAAM,EAAEC,SAASH,SAASI,UAAU,IAAM,GAAGC,WAAAA,IAAeH,OACtDI,MAAMR,MAAMS,OAAyB,IAAA,GACrCC,cAAcX,YAAYG,OAAAA;AAGhCF,eAA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5CF,mBAAW,SAACX,aAAAA;iBAAgB,CAACA;YACzBd,SAASkD,kBACXL,iCAAiC5B,UAAUU,MAAMiC,qBAAoB,GAIhEf,iCAAiC5B,WAASU,MAAMkC,gBAAe;MAExE,CAAA;IACF;IACAC,WAAWb;;;;IAIXc,aACE/D,SAASkD,gBACP,qBAAC3C,aAAAA;MACCE,SAASqC;MACTpC,SAAS,CAACmC,iCAAiC5B;MAC3CyB;MACAC;MACArC;MACAsC;MACAH;;;;MAIAN,OAAO;QAAE6B,WAAW;MAAoB;SAExC;EACR;AACF;",
5
+ "names": ["useComposedRefs", "isWeb", "composeEventHandlers", "useLabelContext", "usePrevious", "React", "getState", "checked", "BubbleInput", "props", "control", "bubbles", "inputProps", "ref", "useRef", "prevChecked", "useEffect", "input", "current", "inputProto", "window", "HTMLInputElement", "prototype", "descriptor", "Object", "getOwnPropertyDescriptor", "setChecked", "set", "event", "Event", "call", "dispatchEvent", "type", "aria-hidden", "defaultChecked", "tabIndex", "style", "position", "pointerEvents", "opacity", "margin", "useSwitch", "disabled", "name", "value", "required", "hasConsumerStoppedPropagationRef", "button", "setButton", "useState", "composedRefs", "isFormControl", "Boolean", "closest", "labelId", "ariaLabelledBy", "labeledBy", "switchProps", "role", "undefined", "onPress", "isPropagationStopped", "stopPropagation", "switchRef", "bubbleInput", "transform"]
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/switch-headless",
3
- "version": "1.110.5",
3
+ "version": "1.111.0",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -33,17 +33,17 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@tamagui/compose-refs": "1.110.5",
37
- "@tamagui/constants": "1.110.5",
38
- "@tamagui/helpers": "1.110.5",
39
- "@tamagui/label": "1.110.5",
40
- "@tamagui/use-previous": "1.110.5"
36
+ "@tamagui/compose-refs": "1.111.0",
37
+ "@tamagui/constants": "1.111.0",
38
+ "@tamagui/helpers": "1.111.0",
39
+ "@tamagui/label": "1.111.0",
40
+ "@tamagui/use-previous": "1.111.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": "*"
44
44
  },
45
45
  "devDependencies": {
46
- "@tamagui/build": "1.110.5",
46
+ "@tamagui/build": "1.111.0",
47
47
  "react": "^18.2.0 || ^19.0.0",
48
48
  "react-native": "0.74.1"
49
49
  },