@rdlabo/ionic-angular-kit 21.2.0-3 → 21.2.0-5
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 +83 -79
- package/fesm2022/rdlabo-ionic-angular-kit-printer.mjs +71 -1
- package/fesm2022/rdlabo-ionic-angular-kit-printer.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit.mjs +170 -4
- package/fesm2022/rdlabo-ionic-angular-kit.mjs.map +1 -1
- package/package.json +5 -1
- package/types/rdlabo-ionic-angular-kit-printer.d.ts +68 -2
- package/types/rdlabo-ionic-angular-kit.d.ts +90 -5
package/README.md
CHANGED
|
@@ -23,25 +23,25 @@ Kit shares the repo `v*` release line with the other libraries (see root README
|
|
|
23
23
|
|
|
24
24
|
### Peer dependencies
|
|
25
25
|
|
|
26
|
-
| Package
|
|
27
|
-
|
|
28
|
-
| `@angular/common`
|
|
29
|
-
| `@angular/core`
|
|
30
|
-
| `@angular/router`
|
|
31
|
-
| `@ionic/angular`
|
|
32
|
-
| `@ionic/storage-angular`
|
|
33
|
-
| `@capacitor/core`
|
|
34
|
-
| `@capacitor/haptics`
|
|
35
|
-
| `@capacitor/keyboard`
|
|
36
|
-
| `@capacitor/network`
|
|
37
|
-
| `@capacitor/preferences`
|
|
38
|
-
| `@capacitor/status-bar`
|
|
26
|
+
| Package | Version |
|
|
27
|
+
| ------------------------------------ | ---------------- |
|
|
28
|
+
| `@angular/common` | `^21.0.0` |
|
|
29
|
+
| `@angular/core` | `^21.0.0` |
|
|
30
|
+
| `@angular/router` | `^21.0.0` |
|
|
31
|
+
| `@ionic/angular` | `^8.0.0` |
|
|
32
|
+
| `@ionic/storage-angular` | `^4.0.0` |
|
|
33
|
+
| `@capacitor/core` | `>=6.0.0 <9.0.0` |
|
|
34
|
+
| `@capacitor/haptics` | `>=6.0.0 <9.0.0` |
|
|
35
|
+
| `@capacitor/keyboard` | `>=6.0.0 <9.0.0` |
|
|
36
|
+
| `@capacitor/network` | `>=6.0.0 <9.0.0` |
|
|
37
|
+
| `@capacitor/preferences` | `>=6.0.0 <9.0.0` |
|
|
38
|
+
| `@capacitor/status-bar` | `>=6.0.0 <9.0.0` |
|
|
39
39
|
| `@capacitor-community/in-app-review` | `>=6.0.0 <9.0.0` |
|
|
40
|
-
| `@rdlabo/capacitor-brotherprint`
|
|
41
|
-
| `dom-to-image-more`
|
|
42
|
-
| `rxjs`
|
|
40
|
+
| `@rdlabo/capacitor-brotherprint` | `>=6.0.0 <9.0.0` |
|
|
41
|
+
| `dom-to-image-more` | `^3.0.0` |
|
|
42
|
+
| `rxjs` | `^7.8.0` |
|
|
43
43
|
|
|
44
|
-
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.
|
|
44
|
+
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 Brother/PNG printer helpers; `pdf-lib` → the PDF printer helper); an app that doesn't use a feature can ignore its unmet-peer warning.
|
|
45
45
|
|
|
46
46
|
---
|
|
47
47
|
|
|
@@ -61,9 +61,7 @@ import { IonicStorageModule } from '@ionic/storage-angular';
|
|
|
61
61
|
import { importProvidersFrom } from '@angular/core';
|
|
62
62
|
|
|
63
63
|
export const appConfig: ApplicationConfig = {
|
|
64
|
-
providers: [
|
|
65
|
-
importProvidersFrom(IonicStorageModule.withConfig({ name: '__mydb' })),
|
|
66
|
-
],
|
|
64
|
+
providers: [importProvidersFrom(IonicStorageModule.withConfig({ name: '__mydb' }))],
|
|
67
65
|
};
|
|
68
66
|
```
|
|
69
67
|
|
|
@@ -185,13 +183,13 @@ alertConfirm(options: {
|
|
|
185
183
|
|
|
186
184
|
`watchKeyboard: true` (on `presentModal` options) expands a bottom sheet to full height when the native keyboard appears (iOS/Android only; no-op on web).
|
|
187
185
|
|
|
188
|
-
**How `presentModal` decides required vs. optional props.** Props are inferred from the component's `input()` fields, and whether each prop is **required** or **optional** is decided by a single rule:
|
|
186
|
+
**How `presentModal` decides required vs. optional props.** Props are inferred from the component's `input()` fields, and whether each prop is **required** or **optional** is decided by a single rule: _does the input's type include `undefined`?_ A default value is not "optional" — providing a default removes `undefined` from the input's type, so a defaulted input becomes a **required** prop.
|
|
189
187
|
|
|
190
|
-
| Declaration | Input type
|
|
191
|
-
| ------------------------ |
|
|
192
|
-
| `input.required<T>()` | `T`
|
|
193
|
-
| `input<T>(defaultValue)` | `T`
|
|
194
|
-
| `input<T>()` (no arg) | `T \| undefined
|
|
188
|
+
| Declaration | Input type | Includes `undefined`? | Prop |
|
|
189
|
+
| ------------------------ | ---------------- | --------------------- | ------------------------------------------ |
|
|
190
|
+
| `input.required<T>()` | `T` | No | required |
|
|
191
|
+
| `input<T>(defaultValue)` | `T` | No | **required** ← a default makes it required |
|
|
192
|
+
| `input<T>()` (no arg) | `T \| undefined` | Yes | optional |
|
|
195
193
|
|
|
196
194
|
To make a prop **optional**, drop the default and use a bare `input<T>()` (its type is `T | undefined`), then apply your fallback where you read it (e.g. `this.enabled() ?? true`). If a component has at least one required input, the `componentProps` argument itself becomes mandatory; if it has no required inputs, `componentProps` may be omitted; a component with no `input()` fields at all accepts loose, untyped props.
|
|
197
195
|
|
|
@@ -216,11 +214,11 @@ This centralizes presentation options, keeps component props and dismiss data ty
|
|
|
216
214
|
|
|
217
215
|
Functional `CanActivateFn` guards for a four-state auth model:
|
|
218
216
|
|
|
219
|
-
| State
|
|
220
|
-
|
|
221
|
-
| `'user'`
|
|
222
|
-
| `'confirm'`
|
|
223
|
-
| `'required'`
|
|
217
|
+
| State | Meaning |
|
|
218
|
+
| ------------- | ---------------------------------------------------- |
|
|
219
|
+
| `'user'` | Fully authenticated |
|
|
220
|
+
| `'confirm'` | Authenticated but email confirmation pending |
|
|
221
|
+
| `'required'` | Not authenticated |
|
|
224
222
|
| `'anonymous'` | Anonymous login active (can be prompted to register) |
|
|
225
223
|
|
|
226
224
|
**Convention:** every redirect path is supplied via `provideKitAuth`; the kit does not hard-code any routes. `authState` and `redirects` are required. The app-specific hooks `onAuthorized` / `onUnauthenticated` are **optional** and default to `true` (allow the authenticated user through) / `false` (fall through to the `whenUnauthorized` redirect), so an app only supplies the ones with real logic.
|
|
@@ -236,12 +234,12 @@ export const appConfig: ApplicationConfig = {
|
|
|
236
234
|
provideKitAuth(() => {
|
|
237
235
|
const auth = inject(AuthService);
|
|
238
236
|
return {
|
|
239
|
-
authState: () => auth.state$,
|
|
237
|
+
authState: () => auth.state$, // Observable<KitAuthState>
|
|
240
238
|
redirects: {
|
|
241
|
-
whenAuthorized: '/home',
|
|
242
|
-
whenConfirming: '/auth/confirm',
|
|
243
|
-
whenNotConfirming: '/auth/signin'
|
|
244
|
-
whenUnauthorized: '/auth',
|
|
239
|
+
whenAuthorized: '/home', // kitRequiredUnauthorizedGuard
|
|
240
|
+
whenConfirming: '/auth/confirm', // kitRequiredUnauthorizedGuard
|
|
241
|
+
whenNotConfirming: '/auth/signin', // kitRequireConfirmingGuard
|
|
242
|
+
whenUnauthorized: '/auth', // kitRequireAuthorizedGuard
|
|
245
243
|
},
|
|
246
244
|
// onAuthorized / onUnauthenticated omitted → defaults (allow / redirect).
|
|
247
245
|
// Supply onAuthorized only when 'user' needs extra work (token login, permissions):
|
|
@@ -277,11 +275,7 @@ const logged = await auth.tokenLogin().catch(async (e) => {
|
|
|
277
275
|
|
|
278
276
|
```typescript
|
|
279
277
|
// routes.ts
|
|
280
|
-
import {
|
|
281
|
-
kitRequiredUnauthorizedGuard,
|
|
282
|
-
kitRequireConfirmingGuard,
|
|
283
|
-
kitRequireAuthorizedGuard,
|
|
284
|
-
} from '@rdlabo/ionic-angular-kit';
|
|
278
|
+
import { kitRequiredUnauthorizedGuard, kitRequireConfirmingGuard, kitRequireAuthorizedGuard } from '@rdlabo/ionic-angular-kit';
|
|
285
279
|
|
|
286
280
|
export const routes: Routes = [
|
|
287
281
|
{
|
|
@@ -364,6 +358,7 @@ export const appConfig: ApplicationConfig = {
|
|
|
364
358
|
```
|
|
365
359
|
|
|
366
360
|
**Error dispatch** (after retries, in `catchError`):
|
|
361
|
+
|
|
367
362
|
1. `offlineFallback` non-null → return fallback observable (no further hooks called)
|
|
368
363
|
2. `401` → `onUnauthorized` · `403` → `onForbidden`
|
|
369
364
|
3. `0` (connected) → `onNetworkError` · `429` → `onRateLimited(retryAfter?)` · `502/503/504` → `onServerBusy(status, retryAfter?)`
|
|
@@ -417,15 +412,10 @@ Sign-in / sign-up conveniences on `ion-input`:
|
|
|
417
412
|
Fleet apps typically `storage.clear()` on sign-out. Pass keys that must survive (e.g. the last sign-in email):
|
|
418
413
|
|
|
419
414
|
```typescript
|
|
420
|
-
import {
|
|
421
|
-
KIT_LAST_AUTH_EMAIL_KEY,
|
|
422
|
-
KIT_THEME_STORAGE_KEY,
|
|
423
|
-
kitClearStoragePreservingKeys,
|
|
424
|
-
} from '@rdlabo/ionic-angular-kit';
|
|
415
|
+
import { KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY, kitClearStoragePreservingKeys } from '@rdlabo/ionic-angular-kit';
|
|
425
416
|
|
|
426
417
|
await kitSignOut(auth, {
|
|
427
|
-
success: () =>
|
|
428
|
-
kitClearStoragePreservingKeys(this.storage, [KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY]),
|
|
418
|
+
success: () => kitClearStoragePreservingKeys(this.storage, [KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY]),
|
|
429
419
|
});
|
|
430
420
|
```
|
|
431
421
|
|
|
@@ -542,7 +532,10 @@ import { kitPresentLanguageActionSheet } from '@rdlabo/ionic-angular-kit';
|
|
|
542
532
|
|
|
543
533
|
await kitPresentLanguageActionSheet(inject(ActionSheetController), {
|
|
544
534
|
header: $localize`言語設定`,
|
|
545
|
-
locales: [
|
|
535
|
+
locales: [
|
|
536
|
+
{ text: 'English', data: 'en-US' },
|
|
537
|
+
{ text: '日本語', data: 'ja' },
|
|
538
|
+
],
|
|
546
539
|
cancelText: $localize`キャンセル`,
|
|
547
540
|
currentLocale: normalizedLocale,
|
|
548
541
|
currentPath: this.#router.url,
|
|
@@ -554,24 +547,38 @@ await kitPresentLanguageActionSheet(inject(ActionSheetController), {
|
|
|
554
547
|
|
|
555
548
|
---
|
|
556
549
|
|
|
557
|
-
### Printer (
|
|
550
|
+
### Printer (label image and PDF plumbing)
|
|
558
551
|
|
|
559
|
-
|
|
552
|
+
Pure functions (no DI) that extract the i18n-free core of the fleet's label printing, so a device-quirk, layout, or PDF fix lands in every app at once. The UI orchestration — paper-selection alerts, loading overlays, storage, printer transport, and app-specific copies policy — stays in each app.
|
|
560
553
|
|
|
561
554
|
- `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.
|
|
562
555
|
- `kitRotationImage(base64)` — rotate a base64 image 90° via canvas.
|
|
563
556
|
- `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()`.
|
|
557
|
+
- `kitCalculatePrintLayout({ paper, labelWidthPx, labelHeightPx, copies, measure?, marginMm? })` — calculate row-major positions across as many pages as required. The default outer margin is 5mm.
|
|
558
|
+
- `kitBuildLabelPdf({ imageData, ...layoutOptions })` — embed the PNG artwork at the calculated positions and return PDF bytes. It deliberately does not open a browser tab or call a native printer.
|
|
559
|
+
- `kitPrintPaperSizes` — A4/B5 presets. Callers may pass any other `KitPrintPaper` dimensions without changing the kit.
|
|
564
560
|
|
|
565
561
|
```typescript
|
|
566
|
-
import { kitDomToPng,
|
|
562
|
+
import { kitBuildBrotherPrintSettings, kitBuildLabelPdf, kitDomToPng, kitPrintPaperSizes } from '@rdlabo/ionic-angular-kit/printer';
|
|
567
563
|
|
|
568
564
|
const png = await kitDomToPng(this.preview().nativeElement, { rotate: true });
|
|
569
565
|
const settings = kitBuildBrotherPrintSettings({
|
|
570
|
-
modelName,
|
|
566
|
+
modelName,
|
|
567
|
+
printBase64: png,
|
|
568
|
+
label,
|
|
571
569
|
numberOfCopies: printOptions.printNum,
|
|
572
570
|
halftoneThreshold: printOptions.halftoneThreshold,
|
|
573
571
|
});
|
|
574
572
|
await BrotherPrint.printImage({ ...settings, port: channel.port, channelInfo: channel.channelInfo });
|
|
573
|
+
|
|
574
|
+
const pdfBytes = await kitBuildLabelPdf({
|
|
575
|
+
imageData: png,
|
|
576
|
+
paper: kitPrintPaperSizes.a4,
|
|
577
|
+
labelWidthPx: 200,
|
|
578
|
+
labelHeightPx: 100,
|
|
579
|
+
copies: 6,
|
|
580
|
+
marginMm: 5,
|
|
581
|
+
});
|
|
575
582
|
```
|
|
576
583
|
|
|
577
584
|
---
|
|
@@ -591,7 +598,11 @@ provideKitFirebaseAnalytics(),
|
|
|
591
598
|
```typescript
|
|
592
599
|
import { inject, Injectable } from '@angular/core';
|
|
593
600
|
import {
|
|
594
|
-
KIT_FIREBASE_AUTH,
|
|
601
|
+
KIT_FIREBASE_AUTH,
|
|
602
|
+
kitSignIn,
|
|
603
|
+
kitSignOut,
|
|
604
|
+
kitResolveAuthStatus,
|
|
605
|
+
kitReauthWithRetry,
|
|
595
606
|
} from '@rdlabo/ionic-angular-kit/auth-firebase';
|
|
596
607
|
import { updatePassword } from 'firebase/auth'; // escape hatch for the reauth mutation
|
|
597
608
|
|
|
@@ -651,29 +662,29 @@ export const appConfig: ApplicationConfig = {
|
|
|
651
662
|
};
|
|
652
663
|
```
|
|
653
664
|
|
|
654
|
-
#### Release
|
|
665
|
+
#### Release and channel model
|
|
655
666
|
|
|
656
|
-
|
|
667
|
+
Each app's release workflow runs when a `vX.Y.Z` or `vX.Y.Z-N` tag is pushed. The shared `classify-mobile-release` composite action in [`ionic-angular-library/.github/actions`](https://github.com/rdlabo-team/ionic-angular-library/tree/main/.github/actions) compares the tag with the previous release and selects the delivery path. Patch and prerelease updates within the same `major.minor` line use `publish-live-update`; major and minor updates use Capawesome Cloud Native Builds and App Store Publishing.
|
|
657
668
|
|
|
658
|
-
|
|
669
|
+
Every delivery channel is named **`production-<native-build-number>`**, where the Android `versionCode` and iOS `CURRENT_PROJECT_VERSION` must match. A Live Update replaces only the JS, HTML, and CSS on an existing native binary, so channels are isolated by build number and updates reach only compatible devices. The upload pins `--android-min/max` and `--ios-min/max` to that build number.
|
|
659
670
|
|
|
660
|
-
-
|
|
661
|
-
|
|
662
|
-
|
|
671
|
+
- **Same channel: eligible for Live Update**
|
|
672
|
+
Keep the native build number unchanged. This path is for JS, HTML, and CSS changes only, including bug fixes, copy, UI, application logic, and npm dependencies that do not affect native code. Incrementing only the patch version within the same `major.minor` line keeps the channel unchanged, so existing users receive the update without installing a new store build.
|
|
673
|
+
Example: `9.0.0` (build `9000000`) followed by a web-only `9.0.1` update; both use `production-9000000`.
|
|
663
674
|
|
|
664
|
-
-
|
|
665
|
-
|
|
666
|
-
|
|
675
|
+
- **New channel: store release required**
|
|
676
|
+
Increment the major or minor version and the native build number. Include changes to `app/android/**`, `app/ios/**`, `capacitor.config.ts` (or `.json`), and Capacitor plugin versions in this release type. The workflow submits iOS builds to TestFlight and Android builds to the Google Play Internal track; promotion to production happens in each store.
|
|
677
|
+
Example: a native update to `9.1.0` (build `9010000`) creates `production-9010000`. Devices still running `9.0.x` remain on `production-9000000` and are unaffected.
|
|
667
678
|
|
|
668
|
-
|
|
679
|
+
The build number encodes the major and minor versions at the front: `floor(buildNumber / 10000) === major * 100 + minor`.
|
|
669
680
|
|
|
670
|
-
|
|
|
671
|
-
|
|
|
672
|
-
| `9.0.x`
|
|
673
|
-
| `9.1.x`
|
|
674
|
-
| `10.2.x`
|
|
681
|
+
| Version | Build number | Channel |
|
|
682
|
+
| -------- | ------------ | --------------------- |
|
|
683
|
+
| `9.0.x` | `9000000` | `production-9000000` |
|
|
684
|
+
| `9.1.x` | `9010000` | `production-9010000` |
|
|
685
|
+
| `10.2.x` | `10020000` | `production-10020000` |
|
|
675
686
|
|
|
676
|
-
`validate-live-update`
|
|
687
|
+
`classify-mobile-release` fails CI when a patch or prerelease contains native, configuration, or Capacitor dependency changes and requires a major or minor bump instead. For store releases, it verifies that the tag matches the native marketing version, the Android and iOS versions and build numbers agree, the build number increases, and the encoding above is valid. `validate-live-update` remains available for compatibility with existing consumers.
|
|
677
688
|
|
|
678
689
|
---
|
|
679
690
|
|
|
@@ -685,14 +696,7 @@ When testing a consumer app that declares `@rdlabo/ionic-angular-kit` as a `file
|
|
|
685
696
|
// vitest.config.ts
|
|
686
697
|
export default defineConfig({
|
|
687
698
|
resolve: {
|
|
688
|
-
dedupe: [
|
|
689
|
-
'@angular/core',
|
|
690
|
-
'@angular/common',
|
|
691
|
-
'@angular/router',
|
|
692
|
-
'@ionic/angular',
|
|
693
|
-
'@ionic/core',
|
|
694
|
-
'rxjs',
|
|
695
|
-
],
|
|
699
|
+
dedupe: ['@angular/core', '@angular/common', '@angular/router', '@ionic/angular', '@ionic/core', 'rxjs'],
|
|
696
700
|
},
|
|
697
701
|
test: {
|
|
698
702
|
server: {
|
|
@@ -701,7 +705,7 @@ export default defineConfig({
|
|
|
701
705
|
/@ionic\/angular/,
|
|
702
706
|
/@ionic\/core/,
|
|
703
707
|
/ionicons/,
|
|
704
|
-
/@rdlabo\/ionic-angular-kit/,
|
|
708
|
+
/@rdlabo\/ionic-angular-kit/, // inline the kit itself
|
|
705
709
|
],
|
|
706
710
|
},
|
|
707
711
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Capacitor } from '@capacitor/core';
|
|
2
2
|
import { BRLMPrinterHalftone, BRLMPrinterCustomPaperUnit, BRLMPrinterCustomPaperType, BRLMPrinterPrintQuality, BRLMPrinterHorizontalAlignment, BRLMPrinterVerticalAlignment, BRLMPrinterImageRotation, BRLMPrinterScaleMode } from '@rdlabo/capacitor-brotherprint';
|
|
3
3
|
import domtoimage from 'dom-to-image-more';
|
|
4
|
+
import { PDFDocument } from 'pdf-lib';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Rotate a base64 image 90°, returning a new base64 data URL of the same MIME type.
|
|
@@ -134,6 +135,75 @@ const kitBuildBrotherPrintSettings = (params) => {
|
|
|
134
135
|
};
|
|
135
136
|
};
|
|
136
137
|
|
|
138
|
+
/** Standard paper presets shared by the printing applications. */
|
|
139
|
+
const kitPrintPaperSizes = {
|
|
140
|
+
a4: { label: 'A4', widthMm: 210, heightMm: 297 },
|
|
141
|
+
b5: { label: 'B5', widthMm: 182, heightMm: 257 },
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Calculate page dimensions and row-major label positions for a printable PDF.
|
|
145
|
+
*
|
|
146
|
+
* Labels keep their aspect ratio, are never enlarged beyond their requested pixel/physical size,
|
|
147
|
+
* and automatically continue on additional pages when the current page is full.
|
|
148
|
+
*/
|
|
149
|
+
const kitCalculatePrintLayout = (params) => {
|
|
150
|
+
const pointsPerMm = 72 / 25.4;
|
|
151
|
+
const pointsPerPixel = 72 / 96;
|
|
152
|
+
const paperWidth = params.paper.widthMm * pointsPerMm;
|
|
153
|
+
const paperHeight = params.paper.heightMm * pointsPerMm;
|
|
154
|
+
const margin = (params.marginMm ?? 5) * pointsPerMm;
|
|
155
|
+
const aspect = params.labelWidthPx / params.labelHeightPx;
|
|
156
|
+
let labelWidth = params.labelWidthPx * pointsPerPixel;
|
|
157
|
+
let labelHeight = params.labelHeightPx * pointsPerPixel;
|
|
158
|
+
if (params.measure?.type === 'width') {
|
|
159
|
+
labelWidth = params.measure.sizeMm * pointsPerMm;
|
|
160
|
+
labelHeight = labelWidth / aspect;
|
|
161
|
+
}
|
|
162
|
+
else if (params.measure?.type === 'height') {
|
|
163
|
+
labelHeight = params.measure.sizeMm * pointsPerMm;
|
|
164
|
+
labelWidth = labelHeight * aspect;
|
|
165
|
+
}
|
|
166
|
+
const scale = Math.min(1, (paperWidth - margin * 2) / labelWidth, (paperHeight - margin * 2) / labelHeight);
|
|
167
|
+
labelWidth *= scale;
|
|
168
|
+
labelHeight *= scale;
|
|
169
|
+
const positions = [];
|
|
170
|
+
let pageIndex = 0;
|
|
171
|
+
let x = margin;
|
|
172
|
+
let y = paperHeight - margin;
|
|
173
|
+
for (let index = 0; index < Math.max(0, params.copies); index++) {
|
|
174
|
+
if (x + labelWidth > paperWidth - margin + 0.01) {
|
|
175
|
+
x = margin;
|
|
176
|
+
y -= labelHeight;
|
|
177
|
+
}
|
|
178
|
+
if (y - labelHeight < margin - 0.01) {
|
|
179
|
+
pageIndex++;
|
|
180
|
+
x = margin;
|
|
181
|
+
y = paperHeight - margin;
|
|
182
|
+
}
|
|
183
|
+
positions.push({ pageIndex, x, y: y - labelHeight });
|
|
184
|
+
x += labelWidth;
|
|
185
|
+
}
|
|
186
|
+
return { paperWidth, paperHeight, labelWidth, labelHeight, positions };
|
|
187
|
+
};
|
|
188
|
+
/** Build a multi-page label PDF and return its bytes without choosing an output destination. */
|
|
189
|
+
const kitBuildLabelPdf = async (params) => {
|
|
190
|
+
const pdf = await PDFDocument.create();
|
|
191
|
+
const image = await pdf.embedPng(params.imageData);
|
|
192
|
+
const layout = kitCalculatePrintLayout(params);
|
|
193
|
+
const pages = layout.positions.length > 0 ? [pdf.addPage([layout.paperWidth, layout.paperHeight])] : [];
|
|
194
|
+
for (const position of layout.positions) {
|
|
195
|
+
while (pages.length <= position.pageIndex)
|
|
196
|
+
pages.push(pdf.addPage([layout.paperWidth, layout.paperHeight]));
|
|
197
|
+
pages[position.pageIndex].drawImage(image, {
|
|
198
|
+
x: position.x,
|
|
199
|
+
y: position.y,
|
|
200
|
+
width: layout.labelWidth,
|
|
201
|
+
height: layout.labelHeight,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return pdf.save();
|
|
205
|
+
};
|
|
206
|
+
|
|
137
207
|
// Printer: Brother label plumbing (DOM→PNG, rotation, print-settings assembly).
|
|
138
208
|
// Split into its own entry point so only apps that print pull in `@rdlabo/capacitor-brotherprint`
|
|
139
209
|
// and `dom-to-image-more`; the core entry stays free of those native peers.
|
|
@@ -142,5 +212,5 @@ const kitBuildBrotherPrintSettings = (params) => {
|
|
|
142
212
|
* Generated bundle index. Do not edit.
|
|
143
213
|
*/
|
|
144
214
|
|
|
145
|
-
export { kitBuildBrotherPrintSettings, kitDomToPng, kitRotationImage };
|
|
215
|
+
export { kitBuildBrotherPrintSettings, kitBuildLabelPdf, kitCalculatePrintLayout, kitDomToPng, kitPrintPaperSizes, kitRotationImage };
|
|
146
216
|
//# sourceMappingURL=rdlabo-ionic-angular-kit-printer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rdlabo-ionic-angular-kit-printer.mjs","sources":["../../../projects/kit/printer/src/kit-printer.ts","../../../projects/kit/printer/src/public-api.ts","../../../projects/kit/printer/src/rdlabo-ionic-angular-kit-printer.ts"],"sourcesContent":["import { Capacitor } from '@capacitor/core';\nimport type { BRLMPrinterLabelName, BRLMPrinterModelName, BRLMPrintOptions } from '@rdlabo/capacitor-brotherprint';\nimport {\n BRLMPrinterCustomPaperType,\n BRLMPrinterCustomPaperUnit,\n BRLMPrinterHalftone,\n BRLMPrinterHorizontalAlignment,\n BRLMPrinterImageRotation,\n BRLMPrinterPrintQuality,\n BRLMPrinterScaleMode,\n BRLMPrinterVerticalAlignment,\n} from '@rdlabo/capacitor-brotherprint';\nimport domtoimage from 'dom-to-image-more';\n\n/**\n * Rotate a base64 image 90°, returning a new base64 data URL of the same MIME type.\n *\n * @remarks\n * Pure DOM/canvas work — no DI. Used before sending a label to the printer when the artwork must be\n * turned to match the tape orientation. Extracted verbatim from the fleet's printer services so the\n * canvas handling lives in one place.\n *\n * @param imageData - a base64 data URL (e.g. `data:image/png;base64,...`)\n * @returns a Promise resolving to the rotated image as a base64 data URL\n */\nexport const kitRotationImage = async (imageData: string): Promise<string> => {\n const imgType = imageData.substring(5, imageData.indexOf(';'));\n\n const image = new Image();\n const loaded = new Promise<void>((resolve) => {\n image.onload = () => resolve();\n });\n image.src = imageData;\n await loaded;\n\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext('2d');\n\n canvas.width = image.height;\n canvas.height = image.width;\n\n ctx!.rotate((90 * Math.PI) / 180);\n ctx!.translate(0, -image.height);\n ctx!.drawImage(image, 0, 0, image.width, image.height);\n\n return canvas.toDataURL(imgType);\n};\n\n/** Options for {@link kitDomToPng}. */\nexport interface KitDomToPngOptions {\n /** When `true`, the rendered PNG is rotated 90° via {@link kitRotationImage}. Defaults to `false`. */\n readonly rotate?: boolean;\n /** Rendering scale passed to `dom-to-image-more`. Defaults to `3` (the fleet's print resolution). */\n readonly scale?: number;\n}\n\n/**\n * Render a DOM element to a base64 PNG for label printing, with the fleet's device-specific fixes.\n *\n * @remarks\n * Pure function — no DI (reads the platform from `Capacitor`, uses the global `document`), so the\n * caller presents its own loading UI around it. Centralizes the hard-won device quirks: on iOS it\n * pads width/height by 2px (otherwise the bottom is clipped), on Android it does not (the padding\n * introduces a black line). Retries the `dom-to-image-more` render up to 10 times because the first\n * pass can occasionally return empty. This is exactly the kind of plumbing where a future fix should\n * land in every app at once.\n *\n * @param element - the element to rasterize (e.g. the label preview host)\n * @param options - rendering options; see {@link KitDomToPngOptions}\n * @returns a Promise resolving to the PNG as a base64 data URL (empty string if every attempt failed)\n * @example\n * ```ts\n * const loading = await this.#loadingCtrl.create({ message: this.text.generating });\n * await loading.present();\n * const png = await kitDomToPng(this.preview().nativeElement, { rotate: true });\n * await loading.dismiss();\n * ```\n */\nexport const kitDomToPng = async (element: HTMLElement, options?: KitDomToPngOptions): Promise<string> => {\n await new Promise((resolve) => requestAnimationFrame(resolve));\n\n const { clientHeight, clientWidth } = element;\n\n // デバイス毎の問題解決のため、px 調整。\n // iOS: ないと下が途切れる。Android: あると黒線が入る。\n const addClient = Capacitor.getPlatform() === 'ios' ? 2 : 0;\n\n let dataUrl = '';\n for (let i = 0; i < 10; i++) {\n const url = await domtoimage.toPng(element, {\n width: clientWidth + addClient,\n height: clientHeight + addClient,\n scale: options?.scale ?? 3,\n copyDefaultStyles: false,\n });\n if (url) {\n dataUrl = url;\n break;\n }\n }\n\n return options?.rotate ? kitRotationImage(dataUrl) : dataUrl;\n};\n\n/** Parameters for {@link kitBuildBrotherPrintSettings}. */\nexport interface KitBrotherPrintSettingsParams {\n /** The target printer model. */\n readonly modelName: BRLMPrinterModelName;\n /** The label artwork as a base64 data URL (the `data:...,` prefix is stripped internally). */\n readonly printBase64: string;\n /** The selected label/paper (its `W<width>H<height>` code drives the tape dimensions). */\n readonly label: BRLMPrinterLabelName;\n /** Number of copies to print. Passed by the caller (apps differ: some use the print option, some fix 1). */\n readonly numberOfCopies: number;\n /** Halftone threshold for the print. */\n readonly halftoneThreshold: number;\n}\n\n/**\n * Assemble the Brother `BRLMPrintOptions` for a die-cut label print, minus the transport fields.\n *\n * @remarks\n * Pure function — no DI. Centralizes the fleet's canonical print settings (fit-page scale, centered,\n * best quality, threshold halftone, 2mm/1mm margins, `gapLength` 2.0) and the tape sizing derived\n * from the label's `W<width>H<height>` code. The caller merges the printer's `port` / `channelInfo`\n * onto the result before calling `BrotherPrint.printImage()`, so channel selection and loading UI stay\n * in the app.\n *\n * @param params - model, artwork, label, copies, and halftone threshold; see {@link KitBrotherPrintSettingsParams}\n * @returns the `BRLMPrintOptions` ready to be spread with `{ port, channelInfo }`\n * @example\n * ```ts\n * const settings = kitBuildBrotherPrintSettings({\n * modelName, printBase64, label, numberOfCopies: printOptions.printNum, halftoneThreshold: printOptions.halftoneThreshold,\n * });\n * await BrotherPrint.printImage({ ...settings, port: channel.port, channelInfo: channel.channelInfo });\n * ```\n */\nexport const kitBuildBrotherPrintSettings = (params: KitBrotherPrintSettingsParams): BRLMPrintOptions => {\n const startPoint = params.printBase64.indexOf(',');\n const tapeSize = params.label.match(/W(\\d+)H(\\d+)/);\n const tapeWidth = tapeSize && tapeSize.length >= 2 ? parseInt(tapeSize[1], 10) : 0;\n const tapeLength = tapeSize && tapeSize.length >= 3 ? parseInt(tapeSize[2], 10) : 0;\n\n // `BRLMPrintOptions` is a `QL | TD` union; a die-cut label legitimately carries fields from both\n // groups, so the object is composed via spreads to bypass the union's excess-property checks — the\n // same technique the source printer services used.\n return {\n ...{\n modelName: params.modelName,\n encodedImage: params.printBase64.slice(startPoint + 1),\n numberOfCopies: params.numberOfCopies,\n autoCut: true,\n\n scaleMode: BRLMPrinterScaleMode.FitPageAspect,\n imageRotation: BRLMPrinterImageRotation.Rotate0,\n verticalAlignment: BRLMPrinterVerticalAlignment.Center,\n horizontalAlignment: BRLMPrinterHorizontalAlignment.Center,\n printQuality: BRLMPrinterPrintQuality.Best,\n },\n ...{\n labelName: params.label,\n },\n ...{\n paperType: BRLMPrinterCustomPaperType.dieCutPaper,\n paperUnit: BRLMPrinterCustomPaperUnit.mm,\n halftone: BRLMPrinterHalftone.Threshold,\n halftoneThreshold: params.halftoneThreshold,\n tapeWidth: Number(tapeWidth.toFixed(1)),\n tapeLength: Number(tapeLength.toFixed(1)),\n gapLength: 2.0,\n\n marginTop: 1.0,\n marginRight: 2.0,\n marginBottom: 1.0,\n marginLeft: 2.0,\n\n paperMarkPosition: 0,\n paperMarkLength: 0,\n },\n };\n};\n","// Printer: Brother label plumbing (DOM→PNG, rotation, print-settings assembly).\n// Split into its own entry point so only apps that print pull in `@rdlabo/capacitor-brotherprint`\n// and `dom-to-image-more`; the core entry stays free of those native peers.\nexport * from './kit-printer';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAcA;;;;;;;;;;AAUG;MACU,gBAAgB,GAAG,OAAO,SAAiB,KAAqB;AAC3E,IAAA,M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AAc;AACrC,YAAA,OAAO,EAAE,IAAI;YAEb,SAAS,EAAE,oBAAoB,CAAC,aAAa;YAC7C,aAAa,EAAE,wBAAwB,CAAC,OAAO;YAC/C,iBAAiB,EAAE,4BAA4B,CAAC,MAAM;YACtD,mBAAmB,EAAE,8BAA8B,CAAC,MAAM;YAC1D,YAAY,EAAE,uBAAuB,CAAC,IAAI;AAC3C,SAAA;QACD,GAAG;YACD,SAAS,EAAE,MAAM,CAAC,KAAK;AACxB,SAAA;QACD,GAAG;YACD,SAAS,EAAE,0BAA0B,CAAC,WAAW;YACjD,SAAS,EAAE,0BAA0B,CAAC,EAAE;YACxC,QAAQ,EAAE,mBAAmB,CAAC,SAAS;YACvC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;YAC3C,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACvC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACzC,YAAA,SAAS,EAAE,GAAG;AAEd,YAAA,SAAS,EAAE,GAAG;AACd,YAAA,WAAW,EAAE,GAAG;AAChB,YAAA,YAAY,EAAE,GAAG;AACjB,YAAA,UAAU,EAAE,GAAG;AAEf,YAAA,iBAAiB,EAAE,CAAC;AACpB,YAAA,eAAe,EAAE,CAAC;AACnB,SAAA;KACF;AACH;;ACrLA;AACA;AACA;;ACFA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-printer.mjs","sources":["../../../projects/kit/printer/src/kit-printer.ts","../../../projects/kit/printer/src/kit-pdf-printer.ts","../../../projects/kit/printer/src/public-api.ts","../../../projects/kit/printer/src/rdlabo-ionic-angular-kit-printer.ts"],"sourcesContent":["import { Capacitor } from '@capacitor/core';\nimport type { BRLMPrinterLabelName, BRLMPrinterModelName, BRLMPrintOptions } from '@rdlabo/capacitor-brotherprint';\nimport {\n BRLMPrinterCustomPaperType,\n BRLMPrinterCustomPaperUnit,\n BRLMPrinterHalftone,\n BRLMPrinterHorizontalAlignment,\n BRLMPrinterImageRotation,\n BRLMPrinterPrintQuality,\n BRLMPrinterScaleMode,\n BRLMPrinterVerticalAlignment,\n} from '@rdlabo/capacitor-brotherprint';\nimport domtoimage from 'dom-to-image-more';\n\n/**\n * Rotate a base64 image 90°, returning a new base64 data URL of the same MIME type.\n *\n * @remarks\n * Pure DOM/canvas work — no DI. Used before sending a label to the printer when the artwork must be\n * turned to match the tape orientation. Extracted verbatim from the fleet's printer services so the\n * canvas handling lives in one place.\n *\n * @param imageData - a base64 data URL (e.g. `data:image/png;base64,...`)\n * @returns a Promise resolving to the rotated image as a base64 data URL\n */\nexport const kitRotationImage = async (imageData: string): Promise<string> => {\n const imgType = imageData.substring(5, imageData.indexOf(';'));\n\n const image = new Image();\n const loaded = new Promise<void>((resolve) => {\n image.onload = () => resolve();\n });\n image.src = imageData;\n await loaded;\n\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext('2d');\n\n canvas.width = image.height;\n canvas.height = image.width;\n\n ctx!.rotate((90 * Math.PI) / 180);\n ctx!.translate(0, -image.height);\n ctx!.drawImage(image, 0, 0, image.width, image.height);\n\n return canvas.toDataURL(imgType);\n};\n\n/** Options for {@link kitDomToPng}. */\nexport interface KitDomToPngOptions {\n /** When `true`, the rendered PNG is rotated 90° via {@link kitRotationImage}. Defaults to `false`. */\n readonly rotate?: boolean;\n /** Rendering scale passed to `dom-to-image-more`. Defaults to `3` (the fleet's print resolution). */\n readonly scale?: number;\n}\n\n/**\n * Render a DOM element to a base64 PNG for label printing, with the fleet's device-specific fixes.\n *\n * @remarks\n * Pure function — no DI (reads the platform from `Capacitor`, uses the global `document`), so the\n * caller presents its own loading UI around it. Centralizes the hard-won device quirks: on iOS it\n * pads width/height by 2px (otherwise the bottom is clipped), on Android it does not (the padding\n * introduces a black line). Retries the `dom-to-image-more` render up to 10 times because the first\n * pass can occasionally return empty. This is exactly the kind of plumbing where a future fix should\n * land in every app at once.\n *\n * @param element - the element to rasterize (e.g. the label preview host)\n * @param options - rendering options; see {@link KitDomToPngOptions}\n * @returns a Promise resolving to the PNG as a base64 data URL (empty string if every attempt failed)\n * @example\n * ```ts\n * const loading = await this.#loadingCtrl.create({ message: this.text.generating });\n * await loading.present();\n * const png = await kitDomToPng(this.preview().nativeElement, { rotate: true });\n * await loading.dismiss();\n * ```\n */\nexport const kitDomToPng = async (element: HTMLElement, options?: KitDomToPngOptions): Promise<string> => {\n await new Promise((resolve) => requestAnimationFrame(resolve));\n\n const { clientHeight, clientWidth } = element;\n\n // デバイス毎の問題解決のため、px 調整。\n // iOS: ないと下が途切れる。Android: あると黒線が入る。\n const addClient = Capacitor.getPlatform() === 'ios' ? 2 : 0;\n\n let dataUrl = '';\n for (let i = 0; i < 10; i++) {\n const url = await domtoimage.toPng(element, {\n width: clientWidth + addClient,\n height: clientHeight + addClient,\n scale: options?.scale ?? 3,\n copyDefaultStyles: false,\n });\n if (url) {\n dataUrl = url;\n break;\n }\n }\n\n return options?.rotate ? kitRotationImage(dataUrl) : dataUrl;\n};\n\n/** Parameters for {@link kitBuildBrotherPrintSettings}. */\nexport interface KitBrotherPrintSettingsParams {\n /** The target printer model. */\n readonly modelName: BRLMPrinterModelName;\n /** The label artwork as a base64 data URL (the `data:...,` prefix is stripped internally). */\n readonly printBase64: string;\n /** The selected label/paper (its `W<width>H<height>` code drives the tape dimensions). */\n readonly label: BRLMPrinterLabelName;\n /** Number of copies to print. Passed by the caller (apps differ: some use the print option, some fix 1). */\n readonly numberOfCopies: number;\n /** Halftone threshold for the print. */\n readonly halftoneThreshold: number;\n}\n\n/**\n * Assemble the Brother `BRLMPrintOptions` for a die-cut label print, minus the transport fields.\n *\n * @remarks\n * Pure function — no DI. Centralizes the fleet's canonical print settings (fit-page scale, centered,\n * best quality, threshold halftone, 2mm/1mm margins, `gapLength` 2.0) and the tape sizing derived\n * from the label's `W<width>H<height>` code. The caller merges the printer's `port` / `channelInfo`\n * onto the result before calling `BrotherPrint.printImage()`, so channel selection and loading UI stay\n * in the app.\n *\n * @param params - model, artwork, label, copies, and halftone threshold; see {@link KitBrotherPrintSettingsParams}\n * @returns the `BRLMPrintOptions` ready to be spread with `{ port, channelInfo }`\n * @example\n * ```ts\n * const settings = kitBuildBrotherPrintSettings({\n * modelName, printBase64, label, numberOfCopies: printOptions.printNum, halftoneThreshold: printOptions.halftoneThreshold,\n * });\n * await BrotherPrint.printImage({ ...settings, port: channel.port, channelInfo: channel.channelInfo });\n * ```\n */\nexport const kitBuildBrotherPrintSettings = (params: KitBrotherPrintSettingsParams): BRLMPrintOptions => {\n const startPoint = params.printBase64.indexOf(',');\n const tapeSize = params.label.match(/W(\\d+)H(\\d+)/);\n const tapeWidth = tapeSize && tapeSize.length >= 2 ? parseInt(tapeSize[1], 10) : 0;\n const tapeLength = tapeSize && tapeSize.length >= 3 ? parseInt(tapeSize[2], 10) : 0;\n\n // `BRLMPrintOptions` is a `QL | TD` union; a die-cut label legitimately carries fields from both\n // groups, so the object is composed via spreads to bypass the union's excess-property checks — the\n // same technique the source printer services used.\n return {\n ...{\n modelName: params.modelName,\n encodedImage: params.printBase64.slice(startPoint + 1),\n numberOfCopies: params.numberOfCopies,\n autoCut: true,\n\n scaleMode: BRLMPrinterScaleMode.FitPageAspect,\n imageRotation: BRLMPrinterImageRotation.Rotate0,\n verticalAlignment: BRLMPrinterVerticalAlignment.Center,\n horizontalAlignment: BRLMPrinterHorizontalAlignment.Center,\n printQuality: BRLMPrinterPrintQuality.Best,\n },\n ...{\n labelName: params.label,\n },\n ...{\n paperType: BRLMPrinterCustomPaperType.dieCutPaper,\n paperUnit: BRLMPrinterCustomPaperUnit.mm,\n halftone: BRLMPrinterHalftone.Threshold,\n halftoneThreshold: params.halftoneThreshold,\n tapeWidth: Number(tapeWidth.toFixed(1)),\n tapeLength: Number(tapeLength.toFixed(1)),\n gapLength: 2.0,\n\n marginTop: 1.0,\n marginRight: 2.0,\n marginBottom: 1.0,\n marginLeft: 2.0,\n\n paperMarkPosition: 0,\n paperMarkLength: 0,\n },\n };\n};\n","import { PDFDocument } from 'pdf-lib';\n\n/** Physical paper dimensions used to build a PDF page. */\nexport interface KitPrintPaper {\n /** Human-readable paper name. */\n readonly label: string;\n /** Paper width in millimetres. */\n readonly widthMm: number;\n /** Paper height in millimetres. */\n readonly heightMm: number;\n}\n\n/** Standard paper presets shared by the printing applications. */\nexport const kitPrintPaperSizes = {\n a4: { label: 'A4', widthMm: 210, heightMm: 297 },\n b5: { label: 'B5', widthMm: 182, heightMm: 257 },\n} as const satisfies Record<string, KitPrintPaper>;\n\n/** A position for one label on a PDF page, expressed in PDF points. */\nexport interface KitPrintPosition {\n readonly pageIndex: number;\n readonly x: number;\n readonly y: number;\n}\n\n/** Calculated PDF page and label dimensions. */\nexport interface KitPrintLayout {\n readonly paperWidth: number;\n readonly paperHeight: number;\n readonly labelWidth: number;\n readonly labelHeight: number;\n readonly positions: readonly KitPrintPosition[];\n}\n\n/** Optional physical size override for a label. */\nexport interface KitPrintMeasure {\n readonly type: 'width' | 'height';\n readonly sizeMm: number;\n}\n\n/** Parameters for {@link kitCalculatePrintLayout}. */\nexport interface KitCalculatePrintLayoutParams {\n readonly paper: KitPrintPaper;\n readonly labelWidthPx: number;\n readonly labelHeightPx: number;\n readonly copies: number;\n readonly measure?: KitPrintMeasure | null;\n /** Outer page margin in millimetres. Defaults to 5mm. */\n readonly marginMm?: number;\n}\n\n/**\n * Calculate page dimensions and row-major label positions for a printable PDF.\n *\n * Labels keep their aspect ratio, are never enlarged beyond their requested pixel/physical size,\n * and automatically continue on additional pages when the current page is full.\n */\nexport const kitCalculatePrintLayout = (params: KitCalculatePrintLayoutParams): KitPrintLayout => {\n const pointsPerMm = 72 / 25.4;\n const pointsPerPixel = 72 / 96;\n const paperWidth = params.paper.widthMm * pointsPerMm;\n const paperHeight = params.paper.heightMm * pointsPerMm;\n const margin = (params.marginMm ?? 5) * pointsPerMm;\n const aspect = params.labelWidthPx / params.labelHeightPx;\n let labelWidth = params.labelWidthPx * pointsPerPixel;\n let labelHeight = params.labelHeightPx * pointsPerPixel;\n\n if (params.measure?.type === 'width') {\n labelWidth = params.measure.sizeMm * pointsPerMm;\n labelHeight = labelWidth / aspect;\n } else if (params.measure?.type === 'height') {\n labelHeight = params.measure.sizeMm * pointsPerMm;\n labelWidth = labelHeight * aspect;\n }\n\n const scale = Math.min(1, (paperWidth - margin * 2) / labelWidth, (paperHeight - margin * 2) / labelHeight);\n labelWidth *= scale;\n labelHeight *= scale;\n\n const positions: KitPrintPosition[] = [];\n let pageIndex = 0;\n let x = margin;\n let y = paperHeight - margin;\n for (let index = 0; index < Math.max(0, params.copies); index++) {\n if (x + labelWidth > paperWidth - margin + 0.01) {\n x = margin;\n y -= labelHeight;\n }\n if (y - labelHeight < margin - 0.01) {\n pageIndex++;\n x = margin;\n y = paperHeight - margin;\n }\n positions.push({ pageIndex, x, y: y - labelHeight });\n x += labelWidth;\n }\n\n return { paperWidth, paperHeight, labelWidth, labelHeight, positions };\n};\n\n/** Parameters for {@link kitBuildLabelPdf}. */\nexport interface KitBuildLabelPdfParams extends KitCalculatePrintLayoutParams {\n /** PNG label artwork as a data URL or base64 string accepted by pdf-lib. */\n readonly imageData: string;\n}\n\n/** Build a multi-page label PDF and return its bytes without choosing an output destination. */\nexport const kitBuildLabelPdf = async (params: KitBuildLabelPdfParams): Promise<Uint8Array> => {\n const pdf = await PDFDocument.create();\n const image = await pdf.embedPng(params.imageData);\n const layout = kitCalculatePrintLayout(params);\n const pages = layout.positions.length > 0 ? [pdf.addPage([layout.paperWidth, layout.paperHeight])] : [];\n\n for (const position of layout.positions) {\n while (pages.length <= position.pageIndex) pages.push(pdf.addPage([layout.paperWidth, layout.paperHeight]));\n pages[position.pageIndex].drawImage(image, {\n x: position.x,\n y: position.y,\n width: layout.labelWidth,\n height: layout.labelHeight,\n });\n }\n\n return pdf.save();\n};\n","// Printer: Brother label plumbing (DOM→PNG, rotation, print-settings assembly).\n// Split into its own entry point so only apps that print pull in `@rdlabo/capacitor-brotherprint`\n// and `dom-to-image-more`; the core entry stays free of those native peers.\nexport * from './kit-printer';\nexport * from './kit-pdf-printer';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAcA;;;;;;;;;;AAUG;MACU,gBAAgB,GAAG,OAAO,SAAiB,KAAqB;AAC3E,IAAA,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAE9D,IAAA,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE;IACzB,MAAM,MAAM,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,KAAI;QAC3C,KAAK,CAAC,MAAM,GAAG,MAAM,OAAO,EAAE;AAChC,IAAA,CAAC,CAAC;AACF,IAAA,KAAK,CAAC,GAAG,GAAG,SAAS;AACrB,IAAA,MAAM,MAAM;IAEZ,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;AAEnC,IAAA,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AAC3B,IAAA,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK;AAE3B,IAAA,GAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC;IACjC,GAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;AAChC,IAAA,GAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC;AAEtD,IAAA,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;AAClC;AAUA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACI,MAAM,WAAW,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