import HTMLElement from '../html-element/HTMLElement.js';
import DOMTokenList from '../../dom-token-list/DOMTokenList.js';
import HTMLLinkElementUtility from './HTMLLinkElementUtility.js';
/**
* HTML Link Element.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement.
*/
export default class HTMLLinkElement extends HTMLElement {
constructor() {
super(...arguments);
this.onerror = null;
this.onload = null;
this.sheet = null;
this._evaluateCSS = true;
this._relList = null;
}
/**
* Returns rel list.
*
* @returns Rel list.
*/
get relList() {
if (!this._relList) {
this._relList = new DOMTokenList(this, 'rel');
}
return this._relList;
}
/**
* Returns as.
*
* @returns As.
*/
get as() {
return this.getAttribute('as') || '';
}
/**
* Sets crossOrigin.
*
* @param crossOrigin CrossOrigin.
*/
set as(as) {
this.setAttribute('as', as);
}
/**
* Returns crossOrigin.
*
* @returns CrossOrigin.
*/
get crossOrigin() {
return this.getAttribute('crossorigin') || '';
}
/**
* Sets crossOrigin.
*
* @param crossOrigin CrossOrigin.
*/
set crossOrigin(crossOrigin) {
this.setAttribute('crossorigin', crossOrigin);
}
/**
* Returns href.
*
* @returns Href.
*/
get href() {
return this.getAttribute('href') || '';
}
/**
* Sets href.
*
* @param href Href.
*/
set href(href) {
this.setAttribute('href', href);
}
/**
* Returns hreflang.
*
* @returns Hreflang.
*/
get hreflang() {
return this.getAttribute('hreflang') || '';
}
/**
* Sets hreflang.
*
* @param hreflang Hreflang.
*/
set hreflang(hreflang) {
this.setAttribute('hreflang', hreflang);
}
/**
* Returns media.
*
* @returns Media.
*/
get media() {
return this.getAttribute('media') || '';
}
/**
* Sets media.
*
* @param media Media.
*/
set media(media) {
this.setAttribute('media', media);
}
/**
* Returns referrerPolicy.
*
* @returns ReferrerPolicy.
*/
get referrerPolicy() {
return this.getAttribute('referrerPolicy') || '';
}
/**
* Sets referrerPolicy.
*
* @param referrerPolicy ReferrerPolicy.
*/
set referrerPolicy(referrerPolicy) {
this.setAttribute('referrerPolicy', referrerPolicy);
}
/**
* Returns rel.
*
* @returns Rel.
*/
get rel() {
return this.getAttribute('rel') || '';
}
/**
* Sets rel.
*
* @param rel Rel.
*/
set rel(rel) {
this.setAttribute('rel', rel);
}
/**
* Returns type.
*
* @returns Type.
*/
get type() {
return this.getAttribute('type') || '';
}
/**
* Sets type.
*
* @param type Type.
*/
set type(type) {
this.setAttribute('type', type);
}
/**
* @override
*/
setAttributeNode(attribute) {
const replacedAttribute = super.setAttributeNode(attribute);
if (attribute.name === 'rel' && this._relList) {
this._relList._updateIndices();
}
if (attribute.name === 'rel' || attribute.name === 'href') {
HTMLLinkElementUtility.loadExternalStylesheet(this);
}
return replacedAttribute;
}
/**
* @override
*/
removeAttributeNode(attribute) {
super.removeAttributeNode(attribute);
if (attribute.name === 'rel' && this._relList) {
this._relList._updateIndices();
}
return attribute;
}
/**
* @override
*/
_connectToNode(parentNode = null) {
const isConnected = this.isConnected;
const isParentConnected = parentNode ? parentNode.isConnected : false;
super._connectToNode(parentNode);
if (isParentConnected && isConnected !== isParentConnected && this._evaluateCSS) {
HTMLLinkElementUtility.loadExternalStylesheet(this);
}
}
}
//# sourceMappingURL=HTMLLinkElement.js.map