@v-c/rate 0.0.1
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/LICENSE +21 -0
- package/dist/Rate.cjs +277 -0
- package/dist/Rate.d.ts +23 -0
- package/dist/Rate.js +272 -0
- package/dist/Star.cjs +125 -0
- package/dist/Star.d.ts +16 -0
- package/dist/Star.js +122 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/useRefs.cjs +16 -0
- package/dist/useRefs.d.ts +6 -0
- package/dist/useRefs.js +14 -0
- package/dist/util.cjs +34 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +34 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 antdv-community
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/Rate.cjs
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_Star = require("./Star.cjs");
|
|
4
|
+
const require_useRefs = require("./useRefs.cjs");
|
|
5
|
+
const require_util = require("./util.cjs");
|
|
6
|
+
let vue = require("vue");
|
|
7
|
+
let __v_c_util = require("@v-c/util");
|
|
8
|
+
let __v_c_util_dist_hooks_useMergedState = require("@v-c/util/dist/hooks/useMergedState");
|
|
9
|
+
__v_c_util_dist_hooks_useMergedState = require_rolldown_runtime.__toESM(__v_c_util_dist_hooks_useMergedState);
|
|
10
|
+
let __v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
|
|
11
|
+
__v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(__v_c_util_dist_KeyCode);
|
|
12
|
+
let __v_c_util_dist_pickAttrs = require("@v-c/util/dist/pickAttrs");
|
|
13
|
+
__v_c_util_dist_pickAttrs = require_rolldown_runtime.__toESM(__v_c_util_dist_pickAttrs);
|
|
14
|
+
let __v_c_util_dist_props_util = require("@v-c/util/dist/props-util");
|
|
15
|
+
var defaults = {
|
|
16
|
+
prefixCls: "vc-rate",
|
|
17
|
+
count: 5,
|
|
18
|
+
allowHalf: false,
|
|
19
|
+
allowClear: true,
|
|
20
|
+
keyboard: true,
|
|
21
|
+
character: "★",
|
|
22
|
+
direction: "ltr",
|
|
23
|
+
tabIndex: 0
|
|
24
|
+
};
|
|
25
|
+
var Rate_default = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, expose }) => {
|
|
26
|
+
const [setStarRef, starRefs] = require_useRefs.default();
|
|
27
|
+
const rateRef = (0, vue.ref)(null);
|
|
28
|
+
const triggerFocus = () => {
|
|
29
|
+
if (!props.disabled) rateRef.value.focus();
|
|
30
|
+
};
|
|
31
|
+
const triggerBlur = () => {
|
|
32
|
+
if (!props.disabled) rateRef.value.blur();
|
|
33
|
+
};
|
|
34
|
+
expose({
|
|
35
|
+
focus: triggerFocus,
|
|
36
|
+
blur: triggerBlur
|
|
37
|
+
});
|
|
38
|
+
const [state, setStateValue] = (0, __v_c_util_dist_hooks_useMergedState.default)(props.defaultValue || 0, { value: (0, vue.computed)(() => props.value) });
|
|
39
|
+
const [cleanedValue, setCleanedValue] = (0, __v_c_util_dist_hooks_useMergedState.default)(null);
|
|
40
|
+
const getStarValue = (index, x) => {
|
|
41
|
+
const { direction, allowHalf } = props;
|
|
42
|
+
const reverse = direction === "rtl";
|
|
43
|
+
let starValue = index + 1;
|
|
44
|
+
if (allowHalf) {
|
|
45
|
+
const starEle = starRefs.value.get(index);
|
|
46
|
+
const leftDis = require_util.getOffsetLeft(starEle);
|
|
47
|
+
const width = starEle.clientWidth;
|
|
48
|
+
if (reverse && x - leftDis > width / 2) starValue -= .5;
|
|
49
|
+
else if (!reverse && x - leftDis < width / 2) starValue -= .5;
|
|
50
|
+
}
|
|
51
|
+
return starValue;
|
|
52
|
+
};
|
|
53
|
+
const changeValue = (nextValue) => {
|
|
54
|
+
setStateValue(nextValue);
|
|
55
|
+
props?.onChange?.(nextValue);
|
|
56
|
+
};
|
|
57
|
+
const focused = (0, vue.ref)(false);
|
|
58
|
+
const onInternalFocus = () => {
|
|
59
|
+
focused.value = true;
|
|
60
|
+
props?.onFocus?.();
|
|
61
|
+
};
|
|
62
|
+
const onInternalBlur = () => {
|
|
63
|
+
focused.value = false;
|
|
64
|
+
props?.onBlur?.();
|
|
65
|
+
};
|
|
66
|
+
const hoverValue = (0, vue.ref)(null);
|
|
67
|
+
const onHover = (event, index) => {
|
|
68
|
+
const nextHoverValue = getStarValue(index, event.pageX);
|
|
69
|
+
if (nextHoverValue !== cleanedValue.value) {
|
|
70
|
+
hoverValue.value = nextHoverValue;
|
|
71
|
+
setCleanedValue(null);
|
|
72
|
+
}
|
|
73
|
+
props?.onHoverChange?.(nextHoverValue);
|
|
74
|
+
};
|
|
75
|
+
const onMouseLeaveCallback = (event) => {
|
|
76
|
+
const { disabled } = props;
|
|
77
|
+
if (!disabled) {
|
|
78
|
+
hoverValue.value = null;
|
|
79
|
+
setCleanedValue(null);
|
|
80
|
+
props?.onHoverChange?.(void 0);
|
|
81
|
+
}
|
|
82
|
+
if (event) props?.onMouseLeave?.(event);
|
|
83
|
+
};
|
|
84
|
+
const onClick = (event, index) => {
|
|
85
|
+
const { allowClear } = props;
|
|
86
|
+
const newValue = getStarValue(index, event.pageX);
|
|
87
|
+
let isReset = false;
|
|
88
|
+
if (allowClear) isReset = newValue === state.value;
|
|
89
|
+
onMouseLeaveCallback();
|
|
90
|
+
changeValue(isReset ? 0 : newValue);
|
|
91
|
+
setCleanedValue(isReset ? newValue : null);
|
|
92
|
+
};
|
|
93
|
+
const onInternalKeyDown = (event) => {
|
|
94
|
+
const { keyCode } = event;
|
|
95
|
+
const value = state.value;
|
|
96
|
+
const { keyboard, count, direction, allowHalf } = props;
|
|
97
|
+
const reverse = direction === "rtl";
|
|
98
|
+
const step = allowHalf ? .5 : 1;
|
|
99
|
+
if (keyboard) {
|
|
100
|
+
if (keyCode === __v_c_util_dist_KeyCode.default.RIGHT && value < count && !reverse) {
|
|
101
|
+
changeValue(value + step);
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
} else if (keyCode === __v_c_util_dist_KeyCode.default.LEFT && value > 0 && !reverse) {
|
|
104
|
+
changeValue(value - step);
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
} else if (keyCode === __v_c_util_dist_KeyCode.default.RIGHT && value > 0 && reverse) {
|
|
107
|
+
changeValue(value - step);
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
} else if (keyCode === __v_c_util_dist_KeyCode.default.LEFT && value < count && reverse) {
|
|
110
|
+
changeValue(value + step);
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
props?.onKeyDown?.(event);
|
|
115
|
+
};
|
|
116
|
+
(0, vue.onMounted)(() => {
|
|
117
|
+
const { autoFocus, disabled } = props;
|
|
118
|
+
if (autoFocus && !disabled) triggerFocus();
|
|
119
|
+
});
|
|
120
|
+
return () => {
|
|
121
|
+
const { count, allowHalf, disabled, prefixCls, direction, character, characterRender, tabIndex,...restProps } = props;
|
|
122
|
+
const { className, style, restAttrs } = (0, __v_c_util_dist_props_util.getAttrStyleAndClass)(attrs);
|
|
123
|
+
const classString = (0, __v_c_util.clsx)(prefixCls, className, {
|
|
124
|
+
[`${prefixCls}-disabled`]: disabled,
|
|
125
|
+
[`${prefixCls}-rtl`]: direction === "rtl"
|
|
126
|
+
});
|
|
127
|
+
const starNodes = Array.from({ length: count }).fill(0).map((_, index) => (0, vue.createVNode)(require_Star.default, {
|
|
128
|
+
"ref": setStarRef(index),
|
|
129
|
+
"index": index,
|
|
130
|
+
"count": count,
|
|
131
|
+
"disabled": disabled,
|
|
132
|
+
"prefixCls": `${prefixCls}-star`,
|
|
133
|
+
"allowHalf": allowHalf,
|
|
134
|
+
"value": hoverValue.value === null ? state.value : hoverValue.value,
|
|
135
|
+
"onClick": onClick,
|
|
136
|
+
"onHover": onHover,
|
|
137
|
+
"key": index,
|
|
138
|
+
"character": character,
|
|
139
|
+
"characterRender": characterRender,
|
|
140
|
+
"focused": focused.value
|
|
141
|
+
}, null));
|
|
142
|
+
return (0, vue.createVNode)("ul", (0, vue.mergeProps)({
|
|
143
|
+
"id": restProps.id,
|
|
144
|
+
"class": classString,
|
|
145
|
+
"style": style,
|
|
146
|
+
"onMouseleave": onMouseLeaveCallback,
|
|
147
|
+
"tabindex": disabled ? -1 : tabIndex,
|
|
148
|
+
"onFocus": disabled ? null : onInternalFocus,
|
|
149
|
+
"onBlur": disabled ? null : onInternalBlur,
|
|
150
|
+
"onKeydown": disabled ? null : onInternalKeyDown,
|
|
151
|
+
"ref": rateRef
|
|
152
|
+
}, (0, __v_c_util_dist_pickAttrs.default)(restAttrs, {
|
|
153
|
+
aria: true,
|
|
154
|
+
data: true,
|
|
155
|
+
attr: true
|
|
156
|
+
})), [starNodes]);
|
|
157
|
+
};
|
|
158
|
+
}, {
|
|
159
|
+
props: /* @__PURE__ */ (0, vue.mergeDefaults)({
|
|
160
|
+
prefixCls: {
|
|
161
|
+
type: String,
|
|
162
|
+
required: false,
|
|
163
|
+
default: void 0
|
|
164
|
+
},
|
|
165
|
+
defaultValue: {
|
|
166
|
+
type: Number,
|
|
167
|
+
required: false,
|
|
168
|
+
default: void 0
|
|
169
|
+
},
|
|
170
|
+
value: {
|
|
171
|
+
type: Number,
|
|
172
|
+
required: false,
|
|
173
|
+
default: void 0
|
|
174
|
+
},
|
|
175
|
+
allowClear: {
|
|
176
|
+
type: Boolean,
|
|
177
|
+
required: false,
|
|
178
|
+
default: void 0
|
|
179
|
+
},
|
|
180
|
+
keyboard: {
|
|
181
|
+
type: Boolean,
|
|
182
|
+
required: false,
|
|
183
|
+
default: void 0
|
|
184
|
+
},
|
|
185
|
+
direction: {
|
|
186
|
+
type: String,
|
|
187
|
+
required: false,
|
|
188
|
+
default: void 0
|
|
189
|
+
},
|
|
190
|
+
tabIndex: {
|
|
191
|
+
type: [Number, String],
|
|
192
|
+
required: false,
|
|
193
|
+
default: void 0
|
|
194
|
+
},
|
|
195
|
+
autoFocus: {
|
|
196
|
+
type: Boolean,
|
|
197
|
+
required: false,
|
|
198
|
+
default: void 0
|
|
199
|
+
},
|
|
200
|
+
onHoverChange: {
|
|
201
|
+
type: Function,
|
|
202
|
+
required: false,
|
|
203
|
+
default: void 0
|
|
204
|
+
},
|
|
205
|
+
onChange: {
|
|
206
|
+
type: Function,
|
|
207
|
+
required: false,
|
|
208
|
+
default: void 0
|
|
209
|
+
},
|
|
210
|
+
onFocus: {
|
|
211
|
+
type: Function,
|
|
212
|
+
required: false,
|
|
213
|
+
default: void 0
|
|
214
|
+
},
|
|
215
|
+
onBlur: {
|
|
216
|
+
type: Function,
|
|
217
|
+
required: false,
|
|
218
|
+
default: void 0
|
|
219
|
+
},
|
|
220
|
+
onKeyDown: {
|
|
221
|
+
type: Function,
|
|
222
|
+
required: false,
|
|
223
|
+
default: void 0
|
|
224
|
+
},
|
|
225
|
+
onMouseLeave: {
|
|
226
|
+
type: Function,
|
|
227
|
+
required: false,
|
|
228
|
+
default: void 0
|
|
229
|
+
},
|
|
230
|
+
"onUpdate:value": {
|
|
231
|
+
type: Function,
|
|
232
|
+
required: false,
|
|
233
|
+
default: void 0
|
|
234
|
+
},
|
|
235
|
+
id: {
|
|
236
|
+
type: String,
|
|
237
|
+
required: false,
|
|
238
|
+
default: void 0
|
|
239
|
+
},
|
|
240
|
+
count: {
|
|
241
|
+
type: Number,
|
|
242
|
+
required: false,
|
|
243
|
+
default: void 0
|
|
244
|
+
},
|
|
245
|
+
character: {
|
|
246
|
+
type: [
|
|
247
|
+
Function,
|
|
248
|
+
Object,
|
|
249
|
+
String,
|
|
250
|
+
Number,
|
|
251
|
+
null,
|
|
252
|
+
Boolean,
|
|
253
|
+
Array
|
|
254
|
+
],
|
|
255
|
+
required: false,
|
|
256
|
+
default: void 0
|
|
257
|
+
},
|
|
258
|
+
characterRender: {
|
|
259
|
+
type: Function,
|
|
260
|
+
required: false,
|
|
261
|
+
default: void 0
|
|
262
|
+
},
|
|
263
|
+
allowHalf: {
|
|
264
|
+
type: Boolean,
|
|
265
|
+
required: false,
|
|
266
|
+
default: void 0
|
|
267
|
+
},
|
|
268
|
+
disabled: {
|
|
269
|
+
type: Boolean,
|
|
270
|
+
required: false,
|
|
271
|
+
default: void 0
|
|
272
|
+
}
|
|
273
|
+
}, defaults),
|
|
274
|
+
inheritAttrs: false,
|
|
275
|
+
name: "Rate"
|
|
276
|
+
});
|
|
277
|
+
exports.default = Rate_default;
|
package/dist/Rate.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FocusEventHandler, KeyboardEventHandler } from '@v-c/util/dist/EventInterface';
|
|
2
|
+
import { StarProps } from './Star';
|
|
3
|
+
export type Direction = 'ltr' | 'rtl';
|
|
4
|
+
export interface RateProps extends Pick<StarProps, 'count' | 'character' | 'characterRender' | 'allowHalf' | 'disabled'> {
|
|
5
|
+
'prefixCls'?: string;
|
|
6
|
+
'defaultValue'?: number;
|
|
7
|
+
'value'?: number;
|
|
8
|
+
'allowClear'?: boolean;
|
|
9
|
+
'keyboard'?: boolean;
|
|
10
|
+
'direction'?: string;
|
|
11
|
+
'tabIndex'?: number | string;
|
|
12
|
+
'autoFocus'?: boolean;
|
|
13
|
+
'onHoverChange'?: (value: number) => void;
|
|
14
|
+
'onChange'?: (value: number) => void;
|
|
15
|
+
'onFocus'?: () => void;
|
|
16
|
+
'onBlur'?: () => void;
|
|
17
|
+
'onKeyDown'?: KeyboardEventHandler;
|
|
18
|
+
'onMouseLeave'?: FocusEventHandler;
|
|
19
|
+
'onUpdate:value'?: (value: number) => void;
|
|
20
|
+
'id'?: string;
|
|
21
|
+
}
|
|
22
|
+
declare const _default: import('vue').DefineSetupFnComponent<RateProps, {}, {}, RateProps & {}, import('vue').PublicProps>;
|
|
23
|
+
export default _default;
|
package/dist/Rate.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import Star_default from "./Star.js";
|
|
2
|
+
import useRefs_default from "./useRefs.js";
|
|
3
|
+
import { getOffsetLeft } from "./util.js";
|
|
4
|
+
import { computed, createVNode, defineComponent, mergeDefaults, mergeProps, onMounted, ref } from "vue";
|
|
5
|
+
import { clsx } from "@v-c/util";
|
|
6
|
+
import useMergedState from "@v-c/util/dist/hooks/useMergedState";
|
|
7
|
+
import KeyCode from "@v-c/util/dist/KeyCode";
|
|
8
|
+
import pickAttrs from "@v-c/util/dist/pickAttrs";
|
|
9
|
+
import { getAttrStyleAndClass } from "@v-c/util/dist/props-util";
|
|
10
|
+
var defaults = {
|
|
11
|
+
prefixCls: "vc-rate",
|
|
12
|
+
count: 5,
|
|
13
|
+
allowHalf: false,
|
|
14
|
+
allowClear: true,
|
|
15
|
+
keyboard: true,
|
|
16
|
+
character: "★",
|
|
17
|
+
direction: "ltr",
|
|
18
|
+
tabIndex: 0
|
|
19
|
+
};
|
|
20
|
+
var Rate_default = /* @__PURE__ */ defineComponent((props, { attrs, expose }) => {
|
|
21
|
+
const [setStarRef, starRefs] = useRefs_default();
|
|
22
|
+
const rateRef = ref(null);
|
|
23
|
+
const triggerFocus = () => {
|
|
24
|
+
if (!props.disabled) rateRef.value.focus();
|
|
25
|
+
};
|
|
26
|
+
const triggerBlur = () => {
|
|
27
|
+
if (!props.disabled) rateRef.value.blur();
|
|
28
|
+
};
|
|
29
|
+
expose({
|
|
30
|
+
focus: triggerFocus,
|
|
31
|
+
blur: triggerBlur
|
|
32
|
+
});
|
|
33
|
+
const [state, setStateValue] = useMergedState(props.defaultValue || 0, { value: computed(() => props.value) });
|
|
34
|
+
const [cleanedValue, setCleanedValue] = useMergedState(null);
|
|
35
|
+
const getStarValue = (index, x) => {
|
|
36
|
+
const { direction, allowHalf } = props;
|
|
37
|
+
const reverse = direction === "rtl";
|
|
38
|
+
let starValue = index + 1;
|
|
39
|
+
if (allowHalf) {
|
|
40
|
+
const starEle = starRefs.value.get(index);
|
|
41
|
+
const leftDis = getOffsetLeft(starEle);
|
|
42
|
+
const width = starEle.clientWidth;
|
|
43
|
+
if (reverse && x - leftDis > width / 2) starValue -= .5;
|
|
44
|
+
else if (!reverse && x - leftDis < width / 2) starValue -= .5;
|
|
45
|
+
}
|
|
46
|
+
return starValue;
|
|
47
|
+
};
|
|
48
|
+
const changeValue = (nextValue) => {
|
|
49
|
+
setStateValue(nextValue);
|
|
50
|
+
props?.onChange?.(nextValue);
|
|
51
|
+
};
|
|
52
|
+
const focused = ref(false);
|
|
53
|
+
const onInternalFocus = () => {
|
|
54
|
+
focused.value = true;
|
|
55
|
+
props?.onFocus?.();
|
|
56
|
+
};
|
|
57
|
+
const onInternalBlur = () => {
|
|
58
|
+
focused.value = false;
|
|
59
|
+
props?.onBlur?.();
|
|
60
|
+
};
|
|
61
|
+
const hoverValue = ref(null);
|
|
62
|
+
const onHover = (event, index) => {
|
|
63
|
+
const nextHoverValue = getStarValue(index, event.pageX);
|
|
64
|
+
if (nextHoverValue !== cleanedValue.value) {
|
|
65
|
+
hoverValue.value = nextHoverValue;
|
|
66
|
+
setCleanedValue(null);
|
|
67
|
+
}
|
|
68
|
+
props?.onHoverChange?.(nextHoverValue);
|
|
69
|
+
};
|
|
70
|
+
const onMouseLeaveCallback = (event) => {
|
|
71
|
+
const { disabled } = props;
|
|
72
|
+
if (!disabled) {
|
|
73
|
+
hoverValue.value = null;
|
|
74
|
+
setCleanedValue(null);
|
|
75
|
+
props?.onHoverChange?.(void 0);
|
|
76
|
+
}
|
|
77
|
+
if (event) props?.onMouseLeave?.(event);
|
|
78
|
+
};
|
|
79
|
+
const onClick = (event, index) => {
|
|
80
|
+
const { allowClear } = props;
|
|
81
|
+
const newValue = getStarValue(index, event.pageX);
|
|
82
|
+
let isReset = false;
|
|
83
|
+
if (allowClear) isReset = newValue === state.value;
|
|
84
|
+
onMouseLeaveCallback();
|
|
85
|
+
changeValue(isReset ? 0 : newValue);
|
|
86
|
+
setCleanedValue(isReset ? newValue : null);
|
|
87
|
+
};
|
|
88
|
+
const onInternalKeyDown = (event) => {
|
|
89
|
+
const { keyCode } = event;
|
|
90
|
+
const value = state.value;
|
|
91
|
+
const { keyboard, count, direction, allowHalf } = props;
|
|
92
|
+
const reverse = direction === "rtl";
|
|
93
|
+
const step = allowHalf ? .5 : 1;
|
|
94
|
+
if (keyboard) {
|
|
95
|
+
if (keyCode === KeyCode.RIGHT && value < count && !reverse) {
|
|
96
|
+
changeValue(value + step);
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
} else if (keyCode === KeyCode.LEFT && value > 0 && !reverse) {
|
|
99
|
+
changeValue(value - step);
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
} else if (keyCode === KeyCode.RIGHT && value > 0 && reverse) {
|
|
102
|
+
changeValue(value - step);
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
} else if (keyCode === KeyCode.LEFT && value < count && reverse) {
|
|
105
|
+
changeValue(value + step);
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
props?.onKeyDown?.(event);
|
|
110
|
+
};
|
|
111
|
+
onMounted(() => {
|
|
112
|
+
const { autoFocus, disabled } = props;
|
|
113
|
+
if (autoFocus && !disabled) triggerFocus();
|
|
114
|
+
});
|
|
115
|
+
return () => {
|
|
116
|
+
const { count, allowHalf, disabled, prefixCls, direction, character, characterRender, tabIndex,...restProps } = props;
|
|
117
|
+
const { className, style, restAttrs } = getAttrStyleAndClass(attrs);
|
|
118
|
+
const classString = clsx(prefixCls, className, {
|
|
119
|
+
[`${prefixCls}-disabled`]: disabled,
|
|
120
|
+
[`${prefixCls}-rtl`]: direction === "rtl"
|
|
121
|
+
});
|
|
122
|
+
const starNodes = Array.from({ length: count }).fill(0).map((_, index) => createVNode(Star_default, {
|
|
123
|
+
"ref": setStarRef(index),
|
|
124
|
+
"index": index,
|
|
125
|
+
"count": count,
|
|
126
|
+
"disabled": disabled,
|
|
127
|
+
"prefixCls": `${prefixCls}-star`,
|
|
128
|
+
"allowHalf": allowHalf,
|
|
129
|
+
"value": hoverValue.value === null ? state.value : hoverValue.value,
|
|
130
|
+
"onClick": onClick,
|
|
131
|
+
"onHover": onHover,
|
|
132
|
+
"key": index,
|
|
133
|
+
"character": character,
|
|
134
|
+
"characterRender": characterRender,
|
|
135
|
+
"focused": focused.value
|
|
136
|
+
}, null));
|
|
137
|
+
return createVNode("ul", mergeProps({
|
|
138
|
+
"id": restProps.id,
|
|
139
|
+
"class": classString,
|
|
140
|
+
"style": style,
|
|
141
|
+
"onMouseleave": onMouseLeaveCallback,
|
|
142
|
+
"tabindex": disabled ? -1 : tabIndex,
|
|
143
|
+
"onFocus": disabled ? null : onInternalFocus,
|
|
144
|
+
"onBlur": disabled ? null : onInternalBlur,
|
|
145
|
+
"onKeydown": disabled ? null : onInternalKeyDown,
|
|
146
|
+
"ref": rateRef
|
|
147
|
+
}, pickAttrs(restAttrs, {
|
|
148
|
+
aria: true,
|
|
149
|
+
data: true,
|
|
150
|
+
attr: true
|
|
151
|
+
})), [starNodes]);
|
|
152
|
+
};
|
|
153
|
+
}, {
|
|
154
|
+
props: /* @__PURE__ */ mergeDefaults({
|
|
155
|
+
prefixCls: {
|
|
156
|
+
type: String,
|
|
157
|
+
required: false,
|
|
158
|
+
default: void 0
|
|
159
|
+
},
|
|
160
|
+
defaultValue: {
|
|
161
|
+
type: Number,
|
|
162
|
+
required: false,
|
|
163
|
+
default: void 0
|
|
164
|
+
},
|
|
165
|
+
value: {
|
|
166
|
+
type: Number,
|
|
167
|
+
required: false,
|
|
168
|
+
default: void 0
|
|
169
|
+
},
|
|
170
|
+
allowClear: {
|
|
171
|
+
type: Boolean,
|
|
172
|
+
required: false,
|
|
173
|
+
default: void 0
|
|
174
|
+
},
|
|
175
|
+
keyboard: {
|
|
176
|
+
type: Boolean,
|
|
177
|
+
required: false,
|
|
178
|
+
default: void 0
|
|
179
|
+
},
|
|
180
|
+
direction: {
|
|
181
|
+
type: String,
|
|
182
|
+
required: false,
|
|
183
|
+
default: void 0
|
|
184
|
+
},
|
|
185
|
+
tabIndex: {
|
|
186
|
+
type: [Number, String],
|
|
187
|
+
required: false,
|
|
188
|
+
default: void 0
|
|
189
|
+
},
|
|
190
|
+
autoFocus: {
|
|
191
|
+
type: Boolean,
|
|
192
|
+
required: false,
|
|
193
|
+
default: void 0
|
|
194
|
+
},
|
|
195
|
+
onHoverChange: {
|
|
196
|
+
type: Function,
|
|
197
|
+
required: false,
|
|
198
|
+
default: void 0
|
|
199
|
+
},
|
|
200
|
+
onChange: {
|
|
201
|
+
type: Function,
|
|
202
|
+
required: false,
|
|
203
|
+
default: void 0
|
|
204
|
+
},
|
|
205
|
+
onFocus: {
|
|
206
|
+
type: Function,
|
|
207
|
+
required: false,
|
|
208
|
+
default: void 0
|
|
209
|
+
},
|
|
210
|
+
onBlur: {
|
|
211
|
+
type: Function,
|
|
212
|
+
required: false,
|
|
213
|
+
default: void 0
|
|
214
|
+
},
|
|
215
|
+
onKeyDown: {
|
|
216
|
+
type: Function,
|
|
217
|
+
required: false,
|
|
218
|
+
default: void 0
|
|
219
|
+
},
|
|
220
|
+
onMouseLeave: {
|
|
221
|
+
type: Function,
|
|
222
|
+
required: false,
|
|
223
|
+
default: void 0
|
|
224
|
+
},
|
|
225
|
+
"onUpdate:value": {
|
|
226
|
+
type: Function,
|
|
227
|
+
required: false,
|
|
228
|
+
default: void 0
|
|
229
|
+
},
|
|
230
|
+
id: {
|
|
231
|
+
type: String,
|
|
232
|
+
required: false,
|
|
233
|
+
default: void 0
|
|
234
|
+
},
|
|
235
|
+
count: {
|
|
236
|
+
type: Number,
|
|
237
|
+
required: false,
|
|
238
|
+
default: void 0
|
|
239
|
+
},
|
|
240
|
+
character: {
|
|
241
|
+
type: [
|
|
242
|
+
Function,
|
|
243
|
+
Object,
|
|
244
|
+
String,
|
|
245
|
+
Number,
|
|
246
|
+
null,
|
|
247
|
+
Boolean,
|
|
248
|
+
Array
|
|
249
|
+
],
|
|
250
|
+
required: false,
|
|
251
|
+
default: void 0
|
|
252
|
+
},
|
|
253
|
+
characterRender: {
|
|
254
|
+
type: Function,
|
|
255
|
+
required: false,
|
|
256
|
+
default: void 0
|
|
257
|
+
},
|
|
258
|
+
allowHalf: {
|
|
259
|
+
type: Boolean,
|
|
260
|
+
required: false,
|
|
261
|
+
default: void 0
|
|
262
|
+
},
|
|
263
|
+
disabled: {
|
|
264
|
+
type: Boolean,
|
|
265
|
+
required: false,
|
|
266
|
+
default: void 0
|
|
267
|
+
}
|
|
268
|
+
}, defaults),
|
|
269
|
+
inheritAttrs: false,
|
|
270
|
+
name: "Rate"
|
|
271
|
+
});
|
|
272
|
+
export { Rate_default as default };
|
package/dist/Star.cjs
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
|
|
5
|
+
__v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(__v_c_util_dist_KeyCode);
|
|
6
|
+
var Star_default = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
|
|
7
|
+
const onHover = (e) => {
|
|
8
|
+
const { index } = props;
|
|
9
|
+
props?.onHover?.(e, index);
|
|
10
|
+
};
|
|
11
|
+
const onClick = (e) => {
|
|
12
|
+
const { index } = props;
|
|
13
|
+
props?.onClick?.(e, index);
|
|
14
|
+
};
|
|
15
|
+
const onKeyDown = (e) => {
|
|
16
|
+
const { index } = props;
|
|
17
|
+
if (e.keyCode === __v_c_util_dist_KeyCode.default.ENTER) props?.onClick?.(e, index);
|
|
18
|
+
};
|
|
19
|
+
const cls = (0, vue.computed)(() => {
|
|
20
|
+
const { prefixCls, index, value, allowHalf, focused } = props;
|
|
21
|
+
const starValue = index + 1;
|
|
22
|
+
let className = prefixCls;
|
|
23
|
+
if (value === 0 && index === 0 && focused) className += ` ${prefixCls}-focused`;
|
|
24
|
+
else if (allowHalf && value + .5 >= starValue && value < starValue) {
|
|
25
|
+
className += ` ${prefixCls}-half ${prefixCls}-active`;
|
|
26
|
+
if (focused) className += ` ${prefixCls}-focused`;
|
|
27
|
+
} else {
|
|
28
|
+
if (starValue <= value) className += ` ${prefixCls}-full`;
|
|
29
|
+
else className += ` ${prefixCls}-zero`;
|
|
30
|
+
if (starValue === value && focused) className += ` ${prefixCls}-focused`;
|
|
31
|
+
}
|
|
32
|
+
return className;
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
const { disabled, prefixCls, characterRender, character, index, count, value } = props;
|
|
36
|
+
const characterNode = typeof character === "function" ? character({
|
|
37
|
+
disabled,
|
|
38
|
+
prefixCls,
|
|
39
|
+
index,
|
|
40
|
+
count,
|
|
41
|
+
value
|
|
42
|
+
}) : character;
|
|
43
|
+
let star = (0, vue.createVNode)("li", { "class": cls.value }, [(0, vue.createVNode)("div", {
|
|
44
|
+
"onClick": disabled ? null : onClick,
|
|
45
|
+
"onKeydown": disabled ? null : onKeyDown,
|
|
46
|
+
"onMousemove": disabled ? null : onHover,
|
|
47
|
+
"role": "radio",
|
|
48
|
+
"aria-checked": value > index ? "true" : "false",
|
|
49
|
+
"aria-posinset": index + 1,
|
|
50
|
+
"aria-setsize": count,
|
|
51
|
+
"tabindex": disabled ? -1 : 0
|
|
52
|
+
}, [(0, vue.createVNode)("div", { "class": `${prefixCls}-first` }, [characterNode]), (0, vue.createVNode)("div", { "class": `${prefixCls}-second` }, [characterNode])])]);
|
|
53
|
+
if (characterRender) star = characterRender(star, props);
|
|
54
|
+
return star;
|
|
55
|
+
};
|
|
56
|
+
}, {
|
|
57
|
+
props: {
|
|
58
|
+
value: {
|
|
59
|
+
type: Number,
|
|
60
|
+
required: false,
|
|
61
|
+
default: void 0
|
|
62
|
+
},
|
|
63
|
+
index: {
|
|
64
|
+
type: Number,
|
|
65
|
+
required: false,
|
|
66
|
+
default: void 0
|
|
67
|
+
},
|
|
68
|
+
prefixCls: {
|
|
69
|
+
type: String,
|
|
70
|
+
required: false,
|
|
71
|
+
default: void 0
|
|
72
|
+
},
|
|
73
|
+
allowHalf: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
required: false,
|
|
76
|
+
default: void 0
|
|
77
|
+
},
|
|
78
|
+
disabled: {
|
|
79
|
+
type: Boolean,
|
|
80
|
+
required: false,
|
|
81
|
+
default: void 0
|
|
82
|
+
},
|
|
83
|
+
character: {
|
|
84
|
+
type: [
|
|
85
|
+
Function,
|
|
86
|
+
Object,
|
|
87
|
+
String,
|
|
88
|
+
Number,
|
|
89
|
+
null,
|
|
90
|
+
Boolean,
|
|
91
|
+
Array
|
|
92
|
+
],
|
|
93
|
+
required: false,
|
|
94
|
+
default: void 0
|
|
95
|
+
},
|
|
96
|
+
characterRender: {
|
|
97
|
+
type: Function,
|
|
98
|
+
required: false,
|
|
99
|
+
default: void 0
|
|
100
|
+
},
|
|
101
|
+
onClick: {
|
|
102
|
+
type: Function,
|
|
103
|
+
required: false,
|
|
104
|
+
default: void 0
|
|
105
|
+
},
|
|
106
|
+
onHover: {
|
|
107
|
+
type: Function,
|
|
108
|
+
required: false,
|
|
109
|
+
default: void 0
|
|
110
|
+
},
|
|
111
|
+
focused: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
required: false,
|
|
114
|
+
default: void 0
|
|
115
|
+
},
|
|
116
|
+
count: {
|
|
117
|
+
type: Number,
|
|
118
|
+
required: false,
|
|
119
|
+
default: void 0
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
name: "RateStar",
|
|
123
|
+
inheritAttrs: false
|
|
124
|
+
});
|
|
125
|
+
exports.default = Star_default;
|
package/dist/Star.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
export interface StarProps {
|
|
3
|
+
value?: number;
|
|
4
|
+
index?: number;
|
|
5
|
+
prefixCls?: string;
|
|
6
|
+
allowHalf?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
character?: ((props: StarProps) => any) | VueNode;
|
|
9
|
+
characterRender?: ((origin: any, props: StarProps) => any);
|
|
10
|
+
onClick?: (e: MouseEvent | KeyboardEvent, index: number) => void;
|
|
11
|
+
onHover?: (e: MouseEvent, index: number) => void;
|
|
12
|
+
focused?: boolean;
|
|
13
|
+
count?: number;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: import('vue').DefineSetupFnComponent<StarProps, {}, {}, StarProps & {}, import('vue').PublicProps>;
|
|
16
|
+
export default _default;
|
package/dist/Star.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { computed, createVNode, defineComponent } from "vue";
|
|
2
|
+
import KeyCode from "@v-c/util/dist/KeyCode";
|
|
3
|
+
var Star_default = /* @__PURE__ */ defineComponent((props) => {
|
|
4
|
+
const onHover = (e) => {
|
|
5
|
+
const { index } = props;
|
|
6
|
+
props?.onHover?.(e, index);
|
|
7
|
+
};
|
|
8
|
+
const onClick = (e) => {
|
|
9
|
+
const { index } = props;
|
|
10
|
+
props?.onClick?.(e, index);
|
|
11
|
+
};
|
|
12
|
+
const onKeyDown = (e) => {
|
|
13
|
+
const { index } = props;
|
|
14
|
+
if (e.keyCode === KeyCode.ENTER) props?.onClick?.(e, index);
|
|
15
|
+
};
|
|
16
|
+
const cls = computed(() => {
|
|
17
|
+
const { prefixCls, index, value, allowHalf, focused } = props;
|
|
18
|
+
const starValue = index + 1;
|
|
19
|
+
let className = prefixCls;
|
|
20
|
+
if (value === 0 && index === 0 && focused) className += ` ${prefixCls}-focused`;
|
|
21
|
+
else if (allowHalf && value + .5 >= starValue && value < starValue) {
|
|
22
|
+
className += ` ${prefixCls}-half ${prefixCls}-active`;
|
|
23
|
+
if (focused) className += ` ${prefixCls}-focused`;
|
|
24
|
+
} else {
|
|
25
|
+
if (starValue <= value) className += ` ${prefixCls}-full`;
|
|
26
|
+
else className += ` ${prefixCls}-zero`;
|
|
27
|
+
if (starValue === value && focused) className += ` ${prefixCls}-focused`;
|
|
28
|
+
}
|
|
29
|
+
return className;
|
|
30
|
+
});
|
|
31
|
+
return () => {
|
|
32
|
+
const { disabled, prefixCls, characterRender, character, index, count, value } = props;
|
|
33
|
+
const characterNode = typeof character === "function" ? character({
|
|
34
|
+
disabled,
|
|
35
|
+
prefixCls,
|
|
36
|
+
index,
|
|
37
|
+
count,
|
|
38
|
+
value
|
|
39
|
+
}) : character;
|
|
40
|
+
let star = createVNode("li", { "class": cls.value }, [createVNode("div", {
|
|
41
|
+
"onClick": disabled ? null : onClick,
|
|
42
|
+
"onKeydown": disabled ? null : onKeyDown,
|
|
43
|
+
"onMousemove": disabled ? null : onHover,
|
|
44
|
+
"role": "radio",
|
|
45
|
+
"aria-checked": value > index ? "true" : "false",
|
|
46
|
+
"aria-posinset": index + 1,
|
|
47
|
+
"aria-setsize": count,
|
|
48
|
+
"tabindex": disabled ? -1 : 0
|
|
49
|
+
}, [createVNode("div", { "class": `${prefixCls}-first` }, [characterNode]), createVNode("div", { "class": `${prefixCls}-second` }, [characterNode])])]);
|
|
50
|
+
if (characterRender) star = characterRender(star, props);
|
|
51
|
+
return star;
|
|
52
|
+
};
|
|
53
|
+
}, {
|
|
54
|
+
props: {
|
|
55
|
+
value: {
|
|
56
|
+
type: Number,
|
|
57
|
+
required: false,
|
|
58
|
+
default: void 0
|
|
59
|
+
},
|
|
60
|
+
index: {
|
|
61
|
+
type: Number,
|
|
62
|
+
required: false,
|
|
63
|
+
default: void 0
|
|
64
|
+
},
|
|
65
|
+
prefixCls: {
|
|
66
|
+
type: String,
|
|
67
|
+
required: false,
|
|
68
|
+
default: void 0
|
|
69
|
+
},
|
|
70
|
+
allowHalf: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
required: false,
|
|
73
|
+
default: void 0
|
|
74
|
+
},
|
|
75
|
+
disabled: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
required: false,
|
|
78
|
+
default: void 0
|
|
79
|
+
},
|
|
80
|
+
character: {
|
|
81
|
+
type: [
|
|
82
|
+
Function,
|
|
83
|
+
Object,
|
|
84
|
+
String,
|
|
85
|
+
Number,
|
|
86
|
+
null,
|
|
87
|
+
Boolean,
|
|
88
|
+
Array
|
|
89
|
+
],
|
|
90
|
+
required: false,
|
|
91
|
+
default: void 0
|
|
92
|
+
},
|
|
93
|
+
characterRender: {
|
|
94
|
+
type: Function,
|
|
95
|
+
required: false,
|
|
96
|
+
default: void 0
|
|
97
|
+
},
|
|
98
|
+
onClick: {
|
|
99
|
+
type: Function,
|
|
100
|
+
required: false,
|
|
101
|
+
default: void 0
|
|
102
|
+
},
|
|
103
|
+
onHover: {
|
|
104
|
+
type: Function,
|
|
105
|
+
required: false,
|
|
106
|
+
default: void 0
|
|
107
|
+
},
|
|
108
|
+
focused: {
|
|
109
|
+
type: Boolean,
|
|
110
|
+
required: false,
|
|
111
|
+
default: void 0
|
|
112
|
+
},
|
|
113
|
+
count: {
|
|
114
|
+
type: Number,
|
|
115
|
+
required: false,
|
|
116
|
+
default: void 0
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
name: "RateStar",
|
|
120
|
+
inheritAttrs: false
|
|
121
|
+
});
|
|
122
|
+
export { Star_default as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
+
key = keys[i];
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: ((k) => from[k]).bind(null, key),
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
value: mod,
|
|
19
|
+
enumerable: true
|
|
20
|
+
}) : target, mod));
|
|
21
|
+
exports.__toESM = __toESM;
|
package/dist/index.cjs
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/useRefs.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let __v_c_util_dist_Dom_findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
5
|
+
function useRefs() {
|
|
6
|
+
const refs = (0, vue.ref)(/* @__PURE__ */ new Map());
|
|
7
|
+
const setRef = (key) => (el) => {
|
|
8
|
+
refs.value.set(key, (0, __v_c_util_dist_Dom_findDOMNode.getDOM)(el));
|
|
9
|
+
};
|
|
10
|
+
(0, vue.onBeforeUpdate)(() => {
|
|
11
|
+
refs.value = /* @__PURE__ */ new Map();
|
|
12
|
+
});
|
|
13
|
+
return [setRef, refs];
|
|
14
|
+
}
|
|
15
|
+
var useRefs_default = useRefs;
|
|
16
|
+
exports.default = useRefs_default;
|
package/dist/useRefs.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { onBeforeUpdate, ref } from "vue";
|
|
2
|
+
import { getDOM } from "@v-c/util/dist/Dom/findDOMNode";
|
|
3
|
+
function useRefs() {
|
|
4
|
+
const refs = ref(/* @__PURE__ */ new Map());
|
|
5
|
+
const setRef = (key) => (el) => {
|
|
6
|
+
refs.value.set(key, getDOM(el));
|
|
7
|
+
};
|
|
8
|
+
onBeforeUpdate(() => {
|
|
9
|
+
refs.value = /* @__PURE__ */ new Map();
|
|
10
|
+
});
|
|
11
|
+
return [setRef, refs];
|
|
12
|
+
}
|
|
13
|
+
var useRefs_default = useRefs;
|
|
14
|
+
export { useRefs_default as default };
|
package/dist/util.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function getScroll(w) {
|
|
2
|
+
let ret = w.scrollX;
|
|
3
|
+
const method = "scrollLeft";
|
|
4
|
+
if (typeof ret !== "number") {
|
|
5
|
+
const d = w.document;
|
|
6
|
+
ret = d.documentElement[method];
|
|
7
|
+
if (typeof ret !== "number") ret = d.body[method];
|
|
8
|
+
}
|
|
9
|
+
return ret;
|
|
10
|
+
}
|
|
11
|
+
function getClientPosition(elem) {
|
|
12
|
+
let x;
|
|
13
|
+
let y;
|
|
14
|
+
const doc = elem.ownerDocument;
|
|
15
|
+
const { body } = doc;
|
|
16
|
+
const docElem = doc && doc.documentElement;
|
|
17
|
+
const box = elem.getBoundingClientRect();
|
|
18
|
+
x = box.left;
|
|
19
|
+
y = box.top;
|
|
20
|
+
x -= docElem.clientLeft || body.clientLeft || 0;
|
|
21
|
+
y -= docElem.clientTop || body.clientTop || 0;
|
|
22
|
+
return {
|
|
23
|
+
left: x,
|
|
24
|
+
top: y
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function getOffsetLeft(el) {
|
|
28
|
+
const pos = getClientPosition(el);
|
|
29
|
+
const doc = el.ownerDocument;
|
|
30
|
+
const w = doc.defaultView || doc.parentWindow;
|
|
31
|
+
pos.left += getScroll(w);
|
|
32
|
+
return pos.left;
|
|
33
|
+
}
|
|
34
|
+
exports.getOffsetLeft = getOffsetLeft;
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getOffsetLeft(el: HTMLElement): number;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function getScroll(w) {
|
|
2
|
+
let ret = w.scrollX;
|
|
3
|
+
const method = "scrollLeft";
|
|
4
|
+
if (typeof ret !== "number") {
|
|
5
|
+
const d = w.document;
|
|
6
|
+
ret = d.documentElement[method];
|
|
7
|
+
if (typeof ret !== "number") ret = d.body[method];
|
|
8
|
+
}
|
|
9
|
+
return ret;
|
|
10
|
+
}
|
|
11
|
+
function getClientPosition(elem) {
|
|
12
|
+
let x;
|
|
13
|
+
let y;
|
|
14
|
+
const doc = elem.ownerDocument;
|
|
15
|
+
const { body } = doc;
|
|
16
|
+
const docElem = doc && doc.documentElement;
|
|
17
|
+
const box = elem.getBoundingClientRect();
|
|
18
|
+
x = box.left;
|
|
19
|
+
y = box.top;
|
|
20
|
+
x -= docElem.clientLeft || body.clientLeft || 0;
|
|
21
|
+
y -= docElem.clientTop || body.clientTop || 0;
|
|
22
|
+
return {
|
|
23
|
+
left: x,
|
|
24
|
+
top: y
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function getOffsetLeft(el) {
|
|
28
|
+
const pos = getClientPosition(el);
|
|
29
|
+
const doc = el.ownerDocument;
|
|
30
|
+
const w = doc.defaultView || doc.parentWindow;
|
|
31
|
+
pos.left += getScroll(w);
|
|
32
|
+
return pos.left;
|
|
33
|
+
}
|
|
34
|
+
export { getOffsetLeft };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-c/rate",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./dist/*": "./dist/*",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"package.json"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"vue": "^3.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@v-c/util": "^1.0.2"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "vite build",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"prepublish": "pnpm build",
|
|
32
|
+
"patch": "bumpp --release patch",
|
|
33
|
+
"bump": "bumpp"
|
|
34
|
+
}
|
|
35
|
+
}
|