(function(window) {
/*jshint maxlen:false*/
'use strict';
var proto = Object.create(HTMLElement.prototype);
injectGlobalStyles();
proto.createdCallback = function() {
var shadowRoot = this.createShadowRoot();
shadowRoot.innerHTML =
`
`;
var $id = shadowRoot.getElementById.bind(shadowRoot);
this.els = {
container: $id('container'),
spinner: $id('spinner'),
value: $id('value'),
heading: $id('heading'),
subheading: $id('subheading')
};
if (!this.hasAttribute('value') && !this.hasAttribute('heading') &&
!this.hasAttribute('subheading')) {
this.els.container.hidden = true;
}
this.value = this.getAttribute('value');
this.heading = this.getAttribute('heading');
this.subheading = this.getAttribute('subheading');
this.onDOMRetranslated = () => {
document.l10n.translateFragment(shadowRoot);
};
};
proto.attachedCallback = function() {
document.addEventListener('DOMRetranslated', this.onDOMRetranslated);
this.onDOMRetranslated();
};
proto.detachedCallback = function() {
document.removeEventListener('DOMRetranslated', this.onDOMRetranslated);
};
proto.attributeChangedCallback = function(attr, oldVal, newVal) {
var promise;
var l10nId = this.getAttribute(attr + '-l10n-id');
if (!newVal && l10nId) {
promise = document.l10n.formatValues(l10nId);
} else {
promise = Promise.resolve();
}
promise.then(() => {
switch (attr) {
case 'value':
this.els.value.textContent = newVal;
break;
case 'heading':
this.els.heading.textContent = newVal;
break;
case 'subheading':
this.els.subheading.textContent = newVal;
break;
}
});
};
proto.update = function(properties = {}) {
this.value = properties.value || this.value;
this.heading = properties.heading || this.heading;
this.subheading = properties.subheading || this.subheading;
this.els.container.hidden = false;
};
proto.clear = function() {
this.els.container.hidden = true;
};
['value', 'heading', 'subheading'].forEach((prop) => {
Object.defineProperty(proto, prop, {
get: function() {
return this.getAttribute(prop);
},
set: function(value) {
this.setAttribute(prop, value || '');
}
});
});
function injectGlobalStyles() {
var style = document.createElement('style');
style.innerHTML =
`@keyframes music-scan-progress-spinner {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}`;
document.head.appendChild(style);
}
try {
window.MusicScanProgress = document.registerElement('music-scan-progress', {
prototype: proto
});
} catch (e) {
if (e.name !== 'NotSupportedError') {
throw e;
}
}
})(window);