from static method
Implementation
static DOMAttribute? from(String? name, Object? value) {
name = normalizeName(name);
if (name == null) return null;
if (value is String && DOMTemplate.possiblyATemplate(value)) {
var template = DOMTemplate.parse(value);
if (!template.hasOnlyContent) {
return DOMAttribute(name, DOMAttributeValueTemplate(value));
}
}
if (name == 'style') {
return DOMAttribute(name, DOMAttributeValueCSS(value));
}
var delimiter = _attributesValueAsListDelimiters[name];
if (delimiter != null) {
var delimiterPattern = _attributesValueAsListDelimitersPatterns[name]!;
var attrSet = _attributesValueAsSet.contains(name);
if (attrSet) {
return DOMAttribute(
name, DOMAttributeValueSet(value, delimiter, delimiterPattern));
} else {
return DOMAttribute(
name, DOMAttributeValueList(value, delimiter, delimiterPattern));
}
} else {
var attrBoolean = _attributesValueAsBoolean.contains(name);
if (attrBoolean) {
if (value != null) {
// An empty value for a boolean attribute should be treated as true:
var attrValue = (value is String && value.isEmpty)
? DOMAttributeValueBoolean(true)
: DOMAttributeValueBoolean(value);
return DOMAttribute(name, attrValue);
}
return null;
} else {
return DOMAttribute(name, DOMAttributeValueString(value));
}
}
}