Collage Maker Developer Reference (previous engine)
Maintain the canvas collage editor: UI contract, state model, layers, pointer input, transform math, rendering, exports, session JSON, research tools, public API and Library image capture.
Superseded
This describes the engine replaced on 11 September 2026. The runtime it documents — the undo stack that saved the state each action had just created, the coverage figure that summed layer areas without looking at where they were, the bootstrap “confidence interval” that read no data, and the export that drew the guides and the selection box into the file — no longer exists. The current reference is Collage Measurement Developer Reference.
Overview
Collage Maker Lab is a static HTML page with a standalone IIFE runtime. It stores global canvas
settings in S, keeps images as layer objects, renders through Canvas 2D, supports
pointer and keyboard editing, records undo states, exports raster and JSON outputs, runs layout
research tools and exposes a small API for Library.
1. Code map
+| File | Role |
|---|---|
tool/general/tools/collage-maker/index.html |
Tool shell, SEO metadata, controls, canvas, action panels, standards, formulas, references, research panels and fullscreen overlay. |
js/tool/collage-maker.js |
Runtime IIFE: state, layers, pointer input, keyboard shortcuts, transforms, render, stats, exports, session JSON, batch, bootstrap and public API. |
js/library/tool-bindings.js |
Registers Collage Maker as a Creative image tool and captures cm-canvas
for Library. |
data/documentation.json |
Documentation discovery source used by RSS, sitemaps, cache manifest and related generated files. |
2. Page shell and tabs
+The page uses the standard Auric Artisan tool shell with shared CSS, generated inline scripts,
header/time/announcement includes, cursor layer, scroll layer, loader, eye-rest UI, tool footer
and idle canvas. The app root is cm-app, and the quick-start guide is
cm-guide with dismiss button cm-guide-dismiss.
Tab buttons use data-cm-tab and switch p-cm-lab,
p-cm-actions, p-cm-standards, p-cm-formulas,
p-cm-refs and p-cm-research. The fullscreen chart overlay uses
clm-chart-fs-overlay, clm-chart-fs-title,
clm-chart-fs-close and clm-chart-fs-canvas.
3. UI contract
+| Area | Important IDs |
|---|---|
| Upload and global actions | cm-files, cm-auto-layout, cm-clear |
| Canvas controls | cm-aspect, cm-res-scale, cm-pad,
cm-gap, cm-radius, cm-bg,
cm-bg-transparent |
| Guides | cm-snap, cm-show-guides,
cm-show-thirds, cm-snap-step |
| Selected layer controls | cm-scale, cm-rot, cm-opa,
cm-width-pct, cm-selected-label |
| Layer buttons | cm-bring-front, cm-send-back, cm-center,
cm-duplicate, cm-rot-reset, cm-flip-h,
cm-flip-v, cm-rename, cm-replace |
| Canvas and diagnostics | cm-canvas, cm-canvas-wrap, cm-histogram,
cm-stats, cm-meta-bg, cm-meta-aspect,
cm-meta-dims, cm-meta-layers |
| Exports and sessions | cm-download, cm-download-jpeg, cm-copy-png,
cm-jpeg-q, cm-export-selection,
cm-btn-save-session, cm-btn-load-session,
cm-copy-json, cm-load-json,
cm-btn-copy-link |
| Research | cm-bootstrap-run, cm-bootstrap-canvas,
cm-bootstrap-output, cm-batch-input,
cm-batch-run, cm-batch-csv,
cm-batch-output |
When adding or renaming a control, update init bindings, reset behavior, state serialization, Library capture metadata and tests together.
4. State and layer model
+The runtime state object S stores canvas and editor state:
{
canvasW, canvasH, bgColor, bgTransparent,
pad, gap, radius, snap, snapStep,
showGuides, showThirds, resScale,
jpegQ, exportSelection, selId
}
Each layer is stored as an object with image plus transform metadata:
{
id, img, name, cx, cy, bw, bh,
scale, rot, opa, flipX, flipY,
locked, visible
}
snap_state() serializes S and all layer metadata except
img. This is used by undo/redo and by the public getState() API.
5. Pointer, keyboard and undo
+canvasXY()converts browser pointer coordinates into canvas pixel coordinates.hitTest()transforms the pointer into each layer local coordinate space and tests a rotated rectangle.cornerHit()detects the four resize handles on the selected layer.onDown(),onMove()andonUp()manage select, drag and resize states.onWheel()rotates with Alt+wheel and scales with Shift+wheel.onKey()handles delete, arrow nudging, auto-layout, fullscreen, undo and redo.
The undo stack and redo stack store JSON snapshots with a maximum of 40 undo states. Image elements remain in memory and restored snapshots only reapply layer metadata to matching ids.
6. Aspect, snapping and auto layout
+applyAspect(val) parses ratios such as 4:3, uses 1200 as the base width
and multiplies dimensions by S.resScale. For 4:3 at scale 1, the canvas is 1200 by
900 px.
snapVal(v) rounds drag positions to the nearest S.snapStep when
snapping is enabled. Auto layout uses only visible layers:
cols = ceil(sqrt(n))
rows = ceil(n / cols)
cellW = (canvasW - pad * 2 - gap * (cols - 1)) / cols
cellH = (canvasH - pad * 2 - gap * (rows - 1)) / rows
Each layer is centered into its cell, scaled to fit within the cell and reset to zero rotation.
7. Rendering, metrics and charts
+render()clears the canvas, draws background or checkerboard, draws the rule-of-thirds overlay, renders visible layers bottom to top, then draws the selected layer outline, handles and center guides.roundRect()creates the rounded background path when radius is greater than 0.renderLayerList()builds the layer panel with thumbnails, visibility, lock and delete buttons.syncLayerControls()updates selected layer sliders from the current layer.renderHistogram()draws layer areas and highlights the selected layer.renderStats()reports canvas area, layer coverage, visible layer count, undo steps and overlap estimate.refreshAll()calls all major render/update functions.
Theme changes are handled by a body class mutation observer that calls refreshAll().
8. Exports and session JSON
+| Function | Contract |
|---|---|
exportPNG() |
Downloads collage.png, or routes to selected-layer PNG export when
S.exportSelection is true. |
exportJPEG() |
Downloads collage.jpg using S.jpegQ. |
exportSelectedOnly(fmt) |
Creates a temporary canvas sized to the selected layer and exports it as PNG or JPEG. |
copyPNG() |
Writes a PNG blob to the clipboard through ClipboardItem when
supported. |
buildSessionJSON() |
Returns version, canvas settings and layer metadata without image data. |
exportSessionJSON() |
Downloads collage-session.json. |
loadJSON() and handleSessionFile() |
Apply session canvas settings and layer metadata to currently loaded matching layers. |
copyLink() |
Copies location.origin + location.pathname; it does not encode state.
|
9. Batch and bootstrap
+runBatch() expects a JSON array. Each item can provide n,
cols, pad, gap, canvasW and
canvasH. It computes columns, rows, cell width, cell height, coverage and canvas
label, then writes an HTML table to cm-batch-output.
exportBatchCSV() serializes that table into collage-batch.csv.
runBootstrap() uses the active layer count or 4 fallback layers, randomizes columns,
padding and gap, computes coverage for each sample, sorts results and draws a histogram with 2.5
percent, 97.5 percent and mean markers. The runtime supports an optional
cm-bootstrap-n field; without it, the default is 500 iterations.
10. Public API and library binding
+The runtime exposes:
window.AACollageMaker = {
getState: function () { ... },
restoreState: function (data) { ... }
};
getState() returns a parsed snapshot of S and layer metadata.
restoreState(data) merges data.S into state and applies layer metadata
to already loaded layers with matching ids, then calls refreshAll().
The Library binding registers /tool/general/tools/collage-maker/ as tool id
collage-maker, name Collage Maker, category Creative and
asset type image. It captures cm-canvas and stores extras:
background, aspect, layers and dimensions. Restore applies background, aspect and saved form
inputs, then shows a message that source images must be re-uploaded.
11. Testing checklist
+- Open the route and confirm all six tabs switch correctly.
- Upload JPG, PNG, WebP and multiple images in one selection.
- Change all aspect ratios and resolution scales; verify canvas metadata and export size.
- Test drag, resize handles, Alt+wheel rotation, Shift+wheel scaling and arrow nudging.
- Verify snap on/off, snap step, center guides and rule-of-thirds overlay.
- Test every layer button: front, back, center, duplicate, reset rotation, flips, rename, replace, visibility, lock and delete.
- Confirm undo and redo after moves, slider edits, deletes and auto layout.
- Export full PNG, full JPEG, selected-layer PNG, selected-layer JPEG and clipboard PNG.
- Save session JSON, copy JSON, paste JSON and load a session JSON file after re-uploading matching images.
- Run batch analysis with valid and invalid input, then export CSV.
- Run bootstrap with no images and with several layers; verify chart and output text.
- Save to Library and restore layout settings, confirming the re-upload message is accurate.
For user workflow details, see the Collage Maker User Guide.