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

patch(TS): canvas patch init 2 #8520

Merged
merged 40 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7c83395
broken progress
asturur Dec 12, 2022
fdf9245
save work
asturur Dec 12, 2022
aa0b140
save progress work
asturur Dec 17, 2022
6c02e74
may i have broke stuff
asturur Dec 17, 2022
84541aa
what did i do
asturur Dec 17, 2022
135ef2a
something killed fabric.config
asturur Dec 18, 2022
54e6351
stupid vscode you killed a full evening
asturur Dec 18, 2022
5ba11af
test passing
asturur Dec 18, 2022
47d717b
minimal changes
asturur Dec 18, 2022
305d6e8
clean up canvas
asturur Dec 18, 2022
1c577f3
patch canvas init logic
ShaMan123 Dec 18, 2022
286967c
fix(): apply canvas style before saving `_originalCanvasStyle`
ShaMan123 Dec 18, 2022
efcf9f1
cleanup redundant call
ShaMan123 Dec 18, 2022
644f94f
Revert "fix(): apply canvas style before saving `_originalCanvasStyle`"
ShaMan123 Dec 18, 2022
c31e5d7
rm redundant objects init
ShaMan123 Dec 19, 2022
281b831
mv
ShaMan123 Dec 19, 2022
9818c73
rm render bound methods
ShaMan123 Dec 19, 2022
143c4cc
test
ShaMan123 Dec 19, 2022
a9c7c7a
Update canvas.js
ShaMan123 Dec 19, 2022
fe21142
Merge branch 'master' into ts-canvas-patch-init
ShaMan123 Dec 29, 2022
4971d73
restore
ShaMan123 Dec 29, 2022
2abdf9a
dump _initEventListeners
ShaMan123 Dec 29, 2022
9ca6002
dump _bindEvents
ShaMan123 Dec 29, 2022
f5e96ca
Update CHANGELOG.md
ShaMan123 Dec 29, 2022
cba9325
fix(): regression unwanted init retina
ShaMan123 Jan 3, 2023
6e1ddc1
Merge branch 'master' into ts-canvas-patch-init
ShaMan123 Jan 3, 2023
359606c
Update CHANGELOG.md
ShaMan123 Jan 3, 2023
65afac6
fix(): set elements size on init
ShaMan123 Jan 3, 2023
b27ac06
forgotten
ShaMan123 Jan 3, 2023
fadd45f
rerfactor(): rm initSize => setDimensions
ShaMan123 Jan 3, 2023
95cc420
fix
ShaMan123 Jan 3, 2023
a1e89a7
cleanup + protected
ShaMan123 Jan 3, 2023
1d848ee
Update canvas.js
ShaMan123 Jan 4, 2023
15c8bf7
Merge branch 'master' into ts-canvas-patch-init
ShaMan123 Jan 6, 2023
a3caeac
Merge branch 'master' into ts-canvas-patch-init
asturur Jan 14, 2023
7c4910d
fix(): bad merge
ShaMan123 Jan 15, 2023
d8557f3
first commit
asturur Jan 15, 2023
e6148fc
changes to setDimensions
asturur Jan 15, 2023
e1ffe0c
mantain terser bind code
asturur Jan 15, 2023
9d19204
of course prettier
asturur Jan 15, 2023
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
13 changes: 4 additions & 9 deletions src/canvas/canvas.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ export class SelectableCanvas<
_activeObject?: FabricObject;
_hasITextHandlers?: boolean;
_iTextInstances: (IText | Textbox)[];

/**
* Constructor
* @param {HTMLCanvasElement | String} el canvas element to initialize instance on
Expand All @@ -505,20 +506,14 @@ export class SelectableCanvas<
*/
constructor(el: string | HTMLCanvasElement, options = {}) {
super(el, options);
this._createCacheCanvas();
}

_init(el: string | HTMLCanvasElement, options = {}) {
this.renderAndResetBound = this.renderAndReset.bind(this);
this.requestRenderAllBound = this.requestRenderAll.bind(this);
this._initStatic(el, options);
protected initElements(el: string | HTMLCanvasElement) {
super.initElements(el);
this._applyCanvasStyle(this.lowerCanvasEl);
this._initWrapperElement();
this._createUpperCanvas();
// @ts-ignore
this._initEventListeners();
this._initRetinaScaling();
this.calcOffset();
this._createCacheCanvas();
}

/**
Expand Down
54 changes: 18 additions & 36 deletions src/canvas/static_canvas.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ export class StaticCanvas<
* in order to return it to original state on dispose
* @type string
*/
_originalCanvasStyle?: string;

renderAndResetBound: () => void;
requestRenderAllBound: () => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dropped

private _originalCanvasStyle?: string;

_offset: { left: number; top: number };
protected hasLostContext: boolean;
Expand All @@ -286,6 +283,22 @@ export class StaticCanvas<
kill: (reason?: any) => void;
};

