wavesurfer.js 6.5.1 → 7.0.0-alpha.0

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.
Files changed (132) hide show
  1. package/.eslintrc.json +24 -0
  2. package/.prettierrc +8 -0
  3. package/README.md +26 -117
  4. package/dist/base-plugin.d.ts +10 -0
  5. package/dist/base-plugin.js +13 -0
  6. package/dist/decoder.d.ts +10 -0
  7. package/dist/decoder.js +43 -0
  8. package/dist/event-emitter.d.ts +11 -0
  9. package/dist/event-emitter.js +21 -0
  10. package/dist/fetcher.d.ts +4 -0
  11. package/dist/fetcher.js +17 -0
  12. package/dist/index.d.ts +92 -0
  13. package/dist/index.js +166 -0
  14. package/dist/player-webaudio.d.ts +8 -0
  15. package/dist/player-webaudio.js +31 -0
  16. package/dist/player.d.ts +16 -0
  17. package/dist/player.js +40 -0
  18. package/dist/plugins/regions.d.ts +48 -0
  19. package/dist/plugins/regions.js +183 -0
  20. package/dist/renderer.d.ts +34 -0
  21. package/dist/renderer.js +193 -0
  22. package/dist/timer.d.ts +10 -0
  23. package/dist/timer.js +17 -0
  24. package/examples/audio.ogg +0 -0
  25. package/examples/bars.js +19 -0
  26. package/examples/basic.js +8 -0
  27. package/examples/gradient.js +28 -0
  28. package/examples/regions.js +63 -0
  29. package/examples/video.js +19 -0
  30. package/examples/webaudio.js +14 -0
  31. package/package.json +19 -99
  32. package/src/base-plugin.ts +20 -0
  33. package/src/decoder.ts +41 -0
  34. package/src/event-emitter.ts +35 -0
  35. package/src/fetcher.ts +7 -0
  36. package/src/index.ts +252 -0
  37. package/src/player-webaudio.ts +34 -0
  38. package/src/player.ts +50 -0
  39. package/src/plugins/regions.ts +240 -0
  40. package/src/renderer.ts +250 -0
  41. package/src/timer.ts +27 -0
  42. package/tsconfig.json +105 -0
  43. package/tutorial/index.html +47 -0
  44. package/tutorial/src/editor.js +70 -0
  45. package/tutorial/src/init.js +66 -0
  46. package/tutorial/src/url.js +25 -0
  47. package/tutorial/style.css +211 -0
  48. package/yarn-error.log +1049 -0
  49. package/LICENSE +0 -29
  50. package/dist/plugin/wavesurfer.cursor.js +0 -418
  51. package/dist/plugin/wavesurfer.cursor.js.map +0 -1
  52. package/dist/plugin/wavesurfer.cursor.min.js +0 -7
  53. package/dist/plugin/wavesurfer.cursor.min.js.map +0 -1
  54. package/dist/plugin/wavesurfer.elan.js +0 -381
  55. package/dist/plugin/wavesurfer.elan.js.map +0 -1
  56. package/dist/plugin/wavesurfer.elan.min.js +0 -7
  57. package/dist/plugin/wavesurfer.elan.min.js.map +0 -1
  58. package/dist/plugin/wavesurfer.markers.js +0 -520
  59. package/dist/plugin/wavesurfer.markers.js.map +0 -1
  60. package/dist/plugin/wavesurfer.markers.min.js +0 -7
  61. package/dist/plugin/wavesurfer.markers.min.js.map +0 -1
  62. package/dist/plugin/wavesurfer.mediasession.js +0 -181
  63. package/dist/plugin/wavesurfer.mediasession.js.map +0 -1
  64. package/dist/plugin/wavesurfer.mediasession.min.js +0 -7
  65. package/dist/plugin/wavesurfer.mediasession.min.js.map +0 -1
  66. package/dist/plugin/wavesurfer.microphone.js +0 -466
  67. package/dist/plugin/wavesurfer.microphone.js.map +0 -1
  68. package/dist/plugin/wavesurfer.microphone.min.js +0 -7
  69. package/dist/plugin/wavesurfer.microphone.min.js.map +0 -1
  70. package/dist/plugin/wavesurfer.minimap.js +0 -440
  71. package/dist/plugin/wavesurfer.minimap.js.map +0 -1
  72. package/dist/plugin/wavesurfer.minimap.min.js +0 -7
  73. package/dist/plugin/wavesurfer.minimap.min.js.map +0 -1
  74. package/dist/plugin/wavesurfer.playhead.js +0 -300
  75. package/dist/plugin/wavesurfer.playhead.js.map +0 -1
  76. package/dist/plugin/wavesurfer.playhead.min.js +0 -7
  77. package/dist/plugin/wavesurfer.playhead.min.js.map +0 -1
  78. package/dist/plugin/wavesurfer.regions.js +0 -1335
  79. package/dist/plugin/wavesurfer.regions.js.map +0 -1
  80. package/dist/plugin/wavesurfer.regions.min.js +0 -7
  81. package/dist/plugin/wavesurfer.regions.min.js.map +0 -1
  82. package/dist/plugin/wavesurfer.spectrogram.js +0 -736
  83. package/dist/plugin/wavesurfer.spectrogram.js.map +0 -1
  84. package/dist/plugin/wavesurfer.spectrogram.min.js +0 -7
  85. package/dist/plugin/wavesurfer.spectrogram.min.js.map +0 -1
  86. package/dist/plugin/wavesurfer.timeline.js +0 -649
  87. package/dist/plugin/wavesurfer.timeline.js.map +0 -1
  88. package/dist/plugin/wavesurfer.timeline.min.js +0 -7
  89. package/dist/plugin/wavesurfer.timeline.min.js.map +0 -1
  90. package/dist/wavesurfer-html-init.js +0 -381
  91. package/dist/wavesurfer-html-init.js.map +0 -1
  92. package/dist/wavesurfer-html-init.min.js +0 -7
  93. package/dist/wavesurfer-html-init.min.js.map +0 -1
  94. package/dist/wavesurfer.js +0 -6145
  95. package/dist/wavesurfer.js.map +0 -1
  96. package/dist/wavesurfer.min.js +0 -7
  97. package/dist/wavesurfer.min.js.map +0 -1
  98. package/src/drawer.canvasentry.js +0 -427
  99. package/src/drawer.js +0 -413
  100. package/src/drawer.multicanvas.js +0 -617
  101. package/src/html-init.js +0 -241
  102. package/src/mediaelement-webaudio.js +0 -77
  103. package/src/mediaelement.js +0 -443
  104. package/src/peakcache.js +0 -127
  105. package/src/plugin/cursor/index.js +0 -350
  106. package/src/plugin/elan/index.js +0 -307
  107. package/src/plugin/markers/index.js +0 -436
  108. package/src/plugin/mediasession/index.js +0 -94
  109. package/src/plugin/microphone/index.js +0 -415
  110. package/src/plugin/minimap/index.js +0 -403
  111. package/src/plugin/playhead/index.js +0 -226
  112. package/src/plugin/regions/index.js +0 -478
  113. package/src/plugin/regions/region.js +0 -875
  114. package/src/plugin/spectrogram/fft.js +0 -222
  115. package/src/plugin/spectrogram/index.js +0 -522
  116. package/src/plugin/timeline/index.js +0 -600
  117. package/src/util/absMax.js +0 -16
  118. package/src/util/clamp.js +0 -11
  119. package/src/util/fetch.js +0 -222
  120. package/src/util/frame.js +0 -13
  121. package/src/util/get-id.js +0 -22
  122. package/src/util/index.js +0 -14
  123. package/src/util/max.js +0 -16
  124. package/src/util/min.js +0 -16
  125. package/src/util/observer.js +0 -144
  126. package/src/util/orientation.js +0 -98
  127. package/src/util/prevent-click.js +0 -19
  128. package/src/util/request-animation-frame.js +0 -15
  129. package/src/util/silence-mode.js +0 -42
  130. package/src/util/style.js +0 -16
  131. package/src/wavesurfer.js +0 -1797
  132. package/src/webaudio.js +0 -779
