@zag-js/number-input 0.0.0-dev-20220413174154 → 0.0.0-dev-20220416104915

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,25 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __pow = Math.pow;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
5
  var __export = (target, all) => {
24
6
  for (var name in all)
25
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -42,86 +24,43 @@ __export(src_exports, {
42
24
  });
43
25
  module.exports = __toCommonJS(src_exports);
44
26
 
45
- // ../../utilities/dom/src/attrs.ts
27
+ // ../../utilities/dom/dist/index.mjs
46
28
  var dataAttr = (guard) => {
47
29
  return guard ? "" : void 0;
48
30
  };
49
-
50
- // ../../utilities/dom/src/next-tick.ts
51
31
  function nextTick(fn) {
52
32
  const set = /* @__PURE__ */ new Set();
53
- function raf(fn2) {
33
+ function raf2(fn2) {
54
34
  const id = globalThis.requestAnimationFrame(fn2);
55
35
  set.add(() => globalThis.cancelAnimationFrame(id));
56
36
  }
57
- raf(() => raf(fn));
37
+ raf2(() => raf2(fn));
58
38
  return function cleanup() {
59
39
  set.forEach(function(fn2) {
60
40
  fn2();
61
41
  });
62
42
  };
63
43
  }
64
-
65
- // ../../utilities/core/src/array.ts
66
- function clear(v) {
67
- while (v.length > 0)
68
- v.pop();
69
- return v;
70
- }
71
-
72
- // ../../utilities/core/src/functions.ts
73
- var runIfFn = (v, ...a) => {
74
- const res = typeof v === "function" ? v(...a) : v;
75
- return res != null ? res : void 0;
76
- };
77
- var cast = (v) => v;
78
44
  var noop = () => {
79
45
  };
80
46
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
81
- var uuid = /* @__PURE__ */ (() => {
82
- let id = 0;
83
- return () => {
84
- id++;
85
- return id.toString(36);
86
- };
87
- })();
88
-
89
- // ../../utilities/core/src/guard.ts
90
- var ua = (v) => isDom() && v.test(navigator.userAgent);
91
- var isDom = () => !!(typeof window !== "undefined");
92
- var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
93
- var isArray = (v) => Array.isArray(v);
94
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
95
- var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
96
- var isString = (v) => typeof v === "string";
97
- var isFunction = (v) => typeof v === "function";
98
- var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
99
- var isTouchEvent = (v) => isObject(v) && "touches" in v;
100
-
101
- // ../../utilities/core/src/warning.ts
102
- function warn(...a) {
103
- const m = a.length === 1 ? a[0] : a[1];
104
- const c = a.length === 2 ? a[0] : true;
105
- if (c && void 0 !== "production") {
106
- console.warn(m);
107
- }
47
+ function getListenerElements() {
48
+ ;
49
+ globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
50
+ return globalThis.__listenerElements__;
108
51
  }
109
- function invariant(...a) {
110
- const m = a.length === 1 ? a[0] : a[1];
111
- const c = a.length === 2 ? a[0] : true;
112
- if (c && void 0 !== "production") {
113
- throw new Error(m);
114
- }
52
+ function getListenerCache() {
53
+ ;
54
+ globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
55
+ return globalThis.__listenerCache__;
115
56
  }
116
-
117
- // ../../utilities/dom/src/event-bus.ts
118
- var listenerElements = /* @__PURE__ */ new Map();
119
- var listenerCache = /* @__PURE__ */ new Map();
120
57
  function globalEventBus(node, type, handler, options) {
121
58
  var _a;
122
59
  if (!node)
123
60
  return noop;
124
61
  const hash = JSON.stringify({ type, options });
62
+ const listenerElements = getListenerElements();
63
+ const listenerCache = getListenerCache();
125
64
  const group = listenerElements.get(node);
126
65
  if (!listenerElements.has(node)) {
127
66
  const group2 = /* @__PURE__ */ new Map([[hash, /* @__PURE__ */ new Set([handler])]]);
@@ -167,26 +106,18 @@ function globalEventBus(node, type, handler, options) {
167
106
  }
168
107
  };
169
108
  }
170
-
171
- // ../../utilities/dom/src/listener.ts
172
109
  var t = (v) => Object.prototype.toString.call(v).slice(8, -1);
173
110
  var isRef = (v) => t(v) === "Object" && "current" in v;
174
- var runIfFn2 = (fn) => t(fn) === "Function" ? fn() : fn;
111
+ var runIfFn = (fn) => t(fn) === "Function" ? fn() : fn;
175
112
  function addDomEvent(target, event, listener, options) {
176
- const node = isRef(target) ? target.current : runIfFn2(target);
113
+ const node = isRef(target) ? target.current : runIfFn(target);
177
114
  return globalEventBus(node, event, listener, options);
178
115
  }
179
-
180
- // ../../utilities/dom/src/query.ts
181
116
  function getNativeEvent(event) {
182
117
  var _a;
183
118
  return (_a = event.nativeEvent) != null ? _a : event;
184
119
  }
185
-
186
- // ../../utilities/dom/src/constants.ts
187
120
  var MAX_Z_INDEX = 2147483647;
188
-
189
- // ../../utilities/dom/src/keyboard-event.ts
190
121
  var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
191
122
  var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
192
123
  function getEventStep(event) {
@@ -198,8 +129,6 @@ function getEventStep(event) {
198
129
  return isSkipKey ? 10 : 1;
199
130
  }
200
131
  }
201
-
202
- // ../../utilities/dom/src/mutation-observer.ts
203
132
  function observeAttributes(node, attributes, fn) {
204
133
  if (!node)
205
134
  return noop;
@@ -215,8 +144,6 @@ function observeAttributes(node, attributes, fn) {
215
144
  obs.observe(node, { attributes: true, attributeFilter: attrs });
216
145
  return () => obs.disconnect();
217
146
  }
218
-
219
- // ../../utilities/dom/src/pointerlock.ts
220
147
  function addPointerlockChangeListener(doc, fn) {
221
148
  return addDomEvent(doc, "pointerlockchange", fn, false);
222
149
  }
@@ -258,13 +185,31 @@ function requestPointerLock(doc, handlers = {}) {
258
185
  };
259
186
  }
260
187
 
261
- // ../../utilities/number/src/number-format.ts
188
+ // ../../utilities/number/dist/index.mjs
189
+ var __defProp2 = Object.defineProperty;
190
+ var __defProps = Object.defineProperties;
191
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
192
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
193
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
194
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
195
+ var __pow = Math.pow;
196
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
197
+ var __spreadValues = (a, b) => {
198
+ for (var prop in b || (b = {}))
199
+ if (__hasOwnProp2.call(b, prop))
200
+ __defNormalProp(a, prop, b[prop]);
201
+ if (__getOwnPropSymbols)
202
+ for (var prop of __getOwnPropSymbols(b)) {
203
+ if (__propIsEnum.call(b, prop))
204
+ __defNormalProp(a, prop, b[prop]);
205
+ }
206
+ return a;
207
+ };
208
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
262
209
  var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
263
210
  function formatter(n) {
264
211
  return parseFloat(nf.format(n));
265
212
  }
266
-
267
- // ../../utilities/number/src/number.ts
268
213
  function wrap(num, max) {
269
214
  return (num % max + max) % max;
270
215
  }
@@ -319,14 +264,17 @@ function isWithinRange(v, o) {
319
264
  return val >= o.min && val <= o.max;
320
265
  }
321
266
 
322
- // ../../utilities/rect/src/point.ts
267
+ // ../../utilities/rect/dist/index.mjs
268
+ var isArray = (v) => Array.isArray(v);
269
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
270
+ var isTouchEvent = (v) => isObject(v) && "touches" in v;
323
271
  var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
324
272
  function getEventPoint(e, t2 = "page") {
325
273
  const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback : e;
326
274
  return { x: p[`${t2}X`], y: p[`${t2}Y`] };
327
275
  }
328
276
 
329
- // ../../types/src/prop-types.ts
277
+ // ../../types/dist/index.mjs
330
278
  function createNormalizer(fn) {
331
279
  return { button: fn, label: fn, input: fn, output: fn, element: fn };
332
280
  }
@@ -642,733 +590,19 @@ function connect(state, send, normalize = normalizeProp) {
642
590
  };
643
591
  }
644
592
 
645
- // ../../../node_modules/@zag-js/core/src/index.ts
646
- var import_vanilla3 = require("valtio/vanilla");
647
-
648
- // ../../core/src/action-utils.ts
649
- function choose(actions) {
650
- return {
651
- predicate: (guardMap) => (ctx, event) => {
652
- var _a;
653
- return (_a = actions.find((def) => {
654
- var _a2;
655
- def.guard = def.guard || (() => true);
656
- if (isString(def.guard)) {
657
- return !!((_a2 = guardMap[def.guard]) == null ? void 0 : _a2.call(guardMap, ctx, event));
658
- }
659
- if (isGuardHelper(def.guard)) {
660
- return def.guard.predicate(guardMap != null ? guardMap : {})(ctx, event);
661
- }
662
- return def.guard(ctx, event);
663
- })) == null ? void 0 : _a.actions;
664
- }
665
- };
666
- }
667
- function isGuardHelper(value) {
668
- return isObject(value) && value.predicate != null;
669
- }
670
- function determineActionsFn(values, guardMap) {
671
- return (context, event) => {
672
- if (isGuardHelper(values))
673
- return values.predicate(guardMap != null ? guardMap : {})(context, event);
674
- return values;
675
- };
676
- }
677
-
678
- // ../../core/src/guard-utils.ts
679
- function or(...conditions) {
680
- return {
681
- predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
682
- var _a;
683
- if (isString(condition)) {
684
- return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
685
- }
686
- if (isFunction(condition)) {
687
- return condition(ctx, event);
688
- }
689
- return condition.predicate(guards2)(ctx, event);
690
- }).some(Boolean)
691
- };
692
- }
693
- function and(...conditions) {
694
- return {
695
- predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
696
- var _a;
697
- if (isString(condition)) {
698
- return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
699
- }
700
- if (isFunction(condition)) {
701
- return condition(ctx, event);
702
- }
703
- return condition.predicate(guards2)(ctx, event);
704
- }).every(Boolean)
705
- };
706
- }
707
- function not(condition) {
708
- return {
709
- predicate: (guardMap) => (ctx, event) => {
710
- var _a;
711
- if (isString(condition)) {
712
- return !((_a = guardMap[condition]) == null ? void 0 : _a.call(guardMap, ctx, event));
713
- }
714
- if (isFunction(condition)) {
715
- return !condition(ctx, event);
716
- }
717
- return !condition.predicate(guardMap)(ctx, event);
718
- }
719
- };
720
- }
721
- var guards = { or, and, not };
722
- function isGuardHelper2(value) {
723
- return isObject(value) && value.predicate != null;
724
- }
725
- var TruthyGuard = () => true;
726
- function determineGuardFn(guard, guardMap) {
727
- guard = guard != null ? guard : TruthyGuard;
728
- return (context, event) => {
729
- if (isString(guard)) {
730
- const value = guardMap == null ? void 0 : guardMap[guard];
731
- return isFunction(value) ? value(context, event) : value;
732
- }
733
- if (isGuardHelper2(guard)) {
734
- return guard.predicate(guardMap != null ? guardMap : {})(context, event);
735
- }
736
- return guard == null ? void 0 : guard(context, event);
737
- };
738
- }
739
-
740
- // ../../../node_modules/klona/json/index.mjs
741
- function klona(val) {
742
- var k, out, tmp;
743
- if (Array.isArray(val)) {
744
- out = Array(k = val.length);
745
- while (k--)
746
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
747
- return out;
748
- }
749
- if (Object.prototype.toString.call(val) === "[object Object]") {
750
- out = {};
751
- for (k in val) {
752
- if (k === "__proto__") {
753
- Object.defineProperty(out, k, {
754
- value: klona(val[k]),
755
- configurable: true,
756
- enumerable: true,
757
- writable: true
758
- });
759
- } else {
760
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
761
- }
762
- }
763
- return out;
764
- }
765
- return val;
766
- }
767
-
768
- // ../../core/src/machine.ts
769
- var import_utils13 = require("valtio/utils");
770
- var import_vanilla2 = require("valtio/vanilla");
771
-
772
- // ../../core/src/create-proxy.ts
773
- var import_vanilla = require("valtio/vanilla");
774
- function createProxy(config) {
775
- var _a;
776
- const state = (0, import_vanilla.proxy)({
777
- value: "",
778
- previousValue: "",
779
- event: cast({}),
780
- context: (_a = config.context) != null ? _a : cast({}),
781
- done: false,
782
- tags: [],
783
- hasTag(tag) {
784
- return this.tags.includes(tag);
785
- },
786
- matches(...value) {
787
- return value.includes(this.value);
788
- },
789
- can(event) {
790
- return cast(this).nextEvents.includes(event);
791
- },
792
- get nextEvents() {
793
- var _a2, _b, _c, _d;
794
- const stateEvents = (_c = (_b = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b["on"]) != null ? _c : {};
795
- const globalEvents = (_d = config == null ? void 0 : config.on) != null ? _d : {};
796
- return Object.keys(__spreadValues(__spreadValues({}, stateEvents), globalEvents));
797
- },
798
- get changed() {
799
- if (this.event.value === "machine.init" /* Init */ || !this.previousValue)
800
- return false;
801
- return this.value !== this.previousValue;
802
- }
803
- });
804
- return cast(state);
805
- }
806
-
807
- // ../../core/src/delay-utils.ts
808
- function determineDelayFn(delay, delaysMap) {
809
- return (context, event) => {
810
- if (isNumber(delay))
811
- return delay;
812
- if (isFunction(delay)) {
813
- return delay(context, event);
814
- }
815
- if (isString(delay)) {
816
- const value = Number.parseFloat(delay);
817
- if (!Number.isNaN(value)) {
818
- return value;
819
- }
820
- if (delaysMap) {
821
- const valueOrFn = delaysMap == null ? void 0 : delaysMap[delay];
822
- if (valueOrFn == null) {
823
- const msg = `[machine] Cannot determine delay for ${delay}. It doesn't exist in options.delays`;
824
- throw new Error(msg);
825
- }
826
- return isFunction(valueOrFn) ? valueOrFn(context, event) : valueOrFn;
827
- }
828
- }
829
- };
830
- }
831
-
832
- // ../../core/src/utils.ts
833
- function toEvent(event) {
834
- const obj = isString(event) ? { type: event } : event;
835
- return obj;
836
- }
837
- function toArray(value) {
838
- if (!value)
839
- return [];
840
- return isArray(value) ? value : [value];
841
- }
842
-
843
- // ../../core/src/transition-utils.ts
844
- function toTarget(target) {
845
- return isString(target) ? { target } : target;
846
- }
847
- function determineTransitionFn(transitions, guardMap) {
848
- return (context, event) => {
849
- return toArray(transitions).map(toTarget).find((transition) => {
850
- var _a;
851
- const determineGuard = determineGuardFn(transition.guard, guardMap);
852
- const guard = determineGuard(context, event);
853
- return (_a = guard != null ? guard : transition.target) != null ? _a : transition.actions;
854
- });
855
- };
856
- }
857
- function toTransition(transition, current) {
858
- const _transition = isString(transition) ? toTarget(transition) : transition;
859
- const fn = (t2) => {
860
- const isTargetless = t2.actions && !t2.target;
861
- if (isTargetless && current)
862
- t2.target = current;
863
- return t2;
864
- };
865
- if (isArray(_transition)) {
866
- return _transition.map(fn);
867
- }
868
- if (isObject(_transition)) {
869
- return fn(cast(_transition));
870
- }
871
- }
593
+ // src/number-input.machine.ts
594
+ var import_core = require("@zag-js/core");
872
595
 
873
- // ../../core/src/machine.ts
874
- var Machine = class {
875
- constructor(config, options) {
876
- this.config = config;
877
- this.status = "Not Started" /* NotStarted */;
878
- this.type = "machine" /* Machine */;
879
- this.activityEvents = /* @__PURE__ */ new Map();
880
- this.delayedEvents = /* @__PURE__ */ new Map();
881
- this.stateListeners = /* @__PURE__ */ new Set();
882
- this.eventListeners = /* @__PURE__ */ new Set();
883
- this.doneListeners = /* @__PURE__ */ new Set();
884
- this.contextWatchers = /* @__PURE__ */ new Set();
885
- this.removeStateListener = noop;
886
- this.removeEventListener = noop;
887
- this.children = /* @__PURE__ */ new Map();
888
- this.start = (init) => {
889
- if (this.status === "Running" /* Running */) {
890
- return this;
891
- }
892
- this.status = "Running" /* Running */;
893
- const event = toEvent("machine.init" /* Init */);
894
- if (init) {
895
- const resolved = isObject(init) ? init : { context: this.config.context, value: init };
896
- this.setState(resolved.value);
897
- this.setContext(resolved.context);
898
- }
899
- const transition = {
900
- target: !!init ? void 0 : this.config.initial
901
- };
902
- const info = this.getNextStateInfo(transition, event);
903
- info.target = cast(info.target || transition.target);
904
- this.initialState = info;
905
- this.performStateChangeEffects(info.target, info, event);
906
- this.removeStateListener = (0, import_vanilla2.subscribe)(this.state, () => {
907
- this.stateListeners.forEach((listener) => {
908
- listener(this.stateSnapshot);
909
- });
910
- }, this.sync);
911
- this.removeEventListener = (0, import_utils13.subscribeKey)(this.state, "event", (value) => {
912
- if (this.config.onEvent) {
913
- this.executeActions(this.config.onEvent, value);
914
- }
915
- for (const listener of this.eventListeners) {
916
- listener(value);
917
- }
918
- });
919
- this.setupContextWatchers();
920
- this.executeActivities(toEvent("machine.start" /* Start */), toArray(this.config.activities), "machine.start" /* Start */);
921
- this.executeActions(this.config.entry, toEvent("machine.start" /* Start */));
922
- return this;
923
- };
924
- this.setupContextWatchers = () => {
925
- var _a;
926
- for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) {
927
- this.contextWatchers.add((0, import_utils13.subscribeKey)(this.state.context, key, () => {
928
- this.executeActions(fn, this.state.event);
929
- }));
930
- }
931
- };
932
- this.setupComputed = () => {
933
- var _a;
934
- const computed = cast((_a = this.config.computed) != null ? _a : {});
935
- const deriveFns = Object.fromEntries(Object.entries(computed).map(([key, fn]) => [key, (get) => fn(get(this.state.context))]));
936
- (0, import_utils13.derive)(deriveFns, { proxy: this.state.context });
937
- };
938
- this.detachComputed = () => {
939
- (0, import_utils13.underive)(this.state.context, { delete: true });
940
- };
941
- this.stop = () => {
942
- if (this.status === "Stopped" /* Stopped */)
943
- return;
944
- this.setState(null);
945
- this.setEvent("machine.stop" /* Stop */);
946
- if (this.config.context) {
947
- this.setContext(this.config.context);
948
- }
949
- this.stopStateListeners();
950
- this.stopChildren();
951
- this.stopActivities();
952
- this.stopDelayedEvents();
953
- this.stopContextWatchers();
954
- this.stopEventListeners();
955
- this.detachComputed();
956
- this.status = "Stopped" /* Stopped */;
957
- this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */));
958
- return this;
959
- };
960
- this.stopEventListeners = () => {
961
- this.eventListeners.clear();
962
- this.removeEventListener();
963
- };
964
- this.stopStateListeners = () => {
965
- this.removeStateListener();
966
- this.stateListeners.clear();
967
- };
968
- this.stopContextWatchers = () => {
969
- this.contextWatchers.forEach((fn) => fn());
970
- this.contextWatchers.clear();
971
- };
972
- this.stopDelayedEvents = () => {
973
- this.delayedEvents.forEach((state) => {
974
- state.forEach((stop) => stop());
975
- });
976
- this.delayedEvents.clear();
977
- };
978
- this.stopActivities = (state) => {
979
- var _a, _b;
980
- if (state) {
981
- (_a = this.activityEvents.get(state)) == null ? void 0 : _a.forEach((stop) => stop());
982
- (_b = this.activityEvents.get(state)) == null ? void 0 : _b.clear();
983
- this.activityEvents.delete(state);
984
- } else {
985
- this.activityEvents.forEach((state2) => {
986
- state2.forEach((stop) => stop());
987
- state2.clear();
988
- });
989
- this.activityEvents.clear();
990
- }
991
- };
992
- this.sendChild = (evt, to) => {
993
- const event = toEvent(evt);
994
- const id = runIfFn(to, this.contextSnapshot);
995
- const child = this.children.get(id);
996
- if (!child) {
997
- invariant(`[machine/send-child] Cannot send '${event.type}' event to unknown child`);
998
- }
999
- child.send(event);
1000
- };
1001
- this.stopChild = (id) => {
1002
- if (!this.children.has(id)) {
1003
- invariant("[machine/stop-child] Cannot stop unknown child");
1004
- }
1005
- this.children.get(id).stop();
1006
- this.children.delete(id);
1007
- };
1008
- this.removeChild = (id) => {
1009
- this.children.delete(id);
1010
- };
1011
- this.stopChildren = () => {
1012
- this.children.forEach((child) => child.stop());
1013
- this.children.clear();
1014
- };
1015
- this.setParent = (parent) => {
1016
- this.parent = parent;
1017
- };
1018
- this.spawn = (src, id) => {
1019
- const actor = runIfFn(src);
1020
- if (id)
1021
- actor.id = id;
1022
- actor.type = "machine.actor" /* Actor */;
1023
- actor.setParent(this);
1024
- this.children.set(actor.id, cast(actor));
1025
- actor.onDone(() => {
1026
- this.removeChild(actor.id);
1027
- }).start();
1028
- return cast((0, import_vanilla2.ref)(actor));
1029
- };
1030
- this.addActivityCleanup = (state, cleanup) => {
1031
- var _a;
1032
- if (!state)
1033
- return;
1034
- if (!this.activityEvents.has(state)) {
1035
- this.activityEvents.set(state, /* @__PURE__ */ new Set([cleanup]));
1036
- } else {
1037
- (_a = this.activityEvents.get(state)) == null ? void 0 : _a.add(cleanup);
1038
- }
1039
- };
1040
- this.setState = (target) => {
1041
- this.state.previousValue = this.state.value;
1042
- this.state.value = target;
1043
- const stateNode = this.getStateNode(target);
1044
- if (target == null) {
1045
- clear(this.state.tags);
1046
- } else {
1047
- this.state.tags = toArray(stateNode == null ? void 0 : stateNode.tags);
1048
- }
1049
- };
1050
- this.setContext = (context) => {
1051
- for (const key in context) {
1052
- this.state.context[key] = context[key];
1053
- }
1054
- };
1055
- this.withContext = (context) => {
1056
- this.detachComputed();
1057
- const newContext = __spreadValues(__spreadValues({}, this.config.context), context);
1058
- return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options);
1059
- };
1060
- this.withOptions = (options) => {
1061
- this.detachComputed();
1062
- return new Machine(this.config, __spreadValues(__spreadValues({}, this.options), options));
1063
- };
1064
- this.setActions = (actions) => {
1065
- this.actionMap = __spreadValues(__spreadValues({}, this.actionMap), actions);
1066
- };
1067
- this.clone = () => {
1068
- this.detachComputed();
1069
- return new Machine(this.config, this.options);
1070
- };
1071
- this.getStateNode = (state) => {
1072
- var _a;
1073
- if (!state)
1074
- return;
1075
- return (_a = this.config.states) == null ? void 0 : _a[state];
1076
- };
1077
- this.getNextStateInfo = (transitions, event) => {
1078
- var _a;
1079
- const transition = this.determineTransition(transitions, event);
1080
- const target = (_a = transition == null ? void 0 : transition.target) != null ? _a : this.state.value;
1081
- const stateNode = this.getStateNode(target);
1082
- return {
1083
- transition,
1084
- stateNode,
1085
- target
1086
- };
1087
- };
1088
- this.getActionFromDelayedTransition = (transition) => {
1089
- const event = toEvent("machine.after" /* After */);
1090
- const determineDelay = determineDelayFn(transition.delay, this.delayMap);
1091
- const delay = determineDelay(this.contextSnapshot, event);
1092
- let id;
1093
- return {
1094
- entry: () => {
1095
- id = globalThis.setTimeout(() => {
1096
- const current = this.state.value;
1097
- const next = this.getNextStateInfo(transition, event);
1098
- this.performStateChangeEffects(current, next, event);
1099
- }, delay);
1100
- },
1101
- exit: () => {
1102
- globalThis.clearTimeout(id);
1103
- }
1104
- };
1105
- };
1106
- this.getDelayedEventActions = (state) => {
1107
- const stateNode = this.getStateNode(state);
1108
- const event = toEvent("machine.after" /* After */);
1109
- if (!stateNode || !stateNode.after)
1110
- return;
1111
- const entries = [];
1112
- const exits = [];
1113
- if (isArray(stateNode.after)) {
1114
- const transition = this.determineTransition(stateNode.after, event);
1115
- if (!transition)
1116
- return;
1117
- const actions = this.getActionFromDelayedTransition(transition);
1118
- entries.push(actions.entry);
1119
- exits.push(actions.exit);
1120
- } else if (isObject(stateNode.after)) {
1121
- for (const delay in stateNode.after) {
1122
- const transition = stateNode.after[delay];
1123
- let resolvedTransition = {};
1124
- if (isArray(transition)) {
1125
- const picked = this.determineTransition(transition, event);
1126
- if (picked)
1127
- resolvedTransition = picked;
1128
- } else if (isString(transition)) {
1129
- resolvedTransition = { target: transition, delay };
1130
- } else {
1131
- resolvedTransition = __spreadProps(__spreadValues({}, transition), { delay });
1132
- }
1133
- const actions = this.getActionFromDelayedTransition(resolvedTransition);
1134
- entries.push(actions.entry);
1135
- exits.push(actions.exit);
1136
- }
1137
- }
1138
- return { entries, exits };
1139
- };
1140
- this.executeActions = (actions, event) => {
1141
- var _a;
1142
- const _actions = determineActionsFn(actions, this.guardMap)(this.contextSnapshot, event);
1143
- for (const action of toArray(_actions)) {
1144
- const fn = isString(action) ? (_a = this.actionMap) == null ? void 0 : _a[action] : action;
1145
- warn(isString(action) && !fn, `[machine/exec-action] No implementation found for action: \`${action}\``);
1146
- fn == null ? void 0 : fn(this.state.context, event, this.meta);
1147
- }
1148
- };
1149
- this.executeActivities = (event, activities, state) => {
1150
- var _a;
1151
- for (const activity of activities) {
1152
- const fn = isString(activity) ? (_a = this.activityMap) == null ? void 0 : _a[activity] : activity;
1153
- if (!fn) {
1154
- warn(`[machine/exec-activity] No implementation found for activity: \`${activity}\``);
1155
- continue;
1156
- }
1157
- const cleanup = fn(this.state.context, event, this.meta);
1158
- if (cleanup) {
1159
- this.addActivityCleanup(state != null ? state : this.state.value, cleanup);
1160
- }
1161
- }
1162
- };
1163
- this.createEveryActivities = (every, callbackfn) => {
1164
- if (!every)
1165
- return;
1166
- const event = toEvent("machine.every" /* Every */);
1167
- if (isArray(every)) {
1168
- const picked = toArray(every).find((t2) => {
1169
- const determineDelay2 = determineDelayFn(t2.delay, this.delayMap);
1170
- t2.delay = determineDelay2(this.contextSnapshot, event);
1171
- const determineGuard = determineGuardFn(t2.guard, this.guardMap);
1172
- const guard = determineGuard(this.contextSnapshot, event);
1173
- return guard != null ? guard : t2.delay;
1174
- });
1175
- if (!picked)
1176
- return;
1177
- const determineDelay = determineDelayFn(picked.delay, this.delayMap);
1178
- const delay = determineDelay(this.contextSnapshot, event);
1179
- const activity = () => {
1180
- const id = globalThis.setInterval(() => {
1181
- this.executeActions(picked.actions, event);
1182
- }, delay);
1183
- return () => {
1184
- globalThis.clearInterval(id);
1185
- };
1186
- };
1187
- callbackfn(activity);
1188
- } else {
1189
- for (const interval in every) {
1190
- const actions = every == null ? void 0 : every[interval];
1191
- const determineDelay = determineDelayFn(interval, this.delayMap);
1192
- const delay = determineDelay(this.contextSnapshot, event);
1193
- const activity = () => {
1194
- const id = globalThis.setInterval(() => {
1195
- this.executeActions(actions, event);
1196
- }, delay);
1197
- return () => {
1198
- globalThis.clearInterval(id);
1199
- };
1200
- };
1201
- callbackfn(activity);
1202
- }
1203
- }
1204
- };
1205
- this.setEvent = (event) => {
1206
- this.state.event = (0, import_vanilla2.ref)(toEvent(event));
1207
- };
1208
- this.performExitEffects = (current, event) => {
1209
- const currentState = this.state.value;
1210
- const stateNode = current ? this.getStateNode(current) : void 0;
1211
- this.stopActivities(currentState);
1212
- const _exit = determineActionsFn(stateNode == null ? void 0 : stateNode.exit, this.guardMap)(this.contextSnapshot, event);
1213
- const exitActions = toArray(_exit);
1214
- const afterExitActions = this.delayedEvents.get(currentState);
1215
- if (afterExitActions) {
1216
- exitActions.push(...afterExitActions);
1217
- }
1218
- this.executeActions(exitActions, event);
1219
- this.eventListeners.clear();
1220
- };
1221
- this.performEntryEffects = (next, event) => {
1222
- const stateNode = this.getStateNode(next);
1223
- const activities = toArray(stateNode == null ? void 0 : stateNode.activities);
1224
- this.createEveryActivities(stateNode == null ? void 0 : stateNode.every, (activity) => {
1225
- activities.unshift(activity);
1226
- });
1227
- if (activities.length > 0) {
1228
- this.executeActivities(event, activities);
1229
- }
1230
- const _entry = determineActionsFn(stateNode == null ? void 0 : stateNode.entry, this.guardMap)(this.contextSnapshot, event);
1231
- const entryActions = toArray(_entry);
1232
- const afterActions = this.getDelayedEventActions(next);
1233
- if ((stateNode == null ? void 0 : stateNode.after) && afterActions) {
1234
- this.delayedEvents.set(next, afterActions == null ? void 0 : afterActions.exits);
1235
- entryActions.push(...afterActions.entries);
1236
- }
1237
- this.executeActions(entryActions, event);
1238
- if ((stateNode == null ? void 0 : stateNode.type) === "final") {
1239
- this.state.done = true;
1240
- this.doneListeners.forEach((listener) => {
1241
- listener(this.stateSnapshot);
1242
- });
1243
- this.stop();
1244
- }
1245
- };
1246
- this.performTransitionEffects = (transition, event) => {
1247
- const t2 = this.determineTransition(transition, event);
1248
- this.executeActions(t2 == null ? void 0 : t2.actions, event);
1249
- };
1250
- this.performStateChangeEffects = (current, next, event) => {
1251
- var _a, _b;
1252
- this.setEvent(event);
1253
- next.target = (_b = (_a = next.target) != null ? _a : this.state.value) != null ? _b : void 0;
1254
- const ok = next.target && next.target !== this.state.value;
1255
- if (ok) {
1256
- this.performExitEffects(current, event);
1257
- }
1258
- this.performTransitionEffects(next == null ? void 0 : next.transition, event);
1259
- this.setState(next.target);
1260
- if (ok) {
1261
- this.performEntryEffects(next.target, event);
1262
- }
1263
- };
1264
- this.determineTransition = (transition, event) => {
1265
- const fn = determineTransitionFn(transition, this.guardMap);
1266
- return fn == null ? void 0 : fn(this.contextSnapshot, event);
1267
- };
1268
- this.sendParent = (evt) => {
1269
- var _a;
1270
- if (!this.parent) {
1271
- invariant("[machine/send-parent] Cannot send event to an unknown parent");
1272
- }
1273
- const event = toEvent(evt);
1274
- (_a = this.parent) == null ? void 0 : _a.send(event);
1275
- };
1276
- this.send = (evt) => {
1277
- const event = toEvent(evt);
1278
- this.transition(this.state.value, event);
1279
- };
1280
- this.transition = (state, evt) => {
1281
- var _a, _b, _c;
1282
- const stateNode = isString(state) ? this.getStateNode(state) : state == null ? void 0 : state.stateNode;
1283
- const event = toEvent(evt);
1284
- if (!stateNode && !this.config.on) {
1285
- const msg = this.status === "Stopped" /* Stopped */ ? "[machine/transition] Cannot transition a stopped machine" : "[machine/transition] State does not have a definition";
1286
- warn(msg);
1287
- return;
1288
- }
1289
- 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];
1290
- const transition = toTransition(transitionConfig, this.state.value);
1291
- if (!transition)
1292
- return;
1293
- const info = this.getNextStateInfo(transition, event);
1294
- this.performStateChangeEffects(this.state.value, info, event);
1295
- return info.stateNode;
1296
- };
1297
- this.subscribe = (listener) => {
1298
- this.stateListeners.add(listener);
1299
- if (this.status === "Running" /* Running */) {
1300
- listener(this.stateSnapshot);
1301
- }
1302
- return () => {
1303
- this.stateListeners.delete(listener);
1304
- };
1305
- };
1306
- this.onDone = (listener) => {
1307
- this.doneListeners.add(listener);
1308
- return this;
1309
- };
1310
- this.onTransition = (listener) => {
1311
- this.stateListeners.add(listener);
1312
- if (this.status === "Running" /* Running */) {
1313
- listener(this.stateSnapshot);
1314
- }
1315
- return this;
1316
- };
1317
- this.onEvent = (listener) => {
1318
- listener(this.state.event);
1319
- this.eventListeners.add(listener);
1320
- return this;
1321
- };
1322
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1323
- this.options = klona(options);
1324
- this.id = (_a = config.id) != null ? _a : `machine-${uuid()}`;
1325
- this.guardMap = (_c = (_b = this.options) == null ? void 0 : _b.guards) != null ? _c : {};
1326
- this.actionMap = (_e = (_d = this.options) == null ? void 0 : _d.actions) != null ? _e : {};
1327
- this.delayMap = (_g = (_f = this.options) == null ? void 0 : _f.delays) != null ? _g : {};
1328
- this.activityMap = (_i = (_h = this.options) == null ? void 0 : _h.activities) != null ? _i : {};
1329
- this.sync = (_k = (_j = this.options) == null ? void 0 : _j.sync) != null ? _k : false;
1330
- this.state = createProxy(klona(config));
1331
- this.setupComputed();
1332
- const event = toEvent("machine.created" /* Created */);
1333
- this.executeActions(config == null ? void 0 : config.created, event);
1334
- }
1335
- get stateSnapshot() {
1336
- return cast((0, import_vanilla2.snapshot)(this.state));
1337
- }
1338
- get contextSnapshot() {
1339
- return this.stateSnapshot.context;
1340
- }
1341
- get self() {
1342
- const _self = this;
1343
- return {
1344
- id: this.id,
1345
- send: this.send.bind(this),
1346
- sendParent: this.sendParent.bind(this),
1347
- sendChild: this.sendChild.bind(this),
1348
- stop: this.stop.bind(this),
1349
- stopChild: this.stopChild.bind(this),
1350
- spawn: this.spawn.bind(this),
1351
- get state() {
1352
- return _self.stateSnapshot;
1353
- }
1354
- };
1355
- }
1356
- get meta() {
1357
- return {
1358
- state: this.stateSnapshot,
1359
- guards: this.guardMap,
1360
- send: this.send.bind(this),
1361
- listen: this.onEvent.bind(this),
1362
- self: this.self,
1363
- getState: () => this.stateSnapshot
1364
- };
1365
- }
1366
- };
1367
- var createMachine = (config, options) => new Machine(config, options);
596
+ // ../../utilities/core/dist/index.mjs
597
+ var pipe2 = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
598
+ var ua = (v) => isDom() && v.test(navigator.userAgent);
599
+ var isDom = () => !!(typeof window !== "undefined");
600
+ var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
601
+ var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
1368
602
 
