<!-- SPDX-License-Identifier: CC-BY-4.0 -->

# PTDF 1.0 reference validator and renderer

The pasteToPrint repository publishes the browser- and Node-compatible PTDF
1.0 reference implementation under the MIT License.

## Files

- `/assets/js/document-templates.js` — stable template catalog dependency,
- `/assets/js/qr.js` — local QR renderer used by `qr_code`,
- `/assets/js/document-schema.js` — validator, normalizer and HTML renderer,
- `/assets/css/ptdf.css` — reference PTDF block and preview styles.

The exact licensing boundary and license texts are in
[`PTDF-LICENSE.md`](PTDF-LICENSE.md).

## Browser usage

Load the scripts in dependency order:

```html
<link rel="stylesheet" href="/assets/css/ptdf.css">
<script src="/assets/js/document-templates.js"></script>
<script src="/assets/js/qr.js"></script>
<script src="/assets/js/document-schema.js"></script>
```

Then validate and render:

```js
const validation = PasteToPrintDocumentSchema.validate(ptdfDocument);

if (!validation.valid) {
  console.error(validation.errors);
} else {
  const rendered = PasteToPrintDocumentSchema.render(validation.document);
  window.document.querySelector('#preview').innerHTML = rendered.html;
}
```

`render()` validates and normalizes the document before producing HTML. Text is
escaped, links are restricted to supported protocols, images are local Data
URLs, and QR codes are generated locally.

Validation is canonical and does not silently trim string values. String limits
count Unicode code points consistently in browser, Node and PHP implementations.
The renderer also enforces the schema's required `x-ptdf-calendarDate`,
`x-ptdf-maxUtf8Bytes` and `x-ptdf-validBase64` assertions.

## Node usage

```js
const PTDF = require('./assets/js/document-schema.js');

const validation = PTDF.validate(ptdfDocument);
if (!validation.valid) {
  throw new Error(validation.errors[0].message);
}

const html = PTDF.renderHtml(validation.document);
```

The CommonJS entry point automatically loads the template catalog and local QR
dependency from the same directory.

## Public API

The global/CommonJS export contains:

- `VERSION`, `FORMAT_NAME`, `FORMAT_VERSION` and `LIMITS`,
- `BLOCK_TYPES`, `PAPER_SIZES` and `TEMPLATE_IDS`,
- `isDocument(value)`,
- `validate(value)`,
- `normalize(value)`,
- `render(value)`,
- `renderHtml(value)`.

The shared JavaScript/PHP boundary corpus is published as
`/tests/fixtures/ptdf-1.0-conformance.json`.

The renderer returns normalized `paper.orientation` and `template` values to
the caller. The current revision supports both `portrait` and `landscape`, plus
the six `coloring_*` IDs published by Template Catalog v1. A producer targeting
an unknown receiver uses `portrait` and `blank`; it does not infer support from
the PTDF 1.0 name alone.

Two complete renderer inputs are published as
[`landscape-example.json`](api/document-schema/v1/landscape-example.json) and
[`coloring-drawing-example.json`](api/document-schema/v1/coloring-drawing-example.json).
The latter contains only the raster fallback and a reader-facing explanation;
editable drawing project data is intentionally absent.

The editor-side serializer in `/assets/js/ptdf.js` converts an editable
`figure.print-drawing` to a standard raster `image` block. It emits the
`drawingFlattened` warning and never copies the drawing project ID, layers,
history or `ptp.drawing/1` data into the PTDF document. Supported image scale,
alignment and alternative text are retained; page-specific positioning emits
the separate `positionedImageFlattened` warning.

The reference renderer demonstrates PTDF conformance. It does not perform
printing, PDF export, sending, signing, payment or permanent storage.
