Skip to content

Commit

Permalink
chore(TS): polish files and documentation , imports (#8488)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 authored Dec 8, 2022
1 parent 3b2b140 commit 2ffac9a
Show file tree
Hide file tree
Showing 39 changed files with 194 additions and 372 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 files [#8488](https://github.com/fabricjs/fabric.js/pull/8488)
- fix(TS): `EventSpec` recognition [#8497](https://github.com/fabricjs/fabric.js/pull/8497)
- chore(): rm dead code [#8493](https://github.com/fabricjs/fabric.js/pull/8493)
- fix(scaleObject): handle when scale is 0 to not bug flip [#8490](https://github.com/fabricjs/fabric.js/pull/8490)
Expand Down
2 changes: 1 addition & 1 deletion src/filters/removecolor_filter.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
*/
export class RemoveColor extends BaseFilter {
/**
* Color to remove, in any format understood by fabric.Color.
* Color to remove, in any format understood by {@link Color}.
* @param {String} type
* @default
*/
Expand Down
2 changes: 1 addition & 1 deletion src/gradient/gradient.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Gradient<
/* _TO_SVG_START_ */
/**
* Returns SVG representation of an gradient
* @param {fabric.Object} object Object to create a gradient for
* @param {FabricObject} object Object to create a gradient for
* @return {String} SVG representation of an gradient (linear/radial)
*/
toSVG(
Expand Down
36 changes: 17 additions & 19 deletions src/mixins/object_geometry.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export class ObjectGeometry<
* with lineCoords or oCoords in interactive cases but they do not need to be updated when zoom or panning change.
* The coordinates get updated with @method setCoords.
* You can calculate them without updating with @method calcACoords();
* @memberOf fabric.Object.prototype
*/
aCoords: TACoords;

Expand All @@ -88,7 +87,6 @@ export class ObjectGeometry<
* set and refreshed with setCoords.
* Those could go away
* @todo investigate how to get rid of those
* @memberOf fabric.Object.prototype
*/
lineCoords: TCornerPoint;

Expand All @@ -111,67 +109,67 @@ export class ObjectGeometry<
canvas?: StaticCanvas | Canvas;

/**
* @returns {number} x position according to object's {@link fabric.Object#originX} property in canvas coordinate plane
* @returns {number} x position according to object's {@link originX} property in canvas coordinate plane
*/
getX(): number {
return this.getXY().x;
}

/**
* @param {number} value x position according to object's {@link fabric.Object#originX} property in canvas coordinate plane
* @param {number} value x position according to object's {@link originX} property in canvas coordinate plane
*/
setX(value: number) {
this.setXY(this.getXY().setX(value));
}

/**
* @returns {number} y position according to object's {@link fabric.Object#originY} property in canvas coordinate plane
* @returns {number} y position according to object's {@link originY} property in canvas coordinate plane
*/
getY(): number {
return this.getXY().y;
}

/**
* @param {number} value y position according to object's {@link fabric.Object#originY} property in canvas coordinate plane
* @param {number} value y position according to object's {@link originY} property in canvas coordinate plane
*/
setY(value: number) {
this.setXY(this.getXY().setY(value));
}

/**
* @returns {number} x position according to object's {@link fabric.Object#originX} property in parent's coordinate plane\
* if parent is canvas then this property is identical to {@link fabric.Object#getX}
* @returns {number} x position according to object's {@link originX} property in parent's coordinate plane\
* if parent is canvas then this property is identical to {@link getX}
*/
getRelativeX(): number {
return this.left;
}

/**
* @param {number} value x position according to object's {@link fabric.Object#originX} property in parent's coordinate plane\
* if parent is canvas then this method is identical to {@link fabric.Object#setX}
* @param {number} value x position according to object's {@link originX} property in parent's coordinate plane\
* if parent is canvas then this method is identical to {@link setX}
*/
setRelativeX(value: number) {
this.left = value;
}

/**
* @returns {number} y position according to object's {@link fabric.Object#originY} property in parent's coordinate plane\
* if parent is canvas then this property is identical to {@link fabric.Object#getY}
* @returns {number} y position according to object's {@link originY} property in parent's coordinate plane\
* if parent is canvas then this property is identical to {@link getY}
*/
getRelativeY(): number {
return this.top;
}

/**
* @param {number} value y position according to object's {@link fabric.Object#originY} property in parent's coordinate plane\
* if parent is canvas then this property is identical to {@link fabric.Object#setY}
* @param {number} value y position according to object's {@link originY} property in parent's coordinate plane\
* if parent is canvas then this property is identical to {@link setY}
*/
setRelativeY(value: number) {
this.top = value;
}

/**
* @returns {Point} x position according to object's {@link fabric.Object#originX} {@link fabric.Object#originY} properties in canvas coordinate plane
* @returns {Point} x position according to object's {@link originX} {@link originY} properties in canvas coordinate plane
*/
getXY(): Point {
const relativePosition = this.getRelativeXY();
Expand All @@ -182,7 +180,7 @@ export class ObjectGeometry<

/**
* Set an object position to a particular point, the point is intended in absolute ( canvas ) coordinate.
* You can specify {@link fabric.Object#originX} and {@link fabric.Object#originY} values,
* You can specify {@link originX} and {@link originY} values,
* that otherwise are the object's current values.
* @example <caption>Set object's bottom left corner to point (5,5) on canvas</caption>
* object.setXY(new Point(5, 5), 'left', 'bottom').
Expand All @@ -201,15 +199,15 @@ export class ObjectGeometry<
}

/**
* @returns {Point} x,y position according to object's {@link fabric.Object#originX} {@link fabric.Object#originY} properties in parent's coordinate plane
* @returns {Point} x,y position according to object's {@link originX} {@link originY} properties in parent's coordinate plane
*/
getRelativeXY(): Point {
return new Point(this.left, this.top);
}

/**
* As {@link fabric.Object#setXY}, but in current parent's coordinate plane ( the current group if any or the canvas)
* @param {Point} point position according to object's {@link fabric.Object#originX} {@link fabric.Object#originY} properties in parent's coordinate plane
* As {@link setXY}, but in current parent's coordinate plane (the current group if any or the canvas)
* @param {Point} point position according to object's {@link originX} {@link originY} properties in parent's coordinate plane
* @param {TOriginX} [originX] Horizontal origin: 'left', 'center' or 'right'
* @param {TOriginY} [originY] Vertical origin: 'top', 'center' or 'bottom'
*/
Expand Down
1 change: 0 additions & 1 deletion src/mixins/object_interactivity.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class InteractiveFabricObject<
* interactive area of the corner.
* The coordinates depends from the controls positionHandler and are used
* to draw and locate controls
* @memberOf fabric.Object.prototype
*/
oCoords: Record<string, TOCoord> = {};

Expand Down
4 changes: 0 additions & 4 deletions src/mixins/shared_methods.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class CommonMethods<EventSpec> extends Observable<EventSpec> {
* Sets property to a given value. When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls. If you need to update those, call `setCoords()`.
* @param {String|Object} key Property name or object (if object, iterate over the object properties)
* @param {Object|Function} value Property value (if function, the value is passed into it and its return value is used as a new one)
* @return {fabric.Object} thisArg
* @chainable
*/
set(key: string | Record<string, any>, value?: any) {
if (typeof key === 'object') {
Expand All @@ -44,8 +42,6 @@ export class CommonMethods<EventSpec> extends Observable<EventSpec> {
/**
* Toggles specified property from `true` to `false` or from `false` to `true`
* @param {String} property Property to toggle
* @return {fabric.Object} thisArg
* @chainable
*/
toggle(property: string) {
const value = this.get(property);
Expand Down
24 changes: 13 additions & 11 deletions src/parser/elements_parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@ts-nocheck

import { fabric } from '../../HEADER';
import { Gradient } from '../gradient';
import { Group } from '../shapes/group.class';
import { Image } from '../shapes/image.class';
import { capitalize } from '../util/lang_string';
import {
invertTransform,
Expand Down Expand Up @@ -58,19 +61,18 @@ const ElementsParser = function (
};

proto.createCallback = function (index, el) {
const _this = this;
return function (obj) {
return (obj) => {
let _options;
_this.resolveGradient(obj, el, 'fill');
_this.resolveGradient(obj, el, 'stroke');
if (obj instanceof fabric.Image && obj._originalElement) {
this.resolveGradient(obj, el, 'fill');
this.resolveGradient(obj, el, 'stroke');
if (obj instanceof Image && obj._originalElement) {
_options = obj.parsePreserveAspectRatioAttribute(el);
}
obj._removeTransformMatrix(_options);
_this.resolveClipPath(obj, el);
_this.reviver && _this.reviver(el, obj);
_this.instances[index] = obj;
_this.checkIfDone();
this.resolveClipPath(obj, el);
this.reviver && this.reviver(el, obj);
this.instances[index] = obj;
this.checkIfDone();
};
};

Expand All @@ -94,7 +96,7 @@ const ElementsParser = function (
);
if (gradientDef) {
const opacityAttr = el.getAttribute(property + '-opacity');
const gradient = fabric.Gradient.fromElement(gradientDef, obj, {
const gradient = Gradient.fromElement(gradientDef, obj, {
...this.options,
opacity: opacityAttr,
});
Expand Down Expand Up @@ -143,7 +145,7 @@ const ElementsParser = function (
if (container.length === 1) {
clipPath = container[0];
} else {
clipPath = new fabric.Group(container);
clipPath = new Group(container);
}
gTransform = multiplyTransformMatrices(
objTransformInv,
Expand Down
3 changes: 2 additions & 1 deletion src/shapes/group.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { applyTransformToObject } from '../util/misc/objectTransforms';
import { degreesToRadians } from '../util/misc/radiansDegreesConversion';
import { sin } from '../util/misc/sin';
import { FabricObject, fabricObjectDefaultValues } from './fabricObject.class';
import { Rect } from './rect.class';

export type LayoutContextType =
| 'initialization'
Expand Down Expand Up @@ -985,7 +986,7 @@ export class Group extends createCollectionMixin(FabricObject<GroupEvents>) {
if (!this.backgroundColor) {
return '';
}
const fillStroke = fabric.Rect.prototype._toSVG.call(this, reviver);
const fillStroke = Rect.prototype._toSVG.call(this, reviver);
const commons = fillStroke.indexOf('COMMON_PARTS');
fillStroke[commons] = 'for="group" ';
return fillStroke.join('');
Expand Down
Loading

0 comments on commit 2ffac9a

Please sign in to comment.