@tamagui/slider 1.0.1-beta.100
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/cjs/Slider.js +456 -0
- package/dist/cjs/Slider.js.map +7 -0
- package/dist/cjs/SliderImpl.js +163 -0
- package/dist/cjs/SliderImpl.js.map +7 -0
- package/dist/cjs/constants.js +62 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/helpers.js +101 -0
- package/dist/cjs/helpers.js.map +7 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/Slider.js +448 -0
- package/dist/esm/Slider.js.map +7 -0
- package/dist/esm/SliderImpl.js +137 -0
- package/dist/esm/SliderImpl.js.map +7 -0
- package/dist/esm/constants.js +30 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/helpers.js +70 -0
- package/dist/esm/helpers.js.map +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/jsx/Slider.js +324 -0
- package/dist/jsx/Slider.js.map +7 -0
- package/dist/jsx/SliderImpl.js +84 -0
- package/dist/jsx/SliderImpl.js.map +7 -0
- package/dist/jsx/constants.js +30 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/helpers.js +70 -0
- package/dist/jsx/helpers.js.map +7 -0
- package/dist/jsx/index.js +7 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/package.json +46 -0
- package/src/Slider.tsx +592 -0
- package/src/SliderImpl.tsx +118 -0
- package/src/constants.tsx +32 -0
- package/src/helpers.tsx +100 -0
- package/src/index.ts +9 -0
- package/src/types.ts +75 -0
- package/types/Slider.d.ts +357 -0
- package/types/Slider.d.ts.map +1 -0
- package/types/SliderImpl.d.ts +55 -0
- package/types/SliderImpl.d.ts.map +1 -0
- package/types/constants.d.ts +52 -0
- package/types/constants.d.ts.map +1 -0
- package/types/helpers.d.ts +10 -0
- package/types/helpers.d.ts.map +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/types.d.ts +68 -0
- package/types/types.d.ts.map +1 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
+
}
|
|
46
|
+
return to;
|
|
47
|
+
};
|
|
48
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
49
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
|
+
var SliderImpl_exports = {};
|
|
51
|
+
__export(SliderImpl_exports, {
|
|
52
|
+
DirectionalYStack: () => DirectionalYStack,
|
|
53
|
+
SliderFrame: () => SliderFrame,
|
|
54
|
+
SliderImpl: () => SliderImpl
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(SliderImpl_exports);
|
|
57
|
+
var import_core = require("@tamagui/core");
|
|
58
|
+
var import_stacks = require("@tamagui/stacks");
|
|
59
|
+
var React = __toESM(require("react"));
|
|
60
|
+
var import_constants = require("./constants");
|
|
61
|
+
const DirectionalYStack = (0, import_core.styled)(import_stacks.YStack, {
|
|
62
|
+
variants: {
|
|
63
|
+
orientation: {
|
|
64
|
+
horizontal: {},
|
|
65
|
+
vertical: {}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const SliderFrame = (0, import_core.styled)(DirectionalYStack, {
|
|
70
|
+
position: "relative",
|
|
71
|
+
variants: {
|
|
72
|
+
size: (val, extras) => {
|
|
73
|
+
const orientation = extras.props.orientation;
|
|
74
|
+
const size = Math.round((0, import_core.getVariableValue)((0, import_core.getSize)(val)) / 6);
|
|
75
|
+
if (orientation === "horizontal") {
|
|
76
|
+
return {
|
|
77
|
+
height: size,
|
|
78
|
+
borderRadius: size,
|
|
79
|
+
justifyContent: "center"
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
width: size,
|
|
84
|
+
borderRadius: size,
|
|
85
|
+
alignItems: "center"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const SliderImpl = React.forwardRef((props, forwardedRef) => {
|
|
91
|
+
const _a = props, {
|
|
92
|
+
__scopeSlider,
|
|
93
|
+
onSlideStart,
|
|
94
|
+
onSlideMove,
|
|
95
|
+
onSlideEnd,
|
|
96
|
+
onHomeKeyDown,
|
|
97
|
+
onEndKeyDown,
|
|
98
|
+
onStepKeyDown
|
|
99
|
+
} = _a, sliderProps = __objRest(_a, [
|
|
100
|
+
"__scopeSlider",
|
|
101
|
+
"onSlideStart",
|
|
102
|
+
"onSlideMove",
|
|
103
|
+
"onSlideEnd",
|
|
104
|
+
"onHomeKeyDown",
|
|
105
|
+
"onEndKeyDown",
|
|
106
|
+
"onStepKeyDown"
|
|
107
|
+
]);
|
|
108
|
+
const context = (0, import_constants.useSliderContext)(import_constants.SLIDER_NAME, __scopeSlider);
|
|
109
|
+
return /* @__PURE__ */ React.createElement(SliderFrame, __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
110
|
+
size: "$4"
|
|
111
|
+
}, sliderProps), {
|
|
112
|
+
"data-orientation": sliderProps.orientation,
|
|
113
|
+
ref: forwardedRef
|
|
114
|
+
}), import_core.isWeb && {
|
|
115
|
+
onKeyDown: (event) => {
|
|
116
|
+
if (event.key === "Home") {
|
|
117
|
+
onHomeKeyDown(event);
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
} else if (event.key === "End") {
|
|
120
|
+
onEndKeyDown(event);
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
} else if (import_constants.PAGE_KEYS.concat(import_constants.ARROW_KEYS).includes(event.key)) {
|
|
123
|
+
onStepKeyDown(event);
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}), {
|
|
128
|
+
onMoveShouldSetResponderCapture: () => true,
|
|
129
|
+
onScrollShouldSetResponder: () => true,
|
|
130
|
+
onScrollShouldSetResponderCapture: () => true,
|
|
131
|
+
onMoveShouldSetResponder: () => true,
|
|
132
|
+
onStartShouldSetResponder: () => true,
|
|
133
|
+
onResponderTerminationRequest: () => {
|
|
134
|
+
return false;
|
|
135
|
+
},
|
|
136
|
+
onResponderGrant: (0, import_core.composeEventHandlers)(props.onResponderGrant, (event) => {
|
|
137
|
+
const target = event.target;
|
|
138
|
+
console.log("target", target, context.thumbs.has(target), context.thumbs);
|
|
139
|
+
const isStartingOnThumb = context.thumbs.has(target);
|
|
140
|
+
if (import_core.isWeb && target instanceof HTMLElement) {
|
|
141
|
+
if (context.thumbs.has(target)) {
|
|
142
|
+
target.focus();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
onSlideStart(event, isStartingOnThumb ? "thumb" : "track");
|
|
146
|
+
}),
|
|
147
|
+
onResponderMove: (0, import_core.composeEventHandlers)(props.onResponderMove, (event) => {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
onSlideMove(event);
|
|
151
|
+
}),
|
|
152
|
+
onResponderRelease: (0, import_core.composeEventHandlers)(props.onResponderRelease, (event) => {
|
|
153
|
+
onSlideEnd(event);
|
|
154
|
+
})
|
|
155
|
+
}));
|
|
156
|
+
});
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
DirectionalYStack,
|
|
160
|
+
SliderFrame,
|
|
161
|
+
SliderImpl
|
|
162
|
+
});
|
|
163
|
+
//# sourceMappingURL=SliderImpl.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/SliderImpl.tsx"],
|
|
4
|
+
"sourcesContent": ["/* -------------------------------------------------------------------------------------------------\n * SliderImpl\n * -----------------------------------------------------------------------------------------------*/\n\nimport { composeEventHandlers, getSize, getVariableValue, isWeb, styled } from '@tamagui/core'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nimport { ARROW_KEYS, PAGE_KEYS, SLIDER_NAME, useSliderContext } from './constants'\nimport { ScopedProps, SliderImplProps } from './types'\n\nexport const DirectionalYStack = styled(YStack, {\n variants: {\n orientation: {\n horizontal: {},\n vertical: {},\n },\n },\n})\n\nexport const SliderFrame = styled(DirectionalYStack, {\n position: 'relative',\n\n variants: {\n size: (val, extras) => {\n const orientation = extras.props.orientation\n const size = Math.round(getVariableValue(getSize(val)) / 6)\n if (orientation === 'horizontal') {\n return {\n height: size,\n borderRadius: size,\n justifyContent: 'center',\n }\n }\n return {\n width: size,\n borderRadius: size,\n alignItems: 'center',\n }\n },\n },\n})\n\nexport const SliderImpl = React.forwardRef<View, SliderImplProps>(\n (props: ScopedProps<SliderImplProps>, forwardedRef) => {\n const {\n __scopeSlider,\n onSlideStart,\n onSlideMove,\n onSlideEnd,\n onHomeKeyDown,\n onEndKeyDown,\n onStepKeyDown,\n ...sliderProps\n } = props\n const context = useSliderContext(SLIDER_NAME, __scopeSlider)\n return (\n <SliderFrame\n size=\"$4\"\n {...sliderProps}\n data-orientation={sliderProps.orientation}\n ref={forwardedRef}\n {...(isWeb && {\n onKeyDown: (event) => {\n if (event.key === 'Home') {\n onHomeKeyDown(event)\n // Prevent scrolling to page start\n event.preventDefault()\n } else if (event.key === 'End') {\n onEndKeyDown(event)\n // Prevent scrolling to page end\n event.preventDefault()\n } else if (PAGE_KEYS.concat(ARROW_KEYS).includes(event.key)) {\n onStepKeyDown(event)\n // Prevent scrolling for directional key presses\n event.preventDefault()\n }\n },\n })}\n onMoveShouldSetResponderCapture={() => true}\n onScrollShouldSetResponder={() => true}\n onScrollShouldSetResponderCapture={() => true}\n onMoveShouldSetResponder={() => true}\n onStartShouldSetResponder={() => true}\n // onStartShouldSetResponderCapture={() => true}\n onResponderTerminationRequest={() => {\n return false\n }}\n onResponderGrant={composeEventHandlers(props.onResponderGrant, (event) => {\n const target = event.target as HTMLElement | number\n console.log('target', target, context.thumbs.has(target), context.thumbs)\n const isStartingOnThumb = context.thumbs.has(target)\n // // Prevent browser focus behaviour because we focus a thumb manually when values change.\n // Touch devices have a delay before focusing so won't focus if touch immediately moves\n // away from target (sliding). We want thumb to focus regardless.\n if (isWeb && target instanceof HTMLElement) {\n if (context.thumbs.has(target)) {\n target.focus()\n }\n }\n onSlideStart(event, isStartingOnThumb ? 'thumb' : 'track')\n })}\n onResponderMove={composeEventHandlers(props.onResponderMove, (event) => {\n event.preventDefault()\n event.stopPropagation()\n\n // const target = event.target as HTMLElement\n onSlideMove(event)\n })}\n onResponderRelease={composeEventHandlers(props.onResponderRelease, (event) => {\n // const target = event.target as HTMLElement\n onSlideEnd(event)\n })}\n />\n )\n }\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAA+E;AAC/E,oBAAuB;AACvB,YAAuB;AAGvB,uBAAqE;AAG9D,MAAM,oBAAoB,wBAAO,sBAAQ;AAAA,EAC9C,UAAU;AAAA,IACR,aAAa;AAAA,MACX,YAAY,C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iCAAiC,MAAM;AAAA,IACvC,4BAA4B,MAAM;AAAA,IAClC,mCAAmC,MAAM;AAAA,IACzC,0BAA0B,MAAM;AAAA,IAChC,2BAA2B,MAAM;AAAA,IAEjC,+BAA+B,MAAM;AACnC,aAAO;AAAA,IACT;AAAA,IACA,kBAAkB,sCAAqB,MAAM,kBAAkB,CAAC,UAAU;AACxE,YAAM,SAAS,MAAM;AACrB,cAAQ,IAAI,UAAU,QAAQ,QAAQ,OAAO,IAAI,MAAM,GAAG,QAAQ,MAAM;AACxE,YAAM,oBAAoB,QAAQ,OAAO,IAAI,MAAM;AAInD,UAAI,qBAAS,kBAAkB,aAAa;AAC1C,YAAI,QAAQ,OAAO,IAAI,MAAM,GAAG;AAC9B,iBAAO,MAAM;AAAA,QACf;AAAA,MACF;AACA,mBAAa,OAAO,oBAAoB,UAAU,OAAO;AAAA,IAC3D,CAAC;AAAA,IACD,iBAAiB,sCAAqB,MAAM,iBAAiB,CAAC,UAAU;AACtE,YAAM,eAAe;AACrB,YAAM,gBAAgB;AAGtB,kBAAY,KAAK;AAAA,IACnB,CAAC;AAAA,IACD,oBAAoB,sCAAqB,MAAM,oBAAoB,CAAC,UAAU;AAE5E,iBAAW,KAAK;AAAA,IAClB,CAAC;AAAA,IACH;AAEJ,CACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
ARROW_KEYS: () => ARROW_KEYS,
|
|
21
|
+
BACK_KEYS: () => BACK_KEYS,
|
|
22
|
+
PAGE_KEYS: () => PAGE_KEYS,
|
|
23
|
+
SLIDER_NAME: () => SLIDER_NAME,
|
|
24
|
+
SliderOrientationProvider: () => SliderOrientationProvider,
|
|
25
|
+
SliderProvider: () => SliderProvider,
|
|
26
|
+
createSliderContext: () => createSliderContext,
|
|
27
|
+
createSliderScope: () => createSliderScope,
|
|
28
|
+
useSliderContext: () => useSliderContext,
|
|
29
|
+
useSliderOrientationContext: () => useSliderOrientationContext
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(constants_exports);
|
|
32
|
+
var import_create_context = require("@tamagui/create-context");
|
|
33
|
+
const SLIDER_NAME = "Slider";
|
|
34
|
+
const [createSliderContext, createSliderScope] = (0, import_create_context.createContextScope)(SLIDER_NAME);
|
|
35
|
+
const [SliderProvider, useSliderContext] = createSliderContext(SLIDER_NAME);
|
|
36
|
+
const [SliderOrientationProvider, useSliderOrientationContext] = createSliderContext(SLIDER_NAME, {
|
|
37
|
+
startEdge: "left",
|
|
38
|
+
endEdge: "right",
|
|
39
|
+
sizeProp: "width",
|
|
40
|
+
size: 0,
|
|
41
|
+
direction: 1
|
|
42
|
+
});
|
|
43
|
+
const PAGE_KEYS = ["PageUp", "PageDown"];
|
|
44
|
+
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
45
|
+
const BACK_KEYS = {
|
|
46
|
+
ltr: ["ArrowDown", "Home", "ArrowLeft", "PageDown"],
|
|
47
|
+
rtl: ["ArrowDown", "Home", "ArrowRight", "PageDown"]
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
ARROW_KEYS,
|
|
52
|
+
BACK_KEYS,
|
|
53
|
+
PAGE_KEYS,
|
|
54
|
+
SLIDER_NAME,
|
|
55
|
+
SliderOrientationProvider,
|
|
56
|
+
SliderProvider,
|
|
57
|
+
createSliderContext,
|
|
58
|
+
createSliderScope,
|
|
59
|
+
useSliderContext,
|
|
60
|
+
useSliderOrientationContext
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/constants.tsx"],
|
|
4
|
+
"sourcesContent": ["import { SizeTokens } from '@tamagui/core'\nimport { createContextScope } from '@tamagui/create-context'\n\nimport { Direction, SliderContextValue } from './types'\n\nexport const SLIDER_NAME = 'Slider'\n\nexport const [createSliderContext, createSliderScope] = createContextScope(SLIDER_NAME)\n\nexport const [SliderProvider, useSliderContext] =\n createSliderContext<SliderContextValue>(SLIDER_NAME)\n\nexport const [SliderOrientationProvider, useSliderOrientationContext] = createSliderContext<{\n startEdge: 'bottom' | 'left' | 'right'\n endEdge: 'top' | 'right' | 'left'\n sizeProp: 'width' | 'height'\n size: number | SizeTokens\n direction: number\n}>(SLIDER_NAME, {\n startEdge: 'left',\n endEdge: 'right',\n sizeProp: 'width',\n size: 0,\n direction: 1,\n})\n\nexport const PAGE_KEYS = ['PageUp', 'PageDown']\nexport const ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']\nexport const BACK_KEYS: Record<Direction, string[]> = {\n ltr: ['ArrowDown', 'Home', 'ArrowLeft', 'PageDown'],\n rtl: ['ArrowDown', 'Home', 'ArrowRight', 'PageDown'],\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAAmC;AAI5B,MAAM,cAAc;AAEpB,MAAM,CAAC,qBAAqB,qBAAqB,8CAAmB,WAAW;AAE/E,MAAM,CAAC,gBAAgB,oBAC5B,oBAAwC,WAAW;AAE9C,MAAM,CAAC,2BAA2B,+BAA+B,oBAMrE,aAAa;AAAA,EACd,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,WAAW;AACb,CAAC;AAEM,MAAM,YAAY,CAAC,UAAU,UAAU;AACvC,MAAM,aAAa,CAAC,WAAW,aAAa,aAAa,YAAY;AACrE,MAAM,YAAyC;AAAA,EACpD,KAAK,CAAC,aAAa,QAAQ,aAAa,UAAU;AAAA,EAClD,KAAK,CAAC,aAAa,QAAQ,cAAc,UAAU;AACrD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var helpers_exports = {};
|
|
19
|
+
__export(helpers_exports, {
|
|
20
|
+
convertValueToPercentage: () => convertValueToPercentage,
|
|
21
|
+
getClosestValueIndex: () => getClosestValueIndex,
|
|
22
|
+
getDecimalCount: () => getDecimalCount,
|
|
23
|
+
getLabel: () => getLabel,
|
|
24
|
+
getNextSortedValues: () => getNextSortedValues,
|
|
25
|
+
getThumbInBoundsOffset: () => getThumbInBoundsOffset,
|
|
26
|
+
hasMinStepsBetweenValues: () => hasMinStepsBetweenValues,
|
|
27
|
+
linearScale: () => linearScale,
|
|
28
|
+
roundValue: () => roundValue
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
31
|
+
function getNextSortedValues(prevValues = [], nextValue, atIndex) {
|
|
32
|
+
const nextValues = [...prevValues];
|
|
33
|
+
nextValues[atIndex] = nextValue;
|
|
34
|
+
return nextValues.sort((a, b) => a - b);
|
|
35
|
+
}
|
|
36
|
+
function convertValueToPercentage(value, min, max) {
|
|
37
|
+
const maxSteps = max - min;
|
|
38
|
+
const percentPerStep = 100 / maxSteps;
|
|
39
|
+
return percentPerStep * (value - min);
|
|
40
|
+
}
|
|
41
|
+
function getLabel(index, totalValues) {
|
|
42
|
+
if (totalValues > 2) {
|
|
43
|
+
return `Value ${index + 1} of ${totalValues}`;
|
|
44
|
+
} else if (totalValues === 2) {
|
|
45
|
+
return ["Minimum", "Maximum"][index];
|
|
46
|
+
} else {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function getClosestValueIndex(values, nextValue) {
|
|
51
|
+
if (values.length === 1)
|
|
52
|
+
return 0;
|
|
53
|
+
const distances = values.map((value) => Math.abs(value - nextValue));
|
|
54
|
+
const closestDistance = Math.min(...distances);
|
|
55
|
+
return distances.indexOf(closestDistance);
|
|
56
|
+
}
|
|
57
|
+
function getThumbInBoundsOffset(width, left, direction) {
|
|
58
|
+
const halfWidth = width / 2;
|
|
59
|
+
const halfPercent = 50;
|
|
60
|
+
const offset = linearScale([0, halfPercent], [0, halfWidth]);
|
|
61
|
+
return (halfWidth - offset(left) * direction) * direction;
|
|
62
|
+
}
|
|
63
|
+
function getStepsBetweenValues(values) {
|
|
64
|
+
return values.slice(0, -1).map((value, index) => values[index + 1] - value);
|
|
65
|
+
}
|
|
66
|
+
function hasMinStepsBetweenValues(values, minStepsBetweenValues) {
|
|
67
|
+
if (minStepsBetweenValues > 0) {
|
|
68
|
+
const stepsBetweenValues = getStepsBetweenValues(values);
|
|
69
|
+
const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues);
|
|
70
|
+
return actualMinStepsBetweenValues >= minStepsBetweenValues;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function linearScale(input, output) {
|
|
75
|
+
return (value) => {
|
|
76
|
+
if (input[0] === input[1] || output[0] === output[1])
|
|
77
|
+
return output[0];
|
|
78
|
+
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
79
|
+
return output[0] + ratio * (value - input[0]);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function getDecimalCount(value) {
|
|
83
|
+
return (String(value).split(".")[1] || "").length;
|
|
84
|
+
}
|
|
85
|
+
function roundValue(value, decimalCount) {
|
|
86
|
+
const rounder = Math.pow(10, decimalCount);
|
|
87
|
+
return Math.round(value * rounder) / rounder;
|
|
88
|
+
}
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
convertValueToPercentage,
|
|
92
|
+
getClosestValueIndex,
|
|
93
|
+
getDecimalCount,
|
|
94
|
+
getLabel,
|
|
95
|
+
getNextSortedValues,
|
|
96
|
+
getThumbInBoundsOffset,
|
|
97
|
+
hasMinStepsBetweenValues,
|
|
98
|
+
linearScale,
|
|
99
|
+
roundValue
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers.tsx"],
|
|
4
|
+
"sourcesContent": ["export function getNextSortedValues(prevValues: number[] = [], nextValue: number, atIndex: number) {\n const nextValues = [...prevValues]\n nextValues[atIndex] = nextValue\n return nextValues.sort((a, b) => a - b)\n}\n\nexport function convertValueToPercentage(value: number, min: number, max: number) {\n const maxSteps = max - min\n const percentPerStep = 100 / maxSteps\n return percentPerStep * (value - min)\n}\n\n/**\n * Returns a label for each thumb when there are two or more thumbs\n */\nexport function getLabel(index: number, totalValues: number) {\n if (totalValues > 2) {\n return `Value ${index + 1} of ${totalValues}`\n } else if (totalValues === 2) {\n return ['Minimum', 'Maximum'][index]\n } else {\n return undefined\n }\n}\n\n/**\n * Given a `values` array and a `nextValue`, determine which value in\n * the array is closest to `nextValue` and return its index.\n *\n * @example\n * // returns 1\n * getClosestValueIndex([10, 30], 25);\n */\nexport function getClosestValueIndex(values: number[], nextValue: number) {\n if (values.length === 1) return 0\n const distances = values.map((value) => Math.abs(value - nextValue))\n const closestDistance = Math.min(...distances)\n return distances.indexOf(closestDistance)\n}\n\n/**\n * Offsets the thumb centre point while sliding to ensure it remains\n * within the bounds of the slider when reaching the edges\n */\nexport function getThumbInBoundsOffset(width: number, left: number, direction: number) {\n const halfWidth = width / 2\n const halfPercent = 50\n const offset = linearScale([0, halfPercent], [0, halfWidth])\n return (halfWidth - offset(left) * direction) * direction\n}\n\n/**\n * Gets an array of steps between each value.\n *\n * @example\n * // returns [1, 9]\n * getStepsBetweenValues([10, 11, 20]);\n */\nfunction getStepsBetweenValues(values: number[]) {\n return values.slice(0, -1).map((value, index) => values[index + 1] - value)\n}\n\n/**\n * Verifies the minimum steps between all values is greater than or equal\n * to the expected minimum steps.\n *\n * @example\n * // returns false\n * hasMinStepsBetweenValues([1,2,3], 2);\n *\n * @example\n * // returns true\n * hasMinStepsBetweenValues([1,2,3], 1);\n */\nexport function hasMinStepsBetweenValues(values: number[], minStepsBetweenValues: number) {\n if (minStepsBetweenValues > 0) {\n const stepsBetweenValues = getStepsBetweenValues(values)\n const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues)\n return actualMinStepsBetweenValues >= minStepsBetweenValues\n }\n return true\n}\n\n// https://github.com/tmcw-up-for-adoption/simple-linear-scale/blob/master/index.js\nexport function linearScale(input: readonly [number, number], output: readonly [number, number]) {\n return (value: number) => {\n if (input[0] === input[1] || output[0] === output[1]) return output[0]\n const ratio = (output[1] - output[0]) / (input[1] - input[0])\n return output[0] + ratio * (value - input[0])\n }\n}\n\nexport function getDecimalCount(value: number) {\n return (String(value).split('.')[1] || '').length\n}\n\nexport function roundValue(value: number, decimalCount: number) {\n const rounder = Math.pow(10, decimalCount)\n return Math.round(value * rounder) / rounder\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,6BAA6B,aAAuB,CAAC,GAAG,WAAmB,SAAiB;AACjG,QAAM,aAAa,CAAC,GAAG,UAAU;AACjC,aAAW,WAAW;AACtB,SAAO,WAAW,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AACxC;AAEO,kCAAkC,OAAe,KAAa,KAAa;AAChF,QAAM,WAAW,MAAM;AACvB,QAAM,iBAAiB,MAAM;AAC7B,SAAO,iBAAkB,SAAQ;AACnC;AAKO,kBAAkB,OAAe,aAAqB;AAC3D,MAAI,cAAc,GAAG;AACnB,WAAO,SAAS,QAAQ,QAAQ;AAAA,EAClC,WAAW,gBAAgB,GAAG;AAC5B,WAAO,CAAC,WAAW,SAAS,EAAE;AAAA,EAChC,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAUO,8BAA8B,QAAkB,WAAmB;AACxE,MAAI,OAAO,WAAW;AAAG,WAAO;AAChC,QAAM,YAAY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.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
DirectionalYStack: () => import_SliderImpl.DirectionalYStack,
|
|
22
|
+
SliderFrame: () => import_SliderImpl.SliderFrame
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
__reExport(src_exports, require("./Slider"), module.exports);
|
|
26
|
+
var import_SliderImpl = require("./SliderImpl");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
DirectionalYStack,
|
|
30
|
+
SliderFrame
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './Slider'\n// for static extract to find, must export\nexport { SliderFrame, DirectionalYStack } from './SliderImpl'\nexport type {\n SliderProps,\n SliderHorizontalProps,\n SliderVerticalProps,\n SliderTrackProps,\n} from './types'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,qBAAd;AAEA,wBAA+C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["import type { GestureReponderEvent, SizeTokens } from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport type { SizableStackProps } from '@tamagui/stacks'\n\nexport type ScopedProps<P> = P & { __scopeSlider?: Scope }\n\nexport type Direction = 'ltr' | 'rtl'\n\ntype SliderImplPrivateProps = {\n onSlideStart(event: GestureReponderEvent, target: 'thumb' | 'track'): void\n onSlideMove(event: GestureReponderEvent): void\n onSlideEnd(event: GestureReponderEvent): void\n onHomeKeyDown(event: React.KeyboardEvent): void\n onEndKeyDown(event: React.KeyboardEvent): void\n onStepKeyDown(event: React.KeyboardEvent): void\n}\n\nexport interface SliderTrackProps extends SizableStackProps {}\n\nexport interface SliderImplProps extends SliderTrackProps, SliderImplPrivateProps {\n dir?: Direction\n orientation: 'horizontal' | 'vertical'\n}\n\ntype SliderOrientationPrivateProps = {\n min: number\n max: number\n onSlideStart?(value: number, target: 'thumb' | 'track'): void\n onSlideMove?(value: number): void\n onHomeKeyDown(event: React.KeyboardEvent): void\n onEndKeyDown(event: React.KeyboardEvent): void\n onStepKeyDown(step: { event: React.KeyboardEvent; direction: number }): void\n}\n\ninterface SliderOrientationProps\n extends Omit<SliderImplProps, keyof SliderImplPrivateProps | 'orientation'>,\n SliderOrientationPrivateProps {}\n\nexport interface SliderHorizontalProps extends SliderOrientationProps {\n dir?: Direction\n}\n\nexport interface SliderVerticalProps extends SliderOrientationProps {\n dir?: Direction\n}\n\nexport interface SliderProps\n extends Omit<\n SliderHorizontalProps | SliderVerticalProps,\n keyof SliderOrientationPrivateProps | 'defaultValue'\n > {\n size?: SizeTokens\n name?: string\n disabled?: boolean\n orientation?: React.AriaAttributes['aria-orientation']\n dir?: Direction\n min?: number\n max?: number\n step?: number\n minStepsBetweenThumbs?: number\n value?: number[]\n defaultValue?: number[]\n onValueChange?(value: number[]): void\n}\n\nexport type SliderContextValue = {\n size?: SizeTokens | number | null\n disabled?: boolean\n min: number\n max: number\n values: number[]\n valueIndexToChangeRef: React.MutableRefObject<number>\n thumbs: Set<any>\n orientation: SliderProps['orientation']\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|