-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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): more FabricObject types #8405
Conversation
Build Stats
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
READY
@@ -602,6 +602,10 @@ export class ObjectGeometry extends ObjectOrigin { | |||
return this.scale(value / this.height / boundingRectFactor); | |||
} | |||
|
|||
getRetinaScaling() { | |||
return this.canvas?.getRetinaScaling() || 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exposed this instead of having to check if canvas exists
I wonder if we should change this to
return this.canvas?.getRetinaScaling() || config.devicePixelRatio;
Should the method be protected?
src/mixins/object_geometry.mixin.ts
Outdated
getRetinaScaling() { | ||
return this.canvas?.getRetinaScaling() || 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was thinkging of this, but i don't want to do it.
There must be a way to tell TS in all those functions canvas exists, without having to runtime check it.
Like having a type in which Canvas is mandatory and TS understands that is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(but at least should be called getCanvasRetinaScaling
) just to be clear objects do not have their own retina scaling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: good point
In half of the cases the check in needed so it seems.
We can assert Or use !
or what you suggested (need to think how)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I will rename and we merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well OK maybe if we do like I did casting this: this & Required<this, 'canvas'>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
@@ -144,7 +144,7 @@ export class Pattern { | |||
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output | |||
* @return {object} Object representation of a pattern instance | |||
*/ | |||
toObject(propertiesToInclude: (keyof this)[]) { | |||
toObject(propertiesToInclude?: (keyof this)[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty much sure will have to go back to Record<string, any> for this, but for now let's try
@@ -8,6 +8,7 @@ export const twoMathPi = Math.PI * 2; | |||
export const PiBy180 = Math.PI / 180; | |||
export const iMatrix = Object.freeze([1, 0, 0, 1, 0, 0]) as TMat2D; | |||
export const DEFAULT_SVG_FONT_SIZE = 16; | |||
export const ALIASING_LIMIT = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added here but removed nowhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved from Object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
Motivation
Description
More types
Left Gradient/Pattern types alone since there are open PRs for them, I don't want to create conflicts
Exposed
getCanvasRetinaScaling
on ObjectGeometry for ease of useChanges
Gist
In Action