Skip to content

Commit

Permalink
feat(hiccup-svg): update svg(), add convert attrib
Browse files Browse the repository at this point in the history
- update attrib handling and call convertTree() if requested
- update docstrings
  • Loading branch information
postspectacular committed Dec 30, 2020
1 parent 7dde29d commit cd67a09
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/hiccup-svg/src/svg.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import { XML_SVG, XML_XLINK } from "@thi.ng/prefixes";
import { convertTree } from "./convert";
import { fattribs } from "./format";

/**
* Defines an <svg> root element with default XML namespaces. By default
* currently still sets SVG version to 1.1 to support Safari and other
* legacy tooling.
* currently still sets SVG version to 1.1 to support Safari and other legacy
* tooling.
*
* @remarks
* If the `convert: true` attrib is given, all body elements will be
* automatically converted using {@link convertTree}. The `convert` attrib is
* NOT going to be serialized in the final output.
*
* @param attribs - attributes object
* @param body - shape primitives
*/
export const svg = (attribs: any, ...body: any[]): any[] => [
"svg",
fattribs({
export const svg = (attribs: any, ...body: any[]): any[] => {
attribs = fattribs({
version: "1.1",
xmlns: XML_SVG,
"xmlns:xlink": XML_XLINK,
...attribs,
}),
...body,
];
});
if (attribs.convert) {
delete attribs.convert;
return ["svg", attribs, ...body.map(convertTree)];
} else {
return ["svg", attribs, ...body];
}
};

0 comments on commit cd67a09

Please sign in to comment.