@rdlabo/ionic-angular-kit 21.5.40 → 21.6.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/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +285 -199
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit-printer.mjs +173 -1
- package/fesm2022/rdlabo-ionic-angular-kit-printer.mjs.map +1 -1
- package/package.json +1 -1
- package/types/rdlabo-ionic-angular-kit-offline.d.ts +12 -9
- package/types/rdlabo-ionic-angular-kit-printer.d.ts +51 -2
|
@@ -204,6 +204,178 @@ const kitBuildLabelPdf = async (params) => {
|
|
|
204
204
|
return pdf.save();
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
+
const defaultDependencies = () => ({
|
|
208
|
+
document,
|
|
209
|
+
url: URL,
|
|
210
|
+
schedule: (callback, delay) => globalThis.setTimeout(callback, delay),
|
|
211
|
+
});
|
|
212
|
+
const createPdfUrl = (pdfBytes, dependencies) => dependencies.url.createObjectURL(new Blob([Uint8Array.from(pdfBytes).buffer], {
|
|
213
|
+
type: 'application/pdf',
|
|
214
|
+
}));
|
|
215
|
+
const cleanupDelay = (value) => (value !== undefined && Number.isFinite(value) && value >= 0 ? value : 60_000);
|
|
216
|
+
const createCleanup = (pdfUrl, dependencies, link) => {
|
|
217
|
+
let cleaned = false;
|
|
218
|
+
return () => {
|
|
219
|
+
if (cleaned)
|
|
220
|
+
return;
|
|
221
|
+
cleaned = true;
|
|
222
|
+
try {
|
|
223
|
+
link?.remove();
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// Cleanup is best-effort and must not turn successful PDF output into a failure.
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
try {
|
|
230
|
+
dependencies.url.revokeObjectURL(pdfUrl);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
// Object URL cleanup is best-effort for the same reason.
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
const scheduleCleanup = (cleanup, delay, dependencies) => {
|
|
239
|
+
try {
|
|
240
|
+
dependencies.schedule(cleanup, delay);
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
try {
|
|
245
|
+
globalThis.setTimeout(cleanup, delay);
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const isWindowClosed = (target) => {
|
|
254
|
+
try {
|
|
255
|
+
return target.closed;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const closeWindow = (target) => {
|
|
262
|
+
try {
|
|
263
|
+
if (target && !target.closed)
|
|
264
|
+
target.close();
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
// Closing a placeholder is best-effort and must never replace the original output error.
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Download generated PDF bytes without navigating the current application page.
|
|
272
|
+
*
|
|
273
|
+
* @remarks Browser-only. Do not call during server-side rendering.
|
|
274
|
+
*
|
|
275
|
+
* The temporary anchor and object URL stay alive long enough for browsers to start the download.
|
|
276
|
+
* Cleanup is registered before clicking so a cleanup scheduling error cannot be mistaken for a PDF
|
|
277
|
+
* generation failure after the download has already started.
|
|
278
|
+
*/
|
|
279
|
+
const kitDownloadPdf = (pdfBytes, options) => {
|
|
280
|
+
const dependencies = options.dependencies ?? defaultDependencies();
|
|
281
|
+
const pdfUrl = createPdfUrl(pdfBytes, dependencies);
|
|
282
|
+
let link;
|
|
283
|
+
let cleanup = createCleanup(pdfUrl, dependencies);
|
|
284
|
+
let cleanupScheduled = false;
|
|
285
|
+
try {
|
|
286
|
+
link = dependencies.document.createElement('a');
|
|
287
|
+
cleanup = createCleanup(pdfUrl, dependencies, link);
|
|
288
|
+
link.href = pdfUrl;
|
|
289
|
+
link.download = options.filename;
|
|
290
|
+
link.style.display = 'none';
|
|
291
|
+
dependencies.document.body.appendChild(link);
|
|
292
|
+
cleanupScheduled = scheduleCleanup(cleanup, cleanupDelay(options.cleanupDelayMs), dependencies);
|
|
293
|
+
// Keep this as the final synchronous output operation: the browser may start immediately.
|
|
294
|
+
link.click();
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
cleanup();
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
if (!cleanupScheduled)
|
|
302
|
+
cleanup();
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Open a placeholder window synchronously for an asynchronously generated PDF.
|
|
307
|
+
*
|
|
308
|
+
* Call this directly from the user's click handler, before awaiting PDF generation, to avoid popup
|
|
309
|
+
* blocking. If the preview cannot be opened or is closed while generating, showing the PDF safely
|
|
310
|
+
* falls back to a file download and keeps the current application page in place.
|
|
311
|
+
*/
|
|
312
|
+
const preparePdfPreview = (options) => {
|
|
313
|
+
const dependencies = options.dependencies ?? defaultDependencies();
|
|
314
|
+
let target = null;
|
|
315
|
+
try {
|
|
316
|
+
target = dependencies.document.defaultView?.open('', '_blank') ?? null;
|
|
317
|
+
if (target) {
|
|
318
|
+
target.opener = null;
|
|
319
|
+
target.document.title = options.title;
|
|
320
|
+
target.document.body.textContent = options.pendingText;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
closeWindow(target);
|
|
325
|
+
target = null;
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
show: (pdfBytes) => {
|
|
329
|
+
if (!target || isWindowClosed(target)) {
|
|
330
|
+
kitDownloadPdf(pdfBytes, {
|
|
331
|
+
filename: options.fallbackFilename,
|
|
332
|
+
cleanupDelayMs: options.cleanupDelayMs,
|
|
333
|
+
dependencies,
|
|
334
|
+
});
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const pdfUrl = createPdfUrl(pdfBytes, dependencies);
|
|
338
|
+
const cleanup = createCleanup(pdfUrl, dependencies);
|
|
339
|
+
const cleanupScheduled = scheduleCleanup(cleanup, cleanupDelay(options.cleanupDelayMs), dependencies);
|
|
340
|
+
try {
|
|
341
|
+
target.location.replace(pdfUrl);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
cleanup();
|
|
345
|
+
closeWindow(target);
|
|
346
|
+
kitDownloadPdf(pdfBytes, {
|
|
347
|
+
filename: options.fallbackFilename,
|
|
348
|
+
cleanupDelayMs: options.cleanupDelayMs,
|
|
349
|
+
dependencies,
|
|
350
|
+
});
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
if (!cleanupScheduled)
|
|
355
|
+
cleanup();
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
close: () => closeWindow(target),
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Preview an asynchronously generated PDF without risking a popup-blocked result.
|
|
363
|
+
*
|
|
364
|
+
* This function opens its placeholder window synchronously, before invoking `buildPdf`. Call it
|
|
365
|
+
* directly from the user's click handler and pass PDF generation as the callback. Generation errors
|
|
366
|
+
* close the placeholder and are rethrown for the application to present with its own UI.
|
|
367
|
+
*/
|
|
368
|
+
const kitPreviewGeneratedPdf = async (buildPdf, options) => {
|
|
369
|
+
const preview = preparePdfPreview(options);
|
|
370
|
+
try {
|
|
371
|
+
preview.show(await buildPdf());
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
preview.close();
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
207
379
|
// Printer: Brother label plumbing (DOM→PNG, rotation, print-settings assembly).
|
|
208
380
|
// Split into its own entry point so only apps that print pull in `@rdlabo/capacitor-brotherprint`
|
|
209
381
|
// and `dom-to-image-more`; the core entry stays free of those native peers.
|
|
@@ -212,5 +384,5 @@ const kitBuildLabelPdf = async (params) => {
|
|
|
212
384
|
* Generated bundle index. Do not edit.
|
|
213
385
|
*/
|
|
214
386
|
|
|
215
|
-
export { kitBuildBrotherPrintSettings, kitBuildLabelPdf, kitCalculatePrintLayout, kitDomToPng, kitPrintPaperSizes, kitRotationImage };
|
|
387
|
+
export { kitBuildBrotherPrintSettings, kitBuildLabelPdf, kitCalculatePrintLayout, kitDomToPng, kitDownloadPdf, kitPreviewGeneratedPdf, kitPrintPaperSizes, kitRotationImage };
|
|
216
388
|
//# 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/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,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AM,CAAC,WAAW;AAC3B,SAAA,CAAC;IACJ;AAEA,IAAA,OAAO,GAAG,CAAC,IAAI,EAAE;AACnB;;AC5HA;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/kit-browser-pdf.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","/** Browser dependencies used by the PDF output helpers. */\nexport interface KitBrowserPdfDependencies {\n /** Document used to create download links and preview windows. */\n readonly document: Pick<Document, 'body' | 'createElement' | 'defaultView'>;\n /** Object URL implementation used for generated PDF blobs. */\n readonly url: Pick<typeof URL, 'createObjectURL' | 'revokeObjectURL'>;\n /** Scheduler used to delay DOM and object URL cleanup. */\n readonly schedule: (callback: () => void, delay: number) => unknown;\n}\n\n/** Options shared by browser PDF output helpers. */\nexport interface KitBrowserPdfOutputOptions {\n /** Delay before temporary resources are released. Invalid values fall back to 60 seconds. */\n readonly cleanupDelayMs?: number;\n /** Browser dependencies. Override in tests; production callers normally omit this. */\n readonly dependencies?: KitBrowserPdfDependencies;\n}\n\n/** Options for {@link kitDownloadPdf}. */\nexport interface KitDownloadPdfOptions extends KitBrowserPdfOutputOptions {\n /** Filename presented by the browser download. */\n readonly filename: string;\n}\n\n/** Options for {@link kitPreviewGeneratedPdf}. */\nexport interface KitPreviewGeneratedPdfOptions extends KitBrowserPdfOutputOptions {\n /** Title shown while the PDF is being generated. */\n readonly title: string;\n /** Text shown while the PDF is being generated. */\n readonly pendingText: string;\n /** Filename used when a preview window cannot be opened or has been closed. */\n readonly fallbackFilename: string;\n}\n\ninterface PdfPreview {\n readonly show: (pdfBytes: Uint8Array) => void;\n readonly close: () => void;\n}\n\nconst defaultDependencies = (): KitBrowserPdfDependencies => ({\n document,\n url: URL,\n schedule: (callback, delay) => globalThis.setTimeout(callback, delay),\n});\n\nconst createPdfUrl = (pdfBytes: Uint8Array, dependencies: KitBrowserPdfDependencies): string =>\n dependencies.url.createObjectURL(\n new Blob([Uint8Array.from(pdfBytes).buffer], {\n type: 'application/pdf',\n }),\n );\n\nconst cleanupDelay = (value: number | undefined): number => (value !== undefined && Number.isFinite(value) && value >= 0 ? value : 60_000);\n\nconst createCleanup = (pdfUrl: string, dependencies: KitBrowserPdfDependencies, link?: HTMLAnchorElement): (() => void) => {\n let cleaned = false;\n return (): void => {\n if (cleaned) return;\n cleaned = true;\n try {\n link?.remove();\n } catch {\n // Cleanup is best-effort and must not turn successful PDF output into a failure.\n } finally {\n try {\n dependencies.url.revokeObjectURL(pdfUrl);\n } catch {\n // Object URL cleanup is best-effort for the same reason.\n }\n }\n };\n};\n\nconst scheduleCleanup = (cleanup: () => void, delay: number, dependencies: KitBrowserPdfDependencies): boolean => {\n try {\n dependencies.schedule(cleanup, delay);\n return true;\n } catch {\n try {\n globalThis.setTimeout(cleanup, delay);\n return true;\n } catch {\n return false;\n }\n }\n};\n\nconst isWindowClosed = (target: Window): boolean => {\n try {\n return target.closed;\n } catch {\n return true;\n }\n};\n\nconst closeWindow = (target: Window | null): void => {\n try {\n if (target && !target.closed) target.close();\n } catch {\n // Closing a placeholder is best-effort and must never replace the original output error.\n }\n};\n\n/**\n * Download generated PDF bytes without navigating the current application page.\n *\n * @remarks Browser-only. Do not call during server-side rendering.\n *\n * The temporary anchor and object URL stay alive long enough for browsers to start the download.\n * Cleanup is registered before clicking so a cleanup scheduling error cannot be mistaken for a PDF\n * generation failure after the download has already started.\n */\nexport const kitDownloadPdf = (pdfBytes: Uint8Array, options: KitDownloadPdfOptions): void => {\n const dependencies = options.dependencies ?? defaultDependencies();\n const pdfUrl = createPdfUrl(pdfBytes, dependencies);\n let link: HTMLAnchorElement | undefined;\n let cleanup = createCleanup(pdfUrl, dependencies);\n let cleanupScheduled = false;\n\n try {\n link = dependencies.document.createElement('a');\n cleanup = createCleanup(pdfUrl, dependencies, link);\n link.href = pdfUrl;\n link.download = options.filename;\n link.style.display = 'none';\n dependencies.document.body.appendChild(link);\n cleanupScheduled = scheduleCleanup(cleanup, cleanupDelay(options.cleanupDelayMs), dependencies);\n\n // Keep this as the final synchronous output operation: the browser may start immediately.\n link.click();\n } catch (error) {\n cleanup();\n throw error;\n } finally {\n if (!cleanupScheduled) cleanup();\n }\n};\n\n/**\n * Open a placeholder window synchronously for an asynchronously generated PDF.\n *\n * Call this directly from the user's click handler, before awaiting PDF generation, to avoid popup\n * blocking. If the preview cannot be opened or is closed while generating, showing the PDF safely\n * falls back to a file download and keeps the current application page in place.\n */\nconst preparePdfPreview = (options: KitPreviewGeneratedPdfOptions): PdfPreview => {\n const dependencies = options.dependencies ?? defaultDependencies();\n let target: Window | null = null;\n\n try {\n target = dependencies.document.defaultView?.open('', '_blank') ?? null;\n if (target) {\n target.opener = null;\n target.document.title = options.title;\n target.document.body.textContent = options.pendingText;\n }\n } catch {\n closeWindow(target);\n target = null;\n }\n\n return {\n show: (pdfBytes): void => {\n if (!target || isWindowClosed(target)) {\n kitDownloadPdf(pdfBytes, {\n filename: options.fallbackFilename,\n cleanupDelayMs: options.cleanupDelayMs,\n dependencies,\n });\n return;\n }\n\n const pdfUrl = createPdfUrl(pdfBytes, dependencies);\n const cleanup = createCleanup(pdfUrl, dependencies);\n const cleanupScheduled = scheduleCleanup(cleanup, cleanupDelay(options.cleanupDelayMs), dependencies);\n try {\n target.location.replace(pdfUrl);\n } catch {\n cleanup();\n closeWindow(target);\n kitDownloadPdf(pdfBytes, {\n filename: options.fallbackFilename,\n cleanupDelayMs: options.cleanupDelayMs,\n dependencies,\n });\n return;\n } finally {\n if (!cleanupScheduled) cleanup();\n }\n },\n close: (): void => closeWindow(target),\n };\n};\n\n/**\n * Preview an asynchronously generated PDF without risking a popup-blocked result.\n *\n * This function opens its placeholder window synchronously, before invoking `buildPdf`. Call it\n * directly from the user's click handler and pass PDF generation as the callback. Generation errors\n * close the placeholder and are rethrown for the application to present with its own UI.\n */\nexport const kitPreviewGeneratedPdf = async (\n buildPdf: () => Promise<Uint8Array>,\n options: KitPreviewGeneratedPdfOptions,\n): Promise<void> => {\n const preview = preparePdfPreview(options);\n try {\n preview.show(await buildPdf());\n } catch (error) {\n preview.close();\n throw error;\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';\nexport * from './kit-pdf-printer';\nexport * from './kit-browser-pdf';\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,GA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tC,YAAY;AACb,iBAAA,CAAC;gBACF;YACF;oBAAU;AACR,gBAAA,IAAI,CAAC,gBAAgB;AAAE,oBAAA,OAAO,EAAE;YAClC;QACF,CAAC;AACD,QAAA,KAAK,EAAE,MAAY,WAAW,CAAC,MAAM,CAAC;KACvC;AACH,CAAC;AAED;;;;;;AAMG;AACI,MAAM,sBAAsB,GAAG,OACpC,QAAmC,EACnC,OAAsC,KACrB;AACjB,IAAA,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC;AAC1C,IAAA,IAAI;AACF,QAAA,OAAO,CAAC,IAAI,CAAC,MAAM,QAAQ,EAAE,CAAC;IAChC;IAAE,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,EAAE;AACf,QAAA,MAAM,KAAK;IACb;AACF;;ACpNA;AACA;AACA;;ACFA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -330,6 +330,14 @@ declare function commandIdentityMatchesReplicaRow(schema: OfflineReplicaEntitySc
|
|
|
330
330
|
/** Remote identity used by pull reconciliation and uniqueness checks. */
|
|
331
331
|
declare function offlineReplicaRemoteIdentity(schema: OfflineReplicaEntitySchema<Record<string, unknown>>, identity: OfflineReplicaIdentity): OfflineReplicaRemoteIdentity | null;
|
|
332
332
|
|
|
333
|
+
/**
|
|
334
|
+
* Internal repository capability used to detect commits made through another
|
|
335
|
+
* native SQLite connection during a local read/derive/write operation.
|
|
336
|
+
*
|
|
337
|
+
* This symbol is intentionally not re-exported from the package entry point.
|
|
338
|
+
*/
|
|
339
|
+
declare const OFFLINE_REPOSITORY_ATOMIC_MUTATION: unique symbol;
|
|
340
|
+
|
|
333
341
|
/** Current durable storage schema used by both web and native repositories. */
|
|
334
342
|
declare const OFFLINE_SCHEMA_VERSION = 2;
|
|
335
343
|
/** User and partition scope of all local offline data. */
|
|
@@ -431,10 +439,6 @@ interface OfflineReplicaTransaction {
|
|
|
431
439
|
putCommands?: readonly OfflineCommand[];
|
|
432
440
|
removeCommandIds?: readonly string[];
|
|
433
441
|
putCursors?: readonly OfflineReplicaCursor[];
|
|
434
|
-
/** Scopes whose acknowledged server changes still require an authoritative pull. */
|
|
435
|
-
putReconciliationScopes?: readonly OfflineScope[];
|
|
436
|
-
/** Scopes whose authoritative post-acknowledgement pull completed successfully. */
|
|
437
|
-
removeReconciliationScopes?: readonly OfflineScope[];
|
|
438
442
|
/** Durable fatal-pull attentions to upsert for user+scope. */
|
|
439
443
|
putPullAttentions?: readonly OfflinePullAttention[];
|
|
440
444
|
/** Scopes whose fatal-pull attentions should be removed after a successful pull. */
|
|
@@ -455,7 +459,6 @@ interface OfflineRepositoryReader {
|
|
|
455
459
|
getReplicaRowByRemoteId<TValues = unknown>(scope: OfflineScope, sourceKey: string, remoteId: OfflineGeneratedRemoteId): Promise<OfflineReplicaRow<TValues> | null>;
|
|
456
460
|
getReplicaRowByRemoteIdentity<TValues = unknown>(scope: OfflineScope, sourceKey: string, identity: OfflineReplicaRemoteIdentity): Promise<OfflineReplicaRow<TValues> | null>;
|
|
457
461
|
getReplicaCursor(scope: OfflineScope): Promise<OfflineReplicaCursor | null>;
|
|
458
|
-
getReconciliationScopes?(userId: OfflinePrincipalId): Promise<OfflineScope[]>;
|
|
459
462
|
getPullAttentions?(userId: OfflinePrincipalId): Promise<OfflinePullAttention[]>;
|
|
460
463
|
getCommands(scope: OfflineScope): Promise<OfflineCommand[]>;
|
|
461
464
|
getCommandsForUser?(userId: OfflinePrincipalId): Promise<OfflineCommand[]>;
|
|
@@ -474,7 +477,6 @@ interface OfflineRepository {
|
|
|
474
477
|
getReplicaRowByRemoteId<TValues = unknown>(scope: OfflineScope, sourceKey: string, remoteId: OfflineGeneratedRemoteId): Promise<OfflineReplicaRow<TValues> | null>;
|
|
475
478
|
getReplicaRowByRemoteIdentity<TValues = unknown>(scope: OfflineScope, sourceKey: string, identity: OfflineReplicaRemoteIdentity): Promise<OfflineReplicaRow<TValues> | null>;
|
|
476
479
|
getReplicaCursor(scope: OfflineScope): Promise<OfflineReplicaCursor | null>;
|
|
477
|
-
getReconciliationScopes?(userId: OfflinePrincipalId): Promise<OfflineScope[]>;
|
|
478
480
|
/** Durable fatal-pull attentions for the principal, ordered by scope id. */
|
|
479
481
|
getPullAttentions?(userId: OfflinePrincipalId): Promise<OfflinePullAttention[]>;
|
|
480
482
|
getCommands(scope: OfflineScope): Promise<OfflineCommand[]>;
|
|
@@ -499,6 +501,8 @@ interface OfflineRepository {
|
|
|
499
501
|
* must not be called from `read`.
|
|
500
502
|
*/
|
|
501
503
|
runReadSnapshot<T>(read: (reader: OfflineRepositoryReader) => Promise<T>): Promise<T>;
|
|
504
|
+
/** @internal Runs one optimistic read/derive/write operation with platform-specific concurrency validation. */
|
|
505
|
+
[OFFLINE_REPOSITORY_ATOMIC_MUTATION]?<T>(operation: (repository: OfflineRepository) => Promise<T>): Promise<T>;
|
|
502
506
|
}
|
|
503
507
|
/** DI token for the selected platform repository. */
|
|
504
508
|
declare const OFFLINE_REPOSITORY: InjectionToken<OfflineRepository>;
|
|
@@ -520,7 +524,6 @@ declare class IonicOfflineRepository implements OfflineRepository {
|
|
|
520
524
|
getReplicaRowByRemoteId<TValues = unknown>(scope: OfflineScope, sourceKey: string, remoteId: OfflineGeneratedRemoteId): Promise<OfflineReplicaRow<TValues> | null>;
|
|
521
525
|
getReplicaRowByRemoteIdentity<TValues = unknown>(scope: OfflineScope, sourceKey: string, identity: OfflineReplicaRemoteIdentity): Promise<OfflineReplicaRow<TValues> | null>;
|
|
522
526
|
getReplicaCursor(scope: OfflineScope): Promise<OfflineReplicaCursor | null>;
|
|
523
|
-
getReconciliationScopes(userId: OfflinePrincipalId): Promise<OfflineScope[]>;
|
|
524
527
|
getPullAttentions(userId: OfflinePrincipalId): Promise<OfflinePullAttention[]>;
|
|
525
528
|
getCommands(scope: OfflineScope): Promise<OfflineCommand[]>;
|
|
526
529
|
getCommandsForUser(userId: OfflinePrincipalId): Promise<OfflineCommand[]>;
|
|
@@ -738,7 +741,7 @@ declare class OfflineReplicaPullService {
|
|
|
738
741
|
declare class OfflineReplicaMutationCoordinator {
|
|
739
742
|
#private;
|
|
740
743
|
/** Enqueues one local replica critical section behind any in-flight mutation. */
|
|
741
|
-
run<T>(operation: () => Promise<T>): Promise<T>;
|
|
744
|
+
run<T>(operation: (repository: OfflineRepository) => Promise<T>): Promise<T>;
|
|
742
745
|
/** Resolves after every currently queued replica mutation has settled. */
|
|
743
746
|
drain(): Promise<void>;
|
|
744
747
|
/**
|
|
@@ -1326,11 +1329,11 @@ declare class SqliteOfflineRepository implements OfflineRepository {
|
|
|
1326
1329
|
getReplicaRowByRemoteId<TValues = unknown>(scope: OfflineScope, sourceKey: string, remoteId: OfflineGeneratedRemoteId): Promise<OfflineReplicaRow<TValues> | null>;
|
|
1327
1330
|
getReplicaRowByRemoteIdentity<TValues = unknown>(scope: OfflineScope, sourceKey: string, identity: OfflineReplicaRemoteIdentity): Promise<OfflineReplicaRow<TValues> | null>;
|
|
1328
1331
|
getReplicaCursor(scope: OfflineScope): Promise<OfflineReplicaCursor | null>;
|
|
1329
|
-
getReconciliationScopes(userId: OfflinePrincipalId): Promise<OfflineScope[]>;
|
|
1330
1332
|
getPullAttentions(userId: OfflinePrincipalId): Promise<OfflinePullAttention[]>;
|
|
1331
1333
|
getCommands(scope: OfflineScope): Promise<OfflineCommand[]>;
|
|
1332
1334
|
getCommandsForUser(userId: OfflinePrincipalId): Promise<OfflineCommand[]>;
|
|
1333
1335
|
runReadSnapshot<T>(read: (reader: OfflineRepositoryReader) => Promise<T>): Promise<T>;
|
|
1336
|
+
[OFFLINE_REPOSITORY_ATOMIC_MUTATION]<T>(operation: (repository: OfflineRepository) => Promise<T>): Promise<T>;
|
|
1334
1337
|
putCommand(command: OfflineCommand): Promise<void>;
|
|
1335
1338
|
replaceCommand(command: OfflineCommand): Promise<void>;
|
|
1336
1339
|
removeCommand(commandId: string): Promise<void>;
|
|
@@ -143,5 +143,54 @@ interface KitBuildLabelPdfParams extends KitCalculatePrintLayoutParams {
|
|
|
143
143
|
/** Build a multi-page label PDF and return its bytes without choosing an output destination. */
|
|
144
144
|
declare const kitBuildLabelPdf: (params: KitBuildLabelPdfParams) => Promise<Uint8Array>;
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
/** Browser dependencies used by the PDF output helpers. */
|
|
147
|
+
interface KitBrowserPdfDependencies {
|
|
148
|
+
/** Document used to create download links and preview windows. */
|
|
149
|
+
readonly document: Pick<Document, 'body' | 'createElement' | 'defaultView'>;
|
|
150
|
+
/** Object URL implementation used for generated PDF blobs. */
|
|
151
|
+
readonly url: Pick<typeof URL, 'createObjectURL' | 'revokeObjectURL'>;
|
|
152
|
+
/** Scheduler used to delay DOM and object URL cleanup. */
|
|
153
|
+
readonly schedule: (callback: () => void, delay: number) => unknown;
|
|
154
|
+
}
|
|
155
|
+
/** Options shared by browser PDF output helpers. */
|
|
156
|
+
interface KitBrowserPdfOutputOptions {
|
|
157
|
+
/** Delay before temporary resources are released. Invalid values fall back to 60 seconds. */
|
|
158
|
+
readonly cleanupDelayMs?: number;
|
|
159
|
+
/** Browser dependencies. Override in tests; production callers normally omit this. */
|
|
160
|
+
readonly dependencies?: KitBrowserPdfDependencies;
|
|
161
|
+
}
|
|
162
|
+
/** Options for {@link kitDownloadPdf}. */
|
|
163
|
+
interface KitDownloadPdfOptions extends KitBrowserPdfOutputOptions {
|
|
164
|
+
/** Filename presented by the browser download. */
|
|
165
|
+
readonly filename: string;
|
|
166
|
+
}
|
|
167
|
+
/** Options for {@link kitPreviewGeneratedPdf}. */
|
|
168
|
+
interface KitPreviewGeneratedPdfOptions extends KitBrowserPdfOutputOptions {
|
|
169
|
+
/** Title shown while the PDF is being generated. */
|
|
170
|
+
readonly title: string;
|
|
171
|
+
/** Text shown while the PDF is being generated. */
|
|
172
|
+
readonly pendingText: string;
|
|
173
|
+
/** Filename used when a preview window cannot be opened or has been closed. */
|
|
174
|
+
readonly fallbackFilename: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Download generated PDF bytes without navigating the current application page.
|
|
178
|
+
*
|
|
179
|
+
* @remarks Browser-only. Do not call during server-side rendering.
|
|
180
|
+
*
|
|
181
|
+
* The temporary anchor and object URL stay alive long enough for browsers to start the download.
|
|
182
|
+
* Cleanup is registered before clicking so a cleanup scheduling error cannot be mistaken for a PDF
|
|
183
|
+
* generation failure after the download has already started.
|
|
184
|
+
*/
|
|
185
|
+
declare const kitDownloadPdf: (pdfBytes: Uint8Array, options: KitDownloadPdfOptions) => void;
|
|
186
|
+
/**
|
|
187
|
+
* Preview an asynchronously generated PDF without risking a popup-blocked result.
|
|
188
|
+
*
|
|
189
|
+
* This function opens its placeholder window synchronously, before invoking `buildPdf`. Call it
|
|
190
|
+
* directly from the user's click handler and pass PDF generation as the callback. Generation errors
|
|
191
|
+
* close the placeholder and are rethrown for the application to present with its own UI.
|
|
192
|
+
*/
|
|
193
|
+
declare const kitPreviewGeneratedPdf: (buildPdf: () => Promise<Uint8Array>, options: KitPreviewGeneratedPdfOptions) => Promise<void>;
|
|
194
|
+
|
|
195
|
+
export { kitBuildBrotherPrintSettings, kitBuildLabelPdf, kitCalculatePrintLayout, kitDomToPng, kitDownloadPdf, kitPreviewGeneratedPdf, kitPrintPaperSizes, kitRotationImage };
|
|
196
|
+
export type { KitBrotherPrintSettingsParams, KitBrowserPdfDependencies, KitBrowserPdfOutputOptions, KitBuildLabelPdfParams, KitCalculatePrintLayoutParams, KitDomToPngOptions, KitDownloadPdfOptions, KitPreviewGeneratedPdfOptions, KitPrintLayout, KitPrintMeasure, KitPrintPaper, KitPrintPosition };
|