Skip to content

Commit af8d6a1

Browse files
committed
fix typings
1 parent b508b75 commit af8d6a1

File tree

6 files changed

+539
-74
lines changed

6 files changed

+539
-74
lines changed

index.d.ts

Lines changed: 135 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,140 @@
1-
export interface ViewportFunctions {
2-
/**
3-
* A method that runs when the viewport is first entered (triggered only once).
4-
*/
5-
oninit?(): void
6-
/**
7-
* A method to fire when you enter the viewport.
1+
interface ViewportFunctions {
2+
/**
3+
* A method that runs when the viewport is first entered (triggered only once).
4+
*/
5+
oninit?(): void;
6+
/**
7+
* A method to fire when you enter the viewport.
8+
*/
9+
onenter?(): void;
10+
/**
11+
* A method to fire when you leave the viewport.
12+
*/
13+
onexit?(): void;
14+
/**
15+
* A method to fire upon screen resize
16+
*/
17+
onresize?(screenX?: number): void;
18+
}
19+
interface ViewportOptions extends ViewportFunctions {
20+
/**
21+
* An ID reference for the viewport. This will be used in queries
22+
*/
23+
id: string;
24+
/**
25+
* The media query to match
26+
*
27+
* @example
28+
*
29+
* '(min-width: 768px)'
30+
*/
31+
query: string;
32+
}
33+
interface ViewportScreen {
34+
/**
35+
* Whether or not viewport is active
36+
*/
37+
active: boolean;
38+
/**
39+
* The ID reference for the viewport
40+
*/
41+
id: string;
42+
/**
43+
* The media query being matches
44+
*/
45+
query: string;
46+
/**
47+
* Match media instances
48+
*/
49+
test: MediaQueryList;
50+
/**
51+
* A `Set` List of methods that will be triggered upon initializing within the viewport
52+
*/
53+
oninit: Set<() => void>;
54+
/**
55+
* A `Set` List of methods that will be triggered when entering the viewport
856
*/
9-
onenter?(): void
10-
/**
11-
* A method to fire when you leave the viewport.
57+
onenter: Set<() => void>;
58+
/**
59+
* A `Set` List of methods that will be triggered when existing the viewport
1260
*/
13-
onexit?(): void
14-
/**
15-
* A method to fire upon screen resize
61+
onexit: Set<() => void>;
62+
/**
63+
* A `Set` List of methods that will be triggered when resizing the screen.
1664
*/
17-
onresize?(screenX?: number): void
65+
onresize: Set<(screenX?: number) => void>;
1866
}
67+
/**
68+
* The Viewports store
69+
*
70+
* Holds a reference to all states
71+
*/
72+
declare const viewports: Map<string, ReturnType<typeof create>>;
73+
/**
74+
* Create
75+
*
76+
* Create viewport states
77+
*/
78+
declare function create(opts: ViewportOptions): {
79+
onenter: () => void;
80+
onexit: () => void;
81+
onresize: (x: number) => void;
82+
destroy: () => void;
83+
readonly screen: ViewportScreen;
84+
};
85+
/**
86+
* Create Screens
87+
*
88+
* Define a set of viewports to match against. You can
89+
* optionally include methods or use `add` to set methods
90+
* at a later time.
91+
*/
92+
declare const screens: (options: ViewportOptions | ViewportOptions[]) => void;
93+
/**
94+
* Get Viewport
95+
*
96+
* Returns a viewport instance by its `id` else `false`
97+
*/
98+
declare const get: (id: string) => false | {
99+
onenter: () => void;
100+
onexit: () => void;
101+
onresize: (x: number) => void;
102+
destroy: () => void;
103+
readonly screen: ViewportScreen;
104+
};
105+
/**
106+
* Add Methods
107+
*
108+
* Add methods to be invoked in when the viewport is matched.
109+
*/
110+
declare const add: (id: string, actions: ViewportFunctions) => void;
111+
/**
112+
* List Screens
113+
*
114+
* Returns a list of viewport screens from the store. Optionally
115+
* provide a `string[]` list of ids.
116+
*/
117+
declare const list: (ids?: string[]) => ViewportScreen[];
118+
/**
119+
* Check State
120+
*
121+
* Returns a `boolean` value informing on whether the provided
122+
* viewport id is active or not. When no `id` parameter is passed
123+
* a list of viewport screens which are active will be returned.
124+
*/
125+
declare const active: (id?: string) => boolean | ViewportScreen | ViewportScreen[];
126+
/**
127+
* Remove viewport query
128+
*
129+
* Removes and destroys the viewport screen and store with
130+
* the matching `id` provided.
131+
*/
132+
declare const remove: (id: string) => void;
133+
/**
134+
* Destroy
135+
*
136+
* Removes all instances and tears down the listeners.
137+
*/
138+
declare const destroy: () => void;
19139

