@thi.ng/adapt-dpi
Advanced tools
Comparing version 2.2.27 to 2.2.28
# Change Log | ||
- **Last updated**: 2023-12-09T19:12:03Z | ||
- **Last updated**: 2023-12-11T10:07:09Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -5,0 +5,0 @@ |
37
index.js
@@ -1,25 +0,14 @@ | ||
/** | ||
* Sets the canvas size to given `width` & `height` (given as CSS pixels, | ||
* applied as device pixels) and adjusts canvas' `style` to compensate for HDPI | ||
* devices. Note: For 2D canvases, this will automatically clear any prior | ||
* canvas content. Returns given `dpr` (presumably [and also default] the | ||
* window's devicePixelRatio or 1, if not available). | ||
* | ||
* @param canvas - | ||
* @param width - uncompensated pixel width | ||
* @param height - uncompensated pixel height | ||
* @param dpr - device pixel ratio | ||
*/ | ||
export const adaptDPI = (canvas, width, height, dpr = window.devicePixelRatio || 1) => { | ||
if (dpr !== 1) { | ||
canvas.style.width = `${width}px`; | ||
canvas.style.height = `${height}px`; | ||
} | ||
canvas.width = width * dpr; | ||
canvas.height = height * dpr; | ||
return dpr; | ||
const adaptDPI = (canvas, width, height, dpr = window.devicePixelRatio || 1) => { | ||
if (dpr !== 1) { | ||
canvas.style.width = `${width}px`; | ||
canvas.style.height = `${height}px`; | ||
} | ||
canvas.width = width * dpr; | ||
canvas.height = height * dpr; | ||
return dpr; | ||
}; | ||
/** | ||
* Returns true if device's DPR > 1 (aka HighDPI) | ||
*/ | ||
export const isHighDPI = () => (window.devicePixelRatio || 1) > 1; | ||
const isHighDPI = () => (window.devicePixelRatio || 1) > 1; | ||
export { | ||
adaptDPI, | ||
isHighDPI | ||
}; |
{ | ||
"name": "@thi.ng/adapt-dpi", | ||
"version": "2.2.27", | ||
"version": "2.2.28", | ||
"description": "HDPI canvas adapter / styling utility", | ||
@@ -27,3 +27,5 @@ "type": "module", | ||
"scripts": { | ||
"build": "yarn clean && tsc --declaration", | ||
"build": "yarn build:esbuild && yarn build:decl", | ||
"build:decl": "tsc --declaration --emitDeclarationOnly", | ||
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts", | ||
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc", | ||
@@ -38,2 +40,3 @@ "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts", | ||
"@microsoft/api-extractor": "^7.38.3", | ||
"esbuild": "^0.19.8", | ||
"rimraf": "^5.0.5", | ||
@@ -68,3 +71,3 @@ "tools": "^0.0.1", | ||
}, | ||
"gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n" | ||
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22879
6
31