1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | (function webpackUniversalModuleDefinition(root, factory) {
|
7 | if(typeof exports === 'object' && typeof module === 'object')
|
8 | module.exports = factory();
|
9 | else if(typeof define === 'function' && define.amd)
|
10 | define("WaveSurfer", [], factory);
|
11 | else if(typeof exports === 'object')
|
12 | exports["WaveSurfer"] = factory();
|
13 | else
|
14 | root["WaveSurfer"] = root["WaveSurfer"] || {}, root["WaveSurfer"]["html-init"] = factory();
|
15 | })(self, () => {
|
16 | return (() => {
|
17 | var __webpack_modules__ = ({
|
18 |
|
19 | "./src/html-init.js":
|
20 |
|
21 |
|
22 |
|
23 | ((module, exports, __webpack_require__) => {
|
24 |
|
25 | "use strict";
|
26 |
|
27 |
|
28 | Object.defineProperty(exports, "__esModule", ({
|
29 | value: true
|
30 | }));
|
31 | exports["default"] = void 0;
|
32 | var _loadScript = _interopRequireDefault(__webpack_require__( "./node_modules/load-script/index.js"));
|
33 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
34 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
35 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
36 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
37 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | var Init = function () {
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function Init(WaveSurfer) {
|
97 | var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
98 | _classCallCheck(this, Init);
|
99 | if (!WaveSurfer) {
|
100 | throw new Error('WaveSurfer is not available!');
|
101 | }
|
102 |
|
103 | |
104 |
|
105 |
|
106 |
|
107 | this.WaveSurfer = WaveSurfer;
|
108 |
|
109 | |
110 |
|
111 |
|
112 |
|
113 | var _params = this.params = Object.assign({}, {
|
114 |
|
115 |
|
116 | defaults: {
|
117 | backend: 'MediaElement',
|
118 | mediaControls: true
|
119 | },
|
120 |
|
121 | containers: 'wavesurfer',
|
122 |
|
123 | pluginCdnTemplate: '//localhost:8080/dist/plugin/wavesurfer.[name].js',
|
124 |
|
125 |
|
126 |
|
127 | loadPlugin: function loadPlugin(name, cb) {
|
128 | var src = _params.pluginCdnTemplate.replace('[name]', name);
|
129 | (0, _loadScript.default)(src, {
|
130 | async: false
|
131 | }, function (err, plugin) {
|
132 | if (err) {
|
133 |
|
134 | return console.error("WaveSurfer plugin ".concat(name, " not found at ").concat(src));
|
135 | }
|
136 | cb(window.WaveSurfer[name]);
|
137 | });
|
138 | }
|
139 | }, params);
|
140 | |
141 |
|
142 |
|
143 |
|
144 | this.containers = typeof _params.containers == 'string' ? document.querySelectorAll(_params.containers) : _params.containers;
|
145 |
|
146 | this.pluginCache = {};
|
147 | |
148 |
|
149 |
|
150 |
|
151 | this.instances = [];
|
152 | this.initAllEls();
|
153 | }
|
154 |
|
155 | |
156 |
|
157 |
|
158 | _createClass(Init, [{
|
159 | key: "initAllEls",
|
160 | value: function initAllEls() {
|
161 | var _this = this;
|
162 |
|
163 | Array.prototype.forEach.call(this.containers, function (el) {
|
164 |
|
165 | var plugins = el.dataset.plugins ? el.dataset.plugins.split(',') : [];
|
166 |
|
167 |
|
168 | if (!plugins.length) {
|
169 | return _this.initEl(el);
|
170 | }
|
171 |
|
172 | plugins.forEach(function (name, i) {
|
173 |
|
174 | if (!_this.pluginCache[name]) {
|
175 | _this.params.loadPlugin(name, function (lib) {
|
176 | _this.pluginCache[name] = lib;
|
177 |
|
178 | if (i + 1 === plugins.length) {
|
179 | _this.initEl(el, plugins);
|
180 | }
|
181 | });
|
182 | } else if (i === plugins.length) {
|
183 |
|
184 | _this.initEl(el, plugins);
|
185 | }
|
186 | });
|
187 | });
|
188 | }
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 | }, {
|
198 | key: "initEl",
|
199 | value: function initEl(el) {
|
200 | var _this2 = this;
|
201 | var plugins = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
202 | var jsonRegex = /^[[|{]/;
|
203 |
|
204 | var initialisedPlugins = plugins.map(function (plugin) {
|
205 | var options = {};
|
206 |
|
207 | var attrNameRegex = new RegExp('^' + plugin);
|
208 | var attrName;
|
209 |
|
210 |
|
211 | for (attrName in el.dataset) {
|
212 | var regexResult = attrNameRegex.exec(attrName);
|
213 | if (regexResult) {
|
214 | var attr = el.dataset[attrName];
|
215 |
|
216 | var prop = jsonRegex.test(attr) ? JSON.parse(attr) : attr;
|
217 |
|
218 |
|
219 |
|
220 | var unprefixedOptionName = attrName.slice(plugin.length, plugin.length + 1).toLowerCase() + attrName.slice(plugin.length + 1);
|
221 | options[unprefixedOptionName] = prop;
|
222 | }
|
223 | }
|
224 | return _this2.pluginCache[plugin].create(options);
|
225 | });
|
226 |
|
227 | var params = Object.assign({
|
228 | container: el
|
229 | }, this.params.defaults, el.dataset, {
|
230 | plugins: initialisedPlugins
|
231 | });
|
232 |
|
233 |
|
234 | el.style.display = 'block';
|
235 |
|
236 |
|
237 | var instance = this.WaveSurfer.create(params);
|
238 | var peaks = params.peaks ? JSON.parse(params.peaks) : undefined;
|
239 | instance.load(params.url, peaks);
|
240 |
|
241 |
|
242 | this.instances.push(instance);
|
243 | return instance;
|
244 | }
|
245 | }]);
|
246 | return Init;
|
247 | }();
|
248 | if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && !window.WS_StopAutoInit) {
|
249 |
|
250 |
|
251 | if (document.readyState === 'complete') {
|
252 | window.WaveSurferInit = new Init(window.WaveSurfer, window.WS_InitOptions);
|
253 | } else {
|
254 | window.addEventListener('load', function () {
|
255 | window.WaveSurferInit = new Init(window.WaveSurfer, window.WS_InitOptions);
|
256 | });
|
257 | }
|
258 | }
|
259 |
|
260 |
|
261 | var _default = Init;
|
262 | exports["default"] = _default;
|
263 | module.exports = exports.default;
|
264 |
|
265 | }),
|
266 |
|
267 | "./node_modules/load-script/index.js":
|
268 |
|
269 |
|
270 |
|
271 | ((module) => {
|
272 |
|
273 |
|
274 | module.exports = function load (src, opts, cb) {
|
275 | var head = document.head || document.getElementsByTagName('head')[0]
|
276 | var script = document.createElement('script')
|
277 |
|
278 | if (typeof opts === 'function') {
|
279 | cb = opts
|
280 | opts = {}
|
281 | }
|
282 |
|
283 | opts = opts || {}
|
284 | cb = cb || function() {}
|
285 |
|
286 | script.type = opts.type || 'text/javascript'
|
287 | script.charset = opts.charset || 'utf8';
|
288 | script.async = 'async' in opts ? !!opts.async : true
|
289 | script.src = src
|
290 |
|
291 | if (opts.attrs) {
|
292 | setAttributes(script, opts.attrs)
|
293 | }
|
294 |
|
295 | if (opts.text) {
|
296 | script.text = '' + opts.text
|
297 | }
|
298 |
|
299 | var onend = 'onload' in script ? stdOnEnd : ieOnEnd
|
300 | onend(script, cb)
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | if (!script.onload) {
|
306 | stdOnEnd(script, cb);
|
307 | }
|
308 |
|
309 | head.appendChild(script)
|
310 | }
|
311 |
|
312 | function setAttributes(script, attrs) {
|
313 | for (var attr in attrs) {
|
314 | script.setAttribute(attr, attrs[attr]);
|
315 | }
|
316 | }
|
317 |
|
318 | function stdOnEnd (script, cb) {
|
319 | script.onload = function () {
|
320 | this.onerror = this.onload = null
|
321 | cb(null, script)
|
322 | }
|
323 | script.onerror = function () {
|
324 |
|
325 |
|
326 | this.onerror = this.onload = null
|
327 | cb(new Error('Failed to load ' + this.src), script)
|
328 | }
|
329 | }
|
330 |
|
331 | function ieOnEnd (script, cb) {
|
332 | script.onreadystatechange = function () {
|
333 | if (this.readyState != 'complete' && this.readyState != 'loaded') return
|
334 | this.onreadystatechange = null
|
335 | cb(null, script)
|
336 | }
|
337 | }
|
338 |
|
339 |
|
340 | })
|
341 |
|
342 | });
|
343 |
|
344 |
|
345 | var __webpack_module_cache__ = {};
|
346 |
|
347 |
|
348 | function __webpack_require__(moduleId) {
|
349 |
|
350 | var cachedModule = __webpack_module_cache__[moduleId];
|
351 | if (cachedModule !== undefined) {
|
352 | return cachedModule.exports;
|
353 | }
|
354 |
|
355 | var module = __webpack_module_cache__[moduleId] = {
|
356 |
|
357 |
|
358 | exports: {}
|
359 | };
|
360 |
|
361 |
|
362 | __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
363 |
|
364 |
|
365 | return module.exports;
|
366 | }
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | var __webpack_exports__ = __webpack_require__("./src/html-init.js");
|
374 |
|
375 | return __webpack_exports__;
|
376 | })()
|
377 | ;
|
378 | });
|
379 |
|
\ | No newline at end of file |