@zag-js/slider 0.0.0-dev-20220413175519 → 0.0.0-dev-20220415160434

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
@@ -6,7 +6,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __pow = Math.pow;
10
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
10
  var __spreadValues = (a, b) => {
12
11
  for (var prop in b || (b = {}))
@@ -43,12 +42,11 @@ __export(src_exports, {
43
42
  });
44
43
  module.exports = __toCommonJS(src_exports);
45
44
 
46
- // ../../utilities/dom/src/attrs.ts
45
+ // ../../utilities/dom/dist/index.mjs
46
+ var __pow = Math.pow;
47
47
  var dataAttr = (guard) => {
48
48
  return guard ? "" : void 0;
49
49
  };
50
-
51
- // ../../utilities/dom/src/next-tick.ts
52
50
  function nextTick(fn) {
53
51
  const set = /* @__PURE__ */ new Set();
54
52
  function raf2(fn2) {
@@ -68,32 +66,9 @@ function raf(fn) {
68
66
  globalThis.cancelAnimationFrame(id);
69
67
  };
70
68
  }
71
-
72
- // ../../utilities/core/src/array.ts
73
- function clear(v) {
74
- while (v.length > 0)
75
- v.pop();
76
- return v;
77
- }
78
-
79
- // ../../utilities/core/src/functions.ts
80
- var runIfFn = (v, ...a) => {
81
- const res = typeof v === "function" ? v(...a) : v;
82
- return res != null ? res : void 0;
83
- };
84
- var cast = (v) => v;
85
69
  var noop = () => {
86
70
  };
87
71
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
88
- var uuid = /* @__PURE__ */ (() => {
89
- let id = 0;
90
- return () => {
91
- id++;
92
- return id.toString(36);
93
- };
94
- })();
95
-
96
- // ../../utilities/core/src/guard.ts
97
72
  var platform = (v) => isDom() && v.test(navigator.platform);
98
73
  var isDom = () => !!(typeof window !== "undefined");
99
74
  var isMac = () => platform(/^Mac/);
@@ -102,38 +77,25 @@ var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
102
77
  var isIos = () => isIPhone() || isIPad();
103
78
  var isArray = (v) => Array.isArray(v);
104
79
  var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
105
- var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
106
- var isString = (v) => typeof v === "string";
107
- var isFunction = (v) => typeof v === "function";
108
80
  var isMouseEvent = (v) => isObject(v) && "button" in v;
109
- var isTouchEvent = (v) => isObject(v) && "touches" in v;
110
81
  var isLeftClick = (v) => v.button === 0;
111
- var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey || v.shiftKey;
112
-
113
- // ../../utilities/core/src/warning.ts
114
- function warn(...a) {
115
- const m = a.length === 1 ? a[0] : a[1];
116
- const c = a.length === 2 ? a[0] : true;
117
- if (c && void 0 !== "production") {
118
- console.warn(m);
119
- }
82
+ function getListenerElements() {
83
+ ;
84
+ globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
85
+ return globalThis.__listenerElements__;
120
86
  }
121
- function invariant(...a) {
122
- const m = a.length === 1 ? a[0] : a[1];
123
- const c = a.length === 2 ? a[0] : true;
124
- if (c && void 0 !== "production") {
125
- throw new Error(m);
126
- }
87
+ function getListenerCache() {
88
+ ;
89
+ globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
90
+ return globalThis.__listenerCache__;
127
91
  }
128
-
129
- // ../../utilities/dom/src/event-bus.ts
130
- var listenerElements = /* @__PURE__ */ new Map();
131
- var listenerCache = /* @__PURE__ */ new Map();
132
92
  function globalEventBus(node, type, handler, options) {
133
93
  var _a;
134
94
  if (!node)
135
95
  return noop;
136
96
  const hash = JSON.stringify({ type, options });
97
+ const listenerElements = getListenerElements();
98
+ const listenerCache = getListenerCache();
137
99
  const group = listenerElements.get(node);
138
100
  if (!listenerElements.has(node)) {
139
101
  const group2 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
@@ -179,15 +141,13 @@ function globalEventBus(node, type, handler, options) {
179
141
  }
180
142
  };
181
143
  }
182
-
183
- // ../../utilities/dom/src/listener.ts
184
144
  var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
185
145
  var isRef = (v) => t(v) === "Object" && "current" in v;
186
- var runIfFn2 = (fn) => t(fn) === "Function" ? fn() : fn;
187
- var isTouchEvent2 = (v) => t(v) === "Object" && !!v.touches;
146
+ var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
147
+ var isTouchEvent = (v) => t(v) === "Object" && !!v.touches;
188
148
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
189
149
  function extractInfo(event, type = "page") {
190
- const point = isTouchEvent2(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
150
+ const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback : event;
191
151
  return {
192
152
  point: {
193
153
  x: point[`${type}X`],
@@ -196,7 +156,7 @@ function extractInfo(event, type = "page") {
196
156
  };
197
157
  }
198
158
  function addDomEvent(target, event, listener, options) {
199
- const node = isRef(target) ? target.current : runIfFn2(target);
159
+ const node = isRef(target) ? target.current : runIfFn(target);
200
160
  return globalEventBus(node, event, listener, options);
201
161
  }
202
162
  function addPointerEvent(target, event, listener, options) {
@@ -248,8 +208,6 @@ function getEventName(evt) {
248
208
  return mouseEventNames[evt];
249
209
  return evt;
250
210
  }
251
-
252
- // ../../utilities/dom/src/query.ts
253
211
  function getOwnerWindow(el) {
254
212
  var _a;
255
213
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
@@ -258,8 +216,6 @@ function getNativeEvent(event) {
258
216
  var _a;
259
217
  return (_a = event.nativeEvent) != null ? _a : event;
260
218
  }
261
-
262
- // ../../utilities/dom/src/dispatch-event.ts
263
219
  function getDescriptor(el, options) {
264
220
  var _a;
265
221
  const { type, property } = options;
@@ -298,8 +254,6 @@ function trackInputPropertyMutation(el, options) {
298
254
  run = false;
299
255
  };
300
256
  }
301
-
302
- // ../../utilities/dom/src/form.ts
303
257
  function getClosestFormElement(el) {
304
258
  if (isFormElement(el))
305
259
  return el.form;
@@ -318,8 +272,6 @@ function trackFormReset(el, callback) {
318
272
  form == null ? void 0 : form.removeEventListener("reset", callback);
319
273
  };
320
274
  }
321
-
322
- // ../../utilities/dom/src/keyboard-event.ts
323
275
  var rtlKeyMap = {
324
276
  ArrowLeft: "ArrowRight",
325
277
  ArrowRight: "ArrowLeft",
@@ -357,8 +309,6 @@ function getEventStep(event) {
357
309
  return isSkipKey ? 10 : 1;
358
310
  }
359
311
  }
360
-
361
- // ../../utilities/dom/src/text-selection.ts
362
312
  var state = "default";
363
313
  var savedUserSelect = "";
364
314
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
@@ -406,8 +356,6 @@ function restoreTextSelection({ target, doc } = {}) {
406
356
  }
407
357
  }
408
358
  }
409
-
410
- // ../../utilities/dom/src/pointer-event.ts
411
359
  function trackPointerMove(opts) {
412
360
  const { onPointerMove, onPointerUp, ctx } = opts;
413
361
  const { doc = document, threshold = 5 } = ctx;
@@ -425,16 +373,15 @@ function trackPointerMove(opts) {
425
373
  return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
426
374
  }
427
375
 
428
- // ../../utilities/number/src/number-format.ts
376
+ // ../../utilities/number/dist/index.mjs
377
+ var __pow2 = Math.pow;
429
378
  var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
430
379
  function formatter(n) {
431
380
  return parseFloat(nf.format(n));
432
381
  }
433
-
434
- // ../../utilities/number/src/number.ts
435
382
  function round(v, t2) {
436
383
  let num = valueOf(v);
437
- const p = __pow(10, t2 != null ? t2 : 10);
384
+ const p = __pow2(10, t2 != null ? t2 : 10);
438
385
  num = Math.round(num * p) / p;
439
386
  return t2 ? num.toFixed(t2) : v.toString();
440
387
  }
@@ -462,8 +409,6 @@ function valueOf(v) {
462
409
  const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
463
410
  return !Number.isNaN(num) ? num : 0;
464
411
  }
465
-
466
- // ../../utilities/number/src/transform.ts
467
412
  var transform = (a, b) => {
468
413
  const i = { min: a[0], max: a[1] };
469
414
  const o = { min: b[0], max: b[1] };
@@ -475,10 +420,13 @@ var transform = (a, b) => {
475
420
  };
476
421
  };
477
422
 
478
- // ../../utilities/rect/src/point.ts
423
+ // ../../utilities/rect/dist/index.mjs
424
+ var isArray2 = (v) => Array.isArray(v);
425
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
426
+ var isTouchEvent2 = (v) => isObject2(v) && "touches" in v;
479
427
  var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
480
428
  function getEventPoint(e, t2 = "page") {
481
- const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
429
+ const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
482
430
  return { x: p[`${t2}X`], y: p[`${t2}Y`] };
483
431
  }
484
432
  function relativeToNode(p, el) {
@@ -651,12 +599,16 @@ var dom = {
651
599
  }
652
600
  };
653
601
 
654
- // ../../types/src/prop-types.ts
602
+ // ../../types/dist/index.mjs
655
603
  function createNormalizer(fn) {
656
604
  return { button: fn, label: fn, input: fn, output: fn, element: fn };
657
605
  }
658
606
  var normalizeProp = createNormalizer((v) => v);
659
607
 
608
+ // ../../utilities/core/dist/index.mjs
609
+ var isLeftClick2 = (v) => v.button === 0;
610
+ var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey || v.shiftKey;
611
+
660
612
  // src/slider.connect.ts
661
613
  function connect(state2, send, normalize = normalizeProp) {
662
614
  var _a, _b;
@@ -833,7 +785,7 @@ function connect(state2, send, normalize = normalizeProp) {
833
785
  if (!isInteractive)
834
786
  return;
835
787
  const evt = getNativeEvent(event);
836
- if (!isLeftClick(evt) || isModifiedEvent(evt))
788
+ if (!isLeftClick2(evt) || isModifiedEvent(evt))
837
789
  return;
838
790
  const point = getEventPoint(evt);
839
791
  send({ type: "POINTER_DOWN", point });
@@ -870,671 +822,9 @@ function connect(state2, send, normalize = normalizeProp) {
870
822
  };
871
823
  }
872
824
 
873
- // ../../../node_modules/@zag-js/core/src/index.ts
874
- var import_vanilla3 = require("valtio/vanilla");
875
-
876
- // ../../core/src/action-utils.ts
877
- function isGuardHelper(value) {
878
- return isObject(value) && value.predicate != null;
879
- }
880
- function determineActionsFn(values, guardMap) {
881
- return (context, event) => {
882
- if (isGuardHelper(values))
883
- return values.predicate(guardMap != null ? guardMap : {})(context, event);
884
- return values;
885
- };
886
- }
887
-
888
- // ../../core/src/guard-utils.ts
889
- function isGuardHelper2(value) {
890
- return isObject(value) && value.predicate != null;
891
- }
892
- var TruthyGuard = () => true;
893
- function determineGuardFn(guard, guardMap) {
894
- guard = guard != null ? guard : TruthyGuard;
895
- return (context, event) => {
896
- if (isString(guard)) {
897
- const value = guardMap == null ? void 0 : guardMap[guard];
898
- return isFunction(value) ? value(context, event) : value;
899
- }
900
- if (isGuardHelper2(guard)) {
901
- return guard.predicate(guardMap != null ? guardMap : {})(context, event);
902
- }
903
- return guard == null ? void 0 : guard(context, event);
904
- };
905
- }
906
-
907
- // ../../../node_modules/klona/json/index.mjs
908
- function klona(val) {
909
- var k, out, tmp;
910
- if (Array.isArray(val)) {
911
- out = Array(k = val.length);
912
- while (k--)
913
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
914
- return out;
915
- }
916
- if (Object.prototype.toString.call(val) === "[object Object]") {
917
- out = {};
918
- for (k in val) {
919
- if (k === "__proto__") {
920
- Object.defineProperty(out, k, {
921
- value: klona(val[k]),
922
- configurable: true,
923
- enumerable: true,
924
- writable: true
925
- });
926
- } else {
927
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
928
- }
929
- }
930
- return out;
931
- }
932
- return val;
933
- }
934
-
935
- // ../../core/src/machine.ts
936
- var import_utils14 = require("valtio/utils");
937
- var import_vanilla2 = require("valtio/vanilla");
938
-
939
- // ../../core/src/create-proxy.ts
940
- var import_vanilla = require("valtio/vanilla");
941
- function createProxy(config) {
942
- var _a;
943
- const state2 = (0, import_vanilla.proxy)({
944
- value: "",
945
- previousValue: "",
946
- event: cast({}),
947
- context: (_a = config.context) != null ? _a : cast({}),
948
- done: false,
949
- tags: [],
950
- hasTag(tag) {
951
- return this.tags.includes(tag);
952
- },
953
- matches(...value) {
954
- return value.includes(this.value);
955
- },
956
- can(event) {
957
- return cast(this).nextEvents.includes(event);
958
- },
959
- get nextEvents() {
960
- var _a2, _b, _c, _d;
961
- const stateEvents = (_c = (_b = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b["on"]) != null ? _c : {};
962
- const globalEvents = (_d = config == null ? void 0 : config.on) != null ? _d : {};
963
- return Object.keys(__spreadValues(__spreadValues({}, stateEvents), globalEvents));
964
- },
965
- get changed() {
966
- if (this.event.value === "machine.init" /* Init */ || !this.previousValue)
967
- return false;
968
- return this.value !== this.previousValue;
969
- }
970
- });
971
- return cast(state2);
972
- }
973
-
974
- // ../../core/src/delay-utils.ts
975
- function determineDelayFn(delay, delaysMap) {
976
- return (context, event) => {
977
- if (isNumber(delay))
978
- return delay;
979
- if (isFunction(delay)) {
980
- return delay(context, event);
981
- }
982
- if (isString(delay)) {
983
- const value = Number.parseFloat(delay);
984
- if (!Number.isNaN(value)) {
985
- return value;
986
- }
987
- if (delaysMap) {
988
- const valueOrFn = delaysMap == null ? void 0 : delaysMap[delay];
989
- if (valueOrFn == null) {
990
- const msg = `[machine] Cannot determine delay for ${delay}. It doesn't exist in options.delays`;
991
- throw new Error(msg);
992
- }
993
- return isFunction(valueOrFn) ? valueOrFn(context, event) : valueOrFn;
994
- }
995
- }
996
- };
997
- }
998
-
999
- // ../../core/src/utils.ts
1000
- function toEvent(event) {
1001
- const obj = isString(event) ? { type: event } : event;
1002
- return obj;
1003
- }
1004
- function toArray(value) {
1005
- if (!value)
1006
- return [];
1007
- return isArray(value) ? value : [value];
1008
- }
1009
-
1010
- // ../../core/src/transition-utils.ts
1011
- function toTarget(target) {
1012
- return isString(target) ? { target } : target;
1013
- }
1014
- function determineTransitionFn(transitions, guardMap) {
1015
- return (context, event) => {
1016
- return toArray(transitions).map(toTarget).find((transition) => {
1017
- var _a;
1018
- const determineGuard = determineGuardFn(transition.guard, guardMap);
1019
- const guard = determineGuard(context, event);
1020
- return (_a = guard != null ? guard : transition.target) != null ? _a : transition.actions;
1021
- });
1022
- };
1023
- }
1024
- function toTransition(transition, current) {
1025
- const _transition = isString(transition) ? toTarget(transition) : transition;
1026
- const fn = (t2) => {
1027
- const isTargetless = t2.actions && !t2.target;
1028
- if (isTargetless && current)
1029
- t2.target = current;
1030
- return t2;
1031
- };
1032
- if (isArray(_transition)) {
1033
- return _transition.map(fn);
1034
- }
1035
- if (isObject(_transition)) {
1036
- return fn(cast(_transition));
1037
- }
1038
- }
1039
-
1040
- // ../../core/src/machine.ts
1041
- var Machine = class {
1042
- constructor(config, options) {
1043
- this.config = config;
1044
- this.status = "Not Started" /* NotStarted */;
1045
- this.type = "machine" /* Machine */;
1046
- this.activityEvents = /* @__PURE__ */ new Map();
1047
- this.delayedEvents = /* @__PURE__ */ new Map();
1048
- this.stateListeners = /* @__PURE__ */ new Set();
1049
- this.eventListeners = /* @__PURE__ */ new Set();
1050
- this.doneListeners = /* @__PURE__ */ new Set();
1051
- this.contextWatchers = /* @__PURE__ */ new Set();
1052
- this.removeStateListener = noop;
1053
- this.removeEventListener = noop;
1054
- this.children = /* @__PURE__ */ new Map();
1055
- this.start = (init) => {
1056
- if (this.status === "Running" /* Running */) {
1057
- return this;
1058
- }
1059
- this.status = "Running" /* Running */;
1060
- const event = toEvent("machine.init" /* Init */);
1061
- if (init) {
1062
- const resolved = isObject(init) ? init : { context: this.config.context, value: init };
1063
- this.setState(resolved.value);
1064
- this.setContext(resolved.context);
1065
- }
1066
- const transition = {
1067
- target: !!init ? void 0 : this.config.initial
1068
- };
1069
- const info = this.getNextStateInfo(transition, event);
1070
- info.target = cast(info.target || transition.target);
1071
- this.initialState = info;
1072
- this.performStateChangeEffects(info.target, info, event);
1073
- this.removeStateListener = (0, import_vanilla2.subscribe)(this.state, () => {
1074
- this.stateListeners.forEach((listener) => {
1075
- listener(this.stateSnapshot);
1076
- });
1077
- }, this.sync);
1078
- this.removeEventListener = (0, import_utils14.subscribeKey)(this.state, "event", (value) => {
1079
- if (this.config.onEvent) {
1080
- this.executeActions(this.config.onEvent, value);
1081
- }
1082
- for (const listener of this.eventListeners) {
1083
- listener(value);
1084
- }
1085
- });
1086
- this.setupContextWatchers();
1087
- this.executeActivities(toEvent("machine.start" /* Start */), toArray(this.config.activities), "machine.start" /* Start */);
1088
- this.executeActions(this.config.entry, toEvent("machine.start" /* Start */));
1089
- return this;
1090
- };
1091
- this.setupContextWatchers = () => {
1092
- var _a;
1093
- for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) {
1094
- this.contextWatchers.add((0, import_utils14.subscribeKey)(this.state.context, key, () => {
1095
- this.executeActions(fn, this.state.event);
1096
- }));
1097
- }
1098
- };
1099
- this.setupComputed = () => {
1100
- var _a;
1101
- const computed = cast((_a = this.config.computed) != null ? _a : {});
1102
- const deriveFns = Object.fromEntries(Object.entries(computed).map(([key, fn]) => [key, (get) => fn(get(this.state.context))]));
1103
- (0, import_utils14.derive)(deriveFns, { proxy: this.state.context });
1104
- };
1105
- this.detachComputed = () => {
1106
- (0, import_utils14.underive)(this.state.context, { delete: true });
1107
- };
1108
- this.stop = () => {
1109
- if (this.status === "Stopped" /* Stopped */)
1110
- return;
1111
- this.setState(null);
1112
- this.setEvent("machine.stop" /* Stop */);
1113
- if (this.config.context) {
1114
- this.setContext(this.config.context);
1115
- }
1116
- this.stopStateListeners();
1117
- this.stopChildren();
1118
- this.stopActivities();
1119
- this.stopDelayedEvents();
1120
- this.stopContextWatchers();
1121
- this.stopEventListeners();
1122
- this.detachComputed();
1123
- this.status = "Stopped" /* Stopped */;
1124
- this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */));
1125
- return this;
1126
- };
1127
- this.stopEventListeners = () => {
1128
- this.eventListeners.clear();
1129
- this.removeEventListener();
1130
- };
1131
- this.stopStateListeners = () => {
1132
- this.removeStateListener();
1133
- this.stateListeners.clear();
1134
- };
1135
- this.stopContextWatchers = () => {
1136
- this.contextWatchers.forEach((fn) => fn());
1137
- this.contextWatchers.clear();
1138
- };
1139
- this.stopDelayedEvents = () => {
1140
- this.delayedEvents.forEach((state2) => {
1141
- state2.forEach((stop) => stop());
1142
- });
1143
- this.delayedEvents.clear();
1144
- };
1145
- this.stopActivities = (state2) => {
1146
- var _a, _b;
1147
- if (state2) {
1148
- (_a = this.activityEvents.get(state2)) == null ? void 0 : _a.forEach((stop) => stop());
1149
- (_b = this.activityEvents.get(state2)) == null ? void 0 : _b.clear();
1150
- this.activityEvents.delete(state2);
1151
- } else {
1152
- this.activityEvents.forEach((state3) => {
1153
- state3.forEach((stop) => stop());
1154
- state3.clear();
1155
- });
1156
- this.activityEvents.clear();
1157
- }
1158
- };
1159
- this.sendChild = (evt, to) => {
1160
- const event = toEvent(evt);
1161
- const id = runIfFn(to, this.contextSnapshot);
1162
- const child = this.children.get(id);
1163
- if (!child) {
1164
- invariant(`[machine/send-child] Cannot send '${event.type}' event to unknown child`);
1165
- }
1166
- child.send(event);
1167
- };
1168
- this.stopChild = (id) => {
1169
- if (!this.children.has(id)) {
1170
- invariant("[machine/stop-child] Cannot stop unknown child");
1171
- }
1172
- this.children.get(id).stop();
1173
- this.children.delete(id);
1174
- };
1175
- this.removeChild = (id) => {
1176
- this.children.delete(id);
1177
- };
1178
- this.stopChildren = () => {
1179
- this.children.forEach((child) => child.stop());
1180
- this.children.clear();
1181
- };
1182
- this.setParent = (parent) => {
1183
- this.parent = parent;
1184
- };
1185
- this.spawn = (src, id) => {
1186
- const actor = runIfFn(src);
1187
- if (id)
1188
- actor.id = id;
1189
- actor.type = "machine.actor" /* Actor */;
1190
- actor.setParent(this);
1191
- this.children.set(actor.id, cast(actor));
1192
- actor.onDone(() => {
1193
- this.removeChild(actor.id);
1194
- }).start();
1195
- return cast((0, import_vanilla2.ref)(actor));
1196
- };
1197
- this.addActivityCleanup = (state2, cleanup) => {
1198
- var _a;
1199
- if (!state2)
1200
- return;
1201
- if (!this.activityEvents.has(state2)) {
1202
- this.activityEvents.set(state2, /* @__PURE__ */ new Set([cleanup]));
1203
- } else {
1204
- (_a = this.activityEvents.get(state2)) == null ? void 0 : _a.add(cleanup);
1205
- }
1206
- };
1207
- this.setState = (target) => {
1208
- this.state.previousValue = this.state.value;
1209
- this.state.value = target;
1210
- const stateNode = this.getStateNode(target);
1211
- if (target == null) {
1212
- clear(this.state.tags);
1213
- } else {
1214
- this.state.tags = toArray(stateNode == null ? void 0 : stateNode.tags);
1215
- }
1216
- };
1217
- this.setContext = (context) => {
1218
- for (const key in context) {
1219
- this.state.context[key] = context[key];
1220
- }
1221
- };
1222
- this.withContext = (context) => {
1223
- this.detachComputed();
1224
- const newContext = __spreadValues(__spreadValues({}, this.config.context), context);
1225
- return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options);
1226
- };
1227
- this.withOptions = (options) => {
1228
- this.detachComputed();
1229
- return new Machine(this.config, __spreadValues(__spreadValues({}, this.options), options));
1230
- };
1231
- this.setActions = (actions) => {
1232
- this.actionMap = __spreadValues(__spreadValues({}, this.actionMap), actions);
1233
- };
1234
- this.clone = () => {
1235
- this.detachComputed();
1236
- return new Machine(this.config, this.options);
1237
- };
1238
- this.getStateNode = (state2) => {
1239
- var _a;
1240
- if (!state2)
1241
- return;
1242
- return (_a = this.config.states) == null ? void 0 : _a[state2];
1243
- };
1244
- this.getNextStateInfo = (transitions, event) => {
1245
- var _a;
1246
- const transition = this.determineTransition(transitions, event);
1247
- const target = (_a = transition == null ? void 0 : transition.target) != null ? _a : this.state.value;
1248
- const stateNode = this.getStateNode(target);
1249
- return {
1250
- transition,
1251
- stateNode,
1252
- target
1253
- };
1254
- };
1255
- this.getActionFromDelayedTransition = (transition) => {
1256
- const event = toEvent("machine.after" /* After */);
1257
- const determineDelay = determineDelayFn(transition.delay, this.delayMap);
1258
- const delay = determineDelay(this.contextSnapshot, event);
1259
- let id;
1260
- return {
1261
- entry: () => {
1262
- id = globalThis.setTimeout(() => {
1263
- const current = this.state.value;
1264
- const next = this.getNextStateInfo(transition, event);
1265
- this.performStateChangeEffects(current, next, event);
1266
- }, delay);
1267
- },
1268
- exit: () => {
1269
- globalThis.clearTimeout(id);
1270
- }
1271
- };
1272
- };
1273
- this.getDelayedEventActions = (state2) => {
1274
- const stateNode = this.getStateNode(state2);
1275
- const event = toEvent("machine.after" /* After */);
1276
- if (!stateNode || !stateNode.after)
1277
- return;
1278
- const entries = [];
1279
- const exits = [];
1280
- if (isArray(stateNode.after)) {
1281
- const transition = this.determineTransition(stateNode.after, event);
1282
- if (!transition)
1283
- return;
1284
- const actions = this.getActionFromDelayedTransition(transition);
1285
- entries.push(actions.entry);
1286
- exits.push(actions.exit);
1287
- } else if (isObject(stateNode.after)) {
1288
- for (const delay in stateNode.after) {
1289
- const transition = stateNode.after[delay];
1290
- let resolvedTransition = {};
1291
- if (isArray(transition)) {
1292
- const picked = this.determineTransition(transition, event);
1293
- if (picked)
1294
- resolvedTransition = picked;
1295
- } else if (isString(transition)) {
1296
- resolvedTransition = { target: transition, delay };
1297
- } else {
1298
- resolvedTransition = __spreadProps(__spreadValues({}, transition), { delay });
1299
- }
1300
- const actions = this.getActionFromDelayedTransition(resolvedTransition);
1301
- entries.push(actions.entry);
1302
- exits.push(actions.exit);
1303
- }
1304
- }
1305
- return { entries, exits };
1306
- };
1307
- this.executeActions = (actions, event) => {
1308
- var _a;
1309
- const _actions = determineActionsFn(actions, this.guardMap)(this.contextSnapshot, event);
1310
- for (const action of toArray(_actions)) {
1311
- const fn = isString(action) ? (_a = this.actionMap) == null ? void 0 : _a[action] : action;
1312
- warn(isString(action) && !fn, `[machine/exec-action] No implementation found for action: \`${action}\``);
1313
- fn == null ? void 0 : fn(this.state.context, event, this.meta);
1314
- }
1315
- };
1316
- this.executeActivities = (event, activities, state2) => {
1317
- var _a;
1318
- for (const activity of activities) {
1319
- const fn = isString(activity) ? (_a = this.activityMap) == null ? void 0 : _a[activity] : activity;
1320
- if (!fn) {
1321
- warn(`[machine/exec-activity] No implementation found for activity: \`${activity}\``);
1322
- continue;
1323
- }
1324
- const cleanup = fn(this.state.context, event, this.meta);
1325
- if (cleanup) {
1326
- this.addActivityCleanup(state2 != null ? state2 : this.state.value, cleanup);
1327
- }
1328
- }
1329
- };
1330
- this.createEveryActivities = (every, callbackfn) => {
1331
- if (!every)
1332
- return;
1333
- const event = toEvent("machine.every" /* Every */);
1334
- if (isArray(every)) {
1335
- const picked = toArray(every).find((t2) => {
1336
- const determineDelay2 = determineDelayFn(t2.delay, this.delayMap);
1337
- t2.delay = determineDelay2(this.contextSnapshot, event);
1338
- const determineGuard = determineGuardFn(t2.guard, this.guardMap);
1339
- const guard = determineGuard(this.contextSnapshot, event);
1340
- return guard != null ? guard : t2.delay;
1341
- });
1342
- if (!picked)
1343
- return;
1344
- const determineDelay = determineDelayFn(picked.delay, this.delayMap);
1345
- const delay = determineDelay(this.contextSnapshot, event);
1346
- const activity = () => {
1347
- const id = globalThis.setInterval(() => {
1348
- this.executeActions(picked.actions, event);
1349
- }, delay);
1350
- return () => {
1351
- globalThis.clearInterval(id);
1352
- };
1353
- };
1354
- callbackfn(activity);
1355
- } else {
1356
- for (const interval in every) {
1357
- const actions = every == null ? void 0 : every[interval];
1358
- const determineDelay = determineDelayFn(interval, this.delayMap);
1359
- const delay = determineDelay(this.contextSnapshot, event);
1360
- const activity = () => {
1361
- const id = globalThis.setInterval(() => {
1362
- this.executeActions(actions, event);
1363
- }, delay);
1364
- return () => {
1365
- globalThis.clearInterval(id);
1366
- };
1367
- };
1368
- callbackfn(activity);
1369
- }
1370
- }
1371
- };
1372
- this.setEvent = (event) => {
1373
- this.state.event = (0, import_vanilla2.ref)(toEvent(event));
1374
- };
1375
- this.performExitEffects = (current, event) => {
1376
- const currentState = this.state.value;
1377
- const stateNode = current ? this.getStateNode(current) : void 0;
1378
- this.stopActivities(currentState);
1379
- const _exit = determineActionsFn(stateNode == null ? void 0 : stateNode.exit, this.guardMap)(this.contextSnapshot, event);
1380
- const exitActions = toArray(_exit);
1381
- const afterExitActions = this.delayedEvents.get(currentState);
1382
- if (afterExitActions) {
1383
- exitActions.push(...afterExitActions);
1384
- }
1385
- this.executeActions(exitActions, event);
1386
- this.eventListeners.clear();
1387
- };
1388
- this.performEntryEffects = (next, event) => {
1389
- const stateNode = this.getStateNode(next);
1390
- const activities = toArray(stateNode == null ? void 0 : stateNode.activities);
1391
- this.createEveryActivities(stateNode == null ? void 0 : stateNode.every, (activity) => {
1392
- activities.unshift(activity);
1393
- });
1394
- if (activities.length > 0) {
1395
- this.executeActivities(event, activities);
1396
- }
1397
- const _entry = determineActionsFn(stateNode == null ? void 0 : stateNode.entry, this.guardMap)(this.contextSnapshot, event);
1398
- const entryActions = toArray(_entry);
1399
- const afterActions = this.getDelayedEventActions(next);
1400
- if ((stateNode == null ? void 0 : stateNode.after) && afterActions) {
1401
- this.delayedEvents.set(next, afterActions == null ? void 0 : afterActions.exits);
1402
- entryActions.push(...afterActions.entries);
1403
- }
1404
- this.executeActions(entryActions, event);
1405
- if ((stateNode == null ? void 0 : stateNode.type) === "final") {
1406
- this.state.done = true;
1407
- this.doneListeners.forEach((listener) => {
1408
- listener(this.stateSnapshot);
1409
- });
1410
- this.stop();
1411
- }
1412
- };
1413
- this.performTransitionEffects = (transition, event) => {
1414
- const t2 = this.determineTransition(transition, event);
1415
- this.executeActions(t2 == null ? void 0 : t2.actions, event);
1416
- };
1417
- this.performStateChangeEffects = (current, next, event) => {
1418
- var _a, _b;
1419
- this.setEvent(event);
1420
- next.target = (_b = (_a = next.target) != null ? _a : this.state.value) != null ? _b : void 0;
1421
- const ok = next.target && next.target !== this.state.value;
1422
- if (ok) {
1423
- this.performExitEffects(current, event);
1424
- }
1425
- this.performTransitionEffects(next == null ? void 0 : next.transition, event);
1426
- this.setState(next.target);
1427
- if (ok) {
1428
- this.performEntryEffects(next.target, event);
1429
- }
1430
- };
1431
- this.determineTransition = (transition, event) => {
1432
- const fn = determineTransitionFn(transition, this.guardMap);
1433
- return fn == null ? void 0 : fn(this.contextSnapshot, event);
1434
- };
1435
- this.sendParent = (evt) => {
1436
- var _a;
1437
- if (!this.parent) {
1438
- invariant("[machine/send-parent] Cannot send event to an unknown parent");
1439
- }
1440
- const event = toEvent(evt);
1441
- (_a = this.parent) == null ? void 0 : _a.send(event);
1442
- };
1443
- this.send = (evt) => {
1444
- const event = toEvent(evt);
1445
- this.transition(this.state.value, event);
1446
- };
1447
- this.transition = (state2, evt) => {
1448
- var _a, _b, _c;
1449
- const stateNode = isString(state2) ? this.getStateNode(state2) : state2 == null ? void 0 : state2.stateNode;
1450
- const event = toEvent(evt);
1451
- if (!stateNode && !this.config.on) {
1452
- const msg = this.status === "Stopped" /* Stopped */ ? "[machine/transition] Cannot transition a stopped machine" : "[machine/transition] State does not have a definition";
1453
- warn(msg);
1454
- return;
1455
- }
1456
- const transitionConfig = (_c = (_a = stateNode == null ? void 0 : stateNode.on) == null ? void 0 : _a[event.type]) != null ? _c : (_b = this.config.on) == null ? void 0 : _b[event.type];
1457
- const transition = toTransition(transitionConfig, this.state.value);
1458
- if (!transition)
1459
- return;
1460
- const info = this.getNextStateInfo(transition, event);
1461
- this.performStateChangeEffects(this.state.value, info, event);
1462
- return info.stateNode;
1463
- };
1464
- this.subscribe = (listener) => {
1465
- this.stateListeners.add(listener);
1466
- if (this.status === "Running" /* Running */) {
1467
- listener(this.stateSnapshot);
1468
- }
1469
- return () => {
1470
- this.stateListeners.delete(listener);
1471
- };
1472
- };
1473
- this.onDone = (listener) => {
1474
- this.doneListeners.add(listener);
1475
- return this;
1476
- };
1477
- this.onTransition = (listener) => {
1478
- this.stateListeners.add(listener);
1479
- if (this.status === "Running" /* Running */) {
1480
- listener(this.stateSnapshot);
1481
- }
1482
- return this;
1483
- };
1484
- this.onEvent = (listener) => {
1485
- listener(this.state.event);
1486
- this.eventListeners.add(listener);
1487
- return this;
1488
- };
1489
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1490
- this.options = klona(options);
1491
- this.id = (_a = config.id) != null ? _a : `machine-${uuid()}`;
1492
- this.guardMap = (_c = (_b = this.options) == null ? void 0 : _b.guards) != null ? _c : {};
1493
- this.actionMap = (_e = (_d = this.options) == null ? void 0 : _d.actions) != null ? _e : {};
1494
- this.delayMap = (_g = (_f = this.options) == null ? void 0 : _f.delays) != null ? _g : {};
1495
- this.activityMap = (_i = (_h = this.options) == null ? void 0 : _h.activities) != null ? _i : {};
1496
- this.sync = (_k = (_j = this.options) == null ? void 0 : _j.sync) != null ? _k : false;
1497
- this.state = createProxy(klona(config));
1498
- this.setupComputed();
1499
- const event = toEvent("machine.created" /* Created */);
1500
- this.executeActions(config == null ? void 0 : config.created, event);
1501
- }
1502
- get stateSnapshot() {
1503
- return cast((0, import_vanilla2.snapshot)(this.state));
1504
- }
1505
- get contextSnapshot() {
1506
- return this.stateSnapshot.context;
1507
- }
1508
- get self() {
1509
- const _self = this;
1510
- return {
1511
- id: this.id,
1512
- send: this.send.bind(this),
1513
- sendParent: this.sendParent.bind(this),
1514
- sendChild: this.sendChild.bind(this),
1515
- stop: this.stop.bind(this),
1516
- stopChild: this.stopChild.bind(this),
1517
- spawn: this.spawn.bind(this),
1518
- get state() {
1519
- return _self.stateSnapshot;
1520
- }
1521
- };
1522
- }
1523
- get meta() {
1524
- return {
1525
- state: this.stateSnapshot,
1526
- guards: this.guardMap,
1527
- send: this.send.bind(this),
1528
- listen: this.onEvent.bind(this),
1529
- self: this.self,
1530
- getState: () => this.stateSnapshot
1531
- };
1532
- }
1533
- };
1534
- var createMachine = (config, options) => new Machine(config, options);
1535
-
1536
825
  // src/slider.machine.ts
1537
- var machine = createMachine({
826
+ var import_core = require("@zag-js/core");
827
+ var machine = (0, import_core.createMachine)({
1538
828
  id: "slider",
1539
829
  initial: "unknown",
1540
830
  context: {
@@ -1693,7 +983,7 @@ var machine = createMachine({
1693
983
  actions: {
1694
984
  setupDocument(ctx, evt) {
1695
985
  if (evt.doc)
1696
- ctx.doc = (0, import_vanilla3.ref)(evt.doc);
986
+ ctx.doc = (0, import_core.ref)(evt.doc);
1697
987
  ctx.uid = evt.id;
1698
988
  },
1699
989
  checkValue(ctx) {