reamkit 1.0.1 → 1.0.2
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.
|
@@ -3,5 +3,5 @@ import { ResolvedParagraphProperties, ResolvedRunProperties } from './types.js';
|
|
|
3
3
|
export declare const EMPTY_STYLE_SHEET: StyleSheet;
|
|
4
4
|
export declare function resolveRunProperties(runDirect: RunProperties, paragraphDirect: ParagraphProperties, sheet: StyleSheet): ResolvedRunProperties;
|
|
5
5
|
export declare function resolveParagraphProperties(paragraphDirect: ParagraphProperties, sheet: StyleSheet): ResolvedParagraphProperties;
|
|
6
|
-
export declare function resolveBodyStyles(body: ReadonlyArray<BodyElement>, sheet: StyleSheet):
|
|
6
|
+
export declare function resolveBodyStyles(body: ReadonlyArray<BodyElement>, sheet: StyleSheet): ReadonlyArray<BodyElement>;
|
|
7
7
|
export declare function resolveHeadersFootersStyles(hf: ReadonlyMap<string, ReadonlyArray<BodyElement>>, sheet: StyleSheet): ReadonlyMap<string, ReadonlyArray<BodyElement>>;
|
|
@@ -35,7 +35,20 @@ function computeRunProperties(runDirect, paragraphDirect, sheet) {
|
|
|
35
35
|
}
|
|
36
36
|
return mergeRun(acc, runDirect);
|
|
37
37
|
}
|
|
38
|
+
var paragraphCascadeCache = /* @__PURE__ */ new WeakMap();
|
|
38
39
|
function resolveParagraphProperties(paragraphDirect, sheet) {
|
|
40
|
+
let bySheet = paragraphCascadeCache.get(sheet);
|
|
41
|
+
if (!bySheet) {
|
|
42
|
+
bySheet = /* @__PURE__ */ new WeakMap();
|
|
43
|
+
paragraphCascadeCache.set(sheet, bySheet);
|
|
44
|
+
}
|
|
45
|
+
const hit = bySheet.get(paragraphDirect);
|
|
46
|
+
if (hit) return hit;
|
|
47
|
+
const resolved = computeParagraphProperties(paragraphDirect, sheet);
|
|
48
|
+
bySheet.set(paragraphDirect, resolved);
|
|
49
|
+
return resolved;
|
|
50
|
+
}
|
|
51
|
+
function computeParagraphProperties(paragraphDirect, sheet) {
|
|
39
52
|
let acc = mergePar(DEFAULT_RESOLVED_PARAGRAPH, sheet.defaultParagraphProperties);
|
|
40
53
|
if (paragraphDirect.styleId) {
|
|
41
54
|
const chain = resolveStyleChain(paragraphDirect.styleId, sheet);
|
|
@@ -117,52 +130,45 @@ function copyDefined(base, override) {
|
|
|
117
130
|
}
|
|
118
131
|
return out;
|
|
119
132
|
}
|
|
133
|
+
function primeResolvedFixpoint(run, para) {
|
|
134
|
+
let bySheet = runCascadeCache.get(EMPTY_STYLE_SHEET);
|
|
135
|
+
if (!bySheet) {
|
|
136
|
+
bySheet = /* @__PURE__ */ new WeakMap();
|
|
137
|
+
runCascadeCache.set(EMPTY_STYLE_SHEET, bySheet);
|
|
138
|
+
}
|
|
139
|
+
let byRun = bySheet.get(run);
|
|
140
|
+
if (!byRun) {
|
|
141
|
+
byRun = /* @__PURE__ */ new WeakMap();
|
|
142
|
+
bySheet.set(run, byRun);
|
|
143
|
+
}
|
|
144
|
+
if (!byRun.has(para)) byRun.set(para, run);
|
|
145
|
+
}
|
|
146
|
+
function primeParagraphFixpoint(para) {
|
|
147
|
+
let bySheet = paragraphCascadeCache.get(EMPTY_STYLE_SHEET);
|
|
148
|
+
if (!bySheet) {
|
|
149
|
+
bySheet = /* @__PURE__ */ new WeakMap();
|
|
150
|
+
paragraphCascadeCache.set(EMPTY_STYLE_SHEET, bySheet);
|
|
151
|
+
}
|
|
152
|
+
if (!bySheet.has(para)) bySheet.set(para, para);
|
|
153
|
+
}
|
|
120
154
|
function resolveBodyStyles(body, sheet) {
|
|
121
|
-
const visitParagraph = (p) =>
|
|
122
|
-
|
|
123
|
-
properties
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}))
|
|
128
|
-
});
|
|
155
|
+
const visitParagraph = (p) => {
|
|
156
|
+
for (const r of p.runs) r.properties = resolveRunProperties(r.properties, p.properties, sheet);
|
|
157
|
+
p.properties = resolveParagraphProperties(p.properties, sheet);
|
|
158
|
+
primeParagraphFixpoint(p.properties);
|
|
159
|
+
for (const r of p.runs) primeResolvedFixpoint(r.properties, p.properties);
|
|
160
|
+
};
|
|
129
161
|
const visit = (el) => {
|
|
130
|
-
if (el.kind === "paragraph")
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
if (el.kind === "table") return {
|
|
135
|
-
kind: "table",
|
|
136
|
-
table: {
|
|
137
|
-
...el.table,
|
|
138
|
-
rows: el.table.rows.map((row) => ({
|
|
139
|
-
...row,
|
|
140
|
-
cells: row.cells.map((cell) => ({
|
|
141
|
-
...cell,
|
|
142
|
-
content: cell.content.map(visit)
|
|
143
|
-
}))
|
|
144
|
-
}))
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
if (el.kind === "shape" && el.shape.text) return {
|
|
148
|
-
kind: "shape",
|
|
149
|
-
shape: {
|
|
150
|
-
...el.shape,
|
|
151
|
-
text: {
|
|
152
|
-
...el.shape.text,
|
|
153
|
-
content: el.shape.text.content.map(visit)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
return el;
|
|
162
|
+
if (el.kind === "paragraph") visitParagraph(el.paragraph);
|
|
163
|
+
else if (el.kind === "table") for (const row of el.table.rows) for (const cell of row.cells) for (const child of cell.content) visit(child);
|
|
164
|
+
else if (el.kind === "shape" && el.shape.text) for (const child of el.shape.text.content) visit(child);
|
|
158
165
|
};
|
|
159
|
-
|
|
166
|
+
for (const el of body) visit(el);
|
|
167
|
+
return body;
|
|
160
168
|
}
|
|
161
169
|
function resolveHeadersFootersStyles(hf, sheet) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for (const [key, value] of hf) out.set(key, resolveBodyStyles(value, sheet));
|
|
165
|
-
return out;
|
|
170
|
+
for (const value of hf.values()) resolveBodyStyles(value, sheet);
|
|
171
|
+
return hf;
|
|
166
172
|
}
|
|
167
173
|
//#endregion
|
|
168
174
|
export { EMPTY_STYLE_SHEET, resolveBodyStyles, resolveHeadersFootersStyles, resolveParagraphProperties, resolveRunProperties };
|
|
@@ -169,6 +169,25 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
169
169
|
const scaled = printScale < .999;
|
|
170
170
|
const breakRows = new Set(worksheet.rowBreaks ?? []);
|
|
171
171
|
let textBudget = MAX_SHEET_TEXT_CHARS;
|
|
172
|
+
const runPropsByXf = /* @__PURE__ */ new Map();
|
|
173
|
+
const cellRunProps = (xf) => {
|
|
174
|
+
let props = runPropsByXf.get(xf);
|
|
175
|
+
if (props === void 0) {
|
|
176
|
+
const base = xf ? runPropsFromXf(xf, styles) : {};
|
|
177
|
+
props = scaled ? scaleRunFont(base, printScale) : base;
|
|
178
|
+
runPropsByXf.set(xf, props);
|
|
179
|
+
}
|
|
180
|
+
return props;
|
|
181
|
+
};
|
|
182
|
+
const paraPropsByAlignment = /* @__PURE__ */ new Map();
|
|
183
|
+
const cellParaProps = (alignment) => {
|
|
184
|
+
let props = paraPropsByAlignment.get(alignment);
|
|
185
|
+
if (props === void 0) {
|
|
186
|
+
props = alignment ? { alignment } : {};
|
|
187
|
+
paraPropsByAlignment.set(alignment, props);
|
|
188
|
+
}
|
|
189
|
+
return props;
|
|
190
|
+
};
|
|
172
191
|
const rows = [];
|
|
173
192
|
for (let r = 0; r < rowCount; r++) {
|
|
174
193
|
const absR = r + rowStart;
|
|
@@ -186,8 +205,7 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
186
205
|
if (text.length > textBudget) text = text.slice(0, Math.max(0, textBudget));
|
|
187
206
|
textBudget -= text.length;
|
|
188
207
|
const xf = ws && ws.styleIndex !== void 0 ? styles.cellXfs[ws.styleIndex] : void 0;
|
|
189
|
-
const
|
|
190
|
-
const runProps = scaled ? scaleRunFont(baseRunProps, printScale) : baseRunProps;
|
|
208
|
+
const runProps = cellRunProps(xf);
|
|
191
209
|
const alignment = xf ? alignmentFromXf(xf) : void 0;
|
|
192
210
|
const shading = xf ? shadingFromXf(xf, styles) : void 0;
|
|
193
211
|
const borders = xf ? bordersFromXf(xf, styles) : void 0;
|
|
@@ -210,7 +228,7 @@ function worksheetToBody(worksheet, sharedStrings, styles, date1904, print) {
|
|
|
210
228
|
...shading ? { shading } : {},
|
|
211
229
|
...borders ? { borders } : {}
|
|
212
230
|
};
|
|
213
|
-
const paragraphProps = alignment
|
|
231
|
+
const paragraphProps = cellParaProps(alignment);
|
|
214
232
|
cells.push({
|
|
215
233
|
properties,
|
|
216
234
|
content: [{
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reamkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Ream — DOCX/XLSX to PDF (and SVG), built from scratch on the ECMA-376 and ISO 32000 specifications. Parse once, convert anywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"author": "Alex Krassavin",
|
|
6
|
+
"author": "Alex Krassavin <info@reamkit.dev>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/alex-krassavin/reamkit.git"
|