Skip to content

Commit

Permalink
Merge branch 'master' into reduce-setcoords-call
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Jun 23, 2024
2 parents 2c03ee1 + 3cc5d2e commit d93c3fa
Show file tree
Hide file tree
Showing 105 changed files with 5,642 additions and 2,289 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/templates/vanilla/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fabric from 'fabric';
import './styles.css';
import { testCase } from './testcases/nestedSelections';
import { testCase } from './testcases/filters';

const el = document.getElementById('canvas');
const canvas = (window.canvas = new fabric.Canvas(el));
Expand Down
48 changes: 48 additions & 0 deletions .codesandbox/templates/vanilla/src/testcases/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as fabric from 'fabric';

export async function testCase(canvas: fabric.Canvas) {
const canvasImage = new fabric.StaticCanvas(undefined, {
width: 200,
height: 200,
});
canvasImage.add(
new fabric.Rect({ fill: 'red', width: 100, height: 100, top: 0, left: 0 })
);
canvasImage.add(
new fabric.Rect({
fill: 'blue',
width: 100,
height: 100,
top: 0,
left: 100,
})
);
canvasImage.add(
new fabric.Rect({
fill: 'green',
width: 100,
height: 100,
top: 100,
left: 0,
})
);
canvasImage.add(
new fabric.Rect({
fill: 'purple',
width: 100,
height: 100,
top: 100,
left: 100,
})
);
canvasImage.renderAll();
const image = new fabric.Image(canvasImage.lowerCanvasEl);
image.filters = [
new fabric.filters.Noise({ noise: 0.2 }),
new fabric.filters.Vibrance({ vibrance: 0.3 }),
new fabric.filters.Vintage(),
new fabric.filters.Grayscale(),
];
image.applyFilters();
canvas.add(image);
}
69 changes: 69 additions & 0 deletions .codesandbox/templates/vanilla/src/testcases/flippedInteractive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as fabric from 'fabric';

