Skip to content

Conversation

chethanac15
Copy link

Summary

  • Ensures the HTML plugin always removes its overlay when html2canvas throws, so the page doesn’t get stuck behind a non-interactive overlay.
  • Adds a test that verifies overlay cleanup on error.
  • Introduces an optional, opt-in fallback to convert inline CSS Color 4 values like color(display-p3 …) to approximate sRGB rgb/rgba before rendering.

What changed

  • src/modules/html.js

    • Worker.prototype.toCanvas() and Worker.prototype.toContext2d()
      • On success and in .catch(...), safely remove .html2pdf__overlay if present and null it.
    • New helpers
      • replaceDisplayP3InStyle(styleText): rewrites color(display-p3 …) → rgb/rgba (lossy).
      • applyColorFallbackInlineStyles(root): walks the cloned subtree and updates inline style attributes.
    • toContainer()
      • If options.colorSpaceFallback === 'srgb', apply the inline-style fallback to the cloned source before rendering.
  • test/specs/html.spec.js

    • New test: “removes overlay when html2canvas throws an error.”
      • Stubs window.html2canvas to reject, asserts error propagation and overlay removal.
  • types/index.d.ts

    • HTMLOptions: adds colorSpaceFallback?: 'srgb' | 'none'.
  • README.md

    • “HTML rendering notes” section with usage and limitations for colorSpaceFallback.

Usage (optional fallback)

import { jsPDF } from 'jspdf';

const doc = new jsPDF();
await doc.html(elementOrHtmlString, {
  // Converts inline style attributes with color(display-p3 ...) to rgb()/rgba() before rendering
  colorSpaceFallback: 'srgb'
});

Notes and limitations

Testing

  • Full test suite passes locally (pre-existing pending specs unchanged).
  • New test covers overlay cleanup on html2canvas rejection.

Housekeeping

  • Excludes dist/ artifacts from the PR (reset to upstream).

Related

  • Partially addresses html: color(display-p3 ...) support #3856
    • Fully fixes the “overlay left after crash” aspect.
    • Provides an optional, inline-only mitigation for color(display-p3 …) until upstream support lands.

Checklist

  • Overlay is removed on success and error paths in html() rendering
  • Added test for overlay cleanup on error
  • Optional inline color fallback behind colorSpaceFallback: 'srgb'
  • Types updated (HTMLOptions)
  • Docs updated (README)
  • No dist/ artifacts included in the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant