-
-
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): convert StaticCanvas #8485
Conversation
Build Stats
|
this.off('mouse:up', this._mouseUpITextHandler); | ||
this._iTextInstances = null; | ||
this._hasITextHandlers = false; | ||
} |
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.
StaticCanvas shouldn't have Itext handlers, if someone come with a real use case we can revert this back
@ShaMan123 ready to go for me. |
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.
src/util/types.ts
:
I saw your comment regarding using instanceof. My suggestion is simple. We create a base class that is exposed only internally for instanceof checks.
So we do something like:
export class TextBase extends FabricObject {
}
export class Text extends TextBase {
...logic
}
import { TextBase, type Text } from '..';
function isText(what: FabricObject): what is Text {
return what instanceof TextBase
}
A bit clumsy IMO. Is it that bad including it (importing the real class)?
export const isHTMLCanvas = ( | ||
canvas: HTMLCanvasElement | string | ||
): canvas is HTMLCanvasElement => { | ||
return !!canvas && (canvas as HTMLCanvasElement).getContext !== undefined; |
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 wonder if instanceof works on node as well nowadays
export const isPattern = (filler: TFiller): filler is Pattern => { | ||
return ( | ||
!!filler && | ||
(filler as Pattern).offsetX !== undefined && |
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.
no need for this logic, why not instanceof?
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 saw the comments
* The coordinates get updated with @method calcViewportBoundaries. | ||
* @memberOf fabric.StaticCanvas.prototype | ||
*/ | ||
vptCoords: TCornerPoint; |
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.
TCornerPoint
: not a great name
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.
yeah i agree.
} | ||
}); | ||
|
||
if (this._isCurrentlyDrawing) { |
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.
this part shouldn't be in StaticCanvas as well, it is canvas domain
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 didn't even see it
*/ | ||
drawClipPathOnCanvas( | ||
ctx: CanvasRenderingContext2D, | ||
clipPath: TCachedFabricObject |
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.
nice and simple!
width: this.width / (shouldTransform ? vpt[0] : 1), | ||
height: this.height / (shouldTransform ? vpt[3] : 1), | ||
}; | ||
return fill.toSVG(object as Rect, { |
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 don't like object as Rect
I prefer fixing the types in the Filler
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.
yeah so object needs to be a fabricObject, but it can be FabricObject | StaticCanvas to be honest, it just needs to have TSize or extends the interface of a TSize
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 let's change the signature at fill#toSVG
return; | ||
} | ||
if (isFiller(filler)) { | ||
// @ts-ignore TS is so stubbordn that i can't even check if a property exists. |
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.
This is really too much, I agree
oh ok, i understand what you mean with the empty classes. |
….js into TS-convert-static-canvas
Well you can't code split anymore. |
@ShaMan123 Did you reorder imports with some logic? |
VSCODE handles organizing imports |
Is there a way for prettier to do that? |
A quick search: but vscode does that on my machine... not sure if it is core or a plugin |
is the reorder part that isn't great. |
If we make it part of config that won't happen since it will be reordered before committing by vscode/prettier |
It is |
We should move control rendering logic to canvas as well. fabric.js/src/static_canvas.class.ts Line 844 in c0b7c1c
|
I don't understand how the static canvas file passes TS, many fields aren't typed. Did you do some magic config I missed? |
I see, it is because of CollectionMixin types, I will try to fix |
Co-authored-by: ShaMan123 <[email protected]>
Co-authored-by: ShaMan123 <[email protected]>
Converting only StaticCanvas for now, Canvas in next PR
Motivation
Description
Changes
Gist
In Action