@soil/dom
Version:
Declaratively create type-safe HTML and SVG elements.
85 lines • 2.67 kB
JavaScript
import { addChildren } from '../addChildren';
import { assignProps } from '../../../shared/functions/assignProps';
/**
* Factory function for SVG elements.
*/
function svg(tag) {
return function (props, children) {
var elem = document.createElementNS('http://www.w3.org/2000/svg', tag);
if (props !== undefined) {
assignProps(elem, props);
}
if (children !== undefined) {
addChildren(elem, children);
}
return elem;
};
}
/**
* Helpers to facilitate the concise creation of any SVG element.
*
* NOTE The following functions silently depend on the `document` variable
* being globally available. Therefore, unit tests of components that use them
* must be run inside a browser, or must expose `document` globally, e.g.
* through PhantomJS or jsdom.
*/
export var s = {
a: svg('a'),
circle: svg('circle'),
clipPath: svg('clipPath'),
defs: svg('defs'),
desc: svg('desc'),
ellipse: svg('ellipse'),
feBlend: svg('feBlend'),
feColorMatrix: svg('feColorMatrix'),
feComponentTransfer: svg('feComponentTransfer'),
feComposite: svg('feComposite'),
feConvolveMatrix: svg('feConvolveMatrix'),
feDiffuseLighting: svg('feDiffuseLighting'),
feDisplacementMap: svg('feDisplacementMap'),
feDistantLight: svg('feDistantLight'),
feFlood: svg('feFlood'),
feFuncA: svg('feFuncA'),
feFuncB: svg('feFuncB'),
feFuncG: svg('feFuncG'),
feFuncR: svg('feFuncR'),
feGaussianBlur: svg('feGaussianBlur'),
feImage: svg('feImage'),
feMerge: svg('feMerge'),
feMergeNode: svg('feMergeNode'),
feMorphology: svg('feMorphology'),
feOffset: svg('feOffset'),
fePointLight: svg('fePointLight'),
feSpecularLighting: svg('feSpecularLighting'),
feSpotLight: svg('feSpotLight'),
feTile: svg('feTile'),
feTurbulence: svg('feTurbulence'),
filter: svg('filter'),
foreignObject: svg('foreignObject'),
g: svg('g'),
image: svg('image'),
line: svg('line'),
linearGradient: svg('linearGradient'),
marker: svg('marker'),
mask: svg('mask'),
metadata: svg('metadata'),
path: svg('path'),
pattern: svg('pattern'),
polygon: svg('polygon'),
polyline: svg('polyline'),
radialGradient: svg('radialGradient'),
rect: svg('rect'),
script: svg('script'),
stop: svg('stop'),
style: svg('style'),
svg: svg('svg'),
switch: svg('switch'),
symbol: svg('symbol'),
text: svg('text'),
textPath: svg('textPath'),
title: svg('title'),
tspan: svg('tspan'),
use: svg('use'),
view: svg('view'),
};
//# sourceMappingURL=s.js.map