floorplan-diff
v0.1.1
Published
Node library to compare two floor plan buffers and return change points and regions.
Maintainers
Readme
floorplan-diff
Node library for comparing two floor plan PDF buffers and returning differences as normalized points and regions.
Installation
npm install floorplan-diffRuntime requirements
- Node.js
>=20.16. - In Node environments, install
@napi-rs/canvasin the host app to ensure PDF rendering compatibility:
npm install @napi-rs/canvasUsage
import { compareFloorPlans } from 'floorplan-diff';
const result = await compareFloorPlans({
baseBuffer,
compareBuffer,
options: {
includeRegions: true,
includePoints: true,
},
});For CommonJS hosts:
const { compareFloorPlans } = require('floorplan-diff');Input format
- PDF buffers only.
- If a different format is provided, the library throws
UNSUPPORTED_BUFFER_FORMAT.
Result
{
points: [
{ x: 0.52, y: 0.31 }
],
regions: [
{ x: 0.5, y: 0.25, width: 0.1, height: 0.12, cx: 0.55, cy: 0.31 }
],
summary: {
changedPixels: 512,
totalPixels: 102400,
changePercent: 0.5,
pointsCount: 1,
regionsCount: 1
}
}API
compareFloorPlans({ baseBuffer, compareBuffer, options })isPdfBuffer(buffer)convertFirstPagePdfToPng(pdfBuffer, scale?)
Errors
The library throws PlanDiffError with this structure:
{
name: 'PlanDiffError',
code: 'PDF_PAGE_SIZE_MISMATCH',
message: 'Cannot compare PDFs with different page sizes',
details: { ... }
}Main error codes:
INVALID_BUFFERUNSUPPORTED_BUFFER_FORMATPDF_PARSE_ERRORPDF_PAGE_SIZE_MISMATCHPDF_PAGE_ORIENTATION_MISMATCHIMAGE_DECODE_ERRORINTERNAL_PROCESSING_ERROR
Notes
- Coordinates are normalized to the
[0, 1]range. - If no changes are detected, the library returns empty arrays.
npm run buildgenerates both ESM output (dist/index.js) and a CJS-compatible entrypoint (dist/index.cjs) used byexports.require.
