UNPKG

18.3 kBSource Map (JSON)View Raw
1{"version":3,"file":"wavesurfer-html-init.js","mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+CAA+C;AAC/C,CAAC;AACD;;;;;;;;;;;;;;;;ACVA;AAAqC;AAAA;AAAA;AAAA;AAAA;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAnCA,IAoCMA,IAAI;EACN;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACI,cAAYC,UAAU,EAAe;IAAA,IAAbC,MAAM,uEAAG,CAAC,CAAC;IAAA;IAC/B,IAAI,CAACD,UAAU,EAAE;MACb,MAAM,IAAIE,KAAK,CAAC,8BAA8B,CAAC;IACnD;;IAEA;AACR;AACA;AACA;IACQ,IAAI,CAACF,UAAU,GAAGA,UAAU;;IAE5B;AACR;AACA;AACA;IACQ,IAAMG,OAAO,GAAI,IAAI,CAACF,MAAM,GAAGG,MAAM,CAACC,MAAM,CACxC,CAAC,CAAC,EACF;MACI;MACA;MACAC,QAAQ,EAAE;QACNC,OAAO,EAAE,cAAc;QACvBC,aAAa,EAAE;MACnB,CAAC;MACD;MACAC,UAAU,EAAE,YAAY;MACxB;MACAC,iBAAiB,EACb,mDAAmD;MACvD;MACA;MACA;MACAC,UAAU,sBAACC,IAAI,EAAEC,EAAE,EAAE;QACjB,IAAMC,GAAG,GAAGX,OAAO,CAACO,iBAAiB,CAACK,OAAO,CACzC,QAAQ,EACRH,IAAI,CACP;QACD,IAAAI,mBAAU,EAACF,GAAG,EAAE;UAAEG,KAAK,EAAE;QAAM,CAAC,EAAE,UAACC,GAAG,EAAEC,MAAM,EAAK;UAC/C,IAA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cAAc,CACxB;IACL,CAAC,CAAC;EACN;AACJ;;AAEA;AAAA,eACevE,IAAI;AAAA;AAAA;;;;;;;;;;;AC/OnB;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;UChEA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;UEtBA;UACA;UACA;UACA","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/before-startup","webpack://WaveSurfer/webpack/startup","webpack://WaveSurfer/webpack/after-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__(\"./src/html-init.js\");\n",""],"names":["Init","WaveSurfer","params","Error","_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","options","attrNameRegex","RegExp","attrName","regexResult","exec","attr","prop","test","JSON","parse","unprefixedOptionName","slice","toLowerCase","create","container","style","display","instance","peaks","undefined","load","url","push","WS_StopAutoInit","readyState","WaveSurferInit","WS_InitOptions","addEventListener"],"sourceRoot":""}
\No newline at end of file