forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
50 lines (43 loc) · 2.53 KB
/
utils.js
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
HTMLTools = {};
HTMLTools.Parse = {};
var asciiLowerCase = HTMLTools.asciiLowerCase = function (str) {
return str.replace(/[A-Z]/g, function (c) {
return String.fromCharCode(c.charCodeAt(0) + 32);
});
};
var svgCamelCaseAttributes = 'attributeName attributeType baseFrequency baseProfile calcMode clipPathUnits contentScriptType contentStyleType diffuseConstant edgeMode externalResourcesRequired filterRes filterUnits glyphRef glyphRef gradientTransform gradientTransform gradientUnits gradientUnits kernelMatrix kernelUnitLength kernelUnitLength kernelUnitLength keyPoints keySplines keyTimes lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth maskContentUnits maskUnits numOctaves pathLength patternContentUnits patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur requiredExtensions requiredFeatures specularConstant specularExponent specularExponent spreadMethod spreadMethod startOffset stdDeviation stitchTiles surfaceScale surfaceScale systemLanguage tableValues targetX targetY textLength textLength viewBox viewTarget xChannelSelector yChannelSelector zoomAndPan'.split(' ');
var properAttributeCaseMap = (function (map) {
for (var i = 0; i < svgCamelCaseAttributes.length; i++) {
var a = svgCamelCaseAttributes[i];
map[asciiLowerCase(a)] = a;
}
return map;
})({});
var properTagCaseMap = (function (map) {
var knownElements = HTML.knownElementNames;
for (var i = 0; i < knownElements.length; i++) {
var a = knownElements[i];
map[asciiLowerCase(a)] = a;
}
return map;
})({});
// Take a tag name in any case and make it the proper case for HTML.
//
// Modern browsers let you embed SVG in HTML, but SVG elements are special
// in that they have a case-sensitive DOM API (nodeName, getAttribute,
// setAttribute). For example, it has to be `setAttribute("viewBox")`,
// not `"viewbox"`. However, the browser's HTML parser is NOT case sensitive
// and will fix the case for you, so if you write `<svg viewbox="...">`
// you actually get a `"viewBox"` attribute. Any HTML-parsing toolchain
// must do the same.
HTMLTools.properCaseTagName = function (name) {
var lowered = asciiLowerCase(name);
return properTagCaseMap.hasOwnProperty(lowered) ?
properTagCaseMap[lowered] : lowered;
};
// See docs for properCaseTagName.
HTMLTools.properCaseAttributeName = function (name) {
var lowered = asciiLowerCase(name);
return properAttributeCaseMap.hasOwnProperty(lowered) ?
properAttributeCaseMap[lowered] : lowered;
};