export function testCase(canvas: fabric.Canvas, objectCaching = true) {
function renderNamedControl(
this: fabric.Control,
ctx: CanvasRenderingContext2D,
left: number,
top: number,
styleOverride: any,
fabricObject: fabric.FabricObject
) {
ctx.save();
ctx.font = '12px Arial';
ctx.fillStyle = 'black';
ctx.fillText(this.name || '??', left - 12, top - 3);
ctx.restore();
}

canvas.preserveObjectStacking = true;
const rect = new fabric.Rect({
left: 100,
top: 50,
width: 100,
height: 100,
flipX: false,
fill: 'blue',
padding: 20,
});

const controls = rect.controls;

Object.entries(controls).forEach(([key, control]) => {
control.name = key;
control.render = renderNamedControl;
});

const rect2 = new fabric.Rect({
top: 200,
width: 50,
height: 50,
fill: 'red',
flipX: true,
opacity: 1,
controls,
padding: 20,
});

const g = new fabric.Group([rect], {
subTargetCheck: true,
interactive: true,
objectCaching,
skewX: 0,
angle: 90,
flipY: true,
controls,
});
const g2 = new fabric.Group([rect2], {
top: 100,
left: 100,
subTargetCheck: true,
interactive: true,
objectCaching,
angle: 0,
flipY: false,
controls,
});
canvas.add(g);
canvas.add(g2);
}
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ body:
latest before filing a bug report, your issue might have been resolved
already.
options:
- 6.0.0-rc2
- 6.0.0-rc1
- 6.0.0-beta9
- 6.0.0-beta8
- 6.0.0-beta7
Expand Down Expand Up @@ -104,6 +106,11 @@ body:
label: Node Version (if applicable)
description: Provide the version if the bug occurs in Node.js
options:
- 22.2.0
- 22.1.0
- 22.0.0
- 21.7.3
- 21.7.2
- 21.7.1
- 21.7.0
- 21.6.2
Expand All @@ -115,6 +122,12 @@ body:
- 21.2.0
- 21.1.0
- 21.0.0
- 20.14.0
- 20.13.1
- 20.13.0
- 20.12.2
- 20.12.1
- 20.12.0
- 20.11.1
- 20.11.0
- 20.10.0
Expand Down Expand Up @@ -144,6 +157,10 @@ body:
- 19.1.0
- 19.0.1
- 19.0.0
- 18.20.3
- 18.20.2
- 18.20.1
- 18.20.0
- 18.19.1
- 18.19.0
- 18.18.2
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
with:
name: coverage-jest
path: .nyc_output/*.json

e2e:
needs: [prime-build]
name: Playwright tests
Expand Down Expand Up @@ -156,6 +157,10 @@ jobs:
with:
name: coverage-e2e
path: .nyc_output
- uses: actions/download-artifact@v3
with:
name: coverage-jest
path: .nyc_output
- run: ls -l .nyc_output
- run: npm run coverage:report
- uses: ShaMan123/lcov-reporter-action@v1.2.2
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
## [next]

- Reduce some calls to setCoords() [#9795](https://github.com/fabricjs/fabric.js/pull/9795)
- chore(TS): svg reviver is optional [#9935](https://github.com/fabricjs/fabric.js/pull/9935)
- refactor(filters): Remove mainParameter, add stronger types to filters, refactor getUniformLocations [#9933](https://github.com/fabricjs/fabric.js/pull/9933)
- refactor(): remove strict parameter for ancestry. [#9918](https://github.com/fabricjs/fabric.js/pull/9918)
- feat(Color): add support for decimals and different angle types in HSL color parsing [#9915](https://github.com/fabricjs/fabric.js/pull/9915)
- fix(Controls): add support for numeric origins to changeWidth [#9909](https://github.com/fabricjs/fabric.js/pull/9909)
- fix(ActiveSelection): fixed render order so group controls are rendered over child objects [#9914](https://github.com/fabricjs/fabric.js/pull/9914)
- fix(filters): RemoveColor has missing getFragmentSource method ( typo ) [#9911](https://github.com/fabricjs/fabric.js/pull/9911)
- types(): Make event type explicit - non generic, and fix pattern fromObject type [#9907](https://github.com/fabricjs/fabric.js/pull/9907)

## [6.0.0-rc2]

- perf(): remove some runtime RegExp usages [#9802](https://github.com/fabricjs/fabric.js/pull/9802)
- fix(Canvas): Avoid exporting controls with toDataURL [#9896](https://github.com/fabricjs/fabric.js/pull/9896)
- perf(): Rework constructors to avoid the extra perf cost of current setup [#9891](https://github.com/fabricjs/fabric.js/pull/9891)
- perf(): Remove redundant matrix multiplication in multiplayTransformMatrixArray [#9893](https://github.com/fabricjs/fabric.js/pull/9893)
- test(): Convert Animation tests to jest [#9892](https://github.com/fabricjs/fabric.js/pull/9892)
- perf(ObjectGeometry): replace cache key string with array [#9887](https://github.com/fabricjs/fabric.js/pull/9887)
- docs(): Improve JSDOCs for BlendImage [#9876](https://github.com/fabricjs/fabric.js/pull/9876)
- fix(Group): Pass down the abort signal from group to objects [#9890](https://github.com/fabricjs/fabric.js/pull/9890)
- fix(util): restore old composeMatrix code for performances improvement [#9851](https://github.com/fabricjs/fabric.js/pull/9851)
- fix(Control): corner coords definition order [#9884](https://github.com/fabricjs/fabric.js/pull/9884)
- fix(Polyline): safeguard points arg from options [#9855](https://github.com/fabricjs/fabric.js/pull/9855)
- feat(IText): Adjust cursor blinking for better feedback [#9823](https://github.com/fabricjs/fabric.js/pull/9823)
- feat(FabricObject): pass `e` to `shouldStartDragging` [#9843](https://github.com/fabricjs/fabric.js/pull/9843)
- fix(Canvas): mouse move before event data [#9849](https://github.com/fabricjs/fabric.js/pull/9849)
- chore(FabricObject): pass `e` to `shouldStartDragging` [#9843](https://github.com/fabricjs/fabric.js/pull/9843)
- ci(): Add Jest coverage to the report [#9836](https://github.com/fabricjs/fabric.js/pull/9836)
- test(): Add cursor animation testing and migrate some easy one to jest [#9829](https://github.com/fabricjs/fabric.js/pull/9829)
- fix(Group, Controls): Fix interactive group actions when negative scaling is involved [#9811](https://github.com/fabricjs/fabric.js/pull/9811)
- fix(): Replace 'hasOwn' with 'in' operator in typeAssertions check [#9812](https://github.com/fabricjs/fabric.js/pull/9812)

## [6.0.0-rc1]

- fix(Canvas): Fix searchPossibleTargets for non-interactive nested targets [#9762](https://github.com/fabricjs/fabric.js/pull/9762)
- test(): Rename svg tests [#9775](https://github.com/fabricjs/fabric.js/pull/9775)
- refactor(): `_findTargetCorner` is now called `findControl` and returns the key and the control and the coordinates [#9668](https://github.com/fabricjs/fabric.js/pull/9668)
Expand Down
4 changes: 4 additions & 0 deletions fabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export {
*/
FabricObject as Object,
} from './src/shapes/Object/FabricObject';
/**
* Exported so we can tweak default values
*/
export { FabricObject as BaseFabricObject } from './src/shapes/Object/Object';

