mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
feature: add native context types
This commit is contained in:
parent
c7857d7e2b
commit
4e89618a78
@ -86,7 +86,7 @@ var CONTEXT_PROPERTIES = [
|
|||||||
'globalAlpha',
|
'globalAlpha',
|
||||||
'globalCompositeOperation',
|
'globalCompositeOperation',
|
||||||
'imageSmoothingEnabled',
|
'imageSmoothingEnabled',
|
||||||
];
|
] as const;
|
||||||
|
|
||||||
const traceArrMax = 100;
|
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) {
|
CONTEXT_PROPERTIES.forEach(function (prop) {
|
||||||
Object.defineProperty(Context.prototype, prop, {
|
Object.defineProperty(Context.prototype, prop, {
|
||||||
get() {
|
get() {
|
||||||
|
@ -57,7 +57,7 @@ describe('Context', function () {
|
|||||||
'textBaseline',
|
'textBaseline',
|
||||||
'globalAlpha',
|
'globalAlpha',
|
||||||
'globalCompositeOperation',
|
'globalCompositeOperation',
|
||||||
];
|
] as const;
|
||||||
|
|
||||||
it('context wrapper should work like native context', function () {
|
it('context wrapper should work like native context', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
@ -108,10 +108,10 @@ describe('Context', function () {
|
|||||||
|
|
||||||
// test get
|
// test get
|
||||||
nativeContext.fillStyle = '#ff0000';
|
nativeContext.fillStyle = '#ff0000';
|
||||||
assert.equal(context['fillStyle'], '#ff0000');
|
assert.equal(context.fillStyle, '#ff0000');
|
||||||
|
|
||||||
// test set
|
// test set
|
||||||
context['globalAlpha'] = 0.5;
|
context.globalAlpha = 0.5;
|
||||||
assert.equal(context['globalAlpha'], 0.5);
|
assert.equal(context.globalAlpha, 0.5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user