Repository navigation
feat(SignaturePad): fingerprint CSS asset - #1244
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reviewer's GuideThe PR fingerprints the SignaturePad CSS asset by resolving its packaged URL in Razor and injecting it into JavaScript, while also revising canvas resize handling to retain and scale existing strokes and tightening download and observer cleanup. Sequence diagram for fingerprinted SignaturePad initializationsequenceDiagram
participant SignaturePad as SignaturePad Razor
participant JS as SignaturePad JavaScript
participant Assets as Asset resolver
participant DOM as Browser DOM
SignaturePad->>Assets: Resolve Assets[StylePath]
Assets-->>SignaturePad: Return fingerprinted StyleUrl
SignaturePad->>JS: init(id, invoke, alertText, backgroundColor, styleUrl)
JS->>DOM: addLink(styleUrl)
JS->>DOM: Create SignaturePad and observe element resize
Sequence diagram for SignaturePad disposal cleanupsequenceDiagram
participant Component as SignaturePad component
participant JS as SignaturePad JavaScript
participant Data as Data registry
participant Observer as ResizeObserver
Component->>JS: dispose(id)
JS->>Data: Data.get(id)
Data-->>JS: Return observer
JS->>Observer: disconnect()
JS->>Data: Data.remove(id)
Flow diagram for preserving SignaturePad strokes during resizeflowchart TD
A["ResizeObserver detects size change"] --> B["Capture signaturePad.toData()"]
B --> C["Resize canvas for devicePixelRatio"]
C --> D{"Existing stroke data?"}
D -->|Yes| E["Scale stroke points"]
E --> F["signaturePad.fromData(data)"]
D -->|No| G["signaturePad.clear()"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js" line_range="30-31" />
<code_context>
+ var width = canvas.parentElement.offsetWidth;
+ var height = canvas.parentElement.offsetHeight;
+ var data = signaturePad.toData();
+ var scaleX = previousWidth > 0 ? width / previousWidth : 1;
+ var scaleY = previousHeight > 0 ? height / previousHeight : 1;
- // This part causes the canvas to be cleared
</code_context>
<issue_to_address>
**Resizing collapses saved signatures**
When the pad is hidden or collapsed until its parent reports a zero width or height, then expands, `resizeCanvas` scales saved points to zero on a collapsed axis or records zero as the previous dimension; on expansion, the fallback scale of 1 cannot restore the original coordinates, so the signature appears collapsed, misplaced, clipped, or undersized.
Ignore zero-dimension resize measurements and preserve the last nonzero dimensions and saved point coordinates until the pad has nonzero dimensions again.
Also at `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js:32`.
</issue_to_address>
### Comment 2
<location path="src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js" line_range="41-49" />
<code_context>
+ previousHeight = height;
+
+ if (data.length > 0) {
+ signaturePad.fromData(data.map(group => ({
+ ...group,
+ points: group.points.map(point => ({
+ ...point,
+ x: point.x * scaleX,
+ y: point.y * scaleY
+ }))
+ })));
+ }
+ else {
+ signaturePad.clear();
</code_context>
<issue_to_address>
**Resized signatures cannot be saved**
When a signature is present and the canvas is resized, `signaturePad.fromData()` clears the pad before redrawing and leaves its `isEmpty()` flag set, so the save handlers treat the visible signature as empty and refuse to export it.
Restore the non-empty state after redrawing the signature, or use a redraw path that preserves the pad’s `isEmpty()` state.
</issue_to_address>| var scaleX = previousWidth > 0 ? width / previousWidth : 1; | ||
| var scaleY = previousHeight > 0 ? height / previousHeight : 1; |
There was a problem hiding this comment.
🟡 Medium · Resizing collapses saved signatures
When the pad is hidden or collapsed until its parent reports a zero width or height, then expands, resizeCanvas scales saved points to zero on a collapsed axis or records zero as the previous dimension; on expansion, the fallback scale of 1 cannot restore the original coordinates, so the signature appears collapsed, misplaced, clipped, or undersized.
Ignore zero-dimension resize measurements and preserve the last nonzero dimensions and saved point coordinates until the pad has nonzero dimensions again.
Also at src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js:32.
Prompt for AI agents
In `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js` at lines 30-31:
**Resizing collapses saved signatures**
When the pad is hidden or collapsed until its parent reports a zero width or height, then expands, `resizeCanvas` scales saved points to zero on a collapsed axis or records zero as the previous dimension; on expansion, the fallback scale of 1 cannot restore the original coordinates, so the signature appears collapsed, misplaced, clipped, or undersized.
Ignore zero-dimension resize measurements and preserve the last nonzero dimensions and saved point coordinates until the pad has nonzero dimensions again.
Also at `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js:32`.| signaturePad.fromData(data.map(group => ({ | ||
| ...group, | ||
| points: group.points.map(point => ({ | ||
| ...point, | ||
| x: point.x * scaleX, | ||
| y: point.y * scaleY | ||
| })) | ||
| }))); | ||
| } |
There was a problem hiding this comment.
🟠 High · Resized signatures cannot be saved
When a signature is present and the canvas is resized, signaturePad.fromData() clears the pad before redrawing and leaves its isEmpty() flag set, so the save handlers treat the visible signature as empty and refuse to export it.
Restore the non-empty state after redrawing the signature, or use a redraw path that preserves the pad’s isEmpty() state.
Prompt for AI agents
In `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js` at lines 41-49:
**Resized signatures cannot be saved**
When a signature is present and the canvas is resized, `signaturePad.fromData()` clears the pad before redrawing and leaves its `isEmpty()` flag set, so the save handlers treat the visible signature as empty and refuse to export it.
Restore the non-empty state after redrawing the signature, or use a redraw path that preserves the pad’s `isEmpty()` state.
Link issues
fixes #1243
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Improve SignaturePad asset loading, resizing behavior, and resource cleanup.
New Features:
Bug Fixes:
Enhancements:
Build: