@bendyline/squisq-formats 2.2.0 → 2.3.0

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/NOTICE.md CHANGED
@@ -6,14 +6,13 @@ Third-party components remain under their respective license terms.
6
6
 
7
7
  ## Runtime dependencies
8
8
 
9
- | Package | Version | License | Repository |
10
- | ----------------- | ------- | ----------------------- | ----------------------------------- |
11
- | @bendyline/squisq | 2.1.0 | MIT | https://github.com/bendyline/squisq |
12
- | @pdf-lib/upng | 1.0.1 | MIT | https://github.com/Hopding/upng |
13
- | @xmldom/xmldom | 0.9.10 | MIT | https://github.com/xmldom/xmldom |
14
- | jszip | 3.10.1 | MIT OR GPL-3.0-or-later | https://github.com/Stuk/jszip |
15
- | pdf-lib | 1.17.1 | MIT | https://pdf-lib.js.org |
16
- | pdfjs-dist | 4.10.38 | Apache-2.0 | https://mozilla.github.io/pdf.js |
9
+ | Package | Version | License | Repository |
10
+ | -------------- | ------- | ----------------------- | -------------------------------- |
11
+ | @pdf-lib/upng | 1.0.1 | MIT | https://github.com/Hopding/upng |
12
+ | @xmldom/xmldom | 0.9.10 | MIT | https://github.com/xmldom/xmldom |
13
+ | jszip | 3.10.1 | MIT OR GPL-3.0-or-later | https://github.com/Stuk/jszip |
14
+ | pdf-lib | 1.17.1 | MIT | https://pdf-lib.js.org |
15
+ | pdfjs-dist | 4.10.38 | Apache-2.0 | https://mozilla.github.io/pdf.js |
17
16
 
18
17
  Squisq uses jszip under its MIT license option. Copyright and complete license
19
18
  texts for these dependencies are included in their respective npm
