Skip to content

Commit

Permalink
chore(TS) Remove data url and serialization mixins (#8542)
Browse files Browse the repository at this point in the history
Co-authored-by: ShaMan123 <shacharnen@gmail.com>
  • Loading branch information
asturur and ShaMan123 committed Mar 16, 2024
1 parent 7f3ec26 commit 59e6436
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 370 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- brush doesn't add result to canvas anymore
- `path:created`, `before:path:created` events are deprecated, use `interaction:completed` instead
- `_render` method is now protected, use `render` instead
- chore(TS): Migrate smaller mixins to classes (dataurl and serialization ) [#8542](https://github.com/fabricjs/fabric.js/pull/8542)
- chore(TS): Convert Canvas events mixin and grouping mixin [#8519](https://github.com/fabricjs/fabric.js/pull/8519)
- chore(TS): Remove backward compatibility initialize methods [#8525](https://github.com/fabricjs/fabric.js/pull/8525/)
- chore(TS): replace getKlass utility with a registry that doesn't require full fabricJS to work [#8500](https://github.com/fabricjs/fabric.js/pull/8500)
Expand Down
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import './src/pattern.class'; // optional pattern
import './src/shadow.class'; // optional shadow
import './src/canvas/static_canvas.class';
import './src/canvas/canvas_events'; // optional interaction
import './src/mixins/canvas_dataurl_exporter.mixin';
import './src/mixins/canvas_serialization.mixin'; // optional serialization
import './src/canvas/canvas_gestures.mixin'; // optional gestures
import './src/mixins/canvas_animation.mixin'; // optional animation
import './src/mixins/canvas_straightening.mixin'; // optional animation
import './src/shapes/Object/FabricObject';
import './src/mixins/object_stacking.mixin'; // removed in #8461
import './src/mixins/stateful.mixin'; // will die soon
Expand Down
2 changes: 2 additions & 0 deletions src/canvas/canvas.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { Textbox } from '../shapes/textbox.class';
import { pick } from '../util/misc/pick';
import { TSVGReviver } from '../mixins/object.svg_export';
import { sendPointToPlane } from '../util/misc/planeChange';
import { createCanvasElement } from '../util/misc/dom';

type TDestroyedCanvas = Omit<
SelectableCanvas<CanvasEvents>,
Expand Down Expand Up @@ -1535,6 +1536,7 @@ export class SelectableCanvas<
super.destroy();
wrapperEl.removeChild(upperCanvasEl);
wrapperEl.removeChild(lowerCanvasEl);
this._iTextInstances = [];
this.contextCache = null;
this.contextTop = null;
cleanUpJsdomNode(upperCanvasEl);
Expand Down
14 changes: 14 additions & 0 deletions src/canvas/canvas_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ActiveSelection } from '../shapes/active_selection.class';
import { Group } from '../shapes/group.class';
import type { FabricObject } from '../shapes/Object/FabricObject';
import { stopEvent } from '../util/dom_event';
import { createCanvasElement } from '../util/misc/dom';
import { sendPointToPlane } from '../util/misc/planeChange';
import {
isActiveSelection,
Expand Down Expand Up @@ -1640,6 +1641,19 @@ export class Canvas extends SelectableCanvas {
// clear selection and current transformation
this._groupSelector = null;
}

/**
* Clones canvas instance without cloning existing data.
* This essentially copies canvas dimensions since loadFromJSON does not affect canvas size.
* @returns {StaticCanvas}
*/
cloneWithoutData(): Canvas {
const el = createCanvasElement();
el.width = this.width;
el.height = this.height;
// this seems wrong. either Canvas or StaticCanvas
return new Canvas(el);
}
}

// there is an order execution bug if i put this as public property.
Expand Down
Loading

0 comments on commit 59e6436

Please sign in to comment.