2.2.47 • Published 3 days ago

@thi.ng/adapt-dpi v2.2.47

Weekly downloads
23
License
Apache-2.0
Repository
github
Last release
3 days ago

adapt-dpi

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

HDPI canvas adapter / styling utility.

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).

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/adapt-dpi

ES module import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/adapt-dpi"></script>

Skypack documentation

For Node.js REPL:

# with flag only for < v16
node --experimental-repl-await

> const adaptDpi = await import("@thi.ng/adapt-dpi");

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

Dependencies

None

Usage examples

Several demos in this repo's /examples directory are using this package.

A selection:

ScreenshotDescriptionLive demoSource
Entity Component System w/ 100k 3D particlesDemoSource
WebGL cube maps with async texture loadingDemoSource
WebGL instancing, animated gridDemoSource
WebGL MSDF text rendering & particle systemDemoSource

API

Generated API docs

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

const canvas = document.createElement("canvas");

adaptDPI(canvas, 640, 480);

if (isHighDPI()) {
    // ...
}

Authors

Karsten Schmidt

If this project contributes to an academic publication, please cite it as:

@misc{thing-adapt-dpi,
  title = "@thi.ng/adapt-dpi",
  author = "Karsten Schmidt",
  note = "https://thi.ng/adapt-dpi",
  year = 2015
}

License

© 2015 - 2021 Karsten Schmidt // Apache Software License 2.0

2.2.47

3 days ago

2.2.46

6 days ago

2.2.45

15 days ago

2.2.44

18 days ago

2.2.43

30 days ago

2.2.42

1 month ago

2.2.41

2 months ago

2.2.40

2 months ago

2.2.39

2 months ago

2.2.38

2 months ago

2.2.37

3 months ago

2.2.35

3 months ago

2.2.36

3 months ago

2.2.34

3 months ago

2.2.32

3 months ago

2.2.31

4 months ago

2.2.30

4 months ago

2.2.29

4 months ago

2.2.28

5 months ago

2.2.27

5 months ago

2.2.26

5 months ago

2.2.17

9 months ago

2.2.18

8 months ago

2.2.15

9 months ago

2.2.16

9 months ago

2.2.14

9 months ago

2.2.19

8 months ago

2.2.24

6 months ago

2.2.25

5 months ago

2.2.22

6 months ago

2.2.23

6 months ago

2.2.20

7 months ago

2.2.21

6 months ago

2.2.13

11 months ago

2.2.12

12 months ago

2.2.11

1 year ago

2.2.10

1 year ago

2.2.9

1 year ago

2.2.7

1 year ago

2.2.8

1 year ago

2.2.5

1 year ago

2.2.4

1 year ago

2.2.6

1 year ago

2.2.1

1 year ago

2.2.0

2 years ago

2.2.3

1 year ago

2.2.2

1 year ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.8

2 years ago

2.1.9

2 years ago

2.1.6

2 years ago

2.1.7

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.1.0

2 years ago

2.0.4

3 years ago

2.0.6

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.22

3 years ago

1.0.23

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago