Alex Cabrera
audio
c24ff9a
function noop() { }
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === 'function';
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
let src_url_equal_anchor;
function src_url_equal(element_src, url) {
if (!src_url_equal_anchor) {
src_url_equal_anchor = document.createElement('a');
}
src_url_equal_anchor.href = url;
return element_src === src_url_equal_anchor.href;
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
// Track which nodes are claimed during hydration. Unclaimed nodes can then be removed from the DOM
// at the end of hydration without touching the remaining nodes.
let is_hydrating = false;
function start_hydrating() {
is_hydrating = true;
}
function end_hydrating() {
is_hydrating = false;
}
function upper_bound(low, high, key, value) {
// Return first index of value larger than input value in the range [low, high)
while (low < high) {
const mid = low + ((high - low) >> 1);
if (key(mid) <= value) {
low = mid + 1;
}
else {
high = mid;
}
}
return low;
}
function init_hydrate(target) {
if (target.hydrate_init)
return;
target.hydrate_init = true;
// We know that all children have claim_order values since the unclaimed have been detached if target is not <head>
let children = target.childNodes;
// If target is <head>, there may be children without claim_order
if (target.nodeName === 'HEAD') {
const myChildren = [];
for (let i = 0; i < children.length; i++) {
const node = children[i];
if (node.claim_order !== undefined) {
myChildren.push(node);
}
}
children = myChildren;
}
/*
* Reorder claimed children optimally.
* We can reorder claimed children optimally by finding the longest subsequence of
* nodes that are already claimed in order and only moving the rest. The longest
* subsequence subsequence of nodes that are claimed in order can be found by
* computing the longest increasing subsequence of .claim_order values.
*
* This algorithm is optimal in generating the least amount of reorder operations
* possible.
*
* Proof:
* We know that, given a set of reordering operations, the nodes that do not move
* always form an increasing subsequence, since they do not move among each other
* meaning that they must be already ordered among each other. Thus, the maximal
* set of nodes that do not move form a longest increasing subsequence.
*/
// Compute longest increasing subsequence
// m: subsequence length j => index k of smallest value that ends an increasing subsequence of length j
const m = new Int32Array(children.length + 1);
// Predecessor indices + 1
const p = new Int32Array(children.length);
m[0] = -1;
let longest = 0;
for (let i = 0; i < children.length; i++) {
const current = children[i].claim_order;
// Find the largest subsequence length such that it ends in a value less than our current value
// upper_bound returns first greater value, so we subtract one
// with fast path for when we are on the current longest subsequence
const seqLen = ((longest > 0 && children[m[longest]].claim_order <= current) ? longest + 1 : upper_bound(1, longest, idx => children[m[idx]].claim_order, current)) - 1;
p[i] = m[seqLen] + 1;
const newLen = seqLen + 1;
// We can guarantee that current is the smallest value. Otherwise, we would have generated a longer sequence.
m[newLen] = i;
longest = Math.max(newLen, longest);
}
// The longest increasing subsequence of nodes (initially reversed)
const lis = [];
// The rest of the nodes, nodes that will be moved
const toMove = [];
let last = children.length - 1;
for (let cur = m[longest] + 1; cur != 0; cur = p[cur - 1]) {
lis.push(children[cur - 1]);
for (; last >= cur; last--) {
toMove.push(children[last]);
}
last--;
}
for (; last >= 0; last--) {
toMove.push(children[last]);
}
lis.reverse();
// We sort the nodes being moved to guarantee that their insertion order matches the claim order
toMove.sort((a, b) => a.claim_order - b.claim_order);
// Finally, we move the nodes
for (let i = 0, j = 0; i < toMove.length; i++) {
while (j < lis.length && toMove[i].claim_order >= lis[j].claim_order) {
j++;
}
const anchor = j < lis.length ? lis[j] : null;
target.insertBefore(toMove[i], anchor);
}
}
function append(target, node) {
target.appendChild(node);
}
function append_styles(target, style_sheet_id, styles) {
const append_styles_to = get_root_for_style(target);
if (!append_styles_to.getElementById(style_sheet_id)) {
const style = element('style');
style.id = style_sheet_id;
style.textContent = styles;
append_stylesheet(append_styles_to, style);
}
}
function get_root_for_style(node) {
if (!node)
return document;
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
if (root && root.host) {
return root;
}
return node.ownerDocument;
}
function append_stylesheet(node, style) {
append(node.head || node, style);
}
function append_hydration(target, node) {
if (is_hydrating) {
init_hydrate(target);
if ((target.actual_end_child === undefined) || ((target.actual_end_child !== null) && (target.actual_end_child.parentElement !== target))) {
target.actual_end_child = target.firstChild;
}
// Skip nodes of undefined ordering
while ((target.actual_end_child !== null) && (target.actual_end_child.claim_order === undefined)) {
target.actual_end_child = target.actual_end_child.nextSibling;
}
if (node !== target.actual_end_child) {
// We only insert if the ordering of this node should be modified or the parent node is not target
if (node.claim_order !== undefined || node.parentNode !== target) {
target.insertBefore(node, target.actual_end_child);
}
}
else {
target.actual_end_child = node.nextSibling;
}
}
else if (node.parentNode !== target || node.nextSibling !== null) {
target.appendChild(node);
}
}
function insert_hydration(target, node, anchor) {
if (is_hydrating && !anchor) {
append_hydration(target, node);
}
else if (node.parentNode !== target || node.nextSibling != anchor) {
target.insertBefore(node, anchor || null);
}
}
function detach(node) {
node.parentNode.removeChild(node);
}
function element(name) {
return document.createElement(name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(' ');
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function children(element) {
return Array.from(element.childNodes);
}
function init_claim_info(nodes) {
if (nodes.claim_info === undefined) {
nodes.claim_info = { last_index: 0, total_claimed: 0 };
}
}
function claim_node(nodes, predicate, processNode, createNode, dontUpdateLastIndex = false) {
// Try to find nodes in an order such that we lengthen the longest increasing subsequence
init_claim_info(nodes);
const resultNode = (() => {
// We first try to find an element after the previous one
for (let i = nodes.claim_info.last_index; i < nodes.length; i++) {
const node = nodes[i];
if (predicate(node)) {
const replacement = processNode(node);
if (replacement === undefined) {
nodes.splice(i, 1);
}
else {
nodes[i] = replacement;
}
if (!dontUpdateLastIndex) {
nodes.claim_info.last_index = i;
}
return node;
}
}
// Otherwise, we try to find one before
// We iterate in reverse so that we don't go too far back
for (let i = nodes.claim_info.last_index - 1; i >= 0; i--) {
const node = nodes[i];
if (predicate(node)) {
const replacement = processNode(node);
if (replacement === undefined) {
nodes.splice(i, 1);
}
else {
nodes[i] = replacement;
}
if (!dontUpdateLastIndex) {
nodes.claim_info.last_index = i;
}
else if (replacement === undefined) {
// Since we spliced before the last_index, we decrease it
nodes.claim_info.last_index--;
}
return node;
}
}
// If we can't find any matching node, we create a new one
return createNode();
})();
resultNode.claim_order = nodes.claim_info.total_claimed;
nodes.claim_info.total_claimed += 1;
return resultNode;
}
function claim_element_base(nodes, name, attributes, create_element) {
return claim_node(nodes, (node) => node.nodeName === name, (node) => {
const remove = [];
for (let j = 0; j < node.attributes.length; j++) {
const attribute = node.attributes[j];
if (!attributes[attribute.name]) {
remove.push(attribute.name);
}
}
remove.forEach(v => node.removeAttribute(v));
return undefined;
}, () => create_element(name));
}
function claim_element(nodes, name, attributes) {
return claim_element_base(nodes, name, attributes, element);
}
function claim_text(nodes, data) {
return claim_node(nodes, (node) => node.nodeType === 3, (node) => {
const dataStr = '' + data;
if (node.data.startsWith(dataStr)) {
if (node.data.length !== dataStr.length) {
return node.splitText(dataStr.length);
}
}
else {
node.data = dataStr;
}
}, () => text(data), true // Text nodes should not update last index since it is likely not worth it to eliminate an increasing subsequence of actual elements
);
}
function claim_space(nodes) {
return claim_text(nodes, ' ');
}
function set_data(text, data) {
data = '' + data;
if (text.wholeText !== data)
text.data = data;
}
function set_style(node, key, value, important) {
if (value === null) {
node.style.removeProperty(key);
}
else {
node.style.setProperty(key, value, important ? 'important' : '');
}
}
let current_component;
function set_current_component(component) {
current_component = component;
}
const dirty_components = [];
const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
// flush() calls callbacks in this order:
// 1. All beforeUpdate callbacks, in order: parents before children
// 2. All bind:this callbacks, in reverse order: children before parents.
// 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
// for afterUpdates called during the initial onMount, which are called in
// reverse order: children before parents.
// Since callbacks might update component values, which could trigger another
// call to flush(), the following steps guard against this:
// 1. During beforeUpdate, any updated components will be added to the
// dirty_components array and will cause a reentrant call to flush(). Because
// the flush index is kept outside the function, the reentrant call will pick
// up where the earlier call left off and go through all dirty components. The
// current_component value is saved and restored so that the reentrant call will
// not interfere with the "parent" flush() call.
// 2. bind:this callbacks cannot trigger new flush() calls.
// 3. During afterUpdate, any updated components will NOT have their afterUpdate
// callback called a second time; the seen_callbacks set, outside the flush()
// function, guarantees this behavior.
const seen_callbacks = new Set();
let flushidx = 0; // Do *not* move this inside the flush() function
function flush() {
const saved_component = current_component;
do {
// first, call beforeUpdate functions
// and update components
while (flushidx < dirty_components.length) {
const component = dirty_components[flushidx];
flushidx++;
set_current_component(component);
update(component.$$);
}
set_current_component(null);
dirty_components.length = 0;
flushidx = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
seen_callbacks.clear();
set_current_component(saved_component);
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
const outroing = new Set();
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function mount_component(component, target, anchor, customElement) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment && fragment.m(target, anchor);
if (!customElement) {
// onMount happens before the initial afterUpdate
add_render_callback(() => {
const new_on_destroy = on_mount.map(run).filter(is_function);
if (on_destroy) {
on_destroy.push(...new_on_destroy);
}
else {
// Edge case - component was destroyed immediately,
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
}
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const $$ = component.$$ = {
fragment: null,
ctx: null,
// state
props,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
// everything else
callbacks: blank_object(),
dirty,
skip_bound: false,
root: options.target || parent_component.$$.root
};
append_styles && append_styles($$.root);
let ready = false;
$$.ctx = instance
? instance(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
})
: [];
$$.update();
ready = true;
run_all($$.before_update);
// `false` as a special case of no DOM component
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
start_hydrating();
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor, options.customElement);
end_hydrating();
flush();
}
set_current_component(parent_component);
}
/**
* Base class for Svelte components. Used when dev=false.
*/
class SvelteComponent {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
}
/* src/InstanceView.svelte generated by Svelte v3.49.0 */
function add_css(target) {
append_styles(target, "svelte-1qkvlix", ".label.svelte-1qkvlix{font-size:12px;color:rgba(0, 0, 0, 0.5);font-variant:small-caps}.value.svelte-1qkvlix{font-size:12px}.box.svelte-1qkvlix{padding:10px;border:0.5px solid rgb(224, 224, 224);max-width:400px}#container.svelte-1qkvlix{display:flex;flex-direction:row;flex-wrap:wrap}spectrogram canvas{z-index:0 !important}wave canvas{z-index:0 !important}wave{z-index:0 !important}");
}
// (27:4) {#if modelColumn && entry[modelColumn] !== undefined}
function create_if_block(ctx) {
let br;
let t0;
let span0;
let t1;
let t2;
let span1;
let t3_value = /*entry*/ ctx[0][/*modelColumn*/ ctx[1]] + "";
let t3;
return {
c() {
br = element("br");
t0 = space();
span0 = element("span");
t1 = text("output:");
t2 = space();
span1 = element("span");
t3 = text(t3_value);
this.h();
},
l(nodes) {
br = claim_element(nodes, "BR", {});
t0 = claim_space(nodes);
span0 = claim_element(nodes, "SPAN", { class: true });
var span0_nodes = children(span0);
t1 = claim_text(span0_nodes, "output:");
span0_nodes.forEach(detach);
t2 = claim_space(nodes);
span1 = claim_element(nodes, "SPAN", { class: true });
var span1_nodes = children(span1);
t3 = claim_text(span1_nodes, t3_value);
span1_nodes.forEach(detach);
this.h();
},
h() {
attr(span0, "class", "label svelte-1qkvlix");
attr(span1, "class", "value svelte-1qkvlix");
},
m(target, anchor) {
insert_hydration(target, br, anchor);
insert_hydration(target, t0, anchor);
insert_hydration(target, span0, anchor);
append_hydration(span0, t1);
insert_hydration(target, t2, anchor);
insert_hydration(target, span1, anchor);
append_hydration(span1, t3);
},
p(ctx, dirty) {
if (dirty & /*entry, modelColumn*/ 3 && t3_value !== (t3_value = /*entry*/ ctx[0][/*modelColumn*/ ctx[1]] + "")) set_data(t3, t3_value);
},
d(detaching) {
if (detaching) detach(br);
if (detaching) detach(t0);
if (detaching) detach(span0);
if (detaching) detach(t2);
if (detaching) detach(span1);
}
};
}
function create_fragment(ctx) {
let div2;
let div1;
let div0;
let audio;
let source;
let source_src_value;
let source_type_value;
let audio_src_value;
let t0;
let span0;
let t1;
let span1;
let t2_value = /*entry*/ ctx[0][/*labelColumn*/ ctx[2]] + "";
let t2;
let t3;
let if_block = /*modelColumn*/ ctx[1] && /*entry*/ ctx[0][/*modelColumn*/ ctx[1]] !== undefined && create_if_block(ctx);
return {
c() {
div2 = element("div");
div1 = element("div");
div0 = element("div");
audio = element("audio");
source = element("source");
t0 = space();
span0 = element("span");
t1 = text("label: ");
span1 = element("span");
t2 = text(t2_value);
t3 = space();
if (if_block) if_block.c();
this.h();
},
l(nodes) {
div2 = claim_element(nodes, "DIV", { id: true, class: true });
var div2_nodes = children(div2);
div1 = claim_element(div2_nodes, "DIV", { class: true });
var div1_nodes = children(div1);
div0 = claim_element(div1_nodes, "DIV", {});
var div0_nodes = children(div0);
audio = claim_element(div0_nodes, "AUDIO", { src: true });
var audio_nodes = children(audio);
source = claim_element(audio_nodes, "SOURCE", { src: true, type: true });
audio_nodes.forEach(detach);
div0_nodes.forEach(detach);
t0 = claim_space(div1_nodes);
span0 = claim_element(div1_nodes, "SPAN", { class: true });
var span0_nodes = children(span0);
t1 = claim_text(span0_nodes, "label: ");
span0_nodes.forEach(detach);
span1 = claim_element(div1_nodes, "SPAN", { class: true });
var span1_nodes = children(span1);
t2 = claim_text(span1_nodes, t2_value);
span1_nodes.forEach(detach);
t3 = claim_space(div1_nodes);
if (if_block) if_block.l(div1_nodes);
div1_nodes.forEach(detach);
div2_nodes.forEach(detach);
this.h();
},
h() {
if (!src_url_equal(source.src, source_src_value = `${/*entry*/ ctx[0][/*dataColumn*/ ctx[3]]}`)) attr(source, "src", source_src_value);
attr(source, "type", source_type_value = "audio/" + /*entry*/ ctx[0][/*idColumn*/ ctx[4]].split(".").at(-1));
audio.controls = true;
if (!src_url_equal(audio.src, audio_src_value = `${/*entry*/ ctx[0][/*dataColumn*/ ctx[3]]}`)) attr(audio, "src", audio_src_value);
set_style(div0, "display", `flex`, false);
attr(span0, "class", "label svelte-1qkvlix");
attr(span1, "class", "value svelte-1qkvlix");
attr(div1, "class", "box svelte-1qkvlix");
attr(div2, "id", "container");
attr(div2, "class", "svelte-1qkvlix");
},
m(target, anchor) {
insert_hydration(target, div2, anchor);
append_hydration(div2, div1);
append_hydration(div1, div0);
append_hydration(div0, audio);
append_hydration(audio, source);
append_hydration(div1, t0);
append_hydration(div1, span0);
append_hydration(span0, t1);
append_hydration(div1, span1);
append_hydration(span1, t2);
append_hydration(div1, t3);
if (if_block) if_block.m(div1, null);
},
p(ctx, [dirty]) {
if (dirty & /*entry, dataColumn*/ 9 && !src_url_equal(source.src, source_src_value = `${/*entry*/ ctx[0][/*dataColumn*/ ctx[3]]}`)) {
attr(source, "src", source_src_value);
}
if (dirty & /*entry, idColumn*/ 17 && source_type_value !== (source_type_value = "audio/" + /*entry*/ ctx[0][/*idColumn*/ ctx[4]].split(".").at(-1))) {
attr(source, "type", source_type_value);
}
if (dirty & /*entry, dataColumn*/ 9 && !src_url_equal(audio.src, audio_src_value = `${/*entry*/ ctx[0][/*dataColumn*/ ctx[3]]}`)) {
attr(audio, "src", audio_src_value);
}
if (dirty & /*entry, labelColumn*/ 5 && t2_value !== (t2_value = /*entry*/ ctx[0][/*labelColumn*/ ctx[2]] + "")) set_data(t2, t2_value);
if (/*modelColumn*/ ctx[1] && /*entry*/ ctx[0][/*modelColumn*/ ctx[1]] !== undefined) {
if (if_block) {
if_block.p(ctx, dirty);
} else {
if_block = create_if_block(ctx);
if_block.c();
if_block.m(div1, null);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div2);
if (if_block) if_block.d();
}
};
}
function instance($$self, $$props, $$invalidate) {
let { entry } = $$props;
let { options } = $$props;
let { modelColumn } = $$props;
let { labelColumn } = $$props;
let { dataColumn } = $$props;
let { idColumn } = $$props;
$$self.$$set = $$props => {
if ('entry' in $$props) $$invalidate(0, entry = $$props.entry);
if ('options' in $$props) $$invalidate(5, options = $$props.options);
if ('modelColumn' in $$props) $$invalidate(1, modelColumn = $$props.modelColumn);
if ('labelColumn' in $$props) $$invalidate(2, labelColumn = $$props.labelColumn);
if ('dataColumn' in $$props) $$invalidate(3, dataColumn = $$props.dataColumn);
if ('idColumn' in $$props) $$invalidate(4, idColumn = $$props.idColumn);
};
return [entry, modelColumn, labelColumn, dataColumn, idColumn, options];
}
class InstanceView extends SvelteComponent {
constructor(options) {
super();
init(
this,
options,
instance,
create_fragment,
safe_not_equal,
{
entry: 0,
options: 5,
modelColumn: 1,
labelColumn: 2,
dataColumn: 3,
idColumn: 4
},
add_css
);
}
}
function getInstance(
div,
options,
entry,
modelColumn,
labelColumn,
dataColumn,
idColumn
) {
new InstanceView({
target: div,
props: {
entry: entry,
options: options,
modelColumn: modelColumn,
labelColumn: labelColumn,
dataColumn: dataColumn,
idColumn: idColumn,
},
hydrate: true,
});
}
export { getInstance };