UNPKG

@cobinhood/react-native-canvas

Version:

<div align="center"> <img src="https://emojipedia-us.s3.amazonaws.com/thumbs/240/apple/96/fireworks_1f386.png"/> <h1>react-native-canvas</h1> </div>

30 lines (28 loc) 912 B
var scale = function scale(ratio) { return function (item) { if (typeof item === 'number') { return item * ratio; } return item; }; }; window.autoScaleCanvas = function autoScaleCanvas(canvas) { var ctx = canvas.getContext('2d'); var ratio = window.devicePixelRatio || 1; if (ratio !== 1) { var width = canvas.layoutWidth || canvas.width; var height = canvas.layoutHeight || canvas.height; canvas.style.width = width + 'px'; canvas.style.height = height + 'px'; canvas.width = width * ratio; canvas.height = height * ratio; ctx.scale(ratio, ratio); ctx.isPointInPath = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return CanvasRenderingContext2D.prototype.isPointInPath.apply(ctx, args.map(scale(ratio))); }; } return canvas; };