-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hiccup-svg): update svg(), add convert attrib
- update attrib handling and call convertTree() if requested - update docstrings
- Loading branch information
1 parent
7dde29d
commit cd67a09
Showing
1 changed file
with
18 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
}; |