# Frameleaf Image Studio 1.0

An original offline image editor and a reusable browser component. Crop and resize an image, rotate/flip it, adjust its colors, add text, save an editable project and export actual PNG/JPEG/WebP pixels. No runtime framework, account, API key, CDN, upload server or build step.

The optional host-form attachment adapter connects edited images to your own form. The included example prepares two independent image files and inspects FormData locally; it has no upload endpoint. Publication of a revised package remains subject to independent release review.

## Use the editor

Unzip the archive and open `app/index.html` in a modern JavaScript-enabled browser using your approved local access method. Keep the `app` files together. No installation is needed to run the editor. The included Cedar Tea illustration is original synthetic artwork, not a real product photograph or advertisement.

1. Choose **Upload image** for PNG, JPEG or WebP (up to 8 MB, 16 MP, maximum 12000 px per side). Invalid/corrupt images or a project/image-dimension mismatch leave the prior project intact.
2. Choose **Draw crop**, drag on the original source image, then **Apply crop**. You can also use exact X/Y/Width/Height source-image fields. Crop is non-destructive: the original image stays in your JSON. Escape cancels the pending crop.
3. Set output Width or Height, choose whether to Keep aspect ratio, then **Apply size**. **Rotate 90°**, **Flip horizontal** and **Flip vertical** update the image pixels and output dimensions. Cropping operates before rotation and resize.
4. Move Brightness, Contrast, Saturation, Grayscale or Sepia sliders. These operations apply to actual pixel data. The preview is capped at 1400 px on its longest side; export uses the full output dimensions.
5. Choose **+ Add** under Text layers. Edit multiline text, size, color, alignment and X/Y percentages, then **Apply text**. Select a layer in the list or click its rendered text to drag it. Font size is in final-output pixels; normalized positions survive resize. Some text can extend beyond the canvas edges, so inspect your output.
6. Use **Undo/Redo** (40 snapshots). **Reset edits** restores the original image and removes text; Undo can restore the prior state. History shares the immutable background image instead of duplicating its bytes per change.
7. Choose **Save project** for a `.frameleaf.json`. **Open project** restores all image/edits/layers; unsaved replacement requires confirmation. The browser determines the actual download destination. Verify the saved file in your Downloads folder. Project files contain the full original embedded image, so share them only intentionally.
8. Pick PNG, JPEG or WebP in Export settings. PNG preserves transparency. JPEG puts a white background behind transparent pixels. JPEG/WebP quality is adjustable; PNG is lossless. **Export image** requests a real encoded file. Open the downloaded file to verify its dimensions and appearance. Unsupported browser encoders show an error instead of silently changing the file type.

Keyboard shortcuts work while focused inside this editor: Ctrl/⌘ S saves JSON; Ctrl/⌘ Z undoes; Shift + Ctrl/⌘ Z or Ctrl Y redoes; Escape cancels crop/drag; Delete/Backspace removes selected text except while typing. Text fields preserve normal typing behavior. Pointer Events support drawing/dragging, while panels scroll normally. A narrow-viewport visual check does not prove all physical-device touch behavior.

## Embed the same working component

```html
<link rel="stylesheet" href="frameleaf/styles.css">
<div id="image-editor"></div>
<script src="frameleaf/core.js"></script>
<script src="frameleaf/renderer.js"></script>
<script src="frameleaf/frameleaf.js"></script>
<script>
const editor = Frameleaf.mount(document.getElementById('image-editor'), {
  project: myFrameleafProject, // versioned project containing an embedded image
  onChange(project) { /* keep a local draft in your own app if desired */ },
  onExport(result) { console.log(result.width, result.height, result.type); }
});
awaitReady(editor);
async function awaitReady(editor) {
  await editor.ready;
  const output = await editor.exportImage('image/png');
  // output.blob is the actual encoded file; your host controls its delivery.
}
</script>
```

See `samples/embed.html` for a complete original demonstration with an external host button and two independent mountable components. Multiple instances use scoped controls and keyboard events. Styling uses the distinctive `.fl-*` classes and `.frameleaf` root; standalone page background styles belong to index.html, not the component CSS.

API:

- `ready`: Promise that resolves after the initial project's real image decode/render setup; rejects on invalid artwork.
- `getProject()`: a validated state copy. Editing it does not mutate the editor.
- `loadProject(project)`: Promise, validates and decodes before changing the editor. API-driven loads are controlled by the host; interactive loads ask about unsaved replacement.
- `exportImage(type, quality)`: Promise `{blob, width, height, type}`. Types: image/png, image/jpeg, image/webp. Quality: 0.1–1 (PNG ignores quality).
- `destroy()`: removes component content, pending draft/render tasks and window unload handler. Destroy instances before removing their containers.
- Options: `project`, `onChange`, `onExport`, optional `autosaveKey`, optional `warnOnUnload`. A unique autosaveKey is necessary if you explicitly enable drafts on multiple instances. The standalone app enables a local draft and unsaved-unload warning; embeds opt in.

## Attach edited images to your host form

