@aglyn/plugins-commerce 1.12.0 → 1.13.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.
Files changed (79) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/console/catalog-organization-card.component.js +1 -1
  3. package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
  4. package/src/lib/components/console/host-quotes-card.component.js +3 -2
  5. package/src/lib/components/console/host-quotes-card.component.js.map +1 -1
  6. package/src/lib/components/console/order-detail-dialog.component.js +1 -1
  7. package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
  8. package/src/lib/components/console/pay-link-readiness-notice.component.d.ts +1 -1
  9. package/src/lib/components/console/pay-link-readiness-notice.component.js.map +1 -1
  10. package/src/lib/components/console/pos-devices-card.component.js +2 -2
  11. package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
  12. package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +1 -1
  13. package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
  14. package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js +1 -1
  15. package/src/lib/components/console/pos-ops/pos-day-totals-card.component.js.map +1 -1
  16. package/src/lib/components/console/pos-reader-splash-setting.component.js +1 -1
  17. package/src/lib/components/console/pos-reader-splash-setting.component.js.map +1 -1
  18. package/src/lib/components/console/quote-editor-dialog.component.d.ts +5 -0
  19. package/src/lib/components/console/quote-editor-dialog.component.js +104 -16
  20. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  21. package/src/lib/components/console/quote-pay-link.component.d.ts +4 -1
  22. package/src/lib/components/console/quote-pay-link.component.js +23 -12
  23. package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
  24. package/src/lib/components/console/quote-proofs.component.d.ts +3 -2
  25. package/src/lib/components/console/quote-proofs.component.js +73 -5
  26. package/src/lib/components/console/quote-proofs.component.js.map +1 -1
  27. package/src/lib/components/console/quote-send.component.js +9 -6
  28. package/src/lib/components/console/quote-send.component.js.map +1 -1
  29. package/src/lib/components/console/site-member-purchases.component.js +1 -1
  30. package/src/lib/components/console/site-member-purchases.component.js.map +1 -1
  31. package/src/lib/components/quote-page-body.js +14 -8
  32. package/src/lib/components/quote-page-body.js.map +1 -1
  33. package/src/lib/model/commerce-invoices.d.ts +1 -1
  34. package/src/lib/model/commerce-invoices.js +4 -1
  35. package/src/lib/model/commerce-invoices.js.map +1 -1
  36. package/src/lib/model/commerce-quote-email.d.ts +7 -6
  37. package/src/lib/model/commerce-quote-email.js +11 -6
  38. package/src/lib/model/commerce-quote-email.js.map +1 -1
  39. package/src/lib/model/commerce-quote-pay.d.ts +6 -1
  40. package/src/lib/model/commerce-quote-pay.js +18 -8
  41. package/src/lib/model/commerce-quote-pay.js.map +1 -1
  42. package/src/lib/model/commerce-quote-proofs.d.ts +28 -1
  43. package/src/lib/model/commerce-quote-proofs.js +58 -2
  44. package/src/lib/model/commerce-quote-proofs.js.map +1 -1
  45. package/src/lib/model/commerce-quotes.d.ts +22 -1
  46. package/src/lib/model/commerce-quotes.js +25 -5
  47. package/src/lib/model/commerce-quotes.js.map +1 -1
  48. package/src/lib/model/plugin-permissions.d.ts +1 -1
  49. package/src/lib/model/plugin-permissions.js +10 -0
  50. package/src/lib/model/plugin-permissions.js.map +1 -1
  51. package/src/lib/server/commerce-pdf.d.ts +1 -1
  52. package/src/lib/server/commerce-pdf.js +1 -1
  53. package/src/lib/server/commerce-pdf.js.map +1 -1
  54. package/src/lib/server/paid-media-delivery.js +1 -1
  55. package/src/lib/server/paid-media-delivery.js.map +1 -1
  56. package/src/lib/server/quote-email.js +29 -25
  57. package/src/lib/server/quote-email.js.map +1 -1
  58. package/src/lib/server/quote-pay.js +6 -2
  59. package/src/lib/server/quote-pay.js.map +1 -1
  60. package/src/lib/server/quote-proof-media.d.ts +63 -0
  61. package/src/lib/server/quote-proof-media.js +96 -0
  62. package/src/lib/server/quote-proof-media.js.map +1 -0
  63. package/src/lib/server/quote-proofs.js +9 -5
  64. package/src/lib/server/quote-proofs.js.map +1 -1
  65. package/src/lib/server/quote-uploads.d.ts +3 -1
  66. package/src/lib/server/quote-uploads.js +2 -1
  67. package/src/lib/server/quote-uploads.js.map +1 -1
  68. package/src/lib/server/quote.d.ts +3 -0
  69. package/src/lib/server/quote.js +127 -20
  70. package/src/lib/server/quote.js.map +1 -1
  71. package/src/lib/tenant-emails.js +16 -9
  72. package/src/lib/tenant-emails.js.map +1 -1
  73. package/src/lib/transfer/gift-cards.server.js +9 -11
  74. package/src/lib/transfer/gift-cards.server.js.map +1 -1
  75. package/src/lib/utils/commerce-document-pdf.js +12 -9
  76. package/src/lib/utils/commerce-document-pdf.js.map +1 -1
  77. package/src/lib/utils/quote-email-content.d.ts +2 -0
  78. package/src/lib/utils/quote-email-content.js +20 -10
  79. package/src/lib/utils/quote-email-content.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/utils/commerce-document-pdf.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { buildEmailPalette, emailAccent, resolveEmailColor, type EmailPalette } from '@aglyn/shared-util-email'\nimport { relativeLuminanceOfRgb, rgbChannelsOfHex } from '@aglyn/shared-util-tools/contrast'\nimport type { PdfJpegImage } from '@aglyn/shared-util-tools/pdf/pdf-file'\nimport { PdfWriter, pdfRgbFromHex, type PdfRgb, type PdfTableCell } from '@aglyn/shared-util-tools/pdf/pdf-writer'\nimport type { QuotePageAddress, QuotePageView } from '../model/commerce-quote-pay'\nimport { buildOrderInvoiceData, invoiceAddressLines, invoiceMoney, type InvoiceOrder, type OrderInvoiceStore } from './order-invoice'\n\n/*==========================================\n * A QUOTE AND AN INVOICE AS BRANDED PDFs (AGL-4095).\n *\n * renderQuotePdf({ brand, view, revision, payUrl }) → Uint8Array\n * renderOrderInvoicePdf({ brand, order, orderId, store }) → Uint8Array\n *\n * Both are one layout: the business's logo, name and contact at the top left\n * under a band of the site's primary color, the document's name, number,\n * date and standing at the top right, who it is billed and shipped to, the\n * lines in a table whose header wears the primary color, the totals, then\n * notes, terms and (for a quote still to be paid) the pay link as a button\n * and as text, both clickable. Every page ends with the document's name and\n * its page number.\n *\n * Pure over its input: the server reads the site, its theme and its logo\n * (`server/commerce-pdf-brand.ts`) and the quote or order, and these turn\n * them into bytes, so the console's download, the customer's download and\n * the emails that attach a quote or an invoice all make the same file.\n *\n * A quote is drawn from `buildQuotePageView`, the customer-safe projection\n * the quote page shows, so the PDF never says more than the page does. An\n * invoice is drawn from `buildOrderInvoiceData`, the content the printed\n * invoice shows.\n *=========================================*/\n\n/** The colors a document is drawn in, as `#rrggbb`. */\nexport interface CommercePdfColors {\n /** The band, the table's header and the pay button: the site's primary color. */\n accent: string\n /** Text set on the accent. */\n onAccent: string\n /** The accent as text on white: the document's name, links. */\n accentText: string\n /** A wash of the accent, behind the total. */\n tint: string\n ink: string\n muted: string\n rule: string\n}\n\n/** Who the document is from. */\nexport interface CommercePdfBrand {\n businessName: string\n /** Address lines, email, phone and web address, in that order. */\n contactLines: readonly string[]\n /** The site's logo as a JPEG; the business name stands alone without one. */\n logo?: PdfJpegImage | null\n /** The site theme's colors; any left out are the neutral ones. */\n colors?: Partial<CommercePdfColors> | null\n /** The site's time zone, which dates are given in. */\n timeZone?: string | null\n}\n\nconst NEUTRAL_PALETTE = buildEmailPalette({ base: 'tenant' })\nconst neutral = (path: string) => resolveEmailColor(path, NEUTRAL_PALETTE) ?? ''\n\n/** The colors a document wears where its site's theme gives none: the default site theme's greys. */\nexport const COMMERCE_PDF_NEUTRAL_COLORS: Readonly<CommercePdfColors> = Object.freeze({\n accent: neutral('grey.800'),\n onAccent: neutral('background.paper'),\n accentText: neutral('grey.800'),\n tint: neutral('grey.100'),\n ink: neutral('text.primary'),\n muted: neutral('text.secondary'),\n rule: neutral('divider'),\n})\n\n/** WCAG contrast between two `#rrggbb` colors; 1 when either cannot be read. */\nfunction contrast(one: string, other: string): number {\n const a = rgbChannelsOfHex(one)\n const b = rgbChannelsOfHex(other)\n if (!a || !b) return 1\n const la = relativeLuminanceOfRgb(...a)\n const lb = relativeLuminanceOfRgb(...b)\n return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05)\n}\n\n/**\n * A document's colors from a site's resolved palette: the primary color for\n * the accent, the theme's own text and divider colors, and text on the\n * accent that reads at 4.5:1 (the theme's contrast text when it does, else\n * the theme's dark ink or white, whichever reads better).\n */\nexport function commercePdfColorsFromPalette(palette: EmailPalette): CommercePdfColors {\n const accent = emailAccent(palette)\n const read = (path: string, fallback: string) => resolveEmailColor(path, palette) ?? fallback\n const ink = read('text.primary', COMMERCE_PDF_NEUTRAL_COLORS.ink)\n const paper = read('background.paper', COMMERCE_PDF_NEUTRAL_COLORS.onAccent)\n const onAccent =\n contrast(accent.label, accent.fill) >= 4.5\n ? accent.label\n : contrast(ink, accent.fill) >= contrast(paper, accent.fill)\n ? ink\n : paper\n return {\n accent: accent.fill,\n onAccent,\n accentText: contrast(accent.link, paper) >= 4.5 ? accent.link : ink,\n tint: read('tint.primary', COMMERCE_PDF_NEUTRAL_COLORS.tint),\n ink,\n muted: read('text.secondary', COMMERCE_PDF_NEUTRAL_COLORS.muted),\n rule: read('divider', COMMERCE_PDF_NEUTRAL_COLORS.rule),\n }\n}\n\n/*==========================================\n * WHAT A DOCUMENT SAYS\n *=========================================*/\n\ninterface DocumentLine {\n name: string\n details: string[]\n quantity: number\n unit: string\n amount: string\n}\n\ninterface SummaryRow {\n label: string\n value: string\n emphasis?: boolean\n /** A note in place of a figure, such as \"Tax is added at payment\". */\n note?: boolean\n}\n\ninterface CommerceDocument {\n /** QUOTE or INVOICE, across the top. */\n kind: string\n /** `Quote #1042`. */\n title: string\n facts: Array<[string, string]>\n /** A short standing, set in a pill under the facts: `Paid October 30, 2026`. */\n stamp: string | null\n parties: Array<{ label: string; lines: string[] }>\n lines: DocumentLine[]\n summary: SummaryRow[]\n sections: Array<{ heading: string; text: string; link?: string }>\n pay: { url: string; label: string; intro: string } | null\n}\n\n/** A date the American way, in the site's time zone: `October 28, 2026`. */\nexport function formatPdfDate(ms: number | null | undefined, timeZone?: string | null): string {\n if (!ms || !Number.isFinite(ms)) return ''\n const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'long', day: 'numeric' }\n try {\n return new Intl.DateTimeFormat('en-US', { ...options, ...(timeZone ? { timeZone } : {}) }).format(new Date(ms))\n } catch {\n return new Intl.DateTimeFormat('en-US', { ...options, timeZone: 'UTC' }).format(new Date(ms))\n }\n}\n\nconst minus = (text: string) => `-${text}`\n\n/*==========================================\n * THE QUOTE\n *=========================================*/\n\nexport interface QuotePdfInput {\n brand: CommercePdfBrand\n /** The quote as its customer may see it: `buildQuotePageView`. */\n view: QuotePageView\n /** The quote's revision, printed beside its date. */\n revision?: number | null\n /** The pay link, printed on a quote still to be paid; left off when the reader may not have it. */\n payUrl?: string | null\n}\n\nfunction quoteAddressLines(address: QuotePageAddress | null): string[] {\n return invoiceAddressLines(address as never, { phone: false })\n}\n\nfunction quoteDocument(input: QuotePdfInput): CommerceDocument {\n const { view, brand } = input\n const money = (cents: number) => invoiceMoney(cents, view.currency)\n const date = (ms: number | null) => formatPdfDate(ms, brand.timeZone)\n const customer = [view.customerName ?? '', view.company ?? ''].filter(Boolean)\n const billTo = quoteAddressLines(view.billTo)\n const parties: CommerceDocument['parties'] = []\n if (billTo.length) {\n // The bill-to's own name leads; the customer's name and company are added when it does not carry them.\n const named = customer.filter((part) => !billTo.includes(part))\n parties.push({ label: 'Bill to', lines: [...named, ...billTo] })\n } else if (customer.length) {\n parties.push({ label: 'Prepared for', lines: customer })\n }\n const shipTo = quoteAddressLines(view.shipTo)\n if (shipTo.length) parties.push({ label: 'Ship to', lines: shipTo })\n\n const summary: SummaryRow[] = [{ label: 'Subtotal', value: money(view.totals.itemsCents) }]\n if (view.totals.discountCents > 0) {\n summary.push({\n label: view.discountLabel ? `Discount (${view.discountLabel})` : 'Discount',\n value: minus(money(view.totals.discountCents)),\n })\n }\n if (view.totals.shippingCents > 0) summary.push({ label: 'Shipping', value: money(view.totals.shippingCents) })\n if (view.taxAtPayment) summary.push({ label: 'Tax is added at payment', value: '', note: true })\n else if (view.totals.taxCents > 0) summary.push({ label: view.taxLabel || 'Tax', value: money(view.totals.taxCents) })\n else if (view.taxLabel && view.taxLabel !== 'Tax') summary.push({ label: view.taxLabel, value: '', note: true })\n summary.push({ label: view.taxAtPayment ? 'Total before tax' : 'Total', value: money(view.totals.totalCents), emphasis: true })\n\n const stamp =\n view.status === 'paid'\n ? `Paid${view.paidAtMs ? ` ${date(view.paidAtMs)}` : ''}`\n : view.status === 'canceled'\n ? 'Canceled'\n : view.status === 'refunded'\n ? 'Refunded'\n : null\n const facts: Array<[string, string]> = []\n if (view.dateMs) facts.push(['Date', date(view.dateMs)])\n if (input.revision && input.revision > 0) facts.push(['Revision', String(input.revision)])\n\n const sections: CommerceDocument['sections'] = []\n if (view.notes) sections.push({ heading: 'Notes', text: view.notes })\n if (view.terms) sections.push({ heading: 'Terms', text: view.terms })\n\n const payUrl = view.status === 'unpaid' && input.payUrl ? input.payUrl : null\n return {\n kind: 'QUOTE',\n title: view.number,\n facts,\n stamp,\n parties,\n lines: view.lines.map((line) => ({\n name: line.name,\n details: [line.variantLabel ?? '', line.description ?? '', line.sku ? `SKU ${line.sku}` : ''].filter(Boolean),\n quantity: line.quantity,\n unit: line.included ? '' : money(line.unitAmountCents),\n amount: line.included ? 'Included' : money(line.amountCents),\n })),\n summary,\n sections,\n pay: payUrl\n ? {\n url: payUrl,\n label: 'Pay this quote',\n intro: view.approvalRequired\n ? `${view.storeName || 'We'} will ask you to approve the proof first, at this link:`\n : 'Open the quote on our site to pay it securely by card:',\n }\n : null,\n }\n}\n\n/** The quote as a PDF. */\nexport function renderQuotePdf(input: QuotePdfInput): Uint8Array {\n return renderCommerceDocument(input.brand, quoteDocument(input))\n}\n\n/*==========================================\n * THE INVOICE\n *=========================================*/\n\nexport interface OrderInvoicePdfInput {\n brand: CommercePdfBrand\n order: InvoiceOrder\n orderId: string\n /** The store's currency, receipt footer and terms address (`invoiceStoreFrom`). */\n store: OrderInvoiceStore\n /**\n * The order's pay link (AGL-4099), printed on an invoice still to be paid\n * as Pay online with a button and the address; left off when absent.\n */\n payUrl?: string | null\n}\n\nfunction invoiceDocument(input: OrderInvoicePdfInput): CommerceDocument {\n const data = buildOrderInvoiceData(input)\n const money = (cents: number) => invoiceMoney(cents, data.currency)\n const parties: CommerceDocument['parties'] = []\n if (data.billTo.length) parties.push({ label: 'Bill to', lines: data.billTo })\n if (data.shipTo.length) parties.push({ label: 'Ship to', lines: data.shipTo })\n const facts: Array<[string, string]> = []\n if (data.dateMs) facts.push(['Order date', formatPdfDate(data.dateMs, input.brand.timeZone)])\n const sections: CommerceDocument['sections'] = []\n if (data.footer) sections.push({ heading: '', text: data.footer })\n if (data.termsUrl) sections.push({ heading: 'Terms', text: data.termsUrl, link: data.termsUrl })\n const payUrl = input.order.status === 'pending' && input.payUrl ? input.payUrl : null\n return {\n kind: 'INVOICE',\n title: `Invoice ${data.number}`,\n facts,\n stamp: data.paymentStatus,\n parties,\n lines: data.lines.map((line) => ({\n name: line.name,\n details: [line.detail, line.description].filter(Boolean),\n quantity: line.quantity,\n unit: line.included ? '' : money(line.unitCents),\n amount: line.included ? 'Included' : money(line.amountCents),\n })),\n summary: data.summary.map((row) => ({\n label: row.label,\n value: row.minus ? minus(money(row.cents)) : money(row.cents),\n emphasis: row.emphasis,\n })),\n sections,\n pay: payUrl\n ? { url: payUrl, label: 'Pay this invoice', intro: 'Open the invoice on our site to pay it securely by card:' }\n : null,\n }\n}\n\n/** Any order's invoice as a PDF, a paid quote's included. */\nexport function renderOrderInvoicePdf(input: OrderInvoicePdfInput): Uint8Array {\n return renderCommerceDocument(input.brand, invoiceDocument(input))\n}\n\n/*==========================================\n * THE LAYOUT\n *=========================================*/\n\nconst PAGE_MARGIN = { top: 48, right: 48, bottom: 60, left: 48 }\nconst BAND_HEIGHT = 10\nconst LOGO_BOX = { width: 180, height: 50 }\n\nfunction renderCommerceDocument(brand: CommercePdfBrand, document: CommerceDocument): Uint8Array {\n const palette = { ...COMMERCE_PDF_NEUTRAL_COLORS, ...(brand.colors ?? {}) }\n const color = (hex: string, fallback: string): PdfRgb =>\n pdfRgbFromHex(hex) ?? pdfRgbFromHex(fallback) ?? [0, 0, 0]\n const colors = {\n accent: color(palette.accent, COMMERCE_PDF_NEUTRAL_COLORS.accent),\n onAccent: color(palette.onAccent, COMMERCE_PDF_NEUTRAL_COLORS.onAccent),\n accentText: color(palette.accentText, COMMERCE_PDF_NEUTRAL_COLORS.accentText),\n tint: color(palette.tint, COMMERCE_PDF_NEUTRAL_COLORS.tint),\n ink: color(palette.ink, COMMERCE_PDF_NEUTRAL_COLORS.ink),\n muted: color(palette.muted, COMMERCE_PDF_NEUTRAL_COLORS.muted),\n rule: color(palette.rule, COMMERCE_PDF_NEUTRAL_COLORS.rule),\n }\n const businessName = brand.businessName.trim()\n const documentTitle = businessName ? `${document.title} - ${businessName}` : document.title\n\n const writer: PdfWriter = new PdfWriter({\n title: documentTitle,\n margin: PAGE_MARGIN,\n onNewPage: (page) => {\n page.fillRect(0, page.pageHeight - BAND_HEIGHT / 2, page.pageWidth, BAND_HEIGHT / 2, colors.accent)\n const baseline = page.top + 14\n if (businessName) page.textIn(page.left, page.contentWidth, baseline, businessName, { size: 8.5, font: 'bold', color: colors.muted })\n page.textIn(page.left, page.contentWidth, baseline, `${document.title} (continued)`, { size: 8.5, color: colors.muted }, 'right')\n },\n })\n const { left, right } = writer\n\n // The band across the top of the first page.\n writer.fillRect(0, writer.pageHeight - BAND_HEIGHT, writer.pageWidth, BAND_HEIGHT, colors.accent)\n\n // Left: logo, business name, contact.\n const leftWidth = writer.contentWidth * 0.55\n let leftY = writer.top\n if (brand.logo) {\n const drawn = writer.image(brand.logo, { x: left, y: leftY - LOGO_BOX.height, width: LOGO_BOX.width, height: LOGO_BOX.height })\n leftY = drawn.y - 12\n }\n writer.y = leftY\n if (businessName) writer.paragraph(businessName, { width: leftWidth, style: { font: 'bold', size: 14, color: colors.ink }, leading: 1.25, after: 2 })\n for (const line of brand.contactLines) {\n writer.paragraph(line, { width: leftWidth, style: { size: 9, color: colors.muted }, leading: 1.3 })\n }\n leftY = writer.y\n\n // Right: the document's name, number, facts and standing.\n const factsWidth = 210\n const factsX = right - factsWidth\n let rightY = writer.top - 22\n writer.textIn(factsX, factsWidth, rightY, document.kind, { font: 'bold', size: 24, color: colors.accentText }, 'right')\n rightY -= 20\n writer.textIn(factsX, factsWidth, rightY, document.title, { font: 'bold', size: 11, color: colors.ink }, 'right')\n for (const [label, value] of document.facts) {\n rightY -= 14\n const valueWidth = writer.measure(value, { size: 9.5 })\n writer.textIn(factsX, factsWidth, rightY, value, { size: 9.5, color: colors.ink }, 'right')\n writer.textIn(factsX, factsWidth - valueWidth - 8, rightY, label, { size: 9.5, color: colors.muted }, 'right')\n }\n if (document.stamp) {\n rightY -= 24\n const style = { font: 'bold' as const, size: 8.5, color: colors.onAccent }\n const width = writer.measure(document.stamp, style) + 16\n writer.fillRect(right - width, rightY - 5, width, 17, colors.accent)\n writer.textIn(right - width, width, rightY, document.stamp, style, 'center')\n rightY -= 5\n }\n\n writer.y = Math.min(leftY, rightY) - 22\n\n // Who it is for.\n if (document.parties.length) {\n const columnWidth = Math.min(220, writer.contentWidth / document.parties.length)\n const top = writer.y\n let lowest = top\n document.parties.forEach((party, index) => {\n const x = left + index * (columnWidth + 16)\n writer.y = top\n writer.paragraph(party.label.toUpperCase(), { x, width: columnWidth, style: { font: 'bold', size: 8, color: colors.muted }, after: 2 })\n party.lines.forEach((line, lineIndex) => {\n writer.paragraph(line, {\n x,\n width: columnWidth,\n style: { size: 9.5, color: colors.ink, font: lineIndex === 0 ? 'bold' : 'regular' },\n })\n })\n lowest = Math.min(lowest, writer.y)\n })\n writer.y = lowest - 18\n }\n\n // The lines.\n const rows: PdfTableCell[][] = document.lines.map((line) => [\n [\n { text: line.name, style: { font: 'bold', size: 9.5, color: colors.ink } },\n ...line.details.map((detail) => ({ text: detail, style: { size: 8.5, color: colors.muted } })),\n ],\n String(line.quantity),\n line.unit,\n line.amount,\n ])\n writer.table({\n columns: [\n { header: 'Item', width: 0 },\n { header: 'Qty', width: 48, align: 'right' },\n { header: 'Unit price', width: 86, align: 'right' },\n { header: 'Amount', width: 90, align: 'right' },\n ],\n rows,\n headerFill: colors.accent,\n headerStyle: { font: 'bold', size: 8.5, color: colors.onAccent },\n bodyStyle: { size: 9.5, color: colors.ink },\n padding: { x: 8, y: 6 },\n ruleColor: colors.rule,\n })\n\n // The totals on the right; beside them on the left, paying it.\n const summaryWidth = 250\n const summaryX = right - summaryWidth\n const payWidth = writer.contentWidth - summaryWidth - 28\n const rowHeight = 17\n const summaryHeight = document.summary.reduce((sum, row) => sum + (row.emphasis ? rowHeight + 8 : rowHeight), 0)\n const pay = document.pay\n const buttonStyle = { font: 'bold' as const, size: 10.5, color: colors.onAccent }\n const buttonHeight = 26\n const payParts = pay\n ? {\n intro: writer.wrap(pay.intro, payWidth, { size: 9 }),\n url: writer.wrap(pay.url, payWidth, { size: 8 }),\n }\n : null\n const payHeight = payParts ? 18 + payParts.intro.length * 12 + 6 + buttonHeight + 8 + payParts.url.length * 11 : 0\n writer.down(12)\n writer.ensure(Math.max(summaryHeight, payHeight))\n const blockTop = writer.y\n for (const row of document.summary) {\n const height = row.emphasis ? rowHeight + 8 : rowHeight\n if (row.emphasis) writer.fillRect(summaryX, writer.y - height, summaryWidth, height, colors.tint)\n const size = row.emphasis ? 11.5 : 9.5\n const baseline = writer.y - height / 2 - size * 0.35\n const style = row.emphasis\n ? { font: 'bold' as const, size, color: colors.ink }\n : { size, color: row.note ? colors.muted : colors.ink, ...(row.note ? { font: 'italic' as const } : {}) }\n writer.textIn(summaryX + 8, summaryWidth - 16, baseline, row.label, style, 'left')\n if (row.value) writer.textIn(summaryX + 8, summaryWidth - 16, baseline, row.value, style, 'right')\n writer.down(height)\n }\n const summaryBottom = writer.y\n if (pay && payParts) {\n let y = blockTop - 12\n writer.text(left, y, 'Pay online', { font: 'bold', size: 11, color: colors.ink })\n y -= 6\n for (const line of payParts.intro) {\n y -= 12\n writer.text(left, y + 2, line, { size: 9, color: colors.muted })\n }\n y -= 6\n const buttonWidth = writer.measure(pay.label, buttonStyle) + 36\n writer.fillRect(left, y - buttonHeight, buttonWidth, buttonHeight, colors.accent)\n writer.textIn(left, buttonWidth, y - buttonHeight / 2 - 10.5 * 0.35, pay.label, buttonStyle, 'center')\n writer.link(left, y - buttonHeight, buttonWidth, buttonHeight, pay.url)\n y -= buttonHeight + 8\n for (const line of payParts.url) {\n y -= 11\n writer.text(left, y + 2, line, { size: 8, color: colors.accentText })\n writer.link(left, y, writer.measure(line, { size: 8 }), 11, pay.url)\n }\n writer.y = Math.min(summaryBottom, y)\n }\n writer.down(22)\n\n // Notes, terms, the store's footer.\n for (const section of document.sections) {\n if (section.heading) {\n writer.ensure(36)\n writer.paragraph(section.heading, { style: { font: 'bold', size: 10, color: colors.ink }, after: 1 })\n }\n writer.paragraph(section.text, {\n style: { size: 9, color: section.link ? colors.accentText : colors.muted },\n ...(section.link ? { link: section.link } : {}),\n after: 12,\n })\n }\n\n return writer.finish({\n footer: (page, pages) => ({\n left: businessName ? `${businessName} · ${document.title}` : document.title,\n right: `Page ${page} of ${pages}`,\n }),\n footerStyle: { size: 8, color: colors.muted },\n footerRule: colors.rule,\n })\n}\n"],"names":["buildEmailPalette","emailAccent","resolveEmailColor","relativeLuminanceOfRgb","rgbChannelsOfHex","PdfWriter","pdfRgbFromHex","buildOrderInvoiceData","invoiceAddressLines","invoiceMoney","NEUTRAL_PALETTE","base","neutral","path","COMMERCE_PDF_NEUTRAL_COLORS","Object","freeze","accent","onAccent","accentText","tint","ink","muted","rule","contrast","one","other","a","b","la","lb","Math","max","min","commercePdfColorsFromPalette","palette","read","fallback","paper","label","fill","link","formatPdfDate","ms","timeZone","Number","isFinite","options","year","month","day","Intl","DateTimeFormat","format","Date","minus","text","quoteAddressLines","address","phone","quoteDocument","input","view","brand","money","cents","currency","date","customer","customerName","company","filter","Boolean","billTo","parties","length","named","part","includes","push","lines","shipTo","summary","value","totals","itemsCents","discountCents","discountLabel","shippingCents","taxAtPayment","note","taxCents","taxLabel","totalCents","emphasis","stamp","status","paidAtMs","facts","dateMs","revision","String","sections","notes","heading","terms","payUrl","kind","title","number","map","line","name","details","variantLabel","description","sku","quantity","unit","included","unitAmountCents","amount","amountCents","pay","url","intro","approvalRequired","storeName","renderQuotePdf","renderCommerceDocument","invoiceDocument","data","footer","termsUrl","order","paymentStatus","detail","unitCents","row","renderOrderInvoicePdf","PAGE_MARGIN","top","right","bottom","left","BAND_HEIGHT","LOGO_BOX","width","height","document","colors","color","hex","businessName","trim","documentTitle","writer","margin","onNewPage","page","fillRect","pageHeight","pageWidth","baseline","textIn","contentWidth","size","font","leftWidth","leftY","logo","drawn","image","x","y","paragraph","style","leading","after","contactLines","factsWidth","factsX","rightY","valueWidth","measure","columnWidth","lowest","forEach","party","index","toUpperCase","lineIndex","rows","table","columns","header","align","headerFill","headerStyle","bodyStyle","padding","ruleColor","summaryWidth","summaryX","payWidth","rowHeight","summaryHeight","reduce","sum","buttonStyle","buttonHeight","payParts","wrap","payHeight","down","ensure","blockTop","summaryBottom","buttonWidth","section","finish","pages","footerStyle","footerRule"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,EAAEC,WAAW,EAAEC,iBAAiB,QAA2B,2BAA0B;AAC/G,SAASC,sBAAs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OAAOD,OAAOhI,KAAK;QAAC;QAC5CyM,YAAYzE,OAAO/H,IAAI;IACzB;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/utils/commerce-document-pdf.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { buildEmailPalette, emailAccent, resolveEmailColor, type EmailPalette } from '@aglyn/shared-util-email'\nimport { relativeLuminanceOfRgb, rgbChannelsOfHex } from '@aglyn/shared-util-tools/contrast'\nimport type { PdfJpegImage } from '@aglyn/shared-util-tools/pdf/pdf-file'\nimport { PdfWriter, pdfRgbFromHex, type PdfRgb, type PdfTableCell } from '@aglyn/shared-util-tools/pdf/pdf-writer'\nimport type { QuotePageAddress, QuotePageView } from '../model/commerce-quote-pay'\nimport { buildOrderInvoiceData, invoiceAddressLines, invoiceMoney, type InvoiceOrder, type OrderInvoiceStore } from './order-invoice'\n\n/*==========================================\n * A QUOTE AND AN INVOICE AS BRANDED PDFs (AGL-4095).\n *\n * renderQuotePdf({ brand, view, revision, payUrl }) → Uint8Array\n * renderOrderInvoicePdf({ brand, order, orderId, store }) → Uint8Array\n *\n * Both are one layout: the business's logo, name and contact at the top left\n * under a band of the site's primary color, the document's name, number,\n * date and standing at the top right, who it is billed and shipped to, the\n * lines in a table whose header wears the primary color, the totals, then\n * notes, terms and (for a quote still to be paid) the pay link as a button\n * and as text, both clickable. Every page ends with the document's name and\n * its page number.\n *\n * Pure over its input: the server reads the site, its theme and its logo\n * (`server/commerce-pdf-brand.ts`) and the quote or order, and these turn\n * them into bytes, so the console's download, the customer's download and\n * the emails that attach a quote or an invoice all make the same file.\n *\n * A quote is drawn from `buildQuotePageView`, the customer-safe projection\n * the quote page shows, so the PDF never says more than the page does. An\n * invoice is drawn from `buildOrderInvoiceData`, the content the printed\n * invoice shows.\n *=========================================*/\n\n/** The colors a document is drawn in, as `#rrggbb`. */\nexport interface CommercePdfColors {\n /** The band, the table's header and the pay button: the site's primary color. */\n accent: string\n /** Text set on the accent. */\n onAccent: string\n /** The accent as text on white: the document's name, links. */\n accentText: string\n /** A wash of the accent, behind the total. */\n tint: string\n ink: string\n muted: string\n rule: string\n}\n\n/** Who the document is from. */\nexport interface CommercePdfBrand {\n businessName: string\n /** Address lines, email, phone and web address, in that order. */\n contactLines: readonly string[]\n /** The site's logo as a JPEG; the business name stands alone without one. */\n logo?: PdfJpegImage | null\n /** The site theme's colors; any left out are the neutral ones. */\n colors?: Partial<CommercePdfColors> | null\n /** The site's time zone, which dates are given in. */\n timeZone?: string | null\n}\n\nconst NEUTRAL_PALETTE = buildEmailPalette({ base: 'tenant' })\nconst neutral = (path: string) => resolveEmailColor(path, NEUTRAL_PALETTE) ?? ''\n\n/** The colors a document wears where its site's theme gives none: the default site theme's greys. */\nexport const COMMERCE_PDF_NEUTRAL_COLORS: Readonly<CommercePdfColors> = Object.freeze({\n accent: neutral('grey.800'),\n onAccent: neutral('background.paper'),\n accentText: neutral('grey.800'),\n tint: neutral('grey.100'),\n ink: neutral('text.primary'),\n muted: neutral('text.secondary'),\n rule: neutral('divider'),\n})\n\n/** WCAG contrast between two `#rrggbb` colors; 1 when either cannot be read. */\nfunction contrast(one: string, other: string): number {\n const a = rgbChannelsOfHex(one)\n const b = rgbChannelsOfHex(other)\n if (!a || !b) return 1\n const la = relativeLuminanceOfRgb(...a)\n const lb = relativeLuminanceOfRgb(...b)\n return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05)\n}\n\n/**\n * A document's colors from a site's resolved palette: the primary color for\n * the accent, the theme's own text and divider colors, and text on the\n * accent that reads at 4.5:1 (the theme's contrast text when it does, else\n * the theme's dark ink or white, whichever reads better).\n */\nexport function commercePdfColorsFromPalette(palette: EmailPalette): CommercePdfColors {\n const accent = emailAccent(palette)\n const read = (path: string, fallback: string) => resolveEmailColor(path, palette) ?? fallback\n const ink = read('text.primary', COMMERCE_PDF_NEUTRAL_COLORS.ink)\n const paper = read('background.paper', COMMERCE_PDF_NEUTRAL_COLORS.onAccent)\n const onAccent =\n contrast(accent.label, accent.fill) >= 4.5\n ? accent.label\n : contrast(ink, accent.fill) >= contrast(paper, accent.fill)\n ? ink\n : paper\n return {\n accent: accent.fill,\n onAccent,\n accentText: contrast(accent.link, paper) >= 4.5 ? accent.link : ink,\n tint: read('tint.primary', COMMERCE_PDF_NEUTRAL_COLORS.tint),\n ink,\n muted: read('text.secondary', COMMERCE_PDF_NEUTRAL_COLORS.muted),\n rule: read('divider', COMMERCE_PDF_NEUTRAL_COLORS.rule),\n }\n}\n\n/*==========================================\n * WHAT A DOCUMENT SAYS\n *=========================================*/\n\ninterface DocumentLine {\n name: string\n details: string[]\n quantity: number\n unit: string\n amount: string\n}\n\ninterface SummaryRow {\n label: string\n value: string\n emphasis?: boolean\n /** A note in place of a figure, such as \"Tax is added at payment\". */\n note?: boolean\n}\n\ninterface CommerceDocument {\n /** QUOTE or INVOICE, across the top. */\n kind: string\n /** `Quote #1042`. */\n title: string\n facts: Array<[string, string]>\n /** A short standing, set in a pill under the facts: `Paid October 30, 2026`. */\n stamp: string | null\n parties: Array<{ label: string; lines: string[] }>\n lines: DocumentLine[]\n summary: SummaryRow[]\n sections: Array<{ heading: string; text: string; link?: string }>\n pay: { url: string; label: string; intro: string } | null\n}\n\n/** A date the American way, in the site's time zone: `October 28, 2026`. */\nexport function formatPdfDate(ms: number | null | undefined, timeZone?: string | null): string {\n if (!ms || !Number.isFinite(ms)) return ''\n const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'long', day: 'numeric' }\n try {\n return new Intl.DateTimeFormat('en-US', { ...options, ...(timeZone ? { timeZone } : {}) }).format(new Date(ms))\n } catch {\n return new Intl.DateTimeFormat('en-US', { ...options, timeZone: 'UTC' }).format(new Date(ms))\n }\n}\n\nconst minus = (text: string) => `-${text}`\n\n/*==========================================\n * THE QUOTE\n *=========================================*/\n\nexport interface QuotePdfInput {\n brand: CommercePdfBrand\n /** The quote as its customer may see it: `buildQuotePageView`. */\n view: QuotePageView\n /** The quote's revision, printed beside its date. */\n revision?: number | null\n /** The pay link, printed on a quote still to be paid; left off when the reader may not have it. */\n payUrl?: string | null\n}\n\nfunction quoteAddressLines(address: QuotePageAddress | null): string[] {\n return invoiceAddressLines(address as never, { phone: false })\n}\n\nfunction quoteDocument(input: QuotePdfInput): CommerceDocument {\n const { view, brand } = input\n const money = (cents: number) => invoiceMoney(cents, view.currency)\n const date = (ms: number | null) => formatPdfDate(ms, brand.timeZone)\n const customer = [view.customerName ?? '', view.company ?? ''].filter(Boolean)\n const billTo = quoteAddressLines(view.billTo)\n const parties: CommerceDocument['parties'] = []\n if (billTo.length) {\n // The bill-to's own name leads; the customer's name and company are added when it does not carry them.\n const named = customer.filter((part) => !billTo.includes(part))\n parties.push({ label: 'Bill to', lines: [...named, ...billTo] })\n } else if (customer.length) {\n parties.push({ label: 'Prepared for', lines: customer })\n }\n const shipTo = quoteAddressLines(view.shipTo)\n if (shipTo.length) parties.push({ label: 'Ship to', lines: shipTo })\n\n // A proof only quote has no price section at all (AGL-4184).\n const summary: SummaryRow[] = view.proofOnly ? [] : [{ label: 'Subtotal', value: money(view.totals.itemsCents) }]\n if (view.totals.discountCents > 0) {\n summary.push({\n label: view.discountLabel ? `Discount (${view.discountLabel})` : 'Discount',\n value: minus(money(view.totals.discountCents)),\n })\n }\n if (view.totals.shippingCents > 0) summary.push({ label: 'Shipping', value: money(view.totals.shippingCents) })\n if (view.taxAtPayment) summary.push({ label: 'Tax is added at payment', value: '', note: true })\n else if (view.totals.taxCents > 0) summary.push({ label: view.taxLabel || 'Tax', value: money(view.totals.taxCents) })\n else if (view.taxLabel && view.taxLabel !== 'Tax') summary.push({ label: view.taxLabel, value: '', note: true })\n if (!view.proofOnly) {\n summary.push({ label: view.taxAtPayment ? 'Total before tax' : 'Total', value: money(view.totals.totalCents), emphasis: true })\n }\n\n const stamp =\n view.status === 'paid'\n ? `Paid${view.paidAtMs ? ` ${date(view.paidAtMs)}` : ''}`\n : view.status === 'canceled'\n ? 'Canceled'\n : view.status === 'refunded'\n ? 'Refunded'\n : null\n const facts: Array<[string, string]> = []\n if (view.dateMs) facts.push(['Date', date(view.dateMs)])\n if (input.revision && input.revision > 0) facts.push(['Revision', String(input.revision)])\n\n const sections: CommerceDocument['sections'] = []\n if (view.notes) sections.push({ heading: 'Notes', text: view.notes })\n if (view.terms) sections.push({ heading: 'Terms', text: view.terms })\n\n const payUrl = view.status === 'unpaid' && !view.proofOnly && input.payUrl ? input.payUrl : null\n return {\n kind: view.proofOnly ? 'PROOF' : 'QUOTE',\n title: view.number,\n facts,\n stamp,\n parties,\n lines: view.lines.map((line) => ({\n name: line.name,\n details: [line.variantLabel ?? '', line.description ?? '', line.sku ? `SKU ${line.sku}` : ''].filter(Boolean),\n quantity: line.quantity,\n unit: line.included ? '' : money(line.unitAmountCents),\n amount: line.included ? 'Included' : money(line.amountCents),\n })),\n summary,\n sections,\n pay: payUrl\n ? {\n url: payUrl,\n label: 'Pay this quote',\n intro: view.approvalRequired\n ? `${view.storeName || 'We'} will ask you to approve the proof first, at this link:`\n : 'Open the quote on our site to pay it securely by card:',\n }\n : null,\n }\n}\n\n/** The quote as a PDF. */\nexport function renderQuotePdf(input: QuotePdfInput): Uint8Array {\n return renderCommerceDocument(input.brand, quoteDocument(input))\n}\n\n/*==========================================\n * THE INVOICE\n *=========================================*/\n\nexport interface OrderInvoicePdfInput {\n brand: CommercePdfBrand\n order: InvoiceOrder\n orderId: string\n /** The store's currency, receipt footer and terms address (`invoiceStoreFrom`). */\n store: OrderInvoiceStore\n /**\n * The order's pay link (AGL-4099), printed on an invoice still to be paid\n * as Pay online with a button and the address; left off when absent.\n */\n payUrl?: string | null\n}\n\nfunction invoiceDocument(input: OrderInvoicePdfInput): CommerceDocument {\n const data = buildOrderInvoiceData(input)\n const money = (cents: number) => invoiceMoney(cents, data.currency)\n const parties: CommerceDocument['parties'] = []\n if (data.billTo.length) parties.push({ label: 'Bill to', lines: data.billTo })\n if (data.shipTo.length) parties.push({ label: 'Ship to', lines: data.shipTo })\n const facts: Array<[string, string]> = []\n if (data.dateMs) facts.push(['Order date', formatPdfDate(data.dateMs, input.brand.timeZone)])\n const sections: CommerceDocument['sections'] = []\n if (data.footer) sections.push({ heading: '', text: data.footer })\n if (data.termsUrl) sections.push({ heading: 'Terms', text: data.termsUrl, link: data.termsUrl })\n const payUrl = input.order.status === 'pending' && input.payUrl ? input.payUrl : null\n return {\n kind: 'INVOICE',\n title: `Invoice ${data.number}`,\n facts,\n stamp: data.paymentStatus,\n parties,\n lines: data.lines.map((line) => ({\n name: line.name,\n details: [line.detail, line.description].filter(Boolean),\n quantity: line.quantity,\n unit: line.included ? '' : money(line.unitCents),\n amount: line.included ? 'Included' : money(line.amountCents),\n })),\n summary: data.summary.map((row) => ({\n label: row.label,\n value: row.minus ? minus(money(row.cents)) : money(row.cents),\n emphasis: row.emphasis,\n })),\n sections,\n pay: payUrl\n ? { url: payUrl, label: 'Pay this invoice', intro: 'Open the invoice on our site to pay it securely by card:' }\n : null,\n }\n}\n\n/** Any order's invoice as a PDF, a paid quote's included. */\nexport function renderOrderInvoicePdf(input: OrderInvoicePdfInput): Uint8Array {\n return renderCommerceDocument(input.brand, invoiceDocument(input))\n}\n\n/*==========================================\n * THE LAYOUT\n *=========================================*/\n\nconst PAGE_MARGIN = { top: 48, right: 48, bottom: 60, left: 48 }\nconst BAND_HEIGHT = 10\nconst LOGO_BOX = { width: 180, height: 50 }\n\nfunction renderCommerceDocument(brand: CommercePdfBrand, document: CommerceDocument): Uint8Array {\n const palette = { ...COMMERCE_PDF_NEUTRAL_COLORS, ...(brand.colors ?? {}) }\n const color = (hex: string, fallback: string): PdfRgb =>\n pdfRgbFromHex(hex) ?? pdfRgbFromHex(fallback) ?? [0, 0, 0]\n const colors = {\n accent: color(palette.accent, COMMERCE_PDF_NEUTRAL_COLORS.accent),\n onAccent: color(palette.onAccent, COMMERCE_PDF_NEUTRAL_COLORS.onAccent),\n accentText: color(palette.accentText, COMMERCE_PDF_NEUTRAL_COLORS.accentText),\n tint: color(palette.tint, COMMERCE_PDF_NEUTRAL_COLORS.tint),\n ink: color(palette.ink, COMMERCE_PDF_NEUTRAL_COLORS.ink),\n muted: color(palette.muted, COMMERCE_PDF_NEUTRAL_COLORS.muted),\n rule: color(palette.rule, COMMERCE_PDF_NEUTRAL_COLORS.rule),\n }\n const businessName = brand.businessName.trim()\n const documentTitle = businessName ? `${document.title} - ${businessName}` : document.title\n\n const writer: PdfWriter = new PdfWriter({\n title: documentTitle,\n margin: PAGE_MARGIN,\n onNewPage: (page) => {\n page.fillRect(0, page.pageHeight - BAND_HEIGHT / 2, page.pageWidth, BAND_HEIGHT / 2, colors.accent)\n const baseline = page.top + 14\n if (businessName) page.textIn(page.left, page.contentWidth, baseline, businessName, { size: 8.5, font: 'bold', color: colors.muted })\n page.textIn(page.left, page.contentWidth, baseline, `${document.title} (continued)`, { size: 8.5, color: colors.muted }, 'right')\n },\n })\n const { left, right } = writer\n\n // The band across the top of the first page.\n writer.fillRect(0, writer.pageHeight - BAND_HEIGHT, writer.pageWidth, BAND_HEIGHT, colors.accent)\n\n // Left: logo, business name, contact.\n const leftWidth = writer.contentWidth * 0.55\n let leftY = writer.top\n if (brand.logo) {\n const drawn = writer.image(brand.logo, { x: left, y: leftY - LOGO_BOX.height, width: LOGO_BOX.width, height: LOGO_BOX.height })\n leftY = drawn.y - 12\n }\n writer.y = leftY\n if (businessName) writer.paragraph(businessName, { width: leftWidth, style: { font: 'bold', size: 14, color: colors.ink }, leading: 1.25, after: 2 })\n for (const line of brand.contactLines) {\n writer.paragraph(line, { width: leftWidth, style: { size: 9, color: colors.muted }, leading: 1.3 })\n }\n leftY = writer.y\n\n // Right: the document's name, number, facts and standing.\n const factsWidth = 210\n const factsX = right - factsWidth\n let rightY = writer.top - 22\n writer.textIn(factsX, factsWidth, rightY, document.kind, { font: 'bold', size: 24, color: colors.accentText }, 'right')\n rightY -= 20\n writer.textIn(factsX, factsWidth, rightY, document.title, { font: 'bold', size: 11, color: colors.ink }, 'right')\n for (const [label, value] of document.facts) {\n rightY -= 14\n const valueWidth = writer.measure(value, { size: 9.5 })\n writer.textIn(factsX, factsWidth, rightY, value, { size: 9.5, color: colors.ink }, 'right')\n writer.textIn(factsX, factsWidth - valueWidth - 8, rightY, label, { size: 9.5, color: colors.muted }, 'right')\n }\n if (document.stamp) {\n rightY -= 24\n const style = { font: 'bold' as const, size: 8.5, color: colors.onAccent }\n const width = writer.measure(document.stamp, style) + 16\n writer.fillRect(right - width, rightY - 5, width, 17, colors.accent)\n writer.textIn(right - width, width, rightY, document.stamp, style, 'center')\n rightY -= 5\n }\n\n writer.y = Math.min(leftY, rightY) - 22\n\n // Who it is for.\n if (document.parties.length) {\n const columnWidth = Math.min(220, writer.contentWidth / document.parties.length)\n const top = writer.y\n let lowest = top\n document.parties.forEach((party, index) => {\n const x = left + index * (columnWidth + 16)\n writer.y = top\n writer.paragraph(party.label.toUpperCase(), { x, width: columnWidth, style: { font: 'bold', size: 8, color: colors.muted }, after: 2 })\n party.lines.forEach((line, lineIndex) => {\n writer.paragraph(line, {\n x,\n width: columnWidth,\n style: { size: 9.5, color: colors.ink, font: lineIndex === 0 ? 'bold' : 'regular' },\n })\n })\n lowest = Math.min(lowest, writer.y)\n })\n writer.y = lowest - 18\n }\n\n // The lines.\n const rows: PdfTableCell[][] = document.lines.map((line) => [\n [\n { text: line.name, style: { font: 'bold', size: 9.5, color: colors.ink } },\n ...line.details.map((detail) => ({ text: detail, style: { size: 8.5, color: colors.muted } })),\n ],\n String(line.quantity),\n line.unit,\n line.amount,\n ])\n if (rows.length) writer.table({\n columns: [\n { header: 'Item', width: 0 },\n { header: 'Qty', width: 48, align: 'right' },\n { header: 'Unit price', width: 86, align: 'right' },\n { header: 'Amount', width: 90, align: 'right' },\n ],\n rows,\n headerFill: colors.accent,\n headerStyle: { font: 'bold', size: 8.5, color: colors.onAccent },\n bodyStyle: { size: 9.5, color: colors.ink },\n padding: { x: 8, y: 6 },\n ruleColor: colors.rule,\n })\n\n // The totals on the right; beside them on the left, paying it.\n const summaryWidth = 250\n const summaryX = right - summaryWidth\n const payWidth = writer.contentWidth - summaryWidth - 28\n const rowHeight = 17\n const summaryHeight = document.summary.reduce((sum, row) => sum + (row.emphasis ? rowHeight + 8 : rowHeight), 0)\n const pay = document.pay\n const buttonStyle = { font: 'bold' as const, size: 10.5, color: colors.onAccent }\n const buttonHeight = 26\n const payParts = pay\n ? {\n intro: writer.wrap(pay.intro, payWidth, { size: 9 }),\n url: writer.wrap(pay.url, payWidth, { size: 8 }),\n }\n : null\n const payHeight = payParts ? 18 + payParts.intro.length * 12 + 6 + buttonHeight + 8 + payParts.url.length * 11 : 0\n writer.down(12)\n writer.ensure(Math.max(summaryHeight, payHeight))\n const blockTop = writer.y\n for (const row of document.summary) {\n const height = row.emphasis ? rowHeight + 8 : rowHeight\n if (row.emphasis) writer.fillRect(summaryX, writer.y - height, summaryWidth, height, colors.tint)\n const size = row.emphasis ? 11.5 : 9.5\n const baseline = writer.y - height / 2 - size * 0.35\n const style = row.emphasis\n ? { font: 'bold' as const, size, color: colors.ink }\n : { size, color: row.note ? colors.muted : colors.ink, ...(row.note ? { font: 'italic' as const } : {}) }\n writer.textIn(summaryX + 8, summaryWidth - 16, baseline, row.label, style, 'left')\n if (row.value) writer.textIn(summaryX + 8, summaryWidth - 16, baseline, row.value, style, 'right')\n writer.down(height)\n }\n const summaryBottom = writer.y\n if (pay && payParts) {\n let y = blockTop - 12\n writer.text(left, y, 'Pay online', { font: 'bold', size: 11, color: colors.ink })\n y -= 6\n for (const line of payParts.intro) {\n y -= 12\n writer.text(left, y + 2, line, { size: 9, color: colors.muted })\n }\n y -= 6\n const buttonWidth = writer.measure(pay.label, buttonStyle) + 36\n writer.fillRect(left, y - buttonHeight, buttonWidth, buttonHeight, colors.accent)\n writer.textIn(left, buttonWidth, y - buttonHeight / 2 - 10.5 * 0.35, pay.label, buttonStyle, 'center')\n writer.link(left, y - buttonHeight, buttonWidth, buttonHeight, pay.url)\n y -= buttonHeight + 8\n for (const line of payParts.url) {\n y -= 11\n writer.text(left, y + 2, line, { size: 8, color: colors.accentText })\n writer.link(left, y, writer.measure(line, { size: 8 }), 11, pay.url)\n }\n writer.y = Math.min(summaryBottom, y)\n }\n writer.down(22)\n\n // Notes, terms, the store's footer.\n for (const section of document.sections) {\n if (section.heading) {\n writer.ensure(36)\n writer.paragraph(section.heading, { style: { font: 'bold', size: 10, color: colors.ink }, after: 1 })\n }\n writer.paragraph(section.text, {\n style: { size: 9, color: section.link ? colors.accentText : colors.muted },\n ...(section.link ? { link: section.link } : {}),\n after: 12,\n })\n }\n\n return writer.finish({\n footer: (page, pages) => ({\n left: businessName ? `${businessName} · ${document.title}` : document.title,\n right: `Page ${page} of ${pages}`,\n }),\n footerStyle: { size: 8, color: colors.muted },\n footerRule: colors.rule,\n })\n}\n"],"names":["buildEmailPalette","emailAccent","resolveEmailColor","relativeLuminanceOfRgb","rgbChannelsOfHex","PdfWriter","pdfRgbFromHex","buildOrderInvoiceData","invoiceAddressLines","invoiceMoney","NEUTRAL_PALETTE","base","neutral","path","COMMERCE_PDF_NEUTRAL_COLORS","Object","freeze","accent","onAccent","accentText","tint","ink","muted","rule","contrast","one","other","a","b","la","lb","Math","max","min","commercePdfColorsFromPalette","palette","read","fallback","paper","label","fill","link","formatPdfDate","ms","timeZone","Number","isFinite","options","year","month","day","Intl","DateTimeFormat","format","Date","minus","text","quoteAddressLines","address","phone","quoteDocument","input","view","brand","money","cents","currency","date","customer","customerName","company","filter","Boolean","billTo","parties","length","named","part","includes","push","lines","shipTo","summary","proofOnly","value","totals","itemsCents","discountCents","discountLabel","shippingCents","taxAtPayment","note","taxCents","taxLabel","totalCents","emphasis","stamp","status","paidAtMs","facts","dateMs","revision","String","sections","notes","heading","terms","payUrl","kind","title","number","map","line","name","details","variantLabel","description","sku","quantity","unit","included","unitAmountCents","amount","amountCents","pay","url","intro","approvalRequired","storeName","renderQuotePdf","renderCommerceDocument","invoiceDocument","data","footer","termsUrl","order","paymentStatus","detail","unitCents","row","renderOrderInvoicePdf","PAGE_MARGIN","top","right","bottom","left","BAND_HEIGHT","LOGO_BOX","width","height","document","colors","color","hex","businessName","trim","documentTitle","writer","margin","onNewPage","page","fillRect","pageHeight","pageWidth","baseline","textIn","contentWidth","size","font","leftWidth","leftY","logo","drawn","image","x","y","paragraph","style","leading","after","contactLines","factsWidth","factsX","rightY","valueWidth","measure","columnWidth","lowest","forEach","party","index","toUpperCase","lineIndex","rows","table","columns","header","align","headerFill","headerStyle","bodyStyle","padding","ruleColor","summaryWidth","summaryX","payWidth","rowHeight","summaryHeight","reduce","sum","buttonStyle","buttonHeight","payParts","wrap","payHeight","down","ensure","blockTop","summaryBottom","buttonWidth","section","finish","pages","footerStyle","footerRule"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,EAAEC,WAAW,EAAEC,iBAAiB,QAA2B,2BAA0B;AAC/G,SAASC,sBAAsB,EAAEC,gBAAgB,QAAQ,oCAAmC;AAE5F,SAASC,SAAS,EAAEC,aAAa,QAAwC,0CAAyC;AAElH,SAASC,qBAAqB,EAAEC,mBAAmB,EAAEC,YAAY,QAAmD,qBAAiB;AAuDrI,MAAMC,kBAAkBV,kBAAkB;IAAEW,MAAM;AAAS;AAC3D,MAAMC,UAAU,CAACC;QAAiBX;YAAAA,qBAAAA,kBAAkBW,MAAMH,4BAAxBR,qBAA4C;;AAE9E,mGAAmG,GACnG,OAAO,MAAMY,8BAA2DC,OAAOC,MAAM,CAAC;IACpFC,QAAQL,QA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YAAC;YACnE0I,OAAOpH,IAAI,CAACwG,MAAM8B,GAAGlB,OAAO4B,OAAO,CAACzE,MAAM;gBAAEuD,MAAM;YAAE,IAAI,IAAI3C,IAAIC,GAAG;QACrE;QACAgC,OAAOkB,CAAC,GAAGhJ,KAAKE,GAAG,CAACyL,eAAe3C;IACrC;IACAlB,OAAO0D,IAAI,CAAC;IAEZ,oCAAoC;IACpC,KAAK,MAAMK,WAAWtE,SAAS/C,QAAQ,CAAE;QACvC,IAAIqH,QAAQnH,OAAO,EAAE;YACnBoD,OAAO2D,MAAM,CAAC;YACd3D,OAAOmB,SAAS,CAAC4C,QAAQnH,OAAO,EAAE;gBAAEwE,OAAO;oBAAET,MAAM;oBAAQD,MAAM;oBAAIf,OAAOD,OAAOlI,GAAG;gBAAC;gBAAG8J,OAAO;YAAE;QACrG;QACAtB,OAAOmB,SAAS,CAAC4C,QAAQpK,IAAI,EAAE;YAC7ByH,OAAO;gBAAEV,MAAM;gBAAGf,OAAOoE,QAAQnL,IAAI,GAAG8G,OAAOpI,UAAU,GAAGoI,OAAOjI,KAAK;YAAC;WACrEsM,QAAQnL,IAAI,GAAG;YAAEA,MAAMmL,QAAQnL,IAAI;QAAC,IAAI,CAAC;YAC7C0I,OAAO;;IAEX;IAEA,OAAOtB,OAAOgE,MAAM,CAAC;QACnBxF,QAAQ,CAAC2B,MAAM8D,QAAW,CAAA;gBACxB7E,MAAMS,eAAe,GAAGA,aAAa,GAAG,EAAEJ,SAASzC,KAAK,EAAE,GAAGyC,SAASzC,KAAK;gBAC3EkC,OAAO,CAAC,KAAK,EAAEiB,KAAK,IAAI,EAAE8D,OAAO;YACnC,CAAA;QACAC,aAAa;YAAExD,MAAM;YAAGf,OAAOD,OAAOjI,KAAK;QAAC;QAC5C0M,YAAYzE,OAAOhI,IAAI;IACzB;AACF"}
@@ -60,6 +60,8 @@ export interface QuoteEmailContent {
60
60
  text: string;
61
61
  /** The customer approves the proof before they can pay: the button reads "Review and approve". */
62
62
  approvalFirst: boolean;
63
+ /** A proof with no price yet: nothing to pay, and no PDF goes with it. */
64
+ proofOnly: boolean;
63
65
  }
64
66
  /** The quote email's tokens and its plain-text twin. */
65
67
  export declare function quoteEmailContent(input: QuoteEmailContentInput): QuoteEmailContent;
@@ -13,7 +13,7 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */ import { currentQuoteProofs, formatOrderMoney, formatQuoteNumber, quotePaymentBlockedByApproval, quotePayTax, quoteSendIsNewRevision } from "../model/index.js";
16
+ */ import { currentQuoteProofs, formatOrderMoney, formatQuoteNumber, quoteIsProofOnly, quotePaymentBlockedByApproval, quotePayTax, quoteSendIsNewRevision } from "../model/index.js";
17
17
  import { escapeHtml } from "./escape-html.js";
18
18
  /*==========================================
19
19
  * WHAT THE QUOTE EMAIL SAYS (AGL-4097).
@@ -30,6 +30,11 @@ import { escapeHtml } from "./escape-html.js";
30
30
  * pay" with the total. Both go to the quote's pay link, where the customer
31
31
  * does either.
32
32
  *
33
+ * A PROOF ONLY quote (no lines, AGL-4184) says so in the same tokens: "Your
34
+ * proof from …", what to do with the proof, "Review the proof", `quote.label`
35
+ * "Proof", and an empty `quote.total`, whose row a details panel then does not
36
+ * draw. No PDF goes with it (`quote-email.ts`): its proof is the whole of it.
37
+ *
33
38
  * Prices appear only in the tokens the catalog names for them
34
39
  * (`quote.total`, `quote.buttonLabel`); the composed markup
35
40
  * (`quote.proofImages`) carries pictures and file names, nothing else.
@@ -63,10 +68,13 @@ const plural = (count, one, many)=>`${count} ${count === 1 ? one : many}`;
63
68
  const business = businessName.trim() || 'the business';
64
69
  const revision = Math.max(1, Math.floor(Number((_quote_revision = quote.revision) != null ? _quote_revision : 1)) || 1);
65
70
  const number = formatQuoteNumber(order, input.quoteId).replace(/^Quote\s+/, '');
71
+ const proofOnly = quoteIsProofOnly(order);
72
+ const noun = proofOnly ? 'proof' : 'quote';
73
+ const label = proofOnly ? 'Proof' : 'Quote';
66
74
  const taxAtPayment = quotePayTax(quote, input.store).basis.kind === 'at-payment';
67
75
  const money = formatOrderMoney(Number((_ref = (_order_totals = order.totals) == null ? void 0 : _order_totals.totalCents) != null ? _ref : 0), input.currency);
68
- const total = taxAtPayment ? `${money} before tax` : money;
69
- const approvalFirst = quotePaymentBlockedByApproval(quote);
76
+ const total = proofOnly ? '' : taxAtPayment ? `${money} before tax` : money;
77
+ const approvalFirst = !proofOnly && quotePaymentBlockedByApproval(quote);
70
78
  // The proofs: pictures an inbox draws, up to three, then every other file by name.
71
79
  const proofs = currentQuoteProofs(quote);
72
80
  const pictured = [];
@@ -91,20 +99,21 @@ const plural = (count, one, many)=>`${count} ${count === 1 ? one : many}`;
91
99
  ] : []
92
100
  ];
93
101
  const lead = pictured.length ? 'Also with this revision' : named.length === 1 ? 'Proof' : 'Proofs';
94
- const seeIt = named.length + morePictures === 1 ? 'See it on your quote page.' : 'See them on your quote page.';
102
+ const seeIt = named.length + morePictures === 1 ? `See it on your ${noun} page.` : `See them on your ${noun} page.`;
95
103
  const proofFiles = parts.length ? `${lead}: ${joinNames(parts)}. ${seeIt}` : '';
96
104
  const radius = Math.max(0, Math.round(Number((_input_radius = input.radius) != null ? _input_radius : 4)) || 0);
97
105
  const proofImages = proofImagesHtml(pictured, input.payUrl, input.colors, radius);
98
106
  const updated = quoteSendIsNewRevision(quote);
99
- const heading = updated ? 'Your updated quote' : businessName.trim() ? `Your quote from ${businessName.trim()}` : 'Your quote';
100
- const intro = updated ? `${capitalize(business)} updated your quote. This is revision ${revision}, and it replaces the one sent before.` + (input.linkReplaced ? ' The link in the earlier email no longer opens the quote, so use the button below.' : '') + ' The new version is attached as a PDF.' : `${capitalize(business)} put together a quote for you. The details are below, and the quote is attached as a PDF.`;
107
+ const heading = updated ? `Your updated ${noun}` : businessName.trim() ? `Your ${noun} from ${businessName.trim()}` : `Your ${noun}`;
108
+ const intro = updated ? `${capitalize(business)} updated your ${noun}. This is revision ${revision}, and it replaces the one sent before.` + (input.linkReplaced ? ` The link in the earlier email no longer opens the ${noun}, so use the button below.` : '') + (proofOnly ? '' : ' The new version is attached as a PDF.') : proofOnly ? `${capitalize(business)} sent you a proof to look over.` : `${capitalize(business)} put together a quote for you. The details are below, and the quote is attached as a PDF.`;
101
109
  const proofed = proofs.length > 0;
102
110
  const approved = proofed && Number(quote.approvedRevision) === revision;
103
- const nextStep = approvalFirst ? 'Look over the proof, then approve it on your quote page. Once you approve it, you can pay there.' : approved ? 'You approved the proof. Pay on your quote page whenever you’re ready.' : proofed ? 'Look over your quote and the proof. On your quote page you can approve the proof or ask for changes, and pay whenever you’re ready.' : 'Look over your quote, and pay it on your quote page whenever you’re ready.';
104
- const buttonLabel = approvalFirst ? 'Review and approve' : `View and pay ${money}${taxAtPayment ? ' plus tax' : ''}`;
111
+ const nextStep = proofOnly ? approved ? 'You approved this proof. You can still ask for changes on your proof page.' : 'Look over the proof, then approve it or ask for changes on your proof page.' : approvalFirst ? 'Look over the proof, then approve it on your quote page. Once you approve it, you can pay there.' : approved ? 'You approved the proof. Pay on your quote page whenever you’re ready.' : proofed ? 'Look over your quote and the proof. On your quote page you can approve the proof or ask for changes, and pay whenever you’re ready.' : 'Look over your quote, and pay it on your quote page whenever you’re ready.';
112
+ const buttonLabel = proofOnly ? 'Review the proof' : approvalFirst ? 'Review and approve' : `View and pay ${money}${taxAtPayment ? ' plus tax' : ''}`;
105
113
  const message = input.message.trim();
106
114
  const tokens = {
107
115
  'quote.subject': input.subject,
116
+ 'quote.label': label,
108
117
  'quote.number': number,
109
118
  'quote.revision': String(revision),
110
119
  'quote.total': total,
@@ -121,7 +130,7 @@ const plural = (count, one, many)=>`${count} ${count === 1 ? one : many}`;
121
130
  heading,
122
131
  intro,
123
132
  message,
124
- `Quote: ${number}\nRevision: ${revision}\nTotal: ${total}`,
133
+ `${label}: ${number}\nRevision: ${revision}${total ? `\nTotal: ${total}` : ''}`,
125
134
  pictured.length ? `Proof: ${joinNames(pictured.map((proof)=>proof.name))}` : '',
126
135
  proofFiles,
127
136
  nextStep,
@@ -131,7 +140,8 @@ const plural = (count, one, many)=>`${count} ${count === 1 ? one : many}`;
131
140
  return {
132
141
  tokens,
133
142
  text,
134
- approvalFirst
143
+ approvalFirst,
144
+ proofOnly
135
145
  };
136
146
  }
137
147
  /** The space between two pictures side by side, in px. */ const IMAGE_GAP = 12;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/utils/quote-email-content.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n currentQuoteProofs,\n formatOrderMoney,\n formatQuoteNumber,\n quotePaymentBlockedByApproval,\n quotePayTax,\n quoteSendIsNewRevision,\n type HostOrder,\n type OrderQuote,\n type PayLinkStore,\n} from '../model'\nimport { escapeHtml } from './escape-html'\n\n/*==========================================\n * WHAT THE QUOTE EMAIL SAYS (AGL-4097).\n *\n * The `quote-sent` catalog email's tokens, composed per send: its heading,\n * what this email is (a quote, or an updated revision of one the customer was\n * already emailed: `quoteSendIsNewRevision`, read off the sends on record\n * before this one, so a first email or a resend never says \"updated\"), the business's\n * own message, the quote's number, revision and total, up to three proof\n * images, the other proof files by name, what to do next and the button. The\n * next step and the button follow the business's approval control\n * (`quotePaymentBlockedByApproval`): while the customer must approve the\n * proof first, the button is \"Review and approve\"; otherwise it is \"View and\n * pay\" with the total. Both go to the quote's pay link, where the customer\n * does either.\n *\n * Prices appear only in the tokens the catalog names for them\n * (`quote.total`, `quote.buttonLabel`); the composed markup\n * (`quote.proofImages`) carries pictures and file names, nothing else.\n *\n * Pure: the send route and the sample renders call the same function.\n *=========================================*/\n\n/** The catalog key the quote email is sent and designed under. */\nexport const QUOTE_EMAIL_KEY = 'quote-sent'\n\n/** The most proof images drawn in the email; the rest are named. */\nexport const QUOTE_EMAIL_MAX_IMAGES = 3\n\n/**\n * The column's inner width in the built-in copy: the 600px column less the\n * section's padding on each side.\n */\nexport const QUOTE_EMAIL_IMAGE_WIDTH = 552\n\n/**\n * Pictures every inbox draws. WebP is left to the quote page, where it shows:\n * Outlook for Windows draws no WebP.\n */\nconst EMAIL_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif'])\n\n/** The most file names listed before \"and N more\". */\nconst MAX_NAMED_FILES = 5\n\n/** The theme's colors the composed markup draws with, resolved by the sender. */\nexport interface QuoteEmailColors {\n /** The images' outline: the theme's divider. */\n border: string\n /** The caption under each image: the theme's secondary text. */\n muted: string\n}\n\nexport interface QuoteEmailContentInput {\n /** The quote as this email finds it: its `quote.sends` are the emails before this one. */\n order: HostOrder\n quoteId: string\n businessName: string\n currency: string\n /** The subject the email goes under. */\n subject: string\n /** The business's message, as typed; may be empty. */\n message: string\n /** The quote's pay link, at the version this email carries. */\n payUrl: string\n /** A proof's address behind that link, or null when it has none. */\n proofUrl: (proofId: string) => string | null\n /** This email gives the customer a new pay link, and the earlier email's no longer opens the quote. */\n linkReplaced: boolean\n colors: QuoteEmailColors\n /** The theme's corner radius in px, for the images. */\n radius?: number\n /** The store's sales tax choice, which a quote saved before it was made takes (`quotePayTax`). */\n store?: PayLinkStore | null\n}\n\nexport interface QuoteEmailContent {\n /** The catalog email's merge tokens. */\n tokens: Record<string, string>\n /** The same email as plain text, for a send whose design cannot be rendered. */\n text: string\n /** The customer approves the proof before they can pay: the button reads \"Review and approve\". */\n approvalFirst: boolean\n}\n\n/** `a`, `a and b`, `a, b and c`. */\nfunction joinNames(names: readonly string[]): string {\n if (names.length <= 1) return names.join('')\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`\n}\n\nconst plural = (count: number, one: string, many: string) => `${count} ${count === 1 ? one : many}`\n\n/** The quote email's tokens and its plain-text twin. */\nexport function quoteEmailContent(input: QuoteEmailContentInput): QuoteEmailContent {\n const { order, businessName } = input\n const quote = (order.quote ?? {}) as OrderQuote\n const business = businessName.trim() || 'the business'\n const revision = Math.max(1, Math.floor(Number(quote.revision ?? 1)) || 1)\n const number = formatQuoteNumber(order, input.quoteId).replace(/^Quote\\s+/, '')\n const taxAtPayment = quotePayTax(quote, input.store).basis.kind === 'at-payment'\n const money = formatOrderMoney(Number(order.totals?.totalCents ?? 0), input.currency)\n const total = taxAtPayment ? `${money} before tax` : money\n const approvalFirst = quotePaymentBlockedByApproval(quote)\n\n // The proofs: pictures an inbox draws, up to three, then every other file by name.\n const proofs = currentQuoteProofs(quote)\n const pictured: Array<{ name: string; url: string }> = []\n const named: string[] = []\n let morePictures = 0\n for (const proof of proofs) {\n const url = EMAIL_IMAGE_TYPES.has(String(proof.contentType ?? '').toLowerCase()) ? input.proofUrl(proof.id) : null\n if (url && pictured.length < QUOTE_EMAIL_MAX_IMAGES) pictured.push({ name: proof.name, url })\n else if (url) morePictures += 1\n else named.push(proof.name)\n }\n const listed = named.slice(0, MAX_NAMED_FILES)\n const overflow = named.length - listed.length + morePictures\n const parts = [...listed, ...(overflow > 0 ? [`${plural(overflow, 'more file', 'more files')}`] : [])]\n const lead = pictured.length ? 'Also with this revision' : named.length === 1 ? 'Proof' : 'Proofs'\n const seeIt = named.length + morePictures === 1 ? 'See it on your quote page.' : 'See them on your quote page.'\n const proofFiles = parts.length ? `${lead}: ${joinNames(parts)}. ${seeIt}` : ''\n\n const radius = Math.max(0, Math.round(Number(input.radius ?? 4)) || 0)\n const proofImages = proofImagesHtml(pictured, input.payUrl, input.colors, radius)\n\n const updated = quoteSendIsNewRevision(quote)\n const heading = updated ? 'Your updated quote' : businessName.trim() ? `Your quote from ${businessName.trim()}` : 'Your quote'\n const intro = updated\n ? `${capitalize(business)} updated your quote. This is revision ${revision}, and it replaces the one sent before.` +\n (input.linkReplaced ? ' The link in the earlier email no longer opens the quote, so use the button below.' : '') +\n ' The new version is attached as a PDF.'\n : `${capitalize(business)} put together a quote for you. The details are below, and the quote is attached as a PDF.`\n\n const proofed = proofs.length > 0\n const approved = proofed && Number(quote.approvedRevision) === revision\n const nextStep = approvalFirst\n ? 'Look over the proof, then approve it on your quote page. Once you approve it, you can pay there.'\n : approved\n ? 'You approved the proof. Pay on your quote page whenever you’re ready.'\n : proofed\n ? 'Look over your quote and the proof. On your quote page you can approve the proof or ask for changes, and pay whenever you’re ready.'\n : 'Look over your quote, and pay it on your quote page whenever you’re ready.'\n const buttonLabel = approvalFirst ? 'Review and approve' : `View and pay ${money}${taxAtPayment ? ' plus tax' : ''}`\n const message = input.message.trim()\n\n const tokens: Record<string, string> = {\n 'quote.subject': input.subject,\n 'quote.number': number,\n 'quote.revision': String(revision),\n 'quote.total': total,\n 'quote.heading': heading,\n 'quote.intro': intro,\n 'quote.message': message,\n 'quote.proofImages': proofImages,\n 'quote.proofFiles': proofFiles,\n 'quote.nextStep': nextStep,\n 'quote.buttonLabel': buttonLabel,\n 'quote.url': input.payUrl,\n }\n\n const text = [\n heading,\n intro,\n message,\n `Quote: ${number}\\nRevision: ${revision}\\nTotal: ${total}`,\n pictured.length ? `Proof: ${joinNames(pictured.map((proof) => proof.name))}` : '',\n proofFiles,\n nextStep,\n `${buttonLabel}: ${input.payUrl}`,\n `Reply to this email to reach ${business}.`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n return { tokens, text, approvalFirst }\n}\n\n/** The space between two pictures side by side, in px. */\nconst IMAGE_GAP = 12\n\n/**\n * The proof pictures, each linked to the quote page with its file name under\n * it: one across the column, or two or three side by side, so the button\n * stays near. A table, the layout every inbox keeps.\n */\nfunction proofImagesHtml(\n pictured: ReadonlyArray<{ name: string; url: string }>,\n payUrl: string,\n colors: QuoteEmailColors,\n radius: number,\n): string {\n if (!pictured.length) return ''\n const count = pictured.length\n const width = Math.floor((QUOTE_EMAIL_IMAGE_WIDTH - IMAGE_GAP * (count - 1)) / count)\n const cells = pictured.map((proof, index) => {\n const left = index === 0 ? 0 : IMAGE_GAP / 2\n const right = index === count - 1 ? 0 : IMAGE_GAP / 2\n return (\n `<td style=\"width:${Math.round(100 / count)}%;vertical-align:top;padding:4px ${right}px 12px ${left}px;\">` +\n `<a href=\"${escapeHtml(payUrl)}\">` +\n `<img src=\"${escapeHtml(proof.url)}\" alt=\"${escapeHtml(`Proof: ${proof.name}`)}\" width=\"${width}\" ` +\n `style=\"display:block;width:100%;max-width:${width}px;height:auto;box-sizing:border-box;` +\n `border:1px solid ${colors.border};border-radius:${radius}px;\" />` +\n `</a>` +\n `<div style=\"font-size:13px;line-height:1.4;color:${colors.muted};padding-top:6px;word-break:break-word;\">${escapeHtml(proof.name)}</div>` +\n `</td>`\n )\n })\n return (\n `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\">` +\n `<tr>${cells.join('')}</tr>` +\n `</table>`\n )\n}\n\nfunction capitalize(value: string): string {\n return value ? value[0].toUpperCase() + value.slice(1) : value\n}\n"],"names":["currentQuoteProofs","formatOrderMoney","formatQuoteNumber","quotePaymentBlockedByApproval","quotePayTax","quoteSendIsNewRevision","escapeHtml","QUOTE_EMAIL_KEY","QUOTE_EMAIL_MAX_IMAGES","QUOTE_EMAIL_IMAGE_WIDTH","EMAIL_IMAGE_TYPES","Set","MAX_NAMED_FILES","joinNames","names","length","join","slice","plural","count","one","many","quoteEmailContent","input","order","quote","businessName","business","trim","revision","Math","max","floor","Number","number","quoteId","replace","taxAtPayment","store","basis","kind","money","totals","totalCents","currency","total","approvalFirst","proofs","pictured","named","morePictures","proof","url","has","String","contentType","toLowerCase","proofUrl","id","push","name","listed","overflow","parts","lead","seeIt","proofFiles","radius","round","proofImages","proofImagesHtml","payUrl","colors","updated","heading","intro","capitalize","linkReplaced","proofed","approved","approvedRevision","nextStep","buttonLabel","message","tokens","subject","text","map","filter","Boolean","IMAGE_GAP","width","cells","index","left","right","border","muted","value","toUpperCase"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,EACjBC,6BAA6B,EAC7BC,WAAW,EACXC,sBAAsB,QAIjB,oBAAU;AACjB,SAASC,UAAU,QAAQ,mBAAe;AAE1C;;;;;;;;;;;;;;;;;;;;2CAoB2C,GAE3C,gEAAgE,GAChE,OAAO,MAAMC,kBAAkB,aAAY;AAE3C,kEAAkE,GAClE,OAAO,MAAMC,yBAAyB,EAAC;AAEvC;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,IAAG;AAE1C;;;CAGC,GACD,MAAMC,oBAAoB,IAAIC,IAAI;IAAC;IAAa;IAAc;CAAY;AAE1E,oDAAoD,GACpD,MAAMC,kBAAkB;AA0CxB,kCAAkC,GAClC,SAASC,UAAUC,KAAwB;IACzC,IAAIA,MAAMC,MAAM,IAAI,GAAG,OAAOD,MAAME,IAAI,CAAC;IACzC,OAAO,GAAGF,MAAMG,KAAK,CAAC,GAAG,CAAC,GAAGD,IAAI,CAAC,MAAM,KAAK,EAAEF,KAAK,CAACA,MAAMC,MAAM,GAAG,EAAE,EAAE;AAC1E;AAEA,MAAMG,SAAS,CAACC,OAAeC,KAAaC,OAAiB,GAAGF,MAAM,CAAC,EAAEA,UAAU,IAAIC,MAAMC,MAAM;AAEnG,sDAAsD,GACtD,OAAO,SAASC,kBAAkBC,KAA6B;QAE9CC,cAEgCC,uBAyBFF;QAtBPC;IANtC,MAAM,EAAEA,KAAK,EAAEE,YAAY,EAAE,GAAGH;IAChC,MAAME,SAASD,eAAAA,MAAMC,KAAK,YAAXD,eAAe,CAAC;IAC/B,MAAMG,WAAWD,aAAaE,IAAI,MAAM;IACxC,MAAMC,WAAWC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACC,QAAOR,kBAAAA,MAAMI,QAAQ,YAAd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EAAE,CAAC,GACnG,CAAC,0CAA0C,EAAEA,MAAM,qCAAqC,CAAC,GACzF,CAAC,iBAAiB,EAAEnB,OAAOwB,MAAM,CAAC,eAAe,EAAE7B,OAAO,OAAO,CAAC,GAClE,CAAC,IAAI,CAAC,GACN,CAAC,iDAAiD,EAAEK,OAAOyB,KAAK,CAAC,yCAAyC,EAAE3F,WAAW6C,MAAMS,IAAI,EAAE,MAAM,CAAC,GAC1I,CAAC,KAAK,CAAC;IAEX;IACA,OACE,CAAC,wEAAwE,CAAC,GAC1E,CAAC,IAAI,EAAEgC,MAAM5E,IAAI,CAAC,IAAI,KAAK,CAAC,GAC5B,CAAC,QAAQ,CAAC;AAEd;AAEA,SAAS4D,WAAWsB,KAAa;IAC/B,OAAOA,QAAQA,KAAK,CAAC,EAAE,CAACC,WAAW,KAAKD,MAAMjF,KAAK,CAAC,KAAKiF;AAC3D"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/utils/quote-email-content.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n currentQuoteProofs,\n formatOrderMoney,\n formatQuoteNumber,\n quoteIsProofOnly,\n quotePaymentBlockedByApproval,\n quotePayTax,\n quoteSendIsNewRevision,\n type HostOrder,\n type OrderQuote,\n type PayLinkStore,\n} from '../model'\nimport { escapeHtml } from './escape-html'\n\n/*==========================================\n * WHAT THE QUOTE EMAIL SAYS (AGL-4097).\n *\n * The `quote-sent` catalog email's tokens, composed per send: its heading,\n * what this email is (a quote, or an updated revision of one the customer was\n * already emailed: `quoteSendIsNewRevision`, read off the sends on record\n * before this one, so a first email or a resend never says \"updated\"), the business's\n * own message, the quote's number, revision and total, up to three proof\n * images, the other proof files by name, what to do next and the button. The\n * next step and the button follow the business's approval control\n * (`quotePaymentBlockedByApproval`): while the customer must approve the\n * proof first, the button is \"Review and approve\"; otherwise it is \"View and\n * pay\" with the total. Both go to the quote's pay link, where the customer\n * does either.\n *\n * A PROOF ONLY quote (no lines, AGL-4184) says so in the same tokens: \"Your\n * proof from …\", what to do with the proof, \"Review the proof\", `quote.label`\n * \"Proof\", and an empty `quote.total`, whose row a details panel then does not\n * draw. No PDF goes with it (`quote-email.ts`): its proof is the whole of it.\n *\n * Prices appear only in the tokens the catalog names for them\n * (`quote.total`, `quote.buttonLabel`); the composed markup\n * (`quote.proofImages`) carries pictures and file names, nothing else.\n *\n * Pure: the send route and the sample renders call the same function.\n *=========================================*/\n\n/** The catalog key the quote email is sent and designed under. */\nexport const QUOTE_EMAIL_KEY = 'quote-sent'\n\n/** The most proof images drawn in the email; the rest are named. */\nexport const QUOTE_EMAIL_MAX_IMAGES = 3\n\n/**\n * The column's inner width in the built-in copy: the 600px column less the\n * section's padding on each side.\n */\nexport const QUOTE_EMAIL_IMAGE_WIDTH = 552\n\n/**\n * Pictures every inbox draws. WebP is left to the quote page, where it shows:\n * Outlook for Windows draws no WebP.\n */\nconst EMAIL_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif'])\n\n/** The most file names listed before \"and N more\". */\nconst MAX_NAMED_FILES = 5\n\n/** The theme's colors the composed markup draws with, resolved by the sender. */\nexport interface QuoteEmailColors {\n /** The images' outline: the theme's divider. */\n border: string\n /** The caption under each image: the theme's secondary text. */\n muted: string\n}\n\nexport interface QuoteEmailContentInput {\n /** The quote as this email finds it: its `quote.sends` are the emails before this one. */\n order: HostOrder\n quoteId: string\n businessName: string\n currency: string\n /** The subject the email goes under. */\n subject: string\n /** The business's message, as typed; may be empty. */\n message: string\n /** The quote's pay link, at the version this email carries. */\n payUrl: string\n /** A proof's address behind that link, or null when it has none. */\n proofUrl: (proofId: string) => string | null\n /** This email gives the customer a new pay link, and the earlier email's no longer opens the quote. */\n linkReplaced: boolean\n colors: QuoteEmailColors\n /** The theme's corner radius in px, for the images. */\n radius?: number\n /** The store's sales tax choice, which a quote saved before it was made takes (`quotePayTax`). */\n store?: PayLinkStore | null\n}\n\nexport interface QuoteEmailContent {\n /** The catalog email's merge tokens. */\n tokens: Record<string, string>\n /** The same email as plain text, for a send whose design cannot be rendered. */\n text: string\n /** The customer approves the proof before they can pay: the button reads \"Review and approve\". */\n approvalFirst: boolean\n /** A proof with no price yet: nothing to pay, and no PDF goes with it. */\n proofOnly: boolean\n}\n\n/** `a`, `a and b`, `a, b and c`. */\nfunction joinNames(names: readonly string[]): string {\n if (names.length <= 1) return names.join('')\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`\n}\n\nconst plural = (count: number, one: string, many: string) => `${count} ${count === 1 ? one : many}`\n\n/** The quote email's tokens and its plain-text twin. */\nexport function quoteEmailContent(input: QuoteEmailContentInput): QuoteEmailContent {\n const { order, businessName } = input\n const quote = (order.quote ?? {}) as OrderQuote\n const business = businessName.trim() || 'the business'\n const revision = Math.max(1, Math.floor(Number(quote.revision ?? 1)) || 1)\n const number = formatQuoteNumber(order, input.quoteId).replace(/^Quote\\s+/, '')\n const proofOnly = quoteIsProofOnly(order)\n const noun = proofOnly ? 'proof' : 'quote'\n const label = proofOnly ? 'Proof' : 'Quote'\n const taxAtPayment = quotePayTax(quote, input.store).basis.kind === 'at-payment'\n const money = formatOrderMoney(Number(order.totals?.totalCents ?? 0), input.currency)\n const total = proofOnly ? '' : taxAtPayment ? `${money} before tax` : money\n const approvalFirst = !proofOnly && quotePaymentBlockedByApproval(quote)\n\n // The proofs: pictures an inbox draws, up to three, then every other file by name.\n const proofs = currentQuoteProofs(quote)\n const pictured: Array<{ name: string; url: string }> = []\n const named: string[] = []\n let morePictures = 0\n for (const proof of proofs) {\n const url = EMAIL_IMAGE_TYPES.has(String(proof.contentType ?? '').toLowerCase()) ? input.proofUrl(proof.id) : null\n if (url && pictured.length < QUOTE_EMAIL_MAX_IMAGES) pictured.push({ name: proof.name, url })\n else if (url) morePictures += 1\n else named.push(proof.name)\n }\n const listed = named.slice(0, MAX_NAMED_FILES)\n const overflow = named.length - listed.length + morePictures\n const parts = [...listed, ...(overflow > 0 ? [`${plural(overflow, 'more file', 'more files')}`] : [])]\n const lead = pictured.length ? 'Also with this revision' : named.length === 1 ? 'Proof' : 'Proofs'\n const seeIt = named.length + morePictures === 1 ? `See it on your ${noun} page.` : `See them on your ${noun} page.`\n const proofFiles = parts.length ? `${lead}: ${joinNames(parts)}. ${seeIt}` : ''\n\n const radius = Math.max(0, Math.round(Number(input.radius ?? 4)) || 0)\n const proofImages = proofImagesHtml(pictured, input.payUrl, input.colors, radius)\n\n const updated = quoteSendIsNewRevision(quote)\n const heading = updated ? `Your updated ${noun}` : businessName.trim() ? `Your ${noun} from ${businessName.trim()}` : `Your ${noun}`\n const intro = updated\n ? `${capitalize(business)} updated your ${noun}. This is revision ${revision}, and it replaces the one sent before.` +\n (input.linkReplaced ? ` The link in the earlier email no longer opens the ${noun}, so use the button below.` : '') +\n (proofOnly ? '' : ' The new version is attached as a PDF.')\n : proofOnly\n ? `${capitalize(business)} sent you a proof to look over.`\n : `${capitalize(business)} put together a quote for you. The details are below, and the quote is attached as a PDF.`\n\n const proofed = proofs.length > 0\n const approved = proofed && Number(quote.approvedRevision) === revision\n const nextStep = proofOnly\n ? approved\n ? 'You approved this proof. You can still ask for changes on your proof page.'\n : 'Look over the proof, then approve it or ask for changes on your proof page.'\n : approvalFirst\n ? 'Look over the proof, then approve it on your quote page. Once you approve it, you can pay there.'\n : approved\n ? 'You approved the proof. Pay on your quote page whenever you’re ready.'\n : proofed\n ? 'Look over your quote and the proof. On your quote page you can approve the proof or ask for changes, and pay whenever you’re ready.'\n : 'Look over your quote, and pay it on your quote page whenever you’re ready.'\n const buttonLabel = proofOnly\n ? 'Review the proof'\n : approvalFirst\n ? 'Review and approve'\n : `View and pay ${money}${taxAtPayment ? ' plus tax' : ''}`\n const message = input.message.trim()\n\n const tokens: Record<string, string> = {\n 'quote.subject': input.subject,\n 'quote.label': label,\n 'quote.number': number,\n 'quote.revision': String(revision),\n 'quote.total': total,\n 'quote.heading': heading,\n 'quote.intro': intro,\n 'quote.message': message,\n 'quote.proofImages': proofImages,\n 'quote.proofFiles': proofFiles,\n 'quote.nextStep': nextStep,\n 'quote.buttonLabel': buttonLabel,\n 'quote.url': input.payUrl,\n }\n\n const text = [\n heading,\n intro,\n message,\n `${label}: ${number}\\nRevision: ${revision}${total ? `\\nTotal: ${total}` : ''}`,\n pictured.length ? `Proof: ${joinNames(pictured.map((proof) => proof.name))}` : '',\n proofFiles,\n nextStep,\n `${buttonLabel}: ${input.payUrl}`,\n `Reply to this email to reach ${business}.`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n return { tokens, text, approvalFirst, proofOnly }\n}\n\n/** The space between two pictures side by side, in px. */\nconst IMAGE_GAP = 12\n\n/**\n * The proof pictures, each linked to the quote page with its file name under\n * it: one across the column, or two or three side by side, so the button\n * stays near. A table, the layout every inbox keeps.\n */\nfunction proofImagesHtml(\n pictured: ReadonlyArray<{ name: string; url: string }>,\n payUrl: string,\n colors: QuoteEmailColors,\n radius: number,\n): string {\n if (!pictured.length) return ''\n const count = pictured.length\n const width = Math.floor((QUOTE_EMAIL_IMAGE_WIDTH - IMAGE_GAP * (count - 1)) / count)\n const cells = pictured.map((proof, index) => {\n const left = index === 0 ? 0 : IMAGE_GAP / 2\n const right = index === count - 1 ? 0 : IMAGE_GAP / 2\n return (\n `<td style=\"width:${Math.round(100 / count)}%;vertical-align:top;padding:4px ${right}px 12px ${left}px;\">` +\n `<a href=\"${escapeHtml(payUrl)}\">` +\n `<img src=\"${escapeHtml(proof.url)}\" alt=\"${escapeHtml(`Proof: ${proof.name}`)}\" width=\"${width}\" ` +\n `style=\"display:block;width:100%;max-width:${width}px;height:auto;box-sizing:border-box;` +\n `border:1px solid ${colors.border};border-radius:${radius}px;\" />` +\n `</a>` +\n `<div style=\"font-size:13px;line-height:1.4;color:${colors.muted};padding-top:6px;word-break:break-word;\">${escapeHtml(proof.name)}</div>` +\n `</td>`\n )\n })\n return (\n `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\">` +\n `<tr>${cells.join('')}</tr>` +\n `</table>`\n )\n}\n\nfunction capitalize(value: string): string {\n return value ? value[0].toUpperCase() + value.slice(1) : value\n}\n"],"names":["currentQuoteProofs","formatOrderMoney","formatQuoteNumber","quoteIsProofOnly","quotePaymentBlockedByApproval","quotePayTax","quoteSendIsNewRevision","escapeHtml","QUOTE_EMAIL_KEY","QUOTE_EMAIL_MAX_IMAGES","QUOTE_EMAIL_IMAGE_WIDTH","EMAIL_IMAGE_TYPES","Set","MAX_NAMED_FILES","joinNames","names","length","join","slice","plural","count","one","many","quoteEmailContent","input","order","quote","businessName","business","trim","revision","Math","max","floor","Number","number","quoteId","replace","proofOnly","noun","label","taxAtPayment","store","basis","kind","money","totals","totalCents","currency","total","approvalFirst","proofs","pictured","named","morePictures","proof","url","has","String","contentType","toLowerCase","proofUrl","id","push","name","listed","overflow","parts","lead","seeIt","proofFiles","radius","round","proofImages","proofImagesHtml","payUrl","colors","updated","heading","intro","capitalize","linkReplaced","proofed","approved","approvedRevision","nextStep","buttonLabel","message","tokens","subject","text","map","filter","Boolean","IMAGE_GAP","width","cells","index","left","right","border","muted","value","toUpperCase"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,iBAAiB,EACjBC,gBAAgB,EAChBC,6BAA6B,EAC7BC,WAAW,EACXC,sBAAsB,QAIjB,oBAAU;AACjB,SAASC,UAAU,QAAQ,mBAAe;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;2CAyB2C,GAE3C,gEAAgE,GAChE,OAAO,MAAMC,kBAAkB,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