smoosic 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/build/smoosic.js +171 -78
  2. package/package.json +82 -77
  3. package/release/smoosic.js +171 -78
  4. package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
  5. package/release/styles/menus.css +26 -0
  6. package/specs/022-text-reposition-on-resize/spec.md +1 -0
  7. package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
  8. package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
  9. package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
  10. package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
  11. package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
  12. package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
  13. package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
  14. package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
  15. package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
  16. package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
  17. package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
  18. package/specs/028-unsaved-changes-indicator/plan.md +96 -0
  19. package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
  20. package/specs/028-unsaved-changes-indicator/research.md +68 -0
  21. package/specs/028-unsaved-changes-indicator/spec.md +135 -0
  22. package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
  23. package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
  24. package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
  25. package/specs/029-remove-promise-helpers/data-model.md +45 -0
  26. package/specs/029-remove-promise-helpers/plan.md +86 -0
  27. package/specs/029-remove-promise-helpers/quickstart.md +53 -0
  28. package/specs/029-remove-promise-helpers/research.md +71 -0
  29. package/specs/029-remove-promise-helpers/spec.md +107 -0
  30. package/specs/029-remove-promise-helpers/tasks.md +164 -0
  31. package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
  32. package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
  33. package/specs/030-copy-paste-voices/data-model.md +63 -0
  34. package/specs/030-copy-paste-voices/plan.md +80 -0
  35. package/specs/030-copy-paste-voices/quickstart.md +50 -0
  36. package/specs/030-copy-paste-voices/research.md +80 -0
  37. package/specs/030-copy-paste-voices/spec.md +124 -0
  38. package/specs/030-copy-paste-voices/tasks.md +183 -0
  39. package/specs/031-select-voice/checklists/requirements.md +39 -0
  40. package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
  41. package/specs/031-select-voice/data-model.md +47 -0
  42. package/specs/031-select-voice/plan.md +79 -0
  43. package/specs/031-select-voice/quickstart.md +43 -0
  44. package/specs/031-select-voice/research.md +55 -0
  45. package/specs/031-select-voice/spec.md +113 -0
  46. package/specs/031-select-voice/tasks.md +171 -0
  47. package/src/application/application.ts +464 -459
  48. package/src/common/promiseHelpers.ts +2 -2
  49. package/src/render/audio/samples.ts +117 -118
  50. package/src/render/sui/pageDivisions.ts +58 -0
  51. package/src/render/sui/renderState.ts +469 -464
  52. package/src/render/sui/scoreChangeState.ts +62 -0
  53. package/src/render/sui/scoreView.ts +30 -0
  54. package/src/render/sui/scoreViewOperations.ts +2555 -2380
  55. package/src/render/sui/svgPageMap.ts +16 -17
  56. package/src/render/sui/textEdit.ts +310 -311
  57. package/src/render/sui/tracker.ts +40 -0
  58. package/src/render/vex/vxNote.ts +3 -1
  59. package/src/smo/xform/copypaste.ts +304 -4
  60. package/src/smo/xform/selections.ts +68 -0
  61. package/src/smo/xform/undo.ts +9 -0
  62. package/src/styles/menus.css +26 -0
  63. package/src/ui/buttons/ribbon.ts +3 -1
  64. package/src/ui/components/buttons/sidebar.vue +15 -6
  65. package/src/ui/components/dialogs/library.vue +3 -1
  66. package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
  67. package/src/ui/dialogs/adapter.ts +181 -183
  68. package/src/ui/dialogs/addMeasure.ts +97 -97
  69. package/src/ui/dialogs/annotationVue.ts +56 -56
  70. package/src/ui/dialogs/audioSettings.ts +121 -123
  71. package/src/ui/dialogs/chordChangeVue.ts +46 -46
  72. package/src/ui/dialogs/clefChange.ts +53 -53
  73. package/src/ui/dialogs/customTuplets.ts +95 -96
  74. package/src/ui/dialogs/customTupletsVue.ts +47 -47
  75. package/src/ui/dialogs/dialog.ts +627 -620
  76. package/src/ui/dialogs/durations.ts +34 -34
  77. package/src/ui/dialogs/dynamics.ts +140 -142
  78. package/src/ui/dialogs/factory.ts +198 -198
  79. package/src/ui/dialogs/fileDialogs.ts +245 -179
  80. package/src/ui/dialogs/fonts.ts +93 -93
  81. package/src/ui/dialogs/globalLayout.ts +40 -40
  82. package/src/ui/dialogs/gracenote.ts +31 -31
  83. package/src/ui/dialogs/hairpin.ts +108 -110
  84. package/src/ui/dialogs/hairpinVue.ts +51 -51
  85. package/src/ui/dialogs/instrument.ts +111 -111
  86. package/src/ui/dialogs/keySignature.ts +175 -176
  87. package/src/ui/dialogs/keySignatureVue.ts +47 -47
  88. package/src/ui/dialogs/library.ts +207 -207
  89. package/src/ui/dialogs/libraryVue.ts +62 -48
  90. package/src/ui/dialogs/lyricVue.ts +46 -46
  91. package/src/ui/dialogs/measureFormat.ts +78 -78
  92. package/src/ui/dialogs/microtones.ts +147 -147
  93. package/src/ui/dialogs/noteHead.ts +319 -319
  94. package/src/ui/dialogs/pageLayout.ts +61 -61
  95. package/src/ui/dialogs/partInfo.ts +60 -60
  96. package/src/ui/dialogs/pedalMarking.ts +117 -117
  97. package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
  98. package/src/ui/dialogs/pitch.ts +352 -352
  99. package/src/ui/dialogs/preferences.ts +40 -40
  100. package/src/ui/dialogs/rehearsalMark.ts +64 -64
  101. package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
  102. package/src/ui/dialogs/scoreId.ts +35 -36
  103. package/src/ui/dialogs/scoreView.ts +42 -42
  104. package/src/ui/dialogs/slur.ts +308 -310
  105. package/src/ui/dialogs/slurVue.ts +91 -91
  106. package/src/ui/dialogs/staffGroup.ts +112 -112
  107. package/src/ui/dialogs/tabNote.ts +84 -84
  108. package/src/ui/dialogs/tabStave.ts +182 -182
  109. package/src/ui/dialogs/tempo.ts +261 -263
  110. package/src/ui/dialogs/tempoVue.ts +73 -73
  111. package/src/ui/dialogs/textBlockVue.ts +127 -127
  112. package/src/ui/dialogs/textBracket.ts +114 -116
  113. package/src/ui/dialogs/textBracketVue.ts +56 -56
  114. package/src/ui/dialogs/tie.ts +140 -142
  115. package/src/ui/dialogs/timeSignature.ts +65 -66
  116. package/src/ui/dialogs/transposeScore.ts +39 -39
  117. package/src/ui/dialogs/unsavedChanges.ts +43 -0
  118. package/src/ui/dialogs/volta.ts +120 -122
  119. package/src/ui/dialogs/voltaVue.ts +51 -51
  120. package/src/ui/fileio/library.ts +110 -111
  121. package/src/ui/menus/edit.ts +100 -1
  122. package/src/ui/menus/file.ts +19 -3
  123. package/tests/pageDivisions.ts +156 -0
  124. package/tests/promiseHelpersUsage.ts +142 -0
  125. package/tests/scoreChangeState.ts +102 -0
  126. package/tests/selectVoice.ts +189 -0
  127. package/tests/voiceCopyPaste.ts +417 -0
