Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(TS): controls #8400

Merged
merged 115 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
ed66b81
WIP
ShaMan123 Oct 12, 2022
0e5305a
Merge branch 'master' into fix-skewing-controls
ShaMan123 Oct 12, 2022
c4633cb
Merge branch 'master' into fix-skewing-controls
ShaMan123 Oct 17, 2022
e30dd32
fix skewing
ShaMan123 Oct 18, 2022
465149f
Update controls_handlers.js
ShaMan123 Oct 18, 2022
95b8b39
Update CHANGELOG.md
ShaMan123 Oct 18, 2022
06cdb64
fix(): use set
ShaMan123 Oct 18, 2022
793df67
Update object.class.ts
ShaMan123 Oct 18, 2022
c6f000d
Update controls.actions.ts
ShaMan123 Oct 18, 2022
d4996d1
ws
ShaMan123 Oct 18, 2022
606df66
fix(): flip assignment
ShaMan123 Oct 18, 2022
cdc2c5e
goldens
ShaMan123 Oct 18, 2022
c1f21d1
revert(): svg stuff
ShaMan123 Oct 18, 2022
aa48a3b
cleanup
ShaMan123 Oct 18, 2022
4e84453
Update object.class.ts
ShaMan123 Oct 18, 2022
5ee4741
fix(): restore `compensateScaleForSkew`
ShaMan123 Oct 18, 2022
cf395b4
cleanup
ShaMan123 Oct 18, 2022
22abcc6
cleanup compensate
ShaMan123 Oct 18, 2022
3f4720a
rename
ShaMan123 Oct 18, 2022
dc482f5
WIP compensation
ShaMan123 Oct 18, 2022
fc70ee9
progress!
ShaMan123 Oct 18, 2022
6ec0e26
revert
ShaMan123 Oct 18, 2022
14c7713
refactor
ShaMan123 Oct 18, 2022
7f6e7a3
cleanup
ShaMan123 Oct 18, 2022
601c363
refactor(): axis keys
ShaMan123 Oct 19, 2022
f4f6635
refactor skew handlers
ShaMan123 Oct 19, 2022
040d459
minor fix + rename
ShaMan123 Oct 19, 2022
902a7ca
`compensationFactor` only for `skewY`
ShaMan123 Oct 19, 2022
4a28d67
fix(): anchoring origin
ShaMan123 Oct 20, 2022
7512123
rename for clarity
ShaMan123 Oct 20, 2022
6912a60
checkout unrelated changes
ShaMan123 Oct 20, 2022
51c63b4
Merge branch 'master' into fix-skewing-controls
ShaMan123 Oct 20, 2022
0d5d805
checkout svg visual tests/assets
ShaMan123 Oct 20, 2022
60dd440
Update controls.actions.ts
ShaMan123 Oct 20, 2022
cb72c5c
Merge branch 'master' into fix-skewing-controls
ShaMan123 Oct 26, 2022
3e67548
cleanup
ShaMan123 Oct 26, 2022
89d2c0b
fix(): skewing!!
ShaMan123 Oct 26, 2022
560f8d8
fix tests + add
ShaMan123 Oct 26, 2022
4db434b
account for scaling
ShaMan123 Oct 26, 2022
5491b5e
Update controls.actions.ts
ShaMan123 Oct 26, 2022
84b5bde
Update canvas.class.ts
ShaMan123 Oct 26, 2022
d17ec00
Update canvas.class.ts
ShaMan123 Oct 26, 2022
227381e
fix skewing on scaled object
ShaMan123 Oct 26, 2022
432a02b
Update controls_handlers.js
ShaMan123 Oct 26, 2022
bc4de25
Update controls.actions.ts
ShaMan123 Oct 26, 2022
ece8cc0
better explained
ShaMan123 Oct 27, 2022
f42a1e0
move `AXIS_KEYS`
ShaMan123 Oct 27, 2022
c603d85
fixes
ShaMan123 Oct 27, 2022
75b94fe
Update controls.actions.ts
ShaMan123 Oct 27, 2022
7248392
much better
ShaMan123 Oct 27, 2022
6888d8c
Merge branch 'master' into fix-skewing-controls
ShaMan123 Oct 27, 2022
0319b86
update resolveOrigin
ShaMan123 Oct 27, 2022
c1a519b
typo
ShaMan123 Oct 27, 2022
4066bf6
skewingSide
ShaMan123 Oct 27, 2022
e56d1f1
Update controls.actions.ts
ShaMan123 Oct 27, 2022
bc6e514
better comments
ShaMan123 Oct 27, 2022
6b11e11
pass down skewingSide
ShaMan123 Oct 27, 2022
7753d72
comments
ShaMan123 Oct 27, 2022
e68d0c2
distanceFromOrigin
ShaMan123 Oct 27, 2022
0f7a201
Update controls.actions.ts
ShaMan123 Oct 27, 2022
1a3146c
Update controls.actions.ts
ShaMan123 Oct 27, 2022
d9c5bd5
Update controls.actions.ts
ShaMan123 Oct 27, 2022
1ba2724
fix(): counter flip
ShaMan123 Oct 27, 2022
43a5657
fix
ShaMan123 Oct 27, 2022
91c5d72
Update buildStats.mjs
ShaMan123 Oct 27, 2022
402c419
modularize WIP
ShaMan123 Oct 29, 2022
63447cf
Merge branch 'master' into ts-controls
ShaMan123 Oct 29, 2022
a7da5a2
update from master
ShaMan123 Oct 29, 2022
028712a
types
ShaMan123 Oct 29, 2022
59b1bdc
object transient types
ShaMan123 Oct 29, 2022
f76ae91
types
ShaMan123 Oct 29, 2022
4482ade
more
ShaMan123 Oct 29, 2022
bdb07fc
Update canvas.class.ts
ShaMan123 Oct 29, 2022
93acd57
scale
ShaMan123 Oct 29, 2022
955ad6a
Update wrapWithFireEvent.ts
ShaMan123 Oct 29, 2022
d82d797
import/export
ShaMan123 Oct 29, 2022
1792aaa
remove fireEvent from export
ShaMan123 Oct 29, 2022
d3ab7f1
exports
ShaMan123 Oct 29, 2022
b37066c
types
ShaMan123 Oct 29, 2022
9e0fbc9
Update util.ts
ShaMan123 Oct 29, 2022
4bae816
Update __types__.ts
ShaMan123 Oct 29, 2022
807a3ff
more work
ShaMan123 Oct 29, 2022
a2bb2ee
Update control.class.ts
ShaMan123 Oct 29, 2022
f39499f
Update object.class.ts
ShaMan123 Oct 29, 2022
1d3eea9
needs verification
ShaMan123 Oct 29, 2022
6b14893
Update __types__.ts
ShaMan123 Oct 29, 2022
11b6fa3
Update objectTransforms.ts
ShaMan123 Oct 29, 2022
0b872ae
Update control.class.ts
ShaMan123 Oct 29, 2022
607dda6
imports
ShaMan123 Oct 29, 2022
54c0953
Update rotate.ts
ShaMan123 Oct 29, 2022
f5b91d5
Update buildStats.mjs
ShaMan123 Oct 29, 2022
f073014
Update buildStats.mjs
ShaMan123 Oct 29, 2022
f9a626d
Update buildStats.mjs
ShaMan123 Oct 29, 2022
2e7cf31
Update buildStats.mjs
ShaMan123 Oct 29, 2022
e4c3f7c
Update buildStats.mjs
ShaMan123 Oct 29, 2022
9cf9113
Update buildStats.mjs
ShaMan123 Oct 29, 2022
6505552
Update buildStats.mjs
ShaMan123 Oct 29, 2022
f273307
jsdoc types
ShaMan123 Oct 29, 2022
59ce8a2
Update default_controls.ts
ShaMan123 Oct 29, 2022
314cacc
fix naming + types
ShaMan123 Oct 29, 2022
7956dcd
fix typo
ShaMan123 Oct 29, 2022
b7c3fee
fix tests
ShaMan123 Oct 29, 2022
915313c
Update object_origin.js
ShaMan123 Oct 29, 2022
eb32d05
fix imports
ShaMan123 Oct 29, 2022
0b465f8
es6
ShaMan123 Oct 29, 2022
b80b34e
Create aaaaaa.json
ShaMan123 Oct 29, 2022
d435c6b
fix tests
ShaMan123 Oct 29, 2022
032cc27
normalizePoint
ShaMan123 Oct 29, 2022
58af5c6
optional textbox controls
ShaMan123 Oct 29, 2022
e083787
review changes
ShaMan123 Oct 29, 2022
00baf49
Update controls.render.ts
ShaMan123 Oct 29, 2022
d765524
Update controls.render.ts
ShaMan123 Oct 29, 2022
310abfb
Update rotate.ts
ShaMan123 Oct 30, 2022
c19df4c
Update scaleSkew.ts
ShaMan123 Oct 30, 2022
0839306
isLocked
ShaMan123 Oct 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 controls e6/ts [#8400](https://github.com/fabricjs/fabric.js/pull/8400)
- ci(): remove buggy changelog action in favor of `git diff` bash script + direct git how to merge `CHANGELOG.md` [#8309](https://github.com/fabricjs/fabric.js/pull/8346)
- fix(): skewing controls accuracy + successive interactions [#8380](https://github.com/fabricjs/fabric.js/pull/8380)
- chore(TS): Convert Geometry and Origin to classes/e6/ts [#8390](https://github.com/fabricjs/fabric.js/pull/8390)
Expand Down
24 changes: 15 additions & 9 deletions scripts/buildStats.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const INACCURATE_COMMENT =

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

function printSizeByte(a, b) {
return printSize(Math.round(a / 1024), Math.round(b / 1024));
return printSize(a / 1024, b / 1024);
}

export async function findCommentId(github, context) {
Expand Down Expand Up @@ -94,13 +96,17 @@ export async function run({ github, context, a, b }) {
printSizeByte(_a.gzipped, _b.gzipped),
];
}),
..._.map(files, ({ a, b }, key) => {
return [
key,
printSizeByte(a.sizeBefore, b.sizeBefore),
printSizeByte(a.sizeAfter, b.sizeAfter),
];
}),
..._.orderBy(
_.map(files, ({ a, b }, key) => {
return [
key,
printSizeByte(a.sizeBefore, b.sizeBefore),
printSizeByte(a.sizeAfter, b.sizeAfter),
];
}),
[0],
['asc']
),
];

const body =
Expand Down
19 changes: 18 additions & 1 deletion src/__types__.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import type { Observable } from './mixins/observable.mixin';
import type { Point } from './point.class';
import { ModifierKey, TMat2D } from './typedefs';

/**
* @todo remove transient
*/
export type Shadow = any;
export type Canvas = any;
export type Canvas = StaticCanvas & {
altActionKey: ModifierKey;
uniScaleKey: ModifierKey;
uniformScaling: boolean;
} & Record<string, any>;
export type StaticCanvas = Record<string, any> & {
getZoom(): number;
viewportTransform: TMat2D;
vptCoords: {
tl: Point;
br: Point;
};
getRetinaScaling(): number;
} & Observable;
export type Rect = any;
export type TObject = any;
41 changes: 12 additions & 29 deletions src/canvas.class.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@ts-nocheck
import { dragHandler, getActionFromCorner } from './controls/actions';
import { Point } from './point.class';
import { FabricObject } from './shapes/object.class';
import { ModifierKey, Transform } from './typedefs';
import { saveObjectTransform } from './util/misc/objectTransforms';

(function (global) {
var fabric = global.fabric,
Expand Down Expand Up @@ -139,7 +142,7 @@ import { FabricObject } from './shapes/object.class';
* if Canvas.uniformScaling is true, pressing this will set it to false
* and viceversa.
* @since 1.6.2
* @type String
* @type ModifierKey
* @default
*/
uniScaleKey: 'shiftKey',
Expand Down Expand Up @@ -168,7 +171,7 @@ import { FabricObject } from './shapes/object.class';
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled feature disabled.
* @since 1.6.2
* @type String
* @type ModifierKey
* @default
*/
centeredKey: 'altKey',
Expand All @@ -179,7 +182,7 @@ import { FabricObject } from './shapes/object.class';
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled feature disabled.
* @since 1.6.2
* @type String
* @type ModifierKey
* @default
*/
altActionKey: 'shiftKey',
Expand All @@ -205,7 +208,7 @@ import { FabricObject } from './shapes/object.class';
* If `null` or empty or containing any other string that is not a modifier key
* feature is disabled.
* @since 1.6.2
* @type String|Array
* @type ModifierKey|ModifierKey[]
* @default
*/
selectionKey: 'shiftKey',
Expand All @@ -219,7 +222,7 @@ import { FabricObject } from './shapes/object.class';
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled.
* @since 1.6.5
* @type null|String
* @type null|ModifierKey
* @default
*/
altSelectionKey: null,
Expand Down Expand Up @@ -738,21 +741,6 @@ import { FabricObject } from './shapes/object.class';
return origin;
},

/**
* @private
* @param {Boolean} alreadySelected true if target is already selected
* @param {String} corner a string representing the corner ml, mr, tl ...
* @param {Event} e Event object
* @param {fabric.Object} [target] inserted back to help overriding. Unused
*/
_getActionFromCorner: function (alreadySelected, corner, e, target) {
ShaMan123 marked this conversation as resolved.
Show resolved Hide resolved
if (!corner || !alreadySelected) {
return 'drag';
}
var control = target.controls[corner];
return control.getActionName(e, control, target);
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the reason of this function.
It says something about overriding, and if is an utile imported directly can't be overridden.
I ll dig in the past to understand why this should or could be overridden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense
so you can override to which control you are passing the event..?


/**
* @private
* @param {Event} e Event object
Expand All @@ -775,20 +763,15 @@ import { FabricObject } from './shapes/object.class';
actionHandler =
alreadySelected && corner
? control.getActionHandler(e, target, control)
: fabric.controlsUtils.dragHandler,
action = this._getActionFromCorner(
alreadySelected,
corner,
e,
target
),
: dragHandler,
action = getActionFromCorner(alreadySelected, corner, e, target),
origin = this._getOriginFromCorner(target, corner),
altKey = e[this.centeredKey],
/**
* relative to target's containing coordinate plane
* both agree on every point
**/
transform = {
transform: Transform = {
target: target,
action: action,
actionHandler: actionHandler,
Expand All @@ -810,7 +793,7 @@ import { FabricObject } from './shapes/object.class';
height: target.height,
shiftKey: e.shiftKey,
altKey: altKey,
original: fabric.util.saveObjectTransform(target),
original: saveObjectTransform(target),
};

if (this._shouldCenterTransform(target, action, altKey)) {
Expand Down
71 changes: 71 additions & 0 deletions src/controls/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { fabric } from '../../HEADER';
import { changeWidth } from './changeWidth';
import { renderCircleControl, renderSquareControl } from './controls.render';
import { dragHandler } from './drag';
import { rotationStyleHandler, rotationWithSnapping } from './rotate';
import {
scaleCursorStyleHandler,
scalingEqually,
scalingX,
scalingY,
} from './scale';
import {
scaleOrSkewActionName,
scaleSkewCursorStyleHandler,
scalingXOrSkewingY,
scalingYOrSkewingX,
} from './scaleSkew';
import { skewCursorStyleHandler, skewHandlerX, skewHandlerY } from './skew';
import { getLocalPoint, getActionFromCorner } from './util';
import { wrapWithFireEvent } from './wrapWithFireEvent';
import { wrapWithFixedAnchor } from './wrapWithFixedAnchor';

export {
scaleCursorStyleHandler,
skewCursorStyleHandler,
scaleSkewCursorStyleHandler,
rotationWithSnapping,
scalingEqually,
scalingX,
scalingY,
scalingYOrSkewingX,
scalingXOrSkewingY,
changeWidth,
skewHandlerX,
skewHandlerY,
dragHandler,
scaleOrSkewActionName,
rotationStyleHandler,
wrapWithFixedAnchor,
wrapWithFireEvent,
getLocalPoint,
getActionFromCorner,
renderCircleControl,
renderSquareControl,
};

/**
* @todo remove as unused
*/
fabric.controlsUtils = {
scaleCursorStyleHandler,
skewCursorStyleHandler,
scaleSkewCursorStyleHandler,
rotationWithSnapping,
scalingEqually,
scalingX,
scalingY,
scalingYOrSkewingX,
scalingXOrSkewingY,
changeWidth,
skewHandlerX,
skewHandlerY,
dragHandler,
scaleOrSkewActionName,
rotationStyleHandler,
wrapWithFixedAnchor,
wrapWithFireEvent,
getLocalPoint,
renderCircleControl,
renderSquareControl,
};
52 changes: 52 additions & 0 deletions src/controls/changeWidth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { TransformActionHandler } from '../typedefs';
import { getLocalPoint, isTransformCentered } from './util';
import { wrapWithFireEvent } from './wrapWithFireEvent';
import { wrapWithFixedAnchor } from './wrapWithFixedAnchor';

/**
* Action handler to change object's width
* Needs to be wrapped with `wrapWithFixedAnchor` to be effective
* @param {Event} eventData javascript event that is doing the transform
* @param {Object} transform javascript object containing a series of information around the current transform
* @param {number} x current mouse x position, canvas normalized
* @param {number} y current mouse y position, canvas normalized
* @return {Boolean} true if some change happened
*/
export const changeObjectWidth: TransformActionHandler = (
eventData,
transform,
x,
y
) => {
const localPoint = getLocalPoint(
transform,
transform.originX,
transform.originY,
x,
y
);
// make sure the control changes width ONLY from it's side of target
if (
transform.originX === 'center' ||
(transform.originX === 'right' && localPoint.x < 0) ||
(transform.originX === 'left' && localPoint.x > 0)
) {
const { target } = transform,
strokePadding =
target.strokeWidth / (target.strokeUniform ? target.scaleX : 1),
multiplier = isTransformCentered(transform) ? 2 : 1,
oldWidth = target.width,
newWidth = Math.ceil(
Math.abs((localPoint.x * multiplier) / target.scaleX) - strokePadding
);
target.set('width', Math.max(newWidth, 0));
// check against actual target width in case `newWidth` was rejected
return oldWidth !== target.width;
}
return false;
};

export const changeWidth = wrapWithFireEvent(
'resizing',
wrapWithFixedAnchor(changeObjectWidth)
);
Loading