@zag-js/slider 0.1.12 → 0.1.13

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
@@ -837,6 +837,7 @@ function connect(state2, send, normalize) {
837
837
 
838
838
  // src/slider.machine.ts
839
839
  var import_core = require("@zag-js/core");
840
+ var import_element_size = require("@zag-js/element-size");
840
841
  function machine(ctx) {
841
842
  return (0, import_core.createMachine)(
842
843
  {
@@ -867,7 +868,7 @@ function machine(ctx) {
867
868
  watch: {
868
869
  value: ["invokeOnChange", "dispatchChangeEvent"]
869
870
  },
870
- activities: ["trackFormReset", "trackFieldsetDisabled"],
871
+ activities: ["trackFormReset", "trackFieldsetDisabled", "trackThumbSize"],
871
872
  on: {
872
873
  SET_VALUE: {
873
874
  actions: "setValue"
@@ -884,7 +885,7 @@ function machine(ctx) {
884
885
  on: {
885
886
  SETUP: {
886
887
  target: "idle",
887
- actions: ["setThumbSize", "checkValue"]
888
+ actions: ["checkValue"]
888
889
  }
889
890
  }
890
891
  },
@@ -979,12 +980,21 @@ function machine(ctx) {
979
980
  send("POINTER_UP");
980
981
  }
981
982
  });
983
+ },
984
+ trackThumbSize(ctx2, _evt) {
985
+ if (ctx2.thumbAlignment !== "contain")
986
+ return;
987
+ return (0, import_element_size.trackElementSize)(dom.getThumbEl(ctx2), (size) => {
988
+ if (size)
989
+ ctx2.thumbSize = size;
990
+ });
982
991
  }
983
992
  },
984
993
  actions: {
985
994
  checkValue(ctx2) {
986
995
  const value = utils.convert(ctx2, ctx2.value);
987
- Object.assign(ctx2, { value, initialValue: value });
996
+ ctx2.value = value;
997
+ ctx2.initialValue = value;
988
998
  },
989
999
  invokeOnChangeStart(ctx2) {
990
1000
  var _a;
@@ -1001,16 +1011,6 @@ function machine(ctx) {
1001
1011
  dispatchChangeEvent(ctx2) {
1002
1012
  dom.dispatchChangeEvent(ctx2);
1003
1013
  },
1004
- setThumbSize(ctx2) {
1005
- if (ctx2.thumbAlignment !== "contain")
1006
- return;
1007
- raf(() => {
1008
- const el = dom.getThumbEl(ctx2);
1009
- if (!el)
1010
- return;
1011
- ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
1012
- });
1013
- },
1014
1014
  setPointerValue(ctx2, evt) {
1015
1015
  const value = dom.getValueFromPoint(ctx2, evt.point);
1016
1016
  if (value == null)
package/dist/index.mjs CHANGED
@@ -809,6 +809,7 @@ function connect(state2, send, normalize) {
809
809
 
810
810
  // src/slider.machine.ts
811
811
  import { createMachine } from "@zag-js/core";
812
+ import { trackElementSize } from "@zag-js/element-size";
812
813
  function machine(ctx) {
813
814
  return createMachine(
814
815
  {
@@ -839,7 +840,7 @@ function machine(ctx) {
839
840
  watch: {
840
841
  value: ["invokeOnChange", "dispatchChangeEvent"]
841
842
  },
842
- activities: ["trackFormReset", "trackFieldsetDisabled"],
843
+ activities: ["trackFormReset", "trackFieldsetDisabled", "trackThumbSize"],
843
844
  on: {
844
845
  SET_VALUE: {
845
846
  actions: "setValue"
@@ -856,7 +857,7 @@ function machine(ctx) {
856
857
  on: {
857
858
  SETUP: {
858
859
  target: "idle",
859
- actions: ["setThumbSize", "checkValue"]
860
+ actions: ["checkValue"]
860
861
  }
861
862
  }
862
863
  },
@@ -951,12 +952,21 @@ function machine(ctx) {
951
952
  send("POINTER_UP");
952
953
  }
953
954
  });
955
+ },
956
+ trackThumbSize(ctx2, _evt) {
957
+ if (ctx2.thumbAlignment !== "contain")
958
+ return;
959
+ return trackElementSize(dom.getThumbEl(ctx2), (size) => {
960
+ if (size)
961
+ ctx2.thumbSize = size;
962
+ });
954
963
  }
955
964
  },
956
965
  actions: {
957
966
  checkValue(ctx2) {
958
967
  const value = utils.convert(ctx2, ctx2.value);
959
- Object.assign(ctx2, { value, initialValue: value });
968
+ ctx2.value = value;
969
+ ctx2.initialValue = value;
960
970
  },
961
971
  invokeOnChangeStart(ctx2) {
962
972
  var _a;
@@ -973,16 +983,6 @@ function machine(ctx) {
973
983
  dispatchChangeEvent(ctx2) {
974
984
  dom.dispatchChangeEvent(ctx2);
975
985
  },
976
- setThumbSize(ctx2) {
977
- if (ctx2.thumbAlignment !== "contain")
978
- return;
979
- raf(() => {
980
- const el = dom.getThumbEl(ctx2);
981
- if (!el)
982
- return;
983
- ctx2.thumbSize = { width: el.offsetWidth, height: el.offsetHeight };
984
- });
985
- },
986
986
  setPointerValue(ctx2, evt) {
987
987
  const value = dom.getValueFromPoint(ctx2, evt.point);
988
988
  if (value == null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,13 +30,13 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@zag-js/core": "0.1.9",
33
- "@zag-js/types": "0.2.3"
33
+ "@zag-js/element-size": "0.2.0",
34
+ "@zag-js/types": "0.2.4"
34
35
  },
35
36
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.9",
37
+ "@zag-js/dom-utils": "0.1.10",
37
38
  "@zag-js/form-utils": "0.1.0",
38
- "@zag-js/number-utils": "0.1.3",
39
- "@zag-js/utils": "0.1.3"
39
+ "@zag-js/number-utils": "0.1.3"
40
40
  },
41
41
  "scripts": {
42
42
  "build-fast": "tsup src/index.ts --format=esm,cjs",