@@ -0,0 +1,70 @@
1
+ let editor = null
2
+
3
+ export const getContent = () => {
4
+ return editor ? editor.getModel().getValue() : ''
5
+ }
6
+
7
+ export const setContent = (newContent) => {
8
+ if (!editor) {
9
+ setTimeout(() => setContent(newContent), 10)
10
+ } else {
11
+ editor.getModel().setValue(newContent)
12
+ }
13
+ }
14
+
15
+ const fetchCode = async (url) => {
16
+ return fetch(url).then((res) => res.text())
17
+ }
18
+
19
+ export const initEditor = (onSetContent) => {
20
+ require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.32.0-dev.20211218/min/vs' } });
21
+
22
+ require(['vs/editor/editor.main'], () => {
23
+ let theme = 'vs'
24
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
25
+ theme = 'vs-dark'
26
+ }
27
+
28
+ monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
29
+ lib: [ 'es2019', 'dom' ],
30
+ allowJs: true,
31
+ allowNonTsExtensions: true,
32
+ baseUrl: window.location.origin,
33
+ moduleResolution: monaco.languages.typescript.ModuleResolutionKind.Classic,
34
+ })
35
+
36
+ const libs = [
37
+ '/dist/index.d.ts',
38
+ '/dist/event-emitter.d.ts',
39
+ '/dist/plugins/regions.d.ts',
40
+ ]
41
+
42
+ Promise.all(
43
+ libs.map(url => fetchCode(url))
44
+ ).then((codes) => {
45
+ codes.forEach((code, index) => {
46
+ monaco.languages.typescript.typescriptDefaults.addExtraLib(code, libs[index])
47
+ })
48
+ }).then(() => {
49
+ const monacoEditor = monaco.editor.create(document.getElementById('editor'), {
50
+ language: 'typescript',
51
+ quickSuggestions: true,
52
+ automaticLayout: true,
53
+ autoClosingBrackets: false,
54
+ minimap: { enabled: false },
55
+ tabSize: 2,
56
+ theme
57
+ });
58
+
59
+ let debounce
60
+ const model = monacoEditor.getModel()
61
+ model.onDidChangeContent(() => {
62
+ if (debounce) clearTimeout(debounce)
63
+ debounce = setTimeout(onSetContent, 300)
64
+ })
65
+
66
+ // Export
67
+ editor = monacoEditor
68
+ })
69
+ })
70
+ }
@@ -0,0 +1,66 @@
1
+ import { initEditor, setContent, getContent } from './editor.js'
2
+
3
+ const onSetContent = () => {
4
+ const code = getContent()
5
+ document.getElementById('preview').srcdoc = `
6
+ <!DOCTYPE html>
7
+ <html>
8
+ <head>
9
+ <meta charset="utf-8">
10
+ <title>Preview</title>
11
+ <style>
12
+ html, body {
13
+ background-color: transparent;
14
+ margin: 0;
15
+ padding: 0;
16
+ }
17
+ body {
18
+ padding: 1rem;
19
+ }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <script type="module">
24
+ ${code}
25
+ </script>
26
+ </body>
27
+ </html>
28
+ <body>
29
+ </body>
30
+ `
31
+ }
32
+
33
+ const fetchContent = async (url) => {
34
+ return fetch(url).then(res => res.text())
35
+ }
36
+
37
+ const init = () => {
38
+ let currentLink = null
39
+
40
+ document.addEventListener('click', (e) => {
41
+ const url = e.target.href
42
+ if (url && url.endsWith('.js')) {
43
+ e.preventDefault()
44
+
45
+ fetchContent(url).then(setContent)
46
+
47
+ if (currentLink) {
48
+ currentLink.classList.remove('active')
49
+ }
50
+ currentLink = e.target
51
+ currentLink.classList.add('active')
52
+
53
+ window.location.hash = e.target.pathname
54
+ }
55
+ })
56
+
57
+ const { hash } = window.location
58
+ let url = '/examples/basic.js'
59
+ if (hash && /^#\/examples\/.+?\.js$/.test(hash)) {
60
+ url = hash.slice(1)
61
+ }
62
+ document.querySelector(`a[href="${url}"]`).click()
63
+ }
64
+
65
+ initEditor(onSetContent)
66
+ init()
@@ -0,0 +1,25 @@
1
+ const GIST_PARAM = 'gist'
2
+
3
+ export const getQueryParam = (param) => {
4
+ return new URL(location.href).searchParams.get(param)
5
+ }
6
+
7
+ export const clearQueryParam = (param) => {
8
+ const path = location.pathname + location.search.replace(new RegExp(`\\b${param}=\\w+`), '').replace(/\?$/, '')
9
+ history.pushState({}, '', path)
10
+ }
11
+
12
+ export const getUrlGistId = () => {
13
+ return getQueryParam(GIST_PARAM)
14
+ }
15
+
16
+ export const setUrlGistId = (id) => {
17
+ const path = `${location.pathname}?${GIST_PARAM}=${encodeURIComponent(id)}`
18
+ history.pushState({}, '', path)
19
+ }
20
+
21
+ export const clearUrlGistId = () => {
22
+ clearQueryParam(GIST_PARAM)
23
+ }
24
+
25
+
@@ -0,0 +1,211 @@
1
+ body, html {
2
+ margin: 0;
3
+ padding: 0;
4
+ background: #fff;
5
+ color: #333;
6
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
7
+ }
8
+
9
+ a {
10
+ color: #333;
11
+ }
12
+
13
+ a:hover {
14
+ color: #000;
15
+ }
16
+
17
+ @media (prefers-color-scheme: dark) {
18
+ body, html {
19
+ background: #1E1E1E;
20
+ color: #fff;
21
+ }
22
+
23
+ a {
24
+ color: #ddd;
25
+ }
26
+
27
+ a:hover {
28
+ color: #fff;
29
+ }
30
+ }
31
+
32
+ * {
33
+ box-sizing: border-box;
34
+ }
35
+
36
+ .layout {
37
+ display: flex;
38
+ flex-wrap: wrap;
39
+ flex-direction: column;
40
+ height: 100vh;
41
+ }
42
+
43
+ .grid {
44
+ display: flex;
45
+ flex-wrap: nowrap;
46
+ flex: 1;
47
+ width: 100vw;
48
+ min-height: 500px;
49
+ }
50
+
51
+ @media (max-width: 768px) {
52
+ .grid {
53
+ flex-wrap: wrap;
54
+ }
55
+ }
56
+
57
+ .sidebar {
58
+ width: 120px;
59
+ padding: 10px;
60
+ padding-right: 0;
61
+ }
62
+
63
+ .sidebar ul {
64
+ list-style: none;
65
+ padding: 0;
66
+ margin: 0;
67
+ }
68
+
69
+ .sidebar li {
70
+ padding: 0;
71
+ margin: 0;
72
+ }
73
+
74
+ .sidebar a {
75
+ display: block;
76
+ padding: 0.5em;
77
+ text-decoration: none;
78
+ }
79
+
80
+ .sidebar a.active {
81
+ background: #ddd;
82
+ position: relative;
83
+ }
84
+
85
+ .sidebar a.active:after {
86
+ content: "▸";
87
+ position: absolute;
88
+ right: 0;
89
+ }
90
+
91
+ @media (prefers-color-scheme: dark) {
92
+ .sidebar a.active {
93
+ background: #333;
94
+ }
95
+ }
96
+
97
+ #editor {
98
+ margin-top: 1em;
99
+ min-width: 50vw;
100
+ }
101
+
102
+ .preview {
103
+ flex: 1;
104
+ min-width: 30vw;
105
+ height: 100%;
106
+ padding: 1em;
107
+ }
108
+
109
+ .preview iframe {
110
+ display: block;
111
+ width: 100%;
112
+ height: 100%;
113
+ border: 1px solid #EDEDEC;
114
+ border-radius: 6px;
115
+ }
116
+
117
+ header {
118
+ padding: 1em;
119
+ text-align: center;
120
+ font-family: sans-serif;
121
+ font-size: 12px;
122
+ color: #fff;
123
+ background: linear-gradient(to right, #3a6186, #89253e);
124
+ position: relative;
125
+ display: flex;
126
+ align-items: center;
127
+ justify-content: space-between;
128
+ }
129
+
130
+ header h1 {
131
+ margin: 0;
132
+ font-size: inherit;
133
+ }
134
+
135
+ header a,
136
+ header a:hover,
137
+ footer a,
138
+ footer a:hover {
139
+ color: #fff;
140
+ }
141
+
142
+ header a:hover,
143
+ footer a:hover {
144
+ text-decoration: none;
145
+ }
146
+
147
+ footer {
148
+ padding: 1em;
149
+ text-align: center;
150
+ font-family: sans-serif;
151
+ font-size: 12px;
152
+ color: #ccc;
153
+ background: linear-gradient(to left, #3a6186, #89253e);
154
+ }
155
+
156
+ .github {
157
+ margin-right: 0.5em;
158
+ }
159
+
160
+ .github:before {
161
+ text-decoration: none;
162
+ content: '';
163
+ display: inline-block;
164
+ margin-right: 5px;
165
+ width: 20px;
166
+ height: 20px;
167
+ vertical-align: middle;
168
+ background: center center no-repeat url("data:image/svg+xml, %3Csvg width='1024' height='1024' viewBox='0 0 1024 1024' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z' transform='scale(64)' fill='%23fff'/%3E%3C/svg%3E%0A");
169
+ background-size: contain;
170
+ }
171
+
172
+ @keyframes fadeIn {
173
+ 0% { opacity: 0; }
174
+ 100% { opacity: 1; }
175
+ }
176
+
177
+ .alert {
178
+ position: fixed;
179
+ z-index: 100;
180
+ top: 10px;
181
+ right: 10px;
182
+ padding: 20px;
183
+ border-radius: 6px;
184
+ background: #426183;
185
+ color: #fff;
186
+ font-size: 20px;
187
+ cursor: pointer;
188
+ text-align: left;
189
+ min-width: 30vw;
190
+ max-width: 40vw;
191
+ max-height: 5em;
192
+ overflow: auto;
193
+ white-space: pre-line;
194
+ animation: fadeIn 100ms ease-in;
195
+ }
196
+
197
+ .eval-decoration {
198
+ background: #CFB3B9;
199
+ }
200
+
201
+ @media (prefers-color-scheme: dark) {
202
+ .eval-decoration {
203
+ background: #792C3D;
204
+ }
205
+ }
206
+
207
+ kbd {
208
+ content: '⌨';
209
+ font-size: 1.2em;
210
+ margin-right: 0.2em;
211
+ }