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

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
@@ -507,34 +507,34 @@ var dom = {
507
507
  },
508
508
  getRootId: (ctx) => {
509
509
  var _a, _b;
510
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider-${ctx.uid}`;
510
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
511
511
  },
512
512
  getThumbId: (ctx) => {
513
513
  var _a, _b;
514
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider-${ctx.uid}-thumb`;
514
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.uid}:thumb`;
515
515
  },
516
516
  getControlId: (ctx) => {
517
517
  var _a, _b;
518
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider-${ctx.uid}-control`;
518
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.uid}:control`;
519
519
  },
520
- getInputId: (ctx) => `slider-${ctx.uid}-input`,
520
+ getInputId: (ctx) => `slider:${ctx.uid}:input`,
521
521
  getOutputId: (ctx) => {
522
522
  var _a, _b;
523
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider-${ctx.uid}-output`;
523
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.uid}:output`;
524
524
  },
525
525
  getTrackId: (ctx) => {
526
526
  var _a, _b;
527
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider--${ctx.uid}track`;
527
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
528
528
  },
529
529
  getRangeId: (ctx) => {
530
530
  var _a, _b;
531
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider-${ctx.uid}-range`;
531
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}:range`;
532
532
  },
533
533
  getLabelId: (ctx) => {
534
534
  var _a, _b;
535
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider-${ctx.uid}-label`;
535
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
536
536
  },
537
- getMarkerId: (ctx, value) => `slider-${ctx.uid}-marker-${value}`,
537
+ getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
538
538
  getThumbEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getThumbId(ctx)),
539
539
  getControlEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getControlId(ctx)),
540
540
  getInputEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getInputId(ctx)),
@@ -800,224 +800,226 @@ function connect(state2, send, normalize = normalizeProp) {
800
800
 
801
801
  // src/slider.machine.ts
802
802
  import { createMachine, ref } from "@zag-js/core";
803
- var machine = createMachine({
804
- id: "slider",
805
- initial: "unknown",
806
- context: {
807
- thumbSize: null,
808
- uid: "",
809
- disabled: false,
810
- threshold: 5,
811
- dir: "ltr",
812
- origin: "start",
813
- orientation: "horizontal",
814
- initialValue: null,
815
- value: 0,
816
- step: 1,
817
- min: 0,
818
- max: 100
819
- },
820
- computed: {
821
- isHorizontal: (ctx) => ctx.orientation === "horizontal",
822
- isVertical: (ctx) => ctx.orientation === "vertical",
823
- isRtl: (ctx) => ctx.orientation === "horizontal" && ctx.dir === "rtl",
824
- isInteractive: (ctx) => !(ctx.disabled || ctx.readonly),
825
- hasMeasuredThumbSize: (ctx) => ctx.thumbSize !== null
826
- },
827
- watch: {
828
- value: ["invokeOnChange", "dispatchChangeEvent"]
829
- },
830
- activities: ["trackFormReset", "trackScriptedUpdate"],
831
- on: {
832
- SET_VALUE: {
833
- actions: "setValue"
834
- },
835
- INCREMENT: {
836
- actions: "increment"
837
- },
838
- DECREMENT: {
839
- actions: "decrement"
840
- }
841
- },
842
- states: {
843
- unknown: {
844
- on: {
845
- SETUP: {
846
- target: "idle",
847
- actions: ["setupDocument", "setThumbSize", "checkValue"]
848
- }
849
- }
803
+ function machine(ctx = {}) {
804
+ return createMachine({
805
+ id: "slider",
806
+ initial: "unknown",
807
+ context: __spreadValues({
808
+ thumbSize: null,
809
+ uid: "",
810
+ disabled: false,
811
+ threshold: 5,
812
+ dir: "ltr",
813
+ origin: "start",
814
+ orientation: "horizontal",
815
+ initialValue: null,
816
+ value: 0,
817
+ step: 1,
818
+ min: 0,
819
+ max: 100
820
+ }, ctx),
821
+ computed: {
822
+ isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
823
+ isVertical: (ctx2) => ctx2.orientation === "vertical",
824
+ isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
825
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readonly),
826
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
850
827
  },
851
- idle: {
852
- on: {
853
- POINTER_DOWN: {
854
- target: "dragging",
855
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
856
- },
857
- FOCUS: "focus"
858
- }
828
+ watch: {
829
+ value: ["invokeOnChange", "dispatchChangeEvent"]
859
830
  },
860
- focus: {
861
- entry: "focusThumb",
862
- on: {
863
- POINTER_DOWN: {
864
- target: "dragging",
865
- actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
866
- },
867
- ARROW_LEFT: {
868
- guard: "isHorizontal",
869
- actions: "decrement"
870
- },
871
- ARROW_RIGHT: {
872
- guard: "isHorizontal",
873
- actions: "increment"
874
- },
875
- ARROW_UP: {
876
- guard: "isVertical",
877
- actions: "increment"
878
- },
879
- ARROW_DOWN: {
880
- guard: "isVertical",
881
- actions: "decrement"
882
- },
883
- PAGE_UP: {
884
- actions: "increment"
885
- },
886
- PAGE_DOWN: {
887
- actions: "decrement"
888
- },
889
- HOME: {
890
- actions: "setToMin"
891
- },
892
- END: {
893
- actions: "setToMax"
894
- },
895
- BLUR: "idle"
831
+ activities: ["trackFormReset", "trackScriptedUpdate"],
832
+ on: {
833
+ SET_VALUE: {
834
+ actions: "setValue"
835
+ },
836
+ INCREMENT: {
837
+ actions: "increment"
838
+ },
839
+ DECREMENT: {
840
+ actions: "decrement"
896
841
  }
897
842
  },
898
- dragging: {
899
- entry: "focusThumb",
900
- activities: "trackPointerMove",
901
- on: {
902
- POINTER_UP: {
903
- target: "focus",
904
- actions: "invokeOnChangeEnd"
905
- },
906
- POINTER_MOVE: {
907
- actions: "setPointerValue"
843
+ states: {
844
+ unknown: {
845
+ on: {
846
+ SETUP: {
847
+ target: "idle",
848
+ actions: ["setupDocument", "setThumbSize", "checkValue"]
849
+ }
850
+ }
851
+ },
852
+ idle: {
853
+ on: {
854
+ POINTER_DOWN: {
855
+ target: "dragging",
856
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
857
+ },
858
+ FOCUS: "focus"
859
+ }
860
+ },
861
+ focus: {
862
+ entry: "focusThumb",
863
+ on: {
864
+ POINTER_DOWN: {
865
+ target: "dragging",
866
+ actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
867
+ },
868
+ ARROW_LEFT: {
869
+ guard: "isHorizontal",
870
+ actions: "decrement"
871
+ },
872
+ ARROW_RIGHT: {
873
+ guard: "isHorizontal",
874
+ actions: "increment"
875
+ },
876
+ ARROW_UP: {
877
+ guard: "isVertical",
878
+ actions: "increment"
879
+ },
880
+ ARROW_DOWN: {
881
+ guard: "isVertical",
882
+ actions: "decrement"
883
+ },
884
+ PAGE_UP: {
885
+ actions: "increment"
886
+ },
887
+ PAGE_DOWN: {
888
+ actions: "decrement"
889
+ },
890
+ HOME: {
891
+ actions: "setToMin"
892
+ },
893
+ END: {
894
+ actions: "setToMax"
895
+ },
896
+ BLUR: "idle"
897
+ }
898
+ },
899
+ dragging: {
900
+ entry: "focusThumb",
901
+ activities: "trackPointerMove",
902
+ on: {
903
+ POINTER_UP: {
904
+ target: "focus",
905
+ actions: "invokeOnChangeEnd"
906
+ },
907
+ POINTER_MOVE: {
908
+ actions: "setPointerValue"
909
+ }
908
910
  }
909
911
  }
910
912
  }
911
- }
912
- }, {
913
- guards: {
914
- isHorizontal: (ctx) => ctx.isHorizontal,
915
- isVertical: (ctx) => ctx.isVertical
916
- },
917
- activities: {
918
- trackScriptedUpdate(ctx, _, { send }) {
919
- let cleanup;
920
- nextTick(() => {
921
- const el = dom.getInputEl(ctx);
922
- if (!el)
923
- return;
924
- cleanup = trackInputPropertyMutation(el, {
925
- type: "input",
926
- property: "value",
927
- fn(value) {
928
- send({ type: "SET_VALUE", value: parseFloat(value) });
913
+ }, {
914
+ guards: {
915
+ isHorizontal: (ctx2) => ctx2.isHorizontal,
916
+ isVertical: (ctx2) => ctx2.isVertical
917
+ },
918
+ activities: {
919
+ trackScriptedUpdate(ctx2, _, { send }) {
920
+ let cleanup;
921
+ nextTick(() => {
922
+ const el = dom.getInputEl(ctx2);
923
+ if (!el)
924
+ return;
925
+ cleanup = trackInputPropertyMutation(el, {
926
+ type: "input",
927
+ property: "value",
928
+ fn(value) {
929
+ send({ type: "SET_VALUE", value: parseFloat(value) });
930
+ }
931
+ });
932
+ });
933
+ return () => cleanup == null ? void 0 : cleanup();
934
+ },
935
+ trackFormReset(ctx2) {
936
+ let cleanup;
937
+ nextTick(() => {
938
+ const el = dom.getInputEl(ctx2);
939
+ if (!el)
940
+ return;
941
+ cleanup = trackFormReset(el, () => {
942
+ if (ctx2.initialValue != null)
943
+ ctx2.value = ctx2.initialValue;
944
+ });
945
+ });
946
+ return cleanup;
947
+ },
948
+ trackPointerMove(ctx2, _evt, { send }) {
949
+ return trackPointerMove({
950
+ ctx: ctx2,
951
+ onPointerMove(info) {
952
+ send({ type: "POINTER_MOVE", point: info.point });
953
+ },
954
+ onPointerUp() {
955
+ send("POINTER_UP");
929
956
  }
930
957
  });
931
- });
932
- return () => cleanup == null ? void 0 : cleanup();
958
+ }
933
959
  },
934
- trackFormReset(ctx) {
935
- let cleanup;
936
- nextTick(() => {
937
- const el = dom.getInputEl(ctx);
938
- if (!el)
939
- return;
940
- cleanup = trackFormReset(el, () => {
941
- if (ctx.initialValue != null)
942
- ctx.value = ctx.initialValue;
960
+ actions: {
961
+ setupDocument(ctx2, evt) {
962
+ if (evt.doc)
963
+ ctx2.doc = ref(evt.doc);
964
+ ctx2.uid = evt.id;
965
+ },
966
+ checkValue(ctx2) {
967
+ const value = utils.convert(ctx2, ctx2.value);
968
+ Object.assign(ctx2, { value, initialValue: value });
969
+ },
970
+ invokeOnChangeStart(ctx2) {
971
+ var _a;
972
+ (_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
973
+ },
974
+ invokeOnChangeEnd(ctx2) {
975
+ var _a;
976
+ (_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
977
+ },
978
+ invokeOnChange(ctx2) {
979
+ var _a;
980
+ (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
981
+ },
982
+ dispatchChangeEvent(ctx2) {
983
+ dom.dispatchChangeEvent(ctx2);
984
+ },
985
+ setThumbSize(ctx2) {
986
+ raf(() => {
987
+ const el = dom.getThumbEl(ctx2);
988
+ if (!el)
989
+ return;
990
+ ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
943
991
  });
944
- });
945
- return cleanup;
946
- },
947
- trackPointerMove(ctx, _evt, { send }) {
948
- return trackPointerMove({
949
- ctx,
950
- onPointerMove(info) {
951
- send({ type: "POINTER_MOVE", point: info.point });
952
- },
953
- onPointerUp() {
954
- send("POINTER_UP");
955
- }
956
- });
957
- }
958
- },
959
- actions: {
960
- setupDocument(ctx, evt) {
961
- if (evt.doc)
962
- ctx.doc = ref(evt.doc);
963
- ctx.uid = evt.id;
964
- },
965
- checkValue(ctx) {
966
- const value = utils.convert(ctx, ctx.value);
967
- Object.assign(ctx, { value, initialValue: value });
968
- },
969
- invokeOnChangeStart(ctx) {
970
- var _a;
971
- (_a = ctx.onChangeStart) == null ? void 0 : _a.call(ctx, { value: ctx.value });
972
- },
973
- invokeOnChangeEnd(ctx) {
974
- var _a;
975
- (_a = ctx.onChangeEnd) == null ? void 0 : _a.call(ctx, { value: ctx.value });
976
- },
977
- invokeOnChange(ctx) {
978
- var _a;
979
- (_a = ctx.onChange) == null ? void 0 : _a.call(ctx, { value: ctx.value });
980
- },
981
- dispatchChangeEvent(ctx) {
982
- dom.dispatchChangeEvent(ctx);
983
- },
984
- setThumbSize(ctx) {
985
- raf(() => {
986
- const el = dom.getThumbEl(ctx);
987
- if (!el)
992
+ },
993
+ setPointerValue(ctx2, evt) {
994
+ const value = dom.getValueFromPoint(ctx2, evt.point);
995
+ if (value == null)
988
996
  return;
989
- ctx.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
990
- });
991
- },
992
- setPointerValue(ctx, evt) {
993
- const value = dom.getValueFromPoint(ctx, evt.point);
994
- if (value == null)
995
- return;
996
- ctx.value = utils.clamp(ctx, value);
997
- },
998
- focusThumb(ctx) {
999
- nextTick(() => {
1000
- var _a;
1001
- return (_a = dom.getThumbEl(ctx)) == null ? void 0 : _a.focus();
1002
- });
1003
- },
1004
- decrement(ctx, evt) {
1005
- ctx.value = utils.decrement(ctx, evt.step);
1006
- },
1007
- increment(ctx, evt) {
1008
- ctx.value = utils.increment(ctx, evt.step);
1009
- },
1010
- setToMin(ctx) {
1011
- ctx.value = ctx.min;
1012
- },
1013
- setToMax(ctx) {
1014
- ctx.value = ctx.max;
1015
- },
1016
- setValue(ctx, evt) {
1017
- ctx.value = utils.convert(ctx, evt.value);
997
+ ctx2.value = utils.clamp(ctx2, value);
998
+ },
999
+ focusThumb(ctx2) {
1000
+ nextTick(() => {
1001
+ var _a;
1002
+ return (_a = dom.getThumbEl(ctx2)) == null ? void 0 : _a.focus();
1003
+ });
1004
+ },
1005
+ decrement(ctx2, evt) {
1006
+ ctx2.value = utils.decrement(ctx2, evt.step);
1007
+ },
1008
+ increment(ctx2, evt) {
1009
+ ctx2.value = utils.increment(ctx2, evt.step);
1010
+ },
1011
+ setToMin(ctx2) {
1012
+ ctx2.value = ctx2.min;
1013
+ },
1014
+ setToMax(ctx2) {
1015
+ ctx2.value = ctx2.max;
1016
+ },
1017
+ setValue(ctx2, evt) {
1018
+ ctx2.value = utils.convert(ctx2, evt.value);
1019
+ }
1018
1020
  }
1019
- }
1020
- });
1021
+ });
1022
+ }
1021
1023
  export {
1022
1024
  connect,
1023
1025
  machine,