20-
export interface ViewportOptions extends ViewportFunctions {
21-
/**
22-
* An ID reference for the viewport. This will be used in queries
23-
*/
24-
id: string;
25-
/**
26-
* The media query to match
27-
*
28-
* @example
29-
*
30-
* '(min-width: 768px)'
31-
*/
32-
query: string;
33-
}
34-
35-
export interface ViewportScreen {
36-
/**
37-
* Whether or not viewport is active
38-
*/
39-
active: boolean;
40-
/**
41-
* The ID reference for the viewport
42-
*/
43-
id: string
44-
/**
45-
* The media query being matches
46-
*/
47-
query: string;
48-
/**
49-
* Match media instances
50-
*/
51-
test: MediaQueryList;
52-
/**
53-
* A `Set` List of methods that will be triggered upon initializing within the viewport
54-
*/
55-
oninit: Set<() => void>;
56-
/**
57-
* A `Set` List of methods that will be triggered when entering the viewport
58-
*/
59-
onenter: Set<() => void>;
60-
/**
61-
* A `Set` List of methods that will be triggered when existing the viewport
62-
*/
63-
onexit: Set<() => void>;
64-
/**
65-
* A `Set` List of methods that will be triggered when resizing the screen.
66-
*/
67-
onresize: Set<(screenX?: number) => void>;
68-
}
140+
export { active, add, destroy, get, list, remove, screens, viewports };

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@panoply/viewports",
33
"description": "A tiny (900 bytes gzipped) media query utility for programmatic control of screen viewports.",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"homepage": "https://github.com/panoply/viewports",
66
"author": {
77
"name": "Nikolas Savvidis",
@@ -53,11 +53,20 @@
5353
}
5454
},
5555
"scripts": {
56-
"dev": "esbuild src/index.ts --outfile=index.js --format=esm --bundle --watch",
57-
"build": "pnpm run esm",
58-
"esm": "esbuild src/index.ts --outfile=index.js --format=esm --bundle --mangle-props=^[$] --minify",
56+
"dev": "tsup --watch",
57+
"build": "tsup --minify --dts",
5958
"gzs": "gzip-size index.js --include-original"
6059
},
60+
"tsup": {
61+
"entry": [
62+
"./src/index.ts"
63+
],
64+
"clean": false,
65+
"outDir": ".",
66+
"format": [
67+
"esm"
68+
]
69+
},
6170
"browserslist": [
6271
"defaults",
6372
"Chrome >= 78",
@@ -75,10 +84,10 @@
7584
"@sissel/eslint-config": "^1.1.0",
7685
"@sissel/prettier-config": "^1.1.0",
7786
"browserslist": "^4.21.4",
78-
"esbuild": "^0.15.12",
7987
"eslint": "^8.26.0",
8088
"gzip-size-cli": "^5.1.0",
8189
"prettier": "^2.7.1",
90+
"tsup": "^6.3.0",
8291
"typescript": "^4.8.4"
8392
}
8493
}

0 commit comments

Comments
 (0)