@nice2dev/ui-diagrams 1.4.14 → 1.4.15
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/CHANGELOG.md +36 -0
- package/dist/components/DiagramCanvas.d.ts +5 -0
- package/dist/components/DiagramToolbar.d.ts +1 -1
- package/dist/components/NiceDiagramEditor.d.ts +14 -2
- package/dist/core/edgeGeometry.d.ts +23 -0
- package/dist/core/exportEngine.d.ts +62 -2
- package/dist/core/pdfWriter.d.ts +19 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +4463 -4237
- package/dist/pdfWriter-BCufjDS6.js +333 -0
- package/dist/pdfWriter-Bc_razGc.cjs +24 -0
- package/package.json +2 -2
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
const G = [
|
|
2
|
+
278,
|
|
3
|
+
278,
|
|
4
|
+
355,
|
|
5
|
+
556,
|
|
6
|
+
556,
|
|
7
|
+
889,
|
|
8
|
+
667,
|
|
9
|
+
191,
|
|
10
|
+
333,
|
|
11
|
+
333,
|
|
12
|
+
389,
|
|
13
|
+
584,
|
|
14
|
+
278,
|
|
15
|
+
333,
|
|
16
|
+
278,
|
|
17
|
+
278,
|
|
18
|
+
556,
|
|
19
|
+
556,
|
|
20
|
+
556,
|
|
21
|
+
556,
|
|
22
|
+
556,
|
|
23
|
+
556,
|
|
24
|
+
556,
|
|
25
|
+
556,
|
|
26
|
+
556,
|
|
27
|
+
556,
|
|
28
|
+
278,
|
|
29
|
+
278,
|
|
30
|
+
584,
|
|
31
|
+
584,
|
|
32
|
+
584,
|
|
33
|
+
556,
|
|
34
|
+
1015,
|
|
35
|
+
667,
|
|
36
|
+
667,
|
|
37
|
+
722,
|
|
38
|
+
722,
|
|
39
|
+
667,
|
|
40
|
+
611,
|
|
41
|
+
778,
|
|
42
|
+
722,
|
|
43
|
+
278,
|
|
44
|
+
500,
|
|
45
|
+
667,
|
|
46
|
+
556,
|
|
47
|
+
833,
|
|
48
|
+
722,
|
|
49
|
+
778,
|
|
50
|
+
667,
|
|
51
|
+
778,
|
|
52
|
+
722,
|
|
53
|
+
667,
|
|
54
|
+
611,
|
|
55
|
+
722,
|
|
56
|
+
667,
|
|
57
|
+
944,
|
|
58
|
+
667,
|
|
59
|
+
667,
|
|
60
|
+
611,
|
|
61
|
+
278,
|
|
62
|
+
278,
|
|
63
|
+
278,
|
|
64
|
+
469,
|
|
65
|
+
556,
|
|
66
|
+
333,
|
|
67
|
+
556,
|
|
68
|
+
556,
|
|
69
|
+
500,
|
|
70
|
+
556,
|
|
71
|
+
556,
|
|
72
|
+
278,
|
|
73
|
+
556,
|
|
74
|
+
556,
|
|
75
|
+
222,
|
|
76
|
+
222,
|
|
77
|
+
500,
|
|
78
|
+
222,
|
|
79
|
+
833,
|
|
80
|
+
556,
|
|
81
|
+
556,
|
|
82
|
+
556,
|
|
83
|
+
556,
|
|
84
|
+
333,
|
|
85
|
+
500,
|
|
86
|
+
278,
|
|
87
|
+
556,
|
|
88
|
+
500,
|
|
89
|
+
722,
|
|
90
|
+
500,
|
|
91
|
+
500,
|
|
92
|
+
500,
|
|
93
|
+
334,
|
|
94
|
+
260,
|
|
95
|
+
334,
|
|
96
|
+
584
|
|
97
|
+
], z = {
|
|
98
|
+
ą: ["aogonek", "a"],
|
|
99
|
+
Ą: ["Aogonek", "A"],
|
|
100
|
+
ć: ["cacute", "c"],
|
|
101
|
+
Ć: ["Cacute", "C"],
|
|
102
|
+
ę: ["eogonek", "e"],
|
|
103
|
+
Ę: ["Eogonek", "E"],
|
|
104
|
+
ł: ["lslash", "l"],
|
|
105
|
+
Ł: ["Lslash", "L"],
|
|
106
|
+
ń: ["nacute", "n"],
|
|
107
|
+
Ń: ["Nacute", "N"],
|
|
108
|
+
ó: ["oacute", "o"],
|
|
109
|
+
Ó: ["Oacute", "O"],
|
|
110
|
+
ś: ["sacute", "s"],
|
|
111
|
+
Ś: ["Sacute", "S"],
|
|
112
|
+
ź: ["zacute", "z"],
|
|
113
|
+
Ź: ["Zacute", "Z"],
|
|
114
|
+
ż: ["zdotaccent", "z"],
|
|
115
|
+
Ż: ["Zdotaccent", "Z"],
|
|
116
|
+
č: ["ccaron", "c"],
|
|
117
|
+
Č: ["Ccaron", "C"],
|
|
118
|
+
ď: ["dcaron", "d"],
|
|
119
|
+
Ď: ["Dcaron", "D"],
|
|
120
|
+
ě: ["ecaron", "e"],
|
|
121
|
+
Ě: ["Ecaron", "E"],
|
|
122
|
+
ň: ["ncaron", "n"],
|
|
123
|
+
Ň: ["Ncaron", "N"],
|
|
124
|
+
ř: ["rcaron", "r"],
|
|
125
|
+
Ř: ["Rcaron", "R"],
|
|
126
|
+
š: ["scaron", "s"],
|
|
127
|
+
Š: ["Scaron", "S"],
|
|
128
|
+
ť: ["tcaron", "t"],
|
|
129
|
+
Ť: ["Tcaron", "T"],
|
|
130
|
+
ů: ["uring", "u"],
|
|
131
|
+
Ů: ["Uring", "U"],
|
|
132
|
+
ž: ["zcaron", "z"],
|
|
133
|
+
Ž: ["Zcaron", "Z"],
|
|
134
|
+
ő: ["ohungarumlaut", "o"],
|
|
135
|
+
ű: ["uhungarumlaut", "u"],
|
|
136
|
+
à: ["agrave", "a"],
|
|
137
|
+
á: ["aacute", "a"],
|
|
138
|
+
â: ["acircumflex", "a"],
|
|
139
|
+
ã: ["atilde", "a"],
|
|
140
|
+
ä: ["adieresis", "a"],
|
|
141
|
+
å: ["aring", "a"],
|
|
142
|
+
æ: ["ae", "m"],
|
|
143
|
+
ç: ["ccedilla", "c"],
|
|
144
|
+
è: ["egrave", "e"],
|
|
145
|
+
é: ["eacute", "e"],
|
|
146
|
+
ê: ["ecircumflex", "e"],
|
|
147
|
+
ë: ["edieresis", "e"],
|
|
148
|
+
ì: ["igrave", "i"],
|
|
149
|
+
í: ["iacute", "i"],
|
|
150
|
+
î: ["icircumflex", "i"],
|
|
151
|
+
ï: ["idieresis", "i"],
|
|
152
|
+
ñ: ["ntilde", "n"],
|
|
153
|
+
ò: ["ograve", "o"],
|
|
154
|
+
ô: ["ocircumflex", "o"],
|
|
155
|
+
õ: ["otilde", "o"],
|
|
156
|
+
ö: ["odieresis", "o"],
|
|
157
|
+
ø: ["oslash", "o"],
|
|
158
|
+
ù: ["ugrave", "u"],
|
|
159
|
+
ú: ["uacute", "u"],
|
|
160
|
+
û: ["ucircumflex", "u"],
|
|
161
|
+
ü: ["udieresis", "u"],
|
|
162
|
+
ý: ["yacute", "y"],
|
|
163
|
+
ÿ: ["ydieresis", "y"],
|
|
164
|
+
ß: ["germandbls", "b"],
|
|
165
|
+
À: ["Agrave", "A"],
|
|
166
|
+
Á: ["Aacute", "A"],
|
|
167
|
+
Â: ["Acircumflex", "A"],
|
|
168
|
+
Ä: ["Adieresis", "A"],
|
|
169
|
+
Å: ["Aring", "A"],
|
|
170
|
+
Ç: ["Ccedilla", "C"],
|
|
171
|
+
È: ["Egrave", "E"],
|
|
172
|
+
É: ["Eacute", "E"],
|
|
173
|
+
Ê: ["Ecircumflex", "E"],
|
|
174
|
+
Í: ["Iacute", "I"],
|
|
175
|
+
Ñ: ["Ntilde", "N"],
|
|
176
|
+
Ö: ["Odieresis", "O"],
|
|
177
|
+
Ø: ["Oslash", "O"],
|
|
178
|
+
Ú: ["Uacute", "U"],
|
|
179
|
+
Ü: ["Udieresis", "U"],
|
|
180
|
+
"–": ["endash", "n"],
|
|
181
|
+
"—": ["emdash", "M"],
|
|
182
|
+
"‘": ["quoteleft", "'"],
|
|
183
|
+
"’": ["quoteright", "'"],
|
|
184
|
+
"“": ["quotedblleft", '"'],
|
|
185
|
+
"”": ["quotedblright", '"'],
|
|
186
|
+
"„": ["quotedblbase", '"'],
|
|
187
|
+
"…": ["ellipsis", "M"],
|
|
188
|
+
"•": ["bullet", "o"],
|
|
189
|
+
"€": ["Euro", "C"],
|
|
190
|
+
"°": ["degree", "o"],
|
|
191
|
+
"«": ["guillemotleft", "n"],
|
|
192
|
+
"»": ["guillemotright", "n"],
|
|
193
|
+
"·": ["periodcentered", "."],
|
|
194
|
+
"×": ["multiply", "+"],
|
|
195
|
+
"§": ["section", "s"]
|
|
196
|
+
}, Q = {
|
|
197
|
+
white: [1, 1, 1],
|
|
198
|
+
black: [0, 0, 0],
|
|
199
|
+
red: [1, 0, 0],
|
|
200
|
+
green: [0, 0.5, 0],
|
|
201
|
+
blue: [0, 0, 1],
|
|
202
|
+
gray: [0.5, 0.5, 0.5],
|
|
203
|
+
grey: [0.5, 0.5, 0.5]
|
|
204
|
+
};
|
|
205
|
+
function S(o, u) {
|
|
206
|
+
if (!o)
|
|
207
|
+
return u;
|
|
208
|
+
const $ = o.trim(), i = /^var\([^,]+,\s*(.+)\)$/.exec($);
|
|
209
|
+
if (i)
|
|
210
|
+
return S(i[1], u);
|
|
211
|
+
if ($ === "transparent" || $ === "none")
|
|
212
|
+
return null;
|
|
213
|
+
const c = /^#([0-9a-f]{3,8})$/i.exec($);
|
|
214
|
+
if (c) {
|
|
215
|
+
const x = c[1].length <= 4 ? [...c[1]].map((l) => l + l).join("") : c[1];
|
|
216
|
+
return [0, 2, 4].map((l) => parseInt(x.slice(l, l + 2), 16) / 255);
|
|
217
|
+
}
|
|
218
|
+
const d = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec($);
|
|
219
|
+
return d ? [1, 2, 3].map((x) => Math.min(1, Number(d[x]) / 255)) : Q[$.toLowerCase()] ?? u;
|
|
220
|
+
}
|
|
221
|
+
const t = (o) => String(+o.toFixed(3)), C = (o) => o.map(t).join(" "), k = {
|
|
222
|
+
A4: [595.28, 841.89],
|
|
223
|
+
A3: [841.89, 1190.55],
|
|
224
|
+
Letter: [612, 792]
|
|
225
|
+
};
|
|
226
|
+
function V(o, u, $) {
|
|
227
|
+
if (typeof document > "u")
|
|
228
|
+
return null;
|
|
229
|
+
try {
|
|
230
|
+
const i = document.createElement("canvas"), c = i.getContext("2d");
|
|
231
|
+
if (!c)
|
|
232
|
+
return null;
|
|
233
|
+
const d = u * 3;
|
|
234
|
+
c.font = `${d}px sans-serif`;
|
|
235
|
+
const x = Math.ceil(c.measureText(o).width) + 4;
|
|
236
|
+
i.width = x, i.height = Math.ceil(d * 1.4), c.fillStyle = "white", c.fillRect(0, 0, i.width, i.height), c.font = `${d}px sans-serif`, c.fillStyle = `rgb(${$.map((b) => Math.round(b * 255)).join(",")})`, c.textBaseline = "middle", c.fillText(o, 2, i.height / 2);
|
|
237
|
+
const l = i.toDataURL("image/jpeg", 0.92), y = l.slice(l.indexOf(",") + 1);
|
|
238
|
+
return { bytes: atob(y), width: i.width, height: i.height };
|
|
239
|
+
} catch {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function X(o, u, $) {
|
|
244
|
+
var O;
|
|
245
|
+
const i = u.margin ?? 28;
|
|
246
|
+
let [c, d] = k[u.pageSize ?? "A4"] ?? k.A4;
|
|
247
|
+
(u.orientation === "landscape" || u.orientation !== "portrait" && o.width > o.height) && ([c, d] = [d, c]);
|
|
248
|
+
const l = c - i * 2, y = d - i * 2, b = u.layout === "tiles", E = b ? 0.75 : Math.min(0.75, l / o.width, y / o.height), L = b ? Math.max(1, Math.ceil(o.width * E / l)) : 1, N = b ? Math.max(1, Math.ceil(o.height * E / y)) : 1, p = /* @__PURE__ */ new Map(), F = (e) => {
|
|
249
|
+
let n = "", h = 0, r = !0;
|
|
250
|
+
for (const a of e) {
|
|
251
|
+
const f = a.codePointAt(0) ?? 63;
|
|
252
|
+
let s, A = a;
|
|
253
|
+
f >= 32 && f <= 126 ? s = f : z[a] && (p.has(a) || p.size < 128) ? (p.has(a) || p.set(a, 128 + p.size), s = p.get(a), A = z[a][1]) : (r = !1, s = 63, A = "?"), n += s.toString(16).padStart(2, "0"), h += G[(A.codePointAt(0) ?? 63) - 32] ?? 556;
|
|
254
|
+
}
|
|
255
|
+
return { hex: n, width: h, ok: r };
|
|
256
|
+
}, w = [], j = [], M = S(o.background, null);
|
|
257
|
+
M && j.push(`${C(M)} rg 0 0 ${t(o.width)} ${t(o.height)} re f`);
|
|
258
|
+
for (const e of o.items)
|
|
259
|
+
if (e.kind === "path") {
|
|
260
|
+
const n = S(e.fill, null), h = S(e.stroke, null);
|
|
261
|
+
if (!n && !h)
|
|
262
|
+
continue;
|
|
263
|
+
const r = [];
|
|
264
|
+
for (const [f, s] of $(e.d))
|
|
265
|
+
f === "M" ? r.push(`${t(s[0])} ${t(s[1])} m`) : f === "L" ? r.push(`${t(s[0])} ${t(s[1])} l`) : f === "C" ? r.push(s.slice(0, 6).map(t).join(" ") + " c") : r.push("h");
|
|
266
|
+
const a = [];
|
|
267
|
+
n && a.push(`${C(n)} rg`), h && (a.push(`${C(h)} RG ${t(e.strokeWidth ?? 1)} w`), a.push((O = e.dash) != null && O.length ? `[${e.dash.map(t).join(" ")}] 0 d` : "[] 0 d")), j.push(`${a.join(" ")} ${r.join(" ")} ${n && h ? "B" : n ? "f" : "S"}`);
|
|
268
|
+
} else {
|
|
269
|
+
const n = S(e.color, [0.2, 0.2, 0.2]) ?? [0.2, 0.2, 0.2], h = F(e.text), r = h.ok ? null : V(e.text, e.size, n);
|
|
270
|
+
if (r) {
|
|
271
|
+
const s = e.size * 1.4, A = r.width / r.height * s, H = e.anchor === "middle" ? e.x - A / 2 : e.x, W = e.y - e.size * 0.35 - s / 2;
|
|
272
|
+
w.push(r), j.push(`q ${t(A)} 0 0 ${t(-s)} ${t(H)} ${t(W + s)} cm /Im${w.length} Do Q`);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const a = h.width * e.size / 1e3, f = e.anchor === "middle" ? e.x - a / 2 : e.x;
|
|
276
|
+
j.push(
|
|
277
|
+
`BT /F1 ${t(e.size)} Tf ${C(n)} rg 1 0 0 -1 ${t(f)} ${t(e.y)} Tm <${h.hex}> Tj ET`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const B = j.join(`
|
|
281
|
+
`), g = [], v = [...p.entries()].sort((e, n) => e[1] - n[1]).map(([e, n]) => `${n} /${z[e][0]}`).join(" ");
|
|
282
|
+
g[2] = "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding << /Type /Encoding /BaseEncoding /WinAnsiEncoding" + (v ? ` /Differences [${v}]` : "") + " >> >>";
|
|
283
|
+
const T = 3;
|
|
284
|
+
w.forEach((e, n) => {
|
|
285
|
+
g[T + n] = `<< /Type /XObject /Subtype /Image /Width ${e.width} /Height ${e.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${e.bytes.length} >>
|
|
286
|
+
stream
|
|
287
|
+
${e.bytes}
|
|
288
|
+
endstream`;
|
|
289
|
+
});
|
|
290
|
+
const U = w.length ? ` /XObject << ${w.map((e, n) => `/Im${n + 1} ${T + n + 1} 0 R`).join(" ")} >>` : "", R = [];
|
|
291
|
+
let P = T + w.length;
|
|
292
|
+
for (let e = 0; e < N; e++)
|
|
293
|
+
for (let n = 0; n < L; n++) {
|
|
294
|
+
const h = P++, r = P++, a = b ? i - n * l : i + (l - o.width * E) / 2, f = i - e * y, s = `q ${t(i)} ${t(i)} ${t(l)} ${t(y)} re W n 1 0 0 -1 0 ${t(d)} cm ${t(E)} 0 0 ${t(E)} ${t(a)} ${t(f)} cm
|
|
295
|
+
${B}
|
|
296
|
+
Q`;
|
|
297
|
+
g[h] = `<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${t(c)} ${t(d)}] /Resources << /Font << /F1 3 0 R >>${U} >> /Contents ${r + 1} 0 R >>`, g[r] = `<< /Length ${s.length} >>
|
|
298
|
+
stream
|
|
299
|
+
${s}
|
|
300
|
+
endstream`, R.push(`${h + 1} 0 R`);
|
|
301
|
+
}
|
|
302
|
+
g[0] = "<< /Type /Catalog /Pages 2 0 R >>", g[1] = `<< /Type /Pages /Kids [${R.join(" ")}] /Count ${R.length} >>`;
|
|
303
|
+
const q = u.title ? `<< /Title <${[...new TextEncoder().encode(u.title)].map((e) => e.toString(16).padStart(2, "0")).join("")}> /Producer (Nice2Dev diagrams) >>` : "<< /Producer (Nice2Dev diagrams) >>";
|
|
304
|
+
g.push(q);
|
|
305
|
+
let m = `%PDF-1.4
|
|
306
|
+
%âãÏÓ
|
|
307
|
+
`;
|
|
308
|
+
const D = [];
|
|
309
|
+
g.forEach((e, n) => {
|
|
310
|
+
D[n] = m.length, m += `${n + 1} 0 obj
|
|
311
|
+
${e}
|
|
312
|
+
endobj
|
|
313
|
+
`;
|
|
314
|
+
});
|
|
315
|
+
const Z = m.length;
|
|
316
|
+
m += `xref
|
|
317
|
+
0 ${g.length + 1}
|
|
318
|
+
0000000000 65535 f
|
|
319
|
+
`, m += D.map((e) => `${String(e).padStart(10, "0")} 00000 n
|
|
320
|
+
`).join(""), m += `trailer
|
|
321
|
+
<< /Size ${g.length + 1} /Root 1 0 R /Info ${g.length} 0 R >>
|
|
322
|
+
startxref
|
|
323
|
+
${Z}
|
|
324
|
+
%%EOF
|
|
325
|
+
`;
|
|
326
|
+
const I = new Uint8Array(m.length);
|
|
327
|
+
for (let e = 0; e < m.length; e++)
|
|
328
|
+
I[e] = m.charCodeAt(e) & 255;
|
|
329
|
+
return I;
|
|
330
|
+
}
|
|
331
|
+
export {
|
|
332
|
+
X as writeDiagramPdf
|
|
333
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],M={ą:["aogonek","a"],Ą:["Aogonek","A"],ć:["cacute","c"],Ć:["Cacute","C"],ę:["eogonek","e"],Ę:["Eogonek","E"],ł:["lslash","l"],Ł:["Lslash","L"],ń:["nacute","n"],Ń:["Nacute","N"],ó:["oacute","o"],Ó:["Oacute","O"],ś:["sacute","s"],Ś:["Sacute","S"],ź:["zacute","z"],Ź:["Zacute","Z"],ż:["zdotaccent","z"],Ż:["Zdotaccent","Z"],č:["ccaron","c"],Č:["Ccaron","C"],ď:["dcaron","d"],Ď:["Dcaron","D"],ě:["ecaron","e"],Ě:["Ecaron","E"],ň:["ncaron","n"],Ň:["Ncaron","N"],ř:["rcaron","r"],Ř:["Rcaron","R"],š:["scaron","s"],Š:["Scaron","S"],ť:["tcaron","t"],Ť:["Tcaron","T"],ů:["uring","u"],Ů:["Uring","U"],ž:["zcaron","z"],Ž:["Zcaron","Z"],ő:["ohungarumlaut","o"],ű:["uhungarumlaut","u"],à:["agrave","a"],á:["aacute","a"],â:["acircumflex","a"],ã:["atilde","a"],ä:["adieresis","a"],å:["aring","a"],æ:["ae","m"],ç:["ccedilla","c"],è:["egrave","e"],é:["eacute","e"],ê:["ecircumflex","e"],ë:["edieresis","e"],ì:["igrave","i"],í:["iacute","i"],î:["icircumflex","i"],ï:["idieresis","i"],ñ:["ntilde","n"],ò:["ograve","o"],ô:["ocircumflex","o"],õ:["otilde","o"],ö:["odieresis","o"],ø:["oslash","o"],ù:["ugrave","u"],ú:["uacute","u"],û:["ucircumflex","u"],ü:["udieresis","u"],ý:["yacute","y"],ÿ:["ydieresis","y"],ß:["germandbls","b"],À:["Agrave","A"],Á:["Aacute","A"],Â:["Acircumflex","A"],Ä:["Adieresis","A"],Å:["Aring","A"],Ç:["Ccedilla","C"],È:["Egrave","E"],É:["Eacute","E"],Ê:["Ecircumflex","E"],Í:["Iacute","I"],Ñ:["Ntilde","N"],Ö:["Odieresis","O"],Ø:["Oslash","O"],Ú:["Uacute","U"],Ü:["Udieresis","U"],"–":["endash","n"],"—":["emdash","M"],"‘":["quoteleft","'"],"’":["quoteright","'"],"“":["quotedblleft",'"'],"”":["quotedblright",'"'],"„":["quotedblbase",'"'],"…":["ellipsis","M"],"•":["bullet","o"],"€":["Euro","C"],"°":["degree","o"],"«":["guillemotleft","n"],"»":["guillemotright","n"],"·":["periodcentered","."],"×":["multiply","+"],"§":["section","s"]},Q={white:[1,1,1],black:[0,0,0],red:[1,0,0],green:[0,.5,0],blue:[0,0,1],gray:[.5,.5,.5],grey:[.5,.5,.5]};function S(o,h){if(!o)return h;const $=o.trim(),i=/^var\([^,]+,\s*(.+)\)$/.exec($);if(i)return S(i[1],h);if($==="transparent"||$==="none")return null;const c=/^#([0-9a-f]{3,8})$/i.exec($);if(c){const x=c[1].length<=4?[...c[1]].map(l=>l+l).join(""):c[1];return[0,2,4].map(l=>parseInt(x.slice(l,l+2),16)/255)}const d=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec($);return d?[1,2,3].map(x=>Math.min(1,Number(d[x])/255)):Q[$.toLowerCase()]??h}const t=o=>String(+o.toFixed(3)),T=o=>o.map(t).join(" "),k={A4:[595.28,841.89],A3:[841.89,1190.55],Letter:[612,792]};function V(o,h,$){if(typeof document>"u")return null;try{const i=document.createElement("canvas"),c=i.getContext("2d");if(!c)return null;const d=h*3;c.font=`${d}px sans-serif`;const x=Math.ceil(c.measureText(o).width)+4;i.width=x,i.height=Math.ceil(d*1.4),c.fillStyle="white",c.fillRect(0,0,i.width,i.height),c.font=`${d}px sans-serif`,c.fillStyle=`rgb(${$.map(b=>Math.round(b*255)).join(",")})`,c.textBaseline="middle",c.fillText(o,2,i.height/2);const l=i.toDataURL("image/jpeg",.92),y=l.slice(l.indexOf(",")+1);return{bytes:atob(y),width:i.width,height:i.height}}catch{return null}}function X(o,h,$){var I;const i=h.margin??28;let[c,d]=k[h.pageSize??"A4"]??k.A4;(h.orientation==="landscape"||h.orientation!=="portrait"&&o.width>o.height)&&([c,d]=[d,c]);const l=c-i*2,y=d-i*2,b=h.layout==="tiles",E=b?.75:Math.min(.75,l/o.width,y/o.height),L=b?Math.max(1,Math.ceil(o.width*E/l)):1,N=b?Math.max(1,Math.ceil(o.height*E/y)):1,p=new Map,F=e=>{let n="",u=0,r=!0;for(const a of e){const f=a.codePointAt(0)??63;let s,A=a;f>=32&&f<=126?s=f:M[a]&&(p.has(a)||p.size<128)?(p.has(a)||p.set(a,128+p.size),s=p.get(a),A=M[a][1]):(r=!1,s=63,A="?"),n+=s.toString(16).padStart(2,"0"),u+=G[(A.codePointAt(0)??63)-32]??556}return{hex:n,width:u,ok:r}},w=[],j=[],P=S(o.background,null);P&&j.push(`${T(P)} rg 0 0 ${t(o.width)} ${t(o.height)} re f`);for(const e of o.items)if(e.kind==="path"){const n=S(e.fill,null),u=S(e.stroke,null);if(!n&&!u)continue;const r=[];for(const[f,s]of $(e.d))f==="M"?r.push(`${t(s[0])} ${t(s[1])} m`):f==="L"?r.push(`${t(s[0])} ${t(s[1])} l`):f==="C"?r.push(s.slice(0,6).map(t).join(" ")+" c"):r.push("h");const a=[];n&&a.push(`${T(n)} rg`),u&&(a.push(`${T(u)} RG ${t(e.strokeWidth??1)} w`),a.push((I=e.dash)!=null&&I.length?`[${e.dash.map(t).join(" ")}] 0 d`:"[] 0 d")),j.push(`${a.join(" ")} ${r.join(" ")} ${n&&u?"B":n?"f":"S"}`)}else{const n=S(e.color,[.2,.2,.2])??[.2,.2,.2],u=F(e.text),r=u.ok?null:V(e.text,e.size,n);if(r){const s=e.size*1.4,A=r.width/r.height*s,H=e.anchor==="middle"?e.x-A/2:e.x,W=e.y-e.size*.35-s/2;w.push(r),j.push(`q ${t(A)} 0 0 ${t(-s)} ${t(H)} ${t(W+s)} cm /Im${w.length} Do Q`);continue}const a=u.width*e.size/1e3,f=e.anchor==="middle"?e.x-a/2:e.x;j.push(`BT /F1 ${t(e.size)} Tf ${T(n)} rg 1 0 0 -1 ${t(f)} ${t(e.y)} Tm <${u.hex}> Tj ET`)}const B=j.join(`
|
|
2
|
+
`),g=[],v=[...p.entries()].sort((e,n)=>e[1]-n[1]).map(([e,n])=>`${n} /${M[e][0]}`).join(" ");g[2]="<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding << /Type /Encoding /BaseEncoding /WinAnsiEncoding"+(v?` /Differences [${v}]`:"")+" >> >>";const C=3;w.forEach((e,n)=>{g[C+n]=`<< /Type /XObject /Subtype /Image /Width ${e.width} /Height ${e.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${e.bytes.length} >>
|
|
3
|
+
stream
|
|
4
|
+
${e.bytes}
|
|
5
|
+
endstream`});const U=w.length?` /XObject << ${w.map((e,n)=>`/Im${n+1} ${C+n+1} 0 R`).join(" ")} >>`:"",R=[];let z=C+w.length;for(let e=0;e<N;e++)for(let n=0;n<L;n++){const u=z++,r=z++,a=b?i-n*l:i+(l-o.width*E)/2,f=i-e*y,s=`q ${t(i)} ${t(i)} ${t(l)} ${t(y)} re W n 1 0 0 -1 0 ${t(d)} cm ${t(E)} 0 0 ${t(E)} ${t(a)} ${t(f)} cm
|
|
6
|
+
${B}
|
|
7
|
+
Q`;g[u]=`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${t(c)} ${t(d)}] /Resources << /Font << /F1 3 0 R >>${U} >> /Contents ${r+1} 0 R >>`,g[r]=`<< /Length ${s.length} >>
|
|
8
|
+
stream
|
|
9
|
+
${s}
|
|
10
|
+
endstream`,R.push(`${u+1} 0 R`)}g[0]="<< /Type /Catalog /Pages 2 0 R >>",g[1]=`<< /Type /Pages /Kids [${R.join(" ")}] /Count ${R.length} >>`;const q=h.title?`<< /Title <${[...new TextEncoder().encode(h.title)].map(e=>e.toString(16).padStart(2,"0")).join("")}> /Producer (Nice2Dev diagrams) >>`:"<< /Producer (Nice2Dev diagrams) >>";g.push(q);let m=`%PDF-1.4
|
|
11
|
+
%âãÏÓ
|
|
12
|
+
`;const D=[];g.forEach((e,n)=>{D[n]=m.length,m+=`${n+1} 0 obj
|
|
13
|
+
${e}
|
|
14
|
+
endobj
|
|
15
|
+
`});const Z=m.length;m+=`xref
|
|
16
|
+
0 ${g.length+1}
|
|
17
|
+
0000000000 65535 f
|
|
18
|
+
`,m+=D.map(e=>`${String(e).padStart(10,"0")} 00000 n
|
|
19
|
+
`).join(""),m+=`trailer
|
|
20
|
+
<< /Size ${g.length+1} /Root 1 0 R /Info ${g.length} 0 R >>
|
|
21
|
+
startxref
|
|
22
|
+
${Z}
|
|
23
|
+
%%EOF
|
|
24
|
+
`;const O=new Uint8Array(m.length);for(let e=0;e<m.length;e++)O[e]=m.charCodeAt(e)&255;return O}exports.writeDiagramPdf=X;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice2dev/ui-diagrams",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.15",
|
|
4
4
|
"description": "Nice2Dev Diagram Editor & Viewer — flowcharts, org charts, BPMN, ER diagrams with animations, data binding, and custom .ndd.json format",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"react-dom": ">=17.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@nice2dev/ui": "^1.4.
|
|
43
|
+
"@nice2dev/ui": "^1.4.15",
|
|
44
44
|
"@testing-library/jest-dom": "^7.0.1",
|
|
45
45
|
"@testing-library/react": "^16.3.3",
|
|
46
46
|
"@types/react": "^19.2.18",
|