capacitor-device-profile 0.0.0-stage → 0.1.1
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/CHANGELOG.md +15 -0
- package/CONTRIBUTING.md +52 -0
- package/LICENSE +21 -0
- package/README.md +83 -2
- package/SECURITY.md +26 -0
- package/dist/cjs/haptics.cjs +37 -0
- package/dist/cjs/haptics.d.cts +36 -0
- package/dist/cjs/haptics.d.cts.map +1 -0
- package/dist/cjs/index.cjs +24 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/index.d.cts.map +1 -0
- package/dist/cjs/lifecycle.cjs +85 -0
- package/dist/cjs/lifecycle.d.cts +48 -0
- package/dist/cjs/lifecycle.d.cts.map +1 -0
- package/dist/cjs/orientation.cjs +16 -0
- package/dist/cjs/orientation.d.cts +21 -0
- package/dist/cjs/orientation.d.cts.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/profile.cjs +86 -0
- package/dist/cjs/profile.d.cts +71 -0
- package/dist/cjs/profile.d.cts.map +1 -0
- package/dist/cjs/react.cjs +61 -0
- package/dist/cjs/react.d.cts +16 -0
- package/dist/cjs/react.d.cts.map +1 -0
- package/dist/cjs/safeArea.cjs +99 -0
- package/dist/cjs/safeArea.d.cts +33 -0
- package/dist/cjs/safeArea.d.cts.map +1 -0
- package/dist/esm/haptics.d.ts +36 -0
- package/dist/esm/haptics.d.ts.map +1 -0
- package/dist/esm/haptics.js +34 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/lifecycle.d.ts +48 -0
- package/dist/esm/lifecycle.d.ts.map +1 -0
- package/dist/esm/lifecycle.js +82 -0
- package/dist/esm/orientation.d.ts +21 -0
- package/dist/esm/orientation.d.ts.map +1 -0
- package/dist/esm/orientation.js +13 -0
- package/dist/esm/profile.d.ts +71 -0
- package/dist/esm/profile.d.ts.map +1 -0
- package/dist/esm/profile.js +77 -0
- package/dist/esm/react.d.ts +16 -0
- package/dist/esm/react.d.ts.map +1 -0
- package/dist/esm/react.js +56 -0
- package/dist/esm/safeArea.d.ts +33 -0
- package/dist/esm/safeArea.d.ts.map +1 -0
- package/dist/esm/safeArea.js +93 -0
- package/docs/API.md +123 -0
- package/docs/ARCHITECTURE.md +49 -0
- package/docs/contributing.md +26 -0
- package/package.json +142 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1 (2026-10-07)
|
|
4
|
+
|
|
5
|
+
First release on npmjs, as `capacitor-device-profile`, MIT licensed, from `github.com/jbcom/capacitor-device-profile`.
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* device profile (phone, foldable-open, tablet, desktop) that re-classifies live on fold and unfold
|
|
10
|
+
* orientation rule that never force-rotates, live safe-area insets, app lifecycle with a back-button stack, and a haptics facade
|
|
11
|
+
* dual ESM and CommonJS builds with format-correct declarations
|
|
12
|
+
|
|
13
|
+
### Build
|
|
14
|
+
|
|
15
|
+
* TypeScript 7 with `moduleResolution: bundler`, Node 26 and pnpm 12
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for taking the time to contribute.
|
|
4
|
+
|
|
5
|
+
## Getting set up
|
|
6
|
+
|
|
7
|
+
With [mise](https://mise.jdx.dev) (recommended — installs the Node and pnpm
|
|
8
|
+
versions pinned in `mise.toml`):
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
mise install
|
|
12
|
+
pnpm install
|
|
13
|
+
pnpm verify # lint, typecheck, test, build, package checks — the same gate CI runs
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Without mise, use `corepack` so pnpm matches the version pinned in
|
|
17
|
+
`package.json#packageManager`. The package is built on Node 26 (`.nvmrc`) and
|
|
18
|
+
runs on any release in the `engines.node` range (`>=24`; CI verifies 24 and 26
|
|
19
|
+
with the official `actions/setup-node` + `pnpm/action-setup`):
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
corepack enable
|
|
23
|
+
pnpm install
|
|
24
|
+
pnpm verify
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Making a change
|
|
28
|
+
|
|
29
|
+
1. Branch off `main`.
|
|
30
|
+
2. Write the test first. A bug fix should come with a test that fails without it.
|
|
31
|
+
3. Run `pnpm verify`. A change is not ready while any part of that is red.
|
|
32
|
+
4. Commit with [Conventional Commits](https://www.conventionalcommits.org):
|
|
33
|
+
`fix:`, `feat:`, `docs:`, `refactor:`, `test:`, `chore:`. Release Please uses
|
|
34
|
+
these commits to drive the changelog and next version number.
|
|
35
|
+
5. Open a pull request describing what changed and why.
|
|
36
|
+
|
|
37
|
+
## What gets reviewed
|
|
38
|
+
|
|
39
|
+
- Does it do what it says, and is there a test proving it?
|
|
40
|
+
- Does it keep the public API honest? A breaking change needs a `!` or a
|
|
41
|
+
`BREAKING CHANGE:` footer.
|
|
42
|
+
- Are the types right for consumers? CI runs `publint` and
|
|
43
|
+
`arethetypeswrong` because broken types only surface at integration time.
|
|
44
|
+
- Does it stay free of runtime dependencies and of any Capacitor import? The
|
|
45
|
+
plugins are passed in, so the package carries no Capacitor version.
|
|
46
|
+
- Is the device-class threshold change backed by a measured device?
|
|
47
|
+
|
|
48
|
+
## Releases
|
|
49
|
+
|
|
50
|
+
Releases are automated. Merging a conventional commit to `main` opens a
|
|
51
|
+
release pull request; merging that publishes to npm with provenance. Do not
|
|
52
|
+
hand-edit versions or the changelog.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jon Bogaty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# capacitor-device-profile
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/jbcom/capacitor-device-profile/actions/workflows/ci.yml)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
A small mobile and foldable runtime for web apps and games that ship in a Capacitor shell: one device
|
|
7
|
+
classification that re-classifies live when a foldable folds or unfolds, one orientation rule, live
|
|
8
|
+
safe-area insets, an app lifecycle with a back-button stack, and a haptics facade.
|
|
9
|
+
|
|
10
|
+
It has no runtime dependencies. Capacitor plugins are passed in, so the package carries no Capacitor
|
|
11
|
+
version, and every module unit-tests without a device.
|
|
12
|
+
|
|
13
|
+
Full documentation: **[jonbogaty.com/capacitor-device-profile](https://jonbogaty.com/capacitor-device-profile/)**
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pnpm add capacitor-device-profile
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requirements:
|
|
22
|
+
|
|
23
|
+
- Node.js 24 or newer for tooling (CI covers Node 24 and 26 on Linux)
|
|
24
|
+
- React 18 or 19 only if you use the optional `capacitor-device-profile/react` bindings
|
|
25
|
+
- The Capacitor plugins you want to drive (`@capacitor/app`, `@capacitor/haptics`,
|
|
26
|
+
`@capacitor/device`) are installed by the application and passed in
|
|
27
|
+
|
|
28
|
+
The package ships native ESM and CommonJS entry points with format-correct TypeScript declarations.
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { App } from '@capacitor/app'
|
|
34
|
+
import { Capacitor } from '@capacitor/core'
|
|
35
|
+
import { Device } from '@capacitor/device'
|
|
36
|
+
import { Haptics } from '@capacitor/haptics'
|
|
37
|
+
import { createAppLifecycle, createHaptics, decideOrientation } from 'capacitor-device-profile'
|
|
38
|
+
import { useDeviceProfile, useSafeAreaInsets } from 'capacitor-device-profile/react'
|
|
39
|
+
|
|
40
|
+
const native = Capacitor.isNativePlatform()
|
|
41
|
+
const lifecycle = createAppLifecycle({ app: App, native, onPause: pauseTimers })
|
|
42
|
+
const haptics = createHaptics({ plugin: Haptics, native })
|
|
43
|
+
|
|
44
|
+
// An open modal closes first on the Android back button; an unhandled press minimises the app.
|
|
45
|
+
const closeModal = lifecycle.pushBackHandler(() => dialog.close())
|
|
46
|
+
|
|
47
|
+
function Screen() {
|
|
48
|
+
const profile = useDeviceProfile({ loadPlatform: () => Device.getInfo() })
|
|
49
|
+
const insets = useSafeAreaInsets()
|
|
50
|
+
const { promptRotate, target } = decideOrientation(profile, 'landscape')
|
|
51
|
+
return promptRotate ? <RotateHint to={target} /> : <Layout form={profile.formFactor} inset={insets} />
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
| Export | What it does |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `classifyDevice(facts)` | `phone`, `foldable-open`, `tablet` or `desktop`, plus a `compact`/`expanded` frame, orientation, short/long edge, aspect and DPR |
|
|
60
|
+
| `isFoldableOpen(facts)` | Touch, aspect at most 1.3 and short edge at least 600 CSS px (OnePlus Open unfolded: 821x765, aspect 1.07) |
|
|
61
|
+
| `readViewportFacts(window, platform?)` | Reads `innerWidth`/`innerHeight`/DPR/touch; `null` gives a desktop default |
|
|
62
|
+
| `decideOrientation(profile, preferred)` | Which orientations to accept and whether to show a "turn the device" hint. Never force-rotates; tablets and foldables accept both |
|
|
63
|
+
| `watchSafeArea(options)` / `readSafeAreaInsets()` | Measures `env(safe-area-inset-*)` through a probe and publishes `--safe-top/right/bottom/left` px variables, re-measured on resize, orientation change, visual-viewport resize and fold posture change |
|
|
64
|
+
| `createAppLifecycle({ app, native, onPause, onResume })` | Pause/resume from Capacitor `App` (native) or page visibility (web); `pushBackHandler` stack; an unconsumed back press minimises instead of exiting |
|
|
65
|
+
| `createHaptics({ plugin, native })` | `impact`, `notify`, `selection`; no-ops on the web and while disabled; plugin failures never throw |
|
|
66
|
+
| `capacitor-device-profile/react`: `useDeviceProfile`, `useSafeAreaInsets`, `subscribeViewportGeometry` | Live bindings: a fold or unfold re-classifies without a reload |
|
|
67
|
+
|
|
68
|
+
The [API reference](./docs/API.md) has every signature and the exact classification rules.
|
|
69
|
+
|
|
70
|
+
## Develop
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
corepack enable
|
|
74
|
+
pnpm install --frozen-lockfile
|
|
75
|
+
pnpm verify # Biome, markdownlint, tsc, Vitest with coverage, the dual ESM/CJS build, publint, attw, a packed-consumer smoke
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Built on Node 26 (`.nvmrc`), pnpm 12 and TypeScript 7. Conventional Commits drive release-please;
|
|
79
|
+
merging its release pull request tags `v<version>` and the `cd.yml` publish job releases to npm with
|
|
80
|
+
provenance. See [CONTRIBUTING.md](./CONTRIBUTING.md) and [AGENTS.md](./AGENTS.md).
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
[MIT](./LICENSE)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
|
|
5
|
+
Please do not open a public issue for a security problem.
|
|
6
|
+
|
|
7
|
+
Report it privately through
|
|
8
|
+
[GitHub Security Advisories](https://github.com/jbcom/capacitor-device-profile/security/advisories/new),
|
|
9
|
+
which lets us discuss and fix the issue before it is disclosed.
|
|
10
|
+
|
|
11
|
+
You can expect an acknowledgement within a few days. If a fix is warranted, we
|
|
12
|
+
will prepare it privately, publish a patched release, and credit you in the
|
|
13
|
+
advisory unless you would rather remain anonymous.
|
|
14
|
+
|
|
15
|
+
## Supported versions
|
|
16
|
+
|
|
17
|
+
The latest `0.x` release receives security fixes. Older pre-1.0 releases are
|
|
18
|
+
not patched unless a coordinated disclosure requires an exceptional backport.
|
|
19
|
+
|
|
20
|
+
## In scope
|
|
21
|
+
|
|
22
|
+
Examples include package supply-chain issues, unexpected code execution during
|
|
23
|
+
install/build, and vulnerabilities in the package's runtime code (it has no
|
|
24
|
+
runtime dependencies). The Capacitor plugins an application passes in, and the
|
|
25
|
+
application built on top of capacitor-device-profile, are outside this repository's
|
|
26
|
+
security boundary.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Haptics facade. Native shells pass Capacitor's `Haptics` plugin; everywhere else every call is a
|
|
4
|
+
* no-op, so game code calls `haptics.impact()` unconditionally. A player setting can switch it off at
|
|
5
|
+
* runtime through `setEnabled`, and plugin failures are swallowed: a missing buzz must never throw
|
|
6
|
+
* into a frame loop.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createHaptics = createHaptics;
|
|
10
|
+
const IMPACT_STYLE = { light: 'LIGHT', medium: 'MEDIUM', heavy: 'HEAVY' };
|
|
11
|
+
const NOTIFICATION_TYPE = { success: 'SUCCESS', warning: 'WARNING', error: 'ERROR' };
|
|
12
|
+
function createHaptics(options) {
|
|
13
|
+
let enabled = options.enabled ?? true;
|
|
14
|
+
const plugin = options.native ? options.plugin : undefined;
|
|
15
|
+
const fire = (call) => {
|
|
16
|
+
if (!enabled || !plugin)
|
|
17
|
+
return;
|
|
18
|
+
void call(plugin).catch(() => undefined);
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
get enabled() {
|
|
22
|
+
return enabled;
|
|
23
|
+
},
|
|
24
|
+
setEnabled(next) {
|
|
25
|
+
enabled = next;
|
|
26
|
+
},
|
|
27
|
+
impact(strength = 'light') {
|
|
28
|
+
fire((target) => target.impact({ style: IMPACT_STYLE[strength] }));
|
|
29
|
+
},
|
|
30
|
+
notify(kind) {
|
|
31
|
+
fire((target) => target.notification({ type: NOTIFICATION_TYPE[kind] }));
|
|
32
|
+
},
|
|
33
|
+
selection() {
|
|
34
|
+
fire((target) => target.selectionChanged());
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Haptics facade. Native shells pass Capacitor's `Haptics` plugin; everywhere else every call is a
|
|
3
|
+
* no-op, so game code calls `haptics.impact()` unconditionally. A player setting can switch it off at
|
|
4
|
+
* runtime through `setEnabled`, and plugin failures are swallowed: a missing buzz must never throw
|
|
5
|
+
* into a frame loop.
|
|
6
|
+
*/
|
|
7
|
+
export type ImpactStrength = 'light' | 'medium' | 'heavy';
|
|
8
|
+
export type NotificationKind = 'success' | 'warning' | 'error';
|
|
9
|
+
/**
|
|
10
|
+
* The subset of Capacitor's `Haptics` plugin this module uses. The values sent are the string values
|
|
11
|
+
* of Capacitor's `ImpactStyle` and `NotificationType` enums; the fields are typed `string` so the real
|
|
12
|
+
* plugin (whose parameters are those enums) is assignable without this package importing Capacitor.
|
|
13
|
+
*/
|
|
14
|
+
export interface HapticsPluginLike {
|
|
15
|
+
impact(options?: {
|
|
16
|
+
style?: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
notification(options?: {
|
|
19
|
+
type?: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
selectionChanged(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface Haptics {
|
|
24
|
+
readonly enabled: boolean;
|
|
25
|
+
setEnabled(enabled: boolean): void;
|
|
26
|
+
impact(strength?: ImpactStrength): void;
|
|
27
|
+
notify(kind: NotificationKind): void;
|
|
28
|
+
selection(): void;
|
|
29
|
+
}
|
|
30
|
+
export interface HapticsOptions {
|
|
31
|
+
plugin?: HapticsPluginLike;
|
|
32
|
+
native: boolean;
|
|
33
|
+
enabled?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare function createHaptics(options: HapticsOptions): Haptics;
|
|
36
|
+
//# sourceMappingURL=haptics.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"haptics.d.ts","sourceRoot":"","sources":["../../src/haptics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AACzD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;AAE9D;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnD,YAAY,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IAClC,MAAM,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;IACvC,MAAM,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACpC,SAAS,IAAI,IAAI,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,MAAM,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAKD,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAwB9D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZERO_INSETS = exports.watchSafeArea = exports.readSafeAreaInsets = exports.applySafeAreaVariables = exports.TABLET_MIN_SHORT_EDGE = exports.readViewportFacts = exports.NEAR_SQUARE_MAX_ASPECT = exports.isFoldableOpen = exports.EXPANDED_MIN_SHORT_EDGE = exports.classifyOrientation = exports.classifyFrame = exports.classifyFormFactor = exports.classifyDevice = exports.decideOrientation = exports.createAppLifecycle = exports.createHaptics = void 0;
|
|
4
|
+
var haptics_js_1 = require("./haptics.cjs");
|
|
5
|
+
Object.defineProperty(exports, "createHaptics", { enumerable: true, get: function () { return haptics_js_1.createHaptics; } });
|
|
6
|
+
var lifecycle_js_1 = require("./lifecycle.cjs");
|
|
7
|
+
Object.defineProperty(exports, "createAppLifecycle", { enumerable: true, get: function () { return lifecycle_js_1.createAppLifecycle; } });
|
|
8
|
+
var orientation_js_1 = require("./orientation.cjs");
|
|
9
|
+
Object.defineProperty(exports, "decideOrientation", { enumerable: true, get: function () { return orientation_js_1.decideOrientation; } });
|
|
10
|
+
var profile_js_1 = require("./profile.cjs");
|
|
11
|
+
Object.defineProperty(exports, "classifyDevice", { enumerable: true, get: function () { return profile_js_1.classifyDevice; } });
|
|
12
|
+
Object.defineProperty(exports, "classifyFormFactor", { enumerable: true, get: function () { return profile_js_1.classifyFormFactor; } });
|
|
13
|
+
Object.defineProperty(exports, "classifyFrame", { enumerable: true, get: function () { return profile_js_1.classifyFrame; } });
|
|
14
|
+
Object.defineProperty(exports, "classifyOrientation", { enumerable: true, get: function () { return profile_js_1.classifyOrientation; } });
|
|
15
|
+
Object.defineProperty(exports, "EXPANDED_MIN_SHORT_EDGE", { enumerable: true, get: function () { return profile_js_1.EXPANDED_MIN_SHORT_EDGE; } });
|
|
16
|
+
Object.defineProperty(exports, "isFoldableOpen", { enumerable: true, get: function () { return profile_js_1.isFoldableOpen; } });
|
|
17
|
+
Object.defineProperty(exports, "NEAR_SQUARE_MAX_ASPECT", { enumerable: true, get: function () { return profile_js_1.NEAR_SQUARE_MAX_ASPECT; } });
|
|
18
|
+
Object.defineProperty(exports, "readViewportFacts", { enumerable: true, get: function () { return profile_js_1.readViewportFacts; } });
|
|
19
|
+
Object.defineProperty(exports, "TABLET_MIN_SHORT_EDGE", { enumerable: true, get: function () { return profile_js_1.TABLET_MIN_SHORT_EDGE; } });
|
|
20
|
+
var safeArea_js_1 = require("./safeArea.cjs");
|
|
21
|
+
Object.defineProperty(exports, "applySafeAreaVariables", { enumerable: true, get: function () { return safeArea_js_1.applySafeAreaVariables; } });
|
|
22
|
+
Object.defineProperty(exports, "readSafeAreaInsets", { enumerable: true, get: function () { return safeArea_js_1.readSafeAreaInsets; } });
|
|
23
|
+
Object.defineProperty(exports, "watchSafeArea", { enumerable: true, get: function () { return safeArea_js_1.watchSafeArea; } });
|
|
24
|
+
Object.defineProperty(exports, "ZERO_INSETS", { enumerable: true, get: function () { return safeArea_js_1.ZERO_INSETS; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createHaptics, type Haptics, type HapticsOptions, type HapticsPluginLike, type ImpactStrength, type NotificationKind, } from './haptics.cjs';
|
|
2
|
+
export { type AppLifecycle, type AppLifecycleOptions, type AppPluginLike, type BackHandler, createAppLifecycle, type LifecycleState, type PluginListenerHandleLike, } from './lifecycle.cjs';
|
|
3
|
+
export { decideOrientation, type OrientationDecision, type PreferredOrientation, } from './orientation.cjs';
|
|
4
|
+
export { classifyDevice, classifyFormFactor, classifyFrame, classifyOrientation, type DevicePlatform, type DeviceProfile, EXPANDED_MIN_SHORT_EDGE, type FormFactor, type FrameClass, isFoldableOpen, NEAR_SQUARE_MAX_ASPECT, readViewportFacts, TABLET_MIN_SHORT_EDGE, type ViewOrientation, type ViewportFacts, } from './profile.cjs';
|
|
5
|
+
export { applySafeAreaVariables, readSafeAreaInsets, type SafeAreaInsets, type SafeAreaWatchOptions, watchSafeArea, ZERO_INSETS, } from './safeArea.cjs';
|
|
6
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,wBAAwB,GAC9B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,cAAc,EACd,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,aAAa,EACb,WAAW,GACZ,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* App lifecycle: pause/resume and the Android back button, on native shells and in the browser.
|
|
4
|
+
*
|
|
5
|
+
* The Capacitor `App` plugin is passed in rather than imported, so this package carries no runtime
|
|
6
|
+
* dependency on Capacitor and the logic unit-tests with a fake. On the web, pause/resume comes from
|
|
7
|
+
* `visibilitychange`, `pagehide` and `pageshow`.
|
|
8
|
+
*
|
|
9
|
+
* Back handling is a stack: the most recently pushed handler (an open modal, then the pause menu)
|
|
10
|
+
* runs first, and returning `true` consumes the press. An unconsumed press minimises the app instead
|
|
11
|
+
* of exiting it, so a stray back never discards unsaved progress.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createAppLifecycle = createAppLifecycle;
|
|
15
|
+
function createAppLifecycle(options) {
|
|
16
|
+
const handlers = [];
|
|
17
|
+
const handles = [];
|
|
18
|
+
const removers = [];
|
|
19
|
+
let state = 'active';
|
|
20
|
+
let disposed = false;
|
|
21
|
+
const transition = (next) => {
|
|
22
|
+
if (disposed || next === state)
|
|
23
|
+
return;
|
|
24
|
+
state = next;
|
|
25
|
+
if (next === 'active')
|
|
26
|
+
options.onResume?.();
|
|
27
|
+
else
|
|
28
|
+
options.onPause?.();
|
|
29
|
+
};
|
|
30
|
+
const handleBack = () => {
|
|
31
|
+
for (let index = handlers.length - 1; index >= 0; index -= 1) {
|
|
32
|
+
const handler = handlers[index];
|
|
33
|
+
if (handler?.())
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
if (options.native && options.app) {
|
|
39
|
+
const app = options.app;
|
|
40
|
+
handles.push(app.addListener('appStateChange', ({ isActive }) => transition(isActive ? 'active' : 'background')));
|
|
41
|
+
handles.push(app.addListener('backButton', () => {
|
|
42
|
+
if (!handleBack())
|
|
43
|
+
void app.minimizeApp().catch(() => undefined);
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const win = options.window ?? (typeof window === 'undefined' ? undefined : window);
|
|
48
|
+
const doc = options.document ?? (typeof document === 'undefined' ? undefined : document);
|
|
49
|
+
if (win && doc) {
|
|
50
|
+
const onVisibility = () => transition(doc.hidden ? 'background' : 'active');
|
|
51
|
+
const onHide = () => transition('background');
|
|
52
|
+
const onShow = () => transition('active');
|
|
53
|
+
doc.addEventListener('visibilitychange', onVisibility);
|
|
54
|
+
win.addEventListener('pagehide', onHide);
|
|
55
|
+
win.addEventListener('pageshow', onShow);
|
|
56
|
+
removers.push(() => {
|
|
57
|
+
doc.removeEventListener('visibilitychange', onVisibility);
|
|
58
|
+
win.removeEventListener('pagehide', onHide);
|
|
59
|
+
win.removeEventListener('pageshow', onShow);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
get state() {
|
|
65
|
+
return state;
|
|
66
|
+
},
|
|
67
|
+
pushBackHandler(handler) {
|
|
68
|
+
handlers.push(handler);
|
|
69
|
+
return () => {
|
|
70
|
+
const index = handlers.lastIndexOf(handler);
|
|
71
|
+
if (index >= 0)
|
|
72
|
+
handlers.splice(index, 1);
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
handleBack,
|
|
76
|
+
async dispose() {
|
|
77
|
+
disposed = true;
|
|
78
|
+
handlers.length = 0;
|
|
79
|
+
for (const remove of removers.splice(0))
|
|
80
|
+
remove();
|
|
81
|
+
const settled = await Promise.allSettled(handles.splice(0));
|
|
82
|
+
await Promise.allSettled(settled.flatMap((result) => (result.status === 'fulfilled' ? [result.value.remove()] : [])));
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App lifecycle: pause/resume and the Android back button, on native shells and in the browser.
|
|
3
|
+
*
|
|
4
|
+
* The Capacitor `App` plugin is passed in rather than imported, so this package carries no runtime
|
|
5
|
+
* dependency on Capacitor and the logic unit-tests with a fake. On the web, pause/resume comes from
|
|
6
|
+
* `visibilitychange`, `pagehide` and `pageshow`.
|
|
7
|
+
*
|
|
8
|
+
* Back handling is a stack: the most recently pushed handler (an open modal, then the pause menu)
|
|
9
|
+
* runs first, and returning `true` consumes the press. An unconsumed press minimises the app instead
|
|
10
|
+
* of exiting it, so a stray back never discards unsaved progress.
|
|
11
|
+
*/
|
|
12
|
+
export type LifecycleState = 'active' | 'background';
|
|
13
|
+
export interface PluginListenerHandleLike {
|
|
14
|
+
remove(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** The subset of Capacitor's `App` plugin this module uses. */
|
|
17
|
+
export interface AppPluginLike {
|
|
18
|
+
addListener(event: 'appStateChange', listener: (state: {
|
|
19
|
+
isActive: boolean;
|
|
20
|
+
}) => void): Promise<PluginListenerHandleLike>;
|
|
21
|
+
addListener(event: 'backButton', listener: (event: {
|
|
22
|
+
canGoBack: boolean;
|
|
23
|
+
}) => void): Promise<PluginListenerHandleLike>;
|
|
24
|
+
minimizeApp(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** Returns true when it handled the press. */
|
|
27
|
+
export type BackHandler = () => boolean;
|
|
28
|
+
export interface AppLifecycleOptions {
|
|
29
|
+
/** Capacitor's `App` plugin; required for native back-button and state events. */
|
|
30
|
+
app?: AppPluginLike;
|
|
31
|
+
/** True inside a native shell (`Capacitor.isNativePlatform()`). */
|
|
32
|
+
native: boolean;
|
|
33
|
+
onPause?: () => void;
|
|
34
|
+
onResume?: () => void;
|
|
35
|
+
/** Window and document for the web path; default to the globals. */
|
|
36
|
+
window?: Window;
|
|
37
|
+
document?: Document;
|
|
38
|
+
}
|
|
39
|
+
export interface AppLifecycle {
|
|
40
|
+
readonly state: LifecycleState;
|
|
41
|
+
/** Pushes a back handler; the returned function removes it. */
|
|
42
|
+
pushBackHandler(handler: BackHandler): () => void;
|
|
43
|
+
/** Runs the back stack as a hardware back press would. Returns true when a handler consumed it. */
|
|
44
|
+
handleBack(): boolean;
|
|
45
|
+
dispose(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createAppLifecycle(options: AppLifecycleOptions): AppLifecycle;
|
|
48
|
+
//# sourceMappingURL=lifecycle.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,CAAA;AAEpD,MAAM,WAAW,wBAAwB;IACvC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACxB;AAED,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,WAAW,CACT,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAC/C,OAAO,CAAC,wBAAwB,CAAC,CAAA;IACpC,WAAW,CACT,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAChD,OAAO,CAAC,wBAAwB,CAAC,CAAA;IACpC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAA;AAEvC,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,GAAG,CAAC,EAAE,aAAa,CAAA;IACnB,mEAAmE;IACnE,MAAM,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;IAC9B,+DAA+D;IAC/D,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,IAAI,CAAA;IACjD,mGAAmG;IACnG,UAAU,IAAI,OAAO,CAAA;IACrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CA0E7E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decideOrientation = decideOrientation;
|
|
4
|
+
const BOTH = ['portrait', 'landscape'];
|
|
5
|
+
function decideOrientation(profile, preferred) {
|
|
6
|
+
const flexible = preferred === 'any' ||
|
|
7
|
+
!profile.touch ||
|
|
8
|
+
profile.formFactor === 'desktop' ||
|
|
9
|
+
profile.formFactor === 'tablet' ||
|
|
10
|
+
profile.formFactor === 'foldable-open';
|
|
11
|
+
if (flexible)
|
|
12
|
+
return { allowed: BOTH, promptRotate: false, target: null };
|
|
13
|
+
const allowed = [preferred];
|
|
14
|
+
const promptRotate = profile.orientation !== preferred;
|
|
15
|
+
return { allowed, promptRotate, target: promptRotate ? preferred : null };
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orientation policy. A game declares the orientation it is designed around; the policy decides, per
|
|
3
|
+
* device, which orientations are acceptable and whether to ask a phone player to rotate. Tablets and
|
|
4
|
+
* unfolded foldables are usable either way, so they are never nagged.
|
|
5
|
+
*
|
|
6
|
+
* Never force-rotate. The decision drives a per-screen "turn the device" hint only; the
|
|
7
|
+
* native shell leaves the screen orientation unlocked.
|
|
8
|
+
*/
|
|
9
|
+
import type { DeviceProfile, ViewOrientation } from './profile.cjs';
|
|
10
|
+
/** `any` means the game lays out in both orientations on every device. */
|
|
11
|
+
export type PreferredOrientation = ViewOrientation | 'any';
|
|
12
|
+
export interface OrientationDecision {
|
|
13
|
+
/** Orientations the game should accept on this device. */
|
|
14
|
+
allowed: readonly ViewOrientation[];
|
|
15
|
+
/** True when the player should be asked to rotate the device. */
|
|
16
|
+
promptRotate: boolean;
|
|
17
|
+
/** The orientation to ask for when `promptRotate` is true. */
|
|
18
|
+
target: ViewOrientation | null;
|
|
19
|
+
}
|
|
20
|
+
export declare function decideOrientation(profile: Pick<DeviceProfile, 'formFactor' | 'orientation' | 'touch'>, preferred: PreferredOrientation): OrientationDecision;
|
|
21
|
+
//# sourceMappingURL=orientation.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orientation.d.ts","sourceRoot":"","sources":["../../src/orientation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAElE,0EAA0E;AAC1E,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,KAAK,CAAA;AAE1D,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,OAAO,EAAE,SAAS,eAAe,EAAE,CAAA;IACnC,iEAAiE;IACjE,YAAY,EAAE,OAAO,CAAA;IACrB,8DAA8D;IAC9D,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;CAC/B;AAID,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,aAAa,GAAG,OAAO,CAAC,EACpE,SAAS,EAAE,oBAAoB,GAC9B,mBAAmB,CAWrB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Device profile: a pure classification of the current viewport into the categories a game's layout
|
|
4
|
+
* actually branches on. Every input is injectable so the classification unit-tests without a browser
|
|
5
|
+
* and so a native shell can feed it platform facts (Capacitor `Device.getInfo()`).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.NEAR_SQUARE_MAX_ASPECT = exports.TABLET_MIN_SHORT_EDGE = exports.EXPANDED_MIN_SHORT_EDGE = void 0;
|
|
9
|
+
exports.classifyOrientation = classifyOrientation;
|
|
10
|
+
exports.isFoldableOpen = isFoldableOpen;
|
|
11
|
+
exports.classifyFormFactor = classifyFormFactor;
|
|
12
|
+
exports.classifyFrame = classifyFrame;
|
|
13
|
+
exports.classifyDevice = classifyDevice;
|
|
14
|
+
exports.readViewportFacts = readViewportFacts;
|
|
15
|
+
/** Short edge (CSS px) at which a frame counts as expanded. Phones stay below ~480. */
|
|
16
|
+
exports.EXPANDED_MIN_SHORT_EDGE = 700;
|
|
17
|
+
/** Short edge (CSS px) from which a touch screen is tablet-sized rather than a phone. */
|
|
18
|
+
exports.TABLET_MIN_SHORT_EDGE = 600;
|
|
19
|
+
/**
|
|
20
|
+
* Long/short aspect at or below which a screen is near-square. A phone in portrait is ~2.1, a 4:3
|
|
21
|
+
* tablet 1.33, an unfolded OnePlus Open ~1.08.
|
|
22
|
+
*/
|
|
23
|
+
exports.NEAR_SQUARE_MAX_ASPECT = 1.3;
|
|
24
|
+
function classifyOrientation(width, height) {
|
|
25
|
+
return height > width ? 'portrait' : 'landscape';
|
|
26
|
+
}
|
|
27
|
+
/** True for an unfolded book-style foldable: near-square and tablet-sized, on a touch screen. */
|
|
28
|
+
function isFoldableOpen(facts) {
|
|
29
|
+
if (!facts.touch)
|
|
30
|
+
return false;
|
|
31
|
+
const shortEdge = Math.min(facts.width, facts.height);
|
|
32
|
+
const longEdge = Math.max(facts.width, facts.height);
|
|
33
|
+
if (shortEdge <= 0)
|
|
34
|
+
return false;
|
|
35
|
+
return longEdge / shortEdge <= exports.NEAR_SQUARE_MAX_ASPECT && shortEdge >= exports.TABLET_MIN_SHORT_EDGE;
|
|
36
|
+
}
|
|
37
|
+
function classifyFormFactor(facts) {
|
|
38
|
+
const shortEdge = Math.min(facts.width, facts.height);
|
|
39
|
+
if (facts.platform === 'ios' && /ipad/i.test(facts.model))
|
|
40
|
+
return 'tablet';
|
|
41
|
+
if (isFoldableOpen(facts))
|
|
42
|
+
return 'foldable-open';
|
|
43
|
+
if (!facts.touch && facts.platform === 'web')
|
|
44
|
+
return 'desktop';
|
|
45
|
+
if (facts.platform === 'electron')
|
|
46
|
+
return 'desktop';
|
|
47
|
+
return shortEdge >= exports.TABLET_MIN_SHORT_EDGE ? 'tablet' : 'phone';
|
|
48
|
+
}
|
|
49
|
+
function classifyFrame(facts) {
|
|
50
|
+
if (facts.platform === 'ios')
|
|
51
|
+
return /ipad/i.test(facts.model) ? 'expanded' : 'compact';
|
|
52
|
+
return Math.min(facts.width, facts.height) >= exports.EXPANDED_MIN_SHORT_EDGE ? 'expanded' : 'compact';
|
|
53
|
+
}
|
|
54
|
+
function classifyDevice(facts) {
|
|
55
|
+
const shortEdge = Math.min(facts.width, facts.height);
|
|
56
|
+
const longEdge = Math.max(facts.width, facts.height);
|
|
57
|
+
const native = facts.platform === 'android' || facts.platform === 'ios';
|
|
58
|
+
return {
|
|
59
|
+
frame: classifyFrame(facts),
|
|
60
|
+
formFactor: classifyFormFactor(facts),
|
|
61
|
+
orientation: classifyOrientation(facts.width, facts.height),
|
|
62
|
+
platform: facts.platform,
|
|
63
|
+
native,
|
|
64
|
+
touch: facts.touch || native,
|
|
65
|
+
shortEdge,
|
|
66
|
+
longEdge,
|
|
67
|
+
aspect: shortEdge > 0 ? longEdge / shortEdge : 1,
|
|
68
|
+
devicePixelRatio: facts.devicePixelRatio,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads viewport facts from a window (`null` outside a browser gives a 1280x720 desktop default).
|
|
73
|
+
* Platform facts default to `web` until a native shell says otherwise.
|
|
74
|
+
*/
|
|
75
|
+
function readViewportFacts(win = typeof window === 'undefined' ? null : window, platform = { platform: 'web', model: '' }) {
|
|
76
|
+
if (!win) {
|
|
77
|
+
return { width: 1280, height: 720, devicePixelRatio: 1, touch: false, ...platform };
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
width: win.innerWidth,
|
|
81
|
+
height: win.innerHeight,
|
|
82
|
+
devicePixelRatio: win.devicePixelRatio ?? 1,
|
|
83
|
+
touch: (win.navigator?.maxTouchPoints ?? 0) > 0 || 'ontouchstart' in win,
|
|
84
|
+
...platform,
|
|
85
|
+
};
|
|
86
|
+
}
|