export type {
TFabricObjectProps,
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
coverageDirectory: '.nyc_output',

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['/node_modules/'],
coveragePathIgnorePatterns: ['/node_modules/', 'jest.extend.ts'],

// Indicates which provider should be used to instrument code for coverage (babel)
coverageProvider: 'v8',
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = {
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
maxWorkers: '75%',

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"homepage": "http://fabricjs.com/",
"version": "6.0.0-beta20",
"version": "6.0.0-rc2",
"author": "Juriy Zaytsev <kangax@gmail.com>",
"contributors": [
{
Expand Down
36 changes: 19 additions & 17 deletions src/EventTypeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,30 @@ export type TModificationEvents =

export interface ModifiedEvent<E extends Event = TPointerEvent> {
e?: E;
transform: Transform;
transform?: Transform;
target: FabricObject;
action?: string;
}

type ModificationEventsSpec<
Prefix extends string = '',
Modification = BasicTransformEvent,
Modified = ModifiedEvent | never
> = Record<`${Prefix}${TModificationEvents}`, Modification> &
Record<`${Prefix}modified`, Modified>;

type ObjectModificationEvents = ModificationEventsSpec;

type CanvasModificationEvents = ModificationEventsSpec<
'object:',
BasicTransformEvent & { target: FabricObject },
// TODO: this typing makes not possible to use properties from modified event
// in object:modified
ModifiedEvent | { target: FabricObject }
> & {
type ObjectModificationEvents = {
moving: BasicTransformEvent;
scaling: BasicTransformEvent;
rotating: BasicTransformEvent;
skewing: BasicTransformEvent;
resizing: BasicTransformEvent;
modifyPoly: BasicTransformEvent;
modified: ModifiedEvent;
};

type CanvasModificationEvents = {
'before:transform': TEvent & { transform: Transform };
'object:moving': BasicTransformEvent & { target: FabricObject };
'object:scaling': BasicTransformEvent & { target: FabricObject };
'object:rotating': BasicTransformEvent & { target: FabricObject };
'object:skewing': BasicTransformEvent & { target: FabricObject };
'object:resizing': BasicTransformEvent & { target: FabricObject };
'object:modifyPoly': BasicTransformEvent & { target: FabricObject };
'object:modified': ModifiedEvent;
};

export interface TPointerEventInfo<E extends TPointerEvent = TPointerEvent>
Expand Down
2 changes: 1 addition & 1 deletion src/Pattern/Pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class Pattern {

static async fromObject(
{ type, source, ...serialized }: SerializedPatternOptions,
options: Abortable
options?: Abortable
): Promise<Pattern> {
const img = await loadImage(source, {
...options,
Expand Down
2 changes: 1 addition & 1 deletion src/Pattern/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type PatternOptions = Partial<Pick<Pattern, ExportedKeys>> & {
source: CanvasImageSource;
};

export type SerializedPatternOptions = PatternOptions & {
export type SerializedPatternOptions = Omit<PatternOptions, 'source'> & {
type: 'pattern';
source: string;
};
24 changes: 11 additions & 13 deletions src/Shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ import { rotateVector } from './util/misc/vectors';

const shadowOffsetRegex = '(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?';

const reOffsetsAndBlur = () =>
new RegExp(
'(?:\\s|^)' +
shadowOffsetRegex +
shadowOffsetRegex +
'(' +
reNum +
'?(?:px)?)?(?:\\s?|$)(?:$|\\s)'
);
const reOffsetsAndBlur = new RegExp(
'(?:\\s|^)' +
shadowOffsetRegex +
shadowOffsetRegex +
'(' +
reNum +
'?(?:px)?)?(?:\\s?|$)(?:$|\\s)'
);

export const shadowDefaultValues: Partial<TClassProperties<Shadow>> = {
color: 'rgb(0,0,0)',
Expand Down Expand Up @@ -127,7 +126,7 @@ export class Shadow {
constructor(arg0: string | Partial<TClassProperties<Shadow>>) {
const options: Partial<TClassProperties<Shadow>> =
typeof arg0 === 'string' ? Shadow.parseShadow(arg0) : arg0;
Object.assign(this, (this.constructor as typeof Shadow).ownDefaults);
Object.assign(this, Shadow.ownDefaults);
for (const prop in options) {
// @ts-expect-error for loops are so messy in TS
this[prop] = options[prop];
Expand All @@ -142,11 +141,10 @@ export class Shadow {
*/
static parseShadow(value: string) {
const shadowStr = value.trim(),
regex = reOffsetsAndBlur(),
[, offsetX = 0, offsetY = 0, blur = 0] = (
regex.exec(shadowStr) || []
reOffsetsAndBlur.exec(shadowStr) || []
).map((value) => parseFloat(value) || 0),
color = (shadowStr.replace(regex, '') || 'rgb(0,0,0)').trim();
color = (shadowStr.replace(reOffsetsAndBlur, '') || 'rgb(0,0,0)').trim();

return {
color,
Expand Down
Loading

0 comments on commit d93c3fa

Please sign in to comment.