-
-
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): utils #8230
chore(TS): utils #8230
Changes from all commits
047b4c8
8696f5e
aa90704
debadac
2807ec2
77b0727
d2ac909
f46feee
bc9962c
bf8efa2
bfe92fd
0eb7947
cdf5992
a7a3026
6bb4d2b
4e3939f
92bee80
d2e8f05
3cd1da1
45a46a4
7ecd0c5
0232258
33f18bc
f363dfe
c1eb748
1ea46cb
26a1acf
cc95956
612b5d1
fbe5f75
585b0e6
cabb1c6
7c99ce5
cd54755
5ce2a09
a5d5441
ca6f6b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1044,19 +1044,20 @@ import { Point } from './point.class'; | |
* @throws {CANVAS_INIT_ERROR} If canvas can not be initialized | ||
*/ | ||
_createUpperCanvas: function () { | ||
var lowerCanvasClass = this.lowerCanvasEl.className.replace(/\s*lower-canvas\s*/, ''), | ||
lowerCanvasEl = this.lowerCanvasEl, upperCanvasEl = this.upperCanvasEl; | ||
var lowerCanvasEl = this.lowerCanvasEl, upperCanvasEl = this.upperCanvasEl; | ||
|
||
// there is no need to create a new upperCanvas element if we have already one. | ||
if (upperCanvasEl) { | ||
upperCanvasEl.className = ''; | ||
} | ||
else { | ||
// if there is no upperCanvas (most common case) we create one. | ||
if (!upperCanvasEl) { | ||
upperCanvasEl = this._createCanvasElement(); | ||
this.upperCanvasEl = upperCanvasEl; | ||
} | ||
fabric.util.addClass(upperCanvasEl, 'upper-canvas ' + lowerCanvasClass); | ||
this.upperCanvasEl.setAttribute('data-fabric', 'top'); | ||
// we assign the same classname of the lowerCanvas | ||
upperCanvasEl.className = lowerCanvasEl.className; | ||
// but then we remove the lower-canvas specific className | ||
upperCanvasEl.classList.remove('lower-canvas'); | ||
// we add the specific upper-canvas class | ||
upperCanvasEl.classList.add('upper-canvas'); | ||
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. much better |
||
upperCanvasEl.setAttribute('data-fabric', 'top'); | ||
this.wrapperEl.appendChild(upperCanvasEl); | ||
|
||
this._copyCanvasStyle(lowerCanvasEl, upperCanvasEl); | ||
|
@@ -1082,9 +1083,9 @@ import { Point } from './point.class'; | |
if (this.wrapperEl) { | ||
return; | ||
} | ||
this.wrapperEl = fabric.util.wrapElement(this.lowerCanvasEl, 'div', { | ||
'class': this.containerClass | ||
}); | ||
const container = fabric.document.createElement('div'); | ||
container.classList.add(this.containerClass); | ||
this.wrapperEl = fabric.util.wrapElement(this.lowerCanvasEl, container); | ||
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. drop 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. wrapElement probably don't belong in utils exported object indeed. will be just a function imported here 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. it is used only here across fabric, right? 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. yes i think only here to add a div around the canvas |
||
this.wrapperEl.setAttribute('data-fabric', 'wrapper'); | ||
fabric.util.setStyle(this.wrapperEl, { | ||
width: this.width + 'px', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { TMat2D } from "./typedefs"; | ||
|
||
export { version as VERSION } from '../package.json'; | ||
export const noop = () => {}; | ||
export function noop() {}; | ||
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. Is there a difference between 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. There is a difference that a fat arrow can't be bound and can't be used as a class member. |
||
export const halfPI = Math.PI / 2; | ||
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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { fabric } from '../HEADER'; | ||
import { TMat2D, TRadian } from './typedefs'; | ||
import { sin } from './util/misc/sin'; | ||
import { cos } from './util/misc/cos'; | ||
|
||
export interface IPoint { | ||
x: number | ||
|
@@ -350,16 +352,22 @@ export class Point { | |
|
||
/** | ||
* Rotates `point` around `origin` with `radians` | ||
* WARNING: this is probably a source of circular dependency. | ||
* evaluate what to do when importing rotateVector directly from the file | ||
* @static | ||
* @memberOf fabric.util | ||
* @param {Point} origin The origin of the rotation | ||
* @param {TRadian} radians The radians of the angle for the rotation | ||
* @return {Point} The new rotated point | ||
*/ | ||
rotate(origin: Point, radians: TRadian): Point { | ||
return fabric.util.rotateVector(this.subtract(origin), radians).add(origin); | ||
rotate(radians: TRadian, origin: Point = originZero): Point { | ||
// TODO benchmark and verify the add and subtract how much cost | ||
// and then in case early return if no origin is passed | ||
const sinus = sin(radians), cosinus = cos(radians); | ||
const p = this.subtract(origin); | ||
const rotated = new Point( | ||
p.x * cosinus - p.y * sinus, | ||
p.x * sinus + p.y * cosinus, | ||
); | ||
return rotated.add(origin); | ||
} | ||
|
||
/** | ||
|
@@ -378,4 +386,6 @@ export class Point { | |
} | ||
} | ||
|
||
const originZero = new Point(0, 0); | ||
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. You want to reuse this? That is why you don't inline it in the function signature? 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. i think is more readable defined as a const rather than in the function definition. 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. good question |
||
|
||
fabric.Point = Point; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,14 +310,14 @@ import { pick } from './util/misc/pick'; | |
this.lowerCanvasEl = canvasEl; | ||
} | ||
else { | ||
this.lowerCanvasEl = fabric.util.getById(canvasEl) || this._createCanvasElement(); | ||
this.lowerCanvasEl = fabric.document.getElementById(canvasEl) || canvasEl || this._createCanvasElement(); | ||
} | ||
if (this.lowerCanvasEl.hasAttribute('data-fabric')) { | ||
/* _DEV_MODE_START_ */ | ||
throw new Error('fabric.js: trying to initialize a canvas that has already been initialized'); | ||
/* _DEV_MODE_END_ */ | ||
} | ||
fabric.util.addClass(this.lowerCanvasEl, 'lower-canvas'); | ||
this.lowerCanvasEl.classList.add('lower-canvas'); | ||
this.lowerCanvasEl.setAttribute('data-fabric', 'main'); | ||
if (this.interactive) { | ||
this._originalCanvasStyle = this.lowerCanvasEl.style.cssText; | ||
|
@@ -752,7 +752,7 @@ import { pick } from './util/misc/pick'; | |
this.cancelRequestedRender(); | ||
this.calcViewportBoundaries(); | ||
this.clearContext(ctx); | ||
fabric.util.setImageSmoothing(ctx, this.imageSmoothingEnabled); | ||
ctx.imageSmoothingEnabled = this.imageSmoothingEnabled; | ||
ctx.patternQuality = 'best'; | ||
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. should this 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. Those are node-canvas specific things i m ignoring on purpose. Are their default not good? I want to have a clean canvas interface as much as possible in case we move to skia-canvas or maybe we have both as an option. 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. good is default 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. but missed |
||
this.fire('before:render', { ctx: ctx, }); | ||
this._renderBackground(ctx); | ||
|
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.
VERY STRANGE
And shouldn't happen...
HACKY
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 is not hacky and not everything should be a point.
Before was x and y but wasn't a point.
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.
The reason for the circular dep cycle is just because of the assignment
fabric.Point
that will be removed anyways.If you assign it in index it will not happen.
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.
Don't you agree this is out of pattern?
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 a function about caching, i don't think returning an array to return 2 values is better or worse than returnin an object and calling it a point. I just really need the 2 values out of there.