Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/adapt-dpi

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/adapt-dpi - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [2.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/adapt-dpi@2.0.1...@thi.ng/adapt-dpi@2.0.2) (2021-10-15)
**Note:** Version bump only for package @thi.ng/adapt-dpi
## [2.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/adapt-dpi@2.0.0...@thi.ng/adapt-dpi@2.0.1) (2021-10-13)

@@ -8,0 +16,0 @@

12

index.d.ts
/**
* Sets the canvas size to given `width` & `height` and adjusts style to
* compensate for HDPI devices. Note: For 2D canvases, this will
* automatically clear any prior canvas content.
* 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 the window's devicePixelRatio (or 1, if not
* available).
*

@@ -11,2 +13,6 @@ * @param canvas -

export declare const adaptDPI: (canvas: HTMLCanvasElement, width: number, height: number) => number;
/**
* Returns true if device's DPR > 1 (aka HighDPI)
*/
export declare const isHighDPI: () => boolean;
//# sourceMappingURL=index.d.ts.map
/**
* Sets the canvas size to given `width` & `height` and adjusts style to
* compensate for HDPI devices. Note: For 2D canvases, this will
* automatically clear any prior canvas content.
* 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 the window's devicePixelRatio (or 1, if not
* available).
*

@@ -12,3 +14,3 @@ * @param canvas -

const dpr = window.devicePixelRatio || 1;
if (dpr != 1) {
if (dpr !== 1) {
canvas.style.width = `${width}px`;

@@ -21,1 +23,5 @@ canvas.style.height = `${height}px`;

};
/**
* Returns true if device's DPR > 1 (aka HighDPI)
*/
export const isHighDPI = () => (window.devicePixelRatio || 1) > 1;
{
"name": "@thi.ng/adapt-dpi",
"version": "2.0.1",
"version": "2.0.2",
"description": "HDPI canvas adapter / styling utility",

@@ -37,3 +37,3 @@ "type": "module",

"devDependencies": {
"@thi.ng/testament": "^0.1.1"
"@thi.ng/testament": "^0.1.2"
},

@@ -64,3 +64,3 @@ "keywords": [

},
"gitHead": "2e6b3d7c0f4c5686c1e9bdb4902ed7d3f90bcc19"
"gitHead": "3c5f903104da150588946a94bb118ad559ad395d"
}

@@ -25,7 +25,6 @@ <!-- This file is generated - DO NOT EDIT! -->

Attempts to determine display pixel density via
`window.devicePixelRatio` (default 1.0) and resizes canvas accordingly.
I.e. If DPR != 1.0, attaches explicit `width` and `height` CSS
properties to force canvas to given pixel size, and resizes canvas pixel
buffer itself based on DPR (e.g. 2x size).
Attempts to determine display pixel density via `window.devicePixelRatio`
(default 1.0) and resizes canvas accordingly. I.e. If DPR != 1.0, attaches
explicit `width` and `height` CSS properties to force canvas to given CSS pixel
size, and resizes canvas pixel buffer itself based on DPR (e.g. 2x size).

@@ -61,3 +60,3 @@ ### Status

Package sizes (gzipped, pre-treeshake): ESM: 150 bytes
Package sizes (gzipped, pre-treeshake): ESM: 168 bytes

@@ -88,3 +87,3 @@ ## Dependencies

```ts
import { adaptDPI } from "@thi.ng/adapt-dpi";
import { adaptDPI, isHighDPI } from "@thi.ng/adapt-dpi";

@@ -94,2 +93,6 @@ const canvas = document.createElement("canvas");

adaptDPI(canvas, 640, 480);
if (isHighDPI()) {
// ...
}
```

@@ -96,0 +99,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc