@rdlabo/ionic-angular-kit 0.0.11 → 0.0.13
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
CHANGED
|
@@ -26,10 +26,18 @@ npm install @rdlabo/ionic-angular-kit
|
|
|
26
26
|
| `@ionic/angular` | `^8.0.0` |
|
|
27
27
|
| `@ionic/storage-angular` | `^4.0.0` |
|
|
28
28
|
| `@capacitor/core` | `>=6.0.0 <9.0.0` |
|
|
29
|
+
| `@capacitor/haptics` | `>=6.0.0 <9.0.0` |
|
|
29
30
|
| `@capacitor/keyboard` | `>=6.0.0 <9.0.0` |
|
|
30
31
|
| `@capacitor/network` | `>=6.0.0 <9.0.0` |
|
|
32
|
+
| `@capacitor/preferences` | `>=6.0.0 <9.0.0` |
|
|
33
|
+
| `@capacitor/status-bar` | `>=6.0.0 <9.0.0` |
|
|
34
|
+
| `@capacitor-community/in-app-review` | `>=6.0.0 <9.0.0` |
|
|
35
|
+
| `@rdlabo/capacitor-brotherprint` | `>=6.0.0 <9.0.0` |
|
|
36
|
+
| `dom-to-image-more` | `^3.0.0` |
|
|
31
37
|
| `rxjs` | `^7.8.0` |
|
|
32
38
|
|
|
39
|
+
Feature-scoped peers are only needed by the features that use them (`status-bar` → `KitThemeController`; `preferences` + `in-app-review` → `kitRequestReview`; `capacitor-brotherprint` + `dom-to-image-more` → the printer helpers); an app that doesn't use a feature can ignore its unmet-peer warning.
|
|
40
|
+
|
|
33
41
|
---
|
|
34
42
|
|
|
35
43
|
## Features
|
|
@@ -409,6 +417,43 @@ export class ComposePage {
|
|
|
409
417
|
|
|
410
418
|
---
|
|
411
419
|
|
|
420
|
+
### KitThemeController + provideKitTheme
|
|
421
|
+
|
|
422
|
+
Light/dark theme controller that unifies the theme logic that had drifted across the fleet: it persists the user's choice, follows the OS `prefers-color-scheme` until the user overrides it, toggles the configured palette classes, and syncs the native Android status bar. It also fixes a latent leak in one variant where the system-theme listener stayed registered after a manual toggle — `changeTheme()` always detaches the listener first, so a later OS change can't silently flip an app the user pinned.
|
|
423
|
+
|
|
424
|
+
Per-app CSS differences are absorbed by config: `darkClasses` are toggled on when dark, `lightClasses` on when light. The kit ships no class names of its own. Subscribe to `themeSubject` (a `BehaviorSubject`) to reflect the current mode in the UI. It is a controller (not a plain function) because the subject and OS-listener are shared state across the app lifetime.
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
// app.config.ts
|
|
428
|
+
provideKitTheme({
|
|
429
|
+
storageKey: StorageKeyEnum.theme,
|
|
430
|
+
darkClasses: ['ion-palette-dark', 'a2ui-dark'],
|
|
431
|
+
lightClasses: ['a2ui-light'],
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// app.component.ts — apply on boot
|
|
435
|
+
inject(KitThemeController).setDefaultThemeMode();
|
|
436
|
+
|
|
437
|
+
// settings page — bind a toggle
|
|
438
|
+
const theme = inject(KitThemeController);
|
|
439
|
+
theme.themeSubject.subscribe((mode) => this.isDark.set(mode === 'dark'));
|
|
440
|
+
theme.changeTheme(true); // force dark, stop following the OS
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
### kitRequestReview
|
|
446
|
+
|
|
447
|
+
A plain function (no DI — `@capacitor/preferences`, `@capacitor-community/in-app-review` and `Capacitor` are all static) that requests the native in-app review dialog, throttled so the user is prompted at most once per window. A no-op on web. The wait/throttle/record sequence was previously copy-pasted verbatim across the fleet; centralizing it means a single place to tune the prompt cadence. The storage key and throttle window are passed as arguments, so the kit ships no config of its own.
|
|
448
|
+
|
|
449
|
+
```typescript
|
|
450
|
+
import { kitRequestReview } from '@rdlabo/ionic-angular-kit';
|
|
451
|
+
|
|
452
|
+
await kitRequestReview({ storageKey: StorageEnum.lastRequestRate, throttleMonths: 3 });
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
412
457
|
### Utilities
|
|
413
458
|
|
|
414
459
|
Framework-agnostic helpers (no DI required unless noted):
|
|
@@ -432,6 +477,61 @@ async onSubmit(event: Event) {
|
|
|
432
477
|
}
|
|
433
478
|
```
|
|
434
479
|
|
|
480
|
+
Ionic-event / lifecycle helpers:
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
import { kitChangeEventDisabled, kitCreateDidEnter } from '@rdlabo/ionic-angular-kit';
|
|
484
|
+
|
|
485
|
+
// Toggle a signal-held ion-infinite-scroll / ion-refresher's `disabled` (no-op when empty).
|
|
486
|
+
kitChangeEventDisabled(infiniteScrollSignal, true);
|
|
487
|
+
|
|
488
|
+
// Observe an Ionic page's "is entered" state from its lifecycle DOM events (true on didEnter).
|
|
489
|
+
readonly isEntered = toSignal(kitCreateDidEnter(inject(ElementRef)), { initialValue: false });
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
### kitPresentLanguageActionSheet
|
|
495
|
+
|
|
496
|
+
A plain function (the `ActionSheetController` is passed in — nothing injected) that presents a language picker and, on a new selection, reloads the app at that locale's entry point. Unifies the language-switch flow duplicated across apps: it stashes the current path in `sessionStorage` (to restore after reload), records the chosen locale in `localStorage`, and calls `window.location.replace()` with the app-provided URL. Being a navigation helper, it stays standalone rather than part of a controller. All text, the locale list, and the per-locale URL mapping are injected, so the kit stays free of i18n strings.
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
import { kitPresentLanguageActionSheet } from '@rdlabo/ionic-angular-kit';
|
|
500
|
+
|
|
501
|
+
await kitPresentLanguageActionSheet(inject(ActionSheetController), {
|
|
502
|
+
header: $localize`言語設定`,
|
|
503
|
+
locales: [{ text: 'English', data: 'en-US' }, { text: '日本語', data: 'ja' }],
|
|
504
|
+
cancelText: $localize`キャンセル`,
|
|
505
|
+
currentLocale: normalizedLocale,
|
|
506
|
+
currentPath: this.#router.url,
|
|
507
|
+
pathnameStorageKey: StorageKeyEnum.pathnameBeforeRedirect,
|
|
508
|
+
buildRedirectUrl: (locale) => location.origin + (localePath[locale.toLowerCase()] ?? '/index.html'),
|
|
509
|
+
enabled: environment.production,
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
### Printer (Brother label plumbing)
|
|
516
|
+
|
|
517
|
+
Three pure functions (no DI) that extract the i18n-free core of the fleet's Brother label printing, so a device-quirk or print-setting fix lands in every app at once. The UI orchestration — search/channel-selection alerts, loading overlays, and the app-specific paper list — stays in each app, since those diverge (labels, paper options, copies policy).
|
|
518
|
+
|
|
519
|
+
- `kitDomToPng(element, { rotate?, scale? })` — render a DOM element to a base64 PNG with the fleet's device fixes (iOS +2px to avoid bottom clipping, none on Android to avoid a black line; retries up to 10×). The caller presents its own loading UI.
|
|
520
|
+
- `kitRotationImage(base64)` — rotate a base64 image 90° via canvas.
|
|
521
|
+
- `kitBuildBrotherPrintSettings({ modelName, printBase64, label, numberOfCopies, halftoneThreshold })` — assemble the canonical `BRLMPrintOptions` (fit-page, centered, best quality, threshold halftone, standard margins, tape size parsed from the label's `W<w>H<h>` code). Merge `{ port, channelInfo }` from the selected channel before calling `BrotherPrint.printImage()`.
|
|
522
|
+
|
|
523
|
+
```typescript
|
|
524
|
+
import { kitDomToPng, kitBuildBrotherPrintSettings } from '@rdlabo/ionic-angular-kit';
|
|
525
|
+
|
|
526
|
+
const png = await kitDomToPng(this.preview().nativeElement, { rotate: true });
|
|
527
|
+
const settings = kitBuildBrotherPrintSettings({
|
|
528
|
+
modelName, printBase64: png, label,
|
|
529
|
+
numberOfCopies: printOptions.printNum,
|
|
530
|
+
halftoneThreshold: printOptions.halftoneThreshold,
|
|
531
|
+
});
|
|
532
|
+
await BrotherPrint.printImage({ ...settings, port: channel.port, channelInfo: channel.channelInfo });
|
|
533
|
+
```
|
|
534
|
+
|
|
435
535
|
---
|
|
436
536
|
|
|
437
537
|
## Consumer Vitest setup notes
|