From c4b6e307070de4a2f055a6856b397460ad06f9e1 Mon Sep 17 00:00:00 2001 From: Robert Douglas <57234112+realrobertdouglas@users.noreply.github.com> Date: Tue, 13 Oct 2026 14:49:10 -0500 Subject: [PATCH] feat(ghost): Stamp hands the ghost back to the cursor (STAMP-PICKUP) Wendi: "i want the text and box to go away after using a ghost stamp." The box and the word Typical are the ghost itself, which survived its own stamp by design so it could be dragged to the next location and stamped again; clearing it meant right-click, Delete ghost, after every stamp. The next stamp is served better by carrying the ghost than by leaving it. - Stamp lands the marks and hands the ghost back to the cursor, grabbed where the menu was opened, as it rides between capture and the first drop. Nothing stays over the marks just stamped. The next click drops it on the next spot; Esc lets it go ("Ghost dropped. The stamped marks stay."); any other tool orphans it as before. - Undo of a stamp takes the marks back and puts the ghost back on the sheet, so the copy in hand is dropped rather than doubled (state.placingGhostFromStamp, read by app.js undo/redo through dropGhostPickedUpByStamp); a ghost in hand from a capture is untouched by an unrelated undo. - features/ghost.js, app.js, ghost.spec.js (the new test: stamp, in hand with the grab point, the next drop, stamp again, Esc, undo and redo, a captured ghost's undo), the ARCHITECTURE row, CHANGELOG, sw.js and the TOC restamped. npm run check: all 14 steps pass. ghost.spec.js 17/17; duct-ghost and esc-ladder specs pass. Walked in the browser on test-page.pdf: capture, place, Stamp from the menu, the ghost riding the pointer with nothing over the stamped marks, Esc leaving only real marks. Co-Authored-By: Claude Fable 5.1 --- ARCHITECTURE.md | 126 +++++++++++++++++++++++----------------------- CHANGELOG.md | 21 ++++++++ app.js | 16 +++++- features/ghost.js | 34 +++++++++++-- ghost.spec.js | 68 +++++++++++++++++++++++++ sw.js | 6 +-- 6 files changed, 198 insertions(+), 73 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 9b7578cb..91cfdf60 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -28,18 +28,18 @@ off — and where it doesn't. | File | Lines | Status / verdict | |------|------:|------------------| -| [app.js](app.js) | 7,159 | **The remaining monolith** — down from 16.2k (9.9k after save-engine Stage 6, 8.1k after the Tier-2 splits, then −987 from the canvas-draw extraction). The only file worth actively shrinking; the region table below says what's left and in what order. | +| [app.js](app.js) | 7,171 | **The remaining monolith** — down from 16.2k (9.9k after save-engine Stage 6, 8.1k after the Tier-2 splits, then −987 from the canvas-draw extraction). The only file worth actively shrinking; the region table below says what's left and in what order. | | [save-engine.js](save-engine.js) | 3,263 | Done — the extracted save/sync seam module (Stages 1–7), 91 node tests. R21 (2026-09-26) folded its repeated blocks inside the file; do not split it. Large but modular and fully node-testable; no further action. | | [pdf-tile-cache.js](pdf-tile-cache.js) | 867 | Done (stage 1, 2026-07-30) — the PDF raster-cache substrate extracted from app.js's "PDF render bitmap cache" section (`createPdfTileCache(ctx)`, the save-engine seam recipe): page-bitmap LRU, downsample pyramid, persisted zoom rungs, idle prefetch, full-document warm-up. Pinned by nine Playwright specs (page-switch-cache, pyramid, pyramid-persist, rung-prefetch, doc-warmup, zoom-ladder, commit-tile, crop-tile, tile-grid). Stage 2 (later): the Sharp crop tile / tile grid section. | | [canvas-draw.js](canvas-draw.js) | 1,417 | Done — the unified annotation draw core (`createCanvasDraw(deps)` + `drawAnnotationsCore`), node-tested, guarded by [render-pixels.spec.js](render-pixels.spec.js). Both draw paths are thin env-builders over it. | | [app/index.html](app/index.html) | 3,880 | The shell: HTML structure + every modal, no inline JS. Flat markup with no build step to split it; grows roughly linearly with modal count. Leave. | -| [styles.css](styles.css) | 2,879 | All CSS, token-organized. Leave. | +| [styles.css](styles.css) | 2,880 | All CSS, token-organized. Leave. | | [features/load-project.js](features/load-project.js) | 751 | Largest feature file (Load Project modal + filters), split 2026-07-30: the copy/fork domain moved to [features/copy-project.js](features/copy-project.js) at the file's documented domain boundary, and the row renderer was decomposed along its action boundaries (size / row HTML / actions / admin access / load click). Healthy — leave. | | [annotation-model.js](annotation-model.js) | 1,225 | Done — extracted canvas/annotation data model + node tests. | | [undo-stack.js](undo-stack.js) | 218 | Done (2026-07-30) — `createUndoStack(ctx)` split out of annotation-model.js: the model is pure-ish data transformation, the stack is a command-history controller with UI side-effect hooks in its ctx. Covered by the undo tests in [annotation-model.test.js](annotation-model.test.js) (interleaved with model tests, dual-require). | | [icons.js](icons.js) | 531 | Bundled icon data, mostly literals. Leave. | | [report.js](report.js) | 991 | Self-contained report builder with a frozen `window.*` contract. Leave. | -| `features/*.js` (108 files) | 37,489 total | Mostly single-feature files with their own specs. The largest are the teaching layer (tutorial 1,656; lessons 1,043, the three courses 609 to 725; tour-blank 794) and duct-tool (866); DECOMPOSITION_MAP.md has a verdict for every one. | +| `features/*.js` (108 files) | 37,513 total | Mostly single-feature files with their own specs. The largest are the teaching layer (tutorial 1,656; lessons 1,043, the three courses 609 to 725; tour-blank 794) and duct-tool (866); DECOMPOSITION_MAP.md has a verdict for every one. | ### What's left inside app.js (by `// SECTION:` size) @@ -246,7 +246,7 @@ modules. Candidates in priority order: | [features/save-project.js](features/save-project.js) | The **Save Project modal**: open/prefill with the PDF-size probe ladder (buffer → IDB `pdfCacheGet` → storage `.info`), the Include-PDF toggle pair, and the Save action with the three-tier checkout-expiry preflight (`probeCheckoutLock`) and the stale-cloud-PDF confirm, delegating to `performSaveProjectToCloud`. In the canvas-only state (a bid open without its PDF, `App.isCanvasOnlyPending()`, the engine's MAP-EMPTY-SAVE test published by app.js) it rewords `#saveProjectNoPdfMessage` to say the marks can't be saved until the PDF is back and disables Save (MAP-MANUAL-SAVE; the engine holds the write too). Registers **nothing** — the zone-modals pattern; every handler moved with its DOM element. Coverage rides [upload-then-save.spec.js](upload-then-save.spec.js) (dev-auth-gated) and [indexeddb-backup.spec.js](indexeddb-backup.spec.js) (no name-matched spec; the expiry preflight is untested). | | [features/line-color.js](features/line-color.js) | The **shared color-selection service** (registry split #36): `showLineColorModal(currentColor, onApply)` (callback stashed on `state.pendingLineColorApply`), `pushRecentColor` (custom-only recents via the pure `nextRecentColors`, localStorage-persisted), and `setupCreateColorPicker(opts)` (the Presets / custom / Recent picker embedded in the three create surfaces). Consumed by features/item-details.js, counter.js, choose-create-line-type.js, quick-line.js, and app.js — a shared dependency of four feature files, so it must not be merged into any one of them. Reads `COLORS` / `nextRecentColors` as bare constants.js globals (unlike the other feature files). Regression: [create-color-picker.spec.js](create-color-picker.spec.js) (no name-matched spec). | | [features/custom-icon-upload.js](features/custom-icon-upload.js) | **Custom icon upload** (registry split #37): `parseUploadedSvg` (SVG path/rect/circle/ellipse/line → normalized path icon) + the `#customIconUploadInput` handler that persists the icon (`getUserCustomIcons`/`saveUserCustomIcons`) and refreshes the three custom icon grids (Create Counter, Quick Count, Details). The Create Counter grid is rebuilt by its owner's builder, `App.buildCreateCustomIconGrid` ([features/counter.js](features/counter.js)), the same one the panel opens with, so a pick after an upload fills the name AND re-reads the fixture units (MAP-ICON-PREFILL, D34); the upload's own autofill re-reads them too (`App.syncWsfuForm('create')`). `selectUploadedIcon` makes the success visible (T2-05 #19): it scrolls the new cell into view (`scrollIntoView({ block: 'nearest' })` — the cell appends below the grid's 200px fold) and adds the one-shot `.flash-new` selection-ring pulse (styles.css `icon-cell-flash` keyframes; no removal listener — every upload rebuilds the grid via `innerHTML`, so the class never survives a rerender). Registers nothing; reads feature-registered members at call time (`App.buildCreateCustomIconGrid` + `App.markCreateIconPicked` from counter.js, `App.syncWsfuForm` from water-fixtures.js, `App.updateCounterQuickCountNamePreview` from quick-modals.js, `App.getCounterLineTypeDetailsItem` from item-details.js). Persistence side covered by [custom-icon-paths-indexeddb.spec.js](custom-icon-paths-indexeddb.spec.js); the upload path by [custom-icon-upload.spec.js](custom-icon-upload.spec.js) (real FileReader + DOMParser walk via `setInputFiles`; grid refresh + selection + name autofill; a custom pick after an upload prefills Fixture units the same as before one; the T2-05 in-scroll-window + `.flash-new` assertions; the no-supported-shapes rejection alert). | -| [features/ghost.js](features/ghost.js) | **The Ghost tool** (PROTOTYPE): rubber-band a batch of placed marks into a translucent reference copy ("a typical"), drag it over another part of the sheet, and optionally **Stamp** it down as real counted marks. Owns the capture→place gesture (`handleGhostCanvasClick`, staged `handleGhostEscape`) and the per-ghost right-click menu (`tryOpenGhostMenuAt` — Stamp / Show counts / Show runs / Delete). The model half is pure in annotation-model.js (`captureGhostFromRect`, `ghostCounts`, `ghostBounds`, `translateGhost`, `stampGhostIntoAnnotations`, `ghostIndexAtPoint`); drawing is `drawGhosts` in canvas-draw.js (live overlay ONLY — never the export path, like the grid). Ghosts are a DISTINCT annotation kind (`ann.ghosts[]`, `{ id, label, showCounters, showLines, src }` with src annotation-shaped in absolute PDF-space) so no tally surface can read them; Stamp is the single door to counted marks. MAP-GHOST-DELETE: registers `App.purgeFromEveryGhost(kind, id)`, which the delete cascades (item-details.js `performDeleteCounterLineType`, groups.js `deleteGroup`) call after pruning the live marks; it runs the pure `purgeFromGhosts` over every page and layer plus the ghost riding the cursor, and drops `activeGhostId` / the open menu for a ghost it emptied, so a deleted type or group cannot be stamped back uncounted. App.* deps: state, TOOL, ensureActiveCanvas, getActiveAnnotations, getPageCanvases, pushUndoSnapshot, markProjectDirty, showToast, placeFixedMenu, renderAnnotations, updateUI, logUserEvent + the model wrappers (and `purgeFromGhosts`). Hotkey G. | +| [features/ghost.js](features/ghost.js) | **The Ghost tool** (PROTOTYPE): rubber-band a batch of placed marks into a translucent reference copy ("a typical"), drag it over another part of the sheet, and optionally **Stamp** it down as real counted marks. Owns the capture→place gesture (`handleGhostCanvasClick`, staged `handleGhostEscape`) and the per-ghost right-click menu (`tryOpenGhostMenuAt` — Stamp / Show counts / Show runs / Delete). The model half is pure in annotation-model.js (`captureGhostFromRect`, `ghostCounts`, `ghostBounds`, `translateGhost`, `stampGhostIntoAnnotations`, `ghostIndexAtPoint`); drawing is `drawGhosts` in canvas-draw.js (live overlay ONLY — never the export path, like the grid). Ghosts are a DISTINCT annotation kind (`ann.ghosts[]`, `{ id, label, showCounters, showLines, src }` with src annotation-shaped in absolute PDF-space) so no tally surface can read them; Stamp is the single door to counted marks. STAMP-PICKUP (2026-10-13, Wendi): Stamp hands the ghost back to the cursor: the marks land, the ghost leaves `ann.ghosts` and rides the pointer again (`state.placingGhost`, grabbed where the menu was opened, `state.placingGhostFromStamp`), so nothing stays over the stamped marks and the next spot is one click away; Esc lets it go, another tool orphans it, and app.js's undo/redo drop it (`dropGhostPickedUpByStamp`), since the undo of the stamp puts the ghost back on the sheet. MAP-GHOST-DELETE: registers `App.purgeFromEveryGhost(kind, id)`, which the delete cascades (item-details.js `performDeleteCounterLineType`, groups.js `deleteGroup`) call after pruning the live marks; it runs the pure `purgeFromGhosts` over every page and layer plus the ghost riding the cursor, and drops `activeGhostId` / the open menu for a ghost it emptied, so a deleted type or group cannot be stamped back uncounted. App.* deps: state, TOOL, ensureActiveCanvas, getActiveAnnotations, getPageCanvases, pushUndoSnapshot, markProjectDirty, showToast, placeFixedMenu, renderAnnotations, updateUI, logUserEvent + the model wrappers (and `purgeFromGhosts`). Hotkey G. | | [ghost.spec.js](ghost.spec.js) | Playwright regression for features/ghost.js: registry contract + G arming, the three-click capture→place gesture leaving every tally untouched (footer text pinned byte-identical), the both-ends capture rule + empty-box refusal, the staged Escape ladder, show/hide toggles gating Stamp, Stamp minting fresh-id real marks with the ghost surviving for the next drop, and the save/load sanitizer roundtrip. MAP-GHOST-DELETE: deleting a counter, a line type (the details modal's Delete + confirm) or a group (`App.deleteGroup` + `#confirmOk`) empties it out of the Typical, and a Stamp from the ghost menu brings back none of it; deleting everything a Typical held removes the Typical. | | [features/hotkey-peek.js](features/hotkey-peek.js) | **Hotkey peek**: hold Cmd (or Alt) about 1.5s to show a `` badge on every visible control that has a hotkey (`body.hotkey-peek`); release, blur or a second key hides or cancels it. Badges are stamped lazily from `App.HOTKEYS` (so they cannot drift from the keydown handler); runner entries map through `RUNNER_BADGE_TARGETS`. Adds a visual layer only, never handles a hotkey. Debug seam `App.__hotkeyPeekState`. Spec: [hotkey-peek.spec.js](hotkey-peek.spec.js). | | [keyboard-map.spec.js](keyboard-map.spec.js) | Playwright regression for the Keyboard Map — the load-bearing test is the **derivation guard**: it walks every `` in the Macros table, normalizes it with a mirror of the feature's `normalizeKeyToken`, and asserts each one resolves to a board key that is lit (so a future shortcut row the board can't represent fails CI-adjacent local runs rather than silently going dark). Split by breakpoint: the **desktop** describe (default viewport) asserts the inline board is pre-built and visible on Macros-open with **no second click**, the See Keyboard button and its modal stay out of the way, the tool hotkeys `M/S/C/L/J/P/D/R/H/X/V/N/Z/Q` + Space/Escape/arrows are lit, modifiers are outlined rather than filled, an unmapped key (`G`) is a plain silhouette, and the hover caption names the action (incl. a two-action key); a second desktop test asserts the layout contract — card within the viewport, the **body** (not the card) scrolling, and the board sitting above it. The **mobile** describe (375×812) asserts the inverse visibility, that the button opens the modal on top of the list, that the board scrolls inside `.kb-board-wrap` without the page body overflowing, Escape ordering (board first, then the list), and the close button. Both run the derivation guard against their own host. Filters the gitignored `/config.local.js` 404 like [render-pixels.spec.js](render-pixels.spec.js). `npx playwright test keyboard-map.spec.js` | @@ -663,65 +663,65 @@ live list with current `app.js` line numbers is generated by `npm run build:toc` - L737 - [sync] Field-error telemetry - L796 - [sync] Dirty tracking & local session reset - L802 - Undo/redo stacks -- L1001 - [sync] Checkout probe, hashing & PDF cache -- L1063 - Math & Format Helpers -- L1583 - Coordinate Helpers -- L1591 - PDF render bitmap cache -- L1645 - Sharp crop tile (deep-zoom sharpening + window-first commits) -- L1656 - PDF Rendering -- L2531 - Recent bids -- L2558 - UI Render Functions -- L2915 - Placing selection (setActiveCounterType / setActiveLineType) -- L3025 - Inline rename & polyline edit mode -- L3141 - Modal primitives (showModal / hideModal) -- L3307 - Toasts & line color picker -- L3376 - Airboard cloud sync -- L3421 - Supabase RPC & presence heartbeat -- L3461 - User activity / event telemetry -- L3520 - Supabase auth & dev auth -- L3711 - [sync] Checkout subscription & permission refresh -- L3721 - Modals & Handlers -- L3789 - PDF intake (upload, test PDF, hashing) -- L3797 - Toolbar tool buttons -- L3958 - Tool sidebar buttons & legend overlay -- L4044 - Add Line Type modal -- L4126 - Line color & sidebar handlers -- L4197 - Polyline modal & drawing -- L4254 - Zoom bar & page navigation -- L4280 - Export canvas JSON -- L4305 - PDF download helpers -- L4314 - View-link URL helpers & show-highlights/notes -- L4346 - Custom icon upload handler -- L4356 - Macros & custom-icon tips openers -- L4376 - Sidebar drawer toggles -- L4407 - Mobile actions burger menu pointer & header logo -- L4419 - User Activity pointer (format.js + features/user-activity.js) -- L4431 - My Settings pointer (features/my-settings.js) -- L4456 - Project Settings pointer (features/project-settings.js) -- L4462 - Auth & settings entry buttons - - L4507 - Project Settings checkout & Save Status bell - - L4620 - [sync] Checkout expired recovery - - L4676 - [sync] Turn In - - L4741 - Share modal pointer & copy-project openers - - L4772 - Settings menu actions - - L4784 - Auth sign-in form - - L4809 - Save Project modal - - L4820 - Checkout expired recovery modal wiring - - L4923 - Last-session restore prompt -- L4935 - Canvas Event Handlers -- L5319 - Event Binding -- L5329 - Aim loupe (mobile press-hold precise placement) -- L5482 - Zoom transform preview & commit -- L5561 - Canvas mouse, wheel & touch handlers -- L6250 - Global dropdown dismissal & keyboard hotkeys -- L6428 - [sync] Manual save to cloud -- L6438 - [sync] Auto-save -- L6445 - [sync] Local backup (IndexedDB takeoff state) -- L6454 - [sync] Visibility & timers -- L6471 - [sync] Checkout keep-alive -- L6485 - App feature registry -- L6878 - View-only mode -- L6884 - Init / boot +- L1012 - [sync] Checkout probe, hashing & PDF cache +- L1074 - Math & Format Helpers +- L1594 - Coordinate Helpers +- L1602 - PDF render bitmap cache +- L1656 - Sharp crop tile (deep-zoom sharpening + window-first commits) +- L1667 - PDF Rendering +- L2542 - Recent bids +- L2569 - UI Render Functions +- L2926 - Placing selection (setActiveCounterType / setActiveLineType) +- L3037 - Inline rename & polyline edit mode +- L3153 - Modal primitives (showModal / hideModal) +- L3319 - Toasts & line color picker +- L3388 - Airboard cloud sync +- L3433 - Supabase RPC & presence heartbeat +- L3473 - User activity / event telemetry +- L3532 - Supabase auth & dev auth +- L3723 - [sync] Checkout subscription & permission refresh +- L3733 - Modals & Handlers +- L3801 - PDF intake (upload, test PDF, hashing) +- L3809 - Toolbar tool buttons +- L3970 - Tool sidebar buttons & legend overlay +- L4056 - Add Line Type modal +- L4138 - Line color & sidebar handlers +- L4209 - Polyline modal & drawing +- L4266 - Zoom bar & page navigation +- L4292 - Export canvas JSON +- L4317 - PDF download helpers +- L4326 - View-link URL helpers & show-highlights/notes +- L4358 - Custom icon upload handler +- L4368 - Macros & custom-icon tips openers +- L4388 - Sidebar drawer toggles +- L4419 - Mobile actions burger menu pointer & header logo +- L4431 - User Activity pointer (format.js + features/user-activity.js) +- L4443 - My Settings pointer (features/my-settings.js) +- L4468 - Project Settings pointer (features/project-settings.js) +- L4474 - Auth & settings entry buttons + - L4519 - Project Settings checkout & Save Status bell + - L4632 - [sync] Checkout expired recovery + - L4688 - [sync] Turn In + - L4753 - Share modal pointer & copy-project openers + - L4784 - Settings menu actions + - L4796 - Auth sign-in form + - L4821 - Save Project modal + - L4832 - Checkout expired recovery modal wiring + - L4935 - Last-session restore prompt +- L4947 - Canvas Event Handlers +- L5331 - Event Binding +- L5341 - Aim loupe (mobile press-hold precise placement) +- L5494 - Zoom transform preview & commit +- L5573 - Canvas mouse, wheel & touch handlers +- L6262 - Global dropdown dismissal & keyboard hotkeys +- L6440 - [sync] Manual save to cloud +- L6450 - [sync] Auto-save +- L6457 - [sync] Local backup (IndexedDB takeoff state) +- L6466 - [sync] Visibility & timers +- L6483 - [sync] Checkout keep-alive +- L6497 - App feature registry +- L6890 - View-only mode +- L6896 - Init / boot diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b5c77a..1b2591f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,27 @@ expired recovery UX" work occupies that slot). --- +## feat(ghost): Stamp hands the ghost back to the cursor (STAMP-PICKUP, 2026-10-13) + +Wendi: "i want the text and box to go away after using a ghost stamp." The box and the word +Typical are the ghost itself, which survived its own stamp by design so it could be dragged +to the next location and stamped again; clearing it meant right-click, Delete ghost, after +every stamp. The same next-stamp is served better by carrying the ghost than by leaving it. + +- **Stamp** now lands the marks and hands the ghost back to the cursor, grabbed where the menu + was opened, exactly as it rides between capture and the first drop. Nothing stays over the + marks just stamped. The next click drops it on the next spot; Esc lets it go ("Ghost + dropped. The stamped marks stay."); any other tool orphans it as before. +- **Undo** of a stamp takes the marks back and puts the ghost back on the sheet, so the copy in + hand is dropped rather than doubled (`state.placingGhostFromStamp`, read by app.js's undo and + redo through `dropGhostPickedUpByStamp`); a ghost in hand from a capture is untouched by an + unrelated undo, since no step holds it. On touch nothing moves until the next tap, which is + how placement already works there. +- features/ghost.js (the stamp branch, the grab point from the menu, Esc, the purge), app.js + (the state field, clearToolStarts, undo/redo), ghost.spec.js (the new test: stamp, in hand + with the grab point, the next drop, stamp again, Esc, undo and redo, a captured ghost's undo), + the ARCHITECTURE row, sw.js and the TOC restamped. + ## style(bid-board): the cloud says nothing unless it is missing (CLOUD-OFF-ICON, 2026-10-13) Will, on the quieter cards: "when something is fully cloud I would like to see nothing; when diff --git a/app.js b/app.js index e7397ee9..591e00a7 100644 --- a/app.js +++ b/app.js @@ -296,7 +296,7 @@ const state = { pages: [], currentPage: 0, zoom: 1.0, tool: TOOL.NONE, scaleMode: SCALE_MODES.NONE, scalePointA: null, scalePointB: null, gridOriginPickMode: false, activeCounterType: null, activePolylineId: null, drawingPolyline: null, - quickLineStart: null, highlightStart: null, multiplyZoneStart: null, scaleZoneStart: null, deleteZoneStart: null, roomBoxStart: null, scheduleBoxStart: null, chainStart: null, ghostRectStart: null, placingGhost: null, placingGhostLast: null, activeGhostId: null, draggingGhostIdx: null, draggingGhostLast: null, ghostDragMoved: false, justFinishedDragGhost: false, pendingRoomBox: null, pendingRoomBoxEdit: null, pendingMultiplyZone: null, pendingMultiplyZoneValue: null, pendingMultiplyZoneEdit: null, pendingScaleZone: null, pendingScaleZoneEdit: null, scaleModalApplyTarget: null, scaleCheckMode: false, pendingNote: null, editingNote: null, mousePos: { x: 0, y: 0 }, pan: { x: 0, y: 0 }, isPanning: false, panStart: null, + quickLineStart: null, highlightStart: null, multiplyZoneStart: null, scaleZoneStart: null, deleteZoneStart: null, roomBoxStart: null, scheduleBoxStart: null, chainStart: null, ghostRectStart: null, placingGhost: null, placingGhostLast: null, placingGhostFromStamp: false, activeGhostId: null, draggingGhostIdx: null, draggingGhostLast: null, ghostDragMoved: false, justFinishedDragGhost: false, pendingRoomBox: null, pendingRoomBoxEdit: null, pendingMultiplyZone: null, pendingMultiplyZoneValue: null, pendingMultiplyZoneEdit: null, pendingScaleZone: null, pendingScaleZoneEdit: null, scaleModalApplyTarget: null, scaleCheckMode: false, pendingNote: null, editingNote: null, mousePos: { x: 0, y: 0 }, pan: { x: 0, y: 0 }, isPanning: false, panStart: null, counters: [], lineTypes: [], activeLineTypeId: null, groupsEnabled: false, trade: null, stripPins: {}, ceilingHeightFt: null, makeUpFt: null, codes: null, bidCheck: { manual: {} }, bidCheckCollapsed: true, ctxTarget: null, selectedLineId: null, selectedLineIsPoly: false, selectedLinePageIdx: null, selectedDuctRunId: null, selectedDuctRunPageIdx: null, ductListCollapsed: false, counterSettings: { ...COUNTER_SETTINGS_DEFAULTS }, // per device: merged from localStorage below (MAP-SETTINGS) iconNames: {}, @@ -871,18 +871,29 @@ } // The one undo choke point (Ctrl+Z + the bottom-bar button): a successful // undo toasts how many are left so the 50-step ceiling is never a surprise. + // STAMP-PICKUP (features/ghost.js): a ghost that Stamp handed to the cursor is dropped by + // an undo or redo, since the undo of the stamp puts that ghost back on the sheet (the + // snapshot holds it) and a second copy in hand would double it. A ghost in hand from a + // capture is untouched: no step holds it, so nothing comes back for it to double. + function dropGhostPickedUpByStamp() { + if (!state.placingGhostFromStamp) return; + state.placingGhost = null; + state.placingGhostLast = null; + state.placingGhostFromStamp = false; + } function undo() { // Undo/redo take the snapshot for the opposite stack at apply time, so the // run being edited must be home for those too (else redo drops it). const applied = withEditingPolylineHome(() => undoStackModel.undo()); if (applied) { leaveEditModeIfOrphaned(); + dropGhostPickedUpByStamp(); const left = undoStackModel.undoDepth(); showToast(left + (left === 1 ? ' undo left' : ' undos left'), 1000); } return applied; } - function redo() { const applied = withEditingPolylineHome(() => undoStackModel.redo()); if (applied) leaveEditModeIfOrphaned(); return applied; } + function redo() { const applied = withEditingPolylineHome(() => undoStackModel.redo()); if (applied) { leaveEditModeIfOrphaned(); dropGhostPickedUpByStamp(); } return applied; } function clearUndoStacks() { return undoStackModel.clearUndoStacks(); } function resetAutosaveDegradedState() { return saveEngine.resetAutosaveDegradedState(); } @@ -2945,6 +2956,7 @@ state.ghostRectStart = null; state.placingGhost = null; // a ghost in hand is orphaned by any other tool state.placingGhostLast = null; + state.placingGhostFromStamp = false; if (state.tool !== TOOL.SCALE && (state.scalePointA || state.scalePointB)) { state.scalePointA = null; state.scalePointB = null; state.scaleMode = SCALE_MODES.NONE; } diff --git a/features/ghost.js b/features/ghost.js index 152a9fcf..e4e647c8 100644 --- a/features/ghost.js +++ b/features/ghost.js @@ -17,10 +17,20 @@ // Summary, legend, report, Copy to /Tooling, Copy Summary, the PDF legend) // reads ann.ghosts, so a ghost cannot leak into a number. The single door from // ghost to counted mark is Stamp. +// +// STAMP-PICKUP (2026-10-13, Wendi: "I want the text and box to go away after +// using a ghost stamp"): Stamp hands the ghost back to the cursor. The marks +// land as real marks, the ghost leaves the sheet and rides the pointer again, +// as it did between capture and the first drop, so the next spot is one click +// away and nothing stays over the marks just stamped, no box, no label. Esc +// drops it; another tool orphans it (app.js clearToolStarts); an undo of the +// stamp puts the ghost back on the sheet and drops the one in hand +// (state.placingGhostFromStamp, read by app.js undo/redo). (function () { const App = (window.App = window.App || {}); let menuGhostId = null; + let menuGhostPdf = null; // where the menu was opened, in PDF space: the grab point when Stamp picks the ghost up // --- The capture → place gesture ------------------------------------------ // Three clicks: corner, corner, drop. The two-corner rectangle is the same @@ -56,6 +66,7 @@ } state.placingGhost = null; state.placingGhostLast = null; + state.placingGhostFromStamp = false; return; } @@ -96,9 +107,11 @@ function handleGhostEscape() { const state = App.state; if (state.placingGhost) { + const fromStamp = !!state.placingGhostFromStamp; state.placingGhost = null; state.placingGhostLast = null; - App.showToast('Ghost discarded.', 1600); + state.placingGhostFromStamp = false; + App.showToast(fromStamp ? 'Ghost dropped. The stamped marks stay.' : 'Ghost discarded.', 1600); return true; } if (state.ghostRectStart) { @@ -147,6 +160,7 @@ const menu = document.getElementById('ghostMenu'); if (menu) { menu.classList.remove('visible'); menu.innerHTML = ''; } menuGhostId = null; + menuGhostPdf = null; document.removeEventListener('pointerdown', onGhostMenuDocPointerDown, true); document.removeEventListener('keydown', onGhostMenuDocKeyDown, true); window.removeEventListener('resize', hideGhostMenu); @@ -182,10 +196,19 @@ hideGhostMenu(); return; } + // STAMP-PICKUP: the stamped marks are real now, so the ghost leaves the sheet + // and rides the pointer again for the next spot, grabbed where the menu was + // opened. Nothing stays over the marks just stamped. The undo snapshot above + // holds the ghost in place, so Ctrl+Z puts it back and drops this one (app.js). + const gi = (ann.ghosts || []).indexOf(g); + if (gi >= 0) ann.ghosts.splice(gi, 1); + if (state.activeGhostId === g.id) state.activeGhostId = null; + const b = App.ghostBounds(g); + state.placingGhost = g; + state.placingGhostLast = menuGhostPdf ? { x: menuGhostPdf.x, y: menuGhostPdf.y } : { x: (b.x1 + b.x2) / 2, y: (b.y1 + b.y2) / 2 }; + state.placingGhostFromStamp = true; App.markProjectDirty(); - // The ghost SURVIVES the stamp: the whole point is to move it to the - // next location and stamp again. Undo takes the marks back off. - App.showToast('Stamped ' + describeCounts(res) + '. The ghost stays put for the next one. Stamped in error? Ctrl+Z undoes it.', 4000); + App.showToast('Stamped ' + describeCounts(res) + '. The ghost is in hand for the next spot: click to drop it, Esc to let it go. Ctrl+Z undoes the stamp.', 4000); App.logUserEvent && App.logUserEvent('ghost_stamped', { counters: res.counters, lines: res.lines }); } else if (action === 'toggleCounters') { g.showCounters = g.showCounters === false; @@ -228,7 +251,7 @@ if (state.placingGhost) { const res = App.purgeFromGhosts({ ghosts: [state.placingGhost] }, kind, id); changed += res.changed; - if (res.removedGhostIds.length) { state.placingGhost = null; state.placingGhostLast = null; } + if (res.removedGhostIds.length) { state.placingGhost = null; state.placingGhostLast = null; state.placingGhostFromStamp = false; } } if (state.activeGhostId && removed.includes(state.activeGhostId)) state.activeGhostId = null; if (menuGhostId && removed.includes(menuGhostId)) hideGhostMenu(); @@ -249,6 +272,7 @@ state.activeGhostId = ann.ghosts[i].id; App.renderAnnotations(); openGhostMenu(clientX, clientY, ann.ghosts[i].id); + menuGhostPdf = { x: pdfPos.x, y: pdfPos.y }; return true; } diff --git a/ghost.spec.js b/ghost.spec.js index 4cbf73d9..86bc2aa2 100644 --- a/ghost.spec.js +++ b/ghost.spec.js @@ -210,6 +210,74 @@ test.describe('Ghost tool (features/ghost.js)', () => { expect(idsUnique).toBe(true); }); + // STAMP-PICKUP (2026-10-13): Stamp from the menu hands the ghost back to the cursor, so + // nothing stays over the marks just stamped; the next drop places it again, Esc lets it go, + // and an undo of the stamp puts the ghost back on the sheet and drops the one in hand. + test('Stamp hands the ghost back to the cursor; Esc lets it go; undo puts it back', async ({ page }) => { + await seedPlan(page); + await page.evaluate(() => { + document.getElementById('ghostBtn').click(); + window.App.handleGhostCanvasClick({ x: 0, y: 0 }); + window.App.handleGhostCanvasClick({ x: 100, y: 100 }); + window.App.handleGhostCanvasClick({ x: 300, y: 100 }); + window.App.hideModal('airboardToastModal'); + }); + expect(await totals(page)).toMatchObject({ counters: 2, lines: 1, ghosts: 1 }); + + // Right-click the ghost's centre and Stamp: the marks are real, the ghost is in hand. + const stamp = () => page.evaluate(() => { + const st = window.state; + const b = window.App.ghostBounds(window.App.getActiveAnnotations(st.pages[0]).ghosts[0]); + const at = { x: (b.x1 + b.x2) / 2, y: (b.y1 + b.y2) / 2 }; + if (!window.App.tryOpenGhostMenuAt(at, 200, 200)) throw new Error('ghost menu did not open'); + document.querySelector('#ghostMenu [data-ghost-action="stamp"]').click(); + return { at, toast: document.getElementById('airboardToastText')?.textContent || '' }; + }); + const first = await stamp(); + expect(first.toast).toContain('in hand for the next spot'); + expect(await totals(page)).toMatchObject({ counters: 4, lines: 2, ghosts: 0 }); + expect(await page.evaluate(() => ({ + inHand: !!window.state.placingGhost, + fromStamp: window.state.placingGhostFromStamp, + tool: window.state.tool, + grab: window.state.placingGhostLast, + menuOpen: document.getElementById('ghostMenu').classList.contains('visible'), + }))).toEqual({ inHand: true, fromStamp: true, tool: 14, grab: first.at, menuOpen: false }); + + // The next click carries it by (click - grab) and drops it: on the sheet again, as one ghost. + await page.evaluate((at) => { window.App.handleGhostCanvasClick({ x: at.x, y: at.y + 200 }); }, first.at); + expect(await totals(page)).toMatchObject({ counters: 4, lines: 2, ghosts: 1 }); + expect(await page.evaluate(() => ({ inHand: !!window.state.placingGhost, fromStamp: window.state.placingGhostFromStamp }))).toEqual({ inHand: false, fromStamp: false }); + const moved = await page.evaluate(() => window.App.getActiveAnnotations(window.state.pages[0]).ghosts[0].src.counterMarkers.wc[0]); + expect(moved.x).toBe(260); // the first drop put it at (260, 60); the carry adds (0, +200) + expect(moved.y).toBe(260); + + // Stamp again, then Esc: nothing left on the sheet, the tool still armed, the marks kept. + await stamp(); + expect(await totals(page)).toMatchObject({ counters: 6, lines: 3, ghosts: 0 }); + await page.locator('body').press('Escape'); + expect(await page.evaluate(() => ({ inHand: !!window.state.placingGhost, tool: window.state.tool }))).toEqual({ inHand: false, tool: 14 }); + expect(await totals(page)).toMatchObject({ counters: 6, lines: 3, ghosts: 0 }); + + // Undo of a stamp: the marks come back off, the ghost is back on the sheet, and the copy + // in hand is dropped so it is not doubled. Redo re-stamps and leaves nothing in hand. + await page.evaluate(() => { window.App.handleGhostCanvasClick({ x: 0, y: 0 }); window.App.handleGhostCanvasClick({ x: 100, y: 100 }); window.App.handleGhostCanvasClick({ x: 300, y: 400 }); }); + await stamp(); + expect(await totals(page)).toMatchObject({ counters: 8, lines: 4, ghosts: 0 }); + await page.locator('body').press('Control+z'); + expect(await totals(page)).toMatchObject({ counters: 6, lines: 3, ghosts: 1 }); + expect(await page.evaluate(() => ({ inHand: !!window.state.placingGhost, fromStamp: window.state.placingGhostFromStamp }))).toEqual({ inHand: false, fromStamp: false }); + await page.locator('body').press('Control+Shift+z'); + expect(await totals(page)).toMatchObject({ counters: 8, lines: 4, ghosts: 0 }); + expect(await page.evaluate(() => !!window.state.placingGhost)).toBe(false); + + // A ghost in hand from a CAPTURE survives an unrelated undo: no step holds it. + await page.evaluate(() => { window.App.pushUndoSnapshot(); window.App.handleGhostCanvasClick({ x: 0, y: 0 }); window.App.handleGhostCanvasClick({ x: 100, y: 100 }); }); + expect(await page.evaluate(() => !!window.state.placingGhost)).toBe(true); + await page.locator('body').press('Control+z'); + expect(await page.evaluate(() => ({ inHand: !!window.state.placingGhost, fromStamp: window.state.placingGhostFromStamp }))).toEqual({ inHand: true, fromStamp: false }); + }); + test('dragging a ghost with the mouse never arms a capture corner', async ({ page }) => { await seedPlan(page); // Place a ghost via the gesture API, then interact with REAL pointer diff --git a/sw.js b/sw.js index 1f39e043..cc1d74cd 100644 --- a/sw.js +++ b/sw.js @@ -23,7 +23,7 @@ * visit once the CDN has settled. The app's admin "global force reload" clears caches * as a backstop. */ -const CACHE_VERSION = 'e253bf9e8c39'; +const CACHE_VERSION = '0792cc5f5aa1'; const CACHE_NAME = `counttooling-shell-${CACHE_VERSION}`; // The full same-origin app shell. GENERATED by `npm run build:sw`, do not edit by hand: @@ -273,7 +273,7 @@ const PRECACHE_SHA256 = { '/undo-stack.js': '34180b25071008b6f29c8b3c2529faa29e21c2957e9ee26b5510e5ef5750f69c', '/save-engine.js': 'd620a2ade982357362d0e7dd9c701df90a3cffe47e66f780dcd1d24b81fda918', '/pdf-tile-cache.js': 'd9d520d6399480191df2b97038ce0b453803666d79f1b804a995484e98fc5772', - '/app.js': '4bcfbfb8613cb827d5d0b94095bedac90fdcea5ab954f7c9d13a663a6a725442', + '/app.js': '12bc08bcda9d8d7ac75e35f38262fe181e7ba7f769947261977126058e48f072', '/features/canvas-repair.js': 'b2dca5c86174ed9589d0c44091d9265c2e3af039c08cf4422eb151fa5fd8ec02', '/features/view-only.js': 'f4e6c4f5601c089aa1001a9583c409e61d9090a639acd6a69994bccd6ca0dbcc', '/features/save-project.js': '6f01819d040f4a05ee9805ccabdc5170973429a39d5d0c3e54381a0d43866ad2', @@ -325,7 +325,7 @@ const PRECACHE_SHA256 = { '/features/bid-chip.js': '5ae93765826726786ff26e08706ed415d86c29f4383ab364bbbf878531272568', '/features/header-more.js': '5ac497cb75bf94b20da440f4dfb4996cd6a6bbde2d5c7ee3a9b00e43d976f5de', '/features/canvas-layers.js': '4221ddc56bcd2447eb6bd7ecdb681872753d3808c4b228c17188975758077575', - '/features/ghost.js': 'acb4822e886f15f3c93506de3354635c3b052aa25eb2dd0ed085d715d6c7b8c3', + '/features/ghost.js': '9fbc97eb09c84f52ccb7544436d03beb0551bfd0fa61899fc01613931cf59cfe', '/features/canvas-switcher.js': '89970ea9ae56c8bffa8f3fd0360ea4ba3e901bec1a772972117dcebe5acc9393', '/features/summary-list.js': '6b7a9f6eef9d3faa990e16577366c4f3a16b7484d20ff14fd449be3695237d85', '/features/my-settings.js': 'd3792711b4d9107dd53770c2ec09da1c1911882d0be95de63d86715170d67efa',