Merge pull request #1422 from yinguangyao/master

feature: add native context types
This commit is contained in:
Anton Lavrenov 2022-10-10 11:35:40 -05:00 committed by GitHub
commit 578191d5d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -86,7 +86,7 @@ var CONTEXT_PROPERTIES = [
'globalAlpha',
'globalCompositeOperation',
'imageSmoothingEnabled',
];
] as const;
const traceArrMax = 100;
/**
@ -701,6 +701,11 @@ export class Context {
}
}
// supported context properties
type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
export interface Context extends CanvasContextProps {};
CONTEXT_PROPERTIES.forEach(function (prop) {
Object.defineProperty(Context.prototype, prop, {
get() {

View File

@ -57,7 +57,7 @@ describe('Context', function () {
'textBaseline',
'globalAlpha',
'globalCompositeOperation',
];
] as const;
it('context wrapper should work like native context', function () {
var stage = addStage();
@ -108,10 +108,10 @@ describe('Context', function () {
// test get
nativeContext.fillStyle = '#ff0000';
assert.equal(context['fillStyle'], '#ff0000');
assert.equal(context.fillStyle, '#ff0000');
// test set
context['globalAlpha'] = 0.5;
assert.equal(context['globalAlpha'], 0.5);
context.globalAlpha = 0.5;
assert.equal(context.globalAlpha, 0.5);
});
});