mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: @idraw/kernal context-2d add globalCompositeOperation attr
This commit is contained in:
parent
a38c5e2343
commit
49691f81d1
2 changed files with 47 additions and 19 deletions
|
|
@ -1,13 +1,24 @@
|
|||
import Context2d from './../../src/lib/context-2d';
|
||||
|
||||
describe('@idraw/kernal: lib/context-2d', () => {
|
||||
|
||||
test('Context2d.globalAlpha', async () => {
|
||||
const globalAlpha = 0.55;
|
||||
const ctx2d = new Context2d();
|
||||
ctx2d.globalAlpha = globalAlpha;
|
||||
expect(ctx2d.globalAlpha).toStrictEqual(globalAlpha);
|
||||
expect(ctx2d.$getAllAttrs()).toStrictEqual({ globalAlpha });
|
||||
expect(ctx2d.$getAllRecords()).toStrictEqual([ { name: 'globalAlpha', type: 'attr', args: [ 0.55 ] } ]);
|
||||
expect(ctx2d.$getAllRecords()).toStrictEqual([ { name: 'globalAlpha', type: 'attr', args: [ globalAlpha ] } ]);
|
||||
});
|
||||
|
||||
test('Context2d.globalCompositeOperation', async () => {
|
||||
const globalCompositeOperation = 'source-over';
|
||||
const ctx2d = new Context2d();
|
||||
ctx2d.globalCompositeOperation = globalCompositeOperation;
|
||||
expect(ctx2d.globalCompositeOperation).toStrictEqual(globalCompositeOperation);
|
||||
expect(ctx2d.$getAllAttrs()).toStrictEqual({ globalCompositeOperation });
|
||||
expect(ctx2d.$getAllRecords()).toStrictEqual([ { name: 'globalCompositeOperation', type: 'attr', args: [ globalCompositeOperation ] } ]);
|
||||
expect(1).toStrictEqual(1);
|
||||
});
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
import { TypeContext, TypeBoardSizeOptions } from '@idraw/types';
|
||||
// import { TypeContext, TypeBoardSizeOptions } from '@idraw/types';
|
||||
|
||||
interface CanvasRenderingContext2D extends
|
||||
CanvasCompositing,
|
||||
CanvasDrawImage,
|
||||
CanvasDrawPath,
|
||||
CanvasFillStrokeStyles,
|
||||
CanvasFilters,
|
||||
CanvasImageData,
|
||||
CanvasImageSmoothing,
|
||||
CanvasPath,
|
||||
CanvasPathDrawingStyles,
|
||||
CanvasRect,
|
||||
CanvasShadowStyles,
|
||||
CanvasState,
|
||||
CanvasText,
|
||||
CanvasTextDrawingStyles,
|
||||
CanvasTransform,
|
||||
CanvasUserInterface {};
|
||||
// interface CanvasRenderingContext2D extends
|
||||
// CanvasCompositing,
|
||||
// CanvasDrawImage,
|
||||
// CanvasDrawPath,
|
||||
// CanvasFillStrokeStyles,
|
||||
// CanvasFilters,
|
||||
// CanvasImageData,
|
||||
// CanvasImageSmoothing,
|
||||
// CanvasPath,
|
||||
// CanvasPathDrawingStyles,
|
||||
// CanvasRect,
|
||||
// CanvasShadowStyles,
|
||||
// CanvasState,
|
||||
// CanvasText,
|
||||
// CanvasTextDrawingStyles,
|
||||
// CanvasTransform,
|
||||
// CanvasUserInterface {};
|
||||
|
||||
|
||||
type ContextRecord = {
|
||||
|
|
@ -27,6 +27,7 @@ type ContextRecord = {
|
|||
|
||||
type ContextAttr = {
|
||||
globalAlpha?: number;
|
||||
globalCompositeOperation?: string;
|
||||
}
|
||||
|
||||
class Context2d {
|
||||
|
|
@ -51,6 +52,22 @@ class Context2d {
|
|||
})
|
||||
}
|
||||
|
||||
get globalCompositeOperation (): string | undefined {
|
||||
return this._attrs['globalCompositeOperation'];
|
||||
}
|
||||
|
||||
// source-over source-in source-out source-atop destination-over destination-in destination-out destination-atop lighter copy xor multiply screen overlay darken lighten color-dodge color-burn hard-light soft-light difference exclusion hue saturation color luminosity
|
||||
set globalCompositeOperation(value: string | undefined) {
|
||||
this._attrs['globalCompositeOperation'] = value;
|
||||
this._records.push({
|
||||
name: 'globalCompositeOperation',
|
||||
type: 'attr',
|
||||
args: [value]
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
$getAllRecords(): ContextRecord[] {
|
||||
return this._records;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue