A sample closeout PDF has a before photo for work-order line WO-02 and an empty after slot. The companion CSV flags that same line for review. A sample wholesale order form has SKU CEDAR-8 at $12.00 for boutiques and $10.20 for distributors. The buyer gets only their group's price.
Both jobs start with a local file picker. The browser turns the input into records, runs checks on those records, and produces a file the operator can inspect before sending. Canvas transforms, Web Crypto digests, GS1 check digits, and CSV quoting can all run without npm packages. The production workbenches use React for the UI and pdf-lib for direct PDF downloads. Both request an export permit using project IDs, counts, and export metadata, then render the file locally from the draft.
Field closeout starts with the work-order line
CloseoutPack attaches the before and after photos to a numbered line with a scope and status. Its JPEG normalizer reads EXIF orientation and capture time, removes the EXIF segments from the bytes passed to the decoder, and applies the orientation once on Canvas. That prevents a browser that honors EXIF from rotating the same image a second time. The workbench caps the rendered long edge at 1,400 pixels, encodes a JPEG, and closes the decoded bitmap. The capture time travels as a separate field for the audit. The picker accepts JPEG, PNG, and WebP, so an iPhone HEIC original needs a supported copy.
The audit compares the timestamps when both are parseable. If Before is later than After, it flags a possible swap for review. Missing timestamps leave the order to the operator. The same line number anchors the photo pair in the US Letter PDF and the findings in the open-items CSV. CloseoutPack · WHATWG Canvas specification
The browser-only example below lets the decoder apply embedded orientation. Serve it on HTTPS or localhost. Pass a local image File to localJpeg. Hash the input for an exact-byte repeat check, or hash the generated JPEG to identify that exact export. Run await sha256Test() to check the digest against a known value.
async function localJpeg(file) {
if (!file.size || file.size > 24 * 1024 * 1024) {
throw new Error("Choose a nonempty image up to 24 MiB")
}
const bitmap = await createImageBitmap(file, { imageOrientation: "from-image" })
try {
const scale = Math.min(1, 1400 / Math.max(bitmap.width, bitmap.height))
const canvas = document.createElement("canvas")
canvas.width = Math.max(1, Math.round(bitmap.width * scale))
canvas.height = Math.max(1, Math.round(bitmap.height * scale))
const ctx = canvas.getContext("2d", { alpha: false })
if (!ctx) throw new Error("Canvas is unavailable")
ctx.fillStyle = "#fff"
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height)
const jpeg = await new Promise(resolve => canvas.toBlob(resolve, "image/jpeg", 0.82))
if (!jpeg || jpeg.type !== "image/jpeg") throw new Error("JPEG encoding failed")
return jpeg
} finally {
bitmap.close()
}
}
async function sha256Hex(blob) {
const digest = await crypto.subtle.digest("SHA-256", await blob.arrayBuffer())
return Array.from(new Uint8Array(digest), byte =>
byte.toString(16).padStart(2, "0")
).join("")
}
const sha256Test = async () =>
(await sha256Hex(new Blob(["abc"]))) ===
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
SHA-256 is a reference pattern here for a local duplicate check or export manifest. The CloseoutPack audit uses line IDs, photo presence, status, and timestamps. Two encodes of the same scene can produce different bytes. A digest identifies bytes and provides no evidence of when or where the photo was taken. Decode and hash one photo at a time on mobile. A 4,000 × 3,000 RGBA buffer alone is 48,000,000 bytes, and Web Crypto's digest() takes the full input in memory. Web Cryptography API
The paperwork around the report has its own rounding and filtering rules.
- JobQuote rounds each line extension to cents, then rounds each row's tax. Its HVAC fixture totals $334.75 plus $5.92 tax for $340.67. A 30% deposit rounds to $102.20, leaving $238.47. JobQuote
- PunchList calculates completion across the board and exports the rows visible under both filters. In its starter fixture, 1 of 5 rows is done. Selecting Open and High exports one row. PunchList
- InvCalc applies a selected late fee once to overdue unpaid principal. Its $1,405.75 invoice less a $450.00 deposit leaves $955.75. Seven days overdue activates the 2.50% fee in the fixture, adding $23.89 for $979.64 due. InvCalc
For a standalone photo appendix, seven photos at four per page use two Letter pages, split 4 + 3. The photo-sheet tool prints through the browser's Save as PDF dialog. Photo Sheet Builder
Wholesale export starts with one row per variant
LineSheetPack reads the Shopify or ordinary CSV with File.text(). Its parser handles commas and line breaks inside quoted cells, then maps modern or legacy headers into typed catalog rows. Keep a Shopify product export as the source and identify each sellable variant by SKU in the buyer catalog. An image-only continuation row belongs to the product's media. Counting it as a variant inflates the assortment. Shopify product CSV reference · RFC 4180
For each buyer group, select its assortment, resolve the per-SKU override or the group's discount, then render the PDF and order CSV from that same selection. The order CSV leaves Order Qty blank for the buyer. Without an override, calculate the discounted unit price once in integer cents.
function discountedCents(cents, discountBps) {
// Nonnegative integer cents and a discount from 0 to 10,000 basis points.
return (cents * (10_000n - discountBps) + 5_000n) / 10_000n
}
discountedCents(1_200n, 1_500n) // 1020n, or $10.20
discountedCents(101n, 5_000n) // 51n, or $0.51
Group A at zero discount stays at $12.00. Group B at 15% uses $10.20. The $1.01 half-price case lands at exactly 50.5 cents and rounds up once. The production code uses bounded safe integers for this calculation. The reference snippet uses BigInt.
An MOQ of 25 with six units per case takes five cases, or 30 units, in MOQ Calc. LineSheetPack flags 25 as incompatible with the pack and expects a corrected minimum such as 30 before export. At a $6.00 landed cost, the $12.00 wholesale offer earns $6.00 gross per unit and $180.00 on 30 units. MOQ Calc · LineSheetPack
Validate identifiers and protect the spreadsheet boundary
Store a GTIN as a string. Starting at the rightmost payload digit, multiply by 3, 1, 3, 1 and continue left. For UPC payload 03600029145, the weighted sum is 58. The check digit is (10 - (58 % 10)) % 10 = 2, yielding 036000291452. After validation, a 14-digit padded key lets a batch detect that 00036000291452 represents the same identifier. The checksum checks composition. Assignment and ownership come from GS1 records. GS1 General Specifications · Barcode Lab GTIN checker
CSV quoting protects the structure of a row. A spreadsheet can still evaluate a quoted cell as a formula after parsing it. LineSheetPack checks the first relevant character of untrusted text, prefixes formula-like values with an apostrophe, and then doubles embedded quotes and wraps the cell. Validated price and quantity fields take a separate numeric path.
function spreadsheetTextCell(value) {
const looksLikeFormula = /^\s*[=+\-@=+-@\t\r\n]/u.test(value)
const text = looksLikeFormula ? "'" + value : value
return '"' + text.replaceAll('"', '""') + '"'
}
spreadsheetTextCell('Cedar, "8 oz"') // '"Cedar, ""8 oz"""'
spreadsheetTextCell(" =1+1") // a quoted cell beginning with an apostrophe
Apply that guard at the export boundary. Keep the source values for review and preserve leading zeroes by importing identifier columns into spreadsheets as text. CSV Clean's variant validator labels an apostrophe-modified file -audit.csv for spreadsheet review. Fix flagged values in the source and regenerate the Shopify import copy. Spreadsheet behavior varies, especially after saving and reopening a CSV. Exercise the guard in the receiving application with a fixture that includes whitespace, quotes, and a harmless formula. OWASP CSV Injection · CSV Clean variant validator
At fulfillment, carry the buyer's PO and SKUs into the packing slip. If one SKU has 24 ordered and 18 packed, and another has 12 ordered and 14 packed, report six short and two extra. Netting those counts would hide two distinct corrections. Pack Slip
Check the boundary with two fixtures
- Give the photo workbench one sideways JPEG and a second line with the After slot empty. Verify the rotation, the flagged line number, and the handoff on an actual phone.
- Give the catalog workbench a quoted multiline title, a leading-zero SKU, and a 25-unit minimum with a six-unit case pack. Correct the minimum to 30 and compare each group's PDF and CSV prices side by side.
- Open the browser's Network panel before feeding either fixture. Inspect requests during import, validation, and export for the fixture bytes. Page loads, analytics, and checkout can make requests. The zero-upload claim here covers the local file-processing path.
Disclosure. This teardown covers tools from our own portfolio. AI assisted the writing.
Top comments (0)