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,EAASD,EAAWI,GACtCH,EAAQ1D,GAKT0D,EAAOC,QACVF,EAASC,EAAQ1D,GAGnBgE,EAAKS,YAAYf,EACnB,C,GCpCIgB,EAA2B,CAAC,ECE5BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqB7B,IAAjB8B,EACH,OAAOA,EAAalG,QAGrB,IAAIC,EAAS6F,EAAyBG,GAAY,CAGjDjG,QAAS,CAAC,GAOX,OAHAmG,EAAoBF,GAAUhG,EAAQA,EAAOD,QAASgG,GAG/C/F,EAAOD,OACf,CCnB0BgG,CAAoB,K,EJO9C,I,EGTIF,ECEAC,C","sources":["webpack://WaveSurfer/webpack/universalModuleDefinition","webpack://WaveSurfer/./src/html-init.js","webpack://WaveSurfer/./node_modules/load-script/index.js","webpack://WaveSurfer/webpack/bootstrap","webpack://WaveSurfer/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"WaveSurfer\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"WaveSurfer\"] = factory();\n\telse\n\t\troot[\"WaveSurfer\"] = root[\"WaveSurfer\"] || {}, root[\"WaveSurfer\"][\"html-init\"] = factory();\n})(self, () => {\nreturn ","import loadScript from 'load-script';\n\n/**\n * @typedef {Object} InitParams\n * @property {WavesurferParams} [defaults={backend: 'MediaElement,\n * mediaControls: true}] The default wavesurfer initialisation parameters\n * @property {string|NodeList} containers='wavesurfer' Selector or NodeList of\n * elements to attach instances to\n * @property {string}\n * pluginCdnTemplate='//localhost:8080/dist/plugin/wavesurfer.[name].js' URL\n * template for the dynamic loading of plugins\n * @property {function} loadPlugin If set overwrites the default request function,\n * can be used to inject plugins differently.\n */\n/**\n * The HTML initialisation API is not part of the main library bundle file and\n * must be additionally included.\n *\n * The API attaches wavesurfer instances to all `<wavesurfer>` (can be\n * customised), parsing their `data-` attributes to construct an options object\n * for initialisation. Among other things it can dynamically load plugin code.\n *\n * The automatic initialisation can be prevented by setting the\n * `window.WS_StopAutoInit` flag to true. The `html-init[.min].js` file exports\n * the `Init` class, which can be called manually.\n *\n * Site-wide defaults can be added by setting `window.WS_InitOptions`.\n *\n * @example\n * <!-- with minimap and timeline plugin -->\n * <wavesurfer\n * data-url=\"../media/demo.wav\"\n * data-plugins=\"minimap,timeline\"\n * data-minimap-height=\"30\"\n * data-minimap-wave-color=\"#ddd\"\n * data-minimap-progress-color=\"#999\"\n * data-timeline-font-size=\"13px\"\n * data-timeline-container=\"#timeline\"\n * >\n * </wavesurfer>\n * <div id=\"timeline\"></div>\n *\n * <!-- with regions plugin -->\n * <wavesurfer\n * data-url=\"../media/demo.wav\"\n * data-plugins=\"regions\"\n * data-regions-regions='[{\"start\": 1,\"end\": 3,\"color\": \"hsla(400, 100%, 30%, 0.5)\"}]'\n * >\n * </wavesurfer>\n */\nclass Init {\n /**\n * Instantiate Init class and initialize elements\n *\n * This is done automatically if `window` is defined and\n * `window.WS_StopAutoInit` is not set to true\n *\n * @param {WaveSurfer} WaveSurfer The WaveSurfer library object\n * @param {InitParams} params initialisation options\n */\n constructor(WaveSurfer, params = {}) {\n if (!WaveSurfer) {\n throw new Error('WaveSurfer is not available!');\n }\n\n /**\n * cache WaveSurfer\n * @private\n */\n this.WaveSurfer = WaveSurfer;\n\n /**\n * build parameters, cache them in _params so minified builds are smaller\n * @private\n */\n const _params = (this.params = Object.assign(\n {},\n {\n // wavesurfer parameter defaults so by default the audio player is\n // usable with native media element controls\n defaults: {\n backend: 'MediaElement',\n mediaControls: true\n },\n // containers to instantiate on, can be selector string or NodeList\n containers: 'wavesurfer',\n // @TODO insert plugin CDN URIs\n pluginCdnTemplate:\n '//localhost:8080/dist/plugin/wavesurfer.[name].js',\n // loadPlugin function can be overridden to inject plugin definition\n // objects, this default function uses load-script to load a plugin\n // and pass it to a callback\n loadPlugin(name, cb) {\n const src = _params.pluginCdnTemplate.replace(\n '[name]',\n name\n );\n loadScript(src, { async: false }, (err, plugin) => {\n if (err) {\n // eslint-disable-next-line no-console\n return console.error(\n `WaveSurfer plugin ${name} not found at ${src}`\n );\n }\n cb(window.WaveSurfer[name]);\n });\n }\n },\n params\n ));\n /**\n * The nodes that should have instances attached to them\n * @type {NodeList}\n */\n this.containers =\n typeof _params.containers == 'string'\n ? document.querySelectorAll(_params.containers)\n : _params.containers;\n /** @private */\n this.pluginCache = {};\n /**\n * An array of wavesurfer instances\n * @type {Object[]}\n */\n this.instances = [];\n\n this.initAllEls();\n }\n\n /**\n * Initialize all container elements\n */\n initAllEls() {\n // iterate over all the container elements\n Array.prototype.forEach.call(this.containers, el => {\n // load the plugins as an array of plugin names\n const plugins = el.dataset.plugins\n ? el.dataset.plugins.split(',')\n : [];\n\n // no plugins to be loaded, just render\n if (!plugins.length) {\n return this.initEl(el);\n }\n // … or: iterate over all the plugins\n plugins.forEach((name, i) => {\n // plugin is not cached already, load it\n if (!this.pluginCache[name]) {\n this.params.loadPlugin(name, lib => {\n this.pluginCache[name] = lib;\n // plugins were all loaded, render the element\n if (i + 1 === plugins.length) {\n this.initEl(el, plugins);\n }\n });\n } else if (i === plugins.length) {\n // plugin was cached and this plugin was the last\n this.initEl(el, plugins);\n }\n });\n });\n }\n\n /**\n * Initialize a single container element and add to `this.instances`\n *\n * @param {HTMLElement} el The container to instantiate wavesurfer to\n * @param {PluginDefinition[]} plugins An Array of plugin names to initialize with\n * @return {Object} Wavesurfer instance\n */\n initEl(el, plugins = []) {\n const jsonRegex = /^[[|{]/;\n // initialize plugins with the correct options\n const initialisedPlugins = plugins.map(plugin => {\n const options = {};\n // the regex to find this plugin attributes\n const attrNameRegex = new RegExp('^' + plugin);\n let attrName;\n // iterate over all the data attributes and find ones for this\n // plugin\n for (attrName in el.dataset) {\n const regexResult = attrNameRegex.exec(attrName);\n if (regexResult) {\n const attr = el.dataset[attrName];\n // if the string begins with a [ or a { parse it as JSON\n const prop = jsonRegex.test(attr) ? JSON.parse(attr) : attr;\n // this removes the plugin prefix and changes the first letter\n // of the resulting string to lower case to follow the naming\n // convention of ws params\n const unprefixedOptionName =\n attrName\n .slice(plugin.length, plugin.length + 1)\n .toLowerCase() + attrName.slice(plugin.length + 1);\n options[unprefixedOptionName] = prop;\n }\n }\n return this.pluginCache[plugin].create(options);\n });\n // build parameter object for this container\n const params = Object.assign(\n { container: el },\n this.params.defaults,\n el.dataset,\n { plugins: initialisedPlugins }\n );\n\n // @TODO make nicer\n el.style.display = 'block';\n\n // initialize wavesurfer, load audio (with peaks if provided)\n const instance = this.WaveSurfer.create(params);\n const peaks = params.peaks ? JSON.parse(params.peaks) : undefined;\n instance.load(params.url, peaks);\n\n // push this instance into the instances cache\n this.instances.push(instance);\n return instance;\n }\n}\n\n// if window object exists and window.WS_StopAutoInit is not true\nif (typeof window === 'object' && !window.WS_StopAutoInit) {\n // call init when document is ready, apply any custom default settings\n // in window.WS_InitOptions\n if (document.readyState === 'complete') {\n window.WaveSurferInit = new Init(\n window.WaveSurfer,\n window.WS_InitOptions\n );\n } else {\n window.addEventListener('load', () => {\n window.WaveSurferInit = new Init(\n window.WaveSurfer,\n window.WS_InitOptions\n );\n });\n }\n}\n\n// export init for manual usage\nexport default Init;\n","\nmodule.exports = function load (src, opts, cb) {\n var head = document.head || document.getElementsByTagName('head')[0]\n var script = document.createElement('script')\n\n if (typeof opts === 'function') {\n cb = opts\n opts = {}\n }\n\n opts = opts || {}\n cb = cb || function() {}\n\n script.type = opts.type || 'text/javascript'\n script.charset = opts.charset || 'utf8';\n script.async = 'async' in opts ? !!opts.async : true\n script.src = src\n\n if (opts.attrs) {\n setAttributes(script, opts.attrs)\n }\n\n if (opts.text) {\n script.text = '' + opts.text\n }\n\n var onend = 'onload' in script ? stdOnEnd : ieOnEnd\n onend(script, cb)\n\n // some good legacy browsers (firefox) fail the 'in' detection above\n // so as a fallback we always set onload\n // old IE will ignore this and new IE will set onload\n if (!script.onload) {\n stdOnEnd(script, cb);\n }\n\n head.appendChild(script)\n}\n\nfunction setAttributes(script, attrs) {\n for (var attr in attrs) {\n script.setAttribute(attr, attrs[attr]);\n }\n}\n\nfunction stdOnEnd (script, cb) {\n script.onload = function () {\n this.onerror = this.onload = null\n cb(null, script)\n }\n script.onerror = function () {\n // this.onload = null here is necessary\n // because even IE9 works not like others\n this.onerror = this.onload = null\n cb(new Error('Failed to load ' + this.src), script)\n }\n}\n\nfunction ieOnEnd (script, cb) {\n script.onreadystatechange = function () {\n if (this.readyState != 'complete' && this.readyState != 'loaded') return\n this.onreadystatechange = null\n cb(null, script) // there is no way to catch loading errors in IE8\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(531);\n"],"names":["root","factory","exports","module","define","amd","self","Init","WaveSurfer","params","Error","this","_params","Object","assign","defaults","backend","mediaControls","containers","pluginCdnTemplate","loadPlugin","name","cb","src","replace","loadScript","async","err","plugin","console","error","window","document","querySelectorAll","pluginCache","instances","initAllEls","Array","prototype","forEach","call","el","plugins","dataset","split","length","initEl","i","lib","jsonRegex","initialisedPlugins","map","attrName","options","attrNameRegex","RegExp","exec","attr","prop","test","JSON","parse","slice","toLowerCase","create","container","style","display","instance","peaks","undefined","load","url","push","WS_StopAutoInit","readyState","WaveSurferInit","WS_InitOptions","addEventListener","stdOnEnd","script","onload","onerror","ieOnEnd","onreadystatechange","opts","head","getElementsByTagName","createElement","type","charset","attrs","setAttribute","setAttributes","text","appendChild","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
\No newline at end of file