@greener-games/vite-screen-size 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -0
- package/dist/index.cjs +60 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.mjs +97 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @greener-games/vite-plugin-screen-size
|
|
2
|
+
|
|
3
|
+
A lightweight Vite plugin that displays the current screen dimensions and active breakpoint in a small, non-intrusive overlay during development.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 📏 **Live Dimensions**: Shows real-time window width and height.
|
|
11
|
+
- 📱 **Breakpoint Detection**: Automatically identifies the active breakpoint (Tailwind, Bootstrap, or Custom).
|
|
12
|
+
- 🎨 **Modern UI**: Clean, semi-transparent overlay with a glassmorphism effect.
|
|
13
|
+
- 🛠 **Zero Config**: Works out of the box with Tailwind breakpoints.
|
|
14
|
+
- 🚀 **Dev-Only**: Automatically disabled in production builds.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -D @greener-games/vite-plugin-screen-size
|
|
20
|
+
# or
|
|
21
|
+
yarn add -D @greener-games/vite-plugin-screen-size
|
|
22
|
+
# or
|
|
23
|
+
pnpm add -D @greener-games/vite-plugin-screen-size
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Add it to your `vite.config.ts` (or `vite.config.js`):
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { defineConfig } from 'vite';
|
|
32
|
+
import screenSize from '@greener-games/vite-plugin-screen-size';
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [
|
|
36
|
+
// Simple setup with default options (Tailwind breakpoints)
|
|
37
|
+
screenSize()
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
The plugin uses Tailwind CSS breakpoints by default. You can change this behavior by providing an options object to the plugin.
|
|
45
|
+
|
|
46
|
+
You can customize the breakpoints or use a different preset:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
screenSize({
|
|
50
|
+
/**
|
|
51
|
+
* Presets: 'tailwind' (default), 'bootstrap', or 'none'
|
|
52
|
+
*/
|
|
53
|
+
preset: 'tailwind',
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Custom breakpoints mapping name to pixel value.
|
|
57
|
+
* Custom breakpoints will override preset values if the names overlap.
|
|
58
|
+
*/
|
|
59
|
+
breakpoints: {
|
|
60
|
+
xs: 480,
|
|
61
|
+
tablet: 768,
|
|
62
|
+
desktop: 1024,
|
|
63
|
+
'4k': 2560
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Tailwind (Default)**
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"sm": 640,
|
|
72
|
+
"md": 768,
|
|
73
|
+
"lg": 1024,
|
|
74
|
+
"xl": 1280,
|
|
75
|
+
"2xl": 1536
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Bootstrap**
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"sm": 576,
|
|
83
|
+
"md": 768,
|
|
84
|
+
"lg": 992,
|
|
85
|
+
"xl": 1200,
|
|
86
|
+
"xxl": 1400
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**None**
|
|
91
|
+
Pass `preset: 'none'` to start with a blank slate, requiring you to provide your own breakpoints object.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
### Options
|
|
95
|
+
|
|
96
|
+
| Property | Type | Default | Description |
|
|
97
|
+
| --- | --- | --- | --- |
|
|
98
|
+
| `preset` | `'tailwind' \| 'bootstrap' \| 'none'` | `'tailwind'` | Predefined breakpoint sets. |
|
|
99
|
+
| `breakpoints` | `Record<string, number>` | `{}` | Custom breakpoint definitions. |
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=e=>`
|
|
2
|
+
(function() {
|
|
3
|
+
const breakpoints = ${JSON.stringify(e)};
|
|
4
|
+
const id = '__vite-plugin-screen-size';
|
|
5
|
+
if (document.getElementById(id)) return;
|
|
6
|
+
|
|
7
|
+
const container = document.createElement('div');
|
|
8
|
+
container.id = id;
|
|
9
|
+
Object.assign(container.style, {
|
|
10
|
+
position: 'fixed',
|
|
11
|
+
bottom: '10px',
|
|
12
|
+
right: '10px',
|
|
13
|
+
backgroundColor: 'rgba(15, 23, 42, 0.8)',
|
|
14
|
+
backdropFilter: 'blur(8px)',
|
|
15
|
+
color: '#f8fafc',
|
|
16
|
+
padding: '6px 12px',
|
|
17
|
+
borderRadius: '8px',
|
|
18
|
+
fontSize: '12px',
|
|
19
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
20
|
+
zIndex: '999999',
|
|
21
|
+
pointerEvents: 'none',
|
|
22
|
+
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
|
|
23
|
+
border: '1px solid rgba(255, 255, 255, 0.1)',
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
gap: '8px',
|
|
27
|
+
transition: 'opacity 0.2s'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const sizeEl = document.createElement('span');
|
|
31
|
+
const breakpointEl = document.createElement('span');
|
|
32
|
+
breakpointEl.style.fontWeight = 'bold';
|
|
33
|
+
breakpointEl.style.color = '#38bdf8';
|
|
34
|
+
breakpointEl.style.paddingLeft = '8px';
|
|
35
|
+
breakpointEl.style.borderLeft = '1px solid rgba(255, 255, 255, 0.2)';
|
|
36
|
+
|
|
37
|
+
container.appendChild(sizeEl);
|
|
38
|
+
container.appendChild(breakpointEl);
|
|
39
|
+
document.body.appendChild(container);
|
|
40
|
+
|
|
41
|
+
function update() {
|
|
42
|
+
const w = window.innerWidth;
|
|
43
|
+
const h = window.innerHeight;
|
|
44
|
+
sizeEl.textContent = \`\${w} × \${h}\`;
|
|
45
|
+
|
|
46
|
+
let active = 'base';
|
|
47
|
+
const sorted = Object.entries(breakpoints).sort((a, b) => b[1] - a[1]);
|
|
48
|
+
for (const [name, val] of sorted) {
|
|
49
|
+
if (w >= val) {
|
|
50
|
+
active = name;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
breakpointEl.textContent = active.toUpperCase();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
window.addEventListener('resize', update);
|
|
58
|
+
update();
|
|
59
|
+
})();
|
|
60
|
+
`,t={tailwind:{sm:640,md:768,lg:1024,xl:1280,"2xl":1536},bootstrap:{sm:576,md:768,lg:992,xl:1200,xxl:1400},none:{}};function n(n={}){let{preset:r=`tailwind`,breakpoints:i={}}=n,a={...t[r]||{},...i};return{name:`vite-screen-size`,apply:`serve`,transformIndexHtml(){return[{tag:`script`,attrs:{type:`module`},children:e(a),injectTo:`body`}]}}}exports.default=n,exports.screenSize=n;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin as Plugin_2 } from 'vite';
|
|
2
|
+
|
|
3
|
+
declare function screenSize(options?: ScreenSizeOptions): Plugin_2;
|
|
4
|
+
export default screenSize;
|
|
5
|
+
export { screenSize }
|
|
6
|
+
|
|
7
|
+
export declare interface ScreenSizeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Custom breakpoints mapping name to pixel value.
|
|
10
|
+
* e.g. { sm: 640, md: 768 }
|
|
11
|
+
*/
|
|
12
|
+
breakpoints?: Record<string, number>;
|
|
13
|
+
/**
|
|
14
|
+
* Standard presets
|
|
15
|
+
* @default 'tailwind'
|
|
16
|
+
*/
|
|
17
|
+
preset?: 'tailwind' | 'bootstrap' | 'none';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { }
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/client.ts
|
|
2
|
+
var e = (e) => `
|
|
3
|
+
(function() {
|
|
4
|
+
const breakpoints = ${JSON.stringify(e)};
|
|
5
|
+
const id = '__vite-plugin-screen-size';
|
|
6
|
+
if (document.getElementById(id)) return;
|
|
7
|
+
|
|
8
|
+
const container = document.createElement('div');
|
|
9
|
+
container.id = id;
|
|
10
|
+
Object.assign(container.style, {
|
|
11
|
+
position: 'fixed',
|
|
12
|
+
bottom: '10px',
|
|
13
|
+
right: '10px',
|
|
14
|
+
backgroundColor: 'rgba(15, 23, 42, 0.8)',
|
|
15
|
+
backdropFilter: 'blur(8px)',
|
|
16
|
+
color: '#f8fafc',
|
|
17
|
+
padding: '6px 12px',
|
|
18
|
+
borderRadius: '8px',
|
|
19
|
+
fontSize: '12px',
|
|
20
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
21
|
+
zIndex: '999999',
|
|
22
|
+
pointerEvents: 'none',
|
|
23
|
+
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
|
|
24
|
+
border: '1px solid rgba(255, 255, 255, 0.1)',
|
|
25
|
+
display: 'flex',
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
gap: '8px',
|
|
28
|
+
transition: 'opacity 0.2s'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const sizeEl = document.createElement('span');
|
|
32
|
+
const breakpointEl = document.createElement('span');
|
|
33
|
+
breakpointEl.style.fontWeight = 'bold';
|
|
34
|
+
breakpointEl.style.color = '#38bdf8';
|
|
35
|
+
breakpointEl.style.paddingLeft = '8px';
|
|
36
|
+
breakpointEl.style.borderLeft = '1px solid rgba(255, 255, 255, 0.2)';
|
|
37
|
+
|
|
38
|
+
container.appendChild(sizeEl);
|
|
39
|
+
container.appendChild(breakpointEl);
|
|
40
|
+
document.body.appendChild(container);
|
|
41
|
+
|
|
42
|
+
function update() {
|
|
43
|
+
const w = window.innerWidth;
|
|
44
|
+
const h = window.innerHeight;
|
|
45
|
+
sizeEl.textContent = \`\${w} × \${h}\`;
|
|
46
|
+
|
|
47
|
+
let active = 'base';
|
|
48
|
+
const sorted = Object.entries(breakpoints).sort((a, b) => b[1] - a[1]);
|
|
49
|
+
for (const [name, val] of sorted) {
|
|
50
|
+
if (w >= val) {
|
|
51
|
+
active = name;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
breakpointEl.textContent = active.toUpperCase();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
window.addEventListener('resize', update);
|
|
59
|
+
update();
|
|
60
|
+
})();
|
|
61
|
+
`, t = {
|
|
62
|
+
tailwind: {
|
|
63
|
+
sm: 640,
|
|
64
|
+
md: 768,
|
|
65
|
+
lg: 1024,
|
|
66
|
+
xl: 1280,
|
|
67
|
+
"2xl": 1536
|
|
68
|
+
},
|
|
69
|
+
bootstrap: {
|
|
70
|
+
sm: 576,
|
|
71
|
+
md: 768,
|
|
72
|
+
lg: 992,
|
|
73
|
+
xl: 1200,
|
|
74
|
+
xxl: 1400
|
|
75
|
+
},
|
|
76
|
+
none: {}
|
|
77
|
+
};
|
|
78
|
+
function n(n = {}) {
|
|
79
|
+
let { preset: r = "tailwind", breakpoints: i = {} } = n, a = {
|
|
80
|
+
...t[r] || {},
|
|
81
|
+
...i
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
name: "vite-screen-size",
|
|
85
|
+
apply: "serve",
|
|
86
|
+
transformIndexHtml() {
|
|
87
|
+
return [{
|
|
88
|
+
tag: "script",
|
|
89
|
+
attrs: { type: "module" },
|
|
90
|
+
children: e(a),
|
|
91
|
+
injectTo: "body"
|
|
92
|
+
}];
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { n as default, n as screenSize };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@greener-games/vite-screen-size",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vite plugin to show screen size and breakpoints in dev mode.",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "vite build",
|
|
24
|
+
"dev": "vite build --watch",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"vite": "^8.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.12.5",
|
|
32
|
+
"typescript": "^5.4.4",
|
|
33
|
+
"vite": "^8.0.13",
|
|
34
|
+
"vite-plugin-dts": "^4.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|