@@ -167,6 +167,7 @@ body.showAttributeDialog.textEditor .overlay {
167
167
  font-size: 0.9rem;
168
168
  }
169
169
  .side-brand {
170
+ position: relative;
170
171
  display: flex;
171
172
  align-items: center;
172
173
  gap: 8px;
@@ -175,6 +176,31 @@ body.showAttributeDialog.textEditor .overlay {
175
176
  letter-spacing: .12em;
176
177
  text-transform: uppercase;
177
178
  }
179
+ /* The open score's name after the app name; long names are truncated, the full name is in the tooltip.
180
+ The right padding keeps the name clear of the unsaved-changes asterisk. */
181
+ .side-brand .side-score {
182
+ flex: 1 1 auto;
183
+ min-width: 0;
184
+ padding-right: 14px;
185
+ overflow: hidden;
186
+ text-overflow: ellipsis;
187
+ white-space: nowrap;
188
+ text-transform: none;
189
+ letter-spacing: normal;
190
+ font-weight: 400;
191
+ }
192
+ /* Unsaved-changes asterisk: pinned to the right edge of the brand area so it is visible
193
+ even when the score name is truncated. */
194
+ .side-brand .side-changed {
195
+ position: absolute;
196
+ top: 4px;
197
+ bottom: 10px;
198
+ right: 6px;
199
+ display: flex;
200
+ align-items: center;
201
+ letter-spacing: normal;
202
+ font-weight: 700;
203
+ }
178
204
  .side-group {
179
205
  margin-top: var(--space-3);
180
206
  padding: 0 6px 4px;
@@ -38,6 +38,7 @@ A user changes the page width or height (for example, switching paper size or or
38
38
 
39
39
  1. **Given** a text block positioned at some percentage of the current page width/height, **When** the page width and/or height is changed, **Then** the text block's x/y position is recalculated so it sits at the same percentage of the new page width/height.
40
40
  2. **Given** a part has its own page layout separate from the main score, **When** the part's page width/height is changed, **Then** only the part's text groups are repositioned proportionally; the score's own text groups (and other parts) are unaffected.
41
+ 4. **Given** a part is exposed and the user changes its svg scale, page width, or page height in the Part Properties dialog (`SuiScoreViewOperations.updatePartInfo`), **When** the change is applied (or cancelled, which re-applies the backup), **Then** the part's text groups are repositioned with the same scale-ratio and page-dimension-ratio logic as the Global Layout dialog, applied once per text group even if the part's staves share group objects.
41
42
  3. **Given** the score's page width/height is changed while a part is not exposed, **When** the change is applied, **Then** the score's own text groups are repositioned proportionally.
42
43
 
43
44
  ---
@@ -0,0 +1,38 @@
1
+ # Specification Quality Checklist: Fix Bottom-of-Page Modifier Lookup
2
+
3
+ **Purpose**: Validate specification completeness and quality before proceeding to planning
4
+
5
+ **Created**: 2026-10-12
6
+
7
+ **Feature**: [spec.md](../spec.md)
8
+
9
+ ## Content Quality
10
+
11
+ - [x] No implementation details (languages, frameworks, APIs)
12
+ - [x] Focused on user value and business needs
13
+ - [x] Written for non-technical stakeholders
14
+ - [x] All mandatory sections completed
15
+
16
+ ## Requirement Completeness
17
+
18
+ - [x] No [NEEDS CLARIFICATION] markers remain
19
+ - [x] Requirements are testable and unambiguous
20
+ - [x] Success criteria are measurable
21
+ - [x] Success criteria are technology-agnostic (no implementation details)
22
+ - [x] All acceptance scenarios are defined
23
+ - [x] Edge cases are identified
24
+ - [x] Scope is clearly bounded
25
+ - [x] Dependencies and assumptions identified
26
+
27
+ ## Feature Readiness
28
+
29
+ - [x] All functional requirements have clear acceptance criteria
30
+ - [x] User scenarios cover primary flows
31
+ - [x] Feature meets measurable outcomes defined in Success Criteria
32
+ - [x] No implementation details leak into specification
33
+
34
+ ## Notes
35
+
36
+ - The Input line quotes the original request verbatim, so it names the page class and its methods. The rest of the spec uses only behavioral terms.
37
+ - The Assumptions section describes the current rounding behavior, which affects scope, without prescribing code.
38
+ - Ready for `/speckit-clarify` or `/speckit-plan`.
@@ -0,0 +1,51 @@
1
+ # Contract: Page Division Lookup
2
+
3
+ Implemented in `src/render/sui/pageDivisions.ts`, used by `SvgPage` in `src/render/sui/svgPageMap.ts`, and verified by `tests/pageDivisions.ts` (`npm run test:page-divisions`). Spec references: [spec.md](../spec.md).
4
+
5
+ ## Functions
6
+
7
+ ```ts
8
+ export interface PageDivision { start: number; end: number; }
9
+
10
+ /** Split [pageStart, pageStart + pageExtent] into `count` contiguous divisions. */
11
+ export function computeDivisions(pageStart: number, pageExtent: number, count: number): PageDivision[];
12
+
13
+ /** Index of the division containing `position`, or -1 if it is outside the page. */
14
+ export function findDivision(position: number, divisions: PageDivision[]): number;
15
+ ```
16
+
17
+ ## Test cases
18
+
19
+ Unless noted, the page is `pageStart = 0`, `pageExtent = 1000`, `count = 8` (division size 125).
20
+
21
+ | ID | Case | Expected | Spec |
22
+ |----|------|----------|------|
23
+ | D1 | `computeDivisions` returns 8 entries | length 8 | FR-001 |
24
+ | D2 | First start and last end | `divisions[0].start === 0`, `divisions[7].end === 1000` exactly | FR-001 |
25
+ | D3 | Contiguity | `divisions[i].end === divisions[i+1].start` for i in 0..6 | FR-001 |
26
+ | D4 | Midpoint of each division, `62.5 + 125*i` | index `i` for all 8 | FR-002, FR-003 |
27
+ | D5 | Lower half of the last division, e.g. 950 | 7 (the former failure: old formula gave 8) | FR-004 |
28
+ | D6 | Page top edge, 0 | 0 | FR-001 |
29
+ | D7 | Page bottom edge, 1000 | 7 (last division is closed on the right) | FR-004 |
30
+ | D8 | Interior boundary, 125 | 1, the later division, and the same result on every call | FR-005 |
31
+ | D9 | Just below / above a boundary, 124.999 and 125.001 | 0 and 1 | FR-005 |
32
+ | D10 | Before the page, -0.001 | -1 | FR-006 |
33
+ | D11 | After the page, 1000.001 | -1 | FR-006 |
34
+ | D12 | Non-finite input (`NaN`, `Infinity`) | -1, no throw | FR-006 |
35
+ | D13 | Non-zero page start (page 3 of a vertical score, `pageStart = 2000`): 2000, 2999, 3000 | 0, 7, 7 (3000 is this page's bottom edge; see note) | FR-008 |
36
+ | D14 | Different page sizes (extent 1056, 1123, 800) | every position sampled at 1/64 steps maps to exactly one index, indices never decrease, and index 7 is reached | FR-008 |
37
+ | D15 | Exhaustive sweep: 0 to 1000 in steps of 0.5 | no -1, no index above 7, non-decreasing, each of 0 to 7 hit | SC-001 |
38
+ | D16 | Registration/lookup agreement: for every sampled position, `findDivision(p)` called twice and for a tab filed at `p` and a lookup at `p` gives the same index | equal | FR-003, FR-007, SC-002 |
39
+ | D17 | Old-behavior regression: positions in the upper and middle page that previously resolved still return a division, and a tab whose box contains the lookup box is found | found | FR-009, SC-004 |
40
+
41
+ **Note on D13**: The bottom edge of page N and the top edge of page N+1 are the same coordinate. Page selection is handled before division lookup by `SvgPageMap.getRendererFromPoint` (`floor(pos / pageDim)`), which assigns that coordinate to page N+1. `findDivision` is only asked about positions already routed to this page, so inclusive handling of the bottom edge is correct and harmless. The test asserts `findDivision(3000, pageTable) === 7` for the page table that starts at 2000, and documents this note beside the assertion.
42
+
43
+ ## Integration behavior (verified manually; see [quickstart.md](../quickstart.md))
44
+
45
+ | ID | Behavior | Spec |
46
+ |----|----------|------|
47
+ | I1 | A footer text group in the bottom region of a page can be clicked and selected | US1 |
48
+ | I2 | Text at the top, middle and bottom of a page can all be selected | US1.2 |
49
+ | I3 | Horizontal display mode: modifiers near the right end of a page can be selected | FR-008 |
50
+ | I4 | A multi-page score: bottom-of-page text on page 2 can be selected | US1.4 |
51
+ | I5 | Dragging text partly off the bottom of the page does not throw | FR-006 |
@@ -0,0 +1,43 @@
1
+ # Data Model: Fix Bottom-of-Page Modifier Lookup
2
+
3
+ All structures are in-memory render state. Nothing here is serialized, and no existing serialized shape changes (constitution Principle #1).
4
+
5
+ ## PageDivision
6
+
7
+ One vertical (or, in horizontal layout, horizontal) band of a page.
8
+
9
+ | Field | Type | Meaning |
10
+ |-------|------|---------|
11
+ | `start` | number | Absolute score-coordinate position of the band's leading edge (inclusive) |
12
+ | `end` | number | Absolute position of the trailing edge (exclusive, except for the last band, where it is inclusive) |
13
+
14
+ **Invariants**
15
+
16
+ - A page has exactly `SvgPage.modifierDivs` (8) divisions, in increasing order.
17
+ - `divisions[0].start === pageStart` and `divisions[n-1].end === pageStart + pageExtent`, exactly (no accumulated float drift).
18
+ - `divisions[i].end === divisions[i+1].start` for every interior pair (contiguous, no overlap, no gap).
19
+ - Every position in `[pageStart, pageStart + pageExtent]` belongs to exactly one division.
20
+
21
+ ## Division lookup
22
+
23
+ `findDivision(position, divisions) -> number`
24
+
25
+ - Returns the index `i` such that `divisions[i].start <= position < divisions[i].end`.
26
+ - For the last division the upper bound is inclusive: `position === divisions[n-1].end` returns `n-1`.
27
+ - Returns `-1` when `position < divisions[0].start` or `position > divisions[n-1].end`, or when `position` is not a finite number.
28
+ - A position on an interior boundary returns the later division.
29
+
30
+ ## SvgPage (changed fields)
31
+
32
+ | Member | Before | After |
33
+ |--------|--------|-------|
34
+ | `modifierYKeys: number[]` | Page-relative division ends, used only for `.length` | Removed |
35
+ | `divisions: PageDivision[]` | n/a | Built once in the constructor from `box`, the layout's flow dimension, and `modifierDivs` |
36
+ | `divIndex(dim)` | `Math.round((dim - pageTop) / divSize)` | `findDivision(dim, divisions)`; returns -1 when outside the page |
37
+ | `modifierTabDivs: Record<number, ModifierTab[]>` | Keyed by the rounded index | Unchanged in shape; keyed by the new division index (0 to 7) |
38
+
39
+ **State transitions**: `clearMap()` and `clearModifiers()` reset `modifierTabDivs` as before. The `divisions` table does not change for the life of the page.
40
+
41
+ ## ModifierTab
42
+
43
+ Unchanged. A tab is filed under `divIndex` of the flow-dimension position of its `box` (its top edge in vertical layout), and returned by `findModifierTabs` when its box contains the lookup box.
@@ -0,0 +1,77 @@
1
+ # Implementation Plan: Fix Bottom-of-Page Modifier Lookup
2
+
3
+ **Branch**: `027-fix-bottom-modifier-lookup` | **Date**: 2026-10-12 | **Spec**: [spec.md](./spec.md)
4
+
5
+ **Input**: Feature specification from `/specs/027-fix-bottom-modifier-lookup/spec.md`
6
+
7
+ ## Summary
8
+
9
+ `SvgPage` files each modifier tab (text groups, annotations, etc.) under one of 8 vertical divisions of the page, and `findModifierTabs` searches only the division containing the click. Both use `SvgPage.divIndex`, which computes `Math.round((pos - pageTop) / divSize)`. Rounding to the nearest index shifts every division boundary by half a division and produces index 8 for the lower half of the last division; the `div < modifierYKeys.length` guard then silently drops the item, so footers and other bottom-of-page text cannot be selected. The fix replaces the arithmetic with a boundary-based lookup: the page precomputes the absolute start/end of each division once, and `divIndex` returns the division whose range contains the position (or -1 when outside the page). The matching logic lives in a small dependency-free module so it can be regression-tested headlessly. `addModifierTab`, `findModifierTabs` and `clearMeasure` all go through the same function, so filing, lookup and clearing always agree.
10
+
11
+ ## Technical Context
12
+
13
+ **Language/Version**: TypeScript (compiled by the project's `build/build.js`).
14
+
15
+ **Primary Dependencies**: None new. `SvgPage` (`src/render/sui/svgPageMap.ts`) already depends on the `layoutProvider` interface for horizontal vs. vertical flow (`getFlowDimensionPosition` / `getFlowDimensionExtent`); the new helper takes plain numbers and has no imports.
16
+
17
+ **Storage**: N/A. The division table is ephemeral render state, never serialized.
18
+
19
+ **Testing**: Headless `ts-node` script `tests/pageDivisions.ts` (`npm run test:page-divisions`), following `tests/textDragPlacement.ts`: a local `check()` helper, no DOM, no VexFlow. Contract cases are listed in [contracts/division-lookup-contract.md](./contracts/division-lookup-contract.md). No rendering test is added (constitution: rendering regression is lower priority).
20
+
21
+ **Target Platform**: Browser SVG application; tests run under Node.
22
+
23
+ **Project Type**: Single project (library + application), existing `src/` and `tests/` layout.
24
+
25
+ **Performance Goals**: No regression. Division bounds are computed once per page in the constructor; each lookup is a scan of 8 numeric ranges, run once per modifier per render and once per mouse hit-test.
26
+
27
+ **Constraints**: The number of divisions stays 8 (`SvgPage.modifierDivs`). Behavior for the upper and middle page is unchanged (FR-009). Must work for horizontal layouts, where the flow dimension is x and the page extent is its width. No change to serialized data.
28
+
29
+ **Scale/Scope**: One module added, one class (`SvgPage`) modified, one unused export removed.
30
+
31
+ ## Constitution Check
32
+
33
+ *GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
34
+
35
+ - **Principle #1 (Serialization)**: PASS. No persisted field or serialized shape changes; the division table is runtime-only render state.
36
+ - **Principle #2 (Non-UI transformation logic testing)**: PASS. The region math is pure and ships with a headless regression script and a contract case list, matching the pattern of specs 019, 022 and 023, even though the code lives in the render layer rather than `src/smo`.
37
+ - **Principle #3 (Rendering performance)**: PASS. Bounds are precomputed once per page; per-call cost is a scan of 8 numbers. No DOM measurement is added and the render pipeline (`scoreRender.ts`, `renderState.ts`, Vex) is untouched.
38
+ - **Principle #4 (Logical dependencies)**: PASS. The helper is a pure numeric module with no UI, DOM or `smo` imports; `SvgPage` remains the only caller. `src/smo` is not touched.
39
+
40
+ No violations; Complexity Tracking is not needed. Re-check after Phase 1 design: unchanged, still PASS.
41
+
42
+ ## Project Structure
43
+
44
+ ### Documentation (this feature)
45
+
46
+ ```text
47
+ specs/027-fix-bottom-modifier-lookup/
48
+ ├── plan.md
49
+ ├── research.md
50
+ ├── data-model.md
51
+ ├── quickstart.md
52
+ ├── contracts/
53
+ │ └── division-lookup-contract.md
54
+ ├── checklists/
55
+ │ └── requirements.md
56
+ └── tasks.md # created later by /speckit-tasks
57
+ ```
58
+
59
+ ### Source Code (repository root)
60
+
61
+ ```text
62
+ src/render/sui/
63
+ ├── pageDivisions.ts # NEW: pure functions: computeDivisions(start, extent, count), findDivision(pos, divisions)
64
+ └── svgPageMap.ts # SvgPage: build divisions in constructor, divIndex uses findDivision, guards use div >= 0,
65
+ # clearMeasure tolerates an empty division; remove the unused getDiv export
66
+
67
+ tests/
68
+ └── pageDivisions.ts # NEW: headless regression script
69
+
70
+ package.json # add "test:page-divisions" script
71
+ ```
72
+
73
+ **Structure Decision**: Keep the fix inside the existing render layer. A separate import-free module is used instead of putting the logic in `svgPageMap.ts` so that the test does not have to load VexFlow and DOM-dependent code (`svgPageMap.ts` imports the Vex renderer and declares jQuery).
74
+
75
+ ## Complexity Tracking
76
+
77
+ *No Constitution Check violations; table not needed.*
@@ -0,0 +1,36 @@
1
+ # Quickstart: Validating the Bottom-of-Page Lookup Fix
2
+
3
+ Contract cases are in [contracts/division-lookup-contract.md](./contracts/division-lookup-contract.md); the structures are in [data-model.md](./data-model.md).
4
+
5
+ ## 1. Headless regression test
6
+
7
+ From the repository root:
8
+
9
+ ```bash
10
+ npm run test:page-divisions
11
+ ```
12
+
13
+ Expected: every case prints `PASS`, the run ends with `all checks passed`, and the exit code is 0. Before the fix is applied, cases D5 and D15 are expected to fail against the old arithmetic (which is how to confirm the test detects the bug).
14
+
15
+ ## 2. Type check
16
+
17
+ ```bash
18
+ npx tsc --noEmit -p tsconfig.json
19
+ ```
20
+
21
+ Expected: no errors (in particular, no remaining references to the removed `modifierYKeys` or `getDiv`).
22
+
23
+ ## 3. Manual check in the app
24
+
25
+ Prerequisite: build and run the app as usual (`npm run build`, then open the app).
26
+
27
+ 1. Open a new score. Add a text annotation or footer and position it near the bottom of the first page (drag it, or use the text dialog's position controls).
28
+ 2. Click on the text. Expected: it is selected (outline shown). Before the fix, text whose top edge lies in the lower half of the last eighth of the page could not be selected.
29
+ 3. Move the text up through the page in steps (bottom, lower third, middle, upper third, top) and click it at each position. Expected: selected every time.
30
+ 4. Add a second page (long score) and repeat step 2 at the bottom of page 2.
31
+ 5. Switch to horizontal display mode (Global Layout dialog) and place text near the right end of a page. Expected: selectable.
32
+ 6. Drag text partly below the bottom edge of the page. Expected: no error in the browser console.
33
+
34
+ ## 4. Regression spot check
35
+
36
+ Click existing modifiers in the upper and middle part of a score (slurs, dynamics, titles). Expected: selection behaves exactly as before.
@@ -0,0 +1,58 @@
1
+ # Research: Fix Bottom-of-Page Modifier Lookup
2
+
3
+ No NEEDS CLARIFICATION items remained after the spec. The items below record what was verified in the code and the design decisions that follow from it.
4
+
5
+ ## 1. What the current code actually does
6
+
7
+ **Finding**: `SvgPage.divIndex(dim)` in `src/render/sui/svgPageMap.ts` is `Math.round((dim - pageTop) / divSize)` with `divSize = pageExtent / 8`. It rounds to nearest, not down. Consequences for a page of extent H:
8
+
9
+ - Division 0 effectively covers `[0, H/16)`; division k covers `[(k-0.5)H/8, (k+0.5)H/8)`, i.e. all boundaries are shifted half a division.
10
+ - Positions in `[(7.5)H/8, H]` give index 8, which fails `div < modifierYKeys.length` (length 8) and is dropped in `addModifierTab` and `findModifierTabs`. Only the lower half of the last division is lost, not the whole last division.
11
+ - Because filing and lookup use the same shifted function, items in the surviving divisions are still found (the bug does not break the upper and middle page), which is why it went unnoticed.
12
+
13
+ **Decision**: Treat the user's "rounding down" description as the same defect; the spec's Assumptions note the actual rounding.
14
+
15
+ ## 2. `modifierYKeys` holds relative ends and is only used for its length
16
+
17
+ **Finding**: The constructor pushes `divSize, 2*divSize, ...` (page-relative, not absolute) into `modifierYKeys`; nothing compares a position against these values, only `.length` is read.
18
+
19
+ **Decision**: Replace it with a table of absolute `{ start, end }` ranges built from the page's `box` and the layout's flow dimension. Remove `modifierYKeys`.
20
+
21
+ **Alternatives considered**: Keep `modifierYKeys` and fix `divIndex` with `Math.floor` plus clamping. Rejected: it still compares against nothing real, would leave the intent ("start/end of each division") unrepresented, and clamping would hide out-of-page positions rather than rejecting them (FR-006).
22
+
23
+ ## 3. Division bounds are stable per page
24
+
25
+ **Finding**: `SvgPage.box` is assigned only in the constructor, created in `SvgPageMap.addPage` as `(topX, topY, pageWidth, pageHeight)` in absolute score coordinates. `divSize` is already derived from it at construction time.
26
+
27
+ **Decision**: Compute the division table once in the constructor. If a future change makes the box mutable, the table must be rebuilt at the same point.
28
+
29
+ ## 4. Boundary and edge semantics
30
+
31
+ **Decision**:
32
+
33
+ - Division `i` is the half-open range `[start_i, end_i)`, with `end_i` equal to `start_{i+1}` computed by the same expression, so there are no gaps or overlaps from floating-point drift.
34
+ - The last division is closed on the right, so a position exactly at the page's bottom edge belongs to it (FR-004).
35
+ - A position exactly on an interior boundary belongs to the later division (FR-005). Registration, lookup and clearing all use the same function so they always agree.
36
+ - A position before the first start or after the last end returns -1; callers skip it (FR-006). This replaces the old implicit guard.
37
+
38
+ **Alternatives considered**: Clamping out-of-page positions to the first/last division. Rejected: text dragged far off the page would become hit-testable on an unrelated division, and the spec asks for such items to be left unfiled.
39
+
40
+ ## 5. Where to put the logic
41
+
42
+ **Finding**: `svgPageMap.ts` imports the Vex renderer (`../../common/vex`) and uses a global jQuery `$`, so a headless test importing it would need DOM and font setup. Existing headless tests import only `src/smo` modules.
43
+
44
+ **Decision**: New module `src/render/sui/pageDivisions.ts` with two pure functions and no imports. `SvgPage` calls them; the test imports only this module.
45
+
46
+ **Alternatives considered**: (a) Put the functions in `src/smo/data/common.ts`: rejected, it is render-layer geometry and Principle #4 keeps `smo` free of rendering concerns. (b) Test `SvgPage` directly with stubs: rejected as heavier than the problem.
47
+
48
+ ## 6. Related code that shares the defect
49
+
50
+ - **`SvgPage.clearMeasure`** calls `divIndex` and then dereferences `this.modifierTabDivs[div]` without checking it exists, so it throws for an empty division. A search of `src/` finds no callers of `SvgPage.clearMeasure` (only `MappedSystems.clearMeasure` exists alongside it), so the defect is latent. **Decision**: switch it to the shared lookup and tolerate a missing or empty division, so FR-007 holds if it is called.
51
+ - **`getDiv`** (exported from `svgPageMap.ts`) also rounds, takes a different and odd argument form, and has no references in `src/`. **Decision**: remove it rather than leave a second, wrong implementation. Its removal is called out in tasks and the final report.
52
+ - **`SvgPageMap.getRendererFromPoint`** chooses the page with `Math.floor(pointDim / pageDim)`. That is a correct page split (a position on a page boundary belongs to the next page) and is out of scope.
53
+
54
+ ## 7. Out of scope
55
+
56
+ - Filing a tall modifier under every division it overlaps (spec Assumptions).
57
+ - Changing the number of divisions.
58
+ - Any change to `MappedSystems` (measure/system lookup) or to page selection.
@@ -0,0 +1,105 @@
1
+ # Feature Specification: Fix Bottom-of-Page Modifier Lookup
2
+
3
+ **Feature Branch**: `027-fix-bottom-modifier-lookup`
4
+
5
+ **Created**: 2026-10-12
6
+
7
+ **Status**: Draft
8
+
9
+ **Input**: User description: "Fix a long-existing fencepost bug with text/modifiers near the bottom of the page. SvgPage addModifierTab finds the vertical division (modifier tab row) based on the y-coordinate by dividing the y coordinate by the number of divisions and rounding down, but this cuts the last division out. It should instead determine the division from the start/end y of each division. The same issue exists in SvgPage findModifierTabs: the y division should be determined by where the y falls within the start/end of each division, not by dividing and rounding down."
10
+
11
+ ## User Scenarios & Testing *(mandatory)*
12
+
13
+ ### User Story 1 - Select text and modifiers near the bottom of the page (Priority: P1)
14
+
15
+ A user clicks on a text block, annotation, footer, or other score modifier that sits in the lower part of a page. The click should select it, exactly as it does for items higher on the page. Today, items near the bottom edge of the page can be impossible to click or select, because the page's lookup of "what is at this vertical position" has no entry for the bottom-most region.
16
+
17
+ **Why this priority**: This is the visible, long-standing defect. Footers, copyright lines, and bottom-of-page annotations are common, and a user who cannot select them cannot edit, move, or delete them.
18
+
19
+ **Independent Test**: Place a footer text block (or any modifier) in the bottom region of a page, click on it, and confirm it is selected. Repeat with items at several heights down the page, including the very lowest position the item can occupy.
20
+
21
+ **Acceptance Scenarios**:
22
+
23
+ 1. **Given** a modifier or text block whose top edge lies within the last vertical region of a page, **When** the user clicks on it, **Then** it is found and selected.
24
+ 2. **Given** modifiers placed at the top, middle, and bottom of a page, **When** the user clicks each one, **Then** every one is found, with no region of the page that cannot be hit.
25
+ 3. **Given** a modifier near the boundary between two vertical regions, **When** the user clicks on it, **Then** it is found regardless of which side of the boundary its top edge falls on.
26
+ 4. **Given** a multi-page score, **When** the user clicks a modifier near the bottom of any page, **Then** it is found on that page, and the lookup on other pages is unaffected.
27
+
28
+ ---
29
+
30
+ ### User Story 2 - Registering and looking up use the same vertical regions (Priority: P1)
31
+
32
+ When the score is drawn, each modifier is filed under the vertical region of the page it occupies. When the user clicks, the click location is looked up using the same regions. The two steps must always agree: an item filed at a given height must be found by a click at that same height, for every height on the page.
33
+
34
+ **Why this priority**: The bug exists because filing and lookup are not consistent with the actual region boundaries. Correct behavior depends on both steps using the same, boundary-based definition of a region. The bottom-of-page failure in Story 1 is not fully fixed unless both agree.
35
+
36
+ **Independent Test**: For a page, register items at a range of heights spanning the entire page height (including exactly at region boundaries and the page's top and bottom edges), then look each one up by a click at that height; every item must be returned.
37
+
38
+ **Acceptance Scenarios**:
39
+
40
+ 1. **Given** an item registered at any height within the page, **When** a lookup is performed at that same height, **Then** the item is returned.
41
+ 2. **Given** a height that lies exactly on the boundary between two regions, **When** an item is registered or looked up there, **Then** it is assigned to exactly one region, the same one for both operations.
42
+ 3. **Given** a height at the very top or very bottom edge of the page, **When** an item is registered or looked up there, **Then** it falls in the first or last region respectively, not outside the page.
43
+
44
+ ---
45
+
46
+ ### User Story 3 - Redraw and measure clearing stay consistent (Priority: P2)
47
+
48
+ When a measure is redrawn, the page removes the modifiers it had filed for that measure. This must locate the same region that the modifiers were originally filed under, including in the lower part of the page. Otherwise stale entries linger (or fresh ones are lost) for measures near the bottom.
49
+
50
+ **Why this priority**: It uses the same region lookup. It is a secondary symptom of the same defect, and is lower priority only because the user-visible effect is subtler than being unable to click an item.
51
+
52
+ **Independent Test**: Edit a measure in the lowest system on a page that has modifiers attached, and confirm the old entries are replaced rather than duplicated, and that clicking the modifier still works after the edit.
53
+
54
+ **Acceptance Scenarios**:
55
+
56
+ 1. **Given** a measure in the lower part of the page with attached modifiers, **When** that measure is redrawn, **Then** the previous entries for that measure are removed from the region they were filed under, and the redrawn entries are found by clicks.
57
+
58
+ ---
59
+
60
+ ### Edge Cases
61
+
62
+ - What happens when an item's top edge is exactly at the page's bottom edge? It belongs to the last region.
63
+ - What happens when an item's top edge is above the page's top or below its bottom (for example, text dragged partially off the page)? It is not assigned to a region on that page, and the lookup must not fail or error.
64
+ - What happens when a click lies exactly on the boundary between two regions? The item and the click resolve to the same single region.
65
+ - What happens when a page is shorter or taller than the standard sizes (custom page height, landscape orientation, a part with its own page size)? Region boundaries are derived from that page's own height, and every part of the page is covered.
66
+ - What happens on pages after the first, whose positions are measured from the top of the whole score? Region assignment is relative to that page, so the last region of every page is reachable.
67
+ - What happens to items near the top of the page? They keep working as before.
68
+
69
+ ## Requirements *(mandatory)*
70
+
71
+ ### Functional Requirements
72
+
73
+ - **FR-001**: The page MUST divide its full height into a fixed number of contiguous vertical regions, each with a defined start and end, such that every vertical position from the top edge to the bottom edge of the page falls in exactly one region.
74
+ - **FR-002**: When a modifier is registered with the page, the system MUST choose its region by finding the region whose start/end range contains the modifier's top position, rather than by a rounding calculation on the position.
75
+ - **FR-003**: When looking up modifiers at a click position, the system MUST choose the region by finding the region whose start/end range contains the click's position, using exactly the same definition of regions as FR-002.
76
+ - **FR-004**: The last region of the page MUST be usable: a modifier or click in the bottom-most part of the page (up to and including the bottom edge) MUST resolve to the last region.
77
+ - **FR-005**: A position lying exactly on the boundary between two regions MUST resolve to exactly one of them, consistently for registration, lookup and clearing.
78
+ - **FR-006**: Positions outside the page's vertical range MUST NOT be assigned to any region and MUST NOT cause errors during registration or lookup.
79
+ - **FR-007**: Clearing the modifiers belonging to a measure MUST use the same region selection as registration, so the entries removed are those that were filed for that measure.
80
+ - **FR-008**: Regions MUST be determined per page, from that page's own position and height, so the behavior is correct for every page of a multi-page score, for custom page sizes, and for parts with their own page layout.
81
+ - **FR-009**: Existing behavior for modifiers in the upper and middle parts of the page MUST be unchanged: anything that could be clicked before can still be clicked, and nothing is returned that does not contain the click.
82
+
83
+ ### Key Entities
84
+
85
+ - **Page**: One rendered page of the score or part, with a position within the whole score, a height, and a set of vertical regions.
86
+ - **Vertical region**: One of a fixed number of contiguous bands covering the page's full height, each with a start and end position. Modifiers are filed under the region containing their top edge, and lookups search only the region containing the click.
87
+ - **Modifier tab**: A clickable record for a modifier or text group on the page, holding its bounding box. It is filed under a vertical region and returned by lookups whose click falls inside its box.
88
+
89
+ ## Success Criteria *(mandatory)*
90
+
91
+ ### Measurable Outcomes
92
+
93
+ - **SC-001**: 100% of modifiers and text blocks on a page can be found by a click on them, including those in the lowest region of the page; none of the page height is unreachable.
94
+ - **SC-002**: For heights sampled across the full page (top edge, every region boundary, every region midpoint, and bottom edge), an item registered at a height is found by a lookup at that height in 100% of cases.
95
+ - **SC-003**: A footer or other bottom-of-page text block that previously could not be selected can be selected on the first click.
96
+ - **SC-004**: Regression check: modifiers in the upper and middle parts of the page behave identically before and after the change (no modifier that was found before is lost, and no extra modifiers are returned).
97
+
98
+ ## Assumptions
99
+
100
+ - The number of vertical regions per page stays as it is today; this feature changes how a position is matched to a region, not how many regions exist.
101
+ - A modifier is filed under the region containing its top edge, as today. Making a tall modifier findable from every region it overlaps is out of scope.
102
+ - The current calculation rounds to the nearest region index, which both shifts every region boundary by half a region and drops the lower half of the last region. The fix replaces it with boundary-based matching for registration, lookup and measure clearing alike.
103
+ - Page-relative positions come from the existing layout information for the page. The coordinate system and page sizing are unchanged.
104
+ - Positions outside the page are rare (an item dragged partly off the page) and are handled by being left unfiled, not by being forced into the nearest region.
105
+ - The headless regression test pattern used by earlier features applies: the region matching logic is testable without rendering.
@@ -0,0 +1,167 @@
1
+ ---
2
+
3
+ description: "Task list for Fix Bottom-of-Page Modifier Lookup"
4
+ ---
5
+
6
+ # Tasks: Fix Bottom-of-Page Modifier Lookup
7
+
8
+ **Input**: Design documents from `/specs/027-fix-bottom-modifier-lookup/`
9
+
10
+ **Prerequisites**: [plan.md](./plan.md), [spec.md](./spec.md), [research.md](./research.md), [data-model.md](./data-model.md), [contracts/division-lookup-contract.md](./contracts/division-lookup-contract.md), [quickstart.md](./quickstart.md)
11
+
12
+ **Tests**: Included. The plan commits to a headless `tests/pageDivisions.ts` regression script (same pattern as `tests/textDragPlacement.ts`); the contract case IDs (D1 to D17) are the test cases.
13
+
14
+ **Organization**: Tasks are grouped by user story. All three stories share one small pure module (Phase 2), so that module is the blocking foundation; each story then wires or verifies one part of `SvgPage`.
15
+
16
+ ## Format: `[ID] [P?] [Story] Description`
17
+
18
+ - **[P]**: Can run in parallel (different files, no dependencies)
19
+ - **[Story]**: Which user story this task belongs to (US1, US2, US3)
20
+
21
+ ## Path Conventions
22
+
23
+ Single project (per plan.md): `src/render/sui/`, `tests/`, repo root `package.json`.
24
+
25
+ ---
26
+
27
+ ## Phase 1: Setup
28
+
29
+ **Purpose**: Register the test so later phases only add cases.
30
+
31
+ - [X] T001 Add the script `"test:page-divisions": "ts-node -P tests/tsconfig.json tests/pageDivisions.ts"` to `package.json`, next to the existing `test:text-drag-placement` entry.
32
+ - [X] T002 Create `tests/pageDivisions.ts` with the scaffold only: a header comment pointing at `specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md`, the `failures` counter and `check(name, condition, detail?)` helper copied from `tests/textDragPlacement.ts`, and a final summary block that prints `all checks passed` or sets `process.exitCode = 1`. Do not import any module under test yet. Do not import anything from `src/` other than `src/render/sui/pageDivisions.ts` (added in T003); the test must stay free of DOM and VexFlow imports.
33
+
34
+ ---
35
+
36
+ ## Phase 2: Foundational (Blocking Prerequisites)
37
+
38
+ **Purpose**: The pure, import-free division logic that US1, US2 and US3 all call.
39
+
40
+ **CRITICAL**: No user story work can begin until this phase is complete.
41
+
42
+ - [X] T003 Create `src/render/sui/pageDivisions.ts` with no imports. Export `interface PageDivision { start: number; end: number; }`; `computeDivisions(pageStart, pageExtent, count)`, which returns `count` contiguous divisions where `start_i = pageStart + (pageExtent * i) / count`, `end_i = start_{i+1}` (the same expression, so no gaps or drift), and the last `end` is exactly `pageStart + pageExtent`; and `findDivision(position, divisions)`, which returns the index `i` with `start_i <= position < end_i`, treats the last division as closed on the right, and returns `-1` for positions before the first start, after the last end, or non-finite. Per [data-model.md](./data-model.md) and research.md section 4.
43
+ - [X] T004 In `tests/pageDivisions.ts`, add cases D1 to D12 from the contract (division count, exact first start and last end, contiguity, midpoints, lower half of the last division, top and bottom edges, interior boundary and its neighbours, out-of-page and non-finite inputs). Add a local `legacyIndex = (pos, start, extent) => Math.round((pos - start) / (extent / 8))` and a check that `legacyIndex(950, 0, 1000) === 8` (documents the old failure that `findDivision(950) === 7` now fixes).
44
+ - [X] T005 In `tests/pageDivisions.ts`, add cases D13 to D15 (non-zero page start and the bottom-edge note, other page sizes 1056/1123/800, and the exhaustive 0.5-step sweep over a page asserting no `-1`, no index above 7, non-decreasing indices, and that every index 0 to 7 is hit).
45
+ - [X] T006 Run `npm run test:page-divisions` and fix `pageDivisions.ts` until every case passes.
46
+
47
+ **Checkpoint**: The division math is correct and covered; nothing in the app uses it yet.
48
+
49
+ ---
50
+
51
+ ## Phase 3: User Story 1 - Select text and modifiers near the bottom of the page (Priority: P1) MVP
52
+
53
+ **Goal**: Modifiers whose top edge is in the bottom region of a page are filed under, and found from, the last division.
54
+
55
+ **Independent Test**: Place a footer in the lowest part of a page and click it; it is selected. Repeat at several heights and on page 2 (quickstart.md section 3, steps 1 to 4).
56
+
57
+ ### Implementation for User Story 1
58
+
59
+ - [X] T007 [US1] In `src/render/sui/svgPageMap.ts`, import `PageDivision`, `computeDivisions` and `findDivision` from `./pageDivisions`. Add a `divisions: PageDivision[]` field to `SvgPage` and build it once at the end of the constructor with `computeDivisions(this.layoutSource.getFlowDimensionPosition(this.box), this.layoutSource.getFlowDimensionExtent(this.box), SvgPage.modifierDivs)`. Replace the old `modifierYKeys` loop in the constructor and remove the `modifierYKeys` field.
60
+ - [X] T008 [US1] In `src/render/sui/svgPageMap.ts`, change `SvgPage.divIndex(dim)` to `return findDivision(dim, this.divisions);` (documenting that it returns `-1` for positions outside the page), and keep `divSize` as is.
61
+ - [X] T009 [US1] In `src/render/sui/svgPageMap.ts`, update `addModifierTab` and `findModifierTabs` to guard with `div >= 0` instead of `div < this.modifierYKeys.length`. Leave the rest of each method unchanged.
62
+ - [X] T010 [US1] Run `npx tsc --noEmit -p tsconfig.json` and fix any remaining references to `modifierYKeys`.
63
+ - [ ] T011 [US1] Manual validation: follow quickstart.md section 3 steps 1 to 4 in the running app (bottom-of-page text on page 1 and page 2 is selectable).
64
+
65
+ **Checkpoint**: User Story 1 works. Bottom-of-page text is selectable.
66
+
67
+ ---
68
+
69
+ ## Phase 4: User Story 2 - Registering and looking up use the same vertical regions (Priority: P1)
70
+
71
+ **Goal**: Prove filing and lookup agree at every height, and that behavior in the upper and middle page is unchanged.
72
+
73
+ **Independent Test**: `npm run test:page-divisions` passes cases D16 and D17; manual horizontal-mode check (quickstart.md section 3 step 5).
74
+
75
+ ### Tests for User Story 2
76
+
77
+ - [X] T012 [P] [US2] In `tests/pageDivisions.ts`, add case D16: for positions sampled across the page (every 1 unit including all division boundaries and both edges), build a table once, and assert that a tab filed at `findDivision(p, table)` is returned by a lookup at the same `p`, using a small in-test `Record<number, string[]>` that mimics `modifierTabDivs`.
78
+ - [X] T013 [P] [US2] In `tests/pageDivisions.ts`, add case D17: for positions in the upper and middle page (before the last division), assert that the new index is within one of the old `legacyIndex` and that every position still resolves to a division (no `-1`), so nothing that could be filed before is lost.
79
+
80
+ ### Implementation for User Story 2
81
+
82
+ - [X] T014 [US2] Run `npm run test:page-divisions` and confirm all cases D1 to D17 pass.
83
+ - [ ] T015 [US2] Manual validation: quickstart.md section 3 step 5 (horizontal display mode, text near the right end of a page is selectable) and section 4 (existing upper and middle modifiers behave as before).
84
+
85
+ **Checkpoint**: Filing and lookup are shown to agree, in vertical and horizontal flow.
86
+
87
+ ---
88
+
89
+ ## Phase 5: User Story 3 - Redraw and measure clearing stay consistent (Priority: P2)
90
+
91
+ **Goal**: Clearing a measure's modifiers uses the same division selection and cannot fail on an empty division.
92
+
93
+ **Independent Test**: `SvgPage.clearMeasure` resolves the same division as `addModifierTab`, and does not throw when that division holds no modifiers.
94
+
95
+ ### Implementation for User Story 3
96
+
97
+ - [X] T016 [US3] In `src/render/sui/svgPageMap.ts` `SvgPage.clearMeasure`, replace the `div < this.modifierYKeys.length` guard with `div >= 0 && this.modifierTabDivs[div]` so a position outside the page or a division with no modifiers is skipped instead of dereferencing `undefined`. Keep the filtering logic otherwise unchanged (research.md section 6).
98
+ - [X] T017 [US3] In `src/render/sui/svgPageMap.ts`, remove the unused exported `getDiv` function (and the `layoutProvider` import only if nothing else uses it). First confirm with a search of `src/` and `tests/` that `getDiv` has no references.
99
+ - [X] T018 [US3] Run `npx tsc --noEmit -p tsconfig.json` and confirm no errors.
100
+
101
+ **Checkpoint**: All three entry points (`addModifierTab`, `findModifierTabs`, `clearMeasure`) use the same division selection.
102
+
103
+ ---
104
+
105
+ ## Phase 6: Polish & Cross-Cutting Concerns
106
+
107
+ - [X] T019 Run `npm run test:page-divisions`, `npm run test:global-layout-reposition` and `npm run test:text-drag-placement` to confirm no existing headless test regressed.
108
+ - [X] T020 Run `npm run build` and confirm the build succeeds.
109
+ - [ ] T021 Run through all of quickstart.md (sections 1 to 4) and note the result.
110
+
111
+ ---
112
+
113
+ ## Dependencies & Execution Order
114
+
115
+ ### Phase Dependencies
116
+
117
+ - **Setup (Phase 1)**: no dependencies.
118
+ - **Foundational (Phase 2)**: depends on Setup; blocks all user stories.
119
+ - **US1 (Phase 3)**: depends on Phase 2. This is the MVP.
120
+ - **US2 (Phase 4)**: tests T012 and T013 depend only on Phase 2; the manual check T015 depends on US1.
121
+ - **US3 (Phase 5)**: depends on US1 (T007, T008 define `divisions` and the new `divIndex`).
122
+ - **Polish (Phase 6)**: depends on all stories.
123
+
124
+ ### Within Each Story
125
+
126
+ - T007 to T009 all edit `src/render/sui/svgPageMap.ts`, so they run in order (no [P]).
127
+ - T016 and T017 also edit `svgPageMap.ts`; run them after T009.
128
+ - T012 and T013 edit the same test file as T004/T005 but add independent cases; they are marked [P] against each other only if written in separate blocks, otherwise run in order.
129
+
130
+ ### Parallel Opportunities
131
+
132
+ - After T006, US2's tests (T012, T013) can be written while US1's `svgPageMap.ts` edits (T007 to T009) are made, since they touch different files.
133
+ - Everything else is sequential because the work centres on two files.
134
+
135
+ ---
136
+
137
+ ## Parallel Example: after Phase 2
138
+
139
+ ```text
140
+ Task: "Add case D16 to tests/pageDivisions.ts" (T012)
141
+ Task: "Add case D17 to tests/pageDivisions.ts" (T013)
142
+ Task: "Wire divisions into SvgPage in src/render/sui/svgPageMap.ts" (T007 to T009)
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Implementation Strategy
148
+
149
+ ### MVP First (User Story 1 only)
150
+
151
+ 1. Phases 1 and 2 (test registered, division module written and passing).
152
+ 2. Phase 3: wire `SvgPage` to the module.
153
+ 3. Stop and validate: click bottom-of-page text in the app.
154
+
155
+ ### Incremental Delivery
156
+
157
+ 1. MVP above fixes the user-visible bug.
158
+ 2. US2 adds the agreement and no-regression evidence.
159
+ 3. US3 makes `clearMeasure` consistent and removes the dead `getDiv`.
160
+
161
+ ---
162
+
163
+ ## Notes
164
+
165
+ - The whole fix is one new 30-line module plus about a dozen changed lines in `SvgPage`.
166
+ - Removing `modifierYKeys` and `getDiv` is intentional (research.md sections 2 and 6); neither is read anywhere except for `.length`.
167
+ - Commit after each phase.