@algorisys/yappydraw 0.8.278 → 0.8.283
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 +2 -2
- package/chunks/{AllPackages-DytsA6Gg.js → AllPackages-NXu9X6xl.js} +5 -5
- package/chunks/{BaseConfiguration-B0Un-ANd.js → BaseConfiguration-Cn1Beeg_.js} +3 -3
- package/chunks/{Entities-XwxJEcR3.js → Entities-DNDwR9nR.js} +1 -1
- package/chunks/{Factory-B4kWsy6c.js → Factory-hCmMrRZd.js} +8 -8
- package/chunks/{InputJax-DQpRzuU2.js → InputJax-BnvzjXPP.js} +1 -1
- package/chunks/PrioritizedList-CopFulOu.js +35 -0
- package/chunks/{TeXAtom-COgv6VHH.js → TeXAtom-i5HZ7jSY.js} +25 -25
- package/chunks/__vite-browser-external-BsdCVVos.js +110 -0
- package/chunks/_commonjsHelpers-DaMA6jEr.js +8 -0
- package/chunks/{canva-ai-7n8RQQlp.js → canva-ai-6uxuZ0PT.js} +8 -8
- package/chunks/{choice-dialog-state-DzWAU-Fv.js → choice-dialog-state-CTLAD7og.js} +1 -1
- package/chunks/{design-generator-AHGi1XTI.js → design-generator-l8Wo9SER.js} +1 -1
- package/chunks/{drawing-engine-DfKBHdTi.js → drawing-engine-BTqPTS30.js} +1 -1
- package/chunks/{drawings-store-Cyv-1e1L.js → drawings-store-B0h0XeLH.js} +19 -19
- package/chunks/{ds-operations-C9fmILbu.js → ds-operations-CvCIeybe.js} +1 -1
- package/chunks/{export-game-C1SNNfRf.js → export-game-CQ9VCQV9.js} +1 -1
- package/chunks/{game-runtime-ztkqHa3o.js → game-runtime-DGFlcZcF.js} +76 -76
- package/chunks/{html-CEj6ZeJc.js → html-BBKfobGE.js} +56 -55
- package/chunks/html2canvas.esm-BWVIUcAF.js +4802 -0
- package/chunks/{index-vjDu6_KH.js → index-D1ifHWAi.js} +15983 -12966
- package/chunks/index.es-Cmz4JyRm.js +6665 -0
- package/chunks/jspdf.es.min-rJE95jGX.js +9859 -0
- package/chunks/lcms-Car3bVu8.js +949 -0
- package/chunks/lcms-tShoQ1hy.js +4 -0
- package/chunks/{liteAdaptor-BZby1Qz2.js → liteAdaptor-DFCyQb98.js} +2 -2
- package/chunks/{lucide-solid-UJTMB-sy.js → lucide-solid-PB_pG8LH.js} +1 -1
- package/chunks/{markdown-to-slides-CKGVwM_7.js → markdown-to-slides-Ci06cYoT.js} +16 -16
- package/chunks/{mathjax-CnUrFnFS.js → mathjax-BPYOiwki.js} +1 -1
- package/chunks/{mathjax-D6cR72fZ.js → mathjax-BYK64638.js} +2 -2
- package/chunks/{morph-animator-D7JpZIyR.js → morph-animator-nKcVAyGw.js} +1 -1
- package/chunks/{onboarding-tour-DsN4nEFc.js → onboarding-tour-F8YlLQgf.js} +32 -32
- package/chunks/pdf-cmyk-CqVZV2FF.js +339 -0
- package/chunks/pdf-vector-hLlPZeLt.js +200 -0
- package/chunks/pdf-x-DBYFVbAz.js +220 -0
- package/chunks/purify.es-C2Qa7b4C.js +906 -0
- package/chunks/{search-qTCHUaUH.js → search-Nvw1qYCe.js} +2 -2
- package/chunks/{slide-generator-CoHxujzf.js → slide-generator-BwaWABSo.js} +8 -8
- package/chunks/{svg-B2urwbCV.js → svg-CGqKTjgw.js} +3 -3
- package/chunks/svg2pdf.es.min-BVaMJ-wC.js +2452 -0
- package/chunks/{tex-BTCIQDRb.js → tex-Cc_XKudY.js} +4 -4
- package/chunks/{turntable-ai-BEZd382K.js → turntable-ai-DyxE4d5_.js} +1 -1
- package/chunks/{yappy-NspTXSPk.css → yappy-FCQs01wv.css} +1 -1
- package/package.json +1 -1
- package/yappy.js +5 -5
- package/chunks/PrioritizedList-TjDg4i-s.js +0 -39
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { L as S, M as C, N as $ } from "./index-D1ifHWAi.js";
|
|
2
|
+
import { p as E, i as P, a as D, c as T } from "./pdf-cmyk-CqVZV2FF.js";
|
|
3
|
+
const b = (t, i) => {
|
|
4
|
+
for (let n = t; n; n = n.parentElement) {
|
|
5
|
+
const r = n.getAttribute(i);
|
|
6
|
+
if (r !== null && r !== "" && r !== "inherit") return r;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}, B = (t) => {
|
|
10
|
+
if (!t || t === "normal") return 400;
|
|
11
|
+
if (t === "bold" || t === "bolder") return 700;
|
|
12
|
+
if (t === "lighter") return 300;
|
|
13
|
+
const i = parseInt(t, 10);
|
|
14
|
+
return Number.isFinite(i) ? i : 400;
|
|
15
|
+
}, I = (t) => ({
|
|
16
|
+
family: b(t, "font-family") ?? "sans-serif",
|
|
17
|
+
weight: B(b(t, "font-weight")),
|
|
18
|
+
italic: /italic|oblique/.test(b(t, "font-style") ?? "")
|
|
19
|
+
}), U = (t) => {
|
|
20
|
+
const i = t.family.toLowerCase(), n = /monospace|mono\b|courier|code/.test(i) ? "courier" : /(^|,)\s*serif|merriweather|georgia|times/.test(i) ? "times" : "helvetica", r = t.weight >= 600, e = r && t.italic ? "bolditalic" : r ? "bold" : t.italic ? "italic" : "normal";
|
|
21
|
+
return { family: n, style: e };
|
|
22
|
+
}, A = (t) => t.split(",")[0].trim().replace(/^['"]|['"]$/g, ""), L = async (t) => {
|
|
23
|
+
const i = await fetch(t);
|
|
24
|
+
if (!i.ok) throw new Error(`Font fetch failed: ${t} (${i.status})`);
|
|
25
|
+
return i.arrayBuffer();
|
|
26
|
+
}, N = async (t) => {
|
|
27
|
+
const i = new Blob([t]).stream().pipeThrough(new DecompressionStream("deflate"));
|
|
28
|
+
return new Uint8Array(await new Response(i).arrayBuffer());
|
|
29
|
+
}, q = async (t, i = N) => {
|
|
30
|
+
const n = new DataView(t);
|
|
31
|
+
if (t.byteLength < 44 || n.getUint32(0) !== 2001684038) return t;
|
|
32
|
+
const r = n.getUint32(4), e = n.getUint16(12), s = [];
|
|
33
|
+
for (let o = 0; o < e; o++) {
|
|
34
|
+
const g = 44 + o * 20, m = n.getUint32(g), p = n.getUint32(g + 4), h = n.getUint32(g + 8), y = n.getUint32(g + 12), w = n.getUint32(g + 16), v = new Uint8Array(t, p, h), F = h < y ? await i(v) : v;
|
|
35
|
+
if (F.length !== y) throw new Error("WOFF table decompressed to the wrong length");
|
|
36
|
+
s.push({ tag: m, checksum: w, data: F });
|
|
37
|
+
}
|
|
38
|
+
s.sort((o, g) => o.tag - g.tag);
|
|
39
|
+
let u = 12 + e * 16;
|
|
40
|
+
for (const o of s) u += o.data.length + 3 & -4;
|
|
41
|
+
const f = new Uint8Array(u), a = new DataView(f.buffer);
|
|
42
|
+
let d = 1, l = 0;
|
|
43
|
+
for (; d * 2 <= e; )
|
|
44
|
+
d *= 2, l++;
|
|
45
|
+
a.setUint32(0, r), a.setUint16(4, e), a.setUint16(6, d * 16), a.setUint16(8, l), a.setUint16(10, e * 16 - d * 16);
|
|
46
|
+
let c = 12 + e * 16;
|
|
47
|
+
return s.forEach((o, g) => {
|
|
48
|
+
const m = 12 + g * 16;
|
|
49
|
+
a.setUint32(m, o.tag), a.setUint32(m + 4, o.checksum), a.setUint32(m + 8, c), a.setUint32(m + 12, o.data.length), f.set(o.data, c), c += o.data.length + 3 & -4;
|
|
50
|
+
}), f.buffer;
|
|
51
|
+
}, k = (t) => {
|
|
52
|
+
if (t.byteLength < 4) return !1;
|
|
53
|
+
const i = new DataView(t).getUint32(0);
|
|
54
|
+
return i === 65536 || i === 1953658213;
|
|
55
|
+
}, M = (t) => {
|
|
56
|
+
const i = t.slice(t.indexOf(",") + 1), n = atob(i), r = new Uint8Array(n.length);
|
|
57
|
+
for (let e = 0; e < n.length; e++) r[e] = n.charCodeAt(e);
|
|
58
|
+
return r.buffer;
|
|
59
|
+
}, x = (t) => {
|
|
60
|
+
const i = A(t.family), n = S().find((u) => u.family === i);
|
|
61
|
+
if (n)
|
|
62
|
+
return n.kind === "google" || !n.dataUrl ? null : { id: `yd-${n.key}`, load: async () => M(n.dataUrl) };
|
|
63
|
+
const r = C(t.family);
|
|
64
|
+
if (!r) return null;
|
|
65
|
+
const e = $(r, t.weight, t.italic);
|
|
66
|
+
if (!e) return null;
|
|
67
|
+
const s = "/";
|
|
68
|
+
return { id: `yd-${e.file.replace(/\.(ttf|woff)$/, "")}`, load: () => L(`${s}fonts/outline/${e.file}`) };
|
|
69
|
+
}, V = (t) => {
|
|
70
|
+
const i = new Uint8Array(t);
|
|
71
|
+
let n = "";
|
|
72
|
+
for (let r = 0; r < i.length; r += 32768) n += String.fromCharCode(...i.subarray(r, r + 32768));
|
|
73
|
+
return btoa(n);
|
|
74
|
+
}, W = {
|
|
75
|
+
helvetica: "Inter, sans-serif",
|
|
76
|
+
times: "Merriweather, serif",
|
|
77
|
+
courier: "Source Code Pro, monospace"
|
|
78
|
+
}, j = async (t, i, n = !1) => {
|
|
79
|
+
const r = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Set(), s = [...i.querySelectorAll("text, tspan")], u = s.map(I), f = (a) => {
|
|
80
|
+
let d = r.get(a.id);
|
|
81
|
+
return d || (d = a.load().then(q).then((l) => {
|
|
82
|
+
if (!k(l)) return !1;
|
|
83
|
+
const c = `${a.id}.ttf`;
|
|
84
|
+
return t.addFileToVFS(c, V(l)), t.addFont(c, a.id, "normal"), !!t.getFontList()[a.id];
|
|
85
|
+
}).catch(() => !1), r.set(a.id, d)), d;
|
|
86
|
+
};
|
|
87
|
+
return await Promise.all(s.map(async (a, d) => {
|
|
88
|
+
const l = u[d];
|
|
89
|
+
let c = x(l);
|
|
90
|
+
if ((!c || !await f(c)) && n) {
|
|
91
|
+
if (c = x({ ...l, family: W[U(l).family] }), !c || !await f(c)) throw new Error(`PDF/X: could not embed a font for “${l.family}”`);
|
|
92
|
+
e.add(A(l.family));
|
|
93
|
+
}
|
|
94
|
+
if (c && await f(c))
|
|
95
|
+
a.setAttribute("font-family", c.id), a.setAttribute("font-weight", "400"), a.setAttribute("font-style", "normal");
|
|
96
|
+
else {
|
|
97
|
+
const o = U(l);
|
|
98
|
+
a.setAttribute("font-family", o.family), a.setAttribute("font-weight", o.style.includes("bold") ? "700" : "400"), a.setAttribute("font-style", o.style.includes("italic") ? "italic" : "normal"), e.add(A(l.family));
|
|
99
|
+
}
|
|
100
|
+
a.removeAttribute("font-stretch");
|
|
101
|
+
})), [...e];
|
|
102
|
+
}, O = async (t) => {
|
|
103
|
+
const i = [...t.querySelectorAll("image")].filter((n) => /filter\s*:/.test(n.getAttribute("style") ?? ""));
|
|
104
|
+
await Promise.all(i.map(async (n) => {
|
|
105
|
+
const r = (n.getAttribute("style") ?? "").match(/filter\s*:\s*([^;]+)/)?.[1]?.trim(), e = n.getAttribute("href") ?? n.getAttributeNS("http://www.w3.org/1999/xlink", "href");
|
|
106
|
+
if (!(!r || !e))
|
|
107
|
+
try {
|
|
108
|
+
const s = new Image();
|
|
109
|
+
s.src = e, await s.decode();
|
|
110
|
+
const u = document.createElement("canvas");
|
|
111
|
+
u.width = s.naturalWidth, u.height = s.naturalHeight;
|
|
112
|
+
const f = u.getContext("2d");
|
|
113
|
+
if (!f) return;
|
|
114
|
+
f.filter = r, f.drawImage(s, 0, 0), n.setAttribute("href", u.toDataURL("image/png")), n.removeAttribute("style");
|
|
115
|
+
} catch {
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
}, X = (t, i, n, r) => {
|
|
119
|
+
const e = t.cloneNode(!0);
|
|
120
|
+
return e.setAttribute("width", `${r.width}`), e.setAttribute("height", `${r.height}`), e.setAttribute("viewBox", `${r.x - i} ${r.y - n} ${r.width} ${r.height}`), e.style.backgroundColor = "", r.keep && e.querySelectorAll("[data-yappy-id]").forEach((s) => {
|
|
121
|
+
r.keep.has(s.getAttribute("data-yappy-id")) || s.remove();
|
|
122
|
+
}), e.querySelectorAll("[data-yappy-page-bg]").forEach((s) => s.remove()), e.querySelectorAll("style").forEach((s) => {
|
|
123
|
+
s.textContent?.includes("@import") && s.remove();
|
|
124
|
+
}), e;
|
|
125
|
+
}, _ = (t) => {
|
|
126
|
+
if (/^#[0-9a-f]{6}$/i.test(t)) return t;
|
|
127
|
+
const i = document.createElement("canvas").getContext("2d");
|
|
128
|
+
if (!i) return null;
|
|
129
|
+
i.fillStyle = "#000001", i.fillStyle = t;
|
|
130
|
+
const n = String(i.fillStyle);
|
|
131
|
+
if (n === "#000001") return null;
|
|
132
|
+
if (n.startsWith("#")) return n;
|
|
133
|
+
const r = n.match(/rgba?\(([^)]+)\)/);
|
|
134
|
+
if (!r) return null;
|
|
135
|
+
const [e, s, u, f = "1"] = r[1].split(",").map((a) => a.trim());
|
|
136
|
+
return parseFloat(f) === 0 ? null : "#" + [e, s, u].map((a) => (+a).toString(16).padStart(2, "0")).join("");
|
|
137
|
+
}, z = async (t, i, n, r, e) => {
|
|
138
|
+
const [{ jsPDF: s }, { svg2pdf: u }] = await Promise.all([import("./jspdf.es.min-rJE95jGX.js").then((c) => c.j), import("./svg2pdf.es.min-BVaMJ-wC.js")]), f = r[0], a = new s({
|
|
139
|
+
orientation: f.width >= f.height ? "landscape" : "portrait",
|
|
140
|
+
unit: "px",
|
|
141
|
+
format: [f.width, f.height],
|
|
142
|
+
hotfixes: ["px_scaling"],
|
|
143
|
+
// Flate-compress streams. Without it every embedded bitmap is stored raw — a 460×360
|
|
144
|
+
// shadow halo was 650 kB — and content streams and fonts go uncompressed too.
|
|
145
|
+
compress: !0
|
|
146
|
+
}), d = t.cloneNode(!0), l = document.createElement("div");
|
|
147
|
+
l.style.cssText = "position:fixed;left:-100000px;top:0;visibility:hidden;pointer-events:none", document.body.appendChild(l);
|
|
148
|
+
try {
|
|
149
|
+
l.appendChild(d);
|
|
150
|
+
const c = await j(a, d, !!e?.pdfx);
|
|
151
|
+
await O(d), d.remove();
|
|
152
|
+
let o = 0;
|
|
153
|
+
const g = /* @__PURE__ */ new Set();
|
|
154
|
+
if (e) {
|
|
155
|
+
const p = await E(d, e.engine);
|
|
156
|
+
P(a, e.engine, e.exact, e.spots, g), D(a, s.API, p, () => {
|
|
157
|
+
o++;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
for (let p = 0; p < r.length; p++) {
|
|
161
|
+
const h = r[p];
|
|
162
|
+
p > 0 && a.addPage([h.width, h.height], h.width >= h.height ? "landscape" : "portrait");
|
|
163
|
+
const y = h.background ? _(h.background) : null;
|
|
164
|
+
y && (a.setFillColor(y), a.rect(0, 0, h.width, h.height, "F"));
|
|
165
|
+
const w = X(d, i, n, h);
|
|
166
|
+
l.appendChild(w);
|
|
167
|
+
try {
|
|
168
|
+
await u(w, a, { x: 0, y: 0, width: h.width, height: h.height });
|
|
169
|
+
} finally {
|
|
170
|
+
w.remove();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let m = new Uint8Array(a.output("arraybuffer"));
|
|
174
|
+
if (e && (m = await T(m, e.engine, e.exact, g)), e?.pdfx) {
|
|
175
|
+
if (o > 0) throw new Error("PDF/X: an image could not be converted to CMYK");
|
|
176
|
+
const { applyPdfX4: p } = await import("./pdf-x-DBYFVbAz.js");
|
|
177
|
+
m = await p(m, {
|
|
178
|
+
profile: e.engine.profile,
|
|
179
|
+
profileBytes: e.engine.profileBytes,
|
|
180
|
+
title: e.pdfx.title,
|
|
181
|
+
bleedPt: e.pdfx.bleedPt
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return { bytes: m, substitutedFonts: c, rgbImages: o };
|
|
185
|
+
} finally {
|
|
186
|
+
l.remove();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
export {
|
|
190
|
+
O as bakeImageFilters,
|
|
191
|
+
_ as cssColorToHex,
|
|
192
|
+
j as embedSvgFonts,
|
|
193
|
+
x as embeddableFontFor,
|
|
194
|
+
k as isTrueType,
|
|
195
|
+
X as pageSvg,
|
|
196
|
+
z as renderSvgPagesToPdf,
|
|
197
|
+
U as standardPdfFont,
|
|
198
|
+
I as textFaceOf,
|
|
199
|
+
q as woffToSfnt
|
|
200
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { P as A, d as Y, t as B, b as E } from "./pdf-cmyk-CqVZV2FF.js";
|
|
2
|
+
function w(e) {
|
|
3
|
+
if (/^[\x20-\x7e]*$/.test(e)) return `(${e.replace(/[\\()]/g, (s) => "\\" + s)})`;
|
|
4
|
+
let t = "FEFF";
|
|
5
|
+
for (let s = 0; s < e.length; s++) t += e.charCodeAt(s).toString(16).padStart(4, "0").toUpperCase();
|
|
6
|
+
return `<${t}>`;
|
|
7
|
+
}
|
|
8
|
+
const X = (e) => e.replace(/[<>&"']/g, (t) => ({ "<": "<", ">": ">", "&": "&", '"': """, "'": "'" })[t]), F = (e, t = 2) => String(Math.abs(e)).padStart(t, "0");
|
|
9
|
+
function _(e) {
|
|
10
|
+
const t = -e.getTimezoneOffset(), s = t >= 0 ? "+" : "-", o = F(Math.floor(Math.abs(t) / 60)), n = F(Math.abs(t) % 60), p = e.getFullYear(), m = F(e.getMonth() + 1), l = F(e.getDate()), x = F(e.getHours()), D = F(e.getMinutes()), $ = F(e.getSeconds());
|
|
11
|
+
return {
|
|
12
|
+
pdf: `D:${p}${m}${l}${x}${D}${$}${s}${o}'${n}'`,
|
|
13
|
+
xmp: `${p}-${m}-${l}T${x}:${D}:${$}${s}${o}:${n}`
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function K(e) {
|
|
17
|
+
return `<?xpacket begin="\uFEFF" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
|
18
|
+
<x:xmpmeta xmlns:x="adobe:ns:meta/">
|
|
19
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
20
|
+
<rdf:Description rdf:about=""
|
|
21
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
22
|
+
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
|
|
23
|
+
xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
|
|
24
|
+
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
|
|
25
|
+
xmlns:pdfxid="http://www.npes.org/pdfx/ns/id/">
|
|
26
|
+
<dc:format>application/pdf</dc:format>
|
|
27
|
+
<dc:title><rdf:Alt><rdf:li xml:lang="x-default">${X(e.title)}</rdf:li></rdf:Alt></dc:title>
|
|
28
|
+
<xmp:CreateDate>${e.xmpDate}</xmp:CreateDate>
|
|
29
|
+
<xmp:ModifyDate>${e.xmpDate}</xmp:ModifyDate>
|
|
30
|
+
<xmp:MetadataDate>${e.xmpDate}</xmp:MetadataDate>
|
|
31
|
+
<xmp:CreatorTool>YappyDraw</xmp:CreatorTool>
|
|
32
|
+
<pdf:Producer>${X(e.producer)}</pdf:Producer>
|
|
33
|
+
<pdf:Trapped>False</pdf:Trapped>
|
|
34
|
+
<xmpMM:DocumentID>${e.documentId}</xmpMM:DocumentID>
|
|
35
|
+
<xmpMM:InstanceID>${e.instanceId}</xmpMM:InstanceID>
|
|
36
|
+
<xmpMM:VersionID>1</xmpMM:VersionID>
|
|
37
|
+
<xmpMM:RenditionClass>default</xmpMM:RenditionClass>
|
|
38
|
+
<pdfxid:GTS_PDFXVersion>PDF/X-4</pdfxid:GTS_PDFXVersion>
|
|
39
|
+
</rdf:Description>
|
|
40
|
+
</rdf:RDF>
|
|
41
|
+
</x:xmpmeta>
|
|
42
|
+
<?xpacket end="w"?>`;
|
|
43
|
+
}
|
|
44
|
+
const j = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, U = (e) => new Set([...e.matchAll(/\/(F\d+)\s+[\d.]+\s+Tf/g)].map((t) => t[1]));
|
|
45
|
+
async function W(e, t) {
|
|
46
|
+
const s = new A(e), o = s.ref("Root"), n = s.ref("Info");
|
|
47
|
+
if (!o || !n) throw new Error("PDF/X: no catalog or info dictionary");
|
|
48
|
+
const p = s.get(o);
|
|
49
|
+
if (/\/OutputIntents|\/Metadata/.test(p.dict)) throw new Error("PDF/X: catalog already has an output intent or metadata");
|
|
50
|
+
const m = _(t.now ?? /* @__PURE__ */ new Date()), l = t.ids ?? { documentId: `uuid:${j()}`, instanceId: `uuid:${j()}` }, x = /\/Producer\s*\(([^)]*)\)/.exec(s.get(n).dict)?.[1] ?? "jsPDF", D = s.add(`<<
|
|
51
|
+
/N 4
|
|
52
|
+
/Filter /FlateDecode
|
|
53
|
+
>>`, await Y(t.profileBytes)), $ = s.add(`<<
|
|
54
|
+
/Type /OutputIntent
|
|
55
|
+
/S /GTS_PDFX
|
|
56
|
+
/OutputConditionIdentifier ${w(t.profile.outputConditionIdentifier)}
|
|
57
|
+
/OutputCondition ${w(t.profile.outputCondition)}
|
|
58
|
+
/RegistryName (http://www.color.org)
|
|
59
|
+
/Info ${w(t.profile.label)}
|
|
60
|
+
/DestOutputProfile ${D} 0 R
|
|
61
|
+
>>`), P = new TextEncoder().encode(K({ title: t.title, xmpDate: m.xmp, producer: x, ...l })), T = s.add(`<<
|
|
62
|
+
/Type /Metadata
|
|
63
|
+
/Subtype /XML
|
|
64
|
+
>>`, P), I = p.dict.replace(/\/OpenAction\s*\[[^\]]*\]\s*/, "");
|
|
65
|
+
s.set(o, I.replace(/>>\s*$/, `/OutputIntents [${$} 0 R]
|
|
66
|
+
/Metadata ${T} 0 R
|
|
67
|
+
>>`)), s.set(n, `<<
|
|
68
|
+
/Producer ${w(x)}
|
|
69
|
+
/Creator (YappyDraw)
|
|
70
|
+
/Title ${w(t.title)}
|
|
71
|
+
/CreationDate (${m.pdf})
|
|
72
|
+
/ModDate (${m.pdf})
|
|
73
|
+
/Trapped /False
|
|
74
|
+
/GTS_PDFXVersion (PDF/X-4)
|
|
75
|
+
>>`);
|
|
76
|
+
const S = /* @__PURE__ */ new Set();
|
|
77
|
+
for (const a of s.objectNumbers()) {
|
|
78
|
+
const c = s.get(a);
|
|
79
|
+
if (/\/Type\s*\/Page\b/.test(c.dict) && !c.stream) {
|
|
80
|
+
const u = /\/MediaBox\s*\[\s*([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)\s*\]/.exec(c.dict);
|
|
81
|
+
if (!u) throw new Error(`PDF/X: page ${a} has no MediaBox`);
|
|
82
|
+
const [h, g, f, d] = u.slice(1).map(Number), N = t.bleedPt, G = (y) => `[${+(h + y).toFixed(3)} ${+(g + y).toFixed(3)} ${+(f - y).toFixed(3)} ${+(d - y).toFixed(3)}]`, v = (N > 0 ? `/BleedBox ${G(0)} ` : "") + `/TrimBox ${G(N)}`;
|
|
83
|
+
s.set(a, c.dict.replace(/>>\s*$/, `${v}
|
|
84
|
+
>>`));
|
|
85
|
+
const V = /\/Contents\s*(\[[^\]]*\]|\d+\s+0\s+R)/.exec(c.dict)?.[1] ?? "";
|
|
86
|
+
for (const y of V.matchAll(/(\d+)\s+0\s+R/g)) S.add(parseInt(y[1], 10));
|
|
87
|
+
}
|
|
88
|
+
c.stream && /\/Subtype\s*\/Form/.test(c.dict) && S.add(a);
|
|
89
|
+
}
|
|
90
|
+
const C = [];
|
|
91
|
+
for (const a of S) {
|
|
92
|
+
const c = s.get(a);
|
|
93
|
+
c?.stream && C.push(B(await E(c.dict, c.stream)));
|
|
94
|
+
}
|
|
95
|
+
const b = /* @__PURE__ */ new Set();
|
|
96
|
+
C.forEach((a) => U(a).forEach((c) => b.add(c)));
|
|
97
|
+
const M = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set();
|
|
98
|
+
for (const a of s.objectNumbers()) {
|
|
99
|
+
const c = s.get(a);
|
|
100
|
+
if (c.stream || !/^<<\s*\/ProcSet/.test(c.dict)) continue;
|
|
101
|
+
const u = /\/Font\s*<<([^>]*)>>/.exec(c.dict);
|
|
102
|
+
if (!u) continue;
|
|
103
|
+
const h = [...u[1].matchAll(/\/(F\d+)\s+(\d+)\s+0\s+R/g)], g = h.filter((d) => b.has(d[1]));
|
|
104
|
+
h.forEach((d) => (b.has(d[1]) ? R : M).add(parseInt(d[2], 10)));
|
|
105
|
+
const f = g.length ? `/Font << ${g.map((d) => `/${d[1]} ${d[2]} 0 R`).join(" ")} >>` : "";
|
|
106
|
+
s.set(a, c.dict.replace(u[0], f));
|
|
107
|
+
}
|
|
108
|
+
for (const a of M) R.has(a) || s.remove(a);
|
|
109
|
+
L(s), s.setVersion("1.6");
|
|
110
|
+
const r = s.toBytes(), i = await H(r);
|
|
111
|
+
if (i.length) throw new z(i);
|
|
112
|
+
return r;
|
|
113
|
+
}
|
|
114
|
+
class z extends Error {
|
|
115
|
+
problems;
|
|
116
|
+
constructor(t) {
|
|
117
|
+
super(`PDF/X-4 check failed: ${t.join("; ")}`), this.problems = t;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function k(e) {
|
|
121
|
+
const t = /* @__PURE__ */ new Set();
|
|
122
|
+
for (const s of e.objectNumbers()) {
|
|
123
|
+
const o = e.get(s);
|
|
124
|
+
/\/Type\s*\/ExtGState/.test(o.dict) && t.add(s);
|
|
125
|
+
const n = /\/ExtGState\s*<<([^>]*)>>/.exec(o.dict)?.[1] ?? "";
|
|
126
|
+
for (const p of n.matchAll(/(\d+)\s+0\s+R/g)) t.add(parseInt(p[1], 10));
|
|
127
|
+
}
|
|
128
|
+
for (const s of e.objectNumbers()) {
|
|
129
|
+
const o = e.get(s);
|
|
130
|
+
if (t.has(s)) {
|
|
131
|
+
const n = [...o.dict.matchAll(/\/(?:ca|CA)\s+([\d.]+)/g)].some((l) => parseFloat(l[1]) < 1), p = /\/SMask\s*(?!\/None)[<\d]/.test(o.dict), m = /\/BM\s*\/(?!Normal\b|Compatible\b)\w+/.test(o.dict);
|
|
132
|
+
if (n || p || m) return !0;
|
|
133
|
+
}
|
|
134
|
+
if (/\/Subtype\s*\/Image/.test(o.dict) && /\/SMask\s+\d+\s+0\s+R/.test(o.dict)) return !0;
|
|
135
|
+
}
|
|
136
|
+
return !1;
|
|
137
|
+
}
|
|
138
|
+
function O(e) {
|
|
139
|
+
const t = /* @__PURE__ */ new Set();
|
|
140
|
+
for (const s of e.objectNumbers()) {
|
|
141
|
+
const o = /\/S\s*\/Luminosity[\s\S]*?\/G\s+(\d+)\s+0\s+R/.exec(e.get(s).dict);
|
|
142
|
+
o && t.add(parseInt(o[1], 10));
|
|
143
|
+
}
|
|
144
|
+
return t;
|
|
145
|
+
}
|
|
146
|
+
function L(e) {
|
|
147
|
+
const t = O(e);
|
|
148
|
+
for (const s of e.objectNumbers()) {
|
|
149
|
+
const o = e.get(s);
|
|
150
|
+
t.has(s) || !/\/Group\s*<<[^>]*\/CS\s*\/DeviceRGB/.test(o.dict) || e.set(s, o.dict.replace(/(\/Group\s*<<[^>]*\/CS\s*)\/DeviceRGB/, "$1/DeviceCMYK"), o.stream);
|
|
151
|
+
}
|
|
152
|
+
if (k(e))
|
|
153
|
+
for (const s of e.objectNumbers()) {
|
|
154
|
+
const o = e.get(s);
|
|
155
|
+
o.stream || !/\/Type\s*\/Page\b/.test(o.dict) || /\/Group\s*</.test(o.dict) || e.set(s, o.dict.replace(/>>\s*$/, `/Group << /Type /Group /S /Transparency /CS /DeviceCMYK >>
|
|
156
|
+
>>`));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function H(e) {
|
|
160
|
+
const t = [], s = B(e.subarray(0, 8)), o = /^%PDF-(\d\.\d)/.exec(s)?.[1];
|
|
161
|
+
(!o || parseFloat(o) > 1.6) && t.push(`PDF version ${o ?? "?"} (PDF/X-4 is at most 1.6)`);
|
|
162
|
+
let n;
|
|
163
|
+
try {
|
|
164
|
+
n = new A(e);
|
|
165
|
+
} catch (r) {
|
|
166
|
+
return [...t, `unreadable: ${r.message}`];
|
|
167
|
+
}
|
|
168
|
+
/\/Encrypt\b/.test(n.getTrailer()) && t.push("the file is encrypted"), /\/ID\s*\[/.test(n.getTrailer()) || t.push("no file /ID in the trailer");
|
|
169
|
+
const p = n.get(n.ref("Root") ?? -1)?.dict ?? "";
|
|
170
|
+
/\/OpenAction|\/AA\b/.test(p) && t.push("the catalog has document actions");
|
|
171
|
+
const m = /\/OutputIntents\s*\[\s*(\d+)\s+0\s+R/.exec(p)?.[1], l = m ? n.get(+m)?.dict ?? "" : "";
|
|
172
|
+
/\/S\s*\/GTS_PDFX/.test(l) || t.push("no GTS_PDFX output intent"), /\/OutputConditionIdentifier\s*[(<]/.test(l) || t.push("the output intent has no OutputConditionIdentifier");
|
|
173
|
+
const x = /\/DestOutputProfile\s+(\d+)\s+0\s+R/.exec(l)?.[1], D = x ? n.get(+x) : null;
|
|
174
|
+
(!D?.stream || !/\/N\s+4\b/.test(D.dict)) && t.push("the output intent has no embedded CMYK profile");
|
|
175
|
+
const $ = /\/Metadata\s+(\d+)\s+0\s+R/.exec(p)?.[1], P = $ ? new TextDecoder().decode(n.get(+$)?.stream ?? new Uint8Array()) : "";
|
|
176
|
+
/<pdfxid:GTS_PDFXVersion>PDF\/X-4<\/pdfxid:GTS_PDFXVersion>/.test(P) || t.push("XMP does not identify PDF/X-4");
|
|
177
|
+
const T = n.get(n.ref("Info") ?? -1)?.dict ?? "";
|
|
178
|
+
/\/Trapped\s*\/(True|False)/.test(T) || t.push("Info has no /Trapped True or False"), /\/Title\s*[(<]/.test(T) || t.push("Info has no /Title");
|
|
179
|
+
const I = /\/CreationDate\s*\(D:(\d{14})/.exec(T)?.[1], S = /<xmp:CreateDate>(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/.exec(P)?.slice(1).join("");
|
|
180
|
+
(!I || I !== S) && t.push("Info and XMP creation dates disagree"), /\/ModDate\s*\(D:/.test(T) || t.push("Info has no /ModDate");
|
|
181
|
+
const C = k(n), b = /* @__PURE__ */ new Set();
|
|
182
|
+
for (const r of n.objectNumbers()) {
|
|
183
|
+
const i = n.get(r);
|
|
184
|
+
if (i.stream || !/\/Type\s*\/Page\b/.test(i.dict)) continue;
|
|
185
|
+
const a = (f) => {
|
|
186
|
+
const d = new RegExp(`/${f}\\s*\\[\\s*([-\\d.]+)\\s+([-\\d.]+)\\s+([-\\d.]+)\\s+([-\\d.]+)`).exec(i.dict);
|
|
187
|
+
return d ? d.slice(1).map(Number) : null;
|
|
188
|
+
}, c = a("MediaBox"), u = a("TrimBox"), h = a("BleedBox"), g = (f, d) => f[0] >= d[0] - 1e-3 && f[1] >= d[1] - 1e-3 && f[2] <= d[2] + 1e-3 && f[3] <= d[3] + 1e-3;
|
|
189
|
+
c || t.push(`page ${r}: no MediaBox`), u || t.push(`page ${r}: no TrimBox`), c && u && !g(u, c) && t.push(`page ${r}: TrimBox outside the MediaBox`), h && c && u && !(g(u, h) && g(h, c)) && t.push(`page ${r}: BleedBox not between TrimBox and MediaBox`), C && !/\/Group\s*<<[^>]*\/S\s*\/Transparency[^>]*\/CS\s*\/DeviceCMYK/.test(i.dict) && t.push(`page ${r}: transparency without a CMYK page group`);
|
|
190
|
+
for (const f of (/\/Contents\s*(\[[^\]]*\]|\d+\s+0\s+R)/.exec(i.dict)?.[1] ?? "").matchAll(/(\d+)\s+0\s+R/g)) b.add(+f[1]);
|
|
191
|
+
}
|
|
192
|
+
const M = [], R = O(n);
|
|
193
|
+
for (const r of n.objectNumbers()) {
|
|
194
|
+
const i = n.get(r);
|
|
195
|
+
/\/Subtype\s*\/Form/.test(i.dict) && b.add(r), /\/DeviceRGB|\/CalRGB/.test(i.dict) && !R.has(r) && M.push(r);
|
|
196
|
+
}
|
|
197
|
+
M.length && t.push(`RGB colour space in object${M.length > 1 ? "s" : ""} ${M.join(", ")}`);
|
|
198
|
+
for (const r of b) {
|
|
199
|
+
const i = n.get(r);
|
|
200
|
+
if (!i?.stream) continue;
|
|
201
|
+
const a = B(await E(i.dict, i.stream));
|
|
202
|
+
/(^|\s)[\d.]+\s+[\d.]+\s+[\d.]+\s+(rg|RG)(?=\s)/.test(a) && t.push(`RGB colour operators in content stream ${r}`);
|
|
203
|
+
}
|
|
204
|
+
for (const r of n.objectNumbers()) {
|
|
205
|
+
const i = n.get(r);
|
|
206
|
+
if (/\/Type\s*\/Font\b/.test(i.dict) && /\/Subtype\s*\/(Type1|TrueType|MMType1|CIDFontType[02])\b/.test(i.dict)) {
|
|
207
|
+
const a = /\/FontDescriptor\s+(\d+)\s+0\s+R/.exec(i.dict)?.[1], c = a ? n.get(+a)?.dict ?? "" : "";
|
|
208
|
+
/\/FontFile[23]?\s+\d+\s+0\s+R/.test(c) || t.push(`font ${/\/BaseFont\s*\/([^\s/]+)/.exec(i.dict)?.[1] ?? r} is not embedded`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return t;
|
|
212
|
+
}
|
|
213
|
+
export {
|
|
214
|
+
z as PdfXError,
|
|
215
|
+
W as applyPdfX4,
|
|
216
|
+
_ as pdfAndXmpDates,
|
|
217
|
+
w as pdfString,
|
|
218
|
+
H as verifyPdfX4,
|
|
219
|
+
K as xmpPacket
|
|
220
|
+
};
|