1369
603
  // src/number-input.machine.ts
1370
- var { not: not2, and: and2 } = guards;
1371
- var machine = createMachine({
604
+ var { not, and } = import_core.guards;
605
+ var machine = (0, import_core.createMachine)({
1372
606
  id: "number-input",
1373
607
  initial: "unknown",
1374
608
  context: {
@@ -1478,7 +712,7 @@ var machine = createMachine({
1478
712
  actions: ["clearValue", "clearHint"]
1479
713
  },
1480
714
  {
1481
- guard: and2("clampOnBlur", not2("isInRange")),
715
+ guard: and("clampOnBlur", not("isInRange")),
1482
716
  target: "idle",
1483
717
  actions: ["clampValue", "clearHint"]
1484
718
  },
@@ -1490,7 +724,7 @@ var machine = createMachine({
1490
724
  },
1491
725
  "before:spin": {
1492
726
  tags: ["focus"],
1493
- entry: choose([
727
+ entry: (0, import_core.choose)([
1494
728
  { guard: "isIncrementHint", actions: "increment" },
1495
729
  { guard: "isDecrementHint", actions: "decrement" }
1496
730
  ]),
@@ -1513,12 +747,12 @@ var machine = createMachine({
1513
747
  every: [
1514
748
  {
1515
749
  delay: "CHANGE_INTERVAL",
1516
- guard: and2(not2("isAtMin"), "isIncrementHint"),
750
+ guard: and(not("isAtMin"), "isIncrementHint"),
1517
751
  actions: "increment"
1518
752
  },
1519
753
  {
1520
754
  delay: "CHANGE_INTERVAL",
1521
- guard: and2(not2("isAtMax"), "isDecrementHint"),
755
+ guard: and(not("isAtMax"), "isDecrementHint"),
1522
756
  actions: "decrement"
1523
757
  }
1524
758
  ],
@@ -1624,13 +858,13 @@ var machine = createMachine({
1624
858
  function onMouseup() {
1625
859
  send("POINTER_UP_SCRUBBER");
1626
860
  }
1627
- return pipe(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
861
+ return pipe2(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
1628
862
  }
1629
863
  },
1630
864
  actions: {
1631
865
  setupDocument: (ctx, evt) => {
1632
866
  if (evt.doc)
1633
- ctx.doc = (0, import_vanilla3.ref)(evt.doc);
867
+ ctx.doc = (0, import_core.ref)(evt.doc);
1634
868
  ctx.uid = evt.id;
1635
869
  },
1636
870
  focusInput(ctx) {