@opentiny/vue-renderless 3.6.8 → 3.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/action-sheet/index.js +28 -1
- package/action-sheet/vue.js +10 -4
- package/alert/index.js +24 -2
- package/alert/vue.js +15 -11
- package/amount/index.js +4 -4
- package/anchor/index.js +1 -1
- package/autocomplete/vue.js +3 -3
- package/autonavi-map/index.js +1 -1
- package/badge/vue.js +6 -6
- package/baidu-map/index.js +1 -1
- package/bulletin-board/index.js +1 -1
- package/button-group/vue.js +5 -4
- package/calendar/index.js +2 -2
- package/calendar-bar/index.js +268 -0
- package/calendar-bar/vue.js +87 -0
- package/card/index.js +84 -0
- package/card/vue.js +70 -0
- package/card-group/index.js +16 -0
- package/card-group/vue.js +21 -0
- package/card-template/index.js +1 -1
- package/carousel/index.js +89 -2
- package/carousel/vue.js +14 -5
- package/carousel-item/index.js +8 -0
- package/carousel-item/vue.js +7 -3
- package/cascader/index.js +6 -6
- package/cascader/vue.js +3 -3
- package/cascader-menu/vue.js +2 -2
- package/cascader-panel/index.js +4 -4
- package/cascader-panel/node.js +4 -4
- package/cascader-panel/vue.js +2 -2
- package/cascader-select/index.js +179 -0
- package/cascader-select/vue.js +74 -0
- package/cell/vue.js +16 -0
- package/chart-bar/index.js +3 -3
- package/chart-boxplot/index.js +2 -2
- package/chart-candle/index.js +3 -3
- package/chart-core/deps/utils.js +7 -7
- package/chart-core/index.js +2 -2
- package/chart-funnel/index.js +3 -3
- package/chart-gauge/index.js +3 -3
- package/chart-graph/index.js +1 -1
- package/chart-heatmap/index.js +2 -2
- package/chart-line/index.js +3 -3
- package/chart-liquidfill/index.js +2 -2
- package/chart-map/index.js +3 -3
- package/chart-pie/index.js +3 -3
- package/chart-radar/index.js +3 -3
- package/chart-sankey/index.js +3 -3
- package/chart-scatter/index.js +4 -4
- package/chart-sunburst/index.js +1 -1
- package/chart-tree/index.js +2 -2
- package/chart-waterfall/index.js +3 -3
- package/chart-wordcloud/index.js +2 -2
- package/checkbox/index.js +21 -0
- package/checkbox/vue.js +16 -3
- package/checkbox-button/vue.js +1 -1
- package/collapse-item/vue.js +1 -1
- package/column-list-group/index.js +0 -0
- package/column-list-group/vue.js +14 -0
- package/column-list-item/index.js +50 -0
- package/column-list-item/vue.js +39 -0
- package/common/array.js +3 -3
- package/common/bigInt.js +5 -2
- package/common/dataset/index.js +3 -3
- package/common/date.js +2 -2
- package/common/deps/ResizeObserver.js +1 -1
- package/common/deps/clickoutside.js +1 -1
- package/common/deps/date-util.js +4 -4
- package/common/deps/date.js +2 -2
- package/common/deps/debounce.js +1 -1
- package/common/deps/dom.js +1 -1
- package/common/deps/fullscreen/apis.js +3 -3
- package/common/deps/fullscreen/screenfull.js +1 -1
- package/common/deps/infinite-scroll.js +176 -0
- package/common/deps/letter-only.js +1 -1
- package/common/deps/number-only.js +1 -1
- package/common/deps/observe-visibility.js +106 -0
- package/common/deps/popper.js +20 -22
- package/common/deps/popup-manager.js +2 -2
- package/common/deps/repeat-click.js +1 -1
- package/common/deps/resize-event.js +1 -1
- package/common/deps/tree-model/node.js +5 -5
- package/common/deps/tree-model/tree-store.js +3 -3
- package/common/deps/upload-ajax.js +2 -2
- package/common/deps/vue-popper.js +6 -6
- package/common/deps/vue-popup.js +4 -4
- package/common/index.js +2 -2
- package/common/object.js +1 -1
- package/common/runtime.js +24 -24
- package/common/string.js +23 -4
- package/common/validate/rules/range.js +2 -2
- package/common/validate/rules/required.js +1 -1
- package/common/validate/rules/type.js +3 -3
- package/common/validate/schema.js +1 -1
- package/common/validate/util.js +1 -1
- package/common/validate/validations/array.js +1 -1
- package/common/validate/validations/date.js +1 -1
- package/common/validate/validations/enum.js +1 -1
- package/common/validate/validations/float.js +1 -1
- package/common/validate/validations/integer.js +1 -1
- package/common/validate/validations/method.js +1 -1
- package/common/validate/validations/number.js +1 -1
- package/common/validate/validations/pattern.js +1 -1
- package/common/validate/validations/string.js +1 -1
- package/common/validate/validations/type.js +1 -1
- package/container/index.js +1 -1
- package/crop/index.js +2 -2
- package/currency/index.js +2 -2
- package/date-panel/index.js +7 -7
- package/date-panel/vue.js +3 -2
- package/date-picker-mobile/index.js +250 -0
- package/date-picker-mobile/vue.js +86 -0
- package/date-range/index.js +1 -1
- package/date-range/vue.js +1 -1
- package/date-table/index.js +3 -3
- package/date-table/vue.js +1 -1
- package/dialog-box/index.js +6 -4
- package/dialog-box/vue.js +1 -1
- package/dialog-select/index.js +345 -0
- package/dialog-select/vue.js +110 -0
- package/drawer/index.js +83 -0
- package/drawer/vue.js +51 -0
- package/drop-times/index.js +1 -1
- package/dropdown/index.js +2 -2
- package/dropdown/vue.js +4 -3
- package/dropdown-item/index.js +5 -1
- package/dropdown-item/mf.js +79 -0
- package/dropdown-item/vue.js +9 -6
- package/dropdown-menu/index.js +30 -1
- package/dropdown-menu/vue.js +17 -7
- package/dynamic-scroller/index.js +117 -0
- package/dynamic-scroller/vue.js +88 -0
- package/dynamic-scroller-item/index.js +147 -0
- package/dynamic-scroller-item/vue.js +92 -0
- package/espace/index.js +1 -1
- package/espace/vue.js +1 -1
- package/exception/vue.js +3 -1
- package/fall-menu/index.js +4 -4
- package/file-upload/index.js +872 -408
- package/file-upload/vue.js +87 -36
- package/filter/index.js +131 -0
- package/filter/tag-group.js +43 -0
- package/filter/vue.js +73 -0
- package/filter-bar/index.js +9 -0
- package/filter-bar/vue.js +16 -0
- package/filter-box/index.js +17 -0
- package/filter-box/vue.js +19 -0
- package/filter-panel/index.js +42 -0
- package/filter-panel/vue.js +33 -0
- package/floatbar/index.js +1 -1
- package/flowchart/index.js +721 -0
- package/flowchart/vue.js +81 -0
- package/form/index.js +15 -1
- package/form/vue.js +10 -4
- package/form-item/index.js +46 -6
- package/form-item/vue.js +27 -3
- package/fullscreen/index.js +1 -1
- package/fullscreen/vue.js +1 -1
- package/grid/plugins/export.js +2 -2
- package/grid/plugins/exportExcel.js +2 -2
- package/grid/plugins/resize.js +1 -1
- package/grid/static/base/helperEqualCompare.js +1 -1
- package/grid/static/base/isPlainObject.js +1 -1
- package/grid/utils/common.js +3 -3
- package/grid/utils/dom.js +3 -3
- package/grid/utils/event.js +2 -2
- package/guide/index.js +168 -0
- package/guide/vue.js +36 -0
- package/hrapprover/index.js +1 -1
- package/image/index.js +8 -4
- package/image/vue.js +12 -6
- package/image-viewer/index.js +3 -3
- package/image-viewer/vue.js +16 -6
- package/input/index.js +34 -1
- package/input/vue.js +22 -6
- package/ip-address/index.js +1 -1
- package/ip-address/vue.js +1 -1
- package/link-menu/index.js +2 -2
- package/link-menu/vue.js +2 -2
- package/loading/index.js +2 -2
- package/loading/vue.js +2 -1
- package/locales/index.js +1 -1
- package/logout/index.js +1 -1
- package/milestone/index.js +5 -1
- package/modal/index.js +68 -39
- package/modal/vue.js +15 -12
- package/month-range/index.js +1 -1
- package/month-range/vue.js +1 -1
- package/month-table/index.js +5 -5
- package/month-table/vue.js +1 -1
- package/multi-select/index.js +5 -2
- package/multi-select/vue.js +4 -5
- package/nav-menu/index.js +6 -6
- package/notify/index.js +3 -3
- package/numeric/index.js +15 -5
- package/numeric/vue.js +15 -6
- package/option/index.js +1 -1
- package/package.json +2 -1
- package/pager/vue.js +10 -0
- package/pager-item/index.js +1 -1
- package/panel/index.js +1 -1
- package/picker/index.js +7 -7
- package/picker/vue.js +1 -1
- package/picker-column/index.js +1 -1
- package/popconfirm/index.js +25 -0
- package/popconfirm/vue.js +22 -0
- package/popeditor/index.js +7 -7
- package/popeditor/vue.js +2 -2
- package/popover/index.js +11 -3
- package/popover/vue.js +33 -10
- package/popup/index.js +4 -4
- package/pull-refresh/index.js +8 -11
- package/pull-refresh/vue.js +7 -7
- package/radio/index.js +17 -0
- package/radio/vue.js +18 -3
- package/radio-button/index.js +8 -0
- package/radio-button/vue.js +19 -4
- package/radio-group/index.js +1 -1
- package/radio-group/vue.js +5 -2
- package/rate/index.js +4 -2
- package/rate/vue.js +1 -1
- package/record/index.js +190 -0
- package/record/vue.js +44 -0
- package/recycle-scroller/index.js +470 -0
- package/recycle-scroller/vue.js +135 -0
- package/river/index.js +371 -0
- package/river/river.js +352 -0
- package/river/vue.js +77 -0
- package/roles/index.js +1 -1
- package/scrollbar/vue-bar.js +1 -1
- package/scrollbar/vue.js +1 -1
- package/search/index.js +3 -3
- package/select/index.js +21 -14
- package/select/vue.js +38 -15
- package/select-dropdown/vue.js +1 -1
- package/select-mobile/index.js +111 -0
- package/select-mobile/vue.js +58 -0
- package/select-view/index.js +170 -0
- package/select-view/vue.js +82 -0
- package/selected-box/index.js +216 -0
- package/selected-box/vue.js +98 -0
- package/slide-bar/index.js +1 -1
- package/slider/index.js +49 -4
- package/slider/vue.js +15 -4
- package/split/vue.js +1 -1
- package/standard-list-item/index.js +18 -0
- package/standard-list-item/vue.js +22 -0
- package/steps/index.js +30 -0
- package/steps/slide-bar.js +122 -0
- package/steps/vue.js +15 -3
- package/switch/index.js +1 -1
- package/switch/vue.js +2 -1
- package/tab-bar/index.js +2 -2
- package/tab-item/index.js +3 -3
- package/tab-item/vue.js +4 -3
- package/tab-item-mf/index.js +0 -0
- package/tab-item-mf/vue.js +16 -0
- package/tab-nav/index.js +78 -4
- package/tab-nav/vue.js +11 -3
- package/tabbar-item/index.js +1 -1
- package/tabbar-item/vue.js +1 -1
- package/tabs/index.js +8 -9
- package/tabs/vue.js +1 -1
- package/tabs-mf/index.js +109 -0
- package/tabs-mf/vue-bar.js +49 -0
- package/tabs-mf/vue-nav-item.js +22 -0
- package/tabs-mf/vue-nav.js +13 -0
- package/tabs-mf/vue.js +45 -0
- package/tabs-mf/wheel.js +71 -0
- package/tag/index.js +8 -2
- package/tag/vue.js +13 -5
- package/tag-group/index.js +24 -0
- package/tag-group/vue.js +29 -0
- package/tall-storage/index.js +1 -1
- package/tall-storage/vue.js +1 -1
- package/time/index.js +1 -1
- package/time/vue.js +2 -2
- package/time-line/index.js +28 -7
- package/time-line/vue.js +9 -4
- package/time-panel/index.js +2 -2
- package/time-panel/vue.js +1 -1
- package/time-picker-mobile/index.js +30 -0
- package/time-picker-mobile/vue.js +30 -0
- package/time-range/index.js +1 -1
- package/time-range/vue.js +1 -1
- package/time-spinner/index.js +2 -2
- package/time-spinner/vue.js +1 -1
- package/toggle-menu/index.js +2 -2
- package/toggle-menu/vue.js +1 -1
- package/tooltip/index.js +30 -3
- package/tooltip/vue.js +34 -13
- package/top-box/index.js +3 -3
- package/transfer/index.js +1 -1
- package/transfer-panel/index.js +2 -2
- package/tree/index.js +6 -6
- package/tree/vue.js +1 -1
- package/tree-node/index.js +1 -1
- package/upload/index.js +1 -1
- package/upload/vue.js +2 -2
- package/upload-dragger/index.js +5 -1
- package/upload-dragger/vue.js +9 -3
- package/upload-list/index.js +158 -8
- package/upload-list/vue.js +77 -25
- package/user/index.js +86 -70
- package/user/vue.js +15 -5
- package/user-account/vue.js +1 -1
- package/user-contact/index.js +49 -3
- package/user-contact/vue.js +17 -8
- package/user-head-group/vue.js +17 -0
- package/user-link/index.js +10 -2
- package/user-link/vue.js +11 -6
- package/wheel/index.js +1 -1
- package/wizard/index.js +3 -3
- package/year-range/index.js +125 -0
- package/year-range/vue.js +88 -0
- package/year-table/index.js +175 -11
- package/year-table/vue.js +17 -5
package/radio-button/index.js
CHANGED
|
@@ -29,11 +29,19 @@ const toggleEvents = ({ refs, props }) => (isUnBind = false) => {
|
|
|
29
29
|
radioEl[(isUnBind ? "remove" : "add") + "EventListener"](ev, props.events[ev]);
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
+
const keydownHandle = ({ state, props }) => () => {
|
|
33
|
+
state.value = state.isDisabled ? state.value : props.label;
|
|
34
|
+
};
|
|
35
|
+
const handleFocus = (state) => () => state.focus = true;
|
|
36
|
+
const handleBlur = (state) => () => state.focus = false;
|
|
32
37
|
export {
|
|
33
38
|
getGroup,
|
|
34
39
|
getStyle,
|
|
35
40
|
getValue,
|
|
41
|
+
handleBlur,
|
|
36
42
|
handleChange,
|
|
43
|
+
handleFocus,
|
|
44
|
+
keydownHandle,
|
|
37
45
|
setValue,
|
|
38
46
|
toggleEvents
|
|
39
47
|
};
|
package/radio-button/vue.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import "../chunk-PKUHTIDK.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
handleChange,
|
|
4
|
+
getValue,
|
|
5
|
+
setValue,
|
|
6
|
+
getGroup,
|
|
7
|
+
getStyle,
|
|
8
|
+
toggleEvents,
|
|
9
|
+
keydownHandle,
|
|
10
|
+
handleFocus,
|
|
11
|
+
handleBlur
|
|
12
|
+
} from "./index";
|
|
3
13
|
const api = ["state", "handleChange"];
|
|
4
|
-
const renderless = (props, { computed, reactive, onMounted, onBeforeUnmount }, { emit, parent, dispatch, constants, nextTick, refs }) => {
|
|
14
|
+
const renderless = (props, { computed, reactive, onMounted, onBeforeUnmount, inject }, { emit, parent, dispatch, constants, nextTick, refs }) => {
|
|
5
15
|
const api2 = {
|
|
6
16
|
getGroup: getGroup({ constants, parent }),
|
|
7
17
|
toggleEvents: toggleEvents({ refs, props })
|
|
@@ -16,14 +26,19 @@ const renderless = (props, { computed, reactive, onMounted, onBeforeUnmount }, {
|
|
|
16
26
|
activeStyle: computed(() => api2.getStyle()),
|
|
17
27
|
size: computed(() => state.radioGroup.state.radioGroupSize),
|
|
18
28
|
isDisabled: computed(() => props.disabled || state.radioGroup.disabled),
|
|
19
|
-
tabIndex: computed(() => state.isDisabled || state.radioGroup && state.value !== props.label ? -1 : 0)
|
|
29
|
+
tabIndex: computed(() => state.isDisabled || state.radioGroup && state.value !== props.label ? -1 : 0),
|
|
30
|
+
showTips: inject("showTips", null),
|
|
31
|
+
tipContent: props.tipContent
|
|
20
32
|
});
|
|
21
33
|
Object.assign(api2, {
|
|
22
34
|
state,
|
|
23
35
|
getValue: getValue(state),
|
|
24
36
|
getStyle: getStyle(state),
|
|
25
37
|
setValue: setValue({ emit, state }),
|
|
26
|
-
handleChange: handleChange({ constants, dispatch, nextTick, state })
|
|
38
|
+
handleChange: handleChange({ constants, dispatch, nextTick, state }),
|
|
39
|
+
keydownHandle: keydownHandle({ state, props }),
|
|
40
|
+
handleFocus: handleFocus(state),
|
|
41
|
+
handleBlur: handleBlur(state)
|
|
27
42
|
});
|
|
28
43
|
onMounted(api2.toggleEvents);
|
|
29
44
|
onBeforeUnmount(() => {
|
package/radio-group/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../chunk-PKUHTIDK.js";
|
|
2
|
-
import { KEY_CODE } from "
|
|
2
|
+
import { KEY_CODE } from "../common";
|
|
3
3
|
const handleKeydown = ({ parent }) => (event) => {
|
|
4
4
|
const target = event.target;
|
|
5
5
|
const className = target.nodeName === "INPUT" ? "[type=radio]" : "[role=radio]";
|
package/radio-group/vue.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "../chunk-PKUHTIDK.js";
|
|
2
2
|
import { handleKeydown, mounted } from "./index";
|
|
3
3
|
const api = ["state", "handleKeydown"];
|
|
4
|
-
const renderless = (props, { computed, onMounted, reactive, watch }, { parent, dispatch }) => {
|
|
4
|
+
const renderless = (props, { computed, onMounted, reactive, watch, provide }, { parent, dispatch }) => {
|
|
5
5
|
const state = reactive({
|
|
6
6
|
radioGroupSize: computed(() => props.size),
|
|
7
|
-
tag: "div"
|
|
7
|
+
tag: "div",
|
|
8
|
+
activeStyle: props.fill
|
|
8
9
|
});
|
|
9
10
|
parent.$on("handleChange", (value) => {
|
|
10
11
|
parent.$emit("change", value);
|
|
@@ -22,6 +23,8 @@ const renderless = (props, { computed, onMounted, reactive, watch }, { parent, d
|
|
|
22
23
|
}
|
|
23
24
|
);
|
|
24
25
|
onMounted(api2.onMounted);
|
|
26
|
+
provide("radioVertical", props.vertical);
|
|
27
|
+
provide("showTips", props.showTips);
|
|
25
28
|
return api2;
|
|
26
29
|
};
|
|
27
30
|
export {
|
package/rate/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../chunk-PKUHTIDK.js";
|
|
2
|
-
import { KEY_CODE } from "
|
|
2
|
+
import { KEY_CODE } from "../common";
|
|
3
3
|
const computedActiveColor = (props) => (state) => {
|
|
4
4
|
let result = "";
|
|
5
5
|
if (state.currentValue <= props.lowThreshold) {
|
|
@@ -146,7 +146,9 @@ const computedDecimalStyle = ({ props, state }) => {
|
|
|
146
146
|
let fontSize = "";
|
|
147
147
|
if (props.disabled) {
|
|
148
148
|
width = `${props.modelValue * 100 - Math.floor(props.modelValue) * 100 < 50 ? 0 : 100}%`;
|
|
149
|
-
}
|
|
149
|
+
}
|
|
150
|
+
if (props.allowHalf) {
|
|
151
|
+
width = "";
|
|
150
152
|
const reactSize = props.size ? Math.ceil(parseInt(props.size) / 2) + "px" : "6px";
|
|
151
153
|
clip = `rect(0px, ${reactSize}, ${props.size || "14px"}, 0px)`;
|
|
152
154
|
clipPath = "inset(0 50% 0 0)";
|
package/rate/vue.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
computedActiveColor,
|
|
19
19
|
computedActiveClass
|
|
20
20
|
} from "./index";
|
|
21
|
-
import { on, off } from "
|
|
21
|
+
import { on, off } from "../common/deps/dom";
|
|
22
22
|
const api = ["state", "showDecimalIcon", "getIconStyle", "getTextStyle", "selectValue", "handelKey", "setCurrentValue", "resetCurrentValue"];
|
|
23
23
|
const useChangeValue = ({ constants, emit, props, reactive, toRefs, watch, onMounted, onUnmounted, parent }) => {
|
|
24
24
|
const state = reactive({
|
package/record/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import "../chunk-PKUHTIDK.js";
|
|
2
|
+
class Record {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.recorder = null;
|
|
5
|
+
this.mediaStream = null;
|
|
6
|
+
this.recorderFile = null;
|
|
7
|
+
this.audioContext = null;
|
|
8
|
+
this.timeId = null;
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
start() {
|
|
12
|
+
return this.getUserMedia().then(({ stream }) => {
|
|
13
|
+
if (stream) {
|
|
14
|
+
this.initMideaRecoder(stream);
|
|
15
|
+
this.initAudioContext(stream);
|
|
16
|
+
}
|
|
17
|
+
return !!stream;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
getUserMedia() {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || window.getUserMedia;
|
|
23
|
+
const containers = { audio: true };
|
|
24
|
+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
|
25
|
+
navigator.mediaDevices.getUserMedia(containers).then((stream) => resolve({ stream })).catch(resolve);
|
|
26
|
+
} else if (navigator.getUserMedia) {
|
|
27
|
+
navigator.getUserMedia(containers, (stream) => resolve({ stream }), resolve);
|
|
28
|
+
} else {
|
|
29
|
+
resolve(new Error("Not support userMedia"));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
initMideaRecoder(stream) {
|
|
34
|
+
this.recorder = new MediaRecorder(stream);
|
|
35
|
+
this.mediaStream = stream;
|
|
36
|
+
let chunks = [];
|
|
37
|
+
this.recorder.onpause = () => {
|
|
38
|
+
};
|
|
39
|
+
this.recorder.onresume = () => {
|
|
40
|
+
};
|
|
41
|
+
this.recorder.ondataavailable = (e) => {
|
|
42
|
+
chunks.push(e.data);
|
|
43
|
+
};
|
|
44
|
+
this.recorder.onstop = () => {
|
|
45
|
+
this.recorderFile = new Blob(chunks, { "type": this.recorder.mimeType });
|
|
46
|
+
chunks = [];
|
|
47
|
+
const { onstop } = this.config;
|
|
48
|
+
onstop && onstop(this.recorderFile);
|
|
49
|
+
};
|
|
50
|
+
this.recorder.onerror = () => {
|
|
51
|
+
};
|
|
52
|
+
this.recorder.start();
|
|
53
|
+
}
|
|
54
|
+
stop() {
|
|
55
|
+
if (this.recorder.state !== "inactive") {
|
|
56
|
+
this.recorder.stop();
|
|
57
|
+
this.closeStream(this.mediaStream);
|
|
58
|
+
this.audioContext.close();
|
|
59
|
+
}
|
|
60
|
+
clearInterval(this.timeId);
|
|
61
|
+
this.timeId = null;
|
|
62
|
+
}
|
|
63
|
+
closeStream(stream) {
|
|
64
|
+
if (typeof stream.stop === "function") {
|
|
65
|
+
stream.stop();
|
|
66
|
+
} else {
|
|
67
|
+
let trackList = [stream.getAudioTracks(), stream.getVideoTracks()];
|
|
68
|
+
trackList.forEach(
|
|
69
|
+
(tracks) => tracks && tracks.forEach((track) => typeof track.stop === "function" && track.stop())
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
pause() {
|
|
74
|
+
this.recorder.pause();
|
|
75
|
+
this.audioContext.suspend();
|
|
76
|
+
clearInterval(this.timeId);
|
|
77
|
+
this.timeId = null;
|
|
78
|
+
}
|
|
79
|
+
resume() {
|
|
80
|
+
this.recorder.resume();
|
|
81
|
+
this.audioContext.resume();
|
|
82
|
+
clearInterval(this.timeId);
|
|
83
|
+
this.timeId = setInterval(() => this.getRealTimeAudio(), 100);
|
|
84
|
+
}
|
|
85
|
+
initAudioContext(stream) {
|
|
86
|
+
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
87
|
+
const source = this.audioContext.createMediaStreamSource(stream);
|
|
88
|
+
this.analyser = this.audioContext.createAnalyser();
|
|
89
|
+
source.connect(this.analyser);
|
|
90
|
+
clearInterval(this.timeId);
|
|
91
|
+
this.timeId = setInterval(() => this.getRealTimeAudio(), 100);
|
|
92
|
+
}
|
|
93
|
+
getRealTimeAudio() {
|
|
94
|
+
const { onMediaProgress } = this.config;
|
|
95
|
+
onMediaProgress && onMediaProgress(this.analyser, this.audioContext);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const toogleRecord = ({ state, api, emit, constants }) => () => {
|
|
99
|
+
if (state.record.status === constants.STATUS.READY) {
|
|
100
|
+
!state.recorder && (state.recorder = new Record({
|
|
101
|
+
onMediaProgress: api.renderAudioGraph,
|
|
102
|
+
onstop: (file) => emit("confirm", file)
|
|
103
|
+
}));
|
|
104
|
+
state.recorder.start().then((isSuccess) => {
|
|
105
|
+
if (!isSuccess) {
|
|
106
|
+
return emit("error");
|
|
107
|
+
}
|
|
108
|
+
state.record.status = constants.STATUS.RECORDING;
|
|
109
|
+
});
|
|
110
|
+
} else if (state.record.status === constants.STATUS.PAUSE) {
|
|
111
|
+
state.record.status = constants.STATUS.RECORDING;
|
|
112
|
+
state.recorder.resume();
|
|
113
|
+
} else {
|
|
114
|
+
state.record.status = constants.STATUS.PAUSE;
|
|
115
|
+
state.recorder.pause();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const handleConfirm = ({ state, emit }) => () => {
|
|
119
|
+
state.isClickConfirm = true;
|
|
120
|
+
emit("update:modelValue", false);
|
|
121
|
+
};
|
|
122
|
+
const watchModelValue = ({ api }) => (value) => !value && api.resetRecord();
|
|
123
|
+
const calcVoice = (analyser) => {
|
|
124
|
+
const dataArray = new Uint8Array(analyser.fftSize);
|
|
125
|
+
analyser.getByteTimeDomainData(dataArray);
|
|
126
|
+
let highValue = 0;
|
|
127
|
+
let lowValue = 0;
|
|
128
|
+
for (let i = 0; i < analyser.fftSize; i++) {
|
|
129
|
+
highValue += dataArray[i] > 128 ? dataArray[i] - 128 : 0;
|
|
130
|
+
lowValue += dataArray[i] < 128 ? 128 - dataArray[i] : 0;
|
|
131
|
+
}
|
|
132
|
+
let voiceNum = 1;
|
|
133
|
+
const voiceMatch = [0, 100, 500, 1e3, 1e4];
|
|
134
|
+
const ismatch = voiceMatch.some((val2, idx) => {
|
|
135
|
+
if (highValue <= val2) {
|
|
136
|
+
return voiceNum = idx + 1 + (val2 === 0 ? lowValue / 1e3 : highValue / val2);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
!ismatch && (voiceNum = 6);
|
|
140
|
+
const val = voiceNum * 5;
|
|
141
|
+
let result = [-val, 2 * val, -3 * val];
|
|
142
|
+
return result.concat(
|
|
143
|
+
result.slice().reverse().map((times) => -times)
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
const renderAudioGraph = ({ vm, state }) => (analyser, audioContext) => {
|
|
147
|
+
state.record.currentTime = audioContext.currentTime;
|
|
148
|
+
let canvas = vm.$refs.canvas;
|
|
149
|
+
if (canvas) {
|
|
150
|
+
const height = canvas.offsetHeight;
|
|
151
|
+
const width = canvas.offsetWidth;
|
|
152
|
+
canvas.height = height;
|
|
153
|
+
canvas.width = width;
|
|
154
|
+
const canvasCtx = canvas.getContext("2d");
|
|
155
|
+
canvasCtx.clearRect(0, 0, width, height);
|
|
156
|
+
canvasCtx.fillStyle = "#fff";
|
|
157
|
+
canvasCtx.fillRect(0, 0, width, height);
|
|
158
|
+
canvasCtx.lineWidth = 1;
|
|
159
|
+
const grd = canvasCtx.createLinearGradient(0, 0, width, 0);
|
|
160
|
+
grd.addColorStop(0, "rgba(0, 103, 209, 0.1)");
|
|
161
|
+
grd.addColorStop(0.5, "rgba(0, 103, 209, 1)");
|
|
162
|
+
grd.addColorStop(1, "rgba(0, 103, 209, 0.1)");
|
|
163
|
+
canvasCtx.strokeStyle = grd;
|
|
164
|
+
let x = 0;
|
|
165
|
+
canvasCtx.beginPath();
|
|
166
|
+
canvasCtx.moveTo(x, height / 2);
|
|
167
|
+
const tops = calcVoice(analyser);
|
|
168
|
+
const space = width / 12;
|
|
169
|
+
for (let j = 0; j < 6; j++) {
|
|
170
|
+
canvasCtx.quadraticCurveTo(x += space, height / 2 - tops[j], x += space, height / 2);
|
|
171
|
+
}
|
|
172
|
+
canvasCtx.lineTo(width, height / 2);
|
|
173
|
+
canvasCtx.stroke();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const resetRecord = ({ state, constants }) => () => {
|
|
177
|
+
state.record.status = constants.STATUS.READY;
|
|
178
|
+
state.record.currentTime = 0;
|
|
179
|
+
state.isClickConfirm && state.recorder && state.recorder.stop();
|
|
180
|
+
state.isClickConfirm = false;
|
|
181
|
+
};
|
|
182
|
+
const unmounted = ({ api }) => () => api.resetRecord();
|
|
183
|
+
export {
|
|
184
|
+
handleConfirm,
|
|
185
|
+
renderAudioGraph,
|
|
186
|
+
resetRecord,
|
|
187
|
+
toogleRecord,
|
|
188
|
+
unmounted,
|
|
189
|
+
watchModelValue
|
|
190
|
+
};
|
package/record/vue.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "../chunk-PKUHTIDK.js";
|
|
2
|
+
import { toogleRecord, handleConfirm, watchModelValue, renderAudioGraph, unmounted, resetRecord } from "./index";
|
|
3
|
+
const api = ["state", "toogleRecord", "handleConfirm"];
|
|
4
|
+
const initState = ({ api: api2, reactive, computed }) => {
|
|
5
|
+
const state = reactive({
|
|
6
|
+
record: {
|
|
7
|
+
status: "ready",
|
|
8
|
+
currentTime: 0
|
|
9
|
+
},
|
|
10
|
+
recodeTime: computed(() => {
|
|
11
|
+
const time = parseInt(state.record.currentTime);
|
|
12
|
+
const minute = Math.floor(time / 60);
|
|
13
|
+
const second = Math.floor(time % 60);
|
|
14
|
+
return `${minute.toString().padStart(2, 0)}:${second.toString().padStart(2, 0)}`;
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
Object.assign(api2, { state });
|
|
18
|
+
return state;
|
|
19
|
+
};
|
|
20
|
+
const initApi = ({ api: api2, state, emit, vm, constants }) => {
|
|
21
|
+
Object.assign(api2, {
|
|
22
|
+
toogleRecord: toogleRecord({ state, api: api2, emit, constants }),
|
|
23
|
+
handleConfirm: handleConfirm({ state, emit }),
|
|
24
|
+
watchModelValue: watchModelValue({ api: api2 }),
|
|
25
|
+
renderAudioGraph: renderAudioGraph({ vm, state }),
|
|
26
|
+
unmounted: unmounted({ api: api2 }),
|
|
27
|
+
resetRecord: resetRecord({ state, constants })
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const initWatch = ({ watch, props, api: api2 }) => {
|
|
31
|
+
watch(() => props.modelValue, api2.watchModelValue, { immediate: true });
|
|
32
|
+
};
|
|
33
|
+
const renderless = (props, { reactive, watch, computed, onUnmounted }, { emit, vm, constants }) => {
|
|
34
|
+
const api2 = {};
|
|
35
|
+
const state = initState({ api: api2, reactive, computed });
|
|
36
|
+
initApi({ api: api2, state, emit, vm, constants });
|
|
37
|
+
initWatch({ watch, props, api: api2 });
|
|
38
|
+
onUnmounted(() => api2.unmounted);
|
|
39
|
+
return api2;
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
api,
|
|
43
|
+
renderless
|
|
44
|
+
};
|