-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const unused = [ | ||
'direction', | ||
'filter', | ||
'fontKerning', | ||
'fontStretch', | ||
'fontVariantCaps', | ||
'globalCompositeOperation', | ||
'imageSmoothingEnabled', | ||
'imageSmoothingQuality', | ||
'letterSpacing', | ||
'textRendering', | ||
'getContextAttributes', | ||
'getLineDash', | ||
'getTransform', | ||
'isContextLost', | ||
'isPointInStroke', | ||
'reset', | ||
'roundRect', | ||
]; | ||
|
||
// 不常用 | ||
// const rarelyUsed = [ | ||
// 'lineDashOffset', | ||
// 'shadowColor', | ||
// 'shadowOffsetX', | ||
// 'shadowOffsetY', | ||
// 'wordSpacing', | ||
// 'createImageData', | ||
// 'getImageData', | ||
// 'putImageData', | ||
// 'createRadialGradient', | ||
// 'isPointInPath', | ||
// 'quadraticCurveTo', | ||
// 'strokeText', | ||
// 'transform', | ||
// ]; | ||
const createCollectContext = (ctx: CanvasRenderingContext2D) => { | ||
const canvas = ctx.canvas; | ||
|
||
const commands = []; | ||
const context = new Proxy(ctx, { | ||
get: (target, prop) => { | ||
if (prop === 'commands') { | ||
return commands; | ||
} | ||
// @ts-ignore | ||
if (unused.includes(prop)) { | ||
return; | ||
} | ||
commands.push([prop]); | ||
if (typeof target[prop] === 'function') { | ||
return target[prop].bind(target); | ||
} else { | ||
return target[prop]; | ||
} | ||
}, | ||
set: function(obj, prop, value) { | ||
commands.push([prop, value]); | ||
obj[prop] = value; | ||
return true; | ||
}, | ||
}); | ||
|
||
// @ts-ignore | ||
canvas.getContext = () => { | ||
return context; | ||
}; | ||
|
||
return context; | ||
}; | ||
|
||
export default createCollectContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"canvas":true,"clearRect":true,"fillStyle":true,"fillRect":true,"resetTransform":true,"save":true,"beginPath":true,"rect":true,"clip":true,"setTransform":true,"globalAlpha":true,"closePath":true,"fill":true,"restore":true,"arc":true,"font":true,"lineWidth":true,"textAlign":true,"lineJoin":true,"miterLimit":true,"textBaseline":true,"fillText":true,"strokeStyle":true,"moveTo":true,"lineTo":true,"lineCap":true,"stroke":true,"setLineDash":true,"ellipse":true,"bezierCurveTo":true,"createLinearGradient":true,"scale":true,"drawImage":true,"getImageData":true,"measureText":true,"translate":true,"rotate":true,"createPattern":true} |