@zag-js/slider 1.8.1 → 1.8.2

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
@@ -4,7 +4,6 @@ var anatomy$1 = require('@zag-js/anatomy');
4
4
  var domQuery = require('@zag-js/dom-query');
5
5
  var utils = require('@zag-js/utils');
6
6
  var core = require('@zag-js/core');
7
- var elementSize = require('@zag-js/element-size');
8
7
  var types = require('@zag-js/types');
9
8
 
10
9
  // src/slider.anatomy.ts
@@ -32,11 +31,11 @@ var getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text
32
31
  var getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
33
32
  var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
34
33
  var getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
34
+ var getThumbEls = (ctx) => domQuery.queryAll(getControlEl(ctx), "[role=slider]");
35
+ var getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
35
36
  var getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
36
37
  var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
37
- var getElements = (ctx) => domQuery.queryAll(getControlEl(ctx), "[role=slider]");
38
- var getFirstEl = (ctx) => getElements(ctx)[0];
39
- var getValueFromPoint = (params, point) => {
38
+ var getPointValue = (params, point) => {
40
39
  const { prop, scope } = params;
41
40
  const controlEl = getControlEl(scope);
42
41
  if (!controlEl) return;
@@ -55,6 +54,12 @@ var dispatchChangeEvent = (ctx, value) => {
55
54
  domQuery.dispatchInputValueEvent(inputEl, { value: value2 });
56
55
  });
57
56
  };
