@rdlabo/ionic-angular-kit 0.0.12 → 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.
@@ -1,9 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, EnvironmentProviders, OnInit, ElementRef } from '@angular/core';
3
- import { ModalOptions, PopoverOptions, ToastOptions, AlertController } from '@ionic/angular/standalone';
2
+ import { InjectionToken, EnvironmentProviders, OnInit, ElementRef, WritableSignal } from '@angular/core';
3
+ import { ModalOptions, PopoverOptions, ToastOptions, AlertController, ActionSheetController } from '@ionic/angular/standalone';
4
4
  import { PluginListenerHandle } from '@capacitor/core';
5
+ import { BehaviorSubject, Observable } from 'rxjs';
6
+ import { BRLMPrinterModelName, BRLMPrinterLabelName, BRLMPrintOptions } from '@rdlabo/capacitor-brotherprint';
5
7
  import { RouterStateSnapshot, UrlTree, CanActivateFn } from '@angular/router';
6
- import { Observable } from 'rxjs';
7
8
  import { HttpRequest, HttpResponse, HttpErrorResponse, HttpEvent, HttpInterceptorFn } from '@angular/common/http';
8
9
  import { ImpactStyle } from '@capacitor/haptics';
9
10
 
@@ -402,6 +403,70 @@ interface KitAuthFailedAlertOptions {
402
403
  */
403
404
  declare const kitPresentAuthFailedAlert: (alertCtrl: AlertController, options: KitAuthFailedAlertOptions) => Promise<void>;
404
405
 
406
+ /** One selectable language in {@link kitPresentLanguageActionSheet}. */
407
+ interface KitLanguageOption {
408
+ /** Button label shown to the user (e.g. `English`, `日本語`). */
409
+ readonly text: string;
410
+ /** Locale identifier returned when this option is chosen (e.g. `en-US`, `ja`). */
411
+ readonly data: string;
412
+ }
413
+ /**
414
+ * Options for {@link kitPresentLanguageActionSheet}.
415
+ *
416
+ * @remarks
417
+ * The kit ships no strings or URLs of its own: labels, the locale list, and the redirect-URL mapping
418
+ * are all supplied by the caller, so a multilingual app passes `$localize`-resolved text and its own
419
+ * per-locale build paths.
420
+ */
421
+ interface KitLanguageActionSheetOptions {
422
+ /** Action-sheet header text. */
423
+ readonly header: string;
424
+ /** Selectable languages, in display order. */
425
+ readonly locales: readonly KitLanguageOption[];
426
+ /** Text for the cancel button. */
427
+ readonly cancelText: string;
428
+ /** The currently active locale; selecting the same value is a no-op. Normalize before passing. */
429
+ readonly currentLocale: string;
430
+ /** The current in-app path (e.g. `router.url`), stashed so the app can restore it after the reload. */
431
+ readonly currentPath: string;
432
+ /** `sessionStorage` key under which {@link currentPath} is stored. */
433
+ readonly pathnameStorageKey: string;
434
+ /** Maps a chosen locale to the URL to navigate to (the app's per-locale build entry point). */
435
+ readonly buildRedirectUrl: (locale: string) => string;
436
+ /** Gate for the redirect — pass `false` (e.g. outside production) to present without navigating. */
437
+ readonly enabled: boolean;
438
+ }
439
+ /**
440
+ * Present a language picker and, on a new selection, reload the app at that locale's entry point.
441
+ *
442
+ * @remarks
443
+ * A plain function (the `ActionSheetController` is passed in, so nothing is injected) that unifies the
444
+ * language-switch flow duplicated across apps. On a changed selection while {@link enabled} it stashes
445
+ * the current path in `sessionStorage` (so the app can return the user to where they were), records the
446
+ * chosen locale in `localStorage` under `'locale'`, and calls `window.location.replace()` with the
447
+ * app-provided URL. Because it performs navigation, it is a standalone helper rather than part of a
448
+ * controller (mirroring `kitPresentReloadAlert` / `kitPresentAuthFailedAlert`). Centralizing it means a
449
+ * future improvement to the switch flow lands in every app at once.
450
+ *
451
+ * @param actionSheetCtrl - the Ionic `ActionSheetController`
452
+ * @param options - labels, locale list, and redirect configuration; see {@link KitLanguageActionSheetOptions}
453
+ * @returns a Promise that resolves once presented (and, on a new selection, after the reload is triggered)
454
+ * @example
455
+ * ```ts
456
+ * await kitPresentLanguageActionSheet(inject(ActionSheetController), {
457
+ * header: $localize`言語設定`,
458
+ * locales: [{ text: 'English', data: 'en-US' }, { text: '日本語', data: 'ja' }],
459
+ * cancelText: $localize`キャンセル`,
460
+ * currentLocale: normalizedLocale,
461
+ * currentPath: this.#router.url,
462
+ * pathnameStorageKey: StorageKeyEnum.pathnameBeforeRedirect,
463
+ * buildRedirectUrl: (locale) => location.origin + (localePath[locale.toLowerCase()] ?? '/index.html'),
464
+ * enabled: environment.production,
465
+ * });
466
+ * ```
467
+ */
468
+ declare const kitPresentLanguageActionSheet: (actionSheetCtrl: ActionSheetController, options: KitLanguageActionSheetOptions) => Promise<void>;
469
+
405
470
  /**
406
471
  * Work around iOS `ion-input` autofill values not propagating to the Angular form model.
407
472
  *
@@ -485,6 +550,236 @@ type KitKeyboardAdjust = 'transform' | 'offset' | 'keyboard-offset';
485
550
  */
486
551
  declare const kitKeyboardInit: (elementRef: ElementRef, type: KitKeyboardAdjust) => Promise<PluginListenerHandle[]>;
487
552
 
553
+ /**
554
+ * Theme configuration injected via `provideKitTheme()` and consumed by `KitThemeController`.
555
+ *
556
+ * @remarks
557
+ * All fields are required; the consuming application supplies a complete configuration so every app
558
+ * in the fleet has the same shape. The class lists absorb the per-app CSS drift: the kit toggles
559
+ * `darkClasses` on when dark and `lightClasses` on when light, so an app that only uses Ionic's
560
+ * palette passes `darkClasses: ['ion-palette-dark'], lightClasses: []`, while an app with an extra
561
+ * design-system palette adds its own classes (e.g. `darkClasses: ['ion-palette-dark', 'a2ui-dark']`,
562
+ * `lightClasses: ['a2ui-light']`).
563
+ */
564
+ interface KitThemeConfig {
565
+ /** Key under which the chosen theme (`'light'` | `'dark'`) is persisted via `KitStorageService`. */
566
+ readonly storageKey: string;
567
+ /** Classes toggled **on** the document element when the dark theme is active. */
568
+ readonly darkClasses: readonly string[];
569
+ /** Classes toggled **on** the document element when the light theme is active. */
570
+ readonly lightClasses: readonly string[];
571
+ }
572
+ /**
573
+ * Injection token carrying the {@link KitThemeConfig} for `KitThemeController`.
574
+ *
575
+ * @remarks
576
+ * Provide it through {@link provideKitTheme} rather than registering it directly.
577
+ */
578
+ declare const KIT_THEME_CONFIG: InjectionToken<KitThemeConfig>;
579
+ /**
580
+ * Wire `KitThemeController` into the application.
581
+ *
582
+ * @param config - theme configuration: the storage key and the light/dark class lists
583
+ * @returns environment providers to add to the application's provider list
584
+ * @example
585
+ * ```ts
586
+ * bootstrapApplication(AppComponent, {
587
+ * providers: [
588
+ * provideKitTheme({
589
+ * storageKey: StorageKeyEnum.theme,
590
+ * darkClasses: ['ion-palette-dark', 'a2ui-dark'],
591
+ * lightClasses: ['a2ui-light'],
592
+ * }),
593
+ * ],
594
+ * });
595
+ * ```
596
+ */
597
+ declare const provideKitTheme: (config: KitThemeConfig) => EnvironmentProviders;
598
+
599
+ /** The active theme mode. */
600
+ type KitThemeMode = 'light' | 'dark';
601
+ /**
602
+ * Light/dark theme controller: persists the user's choice, follows the OS setting until the user
603
+ * overrides it, toggles the configured palette classes, and syncs the native Android status bar.
604
+ *
605
+ * @remarks
606
+ * Consolidates the theme logic that had drifted across the fleet into one behavior. Notably it fixes
607
+ * a latent leak in one variant where the system-theme listener stayed registered after a manual
608
+ * toggle: {@link changeTheme} always detaches the listener via {@link removeEventListener} before
609
+ * applying the forced theme, so a later OS change can no longer silently flip an app the user pinned.
610
+ *
611
+ * - **Persistence** — the chosen mode is stored via {@link KitStorageService} under the configured key.
612
+ * - **Follow OS until overridden** — on boot with nothing stored, it tracks
613
+ * `prefers-color-scheme` (idempotent registration); once the user calls {@link changeTheme} it stops
614
+ * following and honors the explicit choice.
615
+ * - **Class toggling** — toggles {@link KitThemeConfig.darkClasses} on when dark and
616
+ * {@link KitThemeConfig.lightClasses} on when light, absorbing per-app CSS differences via config.
617
+ * - **Native status bar** — on Android native only, mirrors the Ionic behavior of setting the status
618
+ * bar style to match (iOS derives it from the web content, so it is intentionally left untouched).
619
+ *
620
+ * Subscribe to {@link themeSubject} to reflect the current mode in the UI (e.g. a settings toggle).
621
+ *
622
+ * @example
623
+ * ```ts
624
+ * // On boot (app.component):
625
+ * inject(KitThemeController).setDefaultThemeMode();
626
+ *
627
+ * // From a settings toggle:
628
+ * const theme = inject(KitThemeController);
629
+ * theme.themeSubject.subscribe((mode) => this.isDark.set(mode === 'dark'));
630
+ * theme.changeTheme(true);
631
+ * ```
632
+ */
633
+ declare class KitThemeController {
634
+ #private;
635
+ /**
636
+ * Emits the active theme, seeded with `'light'`.
637
+ *
638
+ * @remarks
639
+ * A `BehaviorSubject`, so a late subscriber immediately receives the current mode; it emits again
640
+ * on every {@link setDefaultThemeMode} / {@link changeTheme} and on OS theme changes while following.
641
+ */
642
+ readonly themeSubject: BehaviorSubject<KitThemeMode>;
643
+ /**
644
+ * Apply the persisted theme, or start following the OS setting when nothing is stored yet.
645
+ *
646
+ * @remarks
647
+ * Call once on boot (e.g. from `app.component`).
648
+ *
649
+ * @returns a Promise that resolves once the initial theme has been applied
650
+ */
651
+ setDefaultThemeMode(): Promise<void>;
652
+ /**
653
+ * Force a theme, persist it, and stop following the OS setting.
654
+ *
655
+ * @param isDark - `true` for the dark theme, `false` for light
656
+ * @returns a Promise that resolves once the theme has been persisted and applied
657
+ */
658
+ changeTheme(isDark: boolean): Promise<void>;
659
+ static ɵfac: i0.ɵɵFactoryDeclaration<KitThemeController, never>;
660
+ static ɵprov: i0.ɵɵInjectableDeclaration<KitThemeController>;
661
+ }
662
+
663
+ /**
664
+ * Options for {@link kitRequestReview}.
665
+ */
666
+ interface KitRequestReviewOptions {
667
+ /**
668
+ * Key under which the timestamp of the last review request is stored (via `@capacitor/preferences`).
669
+ *
670
+ * @remarks
671
+ * Supplied by the caller so the kit ships no storage keys of its own; each app passes its own enum
672
+ * value.
673
+ */
674
+ readonly storageKey: string;
675
+ /**
676
+ * Minimum number of months between review prompts.
677
+ *
678
+ * @remarks
679
+ * A prompt is only shown when this much time has elapsed since the last one (or when there is no
680
+ * record yet), so the OS review dialog is never nagged repeatedly.
681
+ */
682
+ readonly throttleMonths: number;
683
+ }
684
+ /**
685
+ * Request the native in-app review dialog, throttled so the user is prompted at most once per window.
686
+ *
687
+ * @remarks
688
+ * A plain function — no DI needed (`@capacitor/preferences`, `@capacitor-community/in-app-review` and
689
+ * `Capacitor` are all static), so the caller invokes it directly and passes its own config rather
690
+ * than injecting a controller. A no-op on non-native platforms. When enough time has elapsed since
691
+ * the last prompt (per {@link KitRequestReviewOptions.throttleMonths}, tracked under
692
+ * {@link KitRequestReviewOptions.storageKey}), it briefly waits for the app to settle, calls
693
+ * `InAppReview.requestReview()`, and records the new timestamp. The wait/throttle/record sequence
694
+ * was previously copy-pasted verbatim across the fleet; centralizing it means a single place to tune
695
+ * the prompt cadence.
696
+ *
697
+ * @param options - the storage key and throttle window; see {@link KitRequestReviewOptions}
698
+ * @returns a Promise that resolves once the request has been made (or immediately if throttled / on web)
699
+ * @example
700
+ * ```ts
701
+ * await kitRequestReview({ storageKey: StorageEnum.lastRequestRate, throttleMonths: 3 });
702
+ * ```
703
+ */
704
+ declare const kitRequestReview: (options: KitRequestReviewOptions) => Promise<void>;
705
+
706
+ /**
707
+ * Rotate a base64 image 90°, returning a new base64 data URL of the same MIME type.
708
+ *
709
+ * @remarks
710
+ * Pure DOM/canvas work — no DI. Used before sending a label to the printer when the artwork must be
711
+ * turned to match the tape orientation. Extracted verbatim from the fleet's printer services so the
712
+ * canvas handling lives in one place.
713
+ *
714
+ * @param imageData - a base64 data URL (e.g. `data:image/png;base64,...`)
715
+ * @returns a Promise resolving to the rotated image as a base64 data URL
716
+ */
717
+ declare const kitRotationImage: (imageData: string) => Promise<string>;
718
+ /** Options for {@link kitDomToPng}. */
719
+ interface KitDomToPngOptions {
720
+ /** When `true`, the rendered PNG is rotated 90° via {@link kitRotationImage}. Defaults to `false`. */
721
+ readonly rotate?: boolean;
722
+ /** Rendering scale passed to `dom-to-image-more`. Defaults to `3` (the fleet's print resolution). */
723
+ readonly scale?: number;
724
+ }
725
+ /**
726
+ * Render a DOM element to a base64 PNG for label printing, with the fleet's device-specific fixes.
727
+ *
728
+ * @remarks
729
+ * Pure function — no DI (reads the platform from `Capacitor`, uses the global `document`), so the
730
+ * caller presents its own loading UI around it. Centralizes the hard-won device quirks: on iOS it
731
+ * pads width/height by 2px (otherwise the bottom is clipped), on Android it does not (the padding
732
+ * introduces a black line). Retries the `dom-to-image-more` render up to 10 times because the first
733
+ * pass can occasionally return empty. This is exactly the kind of plumbing where a future fix should
734
+ * land in every app at once.
735
+ *
736
+ * @param element - the element to rasterize (e.g. the label preview host)
737
+ * @param options - rendering options; see {@link KitDomToPngOptions}
738
+ * @returns a Promise resolving to the PNG as a base64 data URL (empty string if every attempt failed)
739
+ * @example
740
+ * ```ts
741
+ * const loading = await this.#loadingCtrl.create({ message: this.text.generating });
742
+ * await loading.present();
743
+ * const png = await kitDomToPng(this.preview().nativeElement, { rotate: true });
744
+ * await loading.dismiss();
745
+ * ```
746
+ */
747
+ declare const kitDomToPng: (element: HTMLElement, options?: KitDomToPngOptions) => Promise<string>;
748
+ /** Parameters for {@link kitBuildBrotherPrintSettings}. */
749
+ interface KitBrotherPrintSettingsParams {
750
+ /** The target printer model. */
751
+ readonly modelName: BRLMPrinterModelName;
752
+ /** The label artwork as a base64 data URL (the `data:...,` prefix is stripped internally). */
753
+ readonly printBase64: string;
754
+ /** The selected label/paper (its `W<width>H<height>` code drives the tape dimensions). */
755
+ readonly label: BRLMPrinterLabelName;
756
+ /** Number of copies to print. Passed by the caller (apps differ: some use the print option, some fix 1). */
757
+ readonly numberOfCopies: number;
758
+ /** Halftone threshold for the print. */
759
+ readonly halftoneThreshold: number;
760
+ }
761
+ /**
762
+ * Assemble the Brother `BRLMPrintOptions` for a die-cut label print, minus the transport fields.
763
+ *
764
+ * @remarks
765
+ * Pure function — no DI. Centralizes the fleet's canonical print settings (fit-page scale, centered,
766
+ * best quality, threshold halftone, 2mm/1mm margins, `gapLength` 2.0) and the tape sizing derived
767
+ * from the label's `W<width>H<height>` code. The caller merges the printer's `port` / `channelInfo`
768
+ * onto the result before calling `BrotherPrint.printImage()`, so channel selection and loading UI stay
769
+ * in the app.
770
+ *
771
+ * @param params - model, artwork, label, copies, and halftone threshold; see {@link KitBrotherPrintSettingsParams}
772
+ * @returns the `BRLMPrintOptions` ready to be spread with `{ port, channelInfo }`
773
+ * @example
774
+ * ```ts
775
+ * const settings = kitBuildBrotherPrintSettings({
776
+ * modelName, printBase64, label, numberOfCopies: printOptions.printNum, halftoneThreshold: printOptions.halftoneThreshold,
777
+ * });
778
+ * await BrotherPrint.printImage({ ...settings, port: channel.port, channelInfo: channel.channelInfo });
779
+ * ```
780
+ */
781
+ declare const kitBuildBrotherPrintSettings: (params: KitBrotherPrintSettingsParams) => BRLMPrintOptions;
782
+
488
783
  /**
489
784
  * Discriminated set of authentication states the guards react to.
490
785
  *
@@ -996,5 +1291,45 @@ declare const objectEqual: (a: object, b: object) => boolean;
996
1291
  */
997
1292
  declare const disableHandler: (event: Event, work: Promise<void | boolean>) => Promise<void>;
998
1293
 
999
- export { KIT_AUTH_CONFIG, KIT_HTTP_CONFIG, KIT_OVERLAY_CONFIG, KitAutofillDirective, KitOverlayController, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, kitAuthInterceptor, kitImpact, kitKeyboardInit, kitPresentAuthFailedAlert, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay };
1000
- export type { KitAlertCloseOptions, KitAlertConfirmOptions, KitAuthConfig, KitAuthFailedAlertOptions, KitAuthRedirects, KitAuthState, KitHttpConfig, KitKeyboardAdjust, KitLabels, KitModalPresentOptions, KitOverlayConfig, KitReloadAlertOptions };
1294
+ /**
1295
+ * Toggle the `disabled` flag of a signal-held `ion-infinite-scroll` / `ion-refresher` element.
1296
+ *
1297
+ * @remarks
1298
+ * A tiny pure helper for the common pattern of stashing the completing scroll/refresher element in a
1299
+ * signal (e.g. captured from the event) and later enabling/disabling it — for instance disabling
1300
+ * infinite scroll once the last page has loaded. A no-op when the signal holds no element.
1301
+ *
1302
+ * @param completeEvent - a writable signal holding the infinite-scroll / refresher element (or nullish)
1303
+ * @param disabled - the value to set on the element's `disabled` property
1304
+ * @example
1305
+ * ```ts
1306
+ * const infinite = signal<HTMLIonInfiniteScrollElement | null>(null);
1307
+ * // ...on ionInfinite: infinite.set(ev.target); ...when no more pages:
1308
+ * kitChangeEventDisabled(infinite, true);
1309
+ * ```
1310
+ */
1311
+ declare const kitChangeEventDisabled: (completeEvent: WritableSignal<HTMLIonInfiniteScrollElement | HTMLIonRefresherElement | null | undefined>, disabled: boolean) => void;
1312
+
1313
+ /**
1314
+ * Observe an Ionic page's "is currently entered" state from its lifecycle DOM events.
1315
+ *
1316
+ * @remarks
1317
+ * Emits `true` on `ionViewDidEnter` and `false` on `ionViewWillEnter` / `ionViewWillLeave`, seeded
1318
+ * with `false` via `startWith`. Useful to pause/resume work (timers, video, expensive rendering)
1319
+ * while a page is off-screen in Ionic's stack navigation, without wiring the four lifecycle hooks by
1320
+ * hand. The listeners are removed when the Observable is unsubscribed.
1321
+ *
1322
+ * @param el - an `ElementRef` for the page host element (the `ion-page`)
1323
+ * @returns an Observable that emits whether the page is currently entered
1324
+ * @example
1325
+ * ```ts
1326
+ * export class FeedPage {
1327
+ * readonly #host = inject(ElementRef);
1328
+ * readonly isEntered = toSignal(kitCreateDidEnter(this.#host), { initialValue: false });
1329
+ * }
1330
+ * ```
1331
+ */
1332
+ declare const kitCreateDidEnter: (el: ElementRef) => Observable<boolean>;
1333
+
1334
+ export { KIT_AUTH_CONFIG, KIT_HTTP_CONFIG, KIT_OVERLAY_CONFIG, KIT_THEME_CONFIG, KitAutofillDirective, KitOverlayController, KitReloadAlertController, KitStorageService, KitThemeController, arrayConcatById, disableHandler, kitAuthInterceptor, kitBuildBrotherPrintSettings, kitChangeEventDisabled, kitCreateDidEnter, kitDomToPng, kitImpact, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRequestReview, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, kitRotationImage, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay, provideKitTheme };
1335
+ export type { KitAlertCloseOptions, KitAlertConfirmOptions, KitAuthConfig, KitAuthFailedAlertOptions, KitAuthRedirects, KitAuthState, KitBrotherPrintSettingsParams, KitDomToPngOptions, KitHttpConfig, KitKeyboardAdjust, KitLabels, KitLanguageActionSheetOptions, KitLanguageOption, KitModalPresentOptions, KitOverlayConfig, KitReloadAlertOptions, KitRequestReviewOptions, KitThemeConfig, KitThemeMode };