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