@bendyline/squisq-formats 2.6.19 → 2.6.21

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.
package/README.md CHANGED
@@ -87,7 +87,7 @@ const imported = await pdfToMarkdownDoc(pdfBuffer);
87
87
  const container = await pdfToContainer(pdfBuffer);
88
88
  ```
89
89
 
90
- **Fidelity:** export uses pdf-lib's standard 14 fonts (`themeId` affects colors only). Pass `images` (keyed by the markdown URL, as for DOCX) to draw PNG and JPEG images that stand alone in a paragraph; other images print as an `[Image: alt]` note. PDF has no semantic structure, so import is heuristic and best-effort: headings are detected by font size, and tables / code blocks / blockquotes / links via the `detectTables` / `detectCodeBlocks` / `detectBlockquotes` / `detectLinks` options (all default true). `pdfToMarkdownDoc` is text-only; `pdfToContainer` also extracts embedded XObject and inline raster images in browsers and Node, placed **by page** — each image is inserted after the last content block from its page (image-only pages fall back to the nearest preceding page with content, else the document end). Placement is page-level only; masks, vector artwork, and images that PDF.js cannot expose as decoded pixels are not emitted.
90
+ **Fidelity:** export uses pdf-lib's standard 14 fonts (`themeId` affects colors only). Pages stay white for printing. Theme text, heading, and link colors are retained when they meet 4.5:1 contrast against both white paper and the shaded table header; otherwise the exporter uses its default dark ink for that role. This also applies to inherited and custom themes. Pass `images` (keyed by the markdown URL, as for DOCX) to draw PNG and JPEG images that stand alone in a paragraph; other images print as an `[Image: alt]` note. PDF has no semantic structure, so import is heuristic and best-effort: headings are detected by font size, and tables / code blocks / blockquotes / links via the `detectTables` / `detectCodeBlocks` / `detectBlockquotes` / `detectLinks` options (all default true). `pdfToMarkdownDoc` is text-only; `pdfToContainer` also extracts embedded XObject and inline raster images in browsers and Node, placed **by page** — each image is inserted after the last content block from its page (image-only pages fall back to the nearest preceding page with content, else the document end). Placement is page-level only; masks, vector artwork, and images that PDF.js cannot expose as decoded pixels are not emitted.
91
91
 
92
92
  ### Diagrams as pictures
93
93
 
@@ -20,6 +20,7 @@ import {
20
20
  // src/pdf/export.ts
21
21
  import { PDFDocument, StandardFonts, rgb, PDFString } from "pdf-lib";
22
22
  import fontkit from "@pdf-lib/fontkit";
23
+ import { contrastRatio } from "@bendyline/squisq/schemas";
23
24
  import { docToMarkdown, resolveThemeForDoc } from "@bendyline/squisq/doc";
24
25
  import { readFrontmatterThemeId, sanitizeUrl } from "@bendyline/squisq/markdown";
25
26
 
@@ -477,9 +478,9 @@ async function createExportContext(pdfDoc, options, doc) {
477
478
  if (themeId) {
478
479
  const theme = resolveThemeForDoc(doc, themeId, options.themeRegistry);
479
480
  if (theme.colors) {
480
- colorText = hexToRgb(theme.colors.text) ?? COLOR_TEXT;
481
- colorHeading = hexToRgb(theme.colors.primary) ?? COLOR_HEADING;
482
- colorLink = hexToRgb(theme.colors.highlight || theme.colors.secondary) ?? COLOR_LINK;
481
+ colorText = paperInk(theme.colors.text, COLOR_TEXT);
482
+ colorHeading = paperInk(theme.colors.primary, COLOR_HEADING);
483
+ colorLink = paperInk(theme.colors.highlight || theme.colors.secondary, COLOR_LINK);
483
484
  }
484
485
  }
485
486
  return {
@@ -1172,6 +1173,14 @@ function renderFallbackBlock(node, ctx, extraIndent) {
1172
1173
  ctx.y -= lineH + PARAGRAPH_SPACING;
1173
1174
  }
1174
1175
  }
1176
+ function paperInk(hex, fallback) {
1177
+ const color = hexToRgb(hex);
1178
+ if (!color) return fallback;
1179
+ const tableHeader = "#" + [COLOR_TABLE_HEADER_BG.r, COLOR_TABLE_HEADER_BG.g, COLOR_TABLE_HEADER_BG.b].map(
1180
+ (channel) => Math.round(channel * 255).toString(16).padStart(2, "0")
1181
+ ).join("");
1182
+ return contrastRatio(hex, "#ffffff") >= 4.5 && contrastRatio(hex, tableHeader) >= 4.5 ? color : fallback;
1183
+ }
1175
1184
  function hexToRgb(hex) {
1176
1185
  const h = hex.startsWith("#") ? hex.slice(1) : hex;
1177
1186
  if (h.length !== 6) return void 0;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  convert,
3
3
  defaultRegistry
4
- } from "./chunk-OHR6V4EE.js";
4
+ } from "./chunk-YEV3P7PN.js";
5
5
  import {
6
6
  ConversionError
7
7
  } from "./chunk-KXOZMWBS.js";
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  renderOutsideInDocument,
29
29
  withOutsideInMarkdownEditing,
30
30
  withOutsideInMetadata
31
- } from "./chunk-ZEWBALT5.js";
31
+ } from "./chunk-JXPZEP7D.js";
32
32
  import {
33
33
  DEFAULT_CONVERSION_LIMITS,
34
34
  convert,
@@ -37,7 +37,7 @@ import {
37
37
  defaultRegistry,
38
38
  prepareConversion,
39
39
  resolveConversionLimits
40
- } from "./chunk-OHR6V4EE.js";
40
+ } from "./chunk-YEV3P7PN.js";
41
41
  import {
42
42
  ConversionError
43
43
  } from "./chunk-KXOZMWBS.js";
@@ -93,7 +93,7 @@ import {
93
93
  markdownDocToPdf,
94
94
  pdfToDoc,
95
95
  pdfToMarkdownDoc
96
- } from "./chunk-5ULLXI4B.js";
96
+ } from "./chunk-4GAVHDHU.js";
97
97
  import "./chunk-34KECNZO.js";
98
98
  import "./chunk-BXWNU4T5.js";
99
99
  import "./chunk-IIQYS2YH.js";
@@ -6,8 +6,8 @@ import {
6
6
  renderOutsideInDocument,
7
7
  withOutsideInMarkdownEditing,
8
8
  withOutsideInMetadata
9
- } from "../chunk-ZEWBALT5.js";
10
- import "../chunk-OHR6V4EE.js";
9
+ } from "../chunk-JXPZEP7D.js";
10
+ import "../chunk-YEV3P7PN.js";
11
11
  import "../chunk-KXOZMWBS.js";
12
12
  import {
13
13
  OUTSIDE_IN_FORMAT_IDS,
@@ -43,7 +43,8 @@ interface PdfExportOptions {
43
43
  defaultFontSize?: number;
44
44
  /**
45
45
  * Squisq theme ID to apply (e.g., 'documentary', 'cinematic').
46
- * When set, overrides heading, text, and link colors with the theme palette.
46
+ * Uses readable heading, text, and link colors from the theme palette on
47
+ * white paper. Colors with insufficient contrast use the default PDF ink.
47
48
  * Font changes are not supported (pdf-lib uses standard 14 PDF fonts only).
48
49
  */
49
50
  themeId?: string;
package/dist/pdf/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  pdfToContainer,
6
6
  pdfToDoc,
7
7
  pdfToMarkdownDoc
8
- } from "../chunk-5ULLXI4B.js";
8
+ } from "../chunk-4GAVHDHU.js";
9
9
  import "../chunk-34KECNZO.js";
10
10
  import "../chunk-BXWNU4T5.js";
11
11
  import "../chunk-IIQYS2YH.js";
@@ -9,7 +9,7 @@ import {
9
9
  defaultRegistry,
10
10
  prepareConversion,
11
11
  resolveConversionLimits
12
- } from "../chunk-OHR6V4EE.js";
12
+ } from "../chunk-YEV3P7PN.js";
13
13
  import {
14
14
  ConversionError
15
15
  } from "../chunk-KXOZMWBS.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/squisq-formats",
3
- "version": "2.6.19",
3
+ "version": "2.6.21",
4
4
  "description": "Document format converters — DOCX, PDF, OOXML import/export",
5
5
  "license": "MIT",
6
6
  "author": "Bendyline",
@@ -125,7 +125,7 @@
125
125
  "typecheck": "tsc --noEmit"
126
126
  },
127
127
  "dependencies": {
128
- "@bendyline/squisq": "2.11.19",
128
+ "@bendyline/squisq": "2.11.20",
129
129
  "@pdf-lib/fontkit": "1.1.1",
130
130
  "@pdf-lib/upng": "1.0.1",
131
131
  "@xmldom/xmldom": "0.9.12",
File without changes