@evotecit/officeimo 0.1.19 → 0.1.43
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 +44 -10
- package/bundles/officeimo-canopyx-adapter.js +147 -65
- package/bundles/officeimo-canopyx-adapter.min.js +1 -1
- package/bundles/officeimo-canopyx-adapter.min.mjs +1 -1
- package/bundles/officeimo-canopyx-adapter.mjs +134 -53
- package/bundles/officeimo-canopyx.js +554 -234
- package/bundles/officeimo-canopyx.min.js +1 -1
- package/bundles/officeimo-canopyx.min.mjs +1 -1
- package/bundles/officeimo-canopyx.mjs +477 -158
- package/bundles/officeimo-chartforgex-adapter.js +1924 -0
- package/bundles/officeimo-chartforgex-adapter.min.js +2 -0
- package/bundles/officeimo-chartforgex-adapter.min.mjs +2 -0
- package/bundles/officeimo-chartforgex-adapter.mjs +1910 -0
- package/bundles/officeimo-chartforgex.js +13594 -0
- package/bundles/officeimo-chartforgex.min.js +2 -0
- package/bundles/officeimo-chartforgex.min.mjs +2 -0
- package/bundles/officeimo-chartforgex.mjs +13487 -0
- package/bundles/officeimo-csv.js +12 -7
- package/bundles/officeimo-csv.min.js +1 -1
- package/bundles/officeimo-csv.min.mjs +1 -1
- package/bundles/officeimo-csv.mjs +8 -3
- package/bundles/officeimo-datatables-adapter.js +11 -11
- package/bundles/officeimo-datatables-adapter.min.js +1 -1
- package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
- package/bundles/officeimo-datatables-adapter.mjs +7 -7
- package/bundles/officeimo-datatables.js +418 -180
- package/bundles/officeimo-datatables.min.js +1 -1
- package/bundles/officeimo-datatables.min.mjs +1 -1
- package/bundles/officeimo-datatables.mjs +350 -112
- package/bundles/officeimo-execution.js +14 -9
- package/bundles/officeimo-execution.min.js +1 -1
- package/bundles/officeimo-execution.min.mjs +1 -1
- package/bundles/officeimo-execution.mjs +8 -3
- package/bundles/officeimo-pdf.js +286 -120
- package/bundles/officeimo-pdf.min.js +1 -1
- package/bundles/officeimo-pdf.min.mjs +1 -1
- package/bundles/officeimo-pdf.mjs +244 -78
- package/bundles/officeimo-xlsx.js +136 -59
- package/bundles/officeimo-xlsx.min.js +1 -1
- package/bundles/officeimo-xlsx.min.mjs +1 -1
- package/bundles/officeimo-xlsx.mjs +114 -37
- package/bundles/officeimo.js +416 -178
- package/bundles/officeimo.min.js +1 -1
- package/bundles/officeimo.min.mjs +1 -1
- package/bundles/officeimo.mjs +351 -113
- package/dist/core/progress.js +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/integrations/canopyx/index.js +13 -4
- package/dist/integrations/canopyx/pdf-number.js +9 -6
- package/dist/integrations/canopyx/rule-predicates.d.ts +1 -1
- package/dist/integrations/canopyx/rule-predicates.js +2 -1
- package/dist/integrations/canopyx/rules.d.ts +1 -1
- package/dist/integrations/canopyx/rules.js +11 -13
- package/dist/integrations/canopyx/source.js +57 -7
- package/dist/integrations/canopyx/tones.d.ts +10 -0
- package/dist/integrations/canopyx/tones.js +12 -0
- package/dist/integrations/canopyx/types.d.ts +8 -1
- package/dist/integrations/chartforgex/capture.d.ts +31 -0
- package/dist/integrations/chartforgex/capture.js +103 -0
- package/dist/integrations/chartforgex/index.d.ts +13 -0
- package/dist/integrations/chartforgex/index.js +88 -0
- package/dist/integrations/chartforgex/svg-drawing.d.ts +5 -0
- package/dist/integrations/chartforgex/svg-drawing.js +775 -0
- package/dist/integrations/chartforgex/svg-geometry.d.ts +23 -0
- package/dist/integrations/chartforgex/svg-geometry.js +304 -0
- package/dist/integrations/chartforgex/svg-image.d.ts +9 -0
- package/dist/integrations/chartforgex/svg-image.js +46 -0
- package/dist/integrations/chartforgex/svg-markup.d.ts +10 -0
- package/dist/integrations/chartforgex/svg-markup.js +124 -0
- package/dist/integrations/chartforgex/svg-paint.d.ts +16 -0
- package/dist/integrations/chartforgex/svg-paint.js +146 -0
- package/dist/integrations/chartforgex/types.d.ts +77 -0
- package/dist/integrations/chartforgex/types.js +1 -0
- package/dist/integrations/chartforgex/winansi.d.ts +4 -0
- package/dist/integrations/chartforgex/winansi.js +48 -0
- package/dist/integrations/chartforgex/workbook.d.ts +12 -0
- package/dist/integrations/chartforgex/workbook.js +137 -0
- package/dist/pdf/document-drawings.d.ts +1 -1
- package/dist/pdf/document-drawings.js +91 -17
- package/dist/pdf/document-images.d.ts +7 -1
- package/dist/pdf/document-images.js +59 -24
- package/dist/pdf/document-types.d.ts +3 -1
- package/dist/pdf/document.d.ts +2 -2
- package/dist/pdf/document.js +3 -1
- package/dist/pdf/drawing-types.d.ts +37 -10
- package/dist/pdf/font-resources.d.ts +1 -1
- package/dist/pdf/font-resources.js +6 -3
- package/dist/pdf/index.d.ts +1 -1
- package/dist/pdf/pages.js +15 -0
- package/dist/pdf/png.d.ts +11 -2
- package/dist/pdf/png.js +50 -23
- package/dist/pdf/session.js +3 -2
- package/dist/pdf/settings.d.ts +2 -2
- package/dist/pdf/settings.js +7 -3
- package/dist/xlsx/options.js +2 -2
- package/dist/xlsx/portable.js +1 -1
- package/dist/xlsx/styles.js +28 -18
- package/dist/xlsx/types.d.ts +13 -1
- package/dist/xlsx/workbook.js +9 -1
- package/dist/xlsx/worksheet.d.ts +13 -1
- package/dist/xlsx/worksheet.js +65 -11
- package/package.json +9 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PdfPathCommand } from "../../pdf/document-types.js";
|
|
2
|
+
/** An affine matrix [a b c d e f]: x' = a x + c y + e, y' = b x + d y + f. */
|
|
3
|
+
export type Matrix = readonly [number, number, number, number, number, number];
|
|
4
|
+
export declare const identity: Matrix;
|
|
5
|
+
export declare function multiply(m: Matrix, n: Matrix): Matrix;
|
|
6
|
+
export declare function apply(m: Matrix, x: number, y: number): [number, number];
|
|
7
|
+
export declare function determinant(m: Matrix): number;
|
|
8
|
+
export declare function scaleOf(m: Matrix): number;
|
|
9
|
+
export declare function numbers(text: string): number[];
|
|
10
|
+
/** Parse an SVG transform list. Returns undefined for syntax this reader does not understand. */
|
|
11
|
+
export declare function parseTransform(text: string | undefined): Matrix | undefined;
|
|
12
|
+
/** Absolute user-space commands; quadratic curves and arcs are already cubic. */
|
|
13
|
+
export type UserCommand = PdfPathCommand;
|
|
14
|
+
/** Parse SVG path data. Stops at the first malformed segment, as SVG renderers do, and reports whether it did. */
|
|
15
|
+
export declare function parsePathData(d: string): {
|
|
16
|
+
readonly commands: UserCommand[];
|
|
17
|
+
readonly malformed: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Closed ellipse as four cubic quarters, starting at the rightmost point. */
|
|
20
|
+
export declare function ellipse(cx: number, cy: number, rx: number, ry: number): UserCommand[];
|
|
21
|
+
export declare function rectangle(x: number, y: number, width: number, height: number, rx: number, ry: number): UserCommand[];
|
|
22
|
+
export declare function polyline(points: readonly number[], closed: boolean): UserCommand[];
|
|
23
|
+
export declare function transformCommands(commands: readonly UserCommand[], m: Matrix): PdfPathCommand[];
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
export const identity = [1, 0, 0, 1, 0, 0];
|
|
2
|
+
export function multiply(m, n) {
|
|
3
|
+
return [m[0] * n[0] + m[2] * n[1], m[1] * n[0] + m[3] * n[1], m[0] * n[2] + m[2] * n[3], m[1] * n[2] + m[3] * n[3],
|
|
4
|
+
m[0] * n[4] + m[2] * n[5] + m[4], m[1] * n[4] + m[3] * n[5] + m[5]];
|
|
5
|
+
}
|
|
6
|
+
export function apply(m, x, y) { return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]]; }
|
|
7
|
+
export function determinant(m) { return m[0] * m[3] - m[1] * m[2]; }
|
|
8
|
+
export function scaleOf(m) { return Math.sqrt(Math.abs(determinant(m))); }
|
|
9
|
+
const numberPattern = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
|
|
10
|
+
export function numbers(text) { return (text.match(numberPattern) ?? []).map(Number); }
|
|
11
|
+
/** Parse an SVG transform list. Returns undefined for syntax this reader does not understand. */
|
|
12
|
+
export function parseTransform(text) {
|
|
13
|
+
if (text === undefined || !text.trim() || text.trim() === "none")
|
|
14
|
+
return identity;
|
|
15
|
+
let result = identity, rest = text.trim();
|
|
16
|
+
const item = /^([a-zA-Z]+)\s*\(([^)]*)\)\s*,?\s*/;
|
|
17
|
+
while (rest) {
|
|
18
|
+
const match = item.exec(rest);
|
|
19
|
+
if (!match)
|
|
20
|
+
return undefined;
|
|
21
|
+
const name = match[1], input = match[2].trim(), args = [];
|
|
22
|
+
const unitPattern = /([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)([a-z%]*)/gi;
|
|
23
|
+
let end = 0;
|
|
24
|
+
for (const arg of input.matchAll(unitPattern)) {
|
|
25
|
+
const separator = input.slice(end, arg.index);
|
|
26
|
+
if (!/^\s*,?\s*$/.test(separator) || !args.length && separator)
|
|
27
|
+
return undefined;
|
|
28
|
+
const unit = arg[2].toLowerCase(), value = Number(arg[1]);
|
|
29
|
+
const angle = !args.length && (name === "rotate" || name === "skewX" || name === "skewY");
|
|
30
|
+
if (!unit || (unit === "px" && name === "translate"))
|
|
31
|
+
args.push(value);
|
|
32
|
+
else if (angle && unit === "deg")
|
|
33
|
+
args.push(value);
|
|
34
|
+
else if (angle && unit === "rad")
|
|
35
|
+
args.push(value * 180 / Math.PI);
|
|
36
|
+
else if (angle && unit === "grad")
|
|
37
|
+
args.push(value * .9);
|
|
38
|
+
else if (angle && unit === "turn")
|
|
39
|
+
args.push(value * 360);
|
|
40
|
+
else
|
|
41
|
+
return undefined;
|
|
42
|
+
end = arg.index + arg[0].length;
|
|
43
|
+
}
|
|
44
|
+
if (end !== input.length)
|
|
45
|
+
return undefined;
|
|
46
|
+
let next;
|
|
47
|
+
if (name === "matrix" && args.length === 6)
|
|
48
|
+
next = args;
|
|
49
|
+
else if (name === "translate" && (args.length === 1 || args.length === 2))
|
|
50
|
+
next = [1, 0, 0, 1, args[0], args[1] ?? 0];
|
|
51
|
+
else if (name === "scale" && (args.length === 1 || args.length === 2))
|
|
52
|
+
next = [args[0], 0, 0, args[1] ?? args[0], 0, 0];
|
|
53
|
+
else if (name === "rotate" && (args.length === 1 || args.length === 3)) {
|
|
54
|
+
const angle = args[0] * Math.PI / 180, cos = Math.cos(angle), sin = Math.sin(angle), cx = args[1] ?? 0, cy = args[2] ?? 0;
|
|
55
|
+
next = multiply(multiply([1, 0, 0, 1, cx, cy], [cos, sin, -sin, cos, 0, 0]), [1, 0, 0, 1, -cx, -cy]);
|
|
56
|
+
}
|
|
57
|
+
else if (name === "skewX" && args.length === 1)
|
|
58
|
+
next = [1, 0, Math.tan(args[0] * Math.PI / 180), 1, 0, 0];
|
|
59
|
+
else if (name === "skewY" && args.length === 1)
|
|
60
|
+
next = [1, Math.tan(args[0] * Math.PI / 180), 0, 1, 0, 0];
|
|
61
|
+
else
|
|
62
|
+
return undefined;
|
|
63
|
+
result = multiply(result, next);
|
|
64
|
+
rest = rest.slice(match[0].length);
|
|
65
|
+
}
|
|
66
|
+
return result.every(Number.isFinite) ? result : undefined;
|
|
67
|
+
}
|
|
68
|
+
function arc(out, x1, y1, rx, ry, rotation, large, sweep, x2, y2) {
|
|
69
|
+
if (x1 === x2 && y1 === y2)
|
|
70
|
+
return;
|
|
71
|
+
rx = Math.abs(rx);
|
|
72
|
+
ry = Math.abs(ry);
|
|
73
|
+
if (!rx || !ry) {
|
|
74
|
+
out.push({ op: "line", x: x2, y: y2 });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const phi = rotation * Math.PI / 180, cos = Math.cos(phi), sin = Math.sin(phi);
|
|
78
|
+
const dx = (x1 - x2) / 2, dy = (y1 - y2) / 2, xp = cos * dx + sin * dy, yp = -sin * dx + cos * dy;
|
|
79
|
+
const lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
|
|
80
|
+
if (lambda > 1) {
|
|
81
|
+
const s = Math.sqrt(lambda);
|
|
82
|
+
rx *= s;
|
|
83
|
+
ry *= s;
|
|
84
|
+
}
|
|
85
|
+
const sign = large === sweep ? -1 : 1, numerator = rx * rx * ry * ry - rx * rx * yp * yp - ry * ry * xp * xp;
|
|
86
|
+
const factor = sign * Math.sqrt(Math.max(0, numerator / (rx * rx * yp * yp + ry * ry * xp * xp)));
|
|
87
|
+
const cxp = factor * rx * yp / ry, cyp = -factor * ry * xp / rx;
|
|
88
|
+
const cx = cos * cxp - sin * cyp + (x1 + x2) / 2, cy = sin * cxp + cos * cyp + (y1 + y2) / 2;
|
|
89
|
+
const angle = (ux, uy, vx, vy) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
|
|
90
|
+
const start = angle(1, 0, (xp - cxp) / rx, (yp - cyp) / ry);
|
|
91
|
+
let delta = angle((xp - cxp) / rx, (yp - cyp) / ry, (-xp - cxp) / rx, (-yp - cyp) / ry);
|
|
92
|
+
if (!sweep && delta > 0)
|
|
93
|
+
delta -= 2 * Math.PI;
|
|
94
|
+
else if (sweep && delta < 0)
|
|
95
|
+
delta += 2 * Math.PI;
|
|
96
|
+
const segments = Math.max(1, Math.ceil(Math.abs(delta) / (Math.PI / 2) - 1e-9)), step = delta / segments, k = 4 / 3 * Math.tan(step / 4);
|
|
97
|
+
const point = (t) => [cx + rx * Math.cos(t) * cos - ry * Math.sin(t) * sin, cy + rx * Math.cos(t) * sin + ry * Math.sin(t) * cos];
|
|
98
|
+
const derivative = (t) => [-rx * Math.sin(t) * cos - ry * Math.cos(t) * sin, -rx * Math.sin(t) * sin + ry * Math.cos(t) * cos];
|
|
99
|
+
for (let i = 0; i < segments; i++) {
|
|
100
|
+
const t1 = start + i * step, t2 = t1 + step, [px1, py1] = point(t1), [px2, py2] = i === segments - 1 ? [x2, y2] : point(t2);
|
|
101
|
+
const [d1x, d1y] = derivative(t1), [d2x, d2y] = derivative(t2);
|
|
102
|
+
out.push({ op: "cubic", x1: px1 + k * d1x, y1: py1 + k * d1y, x2: px2 - k * d2x, y2: py2 - k * d2y, x: px2, y: py2 });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Parse SVG path data. Stops at the first malformed segment, as SVG renderers do, and reports whether it did. */
|
|
106
|
+
export function parsePathData(d) {
|
|
107
|
+
const out = [], tokens = /([MmLlHhVvCcSsQqTtAaZz])|([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|([\s,]+)|(.)/g;
|
|
108
|
+
const list = [];
|
|
109
|
+
let malformed = false;
|
|
110
|
+
let comma = false;
|
|
111
|
+
for (const match of d.matchAll(tokens)) {
|
|
112
|
+
if (match[4] !== undefined || comma && match[1] !== undefined) {
|
|
113
|
+
malformed = true;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const separator = match[3];
|
|
117
|
+
if (separator?.includes(",")) {
|
|
118
|
+
const previous = list.at(-1);
|
|
119
|
+
if (previous === undefined || /^[A-Za-z]$/.test(previous) || separator.indexOf(",") !== separator.lastIndexOf(",")) {
|
|
120
|
+
malformed = true;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
comma = true;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (match[1] !== undefined || match[2] !== undefined)
|
|
127
|
+
list.push(match[1] ?? match[2]);
|
|
128
|
+
comma = false;
|
|
129
|
+
}
|
|
130
|
+
malformed ||= comma;
|
|
131
|
+
let i = 0, x = 0, y = 0, startX = 0, startY = 0, command = "", lastControl, lastQuad;
|
|
132
|
+
let open = false;
|
|
133
|
+
const isCommand = (value) => value !== undefined && /^[A-Za-z]$/.test(value);
|
|
134
|
+
const take = () => {
|
|
135
|
+
const value = list[i];
|
|
136
|
+
if (value === undefined || isCommand(value))
|
|
137
|
+
return undefined;
|
|
138
|
+
i++;
|
|
139
|
+
const number = Number(value);
|
|
140
|
+
return Number.isFinite(number) ? number : undefined;
|
|
141
|
+
};
|
|
142
|
+
// Arc flags may be written without separators ("a1 1 0 011 1"): split compact digit runs.
|
|
143
|
+
const flag = () => {
|
|
144
|
+
const raw = list[i];
|
|
145
|
+
if (raw === undefined || isCommand(raw))
|
|
146
|
+
return undefined;
|
|
147
|
+
if (raw === "0" || raw === "1") {
|
|
148
|
+
i++;
|
|
149
|
+
return Number(raw);
|
|
150
|
+
}
|
|
151
|
+
if (/^[01][\d.]/.test(raw)) {
|
|
152
|
+
list[i] = raw.slice(1);
|
|
153
|
+
return Number(raw[0]);
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
};
|
|
157
|
+
while (i < list.length) {
|
|
158
|
+
const token = list[i];
|
|
159
|
+
if (isCommand(token)) {
|
|
160
|
+
command = token;
|
|
161
|
+
i++;
|
|
162
|
+
}
|
|
163
|
+
else if (!command || command === "Z" || command === "z")
|
|
164
|
+
return { commands: out, malformed: true };
|
|
165
|
+
const relative = command === command.toLowerCase(), base = command.toUpperCase();
|
|
166
|
+
if (!out.length && base !== "M")
|
|
167
|
+
return { commands: out, malformed: true };
|
|
168
|
+
const ox = relative ? x : 0, oy = relative ? y : 0;
|
|
169
|
+
if (base === "Z") {
|
|
170
|
+
if (open)
|
|
171
|
+
out.push({ op: "close" });
|
|
172
|
+
x = startX;
|
|
173
|
+
y = startY;
|
|
174
|
+
open = false;
|
|
175
|
+
lastControl = lastQuad = undefined;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const ensure = () => { if (!open) {
|
|
179
|
+
out.push({ op: "move", x, y });
|
|
180
|
+
open = true;
|
|
181
|
+
} };
|
|
182
|
+
if (base === "M") {
|
|
183
|
+
const a = take(), b = take();
|
|
184
|
+
if (a === undefined || b === undefined)
|
|
185
|
+
return { commands: out, malformed: true };
|
|
186
|
+
x = ox + a;
|
|
187
|
+
y = oy + b;
|
|
188
|
+
startX = x;
|
|
189
|
+
startY = y;
|
|
190
|
+
out.push({ op: "move", x, y });
|
|
191
|
+
open = true;
|
|
192
|
+
command = relative ? "l" : "L";
|
|
193
|
+
lastControl = lastQuad = undefined;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (base === "L" || base === "H" || base === "V") {
|
|
197
|
+
const a = take();
|
|
198
|
+
if (a === undefined)
|
|
199
|
+
return { commands: out, malformed: true };
|
|
200
|
+
const b = base === "L" ? take() : undefined;
|
|
201
|
+
if (base === "L" && b === undefined)
|
|
202
|
+
return { commands: out, malformed: true };
|
|
203
|
+
ensure();
|
|
204
|
+
if (base !== "V")
|
|
205
|
+
x = ox + a;
|
|
206
|
+
if (base !== "H")
|
|
207
|
+
y = oy + (b ?? a);
|
|
208
|
+
out.push({ op: "line", x, y });
|
|
209
|
+
lastControl = lastQuad = undefined;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (base === "C" || base === "S") {
|
|
213
|
+
const values = [];
|
|
214
|
+
for (let n = base === "C" ? 6 : 4; n > 0; n--) {
|
|
215
|
+
const v = take();
|
|
216
|
+
if (v === undefined)
|
|
217
|
+
return { commands: out, malformed: true };
|
|
218
|
+
values.push(v);
|
|
219
|
+
}
|
|
220
|
+
const [c1x, c1y] = base === "C" ? [ox + values[0], oy + values[1]] : lastControl ? [2 * x - lastControl[0], 2 * y - lastControl[1]] : [x, y];
|
|
221
|
+
const rest = base === "C" ? values.slice(2) : values;
|
|
222
|
+
const c2x = ox + rest[0], c2y = oy + rest[1], ex = ox + rest[2], ey = oy + rest[3];
|
|
223
|
+
ensure();
|
|
224
|
+
out.push({ op: "cubic", x1: c1x, y1: c1y, x2: c2x, y2: c2y, x: ex, y: ey });
|
|
225
|
+
lastControl = [c2x, c2y];
|
|
226
|
+
lastQuad = undefined;
|
|
227
|
+
x = ex;
|
|
228
|
+
y = ey;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (base === "Q" || base === "T") {
|
|
232
|
+
const values = [];
|
|
233
|
+
for (let n = base === "Q" ? 4 : 2; n > 0; n--) {
|
|
234
|
+
const v = take();
|
|
235
|
+
if (v === undefined)
|
|
236
|
+
return { commands: out, malformed: true };
|
|
237
|
+
values.push(v);
|
|
238
|
+
}
|
|
239
|
+
const [qx, qy] = base === "Q" ? [ox + values[0], oy + values[1]] : lastQuad ? [2 * x - lastQuad[0], 2 * y - lastQuad[1]] : [x, y];
|
|
240
|
+
const ex = ox + values[values.length - 2], ey = oy + values[values.length - 1];
|
|
241
|
+
ensure();
|
|
242
|
+
out.push({ op: "cubic", x1: x + 2 / 3 * (qx - x), y1: y + 2 / 3 * (qy - y), x2: ex + 2 / 3 * (qx - ex), y2: ey + 2 / 3 * (qy - ey), x: ex, y: ey });
|
|
243
|
+
lastQuad = [qx, qy];
|
|
244
|
+
lastControl = undefined;
|
|
245
|
+
x = ex;
|
|
246
|
+
y = ey;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (base === "A") {
|
|
250
|
+
const rx = take(), ry = take(), rotation = take(), large = flag(), sweep = flag(), a = take(), b = take();
|
|
251
|
+
if (rx === undefined || ry === undefined || rotation === undefined || large === undefined || sweep === undefined || a === undefined || b === undefined)
|
|
252
|
+
return { commands: out, malformed: true };
|
|
253
|
+
ensure();
|
|
254
|
+
arc(out, x, y, rx, ry, rotation, large === 1, sweep === 1, ox + a, oy + b);
|
|
255
|
+
x = ox + a;
|
|
256
|
+
y = oy + b;
|
|
257
|
+
lastControl = lastQuad = undefined;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
return { commands: out, malformed: true };
|
|
261
|
+
}
|
|
262
|
+
return { commands: out, malformed };
|
|
263
|
+
}
|
|
264
|
+
const kappa = 0.5522847498307936;
|
|
265
|
+
/** Closed ellipse as four cubic quarters, starting at the rightmost point. */
|
|
266
|
+
export function ellipse(cx, cy, rx, ry) {
|
|
267
|
+
const ox = rx * kappa, oy = ry * kappa;
|
|
268
|
+
return [{ op: "move", x: cx + rx, y: cy },
|
|
269
|
+
{ op: "cubic", x1: cx + rx, y1: cy + oy, x2: cx + ox, y2: cy + ry, x: cx, y: cy + ry },
|
|
270
|
+
{ op: "cubic", x1: cx - ox, y1: cy + ry, x2: cx - rx, y2: cy + oy, x: cx - rx, y: cy },
|
|
271
|
+
{ op: "cubic", x1: cx - rx, y1: cy - oy, x2: cx - ox, y2: cy - ry, x: cx, y: cy - ry },
|
|
272
|
+
{ op: "cubic", x1: cx + ox, y1: cy - ry, x2: cx + rx, y2: cy - oy, x: cx + rx, y: cy }, { op: "close" }];
|
|
273
|
+
}
|
|
274
|
+
export function rectangle(x, y, width, height, rx, ry) {
|
|
275
|
+
rx = Math.min(Math.max(rx, 0), width / 2);
|
|
276
|
+
ry = Math.min(Math.max(ry, 0), height / 2);
|
|
277
|
+
if (!rx || !ry)
|
|
278
|
+
return [{ op: "move", x, y }, { op: "line", x: x + width, y }, { op: "line", x: x + width, y: y + height }, { op: "line", x, y: y + height }, { op: "close" }];
|
|
279
|
+
const ox = rx * (1 - kappa), oy = ry * (1 - kappa), r = x + width, b = y + height;
|
|
280
|
+
return [{ op: "move", x: x + rx, y }, { op: "line", x: r - rx, y }, { op: "cubic", x1: r - ox, y1: y, x2: r, y2: y + oy, x: r, y: y + ry },
|
|
281
|
+
{ op: "line", x: r, y: b - ry }, { op: "cubic", x1: r, y1: b - oy, x2: r - ox, y2: b, x: r - rx, y: b },
|
|
282
|
+
{ op: "line", x: x + rx, y: b }, { op: "cubic", x1: x + ox, y1: b, x2: x, y2: b - oy, x, y: b - ry },
|
|
283
|
+
{ op: "line", x, y: y + ry }, { op: "cubic", x1: x, y1: y + oy, x2: x + ox, y2: y, x: x + rx, y }, { op: "close" }];
|
|
284
|
+
}
|
|
285
|
+
export function polyline(points, closed) {
|
|
286
|
+
const out = [];
|
|
287
|
+
for (let i = 0; i + 1 < points.length; i += 2)
|
|
288
|
+
out.push({ op: i ? "line" : "move", x: points[i], y: points[i + 1] });
|
|
289
|
+
if (closed && out.length)
|
|
290
|
+
out.push({ op: "close" });
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
export function transformCommands(commands, m) {
|
|
294
|
+
return commands.map(c => {
|
|
295
|
+
if (c.op === "close")
|
|
296
|
+
return c;
|
|
297
|
+
const [x, y] = apply(m, c.x, c.y);
|
|
298
|
+
if (c.op === "cubic") {
|
|
299
|
+
const [x1, y1] = apply(m, c.x1, c.y1), [x2, y2] = apply(m, c.x2, c.y2);
|
|
300
|
+
return { op: "cubic", x1, y1, x2, y2, x, y };
|
|
301
|
+
}
|
|
302
|
+
return { op: c.op, x, y };
|
|
303
|
+
});
|
|
304
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PdfJpegImage, PdfPngImage } from "../../pdf/document-types.js";
|
|
2
|
+
/** A decoded `data:` image the PDF writer can embed, with its pixel size for aspect-ratio fitting. */
|
|
3
|
+
export interface SvgDataImage {
|
|
4
|
+
readonly image: PdfPngImage | PdfJpegImage;
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
}
|
|
8
|
+
/** Decode a base64 PNG or JPEG `data:` URL. External references and other image types return undefined. */
|
|
9
|
+
export declare function svgDataImage(href: string): SvgDataImage | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../../core/errors.js";
|
|
2
|
+
import { jpegSize } from "../../pdf/document-images.js";
|
|
3
|
+
import { pngEmbeddableSize } from "../../pdf/png.js";
|
|
4
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5
|
+
const values = new Int16Array(128).fill(-1);
|
|
6
|
+
for (let i = 0; i < alphabet.length; i++)
|
|
7
|
+
values[alphabet.charCodeAt(i)] = i;
|
|
8
|
+
/** Strict base64 with optional padding and ignorable whitespace; undefined for anything else. */
|
|
9
|
+
function base64(text) {
|
|
10
|
+
const compact = text.replace(/[\t\n\f\r ]+/g, "").replace(/={1,2}$/, "");
|
|
11
|
+
if (compact.length % 4 === 1)
|
|
12
|
+
return undefined;
|
|
13
|
+
const output = new Uint8Array(Math.floor(compact.length * 3 / 4));
|
|
14
|
+
let bits = 0, buffer = 0, offset = 0;
|
|
15
|
+
for (let i = 0; i < compact.length; i++) {
|
|
16
|
+
const code = compact.charCodeAt(i), value = code < 128 ? values[code] : -1;
|
|
17
|
+
if (value < 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
buffer = (buffer << 6 | value) & 0xffffff;
|
|
20
|
+
bits += 6;
|
|
21
|
+
if (bits >= 8) {
|
|
22
|
+
bits -= 8;
|
|
23
|
+
output[offset++] = buffer >> bits & 255;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return output;
|
|
27
|
+
}
|
|
28
|
+
/** Decode a base64 PNG or JPEG `data:` URL. External references and other image types return undefined. */
|
|
29
|
+
export function svgDataImage(href) {
|
|
30
|
+
const match = /^\s*data:image\/(png|jpeg|jpg)(?:;[^,;]*=[^,;]*)*;base64,([\s\S]*)$/i.exec(href);
|
|
31
|
+
if (!match)
|
|
32
|
+
return undefined;
|
|
33
|
+
const data = base64(match[2]);
|
|
34
|
+
if (!data)
|
|
35
|
+
return undefined;
|
|
36
|
+
try {
|
|
37
|
+
const format = match[1].toLowerCase() === "png" ? "png" : "jpeg";
|
|
38
|
+
const { width, height } = format === "png" ? pngEmbeddableSize(data) : jpegSize(data);
|
|
39
|
+
return width && height ? { image: { format, data }, width, height } : undefined;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof OfficeIMOError && error.code === "RESOURCE_LIMIT")
|
|
43
|
+
throw error;
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** One parsed SVG element. Names keep their prefix; `local` is the name after it. */
|
|
2
|
+
export interface SvgNode {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly local: string;
|
|
5
|
+
readonly attributes: ReadonlyMap<string, string>;
|
|
6
|
+
readonly children: readonly (SvgNode | string)[];
|
|
7
|
+
}
|
|
8
|
+
/** A small, non-validating parser for serialized SVG: elements, attributes, text, CDATA and character references.
|
|
9
|
+
* Comments, processing instructions and doctype declarations are skipped; external entities are never resolved. */
|
|
10
|
+
export declare function parseSvgMarkup(markup: string, maxDepth?: number): SvgNode;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { NotSupportedError } from "../../core/errors.js";
|
|
2
|
+
const attributePattern = /([A-Za-z_][\w.:-]*)\s*=\s*("([^"]*)"|'([^']*)')/y;
|
|
3
|
+
const entities = { lt: "<", gt: ">", amp: "&", quot: "\"", apos: "'", nbsp: " " };
|
|
4
|
+
function decode(text) {
|
|
5
|
+
return text.indexOf("&") < 0 ? text : text.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[A-Za-z]+);/g, (match, entity) => {
|
|
6
|
+
if (entity[0] === "#") {
|
|
7
|
+
const code = entity[1] === "x" || entity[1] === "X" ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);
|
|
8
|
+
return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "�";
|
|
9
|
+
}
|
|
10
|
+
return entities[entity] ?? match;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** A small, non-validating parser for serialized SVG: elements, attributes, text, CDATA and character references.
|
|
14
|
+
* Comments, processing instructions and doctype declarations are skipped; external entities are never resolved. */
|
|
15
|
+
export function parseSvgMarkup(markup, maxDepth = 256) {
|
|
16
|
+
if (typeof markup !== "string")
|
|
17
|
+
throw new TypeError("Chart SVG must be serialized markup.");
|
|
18
|
+
const stack = [];
|
|
19
|
+
let root, index = 0;
|
|
20
|
+
const text = (value) => { const top = stack[stack.length - 1]; if (top && value)
|
|
21
|
+
top.children.push(value); };
|
|
22
|
+
while (index < markup.length) {
|
|
23
|
+
const open = markup.indexOf("<", index);
|
|
24
|
+
if (open < 0) {
|
|
25
|
+
text(decode(markup.slice(index)));
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
if (open > index)
|
|
29
|
+
text(decode(markup.slice(index, open)));
|
|
30
|
+
if (markup.startsWith("<!--", open)) {
|
|
31
|
+
const end = markup.indexOf("-->", open + 4);
|
|
32
|
+
if (end < 0)
|
|
33
|
+
throw new TypeError("Chart SVG has an unterminated comment.");
|
|
34
|
+
index = end + 3;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (markup.startsWith("<![CDATA[", open)) {
|
|
38
|
+
const end = markup.indexOf("]]>", open + 9);
|
|
39
|
+
if (end < 0)
|
|
40
|
+
throw new TypeError("Chart SVG has an unterminated CDATA section.");
|
|
41
|
+
text(markup.slice(open + 9, end));
|
|
42
|
+
index = end + 3;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (markup[open + 1] === "?") {
|
|
46
|
+
const end = markup.indexOf("?>", open + 2);
|
|
47
|
+
if (end < 0)
|
|
48
|
+
throw new TypeError("Chart SVG has an unterminated processing instruction.");
|
|
49
|
+
index = end + 2;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (markup[open + 1] === "!") {
|
|
53
|
+
if (/^<!DOCTYPE[^>]*\[/i.test(markup.slice(open, open + 1024)))
|
|
54
|
+
throw new NotSupportedError("Chart SVG with an internal DTD subset is not supported.");
|
|
55
|
+
const end = markup.indexOf(">", open + 2);
|
|
56
|
+
if (end < 0)
|
|
57
|
+
throw new TypeError("Chart SVG has an unterminated declaration.");
|
|
58
|
+
index = end + 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (markup[open + 1] === "/") {
|
|
62
|
+
const end = markup.indexOf(">", open + 2);
|
|
63
|
+
if (end < 0)
|
|
64
|
+
throw new TypeError("Chart SVG has an unterminated end tag.");
|
|
65
|
+
const name = markup.slice(open + 2, end).trim(), top = stack.pop();
|
|
66
|
+
if (!top || top.name !== name)
|
|
67
|
+
throw new TypeError("Chart SVG end tag </" + name + "> does not match its element.");
|
|
68
|
+
const node = top;
|
|
69
|
+
if (stack.length)
|
|
70
|
+
stack[stack.length - 1].children.push(node);
|
|
71
|
+
else
|
|
72
|
+
root = node;
|
|
73
|
+
index = end + 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const tag = /^<([A-Za-z_][\w.:-]*)/.exec(markup.slice(open, open + 256));
|
|
77
|
+
if (!tag)
|
|
78
|
+
throw new TypeError("Chart SVG has an invalid start tag.");
|
|
79
|
+
const name = tag[1], attributes = new Map();
|
|
80
|
+
let position = open + tag[0].length, selfClosing = false;
|
|
81
|
+
for (;;) {
|
|
82
|
+
while (position < markup.length && /\s/.test(markup[position]))
|
|
83
|
+
position++;
|
|
84
|
+
const character = markup[position];
|
|
85
|
+
if (character === undefined)
|
|
86
|
+
throw new TypeError("Chart SVG has an unterminated start tag.");
|
|
87
|
+
if (character === ">") {
|
|
88
|
+
position++;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if (character === "/" && markup[position + 1] === ">") {
|
|
92
|
+
position += 2;
|
|
93
|
+
selfClosing = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
attributePattern.lastIndex = position;
|
|
97
|
+
const attribute = attributePattern.exec(markup);
|
|
98
|
+
if (!attribute)
|
|
99
|
+
throw new TypeError("Chart SVG has an invalid attribute on <" + name + ">.");
|
|
100
|
+
attributes.set(attribute[1], decode(attribute[3] ?? attribute[4] ?? ""));
|
|
101
|
+
position = attributePattern.lastIndex;
|
|
102
|
+
}
|
|
103
|
+
if (root)
|
|
104
|
+
throw new TypeError("Chart SVG must have one root element.");
|
|
105
|
+
const local = name.slice(name.indexOf(":") + 1), element = { name, local, attributes, children: [] };
|
|
106
|
+
if (selfClosing) {
|
|
107
|
+
if (stack.length)
|
|
108
|
+
stack[stack.length - 1].children.push(element);
|
|
109
|
+
else
|
|
110
|
+
root = element;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (stack.length >= maxDepth)
|
|
114
|
+
throw new NotSupportedError("Chart SVG nesting exceeds " + maxDepth + " levels.");
|
|
115
|
+
stack.push(element);
|
|
116
|
+
}
|
|
117
|
+
index = position;
|
|
118
|
+
}
|
|
119
|
+
if (stack.length)
|
|
120
|
+
throw new TypeError("Chart SVG has an unclosed <" + stack[stack.length - 1].name + "> element.");
|
|
121
|
+
if (!root || root.local !== "svg")
|
|
122
|
+
throw new TypeError("Chart SVG must have an <svg> root element.");
|
|
123
|
+
return root;
|
|
124
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Straight RGBA, channels 0-255 and alpha 0-1. */
|
|
2
|
+
export interface Rgba {
|
|
3
|
+
readonly r: number;
|
|
4
|
+
readonly g: number;
|
|
5
|
+
readonly b: number;
|
|
6
|
+
readonly a: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function alpha(text: string | undefined): number | undefined;
|
|
9
|
+
/** Parse the CSS color forms a browser's computed style and SVG presentation attributes produce. */
|
|
10
|
+
export declare function parseColor(input: string): Rgba | undefined;
|
|
11
|
+
/** Composite over white, the page colour, and return six-digit hex for the PDF drawing contract. */
|
|
12
|
+
export declare function flatten(color: Rgba, opacity: number): string | undefined;
|
|
13
|
+
/** Inline `style` declarations as a map; later declarations win, `!important` is accepted and dropped. */
|
|
14
|
+
export declare function parseStyle(text: string | undefined): Map<string, string>;
|
|
15
|
+
/** A CSS/SVG length in user units. Percentages resolve against `reference`; `em` against the font size. */
|
|
16
|
+
export declare function length(text: string | undefined, fontSize: number, reference?: number): number | undefined;
|