Skip to content

Commit

Permalink
chore(TS): Convert object geometry in its own class (fabricjs#8390)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored and frankrousseau committed Jan 6, 2023
1 parent d1d09e2 commit 5a3f5ff
Show file tree
Hide file tree
Showing 15 changed files with 1,333 additions and 1,580 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): Conver Geometry and Origin to classes/e6/ts [#8390](https://github.com/fabricjs/fabric.js/pull/8390)
- ci(): build stats report [#8395](https://github.com/fabricjs/fabric.js/pull/8395)
- 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)
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './HEADER';
// import './lib/event'), // optional gestures
// import './lib/event', // optional gestures
import './src/mixins/collection.mixin';
import './src/util/misc/misc';
// import './src/util/named_accessors.mixin'; i would imagine dead forever or proper setters/getters
Expand All @@ -18,8 +18,6 @@ import './src/mixins/canvas_dataurl_exporter.mixin';
import './src/mixins/canvas_serialization.mixin'; // optiona serialization
import './src/mixins/canvas_gestures.mixin'; // optional gestures
import './src/shapes/object.class';
import './src/mixins/object_origin.mixin';
import './src/mixins/object_geometry.mixin';
import './src/mixins/object_ancestry.mixin';
import './src/mixins/object_stacking.mixin';
import './src/mixins/object.svg_export';
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import { terser } from 'rollup-plugin-terser';
import ts from 'rollup-plugin-ts';

const runStats = process.env.BUILD_STATS;
const runStats = Number(process.env.BUILD_STATS);
let analyzed = false;

const splitter = /\n|\s|,/g;
Expand Down
13 changes: 1 addition & 12 deletions scripts/buildStats.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,9 @@ const MAX_COMMENT_CHARS = 65536;
const INACCURATE_COMMENT =
'\n*inaccurate, see [link](https://github.com/doesdev/rollup-plugin-analyzer#why-is-the-reported-size-not-the-same-as-the-file-on-disk)';

function getSign(n) {
switch (Math.sign(n)) {
case 0:
return '';
case 1:
return '+';
case -1:
return '-';
}
}

function printSize(a, b) {
const diff = b - a;
return `${b} (${getSign(diff)}${diff})`;
return `${b} (${Math.sign(diff) > 0 ? '+' : ''}${diff})`;
}

function printSizeByte(a, b) {
Expand Down
2 changes: 1 addition & 1 deletion src/intersection.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fabric } from '../HEADER';

/* Adaptation of work of Kevin Lindsey (kevin@kevlindev.com) */

type IntersectionType = 'Intersection' | 'Coincident' | 'Parallel';
export type IntersectionType = 'Intersection' | 'Coincident' | 'Parallel';

/**
* **Assuming `T`, `A`, `B` are points on the same line**,
Expand Down
17 changes: 17 additions & 0 deletions src/mixins/itext_click_behavior.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//@ts-nocheck
import { invertTransform, transformPoint } from '../util/misc/matrix';
import { Point } from '../point.class';

(function (global) {
var fabric = global.fabric;
fabric.util.object.extend(
Expand Down Expand Up @@ -226,6 +229,20 @@
}
},

/**
* Returns coordinates of a pointer relative to object's top left corner in object's plane
* @param {Event} e Event to operate upon
* @param {Object} [pointer] Pointer to operate upon (instead of event)
* @return {Point} Coordinates of a pointer (x, y)
*/
getLocalPointer: function (e: Event, pointer?: IPoint): Point {
const thePointer = pointer || this.canvas.getPointer(e);
return transformPoint(
thePointer,
invertTransform(this.calcTransformMatrix())
).add(new Point(this.width / 2, this.height / 2));
},

/**
* Returns index of a character corresponding to where an object was clicked
* @param {Event} e Event object
Expand Down
Loading

0 comments on commit 5a3f5ff

Please sign in to comment.