@keepui/ui 0.1.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 +267 -0
- package/capacitor/index.d.ts +6 -0
- package/capacitor/keepui-ui-capacitor.d.ts.map +1 -0
- package/capacitor/lib/providers/provide-keep-ui-capacitor.d.ts +22 -0
- package/capacitor/lib/providers/provide-keep-ui-capacitor.d.ts.map +1 -0
- package/capacitor/lib/services/capacitor-file.service.d.ts +23 -0
- package/capacitor/lib/services/capacitor-file.service.d.ts.map +1 -0
- package/capacitor/public-api.d.ts +3 -0
- package/capacitor/public-api.d.ts.map +1 -0
- package/fesm2022/keepui-ui-capacitor.mjs +79 -0
- package/fesm2022/keepui-ui-capacitor.mjs.map +1 -0
- package/fesm2022/keepui-ui.mjs +656 -0
- package/fesm2022/keepui-ui.mjs.map +1 -0
- package/index.d.ts +6 -0
- package/keepui-ui.d.ts.map +1 -0
- package/lib/components/button/button.component.d.ts +72 -0
- package/lib/components/button/button.component.d.ts.map +1 -0
- package/lib/components/button/button.types.d.ts +17 -0
- package/lib/components/button/button.types.d.ts.map +1 -0
- package/lib/components/card/card.component.d.ts +23 -0
- package/lib/components/card/card.component.d.ts.map +1 -0
- package/lib/components/image-preview/image-preview.component.d.ts +40 -0
- package/lib/components/image-preview/image-preview.component.d.ts.map +1 -0
- package/lib/i18n/keep-ui-translations.d.ts +21 -0
- package/lib/i18n/keep-ui-translations.d.ts.map +1 -0
- package/lib/i18n/translation-keys.d.ts +26 -0
- package/lib/i18n/translation-keys.d.ts.map +1 -0
- package/lib/models/file-result.model.d.ts +11 -0
- package/lib/models/file-result.model.d.ts.map +1 -0
- package/lib/ports/file.port.d.ts +17 -0
- package/lib/ports/file.port.d.ts.map +1 -0
- package/lib/providers/keep-ui-i18n.provider.d.ts +43 -0
- package/lib/providers/keep-ui-i18n.provider.d.ts.map +1 -0
- package/lib/providers/provide-keep-ui.d.ts +16 -0
- package/lib/providers/provide-keep-ui.d.ts.map +1 -0
- package/lib/services/keep-ui-language.service.d.ts +36 -0
- package/lib/services/keep-ui-language.service.d.ts.map +1 -0
- package/lib/services/keep-ui-transloco-loader.service.d.ts +18 -0
- package/lib/services/keep-ui-transloco-loader.service.d.ts.map +1 -0
- package/lib/services/web-file.service.d.ts +17 -0
- package/lib/services/web-file.service.d.ts.map +1 -0
- package/lib/testing/mock-file.service.d.ts +21 -0
- package/lib/testing/mock-file.service.d.ts.map +1 -0
- package/lib/tokens/file.token.d.ts +11 -0
- package/lib/tokens/file.token.d.ts.map +1 -0
- package/package.json +40 -0
- package/public-api.d.ts +15 -0
- package/public-api.d.ts.map +1 -0
- package/schematics/collection.json +10 -0
- package/schematics/ng-add/index.d.ts +12 -0
- package/schematics/ng-add/index.js +34 -0
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/index.ts +42 -0
- package/schematics/ng-add/schema.json +16 -0
- package/styles/_index.css +73 -0
- package/styles/themes.css +130 -0
package/README.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# KeepUI
|
|
2
|
+
|
|
3
|
+
> Angular cross-platform UI component library with optional Capacitor support.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@keepui/ui)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
KeepUI is a reusable Angular component library designed to work seamlessly across:
|
|
13
|
+
|
|
14
|
+
- **Standard Angular web applications** (browser only)
|
|
15
|
+
- **Angular + Capacitor applications** (iOS, Android, PWA)
|
|
16
|
+
|
|
17
|
+
The library uses a **Port/Adapter pattern** to keep UI components fully decoupled from platform-specific APIs. Components never import `@capacitor/*` directly; they depend on an injected `FilePort` interface. Concrete implementations are registered via functional providers.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Package Structure
|
|
22
|
+
|
|
23
|
+
| Package | Description |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `@keepui/ui` | Core components, ports, tokens, web adapter |
|
|
26
|
+
| `@keepui/ui/capacitor` | Capacitor adapter — use *instead of* the web provider |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Using ng add (recommended):
|
|
34
|
+
ng add @keepui/ui
|
|
35
|
+
|
|
36
|
+
# Or manually:
|
|
37
|
+
npm install @keepui/ui
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For Capacitor support (optional):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @capacitor/core @capacitor/camera
|
|
44
|
+
npx cap sync
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Usage — Angular Web App
|
|
50
|
+
|
|
51
|
+
### 1. Register the web provider
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// src/app/app.config.ts
|
|
55
|
+
import { ApplicationConfig } from '@angular/core';
|
|
56
|
+
import { provideKeepUi } from '@keepui/ui';
|
|
57
|
+
|
|
58
|
+
export const appConfig: ApplicationConfig = {
|
|
59
|
+
providers: [
|
|
60
|
+
provideKeepUi(),
|
|
61
|
+
// ...other providers
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Use components
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
// src/app/app.component.ts
|
|
70
|
+
import { Component } from '@angular/core';
|
|
71
|
+
import {
|
|
72
|
+
ButtonComponent,
|
|
73
|
+
CardComponent,
|
|
74
|
+
ImagePreviewComponent,
|
|
75
|
+
} from '@keepui/ui';
|
|
76
|
+
|
|
77
|
+
@Component({
|
|
78
|
+
selector: 'app-root',
|
|
79
|
+
standalone: true,
|
|
80
|
+
imports: [ButtonComponent, CardComponent, ImagePreviewComponent],
|
|
81
|
+
template: `
|
|
82
|
+
<keepui-card>
|
|
83
|
+
<h2>Image Picker</h2>
|
|
84
|
+
<keepui-image-preview />
|
|
85
|
+
</keepui-card>
|
|
86
|
+
|
|
87
|
+
<keepui-button (clicked)="greet()">Hello</keepui-button>
|
|
88
|
+
`,
|
|
89
|
+
})
|
|
90
|
+
export class AppComponent {
|
|
91
|
+
greet() {
|
|
92
|
+
alert('Hello from KeepUI!');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Usage — Angular + Capacitor App
|
|
100
|
+
|
|
101
|
+
### 1. Register the Capacitor provider
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// src/app/app.config.ts
|
|
105
|
+
import { ApplicationConfig } from '@angular/core';
|
|
106
|
+
import { provideKeepUiCapacitor } from '@keepui/ui/capacitor';
|
|
107
|
+
|
|
108
|
+
export const appConfig: ApplicationConfig = {
|
|
109
|
+
providers: [
|
|
110
|
+
provideKeepUiCapacitor(),
|
|
111
|
+
// ...other providers
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> **Note:** Use `provideKeepUiCapacitor()` **instead of** `provideKeepUi()` — never both.
|
|
117
|
+
|
|
118
|
+
### 2. Use the same components
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// src/app/app.component.ts — IDENTICAL to the web example above
|
|
122
|
+
import { ImagePreviewComponent } from '@keepui/ui';
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The component is unchanged. Only the provider differs.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Available Components
|
|
130
|
+
|
|
131
|
+
### `<keepui-button>`
|
|
132
|
+
|
|
133
|
+
```html
|
|
134
|
+
<keepui-button (clicked)="doSomething()">Click me</keepui-button>
|
|
135
|
+
<keepui-button [disabled]="isLoading" type="submit">Submit</keepui-button>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Input | Type | Default | Description |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| `disabled` | `boolean` | `false` | Disables the button |
|
|
141
|
+
| `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | HTML type attribute |
|
|
142
|
+
|
|
143
|
+
| Output | Type | Description |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `clicked` | `void` | Emitted on click |
|
|
146
|
+
|
|
147
|
+
### `<keepui-card>`
|
|
148
|
+
|
|
149
|
+
```html
|
|
150
|
+
<keepui-card [elevation]="2">
|
|
151
|
+
<p>Card content</p>
|
|
152
|
+
</keepui-card>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Input | Type | Default | Description |
|
|
156
|
+
|---|---|---|---|
|
|
157
|
+
| `elevation` | `0 \| 1 \| 2 \| 3` | `1` | Shadow depth |
|
|
158
|
+
|
|
159
|
+
### `<keepui-image-preview>`
|
|
160
|
+
|
|
161
|
+
```html
|
|
162
|
+
<keepui-image-preview />
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
No inputs. Requires `FILE_PORT` to be provided (via `provideKeepUi()` or `provideKeepUiCapacitor()`).
|
|
166
|
+
|
|
167
|
+
**Exposed signals (for advanced usage):**
|
|
168
|
+
|
|
169
|
+
| Signal | Type | Description |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `imageUrl` | `Signal<string \| null>` | URL of the selected image |
|
|
172
|
+
| `error` | `Signal<string \| null>` | Error message if pick failed |
|
|
173
|
+
| `loading` | `Signal<boolean>` | True while picking is in progress |
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Architecture Notes
|
|
178
|
+
|
|
179
|
+
### Port/Adapter Pattern
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
ImagePreviewComponent
|
|
183
|
+
│
|
|
184
|
+
│ inject(FILE_PORT)
|
|
185
|
+
▼
|
|
186
|
+
FilePort (interface)
|
|
187
|
+
│
|
|
188
|
+
┌───┴───────────┐
|
|
189
|
+
│ │
|
|
190
|
+
WebFileService CapacitorFileService
|
|
191
|
+
(browser input) (@capacitor/camera)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
- Components depend only on the `FilePort` interface via the `FILE_PORT` injection token.
|
|
195
|
+
- `provideKeepUi()` registers `WebFileService`.
|
|
196
|
+
- `provideKeepUiCapacitor()` registers `CapacitorFileService`.
|
|
197
|
+
- Capacitor dependencies are **not** pulled into web builds.
|
|
198
|
+
|
|
199
|
+
### Secondary Entrypoint
|
|
200
|
+
|
|
201
|
+
The `@keepui/ui/capacitor` entrypoint is a secondary ng-packagr entrypoint within the same library project. It is compiled and published alongside the main package but kept in a separate entry so Capacitor dependencies are not required in web-only applications.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Testing
|
|
206
|
+
|
|
207
|
+
Use `MockFileService` in your tests:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import { MockFileService } from '@keepui/ui';
|
|
211
|
+
import { FILE_PORT } from '@keepui/ui';
|
|
212
|
+
|
|
213
|
+
TestBed.configureTestingModule({
|
|
214
|
+
imports: [ImagePreviewComponent],
|
|
215
|
+
providers: [{ provide: FILE_PORT, useClass: MockFileService }],
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`MockFileService` resolves by default. Set `nextError` to test error paths:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
const mock = TestBed.inject(FILE_PORT) as MockFileService;
|
|
223
|
+
mock.nextError = new Error('Camera cancelled');
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Building
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Build for production (APF, partial compilation):
|
|
232
|
+
npm run build
|
|
233
|
+
|
|
234
|
+
# Build for development (without schematics):
|
|
235
|
+
npm run build:dev
|
|
236
|
+
|
|
237
|
+
# Build schematics only:
|
|
238
|
+
npm run build:schematics
|
|
239
|
+
|
|
240
|
+
# Run tests:
|
|
241
|
+
npm test
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
The production build output is placed in `dist/keep-ui/` and follows Angular Package Format.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Publishing to npm
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
npm run build
|
|
252
|
+
cd dist/keep-ui
|
|
253
|
+
npm publish --access public
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Ensure `package.json` has the correct `name`, `version`, and `peerDependencies` before publishing.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Future Improvements
|
|
261
|
+
|
|
262
|
+
- Additional components (modal, toast, form controls, etc.)
|
|
263
|
+
- More Capacitor adapters (Geolocation, Share, Haptics)
|
|
264
|
+
- Theming support via CSS custom properties
|
|
265
|
+
- Storybook integration
|
|
266
|
+
- Automated publishing via GitHub Actions
|
|
267
|
+
- E2E tests with Playwright
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keepui-ui-capacitor.d.ts","sourceRoot":"","sources":["../../../projects/keep-ui/capacitor/src/keepui-ui-capacitor.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EnvironmentProviders } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Registers KeepUI providers for an **Angular + Capacitor** application.
|
|
4
|
+
*
|
|
5
|
+
* Registers `CapacitorFileService` as the implementation of `FILE_PORT`,
|
|
6
|
+
* enabling `ImagePreviewComponent` to use the device's native image picker.
|
|
7
|
+
*
|
|
8
|
+
* Add to `app.config.ts` **instead of** `provideKeepUi()`:
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { provideKeepUiCapacitor } from '@keepui/ui/capacitor';
|
|
11
|
+
*
|
|
12
|
+
* export const appConfig: ApplicationConfig = {
|
|
13
|
+
* providers: [provideKeepUiCapacitor()],
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Prerequisites:
|
|
18
|
+
* - `@capacitor/camera` plugin installed and synced (`npx cap sync`)
|
|
19
|
+
* - Camera permissions declared in `AndroidManifest.xml` / `Info.plist`
|
|
20
|
+
*/
|
|
21
|
+
export declare function provideKeepUiCapacitor(): EnvironmentProviders;
|
|
22
|
+
//# sourceMappingURL=provide-keep-ui-capacitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provide-keep-ui-capacitor.d.ts","sourceRoot":"","sources":["../../../../../projects/keep-ui/capacitor/src/lib/providers/provide-keep-ui-capacitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA4B,MAAM,eAAe,CAAC;AAI/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,IAAI,oBAAoB,CAI7D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FilePort } from '@keepui/ui';
|
|
2
|
+
import { FileResult } from '@keepui/ui';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Capacitor implementation of `FilePort`.
|
|
6
|
+
*
|
|
7
|
+
* Uses `@capacitor/camera` to open the native image picker on iOS/Android, and
|
|
8
|
+
* falls back gracefully to the web camera on non-native platforms.
|
|
9
|
+
*
|
|
10
|
+
* The returned `dataUrl` is:
|
|
11
|
+
* - On native: the result of `Capacitor.convertFileSrc(photo.path)`, which
|
|
12
|
+
* converts the native file path to an HTTP URL the WebView can display.
|
|
13
|
+
* - On web/PWA: `photo.webPath` as-is.
|
|
14
|
+
*
|
|
15
|
+
* This service has no dependency on `WebFileService`; it is a fully independent
|
|
16
|
+
* adapter registered by `provideKeepUiCapacitor()`.
|
|
17
|
+
*/
|
|
18
|
+
export declare class CapacitorFileService implements FilePort {
|
|
19
|
+
pickImage(): Promise<FileResult>;
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CapacitorFileService, never>;
|
|
21
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CapacitorFileService>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=capacitor-file.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacitor-file.service.d.ts","sourceRoot":"","sources":["../../../../../projects/keep-ui/capacitor/src/lib/services/capacitor-file.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;;AAExC;;;;;;;;;;;;;GAaG;AACH,qBACa,oBAAqB,YAAW,QAAQ;IAC7C,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC;yCAD3B,oBAAoB;6CAApB,oBAAoB;CAsBhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../../projects/keep-ui/capacitor/src/public-api.ts"],"names":[],"mappings":"AAEA,cAAc,uCAAuC,CAAC;AACtD,cAAc,2CAA2C,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
+
import { Capacitor } from '@capacitor/core';
|
|
4
|
+
import { Camera, CameraSource, CameraResultType } from '@capacitor/camera';
|
|
5
|
+
import { FILE_PORT } from '@keepui/ui';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Capacitor implementation of `FilePort`.
|
|
9
|
+
*
|
|
10
|
+
* Uses `@capacitor/camera` to open the native image picker on iOS/Android, and
|
|
11
|
+
* falls back gracefully to the web camera on non-native platforms.
|
|
12
|
+
*
|
|
13
|
+
* The returned `dataUrl` is:
|
|
14
|
+
* - On native: the result of `Capacitor.convertFileSrc(photo.path)`, which
|
|
15
|
+
* converts the native file path to an HTTP URL the WebView can display.
|
|
16
|
+
* - On web/PWA: `photo.webPath` as-is.
|
|
17
|
+
*
|
|
18
|
+
* This service has no dependency on `WebFileService`; it is a fully independent
|
|
19
|
+
* adapter registered by `provideKeepUiCapacitor()`.
|
|
20
|
+
*/
|
|
21
|
+
class CapacitorFileService {
|
|
22
|
+
async pickImage() {
|
|
23
|
+
const photo = await Camera.getPhoto({
|
|
24
|
+
resultType: CameraResultType.Uri,
|
|
25
|
+
source: CameraSource.Photos,
|
|
26
|
+
quality: 90,
|
|
27
|
+
});
|
|
28
|
+
// `photo.path` is the native file path (only available on native platforms).
|
|
29
|
+
// `photo.webPath` is always available but may be undefined on some edge cases.
|
|
30
|
+
const rawPath = photo.path ?? photo.webPath ?? '';
|
|
31
|
+
// On a native Capacitor context, convert the native path to a WebView-friendly URL.
|
|
32
|
+
const dataUrl = Capacitor.isNativePlatform()
|
|
33
|
+
? Capacitor.convertFileSrc(rawPath)
|
|
34
|
+
: rawPath;
|
|
35
|
+
return {
|
|
36
|
+
dataUrl,
|
|
37
|
+
mimeType: `image/${photo.format}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: CapacitorFileService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
41
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: CapacitorFileService }); }
|
|
42
|
+
}
|
|
43
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: CapacitorFileService, decorators: [{
|
|
44
|
+
type: Injectable
|
|
45
|
+
}] });
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Registers KeepUI providers for an **Angular + Capacitor** application.
|
|
49
|
+
*
|
|
50
|
+
* Registers `CapacitorFileService` as the implementation of `FILE_PORT`,
|
|
51
|
+
* enabling `ImagePreviewComponent` to use the device's native image picker.
|
|
52
|
+
*
|
|
53
|
+
* Add to `app.config.ts` **instead of** `provideKeepUi()`:
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { provideKeepUiCapacitor } from '@keepui/ui/capacitor';
|
|
56
|
+
*
|
|
57
|
+
* export const appConfig: ApplicationConfig = {
|
|
58
|
+
* providers: [provideKeepUiCapacitor()],
|
|
59
|
+
* };
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Prerequisites:
|
|
63
|
+
* - `@capacitor/camera` plugin installed and synced (`npx cap sync`)
|
|
64
|
+
* - Camera permissions declared in `AndroidManifest.xml` / `Info.plist`
|
|
65
|
+
*/
|
|
66
|
+
function provideKeepUiCapacitor() {
|
|
67
|
+
return makeEnvironmentProviders([
|
|
68
|
+
{ provide: FILE_PORT, useClass: CapacitorFileService },
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Public API Surface of @keepui/ui/capacitor
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Generated bundle index. Do not edit.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
export { CapacitorFileService, provideKeepUiCapacitor };
|
|
79
|
+
//# sourceMappingURL=keepui-ui-capacitor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keepui-ui-capacitor.mjs","sources":["../../../projects/keep-ui/capacitor/src/lib/services/capacitor-file.service.ts","../../../projects/keep-ui/capacitor/src/lib/providers/provide-keep-ui-capacitor.ts","../../../projects/keep-ui/capacitor/src/public-api.ts","../../../projects/keep-ui/capacitor/src/keepui-ui-capacitor.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\r\nimport { Capacitor } from '@capacitor/core';\r\nimport { Camera, CameraResultType, CameraSource } from '@capacitor/camera';\r\nimport { FilePort } from '@keepui/ui';\r\nimport { FileResult } from '@keepui/ui';\r\n\r\n/**\r\n * Capacitor implementation of `FilePort`.\r\n *\r\n * Uses `@capacitor/camera` to open the native image picker on iOS/Android, and\r\n * falls back gracefully to the web camera on non-native platforms.\r\n *\r\n * The returned `dataUrl` is:\r\n * - On native: the result of `Capacitor.convertFileSrc(photo.path)`, which\r\n * converts the native file path to an HTTP URL the WebView can display.\r\n * - On web/PWA: `photo.webPath` as-is.\r\n *\r\n * This service has no dependency on `WebFileService`; it is a fully independent\r\n * adapter registered by `provideKeepUiCapacitor()`.\r\n */\r\n@Injectable()\r\nexport class CapacitorFileService implements FilePort {\r\n async pickImage(): Promise<FileResult> {\r\n const photo = await Camera.getPhoto({\r\n resultType: CameraResultType.Uri,\r\n source: CameraSource.Photos,\r\n quality: 90,\r\n });\r\n\r\n // `photo.path` is the native file path (only available on native platforms).\r\n // `photo.webPath` is always available but may be undefined on some edge cases.\r\n const rawPath = photo.path ?? photo.webPath ?? '';\r\n\r\n // On a native Capacitor context, convert the native path to a WebView-friendly URL.\r\n const dataUrl = Capacitor.isNativePlatform()\r\n ? Capacitor.convertFileSrc(rawPath)\r\n : rawPath;\r\n\r\n return {\r\n dataUrl,\r\n mimeType: `image/${photo.format}`,\r\n };\r\n }\r\n}\r\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\r\nimport { FILE_PORT } from '@keepui/ui';\r\nimport { CapacitorFileService } from '../services/capacitor-file.service';\r\n\r\n/**\r\n * Registers KeepUI providers for an **Angular + Capacitor** application.\r\n *\r\n * Registers `CapacitorFileService` as the implementation of `FILE_PORT`,\r\n * enabling `ImagePreviewComponent` to use the device's native image picker.\r\n *\r\n * Add to `app.config.ts` **instead of** `provideKeepUi()`:\r\n * ```ts\r\n * import { provideKeepUiCapacitor } from '@keepui/ui/capacitor';\r\n *\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [provideKeepUiCapacitor()],\r\n * };\r\n * ```\r\n *\r\n * Prerequisites:\r\n * - `@capacitor/camera` plugin installed and synced (`npx cap sync`)\r\n * - Camera permissions declared in `AndroidManifest.xml` / `Info.plist`\r\n */\r\nexport function provideKeepUiCapacitor(): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n { provide: FILE_PORT, useClass: CapacitorFileService },\r\n ]);\r\n}\r\n","// Public API Surface of @keepui/ui/capacitor\r\n\r\nexport * from './lib/services/capacitor-file.service';\r\nexport * from './lib/providers/provide-keep-ui-capacitor';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAMA;;;;;;;;;;;;;AAaG;MAEU,oBAAoB,CAAA;AAC/B,IAAA,MAAM,SAAS,GAAA;AACb,QAAA,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC;YAClC,UAAU,EAAE,gBAAgB,CAAC,GAAG;YAChC,MAAM,EAAE,YAAY,CAAC,MAAM;AAC3B,YAAA,OAAO,EAAE,EAAE;AACZ,SAAA,CAAC;;;QAIF,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,IAAI,EAAE;;AAGjD,QAAA,MAAM,OAAO,GAAG,SAAS,CAAC,gBAAgB;AACxC,cAAE,SAAS,CAAC,cAAc,CAAC,OAAO;cAChC,OAAO;QAEX,OAAO;YACL,OAAO;AACP,YAAA,QAAQ,EAAE,CAAA,MAAA,EAAS,KAAK,CAAC,MAAM,CAAA,CAAE;SAClC;IACH;+GArBW,oBAAoB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;mHAApB,oBAAoB,EAAA,CAAA,CAAA;;4FAApB,oBAAoB,EAAA,UAAA,EAAA,CAAA;kBADhC;;;AChBD;;;;;;;;;;;;;;;;;;AAkBG;SACa,sBAAsB,GAAA;AACpC,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,oBAAoB,EAAE;AACvD,KAAA,CAAC;AACJ;;AC3BA;;ACAA;;AAEG;;;;"}
|