Realistic watercolor drawings
working
Maksimc9634afcbc71
diff --git a/README.md b/README.mdindex 28546c6..f070762 100644--- a/README.md+++ b/README.md@@ -15,7 +15,7 @@ npm run dev # http://localhost:5173npm run build # static site in dist/```-Two small runtime dependencies (vpype-js for SVG import, q-floodfill for the bucket fill). Vite and TypeScript are only used at build time; the UI is plain DOM,+Small runtime dependencies: vpype-js for SVG import, q-floodfill for the bucket fill, and heic-to for iPhone HEIC photos. heic-to is about 3 MB, so it is a separate chunk and only downloads when a browser can't decode HEIC itself. Vite and TypeScript are only used at build time; the UI is plain DOM,and the simulation, colour science and rendering are TypeScript + GLSL.## Text and shapes@@ -119,7 +119,22 @@ reaches into the valleys.**Import texture…** in the library turns any PNG/JPG into a brush tip (dark marks on white areinverted automatically; alpha is respected). Imported brushes are kept in `localStorage`.-Drop an image anywhere on the page to import it.+Drop an image anywhere on the page and choose **Make a brush** or **Use as reference**.++## Reference image and saving++**Ref** puts a photo or sketch (PNG, JPG, WebP, or an iPhone HEIC) under the paint to work from.+Paint glazes over it like a tracing. Opacity is adjustable, and **R** shows or hides it.+**Move** brings up a frame: drag it to move the image, drag a corner, scroll or pinch to scale it, and press Esc+when done (painting pauses while the frame is up). **Fit** puts it back. The reference lives only+on screen (`src/reference/`) and is never part of a saved image.++**Save** opens the export options:+- Background: **Transparent** (default; unpainted paper is see-through, with paint as colour + alpha that+ looks the same when laid over white), **Paper** (the textured paper, as on screen), or **White**.+- Format: PNG, JPEG or WebP. JPEG and WebP have a quality setting, and JPEG has no transparency.++**S** saves immediately with the last settings.## Using it@@ -135,7 +150,8 @@ Drop an image anywhere on the page to import it.| **1–9, 0** | pigments; the last is white gouache || **[ ]** | size || **⌘Z** | undo |-| **S** / **F** | save PNG / fullscreen |+| **R** | show / hide the reference image |+| **S** / **F** | save with the last export settings / fullscreen |Stylus: pressure shapes the stroke. The barrel button switches to water and the eraser endlifts. On iPad, once an Apple Pencil has been used, your finger becomes the water brush.diff --git a/package-lock.json b/package-lock.jsonindex 9608dff..ff28321 100644--- a/package-lock.json+++ b/package-lock.json@@ -8,6 +8,7 @@"name": "watercolor","version": "0.1.0","dependencies": {+ "heic-to": "^1.6.5","q-floodfill": "^1.3.1","vpype-js": "^0.1.0"},@@ -698,6 +699,12 @@"node": "^8.16.0 || ^10.6.0 || >=11.0.0"}},+ "node_modules/heic-to": {+ "version": "1.6.5",+ "resolved": "https://registry.npmjs.org/heic-to/-/heic-to-1.6.5.tgz",+ "integrity": "sha512-xPH6gvrzSRIFo/GyzYbr+DZX1JoQliw1oJBT1PCduR0ruDVs1DjlAdU1m5Thed2ZXBoLqYMCd5UXiJteRl3BNQ==",+ "license": "LGPL-3.0"+ },"node_modules/lightningcss": {"version": "1.33.0","resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz",diff --git a/package.json b/package.jsonindex 2433b37..0e86b89 100644--- a/package.json+++ b/package.json@@ -14,6 +14,7 @@"vite": "^8.3.2"},"dependencies": {+ "heic-to": "^1.6.5","q-floodfill": "^1.3.1","vpype-js": "^0.1.0"}diff --git a/src/engine/Engine.ts b/src/engine/Engine.tsindex 2012cd4..708e741 100644--- a/src/engine/Engine.ts+++ b/src/engine/Engine.ts@@ -28,6 +28,17 @@ export interface EngineCallbacks {onStrokeTool?(tool: Tool | null): void;}+export type ExportFormat = 'png' | 'jpeg' | 'webp';+export type ExportBackground = 'transparent' | 'paper' | 'white';+export interface ExportOptions { format: ExportFormat; background: ExportBackground; quality?: number }++/** Placement of the reference image in document uv (y up): origin and size. */+export interface RefRect { x: number; y: number; w: number; h: number }++/** How the display shader composites: on screen (with the reference) or for an export. */+const MODE = { screen: 0, paper: 1, transparent: 2, white: 3 } as const;+const MAX_REF_SIDE = 4096;+interface Sample { x: number; y: number; p: number; t: number; tx: number; ty: number }interface Stroke {@@ -85,6 +96,11 @@ export class WatercolorEngine {interactive = true;private tipTextures = new Map<string, WebGLTexture>();+ // reference image: shown under the paint on screen only, never exported+ private ref: { tex: WebGLTexture; aspect: number } | null = null;+ private refRect: RefRect = { x: 0, y: 0, w: 1, h: 1 };+ private refOpacity = 0.5;+ private refVisible = true;private lastDir: [number, number] = [1, 0]; // direction of the last stroke, for the first dabprivate lastAngle = 0; // tip angle shown by the hover cursor@@ -190,7 +206,10 @@ export class WatercolorEngine {private createDocument() {const [cw, ch] = this.canvasSize;const s = Math.min(1, MAX_DOC_LONG / Math.max(cw, ch), MAX_DOC_SHORT / Math.min(cw, ch));+ const oldAspect = this.aspect;this.dw = Math.round(cw * s); this.dh = Math.round(ch * s);+ // a reference placed on paper of another shape would be stretched; fit it afresh+ if (this.ref && Math.abs(this.aspect - oldAspect) > 1e-3) this.fitReference();const { gl, g } = this;g.disposeTargets();const ar = this.dw / this.dh;@@ -381,6 +400,65 @@ export class WatercolorEngine {this.updateCursor();}+ /* ------------------------------------------------------- reference image */++ get hasReference() { return this.ref !== null; }++ /** Width / height of the reference image, or 0 without one. */+ get referenceAspect() { return this.ref?.aspect ?? 0; }++ /**+ * Show `img` under the paint (or remove it with null), fitted to the paper.+ * It survives clearing the paper and is never part of an export.+ */+ setReference(img: ImageBitmap | HTMLCanvasElement | null) {+ const { gl } = this;+ if (this.ref) { gl.deleteTexture(this.ref.tex); this.ref = null; }+ if (img) {+ const max = Math.min(MAX_REF_SIDE, gl.getParameter(gl.MAX_TEXTURE_SIZE) as number);+ let src: TexImageSource = img;+ const s = Math.min(1, max / Math.max(img.width, img.height));+ if (s < 1) {+ const c = document.createElement('canvas');+ c.width = Math.max(1, Math.round(img.width * s)); c.height = Math.max(1, Math.round(img.height * s));+ c.getContext('2d')!.drawImage(img, 0, 0, c.width, c.height);+ src = c;+ }+ const tex = gl.createTexture()!;+ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, tex);+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, src);+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);+ this.ref = { tex, aspect: img.width / img.height };+ this.fitReference();+ }+ this.redraw();+ }++ /** The reference placed as large as fits, centred on the paper. */+ fitReference() {+ if (!this.ref) return;+ const k = this.ref.aspect / this.aspect; // the image's width / height in uv units+ const w = k > 1 ? 1 : k, h = k > 1 ? 1 / k : 1;+ this.referenceRect = { x: (1 - w) / 2, y: (1 - h) / 2, w, h };+ }++ get referenceRect(): RefRect { return { ...this.refRect }; }+ set referenceRect(r: RefRect) { this.refRect = { ...r }; this.redraw(); }++ get referenceOpacity() { return this.refOpacity; }+ set referenceOpacity(v: number) { this.refOpacity = clamp(v, 0, 1); this.redraw(); }++ get referenceVisible() { return this.refVisible; }+ set referenceVisible(v: boolean) { this.refVisible = v; this.redraw(); }++ private redraw() { this.dirtyAll = true; this.schedule(); }+/** Drop the GPU copy of a brush tip (after a custom brush is removed or replaced). */forgetBrush(id: string) {const t = this.tipTextures.get(id);@@ -466,10 +544,14 @@ export class WatercolorEngine {return { wetAgo: performance.now() - this.lastWet, wetPeak: this.wetPeak, active: this.active ? { ...this.active } : null };}- /** Render the document at full resolution and return it as a PNG. */- async exportPNG(): Promise<Blob> {+ /**+ * Render the document at full resolution as an image file. The reference image is+ * never included. JPEG has no alpha, so a transparent JPEG is put on white.+ */+ async exportImage(o: ExportOptions): Promise<Blob> {const { dw, dh } = this;- const px = this.readback(false);+ const bg = o.format === 'jpeg' && o.background === 'transparent' ? 'white' : o.background;+ const px = this.readback(false, MODE[bg]);const c = document.createElement('canvas');c.width = dw; c.height = dh;const ctx = c.getContext('2d')!;@@ -477,14 +559,19 @@ export class WatercolorEngine {const row = dw * 4;for (let y = 0; y < dh; y++) img.data.set(px.subarray((dh - 1 - y) * row, (dh - y) * row), y * row);ctx.putImageData(img, 0, 0);- return new Promise((resolve, reject) => c.toBlob(b => (b ? resolve(b) : reject(new Error('export failed'))), 'image/png'));+ const type = `image/${o.format}`;+ return new Promise((resolve, reject) => c.toBlob(b => {+ if (!b) reject(new Error('export failed'));+ else if (b.type !== type) reject(new Error(`This browser cannot save ${o.format.toUpperCase()}`));+ else resolve(b);+ }, type, o.quality));}/** The composited document at full resolution as RGBA8 bytes, bottom row first. */- private readback(flat: boolean): Uint8Array {+ private readback(flat: boolean, mode: number = MODE.paper): Uint8Array {const { gl, g, dw, dh } = this;const out = g.target(dw, dh, [RGBA8], gl.NEAREST);- this.drawDisplay(out, { x: 0, y: 0, w: dw, h: dh }, null, flat);+ this.drawDisplay(out, { x: 0, y: 0, w: dw, h: dh }, null, flat, mode);const px = new Uint8Array(dw * dh * 4);gl.bindFramebuffer(gl.FRAMEBUFFER, out.fbo);gl.readPixels(0, 0, dw, dh, gl.RGBA, gl.UNSIGNED_BYTE, px);@@ -505,6 +592,8 @@ export class WatercolorEngine {this.disposers.forEach(d => d());this.tipTextures.forEach(t => this.gl.deleteTexture(t));this.tipTextures.clear();+ if (this.ref) this.gl.deleteTexture(this.ref.tex);+ this.ref = null;this.g.disposeTargets();}@@ -1075,7 +1164,7 @@ export class WatercolorEngine {/* -------------------------------------------------------------- display */- private drawDisplay(target: Target | null, view: { x: number; y: number; w: number; h: number }, scissor: Rect | null, flat = false) {+ private drawDisplay(target: Target | null, view: { x: number; y: number; w: number; h: number }, scissor: Rect | null, flat = false, mode: number = MODE.screen) {const { gl, g } = this;const p = this.programs.display;p.bind();@@ -1091,6 +1180,13 @@ export class WatercolorEngine {gl.uniform1f(p.u.uEdgeDarken, 0.8);gl.uniform1f(p.u.uFlat, flat ? 1 : 0);gl.uniform3fv(p.u.uDesk, DESK);+ gl.uniform1i(p.u.uMode, mode);+ const ref = mode === MODE.screen && !flat && this.refVisible ? this.ref : null;+ gl.uniform1f(p.u.uRefOpacity, ref ? this.refOpacity : 0);+ // the sampler needs a texture bound either way; the paper stands in when there is none+ gl.uniform1i(p.u.uRef, g.bindTex(6, ref ? ref.tex : this.paper.tex[0]));+ const r = this.refRect;+ gl.uniform4f(p.u.uRefRect, r.x, r.y, r.w, r.h);g.draw(target, scissor, this.canvasSize);}diff --git a/src/engine/shaders.ts b/src/engine/shaders.tsindex 1875c36..7cb34f0 100644--- a/src/engine/shaders.ts+++ b/src/engine/shaders.ts@@ -311,6 +311,10 @@ uniform vec2 uTexel; // document texel sizeuniform float uGranulation, uEdgeDarken;uniform float uFlat; // 1: ignore the paper's relief, grain and wetness (for region picking)uniform vec3 uDesk;+uniform int uMode; // 0 screen, 1 export on paper, 2 export transparent, 3 export on white+uniform sampler2D uRef; // reference image (screen only), sRGB, y up+uniform vec4 uRefRect; // its placement in document uv: xy origin, zw size+uniform float uRefOpacity;vec3 toSRGB(vec3 c){c = clamp(c, 0.0, 1.0);@@ -341,17 +345,41 @@ void main(){float tr;${displayBasisGLSL()}- // Paper: warm white, lit relief, faint fibre mottling (linear light).- vec3 paperCol = vec3(0.925, 0.905, 0.855) * (0.93 + 0.1 * paper.r) * (0.985 + 0.03 * paper.b);- vec3 col = rgb * paperCol;-// White gouache sits on top as an opaque layer, a little patchy on the tooth.float cov = 1.0 - exp(-2.2 * iB.a);cov = clamp(cov * (1.0 + (paper.g - 0.5) * 0.5), 0.0, 1.0);- col = mix(col, vec3(0.96, 0.955, 0.94) * (0.96 + 0.05 * paper.r), cov);+ vec3 gouache = vec3(0.96, 0.955, 0.94) * (0.96 + 0.05 * paper.r);++ if (uMode == 2){+ // Transparent: the pigment's transmittance over white, unmixed into colour + alpha+ // (exact when the image is laid back over white), then the gouache over that.+ vec3 t = toSRGB(rgb);+ float a1 = 1.0 - min(min(t.r, t.g), t.b);+ vec3 c1 = a1 > 1e-4 ? (t - (1.0 - a1)) / a1 : vec3(0.0);+ vec3 g = toSRGB(gouache);+ float al = cov + a1 * (1.0 - cov);+ vec3 c = al > 1e-4 ? (g * cov + c1 * a1 * (1.0 - cov)) / al : vec3(0.0);+ o = vec4(c, al); // straight alpha, as ImageData wants it+ return;+ }++ // Paper: warm white, lit relief, faint fibre mottling (linear light).+ vec3 paperCol = uMode == 3 ? vec3(1.0)+ : vec3(0.925, 0.905, 0.855) * (0.93 + 0.1 * paper.r) * (0.985 + 0.03 * paper.b);+ // On screen, a reference image shows through the paper, under the paint.+ if (uMode == 0 && uRefOpacity > 0.0){+ vec2 ruv = (uv - uRefRect.xy) / uRefRect.zw;+ if (ruv.x >= 0.0 && ruv.y >= 0.0 && ruv.x <= 1.0 && ruv.y <= 1.0){+ vec4 r = texture(uRef, ruv);+ vec3 lin = pow(r.rgb, vec3(2.2));+ paperCol = mix(paperCol, lin, r.a * uRefOpacity);+ }+ }+ vec3 col = rgb * paperCol;+ col = mix(col, uMode == 3 ? vec3(1.0) : gouache, cov);// Wet paper reads darker and slightly cool.- float ws = smoothstep(0.02, 0.7, texture(uWet, uv).x) * (1.0 - uFlat);+ float ws = uMode == 3 ? 0.0 : smoothstep(0.02, 0.7, texture(uWet, uv).x) * (1.0 - uFlat);col *= vec3(1.0) - ws * vec3(0.12, 0.11, 0.08);o = vec4(toSRGB(col), 1.0);diff --git a/src/export/exportPanel.ts b/src/export/exportPanel.tsnew file mode 100644index 0000000..f1a5070--- /dev/null+++ b/src/export/exportPanel.ts@@ -0,0 +1,91 @@+import type { ExportBackground, ExportFormat, WatercolorEngine } from '../engine/Engine';++const KEY = 'watercolor.export';++interface Settings { format: ExportFormat; background: ExportBackground; quality: number }++const DEFAULTS: Settings = { format: 'png', background: 'transparent', quality: 0.92 };+const FORMATS: { id: ExportFormat; label: string; ext: string }[] = [+ { id: 'png', label: 'PNG', ext: 'png' },+ { id: 'jpeg', label: 'JPEG', ext: 'jpg' },+ { id: 'webp', label: 'WebP', ext: 'webp' },+];+const BACKGROUNDS: { id: ExportBackground; label: string; title: string }[] = [+ { id: 'transparent', label: 'Transparent', title: 'Transparent: only the paint, no paper' },+ { id: 'paper', label: 'Paper', title: 'On the textured watercolour paper' },+ { id: 'white', label: 'White', title: 'On plain white' },+];++export interface ExportPanel {+ panel: HTMLElement;+ /** Save straight away with the last used settings. */+ save(): Promise<void>;+}++/** Save dialog: format, background and quality, remembered between visits. */+export function createExportPanel(engine: WatercolorEngine, root: HTMLElement, showToast: (s: string) => void): ExportPanel {+ let settings: Settings = { ...DEFAULTS };+ try { settings = { ...settings, ...JSON.parse(localStorage.getItem(KEY) ?? '{}') }; } catch { /* storage blocked */ }++ const panel = document.createElement('div');+ panel.className = 'panel popover export';+ panel.hidden = true;+ panel.setAttribute('role', 'dialog');+ panel.setAttribute('aria-label', 'Save image');+ panel.innerHTML = `+ <div class="pop-head"><span>Save image</span><span class="sub">The reference image is never included.</span></div>+ <div class="field"><span>Background</span><div class="seg">${BACKGROUNDS.map(b => `<button data-bg="${b.id}" title="${b.title}">${b.label}</button>`).join('')}</div></div>+ <div class="field"><span>Format</span><div class="seg">${FORMATS.map(f => `<button data-format="${f.id}">${f.label}</button>`).join('')}</div></div>+ <label class="slider" data-quality><span>Quality</span><input type="range" min="0.5" max="1" step="0.01"></label>+ <button class="primary" data-export="download">Download</button>`;+ root.appendChild(panel);++ const quality = panel.querySelector<HTMLInputElement>('[data-quality] input')!;++ function render() {+ for (const b of panel.querySelectorAll<HTMLButtonElement>('[data-bg]')) {+ b.classList.toggle('on', b.dataset.bg === settings.background);+ // JPEG has no alpha channel+ b.disabled = b.dataset.bg === 'transparent' && settings.format === 'jpeg';+ }+ for (const b of panel.querySelectorAll<HTMLElement>('[data-format]')) b.classList.toggle('on', b.dataset.format === settings.format);+ panel.querySelector<HTMLElement>('[data-quality]')!.hidden = settings.format === 'png';+ quality.value = String(settings.quality);+ }++ function update(p: Partial<Settings>) {+ settings = { ...settings, ...p };+ if (settings.format === 'jpeg' && settings.background === 'transparent') settings.background = 'paper';+ try { localStorage.setItem(KEY, JSON.stringify(settings)); } catch { /* storage blocked */ }+ render();+ }++ async function save() {+ const { format, background, quality: q } = settings;+ try {+ const blob = await engine.exportImage({ format, background, quality: format === 'png' ? undefined : q });+ const ext = FORMATS.find(f => f.id === format)!.ext;+ const a = document.createElement('a');+ a.href = URL.createObjectURL(blob);+ a.download = `watercolor-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}.${ext}`;+ a.click();+ setTimeout(() => URL.revokeObjectURL(a.href), 4000);+ const bg = background === 'transparent' ? 'transparent' : `on ${background}`;+ showToast(`Saved ${FORMATS.find(f => f.id === format)!.label} · ${bg}`);+ } catch (e) {+ showToast(e instanceof Error ? e.message : 'Could not save the image');+ }+ }++ panel.addEventListener('click', e => {+ const el = (e.target as Element).closest<HTMLElement>('[data-bg], [data-format], [data-export]');+ if (!el) return;+ if (el.dataset.bg) update({ background: el.dataset.bg as ExportBackground });+ else if (el.dataset.format) update({ format: el.dataset.format as ExportFormat });+ else void save();+ });+ quality.addEventListener('input', () => update({ quality: Number(quality.value) }));++ render();+ return { panel, save };+}diff --git a/src/main.ts b/src/main.tsindex b7667a8..884bff3 100644--- a/src/main.ts+++ b/src/main.ts@@ -9,6 +9,9 @@ import { createTextTool } from './text/textTool';import { createShapeTool } from './shapes/shapeTool';import { createFillTool } from './fill/fillTool';import { isSvgFile } from './shapes/svgImport';+import { createReference } from './reference/referenceTool';+import { isRasterFile } from './reference/decode';+import { createExportPanel } from './export/exportPanel';import './styles.css';/** Engine tools plus the text, shape and fill tools, which drive the engine themselves. */@@ -73,14 +76,15 @@ root.innerHTML = `<button class="import" data-action="import" title="Use an image as a brush tip: dark marks on white, or white on transparent">${icon('plus', 16)}<span>Import texture…</span></button><span class="note">PNG or JPG. Light background is inverted automatically.</span></div>- <input type="file" accept="image/*" hidden>+ <input type="file" accept="image/*,.heic,.heif" hidden></div><div class="panel actions">${button('undo', 'undo', 'Undo', 'Undo (⌘Z)')}${button('redo', 'redo', 'Redo', 'Redo (⇧⌘Z)')}${button('dry', 'dry', 'Dry', 'Dry and fix the painting into the paper (D)')}${button('clear', 'clear', 'Clear', 'Clear the paper')}- ${button('save', 'save', 'Save', 'Save PNG (S)')}+ ${button('reference', 'image', 'Ref', 'Reference image under the paint (R to show / hide)')}+ ${button('save', 'save', 'Save', 'Save image (S saves with the last settings)')}${button('settings', 'sliders', 'Settings', 'Brush & water settings')}</div><div class="panel settings" hidden>@@ -94,6 +98,10 @@ root.innerHTML = `</div><div class="well" title="Spectral mix of your last two pigments"><span class="name"></span><span class="mix"></span></div></div>+ <div class="panel drop-choice" hidden role="dialog" aria-label="Use the dropped image">+ <button data-drop="reference">${icon('image', 16)}<span>Use as reference</span></button>+ <button data-drop="brush">${icon('brush', 16)}<span>Make a brush</span></button>+ </div><div class="toast" hidden></div>`;const $ = <T extends HTMLElement = HTMLElement>(sel: string) => root.querySelector<T>(sel)!;@@ -109,7 +117,7 @@ const fileInput = $<HTMLInputElement>('.library input[type="file"]');const undoBtn = $<HTMLButtonElement>('[data-action="undo"]');const redoBtn = $<HTMLButtonElement>('[data-action="redo"]');const clearBtn = $('[data-action="clear"]');-const settingsBtn = $('[data-action="settings"]');+const dropChoice = $('.drop-choice');const customSwatch = $('.swatch.custom');const customInput = $<HTMLInputElement>('.swatch.custom input');const toast = $('.toast');@@ -147,6 +155,10 @@ if (import.meta.env.DEV) (window as unknown as { engine: WatercolorEngine }).engconst textTool = createTextTool(engine, root, canvas, showToast);const shapeTool = createShapeTool(engine, root, canvas, showToast);const fillTool = createFillTool(engine, root, canvas, showToast);+const reference = createReference(engine, root, showToast, on => { engine.interactive = !on && !isPanelTool(tool); });+const exporter = createExportPanel(engine, root, showToast);+/** Small panels that drop down under the action bar, one at a time, keyed by their button's action. */+const popovers: Record<string, HTMLElement> = { settings, reference: reference.panel, save: exporter.panel };/** Tools with their own panel that drive the engine themselves. */const panelTools: Record<PanelTool, { active: boolean; activate(): void; deactivate(): void; stop(): boolean }> = { text: textTool, shape: shapeTool, fill: fillTool };const isPanelTool = (t: UiTool): t is PanelTool => t in panelTools;@@ -221,6 +233,7 @@ function renderBrush() {function setTool(t: UiTool) {if (isPanelTool(t) && t !== tool) toggleLibrary(false);+ reference.stopAdjust();tool = t;for (const [id, p] of Object.entries(panelTools)) if (p.active && id !== t) p.deactivate();if (isPanelTool(t)) {@@ -296,15 +309,6 @@ function removeBrush(id: string) {buildLibrary();}-async function save() {- const blob = await engine.exportPNG();- const a = document.createElement('a');- a.href = URL.createObjectURL(blob);- a.download = `watercolor-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}.png`;- a.click();- setTimeout(() => URL.revokeObjectURL(a.href), 4000);-}-function setConfirmClear(on: boolean) {clearTimeout(confirmTimer);clearBtn.classList.toggle('danger', on);@@ -315,15 +319,37 @@ function setConfirmClear(on: boolean) {function clear() {if (!clearBtn.classList.contains('danger')) { setConfirmClear(true); return; }engine.clear();+ reference.layout();setConfirmClear(false);}-function toggleSettings(force?: boolean) {- settings.hidden = force === undefined ? !settings.hidden : !force;- settingsBtn.classList.toggle('on', !settings.hidden);- settingsBtn.setAttribute('aria-expanded', String(!settings.hidden));+/** Open or close one popover (toggling when `force` is omitted); opening one closes the rest. */+function togglePopover(name: string, force?: boolean) {+ const open = force ?? popovers[name].hidden;+ for (const [n, el] of Object.entries(popovers)) {+ el.hidden = !(open && n === name);+ const b = $(`.actions [data-action="${n}"]`);+ b.classList.toggle('on', !el.hidden);+ b.setAttribute('aria-expanded', String(!el.hidden));+ }+}++const closePopovers = () => { for (const n of Object.keys(popovers)) togglePopover(n, false); };++/* ------------------------------------------------- dropping an image file */++let dropped: File | null = null;++function offerDrop(f: File, x: number, y: number) {+ dropped = f;+ dropChoice.hidden = false;+ const r = dropChoice.getBoundingClientRect();+ dropChoice.style.left = `${Math.max(8, Math.min(innerWidth - r.width - 8, x - r.width / 2))}px`;+ dropChoice.style.top = `${Math.max(8, Math.min(innerHeight - r.height - 8, y - r.height / 2))}px`;}+function closeDrop() { dropped = null; dropChoice.hidden = true; }+function toggleLibrary(force?: boolean) {library.hidden = force === undefined ? !library.hidden : !force;pickBtn.classList.toggle('open', !library.hidden);@@ -345,8 +371,9 @@ root.addEventListener('click', e => {case 'redo': engine.redo(); break;case 'dry': engine.fix(); break;case 'clear': clear(); break;- case 'save': void save(); break;- case 'settings': toggleSettings(); break;+ case 'save': togglePopover('save'); break;+ case 'reference': togglePopover('reference'); break;+ case 'settings': togglePopover('settings'); break;case 'library': toggleLibrary(); break;case 'import': fileInput.click(); break;case 'reset': setParams(DEFAULT_PARAMS); break;@@ -361,6 +388,16 @@ brushList.addEventListener('keydown', e => {if (b) { e.preventDefault(); chooseBrush(b); }});+dropChoice.addEventListener('click', e => {+ const k = (e.target as Element).closest<HTMLElement>('[data-drop]')?.dataset.drop;+ const f = dropped;+ if (!k || !f) return;+ closeDrop();+ if (k === 'reference') void reference.load(f);+ else void importTexture(f);+});+window.addEventListener('pointerdown', e => { if (!dropChoice.hidden && !dropChoice.contains(e.target as Node)) closeDrop(); });+fileInput.addEventListener('change', () => {const f = fileInput.files?.[0];fileInput.value = '';@@ -369,7 +406,7 @@ fileInput.addEventListener('change', () => {else void importTexture(f);});-// drop an image anywhere to make a brush from it+// drop an image anywhere to use it as the reference or make a brush from itroot.addEventListener('dragover', e => { if (e.dataTransfer?.types.includes('Files')) e.preventDefault(); });root.addEventListener('drop', e => {const f = e.dataTransfer?.files?.[0];@@ -378,7 +415,7 @@ root.addEventListener('drop', e => {// an SVG's paths become a shape to trace, not a brush tipe.preventDefault();void shapeTool.loadSvg(f).then(ok => { if (ok) setTool('shape'); });- } else if (f.type.startsWith('image/')) { e.preventDefault(); void importTexture(f); }+ } else if (isRasterFile(f)) { e.preventDefault(); offerDrop(f, e.clientX, e.clientY); }});settings.addEventListener('input', e => {@@ -392,7 +429,7 @@ canvas.addEventListener('pointerdown', () => $('.hint').classList.add('gone'), {// painting dismisses the library so it never covers the work for longcanvas.addEventListener('pointerdown', () => { if (!library.hidden) toggleLibrary(false); });-window.addEventListener('resize', () => { engine.resize(); renderPreviews(); });+window.addEventListener('resize', () => { engine.resize(); reference.layout(); renderPreviews(); });window.addEventListener('keydown', e => {if (e.target instanceof HTMLInputElement && e.target.type !== 'range') return;@@ -400,14 +437,20 @@ window.addEventListener('keydown', e => {if ((e.metaKey || e.ctrlKey) && k === 'z') { e.preventDefault(); if (e.shiftKey) engine.redo(); else engine.undo(); return; }if ((e.metaKey || e.ctrlKey) && k === 'y') { e.preventDefault(); engine.redo(); return; }if (e.metaKey || e.ctrlKey || e.altKey) return;- if (k === 'escape') { if (!Object.values(panelTools).some(p => p.stop())) { toggleLibrary(false); toggleSettings(false); } return; }+ if (k === 'escape') {+ if (!dropChoice.hidden) closeDrop();+ else if (reference.stopAdjust()) { /* done moving the reference */ }+ else if (!Object.values(panelTools).some(p => p.stop())) { toggleLibrary(false); closePopovers(); }+ return;+ }const t = TOOLS.find(x => x.key.toLowerCase() === k);if (t) setTool(t.id);else if (k === '[' || k === ']') setParams({ size: Math.min(1, Math.max(0, params.size + (k === ']' ? 0.05 : -0.05))) });else if (k === ',' || k === '<') cycleBrush(-1);else if (k === '.' || k === '>') cycleBrush(1);else if (k === 'd') engine.fix();- else if (k === 's') void save();+ else if (k === 's') void exporter.save();+ else if (k === 'r') reference.toggleVisible();else if (k === 'f') {if (document.fullscreenElement) void document.exitFullscreen();else void document.documentElement.requestFullscreen?.();diff --git a/src/reference/decode.ts b/src/reference/decode.tsnew file mode 100644index 0000000..cdd091d--- /dev/null+++ b/src/reference/decode.ts@@ -0,0 +1,30 @@+/** File-picker `accept` for the images we can read, iPhone HEIC photos included. */+export const IMAGE_ACCEPT = 'image/png,image/jpeg,image/webp,image/gif,image/avif,image/heic,image/heif,.heic,.heif';++/** HEIC / HEIF (iPhone photos). Some browsers report no MIME type for them, so check the name too. */+export function isHeicFile(f: File): boolean {+ return /^image\/hei[cf]/.test(f.type) || /\.hei[cf]$/i.test(f.name);+}++/** A raster image we may be able to decode (SVG is handled elsewhere). */+export function isRasterFile(f: File): boolean {+ return (f.type.startsWith('image/') && f.type !== 'image/svg+xml') || isHeicFile(f);+}++/**+ * Decode an image file, upright (EXIF orientation applied). Browsers that cannot read+ * HEIC natively fall back to a decoder that is only downloaded when it is needed.+ */+export async function decodeImage(file: Blob): Promise<ImageBitmap> {+ try {+ return await createImageBitmap(file, { imageOrientation: 'from-image' });+ } catch {+ if (!(file instanceof File && isHeicFile(file))) throw new Error('Could not read that image');+ try {+ const { heicTo } = await import('heic-to');+ return await heicTo({ blob: file, type: 'bitmap', options: { imageOrientation: 'from-image' } });+ } catch {+ throw new Error('Could not read that HEIC photo. Try exporting it as JPG.');+ }+ }+}diff --git a/src/reference/referenceTool.ts b/src/reference/referenceTool.tsnew file mode 100644index 0000000..2599382--- /dev/null+++ b/src/reference/referenceTool.ts@@ -0,0 +1,246 @@+import type { WatercolorEngine } from '../engine/Engine';+import { icon } from '../ui/icons';+import { decodeImage, IMAGE_ACCEPT } from './decode';++const KEY = 'watercolor.reference';+const MIN_PX = 24; // smallest the reference can be scaled to, in CSS px++interface Stored { opacity: number; visible: boolean }++/** A rectangle in client (CSS) px. */+interface Box { l: number; t: number; w: number; h: number }++export interface ReferenceController {+ panel: HTMLElement;+ /** Is the move / scale frame up? */+ readonly adjusting: boolean;+ load(file: File): Promise<boolean>;+ toggleVisible(): void;+ /** Leave move / scale mode; true if it was on. */+ stopAdjust(): boolean;+ /** Re-place the frame after the window or document changed. */+ layout(): void;+}++/**+ * A photo or sketch shown under the paint to work from. It lives only on screen: the+ * engine never draws it into an export. While adjusting, a frame over it moves (drag),+ * scales (corners, wheel, pinch) and painting is paused.+ */+export function createReference(+ engine: WatercolorEngine, root: HTMLElement, showToast: (s: string) => void,+ onAdjust: (on: boolean) => void,+): ReferenceController {+ let stored: Stored = { opacity: 0.5, visible: true };+ try { stored = { ...stored, ...JSON.parse(localStorage.getItem(KEY) ?? '{}') }; } catch { /* storage blocked */ }+ engine.referenceOpacity = stored.opacity;+ engine.referenceVisible = stored.visible;+ const persist = () => {+ try { localStorage.setItem(KEY, JSON.stringify({ opacity: engine.referenceOpacity, visible: engine.referenceVisible })); } catch { /* storage blocked */ }+ };++ const panel = document.createElement('div');+ panel.className = 'panel popover reference';+ panel.hidden = true;+ panel.setAttribute('role', 'dialog');+ panel.setAttribute('aria-label', 'Reference image');+ panel.innerHTML = `+ <div class="pop-head"><span>Reference</span><span class="sub">Shown under the paint to work from. Never exported.</span></div>+ <button class="import" data-ref="import">${icon('plus', 16)}<span>Import image…</span></button>+ <label class="slider"><span>Opacity</span><input type="range" min="0" max="1" step="0.01" data-ref="opacity"></label>+ <div class="seg">+ <button data-ref="show" title="Show or hide the reference (R)">Show</button>+ <button data-ref="adjust" title="Drag to move, drag a corner or pinch to scale">Move</button>+ <button data-ref="fit" title="Fit to the paper">Fit</button>+ <button data-ref="remove" title="Remove the reference">Remove</button>+ </div>+ <input type="file" accept="${IMAGE_ACCEPT}" hidden>`;+ root.appendChild(panel);++ const fileInput = panel.querySelector<HTMLInputElement>('input[type="file"]')!;+ const opacity = panel.querySelector<HTMLInputElement>('[data-ref="opacity"]')!;+ const btn = (k: string) => panel.querySelector<HTMLButtonElement>(`[data-ref="${k}"]`)!;++ const frame = document.createElement('div');+ frame.className = 'ref-frame';+ frame.hidden = true;+ frame.innerHTML = ['nw', 'ne', 'sw', 'se'].map(c => `<i data-corner="${c}"></i>`).join('');+ root.appendChild(frame);++ let adjusting = false;++ function render() {+ const has = engine.hasReference;+ opacity.value = String(engine.referenceOpacity);+ opacity.disabled = !has;+ for (const k of ['show', 'adjust', 'fit', 'remove']) btn(k).disabled = !has;+ btn('show').classList.toggle('on', has && engine.referenceVisible);+ btn('adjust').classList.toggle('on', adjusting);+ btn('import').querySelector('span')!.textContent = has ? 'Replace image…' : 'Import image…';+ layout();+ }++ /* ------------------------------------------------- doc uv <-> client box */++ function box(): Box {+ const r = engine.referenceRect;+ const [l, t] = engine.docToClient(r.x, r.y + r.h);+ const [rr, b] = engine.docToClient(r.x + r.w, r.y);+ return { l, t, w: rr - l, h: b - t };+ }++ function setBox(b: Box) {+ const [x0, y0] = engine.clientToDoc(b.l, b.t + b.h);+ const [x1, y1] = engine.clientToDoc(b.l + b.w, b.t);+ engine.referenceRect = { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };+ layout();+ }++ function layout() {+ frame.hidden = !adjusting || !engine.hasReference;+ if (frame.hidden) return;+ const b = box();+ Object.assign(frame.style, { left: `${b.l}px`, top: `${b.t}px`, width: `${b.w}px`, height: `${b.h}px` });+ }++ /** Scale the box by `s` about the client point (cx, cy), keeping a sensible minimum. */+ function scaleAbout(b: Box, s: number, cx: number, cy: number): Box {+ s = Math.max(s, MIN_PX / Math.min(b.w, b.h));+ return { l: cx + (b.l - cx) * s, t: cy + (b.t - cy) * s, w: b.w * s, h: b.h * s };+ }++ /* ------------------------------------------------------------- gestures */++ const pointers = new Map<number, { x: number; y: number }>();+ let gesture:+ | { kind: 'move'; start: Box; x: number; y: number }+ | { kind: 'corner'; start: Box; ax: number; ay: number; sx: number; sy: number }+ | { kind: 'pinch'; start: Box; mx: number; my: number; dist: number }+ | null = null;++ function beginGesture(corner?: string) {+ const start = box();+ const pts = [...pointers.values()];+ if (pts.length >= 2) {+ const [a, b] = pts;+ gesture = { kind: 'pinch', start, mx: (a.x + b.x) / 2, my: (a.y + b.y) / 2, dist: Math.max(1, Math.hypot(a.x - b.x, a.y - b.y)) };+ } else if (corner) {+ // the opposite corner stays put; sx / sy say which way the box grows from it+ const sx = corner.includes('e') ? 1 : -1, sy = corner.includes('s') ? 1 : -1;+ gesture = { kind: 'corner', start, ax: sx > 0 ? start.l : start.l + start.w, ay: sy > 0 ? start.t : start.t + start.h, sx, sy };+ } else {+ gesture = { kind: 'move', start, x: pts[0].x, y: pts[0].y };+ }+ }++ frame.addEventListener('pointerdown', e => {+ e.preventDefault();+ frame.setPointerCapture(e.pointerId);+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });+ beginGesture((e.target as HTMLElement).dataset.corner);+ });++ frame.addEventListener('pointermove', e => {+ if (!pointers.has(e.pointerId) || !gesture) return;+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });+ const g = gesture;+ if (g.kind === 'move') {+ setBox({ ...g.start, l: g.start.l + e.clientX - g.x, t: g.start.t + e.clientY - g.y });+ } else if (g.kind === 'corner') {+ const s = Math.max((g.sx * (e.clientX - g.ax)) / g.start.w, (g.sy * (e.clientY - g.ay)) / g.start.h, MIN_PX / Math.min(g.start.w, g.start.h));+ const w = g.start.w * s, h = g.start.h * s;+ setBox({ l: g.sx > 0 ? g.ax : g.ax - w, t: g.sy > 0 ? g.ay : g.ay - h, w, h });+ } else {+ const [a, b] = [...pointers.values()];+ const mx = (a.x + b.x) / 2, my = (a.y + b.y) / 2;+ const s = Math.hypot(a.x - b.x, a.y - b.y) / g.dist;+ const scaled = scaleAbout(g.start, s, g.mx, g.my);+ setBox({ ...scaled, l: scaled.l + mx - g.mx, t: scaled.t + my - g.my });+ }+ });++ const release = (e: PointerEvent) => {+ if (!pointers.delete(e.pointerId)) return;+ // a pinch that loses a finger carries on as a move with the one left+ if (pointers.size) beginGesture(); else gesture = null;+ };+ frame.addEventListener('pointerup', release);+ frame.addEventListener('pointercancel', release);++ frame.addEventListener('wheel', e => {+ e.preventDefault();+ // trackpad pinches arrive as ctrl+wheel with small deltas+ const s = Math.exp(-e.deltaY * (e.ctrlKey ? 0.01 : 0.0015));+ setBox(scaleAbout(box(), s, e.clientX, e.clientY));+ }, { passive: false });++ /* ------------------------------------------------------------ actions */++ function setAdjust(on: boolean) {+ on &&= engine.hasReference;+ if (on === adjusting) return;+ adjusting = on;+ pointers.clear();+ gesture = null;+ if (on && !engine.referenceVisible) { engine.referenceVisible = true; persist(); }+ onAdjust(on);+ render();+ }++ async function load(file: File): Promise<boolean> {+ try {+ const bmp = await decodeImage(file);+ engine.setReference(bmp);+ bmp.close();+ if (!engine.referenceVisible) { engine.referenceVisible = true; persist(); }+ render();+ showToast('Reference added');+ return true;+ } catch (e) {+ showToast(e instanceof Error ? e.message : 'Could not read that image');+ return false;+ }+ }++ panel.addEventListener('click', e => {+ const k = (e.target as Element).closest<HTMLElement>('[data-ref]')?.dataset.ref;+ switch (k) {+ case 'import': fileInput.click(); break;+ case 'show': engine.referenceVisible = !engine.referenceVisible; persist(); render(); break;+ case 'adjust': setAdjust(!adjusting); break;+ case 'fit': engine.fitReference(); render(); break;+ case 'remove': setAdjust(false); engine.setReference(null); render(); break;+ }+ });++ opacity.addEventListener('input', () => {+ engine.referenceOpacity = Number(opacity.value);+ if (!engine.referenceVisible) engine.referenceVisible = true;+ persist();+ render();+ });++ fileInput.addEventListener('change', () => {+ const f = fileInput.files?.[0];+ fileInput.value = '';+ if (f) void load(f);+ });++ render();++ return {+ panel,+ get adjusting() { return adjusting; },+ load,+ toggleVisible() {+ if (!engine.hasReference) return;+ engine.referenceVisible = !engine.referenceVisible;+ if (!engine.referenceVisible) setAdjust(false);+ persist();+ render();+ showToast(engine.referenceVisible ? 'Reference shown' : 'Reference hidden');+ },+ stopAdjust() { const was = adjusting; setAdjust(false); return was; },+ layout,+ };+}diff --git a/src/styles.css b/src/styles.cssindex 9f4feae..47587f1 100644--- a/src/styles.css+++ b/src/styles.css@@ -145,6 +145,44 @@ button { font: inherit; color: inherit; }}.slider { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px; }.slider span { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }+/* reference + save panels: drop down under the action bar like the settings */+.popover {+ right: calc(14px + env(safe-area-inset-right)); top: calc(84px + env(safe-area-inset-top));+ width: 268px; padding: 12px 14px 12px;+ display: flex; flex-direction: column; gap: 10px;+}+.pop-head { display: flex; flex-direction: column; gap: 3px; }+.pop-head > span:first-child { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink); }+.pop-head .sub { font-size: 10px; color: var(--ink-faint); line-height: 1.4; }+.popover .import { align-self: flex-start; }+.popover .field { display: flex; flex-direction: column; gap: 5px; }+.popover .field > span { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }+.panel button.primary {+ flex-direction: row; justify-content: center; padding: 8px 10px;+ background: rgba(42, 42, 51, 0.82); color: #f6f3ec;+ font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase;+}+.panel button.primary:hover:not(:disabled) { background: rgba(42, 42, 51, 0.92); color: #fff; }++/* the reference image's move / scale frame */+.ref-frame {+ position: fixed; z-index: 4; cursor: move; touch-action: none;+ outline: 1px dashed rgba(42, 42, 51, 0.7); outline-offset: -1px;+ box-shadow: 0 0 0 1px rgba(246, 243, 236, 0.6);+}+.ref-frame i {+ position: absolute; width: 14px; height: 14px; margin: -7px;+ background: #f6f3ec; border: 1px solid rgba(42, 42, 51, 0.7); border-radius: 3px;+}+.ref-frame i[data-corner="nw"] { left: 0; top: 0; cursor: nwse-resize; }+.ref-frame i[data-corner="ne"] { right: 0; top: 0; cursor: nesw-resize; }+.ref-frame i[data-corner="sw"] { left: 0; bottom: 0; cursor: nesw-resize; }+.ref-frame i[data-corner="se"] { right: 0; bottom: 0; cursor: nwse-resize; }++/* asks what a dropped image is for */+.drop-choice { z-index: 7; display: flex; gap: 4px; padding: 6px; }+.drop-choice button { flex-direction: row; gap: 6px; padding: 8px 12px; }+.settings .reset { align-self: flex-end; padding: 4px 6px; font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; }input[type="range"] {@@ -164,10 +202,11 @@ input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radiusleft: 50%; transform: translateX(-50%);bottom: calc(14px + env(safe-area-inset-bottom));max-width: calc(100vw - 28px);- padding: 8px 10px 6px;- display: flex; flex-direction: column; align-items: center; gap: 4px;+ padding: 2px 4px 6px;+ display: flex; flex-direction: column; align-items: center; gap: 2px;}-.swatches { display: flex; gap: 6px; overflow-x: auto; max-width: 100%; padding: 4px 2px; scrollbar-width: none; }+/* room inside the scroller for the selected swatch's lift, scale and ring, which it would otherwise clip */+.swatches { display: flex; gap: 6px; overflow-x: auto; max-width: 100%; padding: 10px 7px 4px; scroll-padding-inline: 7px; scrollbar-width: none; }.swatches::-webkit-scrollbar { display: none; }.panel .swatch, .swatch {@@ -210,7 +249,8 @@ input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius.brush .stroke { width: 100%; height: 40px; }.panel .import span { display: inline; }.toast { top: calc(60px + env(safe-area-inset-top)); }- .settings { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); right: 10px; }+ .settings, .popover { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); right: 10px; }+ .popover .import span, .drop-choice button span, .panel button.primary span { display: inline; }.palette { bottom: calc(10px + env(safe-area-inset-bottom)); }}diff --git a/src/ui/customBrushes.ts b/src/ui/customBrushes.tsindex 90715d0..8f6a049 100644--- a/src/ui/customBrushes.ts+++ b/src/ui/customBrushes.ts@@ -1,4 +1,5 @@import { buildBrush, CUSTOM_BASE, TIP_SIZE, type Brush } from '../engine/brushes';+import { decodeImage } from '../reference/decode';const KEY = 'watercolor.customBrushes';@@ -6,7 +7,7 @@ interface Stored { id: string; name: string; png: string }/** Read an image file into tip data: luminance (inverted on a light background) times alpha. */export async function tipFromImage(file: Blob): Promise<Uint8Array> {- const bmp = await createImageBitmap(file);+ const bmp = await decodeImage(file);const n = TIP_SIZE;const c = document.createElement('canvas');c.width = n; c.height = n;diff --git a/src/ui/icons.ts b/src/ui/icons.tsindex 8e88a13..5c6f4b7 100644--- a/src/ui/icons.ts+++ b/src/ui/icons.ts@@ -10,6 +10,7 @@ const PATHS: Record<string, string> = {fill: 'M10 3.5 4.5 9l7 7 5.5-5.5Z M4.5 9c2 .5 4 .5 6-1 M10 3.5 7.5 1.5 M19 13c1.3 1.8 2 3 2 3.9a2 2 0 0 1-4 0c0-.9.7-2.1 2-3.9Z',dry: 'M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z M12 2v2.5 M12 19.5V22 M2 12h2.5 M19.5 12H22 M4.9 4.9l1.8 1.8 M17.3 17.3l1.8 1.8 M4.9 19.1l1.8-1.8 M17.3 6.7l1.8-1.8',clear: 'M5 7h14 M10 7V4.5h4V7 M7 7l1 13h8l1-13',+ image: 'M4 5h16v14H4Z M4 16l5-5 4 4 2.5-2.5L20 17 M15.5 7.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Z',save: 'M12 4v11 M7.5 10.5 12 15l4.5-4.5 M5 19.5h14',sliders: 'M4 7h9 M17 7h3 M4 17h3 M11 17h9 M15 5v4 M9 15v4',library: 'M4 5.5h6v6H4Z M14 5.5h6v6h-6Z M4 14.5h6v6H4Z M14 14.5h6v6h-6Z',diff --git a/vite.config.ts b/vite.config.tsindex 0229c22..b257bfe 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -3,4 +3,6 @@ import { defineConfig } from 'vite';export default defineConfig({base: './',server: { host: true },+ // the HEIC decoder (~3 MB) is its own chunk, only fetched when an iPhone photo needs it+ build: { chunkSizeWarningLimit: 3500 },});