react-audio-wavekit 0.1.3 → 0.1.4

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.
@@ -90,14 +90,55 @@ const WaveformRenderer = react.forwardRef(function WaveformRenderer2({ peaks, ap
90
90
  },
91
91
  [onSeek, duration]
92
92
  );
93
+ const handleKeyDown = react.useCallback(
94
+ (e) => {
95
+ if (!onSeek || !duration || duration <= 0) return;
96
+ const SEEK_STEP = 5;
97
+ const current = currentTime ?? 0;
98
+ switch (e.key) {
99
+ case "ArrowLeft":
100
+ e.preventDefault();
101
+ onSeek(Math.max(0, current - SEEK_STEP));
102
+ break;
103
+ case "ArrowRight":
104
+ e.preventDefault();
105
+ onSeek(Math.min(duration, current + SEEK_STEP));
106
+ break;
107
+ case "Home":
108
+ e.preventDefault();
109
+ onSeek(0);
110
+ break;
111
+ case "End":
112
+ e.preventDefault();
113
+ onSeek(duration);
114
+ break;
115
+ }
116
+ },
117
+ [onSeek, duration, currentTime]
118
+ );
119
+ const formatTimeForScreen = (seconds) => {
120
+ const mins = Math.floor(seconds / 60);
121
+ const secs = Math.floor(seconds % 60);
122
+ if (mins > 0) {
123
+ return `${mins}분 ${secs}초`;
124
+ }
125
+ return `${secs}초`;
126
+ };
127
+ const isInteractive = !!onSeek && !!duration && duration > 0;
93
128
  return /* @__PURE__ */ jsxRuntime.jsx(
94
129
  "canvas",
95
130
  {
96
131
  ref: canvasRef,
97
- role: "img",
98
- "aria-label": "Audio waveform",
132
+ role: isInteractive ? "slider" : "img",
133
+ "aria-label": isInteractive ? "오디오 탐색" : "오디오 파형",
134
+ "aria-valuemin": isInteractive ? 0 : void 0,
135
+ "aria-valuemax": isInteractive ? Math.floor(duration) : void 0,
136
+ "aria-valuenow": isInteractive ? Math.floor(currentTime ?? 0) : void 0,
137
+ "aria-valuetext": isInteractive ? `${formatTimeForScreen(currentTime ?? 0)} / ${formatTimeForScreen(duration)}` : void 0,
138
+ tabIndex: isInteractive ? 0 : -1,
99
139
  onClick: handleClick,
100
- style: { cursor: onSeek ? "pointer" : void 0, ...style },
140
+ onKeyDown: isInteractive ? handleKeyDown : void 0,
141
+ style: { cursor: isInteractive ? "pointer" : void 0, ...style },
101
142
  ...props
102
143
  }
103
144
  );
@@ -88,14 +88,55 @@ const WaveformRenderer = forwardRef(function WaveformRenderer2({ peaks, appearan
88
88
  },
89
89
  [onSeek, duration]
90
90
  );
91
+ const handleKeyDown = useCallback(
92
+ (e) => {
93
+ if (!onSeek || !duration || duration <= 0) return;
94
+ const SEEK_STEP = 5;
95
+ const current = currentTime ?? 0;
96
+ switch (e.key) {
97
+ case "ArrowLeft":
98
+ e.preventDefault();
99
+ onSeek(Math.max(0, current - SEEK_STEP));
100
+ break;
101
+ case "ArrowRight":
102
+ e.preventDefault();
103
+ onSeek(Math.min(duration, current + SEEK_STEP));
104
+ break;
105
+ case "Home":
106
+ e.preventDefault();
107
+ onSeek(0);
108
+ break;
109
+ case "End":
110
+ e.preventDefault();
111
+ onSeek(duration);
112
+ break;
113
+ }
114
+ },
115
+ [onSeek, duration, currentTime]
116
+ );
117
+ const formatTimeForScreen = (seconds) => {
118
+ const mins = Math.floor(seconds / 60);
119
+ const secs = Math.floor(seconds % 60);
120
+ if (mins > 0) {
121
+ return `${mins}분 ${secs}초`;
122
+ }
123
+ return `${secs}초`;
124
+ };
125
+ const isInteractive = !!onSeek && !!duration && duration > 0;
91
126
  return /* @__PURE__ */ jsx(
92
127
  "canvas",
93
128
  {
94
129
  ref: canvasRef,
95
- role: "img",
96
- "aria-label": "Audio waveform",
130
+ role: isInteractive ? "slider" : "img",
131
+ "aria-label": isInteractive ? "오디오 탐색" : "오디오 파형",
132
+ "aria-valuemin": isInteractive ? 0 : void 0,
133
+ "aria-valuemax": isInteractive ? Math.floor(duration) : void 0,
134
+ "aria-valuenow": isInteractive ? Math.floor(currentTime ?? 0) : void 0,
135
+ "aria-valuetext": isInteractive ? `${formatTimeForScreen(currentTime ?? 0)} / ${formatTimeForScreen(duration)}` : void 0,
136
+ tabIndex: isInteractive ? 0 : -1,
97
137
  onClick: handleClick,
98
- style: { cursor: onSeek ? "pointer" : void 0, ...style },
138
+ onKeyDown: isInteractive ? handleKeyDown : void 0,
139
+ style: { cursor: isInteractive ? "pointer" : void 0, ...style },
99
140
  ...props
100
141
  }
101
142
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-audio-wavekit",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "license": "CC0-1.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",