constructor(el: string | HTMLCanvasElement, options = {}) {
super();
this.renderAndReset = this.renderAndReset.bind(this);
this.requestRenderAll = this.requestRenderAll.bind(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these were renamed,
see description

Copy link
Member

Choose a reason for hiding this comment

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

Yes yes i have read everything i was in the middle of things and then i had to go to bed.
Probably going to let them both names.

this.initElements(el);
this._initOptions(options);
this.calcOffset();
this._initRetinaScaling();
this.calcViewportBoundaries();
}

protected initElements(el: string | HTMLCanvasElement) {
this._createLowerCanvas(el);
this._originalCanvasStyle = this.lowerCanvasEl.style.cssText;
}

add(...objects: FabricObject[]) {
const size = super.add(...objects);
objects.length > 0 && this.renderOnAddRemove && this.requestRenderAll();
Expand Down Expand Up @@ -332,37 +345,6 @@ export class StaticCanvas<
this.renderOnAddRemove && this.requestRenderAll();
}

constructor(el: string | HTMLCanvasElement, options = {}) {
super();
this._init(el, options);
}

/**
* @private
* @param {HTMLCanvasElement | String} el <canvas> element to initialize instance on
* @param {Object} [options] Options object
*/
_init(el: string | HTMLCanvasElement, options = {}) {
this.renderAndResetBound = this.renderAndReset.bind(this);
this.requestRenderAllBound = this.requestRenderAll.bind(this);
this._initStatic(el, options);
this._initRetinaScaling();
this.calcViewportBoundaries();
}

/**
* @private
* @param {HTMLCanvasElement | String} el <canvas> element to initialize instance on
* @param {Object} [options] Options object
*/
_initStatic(el: string | HTMLCanvasElement, options = {}) {
this._objects = [];
this._createLowerCanvas(el);
this._originalCanvasStyle = this.lowerCanvasEl.style.cssText;
this._initOptions(options);
this.calcOffset();
}

/**
* @private
*/
Expand Down Expand Up @@ -727,7 +709,7 @@ export class StaticCanvas<
*/
requestRenderAll() {
if (!this.nextRenderHandle && !this.disposed && !this.destroyed) {
this.nextRenderHandle = requestAnimFrame(this.renderAndResetBound);
this.nextRenderHandle = requestAnimFrame(this.renderAndReset);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mixins/canvas_animation.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fabric.util.object.extend(
*/
fxStraightenObject: function (object: FabricObject) {
return object.fxStraighten({
onChange: this.requestRenderAllBound,
onChange: this.requestRenderAll,
});
},
}
Expand Down
3 changes: 1 addition & 2 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@
assert.ok(canvas.selection, 'default is true');
});

QUnit.test('_initInteractive', function(assert) {
assert.ok(typeof canvas._init === 'function');
QUnit.test('init', function(assert) {
assert.equal(canvas.lowerCanvasEl.getAttribute('data-fabric'), 'main', 'el should be marked by canvas init');
assert.equal(canvas.upperCanvasEl.getAttribute('data-fabric'), 'top', 'el should be marked by canvas init');
assert.equal(canvas.wrapperEl.getAttribute('data-fabric'), 'wrapper', 'el should be marked by canvas init');
Expand Down
2 changes: 2 additions & 0 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@
assert.ok('imageSmoothingEnabled' in canvas);
assert.ok('backgroundVpt' in canvas);
assert.ok('overlayVpt' in canvas);
assert.ok(Array.isArray(canvas._objects), 'is array');
assert.equal(canvas._objects.length, 0, 'is empty array');

assert.equal(canvas.includeDefaultValues, true);
assert.equal(canvas.stateful, false);
Expand Down
8 changes: 8 additions & 0 deletions test/unit/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
}
});

QUnit.test('init', function (assert) {
assert.ok(Array.isArray(collection._objects), 'is array');
assert.equal(collection._objects.length, 0, 'is empty array');
assert.ok(Array.isArray(collection2._objects), 'is array');
assert.equal(collection2._objects.length, 0, 'is empty array');
assert.notEqual(collection._objects, collection2._objects, 'different array');
});

QUnit.test('add', function(assert) {
var obj = { prop: 4 };
assert.ok(typeof collection.add === 'function', 'has add method');
Expand Down