-
-
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): Move more utils to TS #8164
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a99be26
forgot jsdocs before
asturur 6f633a6
added dom
asturur 6757a0e
ok
asturur d2003fe
some more
asturur f9e847c
some more
asturur 6a733f2
rewrote parseArAttribute
asturur 5d843a4
no nested ifs
asturur bfee157
fixed wrong tests
asturur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,25 @@ export const enum StrokeLineJoin { | |
round = 'round', | ||
} | ||
|
||
export const enum ImageFormat { | ||
jpeg = 'jpeg', | ||
jpg = 'jpeg', | ||
png = 'png', | ||
} | ||
|
||
export const enum SVGElementName { | ||
linearGradient = 'linearGradient', | ||
radialGradient = 'radialGradient', | ||
stop = 'stop', | ||
} | ||
|
||
export const enum SupportedSVGUnit { | ||
mm = 'mm', | ||
cm = 'cm', | ||
in = 'in', | ||
pt = 'pt', | ||
pc = 'pc', | ||
em = 'em', | ||
} | ||
|
||
export type TMat2D = [number, number, number, number, number, number]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export type TMat2DBasic = [number,number,number,number];
export type TMat2DAffine = [number,number,number,number,number,number];
export type TMat2D<T> = TMat2DAffine |TMat2DBasic;
export type... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const capValue = (min: number, value: number, max: number) => Math.max(min, Math.min(value, max)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { fabric } from '../../../HEADER'; | ||
import { ImageFormat } from '../../typedefs'; | ||
/** | ||
* Creates canvas element | ||
* @static | ||
* @memberOf fabric.util | ||
* @return {CanvasElement} initialized canvas element | ||
*/ | ||
export const createCanvasElement = (): HTMLCanvasElement => fabric.document.createElement('canvas'); | ||
|
||
/** | ||
* Creates image element (works on client and node) | ||
* @static | ||
* @memberOf fabric.util | ||
* @return {HTMLImageElement} HTML image element | ||
*/ | ||
export const createImage = () =>fabric.document.createElement('img'); | ||
|
||
/** | ||
* Creates a canvas element that is a copy of another and is also painted | ||
* @param {CanvasElement} canvas to copy size and content of | ||
* @static | ||
* @memberOf fabric.util | ||
* @return {CanvasElement} initialized canvas element | ||
*/ | ||
export const copyCanvasElement = (canvas: HTMLCanvasElement): HTMLCanvasElement => { | ||
const newCanvas = createCanvasElement(); | ||
newCanvas.width = canvas.width; | ||
newCanvas.height = canvas.height; | ||
newCanvas.getContext('2d')?.drawImage(canvas, 0, 0); | ||
return newCanvas; | ||
}; | ||
|
||
/** | ||
* since 2.6.0 moved from canvas instance to utility. | ||
* possibly useless | ||
* @param {CanvasElement} canvasEl to copy size and content of | ||
* @param {String} format 'jpeg' or 'png', in some browsers 'webp' is ok too | ||
* @param {Number} quality <= 1 and > 0 | ||
* @static | ||
* @memberOf fabric.util | ||
* @return {String} data url | ||
*/ | ||
export const toDataURL = (canvasEl: HTMLCanvasElement, format: ImageFormat, quality: number) => canvasEl.toDataURL(`image/${format}`, quality); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interface IWithDimensions { | ||
width: number; | ||
height: number; | ||
} | ||
|
||
/** | ||
* Finds the scale for the object source to fit inside the object destination, | ||
* keeping aspect ratio intact. | ||
* respect the total allowed area for the cache. | ||
* @memberOf fabric.util | ||
* @param {Object | fabric.Object} source | ||
* @param {Number} source.height natural unscaled height of the object | ||
* @param {Number} source.width natural unscaled width of the object | ||
* @param {Object | fabric.Object} destination | ||
* @param {Number} destination.height natural unscaled height of the object | ||
* @param {Number} destination.width natural unscaled width of the object | ||
* @return {Number} scale factor to apply to source to fit into destination | ||
*/ | ||
export const findScaleToFit = (source: IWithDimensions, destination: IWithDimensions) => | ||
Math.min(destination.width / source.width, destination.height / source.height); | ||
|
||
/** | ||
* Finds the scale for the object source to cover entirely the object destination, | ||
* keeping aspect ratio intact. | ||
* respect the total allowed area for the cache. | ||
* @memberOf fabric.util | ||
* @param {Object | fabric.Object} source | ||
* @param {Number} source.height natural unscaled height of the object | ||
* @param {Number} source.width natural unscaled width of the object | ||
* @param {Object | fabric.Object} destination | ||
* @param {Number} destination.height natural unscaled height of the object | ||
* @param {Number} destination.width natural unscaled width of the object | ||
* @return {Number} scale factor to apply to source to cover destination | ||
*/ | ||
export const findScaleToCover = (source: IWithDimensions, destination: IWithDimensions) => | ||
Math.max(destination.width / source.width, destination.height / source.height); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why not import directly from the file
lang_array
and not from the index?That will solve the circular dep
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.
Is what i was doing i removed for now all imports from the main index in util, and where possible i m linking to direct files.
Is probably better to leave the util/index.ts just to create the external facing export for who will use fabric.util