-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathprops.ts
75 lines (65 loc) · 1.96 KB
/
props.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* @method normalizeProperty
* @param element {HTMLElement}
* @param slotName {String}
* @returns {Object} { name, type }
*/
export function normalizeProperty(element, slotName) {
let type, normalized;
if (slotName in element) {
normalized = slotName;
type = 'prop';
} else {
let lower = slotName.toLowerCase();
if (lower in element) {
type = 'prop';
normalized = lower;
} else {
type = 'attr';
normalized = slotName;
}
}
if (type === 'prop' &&
(normalized.toLowerCase() === 'style' ||
preferAttr(element.tagName, normalized))) {
type = 'attr';
}
return { normalized, type };
}
export function normalizePropertyValue(value) {
if (value === '') {
return true;
}
return value;
}
// properties that MUST be set as attributes, due to:
// * browser bug
// * strange spec outlier
const ATTR_OVERRIDES = {
// phantomjs < 2.0 lets you set it as a prop but won't reflect it
// back to the attribute. button.getAttribute('type') === null
BUTTON: { type: true, form: true },
INPUT: {
// Some version of IE (like IE9) actually throw an exception
// if you set input.type = 'something-unknown'
type: true,
form: true,
// Chrome 46.0.2464.0: 'autocorrect' in document.createElement('input') === false
// Safari 8.0.7: 'autocorrect' in document.createElement('input') === false
// Mobile Safari (iOS 8.4 simulator): 'autocorrect' in document.createElement('input') === true
autocorrect: true
},
// element.form is actually a legitimate readOnly property, that is to be
// mutated, but must be mutated by setAttribute...
SELECT: { form: true },
OPTION: { form: true },
TEXTAREA: { form: true },
LABEL: { form: true },
FIELDSET: { form: true },
LEGEND: { form: true },
OBJECT: { form: true }
};
function preferAttr(tagName, propName) {
let tag = ATTR_OVERRIDES[tagName.toUpperCase()];
return tag && tag[propName.toLowerCase()] || false;
}