Skip to content

Commit

Permalink
chore(TS): more text typings (fabricjs#8489)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea Bogazzi <andreabogazzi79@gmail.com>
  • Loading branch information
2 people authored and frankrousseau committed Jan 6, 2023
1 parent 30da09b commit eb7ecad
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 190 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): polish text [#8489](https://github.com/fabricjs/fabric.js/pull/8489)
- 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)
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/text_style.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export abstract class TextStyleMixin<
* @param {Number} lineIndex , lineIndex is on wrapped lines.
* @return {Boolean}
*/
isEmptyStyles(lineIndex: number): boolean {
isEmptyStyles(lineIndex?: number): boolean {
if (!this.styles) {
return true;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ export abstract class TextStyleMixin<
* @param {Number} lineIndex to check the style on
* @return {Boolean}
*/
styleHas(property: string, lineIndex: number): boolean {
styleHas(property: string, lineIndex?: number): boolean {
if (!this.styles || !property || property === '') {
return false;
}
Expand Down
16 changes: 10 additions & 6 deletions src/shapes/itext.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,16 @@ export class IText extends ITextClickBehaviorMixin<ITextEvents> {
* @returns {Promise<IText>}
*/
static fromObject(object: object): Promise<IText> {
const styles = stylesFromArray(object.styles, object.text);
//copy object to prevent mutation
const objCopy = Object.assign({}, object, { styles: styles });
return FabricObject._fromObject(IText, objCopy, {
extraParam: 'text',
});
return FabricObject._fromObject(
IText,
{
...object,
styles: stylesFromArray(object.styles, object.text),
},
{
extraParam: 'text',
}
);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/shapes/path.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
joinPath,
makePathSimpler,
parsePath,
type TPathSegmentsInfo,
} from '../util/path';
import { FabricObject, fabricObjectDefaultValues } from './fabricObject.class';

Expand All @@ -30,6 +31,8 @@ export class Path extends FabricObject {

sourcePath?: string;

segmentsInfo?: TPathSegmentsInfo[];

/**
* Constructor
* @param {Array|String} path Path data (sequence of coordinates and corresponding "command" tokens)
Expand Down

0 comments on commit eb7ecad

Please sign in to comment.