Skip to content

Commit

Permalink
chore(): move groupSvgElements to its own util file to help with impo…
Browse files Browse the repository at this point in the history
…rt tree (fabricjs#8506)
  • Loading branch information
ShaMan123 authored and frankrousseau committed Jan 6, 2023
1 parent bfb5d46 commit 30da09b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- chore(TS): fix import cycle, extract `groupSVGElements` [#8506](https://github.com/fabricjs/fabric.js/pull/8506)
- chore(TS): permissive `Point` typings [#8434](https://github.com/fabricjs/fabric.js/pull/8434)
- chore(TS): polish files [#8488](https://github.com/fabricjs/fabric.js/pull/8488)
- fix(TS): `EventSpec` recognition [#8497](https://github.com/fabricjs/fabric.js/pull/8497)
Expand Down
15 changes: 15 additions & 0 deletions src/util/misc/groupSVGElements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FabricObject } from '../../shapes/fabricObject.class';
import { Group } from '../../shapes/group.class';

/**
* Groups SVG elements (usually those retrieved from SVG document)
* @static
* @param {FabricObject[]} elements FabricObject(s) parsed from svg, to group
* @return {FabricObject | Group}
*/
export const groupSVGElements = (elements: FabricObject[]) => {
if (elements && elements.length === 1) {
return elements[0];
}
return new Group(elements);
};
2 changes: 1 addition & 1 deletion src/util/misc/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import { toFixed } from './toFixed';
import {
matrixToSVG,
parsePreserveAspectRatioAttribute,
groupSVGElements,
parseUnit,
getSvgAttributes,
} from './svgParsing';
import { groupSVGElements } from './groupSVGElements';
import { findScaleToFit, findScaleToCover } from './findScaleTo';
import { capValue } from './capValue';
import {
Expand Down
15 changes: 0 additions & 15 deletions src/util/misc/svgParsing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { config } from '../../config';
import { DEFAULT_SVG_FONT_SIZE } from '../../constants';
import type { FabricObject } from '../../shapes/fabricObject.class';
import { Group } from '../../shapes/group.class';
import { SupportedSVGUnit, SVGElementName, TMat2D } from '../../typedefs';
import { toFixed } from './toFixed';
/**
Expand Down Expand Up @@ -76,19 +74,6 @@ export const parseUnit = (value: string, fontSize: number) => {
}
};

/**
* Groups SVG elements (usually those retrieved from SVG document)
* @static
* @param {FabricObject[]} elements FabricObject(s) parsed from svg, to group
* @return {FabricObject | Group}
*/
export const groupSVGElements = (elements: FabricObject[]) => {
if (elements && elements.length === 1) {
return elements[0];
}
return new Group(elements);
};

const enum MeetOrSlice {
meet = 'meet',
slice = 'slice',
Expand Down

0 comments on commit 30da09b

Please sign in to comment.