git ssb

1+

Matt McKegg / mutant



Tree: d21f00b20866259a0cc392aac18a581d68aa23be

Files: d21f00b20866259a0cc392aac18a581d68aa23be / svg-element.js

4688 bytesRaw
1const h = require('./html-element').forDocument(global.document, 'http://www.w3.org/2000/svg')
2const SVG_PROPERTIES = [
3 'about', 'accent-height', 'accumulate', 'additive', 'alignment-baseline', 'alphabetic', 'amplitude', 'arabic-form',
4 'ascent', 'attributeName', 'attributeType', 'azimuth', 'bandwidth', 'baseFrequency', 'baseProfile', 'baseline-shift',
5 'bbox', 'begin', 'bias', 'by', 'calcMode', 'cap-height', 'class', 'clip', 'clip-path', 'clip-rule', 'clipPathUnits',
6 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'content',
7 'contentScriptType', 'contentStyleType', 'cursor', 'cx', 'cy', 'd', 'datatype', 'defaultAction', 'descent', 'diffuseConstant',
8 'direction', 'display', 'divisor', 'dominant-baseline', 'dur', 'dx', 'dy', 'edgeMode', 'editable', 'elevation',
9 'enable-background', 'end', 'event', 'exponent', 'externalResourcesRequired', 'fill', 'fill-opacity', 'fill-rule',
10 'filter', 'filterRes', 'filterUnits', 'flood-color', 'flood-opacity', 'focusHighlight', 'focusable', 'font-family',
11 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'format', 'from',
12 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'glyphRef',
13 'gradientTransform', 'gradientUnits', 'handler', 'hanging', 'height', 'horiz-adv-x', 'horiz-origin-x', 'horiz-origin-y',
14 'id', 'ideographic', 'image-rendering', 'in', 'in2', 'initialVisibility', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4',
15 'kernelMatrix', 'kernelUnitLength', 'kerning', 'keyPoints', 'keySplines', 'keyTimes', 'lang', 'lengthAdjust', 'letter-spacing',
16 'lighting-color', 'limitingConeAngle', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerHeight', 'markerUnits',
17 'markerWidth', 'mask', 'maskContentUnits', 'maskUnits', 'mathematical', 'max', 'media', 'mediaCharacterEncoding',
18 'mediaContentEncodings', 'mediaSize', 'mediaTime', 'method', 'min', 'mode', 'name', 'nav-down', 'nav-down-left',
19 'nav-down-right', 'nav-left', 'nav-next', 'nav-prev', 'nav-right', 'nav-up', 'nav-up-left', 'nav-up-right', 'numOctaves',
20 'observer', 'offset', 'opacity', 'operator', 'order', 'orient', 'orientation', 'origin', 'overflow', 'overlay',
21 'overline-position', 'overline-thickness', 'panose-1', 'path', 'pathLength', 'patternContentUnits', 'patternTransform',
22 'patternUnits', 'phase', 'playbackOrder', 'pointer-events', 'points', 'pointsAtX', 'pointsAtY', 'pointsAtZ', 'preserveAlpha',
23 'preserveAspectRatio', 'primitiveUnits', 'propagate', 'property', 'r', 'radius', 'refX', 'refY', 'rel', 'rendering-intent',
24 'repeatCount', 'repeatDur', 'requiredExtensions', 'requiredFeatures', 'requiredFonts', 'requiredFormats', 'resource', 'restart',
25 'result', 'rev', 'role', 'rotate', 'rx', 'ry', 'scale', 'seed', 'shape-rendering', 'slope', 'snapshotTime', 'spacing',
26 'specularConstant', 'specularExponent', 'spreadMethod', 'startOffset', 'stdDeviation', 'stemh', 'stemv', 'stitchTiles',
27 'stop-color', 'stop-opacity', 'strikethrough-position', 'strikethrough-thickness', 'string', 'stroke', 'stroke-dasharray',
28 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'surfaceScale',
29 'syncBehavior', 'syncBehaviorDefault', 'syncMaster', 'syncTolerance', 'syncToleranceDefault', 'systemLanguage', 'tableValues',
30 'target', 'targetX', 'targetY', 'text-anchor', 'text-decoration', 'text-rendering', 'textLength', 'timelineBegin', 'title',
31 'to', 'transform', 'transformBehavior', 'type', 'typeof', 'u1', 'u2', 'underline-position', 'underline-thickness', 'unicode',
32 'unicode-bidi', 'unicode-range', 'units-per-em', 'v-alphabetic', 'v-hanging', 'v-ideographic', 'v-mathematical', 'values',
33 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'viewBox', 'viewTarget', 'visibility', 'width', 'widths',
34 'word-spacing', 'writing-mode', 'x', 'x-height', 'x1', 'x2', 'xChannelSelector', 'y', 'y1', 'y2', 'yChannelSelector', 'z', 'zoomAndPan'
35]
36
37module.exports = function (tag, properties, children) {
38 if (!children && (Array.isArray(properties) || isText(properties))) {
39 children = properties
40 properties = null
41 }
42
43 properties = properties || {}
44 properties.attributes = properties.attributes || {}
45
46 for (var key in properties) {
47 if (SVG_PROPERTIES.includes(key)) {
48 properties.attributes[key] = properties[key]
49 properties[key] = null
50 }
51 }
52
53 return h(tag, properties, children)
54}
55
56module.exports.destroy = require('./html-element').destroy
57
58function isText (value) {
59 return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'
60}
61

Built with git-ssb-web