Skip to content

Commit

Permalink
chore(TS) Converting Object to a class (#8322)
Browse files Browse the repository at this point in the history
* Observable changes to TS class from @ShaMan123 (#8330)

Co-authored-by: ShaMan123 <[email protected]>
Co-authored-by: Shachar <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2022
1 parent a7e3cbb commit 8235106
Show file tree
Hide file tree
Showing 35 changed files with 2,579 additions and 2,377 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): convert object to es6 class [#8322](https://github.com/fabricjs/fabric.js/pull/8322)
- docs(): guides follow up, feature request template [#8379](https://github.com/fabricjs/fabric.js/pull/8379)
- docs(): refactor guides, bug report template [#8189](https://github.com/fabricjs/fabric.js/pull/8189)
- BREAKING fix(polyline/polygon): stroke bounding box for all line join/cap cases [#8344](https://github.com/fabricjs/fabric.js/pull/8344)
Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import './HEADER';
// import './lib/event'), // optional gestures
import './src/mixins/observable.mixin';
import './src/mixins/collection.mixin';
import './src/mixins/shared_methods.mixin';
import './src/util/misc/misc';
// import './src/util/named_accessors.mixin'; i would imagine dead forever or proper setters/getters
import './src/parser'; // optional parser
Expand Down
3 changes: 2 additions & 1 deletion src/canvas.class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ts-nocheck
import { Point } from './point.class';
import { FabricObject } from './shapes/object.class';

(function (global) {
var fabric = global.fabric,
Expand Down Expand Up @@ -871,7 +872,7 @@ import { Point } from './point.class';
maxX -= strokeOffset;
maxY -= strokeOffset;
// selection border
fabric.Object.prototype._setLineDash.call(
FabricObject.prototype._setLineDash.call(
this,
ctx,
this.selectionDashArray
Expand Down
4 changes: 3 additions & 1 deletion src/controls/default_controls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ts-nocheck
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric,
controlsUtils = fabric.controlsUtils,
Expand All @@ -8,7 +10,7 @@
scalingYOrSkewingX = controlsUtils.scalingYOrSkewingX,
scalingXOrSkewingY = controlsUtils.scalingXOrSkewingY,
scaleOrSkewActionName = controlsUtils.scaleOrSkewActionName,
objectControls = fabric.Object.prototype.controls;
objectControls = FabricObject.prototype.controls;

objectControls.ml = new fabric.Control({
x: -0.5,
Expand Down
9 changes: 3 additions & 6 deletions src/gradient/gradient.class.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { fabric } from '../../HEADER';
import { Color } from '../color';
import { iMatrix } from '../constants';
Expand All @@ -20,11 +21,7 @@ import {
GradientUnits,
SVGOptions,
} from './typedefs';

/**
* @todo remove this transient junk
*/
type FabricObject = any;
import { FabricObject } from '../shapes/object.class';

/**
* Gradient class
Expand Down Expand Up @@ -93,7 +90,7 @@ export class Gradient<
gradientTransform,
id,
}: GradientOptions<T>) {
const uid = fabric.Object.__uid++;
const uid = FabricObject.__uid++;
this.id = id ? `${id}_${uid}` : uid;
this.type = type;
this.gradientUnits = gradientUnits;
Expand Down
6 changes: 4 additions & 2 deletions src/mixins/animation.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ts-nocheck
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric;
fabric.util.object.extend(
Expand Down Expand Up @@ -113,8 +115,8 @@
);

fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Animates object's properties
* @param {String|Object} property Property to animate (if string) or properties to animate (if object)
Expand Down
3 changes: 2 additions & 1 deletion src/mixins/itext.svg_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Color } from '../color';
import { config } from '../config';
import { FabricObject } from '../shapes/object.class';

/* _TO_SVG_START_ */
(function (global) {
Expand Down Expand Up @@ -323,7 +324,7 @@ import { config } from '../config';
* @return {String}
*/
getSvgStyles: function (skipShadow) {
var svgStyle = fabric.Object.prototype.getSvgStyles.call(
var svgStyle = FabricObject.prototype.getSvgStyles.call(
this,
skipShadow
);
Expand Down
7 changes: 4 additions & 3 deletions src/mixins/object.svg_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Color } from '../color';
import { config } from '../config';
import { FabricObject } from '../shapes/object.class';

/* _TO_SVG_START_ */
(function (global) {
Expand All @@ -27,8 +28,8 @@ import { config } from '../config';
toFixed = fabric.util.toFixed;

fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Returns styles-string for svg-export
* @param {Boolean} skipShadow a boolean to skip shadow filter output
Expand Down Expand Up @@ -275,7 +276,7 @@ import { config } from '../config';
index = objectMarkup.indexOf('COMMON_PARTS'),
additionalTransform = options.additionalTransform;
if (clipPath) {
clipPath.clipPathId = 'CLIPPATH_' + fabric.Object.__uid++;
clipPath.clipPathId = 'CLIPPATH_' + FabricObject.__uid++;
clipPathMarkup =
'<clipPath id="' +
clipPath.clipPathId +
Expand Down
6 changes: 4 additions & 2 deletions src/mixins/object_ancestry.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//@ts-nocheck
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric;
fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Checks if object is decendant of target
* Should be used instead of @link {fabric.Collection.contains} for performance reasons
Expand Down
5 changes: 3 additions & 2 deletions src/mixins/object_geometry.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Intersection } from '../intersection.class';
import { Point } from '../point.class';
import { FabricObject } from '../shapes/object.class';

(function (global) {
function arrayFromCoords(coords) {
Expand All @@ -20,8 +21,8 @@ import { Point } from '../point.class';
transformPoint = util.transformPoint;

util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Describe object's corner position in canvas element coordinates.
* properties are depending on control keys and padding the main controls.
Expand Down
5 changes: 3 additions & 2 deletions src/mixins/object_interactivity.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//@ts-nocheck
import { Point } from '../point.class';
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric,
degreesToRadians = fabric.util.degreesToRadians;

fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Determines which corner has been clicked
* @private
Expand Down
5 changes: 3 additions & 2 deletions src/mixins/object_origin.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ts-nocheck
import { Point } from '../point.class';
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric,
Expand All @@ -21,8 +22,8 @@ import { Point } from '../point.class';
*/

fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Resolves origin value relative to center
* @private
Expand Down
6 changes: 4 additions & 2 deletions src/mixins/object_stacking.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//@ts-nocheck
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric;
fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* Moves an object to the bottom of the stack of drawn objects
* @return {fabric.Object} thisArg
Expand Down
8 changes: 5 additions & 3 deletions src/mixins/object_straightening.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//@ts-nocheck
import { FabricObject } from '../shapes/object.class';

(function (global) {
var fabric = global.fabric;
fabric.util.object.extend(
fabric.Object.prototype,
/** @lends fabric.Object.prototype */ {
FabricObject.prototype,
/** @lends FabricObject.prototype */ {
/**
* @private
* @return {Number} angle value
Expand All @@ -26,7 +28,7 @@
},

/**
* Same as {@link fabric.Object.prototype.straighten} but with animation
* Same as {@link FabricObject.prototype.straighten} but with animation
* @param {Object} callbacks Object with callback functions
* @param {Function} [callbacks.onComplete] Invoked on completion
* @param {Function} [callbacks.onChange] Invoked on every step of animation
Expand Down
Loading

0 comments on commit 8235106

Please sign in to comment.