57
+ var getOffsetRect = (el) => ({
58
+ left: el?.offsetLeft ?? 0,
59
+ top: el?.offsetTop ?? 0,
60
+ width: el?.offsetWidth ?? 0,
61
+ height: el?.offsetHeight ?? 0
62
+ });
58
63
  function getBounds(value) {
59
64
  const firstValue = value[0];
60
65
  const lastThumb = value[value.length - 1];
@@ -306,7 +311,7 @@ function connect(service, normalize2) {
306
311
  onClick(event) {
307
312
  if (!interactive) return;
308
313
  event.preventDefault();
309
- getFirstEl(scope)?.focus();
314
+ getFirstThumbEl(scope)?.focus();
310
315
  },
311
316
  style: {
312
317
  userSelect: "none",
@@ -611,7 +616,7 @@ var machine = core.createMachine({
611
616
  action(["syncInputElements", "dispatchChangeEvent"]);
612
617
  });
613
618
  },
614
- effects: ["trackFormControlState", "trackThumbsSize"],
619
+ effects: ["trackFormControlState", "trackThumbSize"],
615
620
  on: {
616
621
  SET_VALUE: [
617
622
  {
@@ -714,13 +719,16 @@ var machine = core.createMachine({
714
719
  }
715
720
  });
716
721
  },
717
- trackThumbsSize({ context, scope, prop }) {
722
+ trackThumbSize({ context, scope, prop }) {
718
723
  if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
719
- return elementSize.trackElementsSize({
720
- getNodes: () => getElements(scope),
721
- observeMutation: true,
722
- callback(size) {
723
- if (!size || isEqualSize(context.get("thumbSize"), size)) return;
724
+ return domQuery.trackElementRect(getThumbEls(scope), {
725
+ box: "border-box",
726
+ measure(el) {
727
+ return getOffsetRect(el);
728
+ },
729
+ onEntry({ rects }) {
730
+ const size = utils.pick(rects[0], ["width", "height"]);
731
+ if (isEqualSize(context.get("thumbSize"), size)) return;
724
732
  context.set("thumbSize", size);
725
733
  }
726
734
  });
@@ -741,7 +749,7 @@ var machine = core.createMachine({
741
749
  },
742
750
  setClosestThumbIndex(params) {
743
751
  const { context, event } = params;
744
- const pointValue = getValueFromPoint(params, event.point);
752
+ const pointValue = getPointValue(params, event.point);
745
753
  if (pointValue == null) return;
746
754
  const focusedIndex = getClosestIndex(params, pointValue);
747
755
  context.set("focusedIndex", focusedIndex);
@@ -755,7 +763,7 @@ var machine = core.createMachine({
755
763
  setPointerValue(params) {
756
764
  queueMicrotask(() => {
757
765
  const { context, event } = params;
758
- const pointValue = getValueFromPoint(params, event.point);
766
+ const pointValue = getPointValue(params, event.point);
759
767
  if (pointValue == null) return;
760
768
  const focusedIndex = context.get("focusedIndex");
761
769
  const value = constrainValue(params, pointValue, focusedIndex);
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
- import { raf, setElementValue, queryAll, trackPointerMove, trackFormControl, getRelativePoint, dispatchInputValueEvent, dataAttr, isLeftClick, isModifierKey, getEventPoint, ariaAttr, getEventStep, getEventKey } from '@zag-js/dom-query';
3
- import { setValueAtIndex, getValuePercent, isEqual, createSplitProps, snapValueToStep, clampValue, getValueRanges, getNextStepValue, getPreviousStepValue, getPercentValue, getClosestValueIndex, first, last, toPx, getValueTransformer } from '@zag-js/utils';
2
+ import { raf, setElementValue, trackElementRect, queryAll, trackPointerMove, trackFormControl, getRelativePoint, dispatchInputValueEvent, dataAttr, isLeftClick, isModifierKey, getEventPoint, ariaAttr, getEventStep, getEventKey } from '@zag-js/dom-query';
3
+ import { setValueAtIndex, pick, getValuePercent, isEqual, createSplitProps, snapValueToStep, clampValue, getValueRanges, getNextStepValue, getPreviousStepValue, getPercentValue, getClosestValueIndex, first, last, toPx, getValueTransformer } from '@zag-js/utils';
4
4
  import { createMachine } from '@zag-js/core';
5
- import { trackElementsSize } from '@zag-js/element-size';
6
5
  import { createProps } from '@zag-js/types';
7
6
 
8
7
  // src/slider.anatomy.ts
@@ -30,11 +29,11 @@ var getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text
30
29
  var getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
31
30
  var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
32
31
  var getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
32
+ var getThumbEls = (ctx) => queryAll(getControlEl(ctx), "[role=slider]");
33
+ var getFirstThumbEl = (ctx) => getThumbEls(ctx)[0];
33
34
  var getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
34
35
  var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
35
- var getElements = (ctx) => queryAll(getControlEl(ctx), "[role=slider]");
36
- var getFirstEl = (ctx) => getElements(ctx)[0];
37
- var getValueFromPoint = (params, point) => {
36
+ var getPointValue = (params, point) => {
38
37
  const { prop, scope } = params;
39
38
  const controlEl = getControlEl(scope);
40
39
  if (!controlEl) return;
@@ -53,6 +52,12 @@ var dispatchChangeEvent = (ctx, value) => {
53
52
  dispatchInputValueEvent(inputEl, { value: value2 });
54
53
  });
55
54
  };
55
+ var getOffsetRect = (el) => ({
56
+ left: el?.offsetLeft ?? 0,
57
+ top: el?.offsetTop ?? 0,
58
+ width: el?.offsetWidth ?? 0,
59
+ height: el?.offsetHeight ?? 0
60
+ });
56
61
  function getBounds(value) {
57
62
  const firstValue = value[0];
58
63
  const lastThumb = value[value.length - 1];
@@ -304,7 +309,7 @@ function connect(service, normalize2) {
304
309
  onClick(event) {
305
310
  if (!interactive) return;
306
311
  event.preventDefault();
307
- getFirstEl(scope)?.focus();
312
+ getFirstThumbEl(scope)?.focus();
308
313
  },
309
314
  style: {
310
315
  userSelect: "none",
@@ -609,7 +614,7 @@ var machine = createMachine({
609
614
  action(["syncInputElements", "dispatchChangeEvent"]);
610
615
  });
611
616
  },
612
- effects: ["trackFormControlState", "trackThumbsSize"],
617
+ effects: ["trackFormControlState", "trackThumbSize"],
613
618
  on: {
614
619
  SET_VALUE: [
615
620
  {
@@ -712,13 +717,16 @@ var machine = createMachine({
712
717
  }
713
718
  });
714
719
  },
715
- trackThumbsSize({ context, scope, prop }) {
720
+ trackThumbSize({ context, scope, prop }) {
716
721
  if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
717
- return trackElementsSize({
718
- getNodes: () => getElements(scope),
719
- observeMutation: true,
720
- callback(size) {
721
- if (!size || isEqualSize(context.get("thumbSize"), size)) return;
722
+ return trackElementRect(getThumbEls(scope), {
723
+ box: "border-box",
724
+ measure(el) {
725
+ return getOffsetRect(el);
726
+ },
727
+ onEntry({ rects }) {
728
+ const size = pick(rects[0], ["width", "height"]);
729
+ if (isEqualSize(context.get("thumbSize"), size)) return;
722
730
  context.set("thumbSize", size);
723
731
  }
724
732
  });
@@ -739,7 +747,7 @@ var machine = createMachine({
739
747
  },
740
748
  setClosestThumbIndex(params) {
741
749
  const { context, event } = params;
742
- const pointValue = getValueFromPoint(params, event.point);
750
+ const pointValue = getPointValue(params, event.point);
743
751
  if (pointValue == null) return;
744
752
  const focusedIndex = getClosestIndex(params, pointValue);
745
753
  context.set("focusedIndex", focusedIndex);
@@ -753,7 +761,7 @@ var machine = createMachine({
753
761
  setPointerValue(params) {
754
762
  queueMicrotask(() => {
755
763
  const { context, event } = params;
756
- const pointValue = getValueFromPoint(params, event.point);
764
+ const pointValue = getPointValue(params, event.point);
757
765
  if (pointValue == null) return;
758
766
  const focusedIndex = context.get("focusedIndex");
759
767
  const value = constrainValue(params, pointValue, focusedIndex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,12 +27,11 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "1.8.1",
31
- "@zag-js/core": "1.8.1",
32
- "@zag-js/dom-query": "1.8.1",
33
- "@zag-js/utils": "1.8.1",
34
- "@zag-js/element-size": "1.8.1",
35
- "@zag-js/types": "1.8.1"
30
+ "@zag-js/anatomy": "1.8.2",
31
+ "@zag-js/core": "1.8.2",
32
+ "@zag-js/dom-query": "1.8.2",
33
+ "@zag-js/utils": "1.8.2",
34
+ "@zag-js/types": "1.8.2"
36
35
  },
37
36
  "devDependencies": {
38
37
  "clean-package": "2.2.0"