@zag-js/slider 0.0.0-dev-20220706194607 → 0.0.0-dev-20220709094240

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
@@ -44,7 +44,23 @@ __export(src_exports, {
44
44
  module.exports = __toCommonJS(src_exports);
45
45
 
46
46
  // ../../utilities/dom/dist/index.mjs
47
+ var __defProp2 = Object.defineProperty;
48
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
49
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
50
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
47
51
  var __pow = Math.pow;
52
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
53
+ var __spreadValues2 = (a, b) => {
54
+ for (var prop in b || (b = {}))
55
+ if (__hasOwnProp2.call(b, prop))
56
+ __defNormalProp2(a, prop, b[prop]);
57
+ if (__getOwnPropSymbols2)
58
+ for (var prop of __getOwnPropSymbols2(b)) {
59
+ if (__propIsEnum2.call(b, prop))
60
+ __defNormalProp2(a, prop, b[prop]);
61
+ }
62
+ return a;
63
+ };
48
64
  var dataAttr = (guard) => {
49
65
  return guard ? "" : void 0;
50
66
  };
@@ -71,10 +87,38 @@ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
71
87
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
72
88
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
73
89
  var isIos = () => isApple() && !isMac();
90
+ function isDocument(el) {
91
+ return el.nodeType === Node.DOCUMENT_NODE;
92
+ }
93
+ function isWindow(value) {
94
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
95
+ }
96
+ function getDocument(el) {
97
+ var _a;
98
+ if (isWindow(el))
99
+ return el.document;
100
+ if (isDocument(el))
101
+ return el;
102
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
103
+ }
74
104
  function getWindow(el) {
75
105
  var _a;
76
106
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
77
107
  }
108
+ function withRootHelpers(domUtils) {
109
+ const roots = {
110
+ getRootNode: (ctx) => {
111
+ var _a, _b;
112
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
113
+ },
114
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
115
+ getWin: (ctx) => {
116
+ var _a;
117
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
118
+ }
119
+ };
120
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
121
+ }
78
122
  function getNativeEvent(e) {
79
123
  var _a;
80
124
  return (_a = e.nativeEvent) != null ? _a : e;
@@ -554,45 +598,37 @@ var utils = {
554
598
  };
555
599
 
556
600
  // src/slider.dom.ts
557
- var dom = __spreadProps(__spreadValues({}, styles), {
558
- getDoc: (ctx) => {
559
- var _a;
560
- return (_a = ctx.doc) != null ? _a : document;
561
- },
562
- getRootNode: (ctx) => {
563
- var _a;
564
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
565
- },
601
+ var dom = withRootHelpers(__spreadProps(__spreadValues({}, styles), {
566
602
  getRootId: (ctx) => {
567
603
  var _a, _b;
568
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
604
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
569
605
  },
570
606
  getThumbId: (ctx) => {
571
607
  var _a, _b;
572
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.uid}:thumb`;
608
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
573
609
  },
574
610
  getControlId: (ctx) => {
575
611
  var _a, _b;
576
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.uid}:control`;
612
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
577
613
  },
578
- getInputId: (ctx) => `slider:${ctx.uid}:input`,
614
+ getInputId: (ctx) => `slider:${ctx.id}:input`,
579
615
  getOutputId: (ctx) => {
580
616
  var _a, _b;
581
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.uid}:output`;
617
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
582
618
  },
583
619
  getTrackId: (ctx) => {
584
620
  var _a, _b;
585
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
621
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
586
622
  },
587
623
  getRangeId: (ctx) => {
588
624
  var _a, _b;
589
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}:range`;
625
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
590
626
  },
591
627
  getLabelId: (ctx) => {
592
628
  var _a, _b;
593
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
629
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
594
630
  },
595
- getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
631
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
596
632
  getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
597
633
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
598
634
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
@@ -618,7 +654,7 @@ var dom = __spreadProps(__spreadValues({}, styles), {
618
654
  return;
619
655
  dispatchInputValueEvent(input, ctx.value);
620
656
  }
621
- });
657
+ }));
622
658
 
623
659
  // src/slider.connect.ts
624
660
  function connect(state2, send, normalize) {
@@ -834,14 +870,13 @@ function connect(state2, send, normalize) {
834
870
 
835
871
  // src/slider.machine.ts
836
872
  var import_core = require("@zag-js/core");
837
- function machine(ctx = {}) {
873
+ function machine(ctx) {
838
874
  return (0, import_core.createMachine)({
839
875
  id: "slider",
840
876
  initial: "unknown",
841
877
  context: __spreadValues({
842
878
  thumbSize: null,
843
879
  thumbAlignment: "contain",
844
- uid: "",
845
880
  disabled: false,
846
881
  threshold: 5,
847
882
  dir: "ltr",
@@ -880,7 +915,7 @@ function machine(ctx = {}) {
880
915
  on: {
881
916
  SETUP: {
882
917
  target: "idle",
883
- actions: ["setupDocument", "setThumbSize", "checkValue"]
918
+ actions: ["setThumbSize", "checkValue"]
884
919
  }
885
920
  }
886
921
  },
@@ -986,13 +1021,6 @@ function machine(ctx = {}) {
986
1021
  }
987
1022
  },
988
1023
  actions: {
989
- setupDocument(ctx2, evt) {
990
- if (evt.doc)
991
- ctx2.doc = (0, import_core.ref)(evt.doc);
992
- if (evt.root)
993
- ctx2.rootNode = (0, import_core.ref)(evt.root);
994
- ctx2.uid = evt.id;
995
- },
996
1024
  checkValue(ctx2) {
997
1025
  const value = utils.convert(ctx2, ctx2.value);
998
1026
  Object.assign(ctx2, { value, initialValue: value });
package/dist/index.mjs CHANGED
@@ -19,7 +19,23 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
21
  // ../../utilities/dom/dist/index.mjs
22
+ var __defProp2 = Object.defineProperty;
23
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
24
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
25
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
22
26
  var __pow = Math.pow;
27
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
28
+ var __spreadValues2 = (a, b) => {
29
+ for (var prop in b || (b = {}))
30
+ if (__hasOwnProp2.call(b, prop))
31
+ __defNormalProp2(a, prop, b[prop]);
32
+ if (__getOwnPropSymbols2)
33
+ for (var prop of __getOwnPropSymbols2(b)) {
34
+ if (__propIsEnum2.call(b, prop))
35
+ __defNormalProp2(a, prop, b[prop]);
36
+ }
37
+ return a;
38
+ };
23
39
  var dataAttr = (guard) => {
24
40
  return guard ? "" : void 0;
25
41
  };
@@ -46,10 +62,38 @@ var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
46
62
  var isMac = () => pt(/^Mac/) && !isTouchDevice;
47
63
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
48
64
  var isIos = () => isApple() && !isMac();
65
+ function isDocument(el) {
66
+ return el.nodeType === Node.DOCUMENT_NODE;
67
+ }
68
+ function isWindow(value) {
69
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
70
+ }
71
+ function getDocument(el) {
72
+ var _a;
73
+ if (isWindow(el))
74
+ return el.document;
75
+ if (isDocument(el))
76
+ return el;
77
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
78
+ }
49
79
  function getWindow(el) {
50
80
  var _a;
51
81
  return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
52
82
  }
83
+ function withRootHelpers(domUtils) {
84
+ const roots = {
85
+ getRootNode: (ctx) => {
86
+ var _a, _b;
87
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
88
+ },
89
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
90
+ getWin: (ctx) => {
91
+ var _a;
92
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
93
+ }
94
+ };
95
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
96
+ }
53
97
  function getNativeEvent(e) {
54
98
  var _a;
55
99
  return (_a = e.nativeEvent) != null ? _a : e;
@@ -529,45 +573,37 @@ var utils = {
529
573
  };
530
574
 
531
575
  // src/slider.dom.ts
532
- var dom = __spreadProps(__spreadValues({}, styles), {
533
- getDoc: (ctx) => {
534
- var _a;
535
- return (_a = ctx.doc) != null ? _a : document;
536
- },
537
- getRootNode: (ctx) => {
538
- var _a;
539
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
540
- },
576
+ var dom = withRootHelpers(__spreadProps(__spreadValues({}, styles), {
541
577
  getRootId: (ctx) => {
542
578
  var _a, _b;
543
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.uid}`;
579
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `slider:${ctx.id}`;
544
580
  },
545
581
  getThumbId: (ctx) => {
546
582
  var _a, _b;
547
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.uid}:thumb`;
583
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.thumb) != null ? _b : `slider:${ctx.id}:thumb`;
548
584
  },
549
585
  getControlId: (ctx) => {
550
586
  var _a, _b;
551
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.uid}:control`;
587
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.control) != null ? _b : `slider:${ctx.id}:control`;
552
588
  },
553
- getInputId: (ctx) => `slider:${ctx.uid}:input`,
589
+ getInputId: (ctx) => `slider:${ctx.id}:input`,
554
590
  getOutputId: (ctx) => {
555
591
  var _a, _b;
556
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.uid}:output`;
592
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.output) != null ? _b : `slider:${ctx.id}:output`;
557
593
  },
558
594
  getTrackId: (ctx) => {
559
595
  var _a, _b;
560
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
596
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}track`;
561
597
  },
562
598
  getRangeId: (ctx) => {
563
599
  var _a, _b;
564
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}:range`;
600
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.id}:range`;
565
601
  },
566
602
  getLabelId: (ctx) => {
567
603
  var _a, _b;
568
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.uid}:label`;
604
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `slider:${ctx.id}:label`;
569
605
  },
570
- getMarkerId: (ctx, value) => `slider:${ctx.uid}:marker:${value}`,
606
+ getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
571
607
  getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
572
608
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
573
609
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
@@ -593,7 +629,7 @@ var dom = __spreadProps(__spreadValues({}, styles), {
593
629
  return;
594
630
  dispatchInputValueEvent(input, ctx.value);
595
631
  }
596
- });
632
+ }));
597
633
 
598
634
  // src/slider.connect.ts
599
635
  function connect(state2, send, normalize) {
@@ -808,15 +844,14 @@ function connect(state2, send, normalize) {
808
844
  }
809
845
 
810
846
  // src/slider.machine.ts
811
- import { createMachine, ref } from "@zag-js/core";
812
- function machine(ctx = {}) {
847
+ import { createMachine } from "@zag-js/core";
848
+ function machine(ctx) {
813
849
  return createMachine({
814
850
  id: "slider",
815
851
  initial: "unknown",
816
852
  context: __spreadValues({
817
853
  thumbSize: null,
818
854
  thumbAlignment: "contain",
819
- uid: "",
820
855
  disabled: false,
821
856
  threshold: 5,
822
857
  dir: "ltr",
@@ -855,7 +890,7 @@ function machine(ctx = {}) {
855
890
  on: {
856
891
  SETUP: {
857
892
  target: "idle",
858
- actions: ["setupDocument", "setThumbSize", "checkValue"]
893
+ actions: ["setThumbSize", "checkValue"]
859
894
  }
860
895
  }
861
896
  },
@@ -961,13 +996,6 @@ function machine(ctx = {}) {
961
996
  }
962
997
  },
963
998
  actions: {
964
- setupDocument(ctx2, evt) {
965
- if (evt.doc)
966
- ctx2.doc = ref(evt.doc);
967
- if (evt.root)
968
- ctx2.rootNode = ref(evt.root);
969
- ctx2.uid = evt.id;
970
- },
971
999
  checkValue(ctx2) {
972
1000
  const value = utils.convert(ctx2, ctx2.value);
973
1001
  Object.assign(ctx2, { value, initialValue: value });
@@ -1,7 +1,15 @@
1
1
  import type { MachineContext as Ctx, Point } from "./slider.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
3
+ getRootNode: (ctx: {
4
+ getRootNode?: () => Node | Document | ShadowRoot;
5
+ }) => Document | ShadowRoot;
6
+ getDoc: (ctx: {
7
+ getRootNode?: () => Node | Document | ShadowRoot;
8
+ }) => Document;
9
+ getWin: (ctx: {
10
+ getRootNode?: () => Node | Document | ShadowRoot;
11
+ }) => Window & typeof globalThis;
12
+ } & {
5
13
  getRootId: (ctx: Ctx) => string;
6
14
  getThumbId: (ctx: Ctx) => string;
7
15
  getControlId: (ctx: Ctx) => string;
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./slider.types";
2
- export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
2
+ export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,5 +1,5 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
- import type { Context, DirectionProperty } from "@zag-js/types";
2
+ import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
3
3
  declare type ElementIds = Partial<{
4
4
  root: string;
5
5
  thumb: string;
@@ -9,7 +9,7 @@ declare type ElementIds = Partial<{
9
9
  label: string;
10
10
  output: string;
11
11
  }>;
12
- declare type PublicContext = DirectionProperty & {
12
+ declare type PublicContext = DirectionProperty & CommonProperties & {
13
13
  /**
14
14
  * The ids of the elements in the slider. Useful for composition.
15
15
  */
@@ -96,7 +96,7 @@ declare type PublicContext = DirectionProperty & {
96
96
  */
97
97
  thumbAlignment?: "contain" | "center";
98
98
  };
99
- export declare type UserDefinedContext = Partial<PublicContext>;
99
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
100
100
  declare type ComputedContext = Readonly<{
101
101
  /**
102
102
  * @computed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.0.0-dev-20220706194607",
3
+ "version": "0.0.0-dev-20220709094240",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,10 +29,10 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.0.0-dev-20220706194607",
33
- "@zag-js/dom-utils": "0.0.0-dev-20220706194607",
32
+ "@zag-js/core": "0.1.7",
33
+ "@zag-js/dom-utils": "0.0.0-dev-20220709094240",
34
34
  "@zag-js/number-utils": "0.1.2",
35
- "@zag-js/types": "0.0.0-dev-20220706194607",
35
+ "@zag-js/types": "0.0.0-dev-20220709094240",
36
36
  "@zag-js/utils": "0.1.2"
37
37
  },
38
38
  "scripts": {