@wamlib/ngx-screen-size-reporter 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
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# NgxScreenSizeReporter
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.1.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build ngx-screen-size-reporter
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/ngx-screen-size-reporter
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BreakpointObserver } from '@angular/cdk/layout';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken, inject, computed, Injectable } from '@angular/core';
|
|
4
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
5
|
+
|
|
6
|
+
const NGX_SCREEN_SIZE_BREAKPOINT_ENUM = {
|
|
7
|
+
SMALL: 'small',
|
|
8
|
+
MEDIUM: 'medium',
|
|
9
|
+
LARGE: 'large',
|
|
10
|
+
SMALL_LANDSCAPE: 'smallLandscape',
|
|
11
|
+
MEDIUM_LANDSCAPE: 'mediumLandscape',
|
|
12
|
+
LARGE_LANDSCAPE: 'largeLandscape'
|
|
13
|
+
};
|
|
14
|
+
const NGX_SCREEN_SIZE_DEFAULT_BREAKPOINTS = {
|
|
15
|
+
[NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL]: '(max-width: 576px)',
|
|
16
|
+
[NGX_SCREEN_SIZE_BREAKPOINT_ENUM.MEDIUM]: '(min-width: 577px) and (max-width: 991px)',
|
|
17
|
+
[NGX_SCREEN_SIZE_BREAKPOINT_ENUM.LARGE]: '(min-width: 992px)',
|
|
18
|
+
[NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL_LANDSCAPE]: '(max-width: 936px) and (orientation: landscape)',
|
|
19
|
+
[NGX_SCREEN_SIZE_BREAKPOINT_ENUM.MEDIUM_LANDSCAPE]: '(min-width: 937px) and (max-width: 1297px) and (orientation: landscape)',
|
|
20
|
+
[NGX_SCREEN_SIZE_BREAKPOINT_ENUM.LARGE_LANDSCAPE]: '(min-width: 1298px) and (orientation: landscape)',
|
|
21
|
+
};
|
|
22
|
+
const NGX_SCREEN_SIZE_CONFIG = new InjectionToken('NGX_SCREEN_SIZE_CONFIG');
|
|
23
|
+
|
|
24
|
+
/** Service that emits whether the screen size is small or large. */
|
|
25
|
+
class ScreenSizeReporter {
|
|
26
|
+
#breakpointObserver = inject(BreakpointObserver);
|
|
27
|
+
#config = inject(NGX_SCREEN_SIZE_CONFIG, { optional: true }) ?? {
|
|
28
|
+
breakpoints: NGX_SCREEN_SIZE_DEFAULT_BREAKPOINTS
|
|
29
|
+
};
|
|
30
|
+
#state = toSignal(this.#breakpointObserver.observe(Object.values(this.#config.breakpoints)), { requireSync: true });
|
|
31
|
+
activeBreakpoint = computed(() => {
|
|
32
|
+
const breakpoints = this.#state().breakpoints;
|
|
33
|
+
const match = Object.entries(this.#config.breakpoints).find(([_, query]) => breakpoints[query]);
|
|
34
|
+
return (match ? match[0] : NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL);
|
|
35
|
+
}, ...(ngDevMode ? [{ debugName: "activeBreakpoint" }] : []));
|
|
36
|
+
isSmallScreen = computed(() => this.activeBreakpoint() === NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL ||
|
|
37
|
+
this.activeBreakpoint() === NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL_LANDSCAPE, ...(ngDevMode ? [{ debugName: "isSmallScreen" }] : []));
|
|
38
|
+
isLargeScreen = computed(() => !this.isSmallScreen(), ...(ngDevMode ? [{ debugName: "isLargeScreen" }] : []));
|
|
39
|
+
screenState = computed(() => ({
|
|
40
|
+
label: this.activeBreakpoint(),
|
|
41
|
+
isSmall: this.isSmallScreen(),
|
|
42
|
+
isLarge: this.isLargeScreen(),
|
|
43
|
+
allBreakpoints: this.#state().breakpoints
|
|
44
|
+
}), ...(ngDevMode ? [{ debugName: "screenState" }] : []));
|
|
45
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ScreenSizeReporter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
46
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ScreenSizeReporter, providedIn: 'root' });
|
|
47
|
+
}
|
|
48
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ScreenSizeReporter, decorators: [{
|
|
49
|
+
type: Injectable,
|
|
50
|
+
args: [{
|
|
51
|
+
providedIn: 'root',
|
|
52
|
+
}]
|
|
53
|
+
}] });
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Public API Surface of ngx-screen-size-reporter
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Generated bundle index. Do not edit.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export { ScreenSizeReporter };
|
|
64
|
+
//# sourceMappingURL=wamlib-ngx-screen-size-reporter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wamlib-ngx-screen-size-reporter.mjs","sources":["../../../projects/ngx-screen-size-reporter/src/lib/ngx-screen-size.ts","../../../projects/ngx-screen-size-reporter/src/lib/ngx-screen-size-reporter.ts","../../../projects/ngx-screen-size-reporter/src/public-api.ts","../../../projects/ngx-screen-size-reporter/src/wamlib-ngx-screen-size-reporter.ts"],"sourcesContent":["import {InjectionToken} from '@angular/core';\n\nexport const NGX_SCREEN_SIZE_BREAKPOINT_ENUM = {\n SMALL: 'small',\n MEDIUM: 'medium',\n LARGE: 'large',\n SMALL_LANDSCAPE: 'smallLandscape',\n MEDIUM_LANDSCAPE: 'mediumLandscape',\n LARGE_LANDSCAPE: 'largeLandscape'\n} as const satisfies Record<string, string>;\n\nexport type NgxScreenSizeBreakpoint = (typeof NGX_SCREEN_SIZE_BREAKPOINT_ENUM)[keyof typeof NGX_SCREEN_SIZE_BREAKPOINT_ENUM];\n\nexport type NgxScreenSizeBreakpointMap = { [K in NgxScreenSizeBreakpoint]: string };\n\nexport interface NgxScreenSizeConfig {\n breakpoints: NgxScreenSizeBreakpointMap;\n}\n\nexport const NGX_SCREEN_SIZE_DEFAULT_BREAKPOINTS = {\n [NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL]: '(max-width: 576px)',\n [NGX_SCREEN_SIZE_BREAKPOINT_ENUM.MEDIUM]: '(min-width: 577px) and (max-width: 991px)',\n [NGX_SCREEN_SIZE_BREAKPOINT_ENUM.LARGE]: '(min-width: 992px)',\n [NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL_LANDSCAPE]: '(max-width: 936px) and (orientation: landscape)',\n [NGX_SCREEN_SIZE_BREAKPOINT_ENUM.MEDIUM_LANDSCAPE]: '(min-width: 937px) and (max-width: 1297px) and (orientation: landscape)',\n [NGX_SCREEN_SIZE_BREAKPOINT_ENUM.LARGE_LANDSCAPE]: '(min-width: 1298px) and (orientation: landscape)',\n} satisfies NgxScreenSizeBreakpointMap;\n\n\nexport const NGX_SCREEN_SIZE_CONFIG = new InjectionToken<NgxScreenSizeConfig>('NGX_SCREEN_SIZE_CONFIG');\n","import { BreakpointObserver } from \"@angular/cdk/layout\";\nimport {Injectable, inject, computed} from \"@angular/core\";\nimport {toSignal} from '@angular/core/rxjs-interop';\nimport {\n NGX_SCREEN_SIZE_BREAKPOINT_ENUM, NGX_SCREEN_SIZE_CONFIG,\n NGX_SCREEN_SIZE_DEFAULT_BREAKPOINTS,\n NgxScreenSizeBreakpoint\n} from './ngx-screen-size';\n\n/** Service that emits whether the screen size is small or large. */\n@Injectable({\n providedIn: 'root',\n})\nexport class ScreenSizeReporter {\n\n #breakpointObserver = inject(BreakpointObserver);\n\n #config = inject(NGX_SCREEN_SIZE_CONFIG, { optional: true }) ?? {\n breakpoints: NGX_SCREEN_SIZE_DEFAULT_BREAKPOINTS\n };\n\n #state = toSignal(\n this.#breakpointObserver.observe(Object.values(this.#config.breakpoints)),\n {requireSync: true}\n );\n\n readonly activeBreakpoint = computed(() => {\n const breakpoints = this.#state().breakpoints;\n const match = Object.entries(this.#config.breakpoints).find(([_, query]) => breakpoints[query]);\n return (match ? match[0] : NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL) as NgxScreenSizeBreakpoint;\n });\n\n readonly isSmallScreen = computed(() =>\n this.activeBreakpoint() === NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL ||\n this.activeBreakpoint() === NGX_SCREEN_SIZE_BREAKPOINT_ENUM.SMALL_LANDSCAPE\n );\n\n readonly isLargeScreen = computed(() => !this.isSmallScreen());\n\n readonly screenState = computed(() => ({\n label: this.activeBreakpoint(),\n isSmall: this.isSmallScreen(),\n isLarge: this.isLargeScreen(),\n allBreakpoints: this.#state().breakpoints\n }));\n\n}\n","/*\n * Public API Surface of ngx-screen-size-reporter\n */\n\nexport * from './lib/ngx-screen-size-reporter';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAEO,MAAM,+BAA+B,GAAG;AAC7C,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,eAAe,EAAE,gBAAgB;AACjC,IAAA,gBAAgB,EAAE,iBAAiB;AACnC,IAAA,eAAe,EAAE;CACwB;AAUpC,MAAM,mCAAmC,GAAG;AACjD,IAAA,CAAC,+BAA+B,CAAC,KAAK,GAAG,oBAAoB;AAC7D,IAAA,CAAC,+BAA+B,CAAC,MAAM,GAAG,2CAA2C;AACrF,IAAA,CAAC,+BAA+B,CAAC,KAAK,GAAG,oBAAoB;AAC7D,IAAA,CAAC,+BAA+B,CAAC,eAAe,GAAG,iDAAiD;AACpG,IAAA,CAAC,+BAA+B,CAAC,gBAAgB,GAAG,yEAAyE;AAC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A,WAAW,GAAG,QAAQ,CAAC,OAAO;AACrC,QAAA,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE;AAC9B,QAAA,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE;AAC7B,QAAA,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE;AAC7B,QAAA,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAC/B,KAAA,CAAC,uDAAC;uGA/BQ,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAlB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kBAAkB,cAFjB,MAAM,EAAA,CAAA;;2FAEP,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAH9B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACZD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wamlib/ngx-screen-size-reporter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": ">=15.0.0",
|
|
6
|
+
"@angular/core": ">=15.0.0",
|
|
7
|
+
"@angular/cdk": ">=15.0.0"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"tslib": "^2.3.0"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"module": "fesm2022/wamlib-ngx-screen-size-reporter.mjs",
|
|
14
|
+
"typings": "types/wamlib-ngx-screen-size-reporter.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": {
|
|
17
|
+
"default": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/wamlib-ngx-screen-size-reporter.d.ts",
|
|
21
|
+
"default": "./fesm2022/wamlib-ngx-screen-size-reporter.mjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
|
|
3
|
+
declare const NGX_SCREEN_SIZE_BREAKPOINT_ENUM: {
|
|
4
|
+
readonly SMALL: "small";
|
|
5
|
+
readonly MEDIUM: "medium";
|
|
6
|
+
readonly LARGE: "large";
|
|
7
|
+
readonly SMALL_LANDSCAPE: "smallLandscape";
|
|
8
|
+
readonly MEDIUM_LANDSCAPE: "mediumLandscape";
|
|
9
|
+
readonly LARGE_LANDSCAPE: "largeLandscape";
|
|
10
|
+
};
|
|
11
|
+
type NgxScreenSizeBreakpoint = (typeof NGX_SCREEN_SIZE_BREAKPOINT_ENUM)[keyof typeof NGX_SCREEN_SIZE_BREAKPOINT_ENUM];
|
|
12
|
+
|
|
13
|
+
/** Service that emits whether the screen size is small or large. */
|
|
14
|
+
declare class ScreenSizeReporter {
|
|
15
|
+
#private;
|
|
16
|
+
readonly activeBreakpoint: _angular_core.Signal<NgxScreenSizeBreakpoint>;
|
|
17
|
+
readonly isSmallScreen: _angular_core.Signal<boolean>;
|
|
18
|
+
readonly isLargeScreen: _angular_core.Signal<boolean>;
|
|
19
|
+
readonly screenState: _angular_core.Signal<{
|
|
20
|
+
label: NgxScreenSizeBreakpoint;
|
|
21
|
+
isSmall: boolean;
|
|
22
|
+
isLarge: boolean;
|
|
23
|
+
allBreakpoints: {
|
|
24
|
+
[key: string]: boolean;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ScreenSizeReporter, never>;
|
|
28
|
+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<ScreenSizeReporter>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { ScreenSizeReporter };
|