package/README.md CHANGED
@@ -299,7 +299,7 @@ Also exported: `createRegistry` / `defaultRegistry` / `defaultFormats`, `BUILTIN
299
299
 
300
300
  The package root re-exports the common converters; `./container`, the plain-HTML/bundle functions, `docxToContainer`, `pdfToContainer`, `PdfPageSize`, and the image utilities are subpath-only.
301
301
 
302
- See the full [API Reference](../../docs/API.md#bendylinesquisq-formats) for every signature and options interface.
302
+ See the full [API Reference](https://github.com/bendyline/squisq/blob/main/docs/API.md#bendylinesquisq-formats) for every signature and options interface.
303
303
 
304
304
  ## Related Packages
305
305
 
@@ -1046,7 +1046,20 @@ function hexToRgb(hex) {
1046
1046
  // src/pdf/import.ts
1047
1047
  import { markdownToDoc } from "@bendyline/squisq/doc";
1048
1048
  import { stringifyMarkdown } from "@bendyline/squisq/markdown";
1049
+
1050
+ // src/pdf/upng.ts
1049
1051
  import UPNG from "@pdf-lib/upng";
1052
+ function isUpngEncoder(value) {
1053
+ return typeof value === "object" && value !== null && "encode" in value && typeof value.encode === "function";
1054
+ }
1055
+ function resolveUpngEncoder(value) {
1056
+ if (isUpngEncoder(value)) return value;
1057
+ if (typeof value !== "object" || value === null || !("default" in value)) return null;
1058
+ return isUpngEncoder(value.default) ? value.default : null;
1059
+ }
1060
+ var upngEncoder = resolveUpngEncoder(UPNG);
1061
+
1062
+ // src/pdf/import.ts
1050
1063
  async function pdfToMarkdownDoc(data, options = {}) {
1051
1064
  options.signal?.throwIfAborted();
1052
1065
  const bytes = data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : data instanceof ArrayBuffer ? new Uint8Array(data) : data;
@@ -1206,7 +1219,8 @@ function imageDataToPng(img) {
1206
1219
  }
1207
1220
  const owned = new Uint8Array(rgba.byteLength);
1208
1221
  owned.set(rgba);
1209
- return UPNG.encode([owned.buffer], img.width, img.height, 0);
1222
+ if (!upngEncoder) return null;
1223
+ return upngEncoder.encode([owned.buffer], img.width, img.height, 0);
1210
1224
  } catch {
1211
1225
  return null;
1212
1226
  }
@@ -1255,6 +1269,22 @@ function insertImageBlocks(blocks, blockPages, images) {
1255
1269
  }
1256
1270
  return result;
1257
1271
  }
1272
+ function hasInterItemSpace(previous, current) {
1273
+ if (!previous) return false;
1274
+ if (/\s$/.test(previous.str) || /^\s/.test(current.str)) return false;
1275
+ const gap = current.x - (previous.x + previous.width);
1276
+ const referenceHeight = Math.min(previous.height, current.height);
1277
+ return gap > Math.max(0.5, referenceHeight * 0.08);
1278
+ }
1279
+ function joinTextItems(items) {
1280
+ let text = "";
1281
+ for (let index = 0; index < items.length; index++) {
1282
+ const item = items[index];
1283
+ if (hasInterItemSpace(items[index - 1], item)) text += " ";
1284
+ text += item.str;
1285
+ }
1286
+ return text;
1287
+ }
1258
1288
  function configurePdfWorker(workerSrc) {
1259
1289
  _workerSrc = workerSrc;
1260
1290
  }
@@ -1337,7 +1367,7 @@ async function extractTextLines(pdf, options) {
1337
1367
  const fontNames = lineItems.map((i) => i.fontName);
1338
1368
  const fontName = modeStr(fontNames) || "";
1339
1369
  const minX = Math.min(...lineItems.map((i) => i.x));
1340
- const text = lineItems.map((i) => i.str).join(" ");
1370
+ const text = joinTextItems(lineItems);
1341
1371
  allLines.push({
1342
1372
  items: lineItems,
1343
1373
  y: key,
@@ -1538,9 +1568,13 @@ function isItalicFont(fontName) {
1538
1568
  function buildInlineNodes(line, options) {
1539
1569
  const nodes = [];
1540
1570
  const detectLinksOpt = options.detectLinks !== false;
1541
- for (const item of line.items) {
1571
+ for (let itemIndex = 0; itemIndex < line.items.length; itemIndex++) {
1572
+ const item = line.items[itemIndex];
1542
1573
  const text = item.str;
1543
1574
  if (!text || text.trim().length === 0) continue;
1575
+ if (hasInterItemSpace(line.items[itemIndex - 1], item)) {
1576
+ nodes.push({ type: "text", value: " " });
1577
+ }
1544
1578
  const bold = isBoldFont(item.fontName);
1545
1579
  const italic = isItalicFont(item.fontName);
1546
1580
  const mono = isMonospaceItem(item);
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  defaultRegistry,
12
12
  prepareConversion,
13
13
  resolveConversionLimits
14
- } from "./chunk-3NKXBZSR.js";
14
+ } from "./chunk-G6J326JW.js";
15
15
  import {
16
16
  inferThemeFromFile
17
17
  } from "./chunk-6S6GU3ZG.js";
@@ -62,7 +62,7 @@ import {
62
62
  markdownDocToPdf,
63
63
  pdfToDoc,
64
64
  pdfToMarkdownDoc
65
- } from "./chunk-PJXJI2LY.js";
65
+ } from "./chunk-GYIVES2E.js";
66
66
  import "./chunk-IIQYS2YH.js";
67
67
  import {
68
68
  collectImagePaths,
package/dist/pdf/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  pdfToContainer,
6
6
  pdfToDoc,
7
7
  pdfToMarkdownDoc
8
- } from "../chunk-PJXJI2LY.js";
8
+ } from "../chunk-GYIVES2E.js";
9
9
  import "../chunk-IIQYS2YH.js";
10
10
  export {
11
11
  configurePdfWorker,
@@ -7,7 +7,7 @@ import {
7
7
  defaultRegistry,
8
8
  prepareConversion,
9
9
  resolveConversionLimits
10
- } from "../chunk-3NKXBZSR.js";
10
+ } from "../chunk-G6J326JW.js";
11
11
  import {
12
12
  ConversionError
13
13
  } from "../chunk-KXOZMWBS.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/squisq-formats",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Document format converters — DOCX, PDF, OOXML import/export",
5
5
  "license": "MIT",
6
6
  "author": "Bendyline",
@@ -24,6 +24,9 @@
24
24
  "access": "public"
25
25
  },
26
26
  "type": "module",
27
+ "engines": {
28
+ "node": ">=22.14.0"
29
+ },
27
30
  "main": "./dist/index.js",
28
31
  "module": "./dist/index.js",
29
32
  "types": "./dist/index.d.ts",
@@ -96,14 +99,14 @@
96
99
  }
97
100
  },
98
101
  "scripts": {
99
- "build": "tsup",
102
+ "build": "tsup && node ../../scripts/remove-empty-chunks.mjs dist",
100
103
  "dev": "concurrently -n js,dts -c blue,gray -r \"tsup --watch --no-dts --no-clean\" \"tsup --watch --dts-only --no-clean\"",
101
104
  "typecheck": "tsc --noEmit"
102
105
  },
103
106
  "dependencies": {
104
107
  "@pdf-lib/upng": "1.0.1",
105
108
  "@xmldom/xmldom": "0.9.10",
106
- "@bendyline/squisq": "2.2.0",
109
+ "@bendyline/squisq": "2.3.0",
107
110
  "jszip": "3.10.1",
108
111
  "pdf-lib": "1.17.1",
109
112
  "pdfjs-dist": "4.10.38"
File without changes