Open `samples/form.html` for a local two-field example. Load `app/form-attachment.js` **after** the three component scripts. This optional original helper uses the same public mount/export API; it does not upload, submit, measure or persist your images.

```js
const hero = FrameleafForm.mount(document.getElementById('hero-editor'), {
  project: myFrameleafProject,
  fieldName: 'hero_image',
  filename: 'product-hero',
  onAttachmentChange(file) { /* null means prepare this field again */ }
});
await hero.ready;
const output = await hero.prepare('image/png'); // genuine File, width, height, type
const data = new FormData(myForm);
hero.appendTo(data); // replaces only hero_image, preserving other fields
// Your application decides whether/where/when to submit data. This helper never does.
```

Use one helper per field and distinct `fieldName` values. `prepare(type, quality)` encodes the current image, wraps its Blob as a correctly named `File`, and rejects stale results if the image changes during encoding or a newer preparation wins. Valid project changes, live color adjustments and pending text edits invalidate only that helper’s file. Invalid image/project/crop/size input preserves the last committed image and attachment. Undo/load/reset invalidate when their committed state changes. `getFile()` returns the prepared File or null; `clear()` invalidates it; `destroy()` clears it, removes host listeners and destroys the editor. Destroy before mounting another helper into the same container.

Build **fresh FormData immediately before your own submission** and call each helper’s `appendTo` then. Previously built FormData, File references and files already sent to your server cannot be revoked by later edits. The helper intentionally does not assign a file input’s `files` property. Its `editor` property exposes the unchanged Frameleaf API for save/open/project access. The standalone editor and basic embed need not load this helper.

## Privacy and backup

The editor performs no network requests. Images stay in local memory and, only when configured, browser-local draft storage. A saved JSON contains the original image and all editing metadata. Do not use real patient or sensitive personal data as test artwork. Browser file-origin storage and private browsing vary; quota failure is visible. **Downloaded JSON is the durable backup**, not a guarantee that localStorage survives browser restarts. Use Recover browser draft if available.

Text is rasterized or inserted into controls with textContent, not interpreted as HTML. Project schema rejects executable/external image URLs, duplicate layer IDs, invalid dimensions and unbounded output. Raster decode must match declared dimensions. A legitimate image can still be visually misleading; you are responsible for reviewing published material.

## Package contents and customization

Runtime users need no npm install. The package contains the editable runtime JavaScript/CSS/HTML, standalone editor, two integration examples, original synthetic artwork/project/output, usage documentation and license notices. Internal test suites, development dependencies and browser review evidence are kept outside the customer ZIP. Keep the supplied directory structure when embedding; the API examples above describe the public customization surface.

`samples/cedar-tea.png`, `cedar-tea.frameleaf.json` and `cedar-tea-edited.png` are the original artwork, editable filled example and actual renderer output. `samples/embed.html` demonstrates independent editor instances; `samples/form.html` demonstrates prepared form attachments. `MANIFEST.json` lists the delivered file hashes. `qa.config.json` records the verification profile; internal verification results are not customer files.

## Limits and release responsibilities

No native source-SVG editing, PSD layers, PDF import, freehand painting, AI transformations, hosted accounts or native CMS installer. Browser memory limits, encoder support and font rasterization vary; sans-serif text can look slightly different across platforms. Physical touch/pinch, other browser engines and large-device performance are not independently verified. Inspect the actual downloaded image and reopen your saved project before relying on a browser or device for an important job.

## Free-product use terms

The approved **Nishvault Free Product Use Terms — v1** in `LICENSE.txt` govern use of the free editor. They permit personal and commercial use and export, sharing, embedding or sale of your created outputs; uploaded artwork remains subject to its rights holders. They do not permit redistribution or resale of the product itself, its complete source/package or a competing rebranded copy. No paid checkout, recurring charge, guaranteed support, service-level agreement or update schedule is included. Optional custom integration requires a separate agreed scope before any payment or work commitment. Third-party dependency notices remain in `THIRD_PARTY.md`.


## Hosted usage measurement

`app/hosted-metrics.js` is an optional first-party adapter for the exact HTTPS Nishvault product/editor routes. A publisher may load it on those hosted pages only. The offline `app/index.html`, downloaded image files and customer embeds do not load it. The component itself makes no network requests; its content-free `frameleaf:export-created` event follows successful image encoding and download dispatch, with only the output MIME format. JSON backups and API rendering alone do not signal image download completion.

The adapter sends fixed anonymous diagnostic `page_view`, `product_export` and `calculator_result` (the existing endpoint's completion event) payloads to `/api/metrics`. It sends no project, image, title, filename, dimensions, URL query, visitor/session ID, referrer or cookies. DNT/GPC disable it. It uses in-memory limits of one page view, one completion and at most 20 exports per document; failures do not retry or interrupt editing. Synthetic hosted QA must use `?nv_internal_test=1`. These diagnostic event counts do not establish unique people, signed canonical funnels, sales, or that a downloaded file was retained. Production integration/persistence require separate release evidence.
