@capawesome/capacitor-accessibility-preferences 0.0.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/CapawesomeCapacitorAccessibilityPreferences.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +159 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/accessibilitypreferences/AccessibilityPreferences.java +70 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/accessibilitypreferences/AccessibilityPreferencesPlugin.java +64 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/accessibilitypreferences/classes/results/GetPreferencesResult.java +55 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/accessibilitypreferences/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/accessibilitypreferences/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/accessibilitypreferences/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +143 -0
- package/dist/esm/definitions.d.ts +78 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +6 -0
- package/dist/esm/web.js +17 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +31 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +34 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/AccessibilityPreferences.swift +44 -0
- package/ios/Plugin/AccessibilityPreferencesPlugin.swift +42 -0
- package/ios/Plugin/Classes/Results/GetPreferencesResult.swift +38 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorAccessibilityPreferences'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
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/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorAccessibilityPreferences",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorAccessibilityPreferences",
|
|
10
|
+
targets: ["AccessibilityPreferencesPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "AccessibilityPreferencesPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "AccessibilityPreferencesPluginTests",
|
|
25
|
+
dependencies: ["AccessibilityPreferencesPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# @capawesome/capacitor-accessibility-preferences
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for reading the user's system accessibility preferences.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- ♿ **Accessibility preferences**: Read the user's system accessibility preferences.
|
|
14
|
+
- 🔤 **Font scale**: Adapt your typography to the user's preferred text size.
|
|
15
|
+
- 🎞️ **Reduce motion**: Disable animations when the user prefers reduced motion.
|
|
16
|
+
- 🎨 **Contrast & colors**: React to increased contrast and inverted colors.
|
|
17
|
+
- 🌐 **Cross-platform**: Works on Android, iOS, and the Web.
|
|
18
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
19
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
20
|
+
|
|
21
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
22
|
+
|
|
23
|
+
## Newsletter
|
|
24
|
+
|
|
25
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
26
|
+
|
|
27
|
+
## Compatibility
|
|
28
|
+
|
|
29
|
+
| Plugin Version | Capacitor Version | Status |
|
|
30
|
+
| -------------- | ----------------- | -------------- |
|
|
31
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
36
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then use the following prompt:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-accessibility-preferences` plugin in my project.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you prefer **Manual Setup**, install the plugin by running the following command:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @capawesome/capacitor-accessibility-preferences
|
|
52
|
+
npx cap sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This plugin does not require any additional permissions or configuration.
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
No configuration required for this plugin.
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { AccessibilityPreferences } from '@capawesome/capacitor-accessibility-preferences';
|
|
65
|
+
|
|
66
|
+
const getPreferences = async () => {
|
|
67
|
+
const preferences = await AccessibilityPreferences.getPreferences();
|
|
68
|
+
return preferences;
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
<docgen-index>
|
|
75
|
+
|
|
76
|
+
* [`getPreferences()`](#getpreferences)
|
|
77
|
+
* [Interfaces](#interfaces)
|
|
78
|
+
|
|
79
|
+
</docgen-index>
|
|
80
|
+
|
|
81
|
+
<docgen-api>
|
|
82
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
83
|
+
|
|
84
|
+
### getPreferences()
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
getPreferences() => Promise<GetPreferencesResult>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Get the user's current system accessibility preferences.
|
|
91
|
+
|
|
92
|
+
Fields that the current platform cannot provide are set to `null`.
|
|
93
|
+
|
|
94
|
+
**Returns:** <code>Promise<<a href="#getpreferencesresult">GetPreferencesResult</a>></code>
|
|
95
|
+
|
|
96
|
+
**Since:** 0.1.0
|
|
97
|
+
|
|
98
|
+
--------------------
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Interfaces
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
#### GetPreferencesResult
|
|
105
|
+
|
|
106
|
+
| Prop | Type | Description | Since |
|
|
107
|
+
| --------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
108
|
+
| **`fontScale`** | <code>number</code> | The system font scale factor. A value of `1.0` represents the default font size. Values greater than `1.0` indicate that the user prefers larger text, values less than `1.0` smaller text. On iOS, the value is derived from the preferred content size category. On Web, this is always `1.0` because the font scale is not exposed to web content. | 0.1.0 |
|
|
109
|
+
| **`isBoldTextEnabled`** | <code>boolean \| null</code> | Whether the user prefers bold text. Returns `null` on platforms where the value cannot be read (Web and Android versions below 12). | 0.1.0 |
|
|
110
|
+
| **`isHighContrastEnabled`** | <code>boolean \| null</code> | Whether the user prefers increased contrast. On iOS, this reflects the "Increase Contrast" setting (darker system colors). On Android, this reflects the high text contrast setting. Returns `null` on platforms where the value cannot be read. | 0.1.0 |
|
|
111
|
+
| **`isInvertColorsEnabled`** | <code>boolean \| null</code> | Whether the user has enabled inverted colors. Returns `null` on Web. | 0.1.0 |
|
|
112
|
+
| **`isReduceMotionEnabled`** | <code>boolean</code> | Whether the user prefers reduced motion (fewer animations). | 0.1.0 |
|
|
113
|
+
| **`isReduceTransparencyEnabled`** | <code>boolean \| null</code> | Whether the user prefers reduced transparency. Only available on iOS. Returns `null` on Android and Web. | 0.1.0 |
|
|
114
|
+
|
|
115
|
+
</docgen-api>
|
|
116
|
+
|
|
117
|
+
## Platform Availability
|
|
118
|
+
|
|
119
|
+
Not every preference can be read on every platform. Fields that the current platform cannot provide are set to `null`.
|
|
120
|
+
|
|
121
|
+
| Field | Android | iOS | Web |
|
|
122
|
+
| ----------------------------- | ------------ | --- | ---- |
|
|
123
|
+
| `fontScale` | ✅ | ✅ | ⚠️\* |
|
|
124
|
+
| `isReduceMotionEnabled` | ✅ | ✅ | ✅ |
|
|
125
|
+
| `isBoldTextEnabled` | ✅ (API 31+) | ✅ | ❌ |
|
|
126
|
+
| `isInvertColorsEnabled` | ✅ | ✅ | ❌ |
|
|
127
|
+
| `isReduceTransparencyEnabled` | ❌ | ✅ | ❌ |
|
|
128
|
+
| `isHighContrastEnabled` | ✅ | ✅ | ✅ |
|
|
129
|
+
|
|
130
|
+
✅ = available · ❌ = always `null` · ⚠️\* = `fontScale` is always `1.0` on Web because it is not exposed to web content.
|
|
131
|
+
|
|
132
|
+
On iOS, `fontScale` is derived from the preferred content size category using the following mapping (relative to the default body text size of 17 pt):
|
|
133
|
+
|
|
134
|
+
| Content size category | `fontScale` |
|
|
135
|
+
| ------------------------------- | ----------- |
|
|
136
|
+
| Extra Small | 0.82 |
|
|
137
|
+
| Small | 0.88 |
|
|
138
|
+
| Medium | 0.94 |
|
|
139
|
+
| Large (default) | 1.0 |
|
|
140
|
+
| Extra Large | 1.12 |
|
|
141
|
+
| Extra Extra Large | 1.24 |
|
|
142
|
+
| Extra Extra Extra Large | 1.35 |
|
|
143
|
+
| Accessibility Medium | 1.65 |
|
|
144
|
+
| Accessibility Large | 1.94 |
|
|
145
|
+
| Accessibility Extra Large | 2.35 |
|
|
146
|
+
| Accessibility Extra Extra Large | 2.76 |
|
|
147
|
+
| Accessibility 3X Large | 3.12 |
|
|
148
|
+
|
|
149
|
+
CSS media queries such as `prefers-reduced-motion` and `prefers-contrast` already cover reduce-motion and contrast inside the WebView. The value of this plugin is the fields CSS cannot see (`fontScale`, bold text, inverted colors) and having a single API for your app logic on all platforms.
|
|
150
|
+
|
|
151
|
+
The screen reader _state_ (VoiceOver/TalkBack) is intentionally out of scope. Use the official [`@capacitor/screen-reader`](https://capacitorjs.com/docs/apis/screen-reader) plugin for that.
|
|
152
|
+
|
|
153
|
+
## Changelog
|
|
154
|
+
|
|
155
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/accessibility-preferences/CHANGELOG.md).
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/accessibility-preferences/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.accessibilitypreferences"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.accessibilitypreferences;
|
|
2
|
+
|
|
3
|
+
import android.content.ContentResolver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.res.Configuration;
|
|
6
|
+
import android.os.Build;
|
|
7
|
+
import android.provider.Settings;
|
|
8
|
+
import androidx.annotation.NonNull;
|
|
9
|
+
import androidx.annotation.Nullable;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.accessibilitypreferences.classes.results.GetPreferencesResult;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.accessibilitypreferences.interfaces.NonEmptyResultCallback;
|
|
12
|
+
|
|
13
|
+
public class AccessibilityPreferences {
|
|
14
|
+
|
|
15
|
+
private static final String SETTING_HIGH_TEXT_CONTRAST_ENABLED = "high_text_contrast_enabled";
|
|
16
|
+
private static final String SETTING_INVERSION_ENABLED = "accessibility_display_inversion_enabled";
|
|
17
|
+
|
|
18
|
+
@NonNull
|
|
19
|
+
private final Context context;
|
|
20
|
+
|
|
21
|
+
public AccessibilityPreferences(@NonNull Context context) {
|
|
22
|
+
this.context = context;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public void getPreferences(@NonNull NonEmptyResultCallback<GetPreferencesResult> callback) {
|
|
26
|
+
GetPreferencesResult result = new GetPreferencesResult(
|
|
27
|
+
getFontScale(),
|
|
28
|
+
isReduceMotionEnabled(),
|
|
29
|
+
isBoldTextEnabled(),
|
|
30
|
+
isInvertColorsEnabled(),
|
|
31
|
+
null,
|
|
32
|
+
isHighContrastEnabled()
|
|
33
|
+
);
|
|
34
|
+
callback.success(result);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private float getFontScale() {
|
|
38
|
+
return context.getResources().getConfiguration().fontScale;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Nullable
|
|
42
|
+
private Boolean isBoldTextEnabled() {
|
|
43
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
int fontWeightAdjustment = context.getResources().getConfiguration().fontWeightAdjustment;
|
|
47
|
+
if (fontWeightAdjustment == Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return fontWeightAdjustment > 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Nullable
|
|
54
|
+
private Boolean isHighContrastEnabled() {
|
|
55
|
+
try {
|
|
56
|
+
return Settings.Secure.getInt(context.getContentResolver(), SETTING_HIGH_TEXT_CONTRAST_ENABLED, 0) == 1;
|
|
57
|
+
} catch (Exception exception) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private boolean isInvertColorsEnabled() {
|
|
63
|
+
return Settings.Secure.getInt(context.getContentResolver(), SETTING_INVERSION_ENABLED, 0) == 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private boolean isReduceMotionEnabled() {
|
|
67
|
+
ContentResolver resolver = context.getContentResolver();
|
|
68
|
+
return Settings.Global.getFloat(resolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) == 0f;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.accessibilitypreferences;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.Logger;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.PluginCall;
|
|
8
|
+
import com.getcapacitor.PluginMethod;
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.accessibilitypreferences.classes.results.GetPreferencesResult;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.accessibilitypreferences.interfaces.NonEmptyResultCallback;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.accessibilitypreferences.interfaces.Result;
|
|
13
|
+
|
|
14
|
+
@CapacitorPlugin(name = "AccessibilityPreferences")
|
|
15
|
+
public class AccessibilityPreferencesPlugin extends Plugin {
|
|
16
|
+
|
|
17
|
+
public static final String TAG = "AccessibilityPreferences";
|
|
18
|
+
|
|
19
|
+
private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
|
|
20
|
+
|
|
21
|
+
private AccessibilityPreferences implementation;
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
public void load() {
|
|
25
|
+
implementation = new AccessibilityPreferences(getContext());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@PluginMethod
|
|
29
|
+
public void getPreferences(PluginCall call) {
|
|
30
|
+
try {
|
|
31
|
+
NonEmptyResultCallback<GetPreferencesResult> callback = new NonEmptyResultCallback<>() {
|
|
32
|
+
@Override
|
|
33
|
+
public void success(@NonNull GetPreferencesResult result) {
|
|
34
|
+
resolveCall(call, result);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public void error(@NonNull Exception exception) {
|
|
39
|
+
rejectCall(call, exception);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
implementation.getPreferences(callback);
|
|
43
|
+
} catch (Exception exception) {
|
|
44
|
+
rejectCall(call, exception);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
49
|
+
String message = exception.getMessage();
|
|
50
|
+
if (message == null) {
|
|
51
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
52
|
+
}
|
|
53
|
+
Logger.error(TAG, message, exception);
|
|
54
|
+
call.reject(message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
58
|
+
if (result == null) {
|
|
59
|
+
call.resolve();
|
|
60
|
+
} else {
|
|
61
|
+
call.resolve(result.toJSObject());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.accessibilitypreferences.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.accessibilitypreferences.interfaces.Result;
|
|
7
|
+
import org.json.JSONObject;
|
|
8
|
+
|
|
9
|
+
public class GetPreferencesResult implements Result {
|
|
10
|
+
|
|
11
|
+
private final float fontScale;
|
|
12
|
+
|
|
13
|
+
@Nullable
|
|
14
|
+
private final Boolean isBoldTextEnabled;
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
private final Boolean isHighContrastEnabled;
|
|
18
|
+
|
|
19
|
+
@Nullable
|
|
20
|
+
private final Boolean isInvertColorsEnabled;
|
|
21
|
+
|
|
22
|
+
private final boolean isReduceMotionEnabled;
|
|
23
|
+
|
|
24
|
+
@Nullable
|
|
25
|
+
private final Boolean isReduceTransparencyEnabled;
|
|
26
|
+
|
|
27
|
+
public GetPreferencesResult(
|
|
28
|
+
float fontScale,
|
|
29
|
+
boolean isReduceMotionEnabled,
|
|
30
|
+
@Nullable Boolean isBoldTextEnabled,
|
|
31
|
+
@Nullable Boolean isInvertColorsEnabled,
|
|
32
|
+
@Nullable Boolean isReduceTransparencyEnabled,
|
|
33
|
+
@Nullable Boolean isHighContrastEnabled
|
|
34
|
+
) {
|
|
35
|
+
this.fontScale = fontScale;
|
|
36
|
+
this.isReduceMotionEnabled = isReduceMotionEnabled;
|
|
37
|
+
this.isBoldTextEnabled = isBoldTextEnabled;
|
|
38
|
+
this.isInvertColorsEnabled = isInvertColorsEnabled;
|
|
39
|
+
this.isReduceTransparencyEnabled = isReduceTransparencyEnabled;
|
|
40
|
+
this.isHighContrastEnabled = isHighContrastEnabled;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Override
|
|
44
|
+
@NonNull
|
|
45
|
+
public JSObject toJSObject() {
|
|
46
|
+
JSObject result = new JSObject();
|
|
47
|
+
result.put("fontScale", fontScale);
|
|
48
|
+
result.put("isReduceMotionEnabled", isReduceMotionEnabled);
|
|
49
|
+
result.put("isBoldTextEnabled", isBoldTextEnabled == null ? JSONObject.NULL : isBoldTextEnabled);
|
|
50
|
+
result.put("isInvertColorsEnabled", isInvertColorsEnabled == null ? JSONObject.NULL : isInvertColorsEnabled);
|
|
51
|
+
result.put("isReduceTransparencyEnabled", isReduceTransparencyEnabled == null ? JSONObject.NULL : isReduceTransparencyEnabled);
|
|
52
|
+
result.put("isHighContrastEnabled", isHighContrastEnabled == null ? JSONObject.NULL : isHighContrastEnabled);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "AccessibilityPreferencesPlugin",
|
|
4
|
+
"slug": "accessibilitypreferencesplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "getPreferences",
|
|
10
|
+
"signature": "() => Promise<GetPreferencesResult>",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "Promise<GetPreferencesResult>",
|
|
13
|
+
"tags": [
|
|
14
|
+
{
|
|
15
|
+
"name": "since",
|
|
16
|
+
"text": "0.1.0"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"docs": "Get the user's current system accessibility preferences.\n\nFields that the current platform cannot provide are set to `null`.",
|
|
20
|
+
"complexTypes": [
|
|
21
|
+
"GetPreferencesResult"
|
|
22
|
+
],
|
|
23
|
+
"slug": "getpreferences"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"properties": []
|
|
27
|
+
},
|
|
28
|
+
"interfaces": [
|
|
29
|
+
{
|
|
30
|
+
"name": "GetPreferencesResult",
|
|
31
|
+
"slug": "getpreferencesresult",
|
|
32
|
+
"docs": "",
|
|
33
|
+
"tags": [
|
|
34
|
+
{
|
|
35
|
+
"text": "0.1.0",
|
|
36
|
+
"name": "since"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"methods": [],
|
|
40
|
+
"properties": [
|
|
41
|
+
{
|
|
42
|
+
"name": "fontScale",
|
|
43
|
+
"tags": [
|
|
44
|
+
{
|
|
45
|
+
"text": "1.0",
|
|
46
|
+
"name": "example"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"text": "0.1.0",
|
|
50
|
+
"name": "since"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"docs": "The system font scale factor.\n\nA value of `1.0` represents the default font size. Values greater than\n`1.0` indicate that the user prefers larger text, values less than `1.0`\nsmaller text.\n\nOn iOS, the value is derived from the preferred content size category.\n\nOn Web, this is always `1.0` because the font scale is not exposed to web\ncontent.",
|
|
54
|
+
"complexTypes": [],
|
|
55
|
+
"type": "number"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "isBoldTextEnabled",
|
|
59
|
+
"tags": [
|
|
60
|
+
{
|
|
61
|
+
"text": "false",
|
|
62
|
+
"name": "example"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"text": "0.1.0",
|
|
66
|
+
"name": "since"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"docs": "Whether the user prefers bold text.\n\nReturns `null` on platforms where the value cannot be read (Web and\nAndroid versions below 12).",
|
|
70
|
+
"complexTypes": [],
|
|
71
|
+
"type": "boolean | null"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "isHighContrastEnabled",
|
|
75
|
+
"tags": [
|
|
76
|
+
{
|
|
77
|
+
"text": "false",
|
|
78
|
+
"name": "example"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"text": "0.1.0",
|
|
82
|
+
"name": "since"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"docs": "Whether the user prefers increased contrast.\n\nOn iOS, this reflects the \"Increase Contrast\" setting (darker system\ncolors). On Android, this reflects the high text contrast setting.\n\nReturns `null` on platforms where the value cannot be read.",
|
|
86
|
+
"complexTypes": [],
|
|
87
|
+
"type": "boolean | null"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name": "isInvertColorsEnabled",
|
|
91
|
+
"tags": [
|
|
92
|
+
{
|
|
93
|
+
"text": "false",
|
|
94
|
+
"name": "example"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"text": "0.1.0",
|
|
98
|
+
"name": "since"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"docs": "Whether the user has enabled inverted colors.\n\nReturns `null` on Web.",
|
|
102
|
+
"complexTypes": [],
|
|
103
|
+
"type": "boolean | null"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"name": "isReduceMotionEnabled",
|
|
107
|
+
"tags": [
|
|
108
|
+
{
|
|
109
|
+
"text": "false",
|
|
110
|
+
"name": "example"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"text": "0.1.0",
|
|
114
|
+
"name": "since"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"docs": "Whether the user prefers reduced motion (fewer animations).",
|
|
118
|
+
"complexTypes": [],
|
|
119
|
+
"type": "boolean"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "isReduceTransparencyEnabled",
|
|
123
|
+
"tags": [
|
|
124
|
+
{
|
|
125
|
+
"text": "false",
|
|
126
|
+
"name": "example"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"text": "0.1.0",
|
|
130
|
+
"name": "since"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"docs": "Whether the user prefers reduced transparency.\n\nOnly available on iOS. Returns `null` on Android and Web.",
|
|
134
|
+
"complexTypes": [],
|
|
135
|
+
"type": "boolean | null"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"enums": [],
|
|
141
|
+
"typeAliases": [],
|
|
142
|
+
"pluginConfigs": []
|
|
143
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export interface AccessibilityPreferencesPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Get the user's current system accessibility preferences.
|
|
4
|
+
*
|
|
5
|
+
* Fields that the current platform cannot provide are set to `null`.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
*/
|
|
9
|
+
getPreferences(): Promise<GetPreferencesResult>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
*/
|
|
14
|
+
export interface GetPreferencesResult {
|
|
15
|
+
/**
|
|
16
|
+
* The system font scale factor.
|
|
17
|
+
*
|
|
18
|
+
* A value of `1.0` represents the default font size. Values greater than
|
|
19
|
+
* `1.0` indicate that the user prefers larger text, values less than `1.0`
|
|
20
|
+
* smaller text.
|
|
21
|
+
*
|
|
22
|
+
* On iOS, the value is derived from the preferred content size category.
|
|
23
|
+
*
|
|
24
|
+
* On Web, this is always `1.0` because the font scale is not exposed to web
|
|
25
|
+
* content.
|
|
26
|
+
*
|
|
27
|
+
* @example 1.0
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
fontScale: number;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the user prefers bold text.
|
|
33
|
+
*
|
|
34
|
+
* Returns `null` on platforms where the value cannot be read (Web and
|
|
35
|
+
* Android versions below 12).
|
|
36
|
+
*
|
|
37
|
+
* @example false
|
|
38
|
+
* @since 0.1.0
|
|
39
|
+
*/
|
|
40
|
+
isBoldTextEnabled: boolean | null;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the user prefers increased contrast.
|
|
43
|
+
*
|
|
44
|
+
* On iOS, this reflects the "Increase Contrast" setting (darker system
|
|
45
|
+
* colors). On Android, this reflects the high text contrast setting.
|
|
46
|
+
*
|
|
47
|
+
* Returns `null` on platforms where the value cannot be read.
|
|
48
|
+
*
|
|
49
|
+
* @example false
|
|
50
|
+
* @since 0.1.0
|
|
51
|
+
*/
|
|
52
|
+
isHighContrastEnabled: boolean | null;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the user has enabled inverted colors.
|
|
55
|
+
*
|
|
56
|
+
* Returns `null` on Web.
|
|
57
|
+
*
|
|
58
|
+
* @example false
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
isInvertColorsEnabled: boolean | null;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the user prefers reduced motion (fewer animations).
|
|
64
|
+
*
|
|
65
|
+
* @example false
|
|
66
|
+
* @since 0.1.0
|
|
67
|
+
*/
|
|
68
|
+
isReduceMotionEnabled: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether the user prefers reduced transparency.
|
|
71
|
+
*
|
|
72
|
+
* Only available on iOS. Returns `null` on Android and Web.
|
|
73
|
+
*
|
|
74
|
+
* @example false
|
|
75
|
+
* @since 0.1.0
|
|
76
|
+
*/
|
|
77
|
+
isReduceTransparencyEnabled: boolean | null;
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AccessibilityPreferencesPlugin {\n /**\n * Get the user's current system accessibility preferences.\n *\n * Fields that the current platform cannot provide are set to `null`.\n *\n * @since 0.1.0\n */\n getPreferences(): Promise<GetPreferencesResult>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetPreferencesResult {\n /**\n * The system font scale factor.\n *\n * A value of `1.0` represents the default font size. Values greater than\n * `1.0` indicate that the user prefers larger text, values less than `1.0`\n * smaller text.\n *\n * On iOS, the value is derived from the preferred content size category.\n *\n * On Web, this is always `1.0` because the font scale is not exposed to web\n * content.\n *\n * @example 1.0\n * @since 0.1.0\n */\n fontScale: number;\n /**\n * Whether the user prefers bold text.\n *\n * Returns `null` on platforms where the value cannot be read (Web and\n * Android versions below 12).\n *\n * @example false\n * @since 0.1.0\n */\n isBoldTextEnabled: boolean | null;\n /**\n * Whether the user prefers increased contrast.\n *\n * On iOS, this reflects the \"Increase Contrast\" setting (darker system\n * colors). On Android, this reflects the high text contrast setting.\n *\n * Returns `null` on platforms where the value cannot be read.\n *\n * @example false\n * @since 0.1.0\n */\n isHighContrastEnabled: boolean | null;\n /**\n * Whether the user has enabled inverted colors.\n *\n * Returns `null` on Web.\n *\n * @example false\n * @since 0.1.0\n */\n isInvertColorsEnabled: boolean | null;\n /**\n * Whether the user prefers reduced motion (fewer animations).\n *\n * @example false\n * @since 0.1.0\n */\n isReduceMotionEnabled: boolean;\n /**\n * Whether the user prefers reduced transparency.\n *\n * Only available on iOS. Returns `null` on Android and Web.\n *\n * @example false\n * @since 0.1.0\n */\n isReduceTransparencyEnabled: boolean | null;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const AccessibilityPreferences = registerPlugin('AccessibilityPreferences', {
|
|
3
|
+
web: () => import('./web').then(m => new m.AccessibilityPreferencesWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { AccessibilityPreferences };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,wBAAwB,GAAG,cAAc,CAC7C,0BAA0B,EAC1B;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,2BAA2B,EAAE,CAAC;CAC1E,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { AccessibilityPreferencesPlugin } from './definitions';\n\nconst AccessibilityPreferences = registerPlugin<AccessibilityPreferencesPlugin>(\n 'AccessibilityPreferences',\n {\n web: () => import('./web').then(m => new m.AccessibilityPreferencesWeb()),\n },\n);\n\nexport * from './definitions';\nexport { AccessibilityPreferences };\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { AccessibilityPreferencesPlugin, GetPreferencesResult } from './definitions';
|
|
3
|
+
export declare class AccessibilityPreferencesWeb extends WebPlugin implements AccessibilityPreferencesPlugin {
|
|
4
|
+
getPreferences(): Promise<GetPreferencesResult>;
|
|
5
|
+
private matchesMediaQuery;
|
|
6
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class AccessibilityPreferencesWeb extends WebPlugin {
|
|
3
|
+
async getPreferences() {
|
|
4
|
+
return {
|
|
5
|
+
fontScale: 1.0,
|
|
6
|
+
isReduceMotionEnabled: this.matchesMediaQuery('(prefers-reduced-motion: reduce)'),
|
|
7
|
+
isBoldTextEnabled: null,
|
|
8
|
+
isInvertColorsEnabled: null,
|
|
9
|
+
isReduceTransparencyEnabled: null,
|
|
10
|
+
isHighContrastEnabled: this.matchesMediaQuery('(prefers-contrast: more)'),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
matchesMediaQuery(query) {
|
|
14
|
+
return window.matchMedia(query).matches;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,MAAM,OAAO,2BACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,cAAc;QAClB,OAAO;YACL,SAAS,EAAE,GAAG;YACd,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAC3C,kCAAkC,CACnC;YACD,iBAAiB,EAAE,IAAI;YACvB,qBAAqB,EAAE,IAAI;YAC3B,2BAA2B,EAAE,IAAI;YACjC,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAAC,0BAA0B,CAAC;SAC1E,CAAC;IACJ,CAAC;IAEO,iBAAiB,CAAC,KAAa;QACrC,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AccessibilityPreferencesPlugin,\n GetPreferencesResult,\n} from './definitions';\n\nexport class AccessibilityPreferencesWeb\n extends WebPlugin\n implements AccessibilityPreferencesPlugin\n{\n async getPreferences(): Promise<GetPreferencesResult> {\n return {\n fontScale: 1.0,\n isReduceMotionEnabled: this.matchesMediaQuery(\n '(prefers-reduced-motion: reduce)',\n ),\n isBoldTextEnabled: null,\n isInvertColorsEnabled: null,\n isReduceTransparencyEnabled: null,\n isHighContrastEnabled: this.matchesMediaQuery('(prefers-contrast: more)'),\n };\n }\n\n private matchesMediaQuery(query: string): boolean {\n return window.matchMedia(query).matches;\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const AccessibilityPreferences = core.registerPlugin('AccessibilityPreferences', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AccessibilityPreferencesWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class AccessibilityPreferencesWeb extends core.WebPlugin {
|
|
10
|
+
async getPreferences() {
|
|
11
|
+
return {
|
|
12
|
+
fontScale: 1.0,
|
|
13
|
+
isReduceMotionEnabled: this.matchesMediaQuery('(prefers-reduced-motion: reduce)'),
|
|
14
|
+
isBoldTextEnabled: null,
|
|
15
|
+
isInvertColorsEnabled: null,
|
|
16
|
+
isReduceTransparencyEnabled: null,
|
|
17
|
+
isHighContrastEnabled: this.matchesMediaQuery('(prefers-contrast: more)'),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
matchesMediaQuery(query) {
|
|
21
|
+
return window.matchMedia(query).matches;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
26
|
+
__proto__: null,
|
|
27
|
+
AccessibilityPreferencesWeb: AccessibilityPreferencesWeb
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
exports.AccessibilityPreferences = AccessibilityPreferences;
|
|
31
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AccessibilityPreferences = registerPlugin('AccessibilityPreferences', {\n web: () => import('./web').then(m => new m.AccessibilityPreferencesWeb()),\n});\nexport * from './definitions';\nexport { AccessibilityPreferences };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class AccessibilityPreferencesWeb extends WebPlugin {\n async getPreferences() {\n return {\n fontScale: 1.0,\n isReduceMotionEnabled: this.matchesMediaQuery('(prefers-reduced-motion: reduce)'),\n isBoldTextEnabled: null,\n isInvertColorsEnabled: null,\n isReduceTransparencyEnabled: null,\n isHighContrastEnabled: this.matchesMediaQuery('(prefers-contrast: more)'),\n };\n }\n matchesMediaQuery(query) {\n return window.matchMedia(query).matches;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,wBAAwB,GAAGA,mBAAc,CAAC,0BAA0B,EAAE;AAC5E,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,2BAA2B,EAAE,CAAC;AAC7E,CAAC;;ACFM,MAAM,2BAA2B,SAASC,cAAS,CAAC;AAC3D,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,GAAG;AAC1B,YAAY,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAAC,kCAAkC,CAAC;AAC7F,YAAY,iBAAiB,EAAE,IAAI;AACnC,YAAY,qBAAqB,EAAE,IAAI;AACvC,YAAY,2BAA2B,EAAE,IAAI;AAC7C,YAAY,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAAC,0BAA0B,CAAC;AACrF,SAAS;AACT,IAAI;AACJ,IAAI,iBAAiB,CAAC,KAAK,EAAE;AAC7B,QAAQ,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO;AAC/C,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var capacitorAccessibilityPreferences = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const AccessibilityPreferences = core.registerPlugin('AccessibilityPreferences', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AccessibilityPreferencesWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class AccessibilityPreferencesWeb extends core.WebPlugin {
|
|
9
|
+
async getPreferences() {
|
|
10
|
+
return {
|
|
11
|
+
fontScale: 1.0,
|
|
12
|
+
isReduceMotionEnabled: this.matchesMediaQuery('(prefers-reduced-motion: reduce)'),
|
|
13
|
+
isBoldTextEnabled: null,
|
|
14
|
+
isInvertColorsEnabled: null,
|
|
15
|
+
isReduceTransparencyEnabled: null,
|
|
16
|
+
isHighContrastEnabled: this.matchesMediaQuery('(prefers-contrast: more)'),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
matchesMediaQuery(query) {
|
|
20
|
+
return window.matchMedia(query).matches;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
25
|
+
__proto__: null,
|
|
26
|
+
AccessibilityPreferencesWeb: AccessibilityPreferencesWeb
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
exports.AccessibilityPreferences = AccessibilityPreferences;
|
|
30
|
+
|
|
31
|
+
return exports;
|
|
32
|
+
|
|
33
|
+
})({}, capacitorExports);
|
|
34
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AccessibilityPreferences = registerPlugin('AccessibilityPreferences', {\n web: () => import('./web').then(m => new m.AccessibilityPreferencesWeb()),\n});\nexport * from './definitions';\nexport { AccessibilityPreferences };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class AccessibilityPreferencesWeb extends WebPlugin {\n async getPreferences() {\n return {\n fontScale: 1.0,\n isReduceMotionEnabled: this.matchesMediaQuery('(prefers-reduced-motion: reduce)'),\n isBoldTextEnabled: null,\n isInvertColorsEnabled: null,\n isReduceTransparencyEnabled: null,\n isHighContrastEnabled: this.matchesMediaQuery('(prefers-contrast: more)'),\n };\n }\n matchesMediaQuery(query) {\n return window.matchMedia(query).matches;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,wBAAwB,GAAGA,mBAAc,CAAC,0BAA0B,EAAE;IAC5E,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,2BAA2B,EAAE,CAAC;IAC7E,CAAC;;ICFM,MAAM,2BAA2B,SAASC,cAAS,CAAC;IAC3D,IAAI,MAAM,cAAc,GAAG;IAC3B,QAAQ,OAAO;IACf,YAAY,SAAS,EAAE,GAAG;IAC1B,YAAY,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAAC,kCAAkC,CAAC;IAC7F,YAAY,iBAAiB,EAAE,IAAI;IACnC,YAAY,qBAAqB,EAAE,IAAI;IACvC,YAAY,2BAA2B,EAAE,IAAI;IAC7C,YAAY,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAAC,0BAA0B,CAAC;IACrF,SAAS;IACT,IAAI;IACJ,IAAI,iBAAiB,CAAC,KAAK,EAAE;IAC7B,QAAQ,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO;IAC/C,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc public class AccessibilityPreferences: NSObject {
|
|
5
|
+
let plugin: AccessibilityPreferencesPlugin
|
|
6
|
+
|
|
7
|
+
init(plugin: AccessibilityPreferencesPlugin) {
|
|
8
|
+
self.plugin = plugin
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func getPreferences(completion: @escaping (GetPreferencesResult?, Error?) -> Void) {
|
|
12
|
+
DispatchQueue.main.async {
|
|
13
|
+
let result = GetPreferencesResult(
|
|
14
|
+
fontScale: self.getFontScale(),
|
|
15
|
+
isReduceMotionEnabled: UIAccessibility.isReduceMotionEnabled,
|
|
16
|
+
isBoldTextEnabled: UIAccessibility.isBoldTextEnabled,
|
|
17
|
+
isInvertColorsEnabled: UIAccessibility.isInvertColorsEnabled,
|
|
18
|
+
isReduceTransparencyEnabled: UIAccessibility.isReduceTransparencyEnabled,
|
|
19
|
+
isHighContrastEnabled: UIAccessibility.isDarkerSystemColorsEnabled
|
|
20
|
+
)
|
|
21
|
+
completion(result, nil)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private static let fontScaleByContentSizeCategory: [UIContentSizeCategory: Double] = [
|
|
26
|
+
.extraSmall: 0.82,
|
|
27
|
+
.small: 0.88,
|
|
28
|
+
.medium: 0.94,
|
|
29
|
+
.large: 1.0,
|
|
30
|
+
.extraLarge: 1.12,
|
|
31
|
+
.extraExtraLarge: 1.24,
|
|
32
|
+
.extraExtraExtraLarge: 1.35,
|
|
33
|
+
.accessibilityMedium: 1.65,
|
|
34
|
+
.accessibilityLarge: 1.94,
|
|
35
|
+
.accessibilityExtraLarge: 2.35,
|
|
36
|
+
.accessibilityExtraExtraLarge: 2.76,
|
|
37
|
+
.accessibilityExtraExtraExtraLarge: 3.12
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
private func getFontScale() -> Double {
|
|
41
|
+
let category = UIApplication.shared.preferredContentSizeCategory
|
|
42
|
+
return Self.fontScaleByContentSizeCategory[category] ?? 1.0
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(AccessibilityPreferencesPlugin)
|
|
5
|
+
public class AccessibilityPreferencesPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "AccessibilityPreferencesPlugin"
|
|
7
|
+
public let jsName = "AccessibilityPreferences"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "getPreferences", returnType: CAPPluginReturnPromise)
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
public static let tag = "AccessibilityPreferencesPlugin"
|
|
13
|
+
|
|
14
|
+
private var implementation: AccessibilityPreferences?
|
|
15
|
+
|
|
16
|
+
override public func load() {
|
|
17
|
+
self.implementation = AccessibilityPreferences(plugin: self)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@objc func getPreferences(_ call: CAPPluginCall) {
|
|
21
|
+
implementation?.getPreferences { result, error in
|
|
22
|
+
if let error = error {
|
|
23
|
+
self.rejectCall(call, error)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
self.resolveCall(call, result)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
31
|
+
CAPLog.print("[", AccessibilityPreferencesPlugin.tag, "] ", error)
|
|
32
|
+
call.reject(error.localizedDescription)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
36
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
37
|
+
call.resolve(result)
|
|
38
|
+
} else {
|
|
39
|
+
call.resolve()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class GetPreferencesResult: NSObject, Result {
|
|
5
|
+
let fontScale: Double
|
|
6
|
+
let isBoldTextEnabled: Bool
|
|
7
|
+
let isHighContrastEnabled: Bool
|
|
8
|
+
let isInvertColorsEnabled: Bool
|
|
9
|
+
let isReduceMotionEnabled: Bool
|
|
10
|
+
let isReduceTransparencyEnabled: Bool
|
|
11
|
+
|
|
12
|
+
init(
|
|
13
|
+
fontScale: Double,
|
|
14
|
+
isReduceMotionEnabled: Bool,
|
|
15
|
+
isBoldTextEnabled: Bool,
|
|
16
|
+
isInvertColorsEnabled: Bool,
|
|
17
|
+
isReduceTransparencyEnabled: Bool,
|
|
18
|
+
isHighContrastEnabled: Bool
|
|
19
|
+
) {
|
|
20
|
+
self.fontScale = fontScale
|
|
21
|
+
self.isReduceMotionEnabled = isReduceMotionEnabled
|
|
22
|
+
self.isBoldTextEnabled = isBoldTextEnabled
|
|
23
|
+
self.isInvertColorsEnabled = isInvertColorsEnabled
|
|
24
|
+
self.isReduceTransparencyEnabled = isReduceTransparencyEnabled
|
|
25
|
+
self.isHighContrastEnabled = isHighContrastEnabled
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc public func toJSObject() -> AnyObject {
|
|
29
|
+
var result = JSObject()
|
|
30
|
+
result["fontScale"] = fontScale
|
|
31
|
+
result["isReduceMotionEnabled"] = isReduceMotionEnabled
|
|
32
|
+
result["isBoldTextEnabled"] = isBoldTextEnabled
|
|
33
|
+
result["isInvertColorsEnabled"] = isInvertColorsEnabled
|
|
34
|
+
result["isReduceTransparencyEnabled"] = isReduceTransparencyEnabled
|
|
35
|
+
result["isHighContrastEnabled"] = isHighContrastEnabled
|
|
36
|
+
return result as AnyObject
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-accessibility-preferences",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Capacitor plugin for reading the user's system accessibility preferences.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorAccessibilityPreferences.podspec",
|
|
15
|
+
"Package.swift"
|
|
16
|
+
],
|
|
17
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/capawesome-team/capacitor-plugins/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/capawesome-team/"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "opencollective",
|
|
33
|
+
"url": "https://opencollective.com/capawesome"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://capawesome.io/docs/plugins/accessibility-preferences/",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
44
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
45
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
46
|
+
"verify:web": "npm run build",
|
|
47
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
48
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
49
|
+
"eslint": "eslint . --ext ts",
|
|
50
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
51
|
+
"swiftlint": "node-swiftlint",
|
|
52
|
+
"docgen": "docgen --api AccessibilityPreferencesPlugin --output-readme README.md --output-json dist/docs.json",
|
|
53
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
54
|
+
"clean": "rimraf ./dist",
|
|
55
|
+
"watch": "tsc --watch",
|
|
56
|
+
"ios:pod:install": "cd ios && pod install --repo-update && cd ..",
|
|
57
|
+
"ios:spm:install": "cd ios && swift package resolve && cd ..",
|
|
58
|
+
"prepublishOnly": "npm run build"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@capacitor/android": "8.0.0",
|
|
62
|
+
"@capacitor/cli": "8.0.0",
|
|
63
|
+
"@capacitor/core": "8.0.0",
|
|
64
|
+
"@capacitor/docgen": "0.3.1",
|
|
65
|
+
"@capacitor/ios": "8.0.0",
|
|
66
|
+
"@ionic/eslint-config": "0.4.0",
|
|
67
|
+
"eslint": "8.57.0",
|
|
68
|
+
"prettier-plugin-java": "2.6.7",
|
|
69
|
+
"rimraf": "6.1.2",
|
|
70
|
+
"rollup": "4.53.3",
|
|
71
|
+
"swiftlint": "2.0.0",
|
|
72
|
+
"typescript": "5.9.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@capacitor/core": ">=8.0.0"
|
|
76
|
+
},
|
|
77
|
+
"eslintConfig": {
|
|
78
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
79
|
+
},
|
|
80
|
+
"capacitor": {
|
|
81
|
+
"ios": {
|
|
82
|
+
"src": "ios"
|
|
83
|
+
},
|
|
84
|
+
"android": {
|
|
85
|
+
"src": "android"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|