@voyantjs/products 0.31.0 → 0.31.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-pdf.d.ts","sourceRoot":"","sources":["../../src/tasks/generate-pdf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"generate-pdf.d.ts","sourceRoot":"","sources":["../../src/tasks/generate-pdf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAMjE,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,UAAU,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,kBAAkB,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,wBAAwB,CAAC,CA2HnC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { and, asc, eq } from "drizzle-orm";
|
|
2
2
|
import { PDFDocument, rgb, StandardFonts } from "pdf-lib";
|
|
3
3
|
import { productDayServices, productDays, productItineraries, products } from "../schema.js";
|
|
4
|
+
import { plainTextForPdf } from "./pdf-text.js";
|
|
4
5
|
export async function generateProductPdf(db, productId) {
|
|
5
6
|
// 1. Fetch product
|
|
6
7
|
const [product] = await db.select().from(products).where(eq(products.id, productId)).limit(1);
|
|
@@ -68,7 +69,7 @@ export async function generateProductPdf(db, productId) {
|
|
|
68
69
|
}
|
|
69
70
|
if (product.description) {
|
|
70
71
|
y -= 8;
|
|
71
|
-
drawText(product.description, { size: 10 });
|
|
72
|
+
drawText(plainTextForPdf(product.description), { size: 10 });
|
|
72
73
|
}
|
|
73
74
|
y -= 16;
|
|
74
75
|
// Days
|
|
@@ -81,7 +82,7 @@ export async function generateProductPdf(db, productId) {
|
|
|
81
82
|
drawText(`Location: ${day.location}`, { size: 9 });
|
|
82
83
|
}
|
|
83
84
|
if (day.description) {
|
|
84
|
-
drawText(day.description, { size: 9 });
|
|
85
|
+
drawText(plainTextForPdf(day.description), { size: 9 });
|
|
85
86
|
}
|
|
86
87
|
// Services
|
|
87
88
|
for (const svc of day.services) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-text.d.ts","sourceRoot":"","sources":["../../src/tasks/pdf-text.ts"],"names":[],"mappings":"AAyBA,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,UAwB5C"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const NAMED_HTML_ENTITIES = {
|
|
2
|
+
amp: "&",
|
|
3
|
+
apos: "'",
|
|
4
|
+
gt: ">",
|
|
5
|
+
lt: "<",
|
|
6
|
+
nbsp: " ",
|
|
7
|
+
quot: '"',
|
|
8
|
+
};
|
|
9
|
+
function decodeHtmlEntities(value) {
|
|
10
|
+
return value.replace(/&(#\d+|#x[\da-f]+|[a-z][\da-z]+);/gi, (match, entity) => {
|
|
11
|
+
if (entity.startsWith("#x")) {
|
|
12
|
+
const codePoint = Number.parseInt(entity.slice(2), 16);
|
|
13
|
+
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
|
|
14
|
+
}
|
|
15
|
+
if (entity.startsWith("#")) {
|
|
16
|
+
const codePoint = Number.parseInt(entity.slice(1), 10);
|
|
17
|
+
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
|
|
18
|
+
}
|
|
19
|
+
return NAMED_HTML_ENTITIES[entity.toLowerCase()] ?? match;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function plainTextForPdf(value) {
|
|
23
|
+
const trimmed = value.trim();
|
|
24
|
+
if (!trimmed) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
const textWithoutTags = /<[a-z][\s\S]*>/i.test(trimmed)
|
|
28
|
+
? trimmed
|
|
29
|
+
.replace(/<\s*br\s*\/?>/gi, "\n")
|
|
30
|
+
.replace(/<\s*li\b[^>]*>/gi, " * ")
|
|
31
|
+
.replace(/<\s*\/\s*(address|article|aside|blockquote|div|footer|h[1-6]|header|li|main|ol|p|section|table|tbody|td|tfoot|th|thead|tr|ul)\s*>/gi, "\n")
|
|
32
|
+
.replace(/<[^>]*>/g, "")
|
|
33
|
+
: trimmed;
|
|
34
|
+
return decodeHtmlEntities(textWithoutTags)
|
|
35
|
+
.replace(/\r\n?/g, "\n")
|
|
36
|
+
.split("\n")
|
|
37
|
+
.map((line) => line.replace(/[ \t\f\v]+/g, " ").trim())
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join(" ");
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/products",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -125,12 +125,12 @@
|
|
|
125
125
|
"hono": "^4.12.10",
|
|
126
126
|
"pdf-lib": "^1.17.1",
|
|
127
127
|
"zod": "^4.3.6",
|
|
128
|
-
"@voyantjs/core": "0.31.
|
|
129
|
-
"@voyantjs/db": "0.31.
|
|
130
|
-
"@voyantjs/hono": "0.31.
|
|
131
|
-
"@voyantjs/utils": "0.31.
|
|
132
|
-
"@voyantjs/catalog": "0.31.
|
|
133
|
-
"@voyantjs/storage": "0.31.
|
|
128
|
+
"@voyantjs/core": "0.31.1",
|
|
129
|
+
"@voyantjs/db": "0.31.1",
|
|
130
|
+
"@voyantjs/hono": "0.31.1",
|
|
131
|
+
"@voyantjs/utils": "0.31.1",
|
|
132
|
+
"@voyantjs/catalog": "0.31.1",
|
|
133
|
+
"@voyantjs/storage": "0.31.1"
|
|
134
134
|
},
|
|
135
135
|
"devDependencies": {
|
|
136
136
|
"typescript": "^6.0.2",
|