Skip to content

Commit d51ee9d

Browse files
committed
Build SVG aliases dynamically
1 parent 49d4c5a commit d51ee9d

File tree

1 file changed

+93
-107
lines changed

1 file changed

+93
-107
lines changed

src/renderers/dom/shared/SVGDOMPropertyConfig.js

Lines changed: 93 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -16,108 +16,91 @@ var NS = {
1616
xml: 'http://www.w3.org/XML/1998/namespace',
1717
};
1818

19-
// We use attributes for everything SVG so let's avoid some duplication and run
20-
// code instead.
21-
// The following are all specified in the HTML config already so we exclude here.
22-
// - class (as className)
23-
// - color
24-
// - height
25-
// - id
26-
// - lang
27-
// - max
28-
// - media
29-
// - method
30-
// - min
31-
// - name
32-
// - style
33-
// - target
34-
// - type
35-
// - width
36-
var ATTRS = {
37-
accentHeight: 'accent-height',
38-
alignmentBaseline: 'alignment-baseline',
39-
arabicForm: 'arabic-form',
40-
baselineShift: 'baseline-shift',
41-
capHeight: 'cap-height',
42-
clipPath: 'clip-path',
43-
clipRule: 'clip-rule',
44-
colorInterpolation: 'color-interpolation',
45-
colorInterpolationFilters: 'color-interpolation-filters',
46-
colorProfile: 'color-profile',
47-
colorRendering: 'color-rendering',
48-
dominantBaseline: 'dominant-baseline',
49-
enableBackground: 'enable-background',
50-
fillOpacity: 'fill-opacity',
51-
fillRule: 'fill-rule',
52-
floodColor: 'flood-color',
53-
floodOpacity: 'flood-opacity',
54-
fontFamily: 'font-family',
55-
fontSize: 'font-size',
56-
fontSizeAdjust: 'font-size-adjust',
57-
fontStretch: 'font-stretch',
58-
fontStyle: 'font-style',
59-
fontVariant: 'font-variant',
60-
fontWeight: 'font-weight',
61-
glyphName: 'glyph-name',
62-
glyphOrientationHorizontal: 'glyph-orientation-horizontal',
63-
glyphOrientationVertical: 'glyph-orientation-vertical',
64-
horizAdvX: 'horiz-adv-x',
65-
horizOriginX: 'horiz-origin-x',
66-
imageRendering: 'image-rendering',
67-
letterSpacing: 'letter-spacing',
68-
lightingColor: 'lighting-color',
69-
markerEnd: 'marker-end',
70-
markerMid: 'marker-mid',
71-
markerStart: 'marker-start',
72-
overlinePosition: 'overline-position',
73-
overlineThickness: 'overline-thickness',
74-
paintOrder: 'paint-order',
75-
panose1: 'panose-1',
76-
pointerEvents: 'pointer-events',
77-
renderingIntent: 'rendering-intent',
78-
shapeRendering: 'shape-rendering',
79-
stopColor: 'stop-color',
80-
stopOpacity: 'stop-opacity',
81-
strikethroughPosition: 'strikethrough-position',
82-
strikethroughThickness: 'strikethrough-thickness',
83-
strokeDasharray: 'stroke-dasharray',
84-
strokeDashoffset: 'stroke-dashoffset',
85-
strokeLinecap: 'stroke-linecap',
86-
strokeLinejoin: 'stroke-linejoin',
87-
strokeMiterlimit: 'stroke-miterlimit',
88-
strokeOpacity: 'stroke-opacity',
89-
strokeWidth: 'stroke-width',
90-
textAnchor: 'text-anchor',
91-
textDecoration: 'text-decoration',
92-
textRendering: 'text-rendering',
93-
underlinePosition: 'underline-position',
94-
underlineThickness: 'underline-thickness',
95-
unicodeBidi: 'unicode-bidi',
96-
unicodeRange: 'unicode-range',
97-
unitsPerEm: 'units-per-em',
98-
vAlphabetic: 'v-alphabetic',
99-
vHanging: 'v-hanging',
100-
vIdeographic: 'v-ideographic',
101-
vMathematical: 'v-mathematical',
102-
vectorEffect: 'vector-effect',
103-
vertAdvY: 'vert-adv-y',
104-
vertOriginX: 'vert-origin-x',
105-
vertOriginY: 'vert-origin-y',
106-
wordSpacing: 'word-spacing',
107-
writingMode: 'writing-mode',
108-
xHeight: 'x-height',
109-
xlinkActuate: 'xlink:actuate',
110-
xlinkArcrole: 'xlink:arcrole',
111-
xlinkHref: 'xlink:href',
112-
xlinkRole: 'xlink:role',
113-
xlinkShow: 'xlink:show',
114-
xlinkTitle: 'xlink:title',
115-
xlinkType: 'xlink:type',
116-
xmlBase: 'xml:base',
117-
xmlnsXlink: 'xmlns:xlink',
118-
xmlLang: 'xml:lang',
119-
xmlSpace: 'xml:space',
120-
};
19+
var ATTRS = [
20+
'accent-height',
21+
'alignment-baseline',
22+
'arabic-form',
23+
'baseline-shift',
24+
'cap-height',
25+
'clip-path',
26+
'clip-rule',
27+
'color-interpolation',
28+
'color-interpolation-filters',
29+
'color-profile',
30+
'color-rendering',
31+
'dominant-baseline',
32+
'enable-background',
33+
'fill-opacity',
34+
'fill-rule',
35+
'flood-color',
36+
'flood-opacity',
37+
'font-family',
38+
'font-size',
39+
'font-size-adjust',
40+
'font-stretch',
41+
'font-style',
42+
'font-variant',
43+
'font-weight',
44+
'glyph-name',
45+
'glyph-orientation-horizontal',
46+
'glyph-orientation-vertical',
47+
'horiz-adv-x',
48+
'horiz-origin-x',
49+
'image-rendering',
50+
'letter-spacing',
51+
'lighting-color',
52+
'marker-end',
53+
'marker-mid',
54+
'marker-start',
55+
'overline-position',
56+
'overline-thickness',
57+
'paint-order',
58+
'panose-1',
59+
'pointer-events',
60+
'rendering-intent',
61+
'shape-rendering',
62+
'stop-color',
63+
'stop-opacity',
64+
'strikethrough-position',
65+
'strikethrough-thickness',
66+
'stroke-dasharray',
67+
'stroke-dashoffset',
68+
'stroke-linecap',
69+
'stroke-linejoin',
70+
'stroke-miterlimit',
71+
'stroke-opacity',
72+
'stroke-width',
73+
'text-anchor',
74+
'text-decoration',
75+
'text-rendering',
76+
'underline-position',
77+
'underline-thickness',
78+
'unicode-bidi',
79+
'unicode-range',
80+
'units-per-em',
81+
'v-alphabetic',
82+
'v-hanging',
83+
'v-ideographic',
84+
'v-mathematical',
85+
'vector-effect',
86+
'vert-adv-y',
87+
'vert-origin-x',
88+
'vert-origin-y',
89+
'word-spacing',
90+
'writing-mode',
91+
'x-height',
92+
'xlink:actuate',
93+
'xlink:arcrole',
94+
'xlink:href',
95+
'xlink:role',
96+
'xlink:show',
97+
'xlink:title',
98+
'xlink:type',
99+
'xml:base',
100+
'xmlns:xlink',
101+
'xml:lang',
102+
'xml:space',
103+
];
121104

122105
var SVGDOMPropertyConfig = {
123106
Properties: {},
@@ -136,11 +119,14 @@ var SVGDOMPropertyConfig = {
136119
DOMAttributeNames: {},
137120
};
138121

139-
Object.keys(ATTRS).forEach(key => {
140-
SVGDOMPropertyConfig.Properties[key] = 0;
141-
if (ATTRS[key]) {
142-
SVGDOMPropertyConfig.DOMAttributeNames[key] = ATTRS[key];
143-
}
122+
var CAMELIZE = /[\-\:]([a-z])/g;
123+
var capitalize = token => token[1].toUpperCase();
124+
125+
ATTRS.forEach(original => {
126+
var reactName = original.replace(CAMELIZE, capitalize);
127+
128+
SVGDOMPropertyConfig.Properties[reactName] = 0;
129+
SVGDOMPropertyConfig.DOMAttributeNames[reactName] = original;
144130
});
145131

146132
module.exports = SVGDOMPropertyConfig;

0 commit comments

Comments
 (0)