Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
938 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | exports.name = 'convertEllipseToCircle';
|
---|
| 4 | exports.type = 'visitor';
|
---|
| 5 | exports.active = true;
|
---|
| 6 | exports.description = 'converts non-eccentric <ellipse>s to <circle>s';
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Converts non-eccentric <ellipse>s to <circle>s.
|
---|
| 10 | *
|
---|
| 11 | * @see https://www.w3.org/TR/SVG11/shapes.html
|
---|
| 12 | *
|
---|
| 13 | * @author Taylor Hunt
|
---|
| 14 | *
|
---|
| 15 | * @type {import('../lib/types').Plugin<void>}
|
---|
| 16 | */
|
---|
| 17 | exports.fn = () => {
|
---|
| 18 | return {
|
---|
| 19 | element: {
|
---|
| 20 | enter: (node) => {
|
---|
| 21 | if (node.name === 'ellipse') {
|
---|
| 22 | const rx = node.attributes.rx || '0';
|
---|
| 23 | const ry = node.attributes.ry || '0';
|
---|
| 24 | if (
|
---|
| 25 | rx === ry ||
|
---|
| 26 | rx === 'auto' ||
|
---|
| 27 | ry === 'auto' // SVG2
|
---|
| 28 | ) {
|
---|
| 29 | node.name = 'circle';
|
---|
| 30 | const radius = rx === 'auto' ? ry : rx;
|
---|
| 31 | delete node.attributes.rx;
|
---|
| 32 | delete node.attributes.ry;
|
---|
| 33 | node.attributes.r = radius;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 | },
|
---|
| 37 | },
|
---|
| 38 | };
|
---|
| 39 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.