@easy-editor/materials-dashboard-audio 0.0.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/.vite/plugins/vite-plugin-external-deps.ts +224 -0
- package/.vite/plugins/vite-plugin-material-dev.ts +218 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +9 -0
- package/dist/component.esm.js +165 -0
- package/dist/component.esm.js.map +1 -0
- package/dist/component.js +173 -0
- package/dist/component.js.map +1 -0
- package/dist/component.min.js +2 -0
- package/dist/component.min.js.map +1 -0
- package/dist/index.cjs +456 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +453 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +460 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/meta.esm.js +292 -0
- package/dist/meta.esm.js.map +1 -0
- package/dist/meta.js +303 -0
- package/dist/meta.js.map +1 -0
- package/dist/meta.min.js +2 -0
- package/dist/meta.min.js.map +1 -0
- package/dist/src/component.d.ts +23 -0
- package/dist/src/configure.d.ts +7 -0
- package/dist/src/constants.d.ts +16 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/meta.d.ts +7 -0
- package/dist/src/snippets.d.ts +7 -0
- package/package.json +68 -0
- package/rollup.config.js +222 -0
- package/src/component.module.css +104 -0
- package/src/component.tsx +140 -0
- package/src/configure.ts +247 -0
- package/src/constants.ts +18 -0
- package/src/index.tsx +7 -0
- package/src/meta.ts +28 -0
- package/src/snippets.ts +50 -0
- package/src/type.d.ts +8 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +9 -0
- package/tsconfig.test.json +7 -0
- package/vite.config.ts +54 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/* @easy-editor/materials-dashboard-image v0.0.1 (component) */
|
|
2
|
+
(function (global, factory) {
|
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react/jsx-runtime')) :
|
|
4
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react/jsx-runtime'], factory) :
|
|
5
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.EasyEditorMaterialsAudioComponent = {}, global.React, global.jsxRuntime));
|
|
6
|
+
})(this, (function (exports, react, jsxRuntime) { 'use strict';
|
|
7
|
+
|
|
8
|
+
function styleInject(css, ref) {
|
|
9
|
+
if (ref === void 0) ref = {};
|
|
10
|
+
var insertAt = ref.insertAt;
|
|
11
|
+
if (typeof document === 'undefined') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
15
|
+
var style = document.createElement('style');
|
|
16
|
+
style.type = 'text/css';
|
|
17
|
+
if (insertAt === 'top') {
|
|
18
|
+
if (head.firstChild) {
|
|
19
|
+
head.insertBefore(style, head.firstChild);
|
|
20
|
+
} else {
|
|
21
|
+
head.appendChild(style);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
head.appendChild(style);
|
|
25
|
+
}
|
|
26
|
+
if (style.styleSheet) {
|
|
27
|
+
style.styleSheet.cssText = css;
|
|
28
|
+
} else {
|
|
29
|
+
style.appendChild(document.createTextNode(css));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var css_248z = ".component-module__container___VbZSk{align-items:center;background:rgba(10,10,26,.95);border:1px solid rgba(26,26,62,.8);border-radius:8px;display:flex;gap:12px;height:100%;padding:12px 16px;width:100%}.component-module__playButton___M6QVA{align-items:center;background:linear-gradient(135deg,#00d4ff,#9b59b6);border:none;border-radius:50%;cursor:pointer;display:flex;flex-shrink:0;height:40px;justify-content:center;transition:transform .2s ease;width:40px}.component-module__playButton___M6QVA:hover{transform:scale(1.05)}.component-module__playIcon___t8-WV{border-bottom:8px solid transparent;border-left:12px solid #fff;border-top:8px solid transparent;height:0;margin-left:3px;width:0}.component-module__pauseIcon___8XmSk{display:flex;gap:3px}.component-module__pauseBar___eM6DG{background:#fff;border-radius:2px;height:14px;width:4px}.component-module__info___VyTlr{flex:1;min-width:0}.component-module__title___Hj54k{color:#e6e6e6;font-size:14px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.component-module__progressContainer___HvygE{align-items:center;display:flex;gap:8px;margin-top:4px}.component-module__progressBar___wROZC{background:rgba(26,26,62,.8);border-radius:2px;cursor:pointer;flex:1;height:4px;overflow:hidden}.component-module__progressFill___F8n5d{background:linear-gradient(90deg,#00d4ff,#9b59b6);border-radius:2px;height:100%;transition:width .1s linear}.component-module__time___-5GMu{color:hsla(0,0%,100%,.6);font-family:Courier New,Courier,monospace;font-size:12px;min-width:80px;text-align:right}.component-module__nativeAudio___vCo17{width:100%}";
|
|
34
|
+
var styles = {"container":"component-module__container___VbZSk","playButton":"component-module__playButton___M6QVA","playIcon":"component-module__playIcon___t8-WV","pauseIcon":"component-module__pauseIcon___8XmSk","pauseBar":"component-module__pauseBar___eM6DG","info":"component-module__info___VyTlr","title":"component-module__title___Hj54k","progressContainer":"component-module__progressContainer___HvygE","progressBar":"component-module__progressBar___wROZC","progressFill":"component-module__progressFill___F8n5d","time":"component-module__time___-5GMu","nativeAudio":"component-module__nativeAudio___vCo17"};
|
|
35
|
+
styleInject(css_248z);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Audio Component
|
|
39
|
+
* 音频播放组件
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
const formatTime = seconds => {
|
|
43
|
+
const mins = Math.floor(seconds / 60);
|
|
44
|
+
const secs = Math.floor(seconds % 60);
|
|
45
|
+
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
46
|
+
};
|
|
47
|
+
const Audio = ({
|
|
48
|
+
ref,
|
|
49
|
+
src = '',
|
|
50
|
+
title = '音频文件',
|
|
51
|
+
autoPlay = false,
|
|
52
|
+
loop = false,
|
|
53
|
+
audioStyle = 'custom',
|
|
54
|
+
style: externalStyle
|
|
55
|
+
}) => {
|
|
56
|
+
const audioRef = react.useRef(null);
|
|
57
|
+
const [isPlaying, setIsPlaying] = react.useState(false);
|
|
58
|
+
const [currentTime, setCurrentTime] = react.useState(0);
|
|
59
|
+
const [duration, setDuration] = react.useState(0);
|
|
60
|
+
react.useEffect(() => {
|
|
61
|
+
const audio = audioRef.current;
|
|
62
|
+
if (!audio) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const handleTimeUpdate = () => setCurrentTime(audio.currentTime);
|
|
66
|
+
const handleLoadedMetadata = () => setDuration(audio.duration);
|
|
67
|
+
const handleEnded = () => setIsPlaying(false);
|
|
68
|
+
audio.addEventListener('timeupdate', handleTimeUpdate);
|
|
69
|
+
audio.addEventListener('loadedmetadata', handleLoadedMetadata);
|
|
70
|
+
audio.addEventListener('ended', handleEnded);
|
|
71
|
+
return () => {
|
|
72
|
+
audio.removeEventListener('timeupdate', handleTimeUpdate);
|
|
73
|
+
audio.removeEventListener('loadedmetadata', handleLoadedMetadata);
|
|
74
|
+
audio.removeEventListener('ended', handleEnded);
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
77
|
+
const togglePlay = () => {
|
|
78
|
+
if (audioRef.current) {
|
|
79
|
+
if (isPlaying) {
|
|
80
|
+
audioRef.current.pause();
|
|
81
|
+
} else {
|
|
82
|
+
audioRef.current.play();
|
|
83
|
+
}
|
|
84
|
+
setIsPlaying(!isPlaying);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const handleProgressClick = e => {
|
|
88
|
+
if (audioRef.current && duration) {
|
|
89
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
90
|
+
const percent = (e.clientX - rect.left) / rect.width;
|
|
91
|
+
audioRef.current.currentTime = percent * duration;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const progress = duration ? currentTime / duration * 100 : 0;
|
|
95
|
+
|
|
96
|
+
// 原生样式
|
|
97
|
+
if (audioStyle === 'native') {
|
|
98
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
99
|
+
className: styles.container,
|
|
100
|
+
ref: ref,
|
|
101
|
+
style: externalStyle,
|
|
102
|
+
children: /*#__PURE__*/jsxRuntime.jsx("audio", {
|
|
103
|
+
autoPlay: autoPlay,
|
|
104
|
+
className: styles.nativeAudio,
|
|
105
|
+
controls: true,
|
|
106
|
+
loop: loop,
|
|
107
|
+
ref: audioRef,
|
|
108
|
+
src: src
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 自定义样式
|
|
114
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
115
|
+
className: styles.container,
|
|
116
|
+
ref: ref,
|
|
117
|
+
style: externalStyle,
|
|
118
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("audio", {
|
|
119
|
+
autoPlay: autoPlay,
|
|
120
|
+
loop: loop,
|
|
121
|
+
ref: audioRef,
|
|
122
|
+
src: src
|
|
123
|
+
}), /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
124
|
+
"aria-label": isPlaying ? 'Pause' : 'Play',
|
|
125
|
+
className: styles.playButton,
|
|
126
|
+
onClick: togglePlay,
|
|
127
|
+
type: "button",
|
|
128
|
+
children: isPlaying ? /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
129
|
+
className: styles.pauseIcon,
|
|
130
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
131
|
+
className: styles.pauseBar
|
|
132
|
+
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
133
|
+
className: styles.pauseBar
|
|
134
|
+
})]
|
|
135
|
+
}) : /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
136
|
+
className: styles.playIcon
|
|
137
|
+
})
|
|
138
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
139
|
+
className: styles.info,
|
|
140
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
141
|
+
className: styles.title,
|
|
142
|
+
children: title
|
|
143
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
144
|
+
className: styles.progressContainer,
|
|
145
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("button", {
|
|
146
|
+
"aria-label": "Seek to position",
|
|
147
|
+
className: styles.progressBar
|
|
148
|
+
// @ts-expect-error
|
|
149
|
+
,
|
|
150
|
+
onClick: handleProgressClick,
|
|
151
|
+
type: "button",
|
|
152
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
153
|
+
className: styles.progressFill,
|
|
154
|
+
style: {
|
|
155
|
+
width: `${progress}%`
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
159
|
+
className: styles.time,
|
|
160
|
+
children: [formatTime(currentTime), " / ", formatTime(duration || 0)]
|
|
161
|
+
})]
|
|
162
|
+
})]
|
|
163
|
+
})]
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
exports.Audio = Audio;
|
|
168
|
+
exports.default = Audio;
|
|
169
|
+
|
|
170
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
171
|
+
|
|
172
|
+
}));
|
|
173
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/component.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","/**\n * Audio Component\n * 音频播放组件\n */\n\nimport { useState, useRef, useEffect, type CSSProperties, type Ref } from 'react'\nimport styles from './component.module.css'\n\nexport type AudioStyle = 'custom' | 'native'\n\nexport interface AudioProps {\n ref?: Ref<HTMLDivElement>\n /** 音频地址 */\n src?: string\n /** 标题 */\n title?: string\n /** 自动播放 */\n autoPlay?: boolean\n /** 循环播放 */\n loop?: boolean\n /** 样式类型 */\n audioStyle?: AudioStyle\n /** 外部样式 */\n style?: CSSProperties\n}\n\nconst formatTime = (seconds: number): string => {\n const mins = Math.floor(seconds / 60)\n const secs = Math.floor(seconds % 60)\n return `${mins}:${secs.toString().padStart(2, '0')}`\n}\n\nexport const Audio: React.FC<AudioProps> = ({\n ref,\n src = '',\n title = '音频文件',\n autoPlay = false,\n loop = false,\n audioStyle = 'custom',\n style: externalStyle,\n}) => {\n const audioRef = useRef<HTMLAudioElement>(null)\n const [isPlaying, setIsPlaying] = useState(false)\n const [currentTime, setCurrentTime] = useState(0)\n const [duration, setDuration] = useState(0)\n\n useEffect(() => {\n const audio = audioRef.current\n if (!audio) {\n return\n }\n\n const handleTimeUpdate = () => setCurrentTime(audio.currentTime)\n const handleLoadedMetadata = () => setDuration(audio.duration)\n const handleEnded = () => setIsPlaying(false)\n\n audio.addEventListener('timeupdate', handleTimeUpdate)\n audio.addEventListener('loadedmetadata', handleLoadedMetadata)\n audio.addEventListener('ended', handleEnded)\n\n return () => {\n audio.removeEventListener('timeupdate', handleTimeUpdate)\n audio.removeEventListener('loadedmetadata', handleLoadedMetadata)\n audio.removeEventListener('ended', handleEnded)\n }\n }, [])\n\n const togglePlay = () => {\n if (audioRef.current) {\n if (isPlaying) {\n audioRef.current.pause()\n } else {\n audioRef.current.play()\n }\n setIsPlaying(!isPlaying)\n }\n }\n\n const handleProgressClick = (e: React.MouseEvent<HTMLDivElement>) => {\n if (audioRef.current && duration) {\n const rect = e.currentTarget.getBoundingClientRect()\n const percent = (e.clientX - rect.left) / rect.width\n audioRef.current.currentTime = percent * duration\n }\n }\n\n const progress = duration ? (currentTime / duration) * 100 : 0\n\n // 原生样式\n if (audioStyle === 'native') {\n return (\n <div className={styles.container} ref={ref} style={externalStyle}>\n <audio autoPlay={autoPlay} className={styles.nativeAudio} controls loop={loop} ref={audioRef} src={src} />\n </div>\n )\n }\n\n // 自定义样式\n return (\n <div className={styles.container} ref={ref} style={externalStyle}>\n <audio autoPlay={autoPlay} loop={loop} ref={audioRef} src={src} />\n\n <button\n aria-label={isPlaying ? 'Pause' : 'Play'}\n className={styles.playButton}\n onClick={togglePlay}\n type='button'\n >\n {isPlaying ? (\n <div className={styles.pauseIcon}>\n <div className={styles.pauseBar} />\n <div className={styles.pauseBar} />\n </div>\n ) : (\n <div className={styles.playIcon} />\n )}\n </button>\n\n <div className={styles.info}>\n <div className={styles.title}>{title}</div>\n <div className={styles.progressContainer}>\n <button\n aria-label='Seek to position'\n className={styles.progressBar}\n // @ts-expect-error\n onClick={handleProgressClick}\n type='button'\n >\n <div className={styles.progressFill} style={{ width: `${progress}%` }} />\n </button>\n <span className={styles.time}>\n {formatTime(currentTime)} / {formatTime(duration || 0)}\n </span>\n </div>\n </div>\n </div>\n )\n}\n\nexport default Audio\n"],"names":["styleInject","css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","formatTime","seconds","mins","Math","floor","secs","toString","padStart","Audio","src","title","autoPlay","loop","audioStyle","externalStyle","audioRef","useRef","isPlaying","setIsPlaying","useState","currentTime","setCurrentTime","duration","setDuration","useEffect","audio","current","handleTimeUpdate","handleLoadedMetadata","handleEnded","addEventListener","removeEventListener","togglePlay","pause","play","handleProgressClick","e","rect","currentTarget","getBoundingClientRect","percent","clientX","left","width","progress","_jsx","className","styles","container","children","nativeAudio","controls","_jsxs","playButton","onClick","pauseIcon","pauseBar","playIcon","info","progressContainer","progressBar","progressFill","time"],"mappings":";;;;;;;EAAA,SAASA,WAA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AA,EAAA;QAAKN,SAAS,EAAEC,MAAM,CAACW,IAAK;EAAAT,MAAAA,QAAA,gBAC1BJ,cAAA,CAAA,KAAA,EAAA;UAAKC,SAAS,EAAEC,MAAM,CAACrC,KAAM;EAAAuC,QAAAA,QAAA,EAAEvC;SAAW,CAAC,eAC3C0C,eAAA,CAAA,KAAA,EAAA;UAAKN,SAAS,EAAEC,MAAM,CAACY,iBAAkB;EAAAV,QAAAA,QAAA,gBACvCJ,cAAA,CAAA,QAAA,EAAA;EACE,UAAA,YAAA,EAAW,kBAAkB;YAC7BC,SAAS,EAAEC,MAAM,CAACa;EAClB;EAAA;EACAN,UAAAA,OAAO,EAAEnB,mBAAoB;EAC7B1C,UAAAA,IAAI,EAAC,QAAQ;EAAAwD,UAAAA,QAAA,eAEbJ,cAAA,CAAA,KAAA,EAAA;cAAKC,SAAS,EAAEC,MAAM,CAACc,YAAa;EAACtE,YAAAA,KAAK,EAAE;gBAAEoD,KAAK,EAAE,GAAGC,QAAQ,CAAA,CAAA;EAAI;aAAI;WAClE,CAAC,eACTQ,eAAA,CAAA,MAAA,EAAA;YAAMN,SAAS,EAAEC,MAAM,CAACe,IAAK;EAAAb,UAAAA,QAAA,EAAA,CAC1BjD,UAAU,CAACoB,WAAW,CAAC,EAAC,KAAG,EAACpB,UAAU,CAACsB,QAAQ,IAAI,CAAC,CAAC;EAAA,SAClD,CAAC;EAAA,OACJ,CAAC;EAAA,KACH,CAAC;EAAA,GACH,CAAC;EAEV;;;;;;;;;;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react/jsx-runtime")):"function"==typeof define&&define.amd?define(["exports","react","react/jsx-runtime"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EasyEditorMaterialsAudioComponent={},e.React,e.jsxRuntime)}(this,function(e,t,o){"use strict";var n="component-module__container___VbZSk",r="component-module__playButton___M6QVA",i="component-module__playIcon___t8-WV",a="component-module__pauseIcon___8XmSk",s="component-module__pauseBar___eM6DG",d="component-module__info___VyTlr",l="component-module__title___Hj54k",_="component-module__progressContainer___HvygE",c="component-module__progressBar___wROZC",u="component-module__progressFill___F8n5d",p="component-module__time___-5GMu",m="component-module__nativeAudio___vCo17";!function(e,t){void 0===t&&(t={});var o=t.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===o&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}}(".component-module__container___VbZSk{align-items:center;background:rgba(10,10,26,.95);border:1px solid rgba(26,26,62,.8);border-radius:8px;display:flex;gap:12px;height:100%;padding:12px 16px;width:100%}.component-module__playButton___M6QVA{align-items:center;background:linear-gradient(135deg,#00d4ff,#9b59b6);border:none;border-radius:50%;cursor:pointer;display:flex;flex-shrink:0;height:40px;justify-content:center;transition:transform .2s ease;width:40px}.component-module__playButton___M6QVA:hover{transform:scale(1.05)}.component-module__playIcon___t8-WV{border-bottom:8px solid transparent;border-left:12px solid #fff;border-top:8px solid transparent;height:0;margin-left:3px;width:0}.component-module__pauseIcon___8XmSk{display:flex;gap:3px}.component-module__pauseBar___eM6DG{background:#fff;border-radius:2px;height:14px;width:4px}.component-module__info___VyTlr{flex:1;min-width:0}.component-module__title___Hj54k{color:#e6e6e6;font-size:14px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.component-module__progressContainer___HvygE{align-items:center;display:flex;gap:8px;margin-top:4px}.component-module__progressBar___wROZC{background:rgba(26,26,62,.8);border-radius:2px;cursor:pointer;flex:1;height:4px;overflow:hidden}.component-module__progressFill___F8n5d{background:linear-gradient(90deg,#00d4ff,#9b59b6);border-radius:2px;height:100%;transition:width .1s linear}.component-module__time___-5GMu{color:hsla(0,0%,100%,.6);font-family:Courier New,Courier,monospace;font-size:12px;min-width:80px;text-align:right}.component-module__nativeAudio___vCo17{width:100%}");const f=e=>`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,"0")}`,x=({ref:e,src:x="",title:h="音频文件",autoPlay:g=!1,loop:y=!1,audioStyle:b="custom",style:v})=>{const j=t.useRef(null),[w,N]=t.useState(!1),[C,k]=t.useState(0),[E,S]=t.useState(0);t.useEffect(()=>{const e=j.current;if(!e)return;const t=()=>k(e.currentTime),o=()=>S(e.duration),n=()=>N(!1);return e.addEventListener("timeupdate",t),e.addEventListener("loadedmetadata",o),e.addEventListener("ended",n),()=>{e.removeEventListener("timeupdate",t),e.removeEventListener("loadedmetadata",o),e.removeEventListener("ended",n)}},[]);const M=E?C/E*100:0;return"native"===b?o.jsx("div",{className:n,ref:e,style:v,children:o.jsx("audio",{autoPlay:g,className:m,controls:!0,loop:y,ref:j,src:x})}):o.jsxs("div",{className:n,ref:e,style:v,children:[o.jsx("audio",{autoPlay:g,loop:y,ref:j,src:x}),o.jsx("button",{"aria-label":w?"Pause":"Play",className:r,onClick:()=>{j.current&&(w?j.current.pause():j.current.play(),N(!w))},type:"button",children:w?o.jsxs("div",{className:a,children:[o.jsx("div",{className:s}),o.jsx("div",{className:s})]}):o.jsx("div",{className:i})}),o.jsxs("div",{className:d,children:[o.jsx("div",{className:l,children:h}),o.jsxs("div",{className:_,children:[o.jsx("button",{"aria-label":"Seek to position",className:c,onClick:e=>{if(j.current&&E){const t=e.currentTarget.getBoundingClientRect(),o=(e.clientX-t.left)/t.width;j.current.currentTime=o*E}},type:"button",children:o.jsx("div",{className:u,style:{width:`${M}%`}})}),o.jsxs("span",{className:p,children:[f(C)," / ",f(E||0)]})]})]})]})};e.Audio=x,e.default=x,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
|
+
//# sourceMappingURL=component.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.min.js","sources":["../../../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/component.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","/**\n * Audio Component\n * 音频播放组件\n */\n\nimport { useState, useRef, useEffect, type CSSProperties, type Ref } from 'react'\nimport styles from './component.module.css'\n\nexport type AudioStyle = 'custom' | 'native'\n\nexport interface AudioProps {\n ref?: Ref<HTMLDivElement>\n /** 音频地址 */\n src?: string\n /** 标题 */\n title?: string\n /** 自动播放 */\n autoPlay?: boolean\n /** 循环播放 */\n loop?: boolean\n /** 样式类型 */\n audioStyle?: AudioStyle\n /** 外部样式 */\n style?: CSSProperties\n}\n\nconst formatTime = (seconds: number): string => {\n const mins = Math.floor(seconds / 60)\n const secs = Math.floor(seconds % 60)\n return `${mins}:${secs.toString().padStart(2, '0')}`\n}\n\nexport const Audio: React.FC<AudioProps> = ({\n ref,\n src = '',\n title = '音频文件',\n autoPlay = false,\n loop = false,\n audioStyle = 'custom',\n style: externalStyle,\n}) => {\n const audioRef = useRef<HTMLAudioElement>(null)\n const [isPlaying, setIsPlaying] = useState(false)\n const [currentTime, setCurrentTime] = useState(0)\n const [duration, setDuration] = useState(0)\n\n useEffect(() => {\n const audio = audioRef.current\n if (!audio) {\n return\n }\n\n const handleTimeUpdate = () => setCurrentTime(audio.currentTime)\n const handleLoadedMetadata = () => setDuration(audio.duration)\n const handleEnded = () => setIsPlaying(false)\n\n audio.addEventListener('timeupdate', handleTimeUpdate)\n audio.addEventListener('loadedmetadata', handleLoadedMetadata)\n audio.addEventListener('ended', handleEnded)\n\n return () => {\n audio.removeEventListener('timeupdate', handleTimeUpdate)\n audio.removeEventListener('loadedmetadata', handleLoadedMetadata)\n audio.removeEventListener('ended', handleEnded)\n }\n }, [])\n\n const togglePlay = () => {\n if (audioRef.current) {\n if (isPlaying) {\n audioRef.current.pause()\n } else {\n audioRef.current.play()\n }\n setIsPlaying(!isPlaying)\n }\n }\n\n const handleProgressClick = (e: React.MouseEvent<HTMLDivElement>) => {\n if (audioRef.current && duration) {\n const rect = e.currentTarget.getBoundingClientRect()\n const percent = (e.clientX - rect.left) / rect.width\n audioRef.current.currentTime = percent * duration\n }\n }\n\n const progress = duration ? (currentTime / duration) * 100 : 0\n\n // 原生样式\n if (audioStyle === 'native') {\n return (\n <div className={styles.container} ref={ref} style={externalStyle}>\n <audio autoPlay={autoPlay} className={styles.nativeAudio} controls loop={loop} ref={audioRef} src={src} />\n </div>\n )\n }\n\n // 自定义样式\n return (\n <div className={styles.container} ref={ref} style={externalStyle}>\n <audio autoPlay={autoPlay} loop={loop} ref={audioRef} src={src} />\n\n <button\n aria-label={isPlaying ? 'Pause' : 'Play'}\n className={styles.playButton}\n onClick={togglePlay}\n type='button'\n >\n {isPlaying ? (\n <div className={styles.pauseIcon}>\n <div className={styles.pauseBar} />\n <div className={styles.pauseBar} />\n </div>\n ) : (\n <div className={styles.playIcon} />\n )}\n </button>\n\n <div className={styles.info}>\n <div className={styles.title}>{title}</div>\n <div className={styles.progressContainer}>\n <button\n aria-label='Seek to position'\n className={styles.progressBar}\n // @ts-expect-error\n onClick={handleProgressClick}\n type='button'\n >\n <div className={styles.progressFill} style={{ width: `${progress}%` }} />\n </button>\n <span className={styles.time}>\n {formatTime(currentTime)} / {formatTime(duration || 0)}\n </span>\n </div>\n </div>\n </div>\n )\n}\n\nexport default Audio\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","formatTime","seconds","Math","floor","toString","padStart","Audio","src","title","autoPlay","loop","audioStyle","externalStyle","audioRef","useRef","isPlaying","setIsPlaying","useState","currentTime","setCurrentTime","duration","setDuration","useEffect","audio","current","handleTimeUpdate","handleLoadedMetadata","handleEnded","addEventListener","removeEventListener","progress","_jsx","className","styles","children","controls","_jsxs","onClick","togglePlay","pause","play","e","rect","currentTarget","getBoundingClientRect","percent","clientX","left","width"],"mappings":"g1BAAA,SAAqBA,EAAKC,QACX,IAARA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,4kDCCA,MAAMe,EAAcC,GAGX,GAFMC,KAAKC,MAAMF,EAAU,OACrBC,KAAKC,MAAMF,EAAU,IACXG,WAAWC,SAAS,EAAG,OAGnCC,EAA8BA,EACzCpB,MACAqB,MAAM,GACNC,QAAQ,OACRC,YAAW,EACXC,QAAO,EACPC,aAAa,SACbpB,MAAOqB,MAEP,MAAMC,EAAWC,EAAAA,OAAyB,OACnCC,EAAWC,GAAgBC,EAAAA,UAAS,IACpCC,EAAaC,GAAkBF,EAAAA,SAAS,IACxCG,EAAUC,GAAeJ,EAAAA,SAAS,GAEzCK,EAAAA,UAAU,KACR,MAAMC,EAAQV,EAASW,QACvB,IAAKD,EACH,OAGF,MAAME,EAAmBA,IAAMN,EAAeI,EAAML,aAC9CQ,EAAuBA,IAAML,EAAYE,EAAMH,UAC/CO,EAAcA,IAAMX,GAAa,GAMvC,OAJAO,EAAMK,iBAAiB,aAAcH,GACrCF,EAAMK,iBAAiB,iBAAkBF,GACzCH,EAA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