@stll/folio-core 0.43.0 → 0.44.0
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/dist/ai-edits/headless.js +6 -5
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/index.js +2 -2
- package/dist/ai-edits/snapshot.js +13 -9
- package/dist/compare/content-alignment.js +16 -1
- package/dist/compare/inline-atoms.js +1 -1
- package/dist/compare/style-resources.js +6 -0
- package/dist/docx/appVersionNormalization.d.ts +0 -18
- package/dist/docx/blockContentParser.js +8 -0
- package/dist/docx/blockRangeMarkers.d.ts +36 -0
- package/dist/docx/blockRangeMarkers.js +59 -0
- package/dist/docx/bookmarkParser.d.ts +2 -20
- package/dist/docx/bookmarkParser.js +6 -30
- package/dist/docx/borderParser.d.ts +13 -0
- package/dist/docx/borderParser.js +71 -0
- package/dist/docx/builtInStyles.d.ts +165 -0
- package/dist/docx/builtInStyles.js +239 -0
- package/dist/docx/commentIdNormalization.d.ts +3 -1
- package/dist/docx/commentIdNormalization.js +18 -1
- package/dist/docx/commentParser.d.ts +2 -1
- package/dist/docx/commentParser.js +34 -7
- package/dist/docx/commentReferenceNormalization.d.ts +4 -1
- package/dist/docx/commentReferenceNormalization.js +23 -14
- package/dist/docx/danglingRelationshipReferences.d.ts +15 -0
- package/dist/docx/danglingRelationshipReferences.js +30 -0
- package/dist/docx/defaultParagraphStyle.d.ts +18 -1
- package/dist/docx/defaultParagraphStyle.js +23 -1
- package/dist/docx/documentParser.d.ts +2 -1
- package/dist/docx/documentParser.js +2 -2
- package/dist/docx/drawingUtils.d.ts +8 -1
- package/dist/docx/drawingUtils.js +12 -3
- package/dist/docx/fieldParser.js +3 -5
- package/dist/docx/footnoteParser.d.ts +3 -2
- package/dist/docx/footnoteParser.js +19 -4
- package/dist/docx/groupDrawingParser.js +1 -1
- package/dist/docx/headerFooterRefParser.d.ts +4 -3
- package/dist/docx/headerFooterRefParser.js +42 -12
- package/dist/docx/headerFooterReferenceNormalization.d.ts +4 -1
- package/dist/docx/headerFooterReferenceNormalization.js +5 -1
- package/dist/docx/hyperlinkParser.js +11 -15
- package/dist/docx/imageParser.d.ts +1 -1
- package/dist/docx/imageParser.js +22 -18
- package/dist/docx/imageRawXml.js +5 -5
- package/dist/docx/markupRangeMarker.d.ts +15 -0
- package/dist/docx/markupRangeMarker.js +44 -0
- package/dist/docx/noteReferenceStyles.d.ts +29 -0
- package/dist/docx/noteReferenceStyles.js +70 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -1
- package/dist/docx/numberingReferenceNormalization.js +20 -1
- package/dist/docx/paraIdRangeNormalization.d.ts +0 -19
- package/dist/docx/paragraphParser.js +66 -99
- package/dist/docx/paragraphPropertySource.js +1 -0
- package/dist/docx/paragraphTraversal.d.ts +37 -1
- package/dist/docx/paragraphTraversal.js +84 -1
- package/dist/docx/parseContext.d.ts +37 -0
- package/dist/docx/parseContext.js +67 -0
- package/dist/docx/parseWarningMessage.d.ts +6 -0
- package/dist/docx/parseWarningMessage.js +44 -0
- package/dist/docx/parser.js +81 -27
- package/dist/docx/relsParser.d.ts +28 -11
- package/dist/docx/relsParser.js +26 -13
- package/dist/docx/revisionIdNormalization.js +81 -7
- package/dist/docx/rezip.js +63 -22
- package/dist/docx/runConsolidator.js +1 -2
- package/dist/docx/runParser.d.ts +8 -1
- package/dist/docx/runParser.js +30 -48
- package/dist/docx/sectionParser.d.ts +2 -1
- package/dist/docx/sectionParser.js +21 -65
- package/dist/docx/serializer/borderSerializer.d.ts +1 -2
- package/dist/docx/serializer/commentSerializer.js +22 -9
- package/dist/docx/serializer/documentSerializer.d.ts +1 -5
- package/dist/docx/serializer/documentSerializer.js +6 -16
- package/dist/docx/serializer/headerFooterSerializer.js +5 -0
- package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
- package/dist/docx/serializer/markupRangeAttributes.js +24 -0
- package/dist/docx/serializer/noteSerializer.js +5 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +1 -5
- package/dist/docx/serializer/paragraphSerializer.js +29 -35
- package/dist/docx/serializer/runSerializer.js +13 -7
- package/dist/docx/serializer/tableSerializer.js +28 -13
- package/dist/docx/serializer/textFormattingSerializer.d.ts +2 -3
- package/dist/docx/server/build.js +8 -1
- package/dist/docx/server/createBilingualDocument.js +10 -18
- package/dist/docx/server/extractDocxText.js +3 -4
- package/dist/docx/shadingParser.d.ts +6 -0
- package/dist/docx/shadingParser.js +32 -0
- package/dist/docx/shapeParser.js +3 -3
- package/dist/docx/styleParser.js +13 -87
- package/dist/docx/styleReferenceResolution.d.ts +36 -0
- package/dist/docx/styleReferenceResolution.js +51 -0
- package/dist/docx/tableLook.d.ts +57 -0
- package/dist/docx/tableLook.js +63 -0
- package/dist/docx/tableParser.d.ts +7 -9
- package/dist/docx/tableParser.js +64 -110
- package/dist/docx/textBoxParser.js +4 -4
- package/dist/docx/trackedMoveRangeNormalization.d.ts +3 -1
- package/dist/docx/trackedMoveRangeNormalization.js +11 -21
- package/dist/docx/transitionalSpelling.d.ts +13 -2
- package/dist/docx/transitionalSpelling.js +23 -1
- package/dist/docx/verbatimCapture.js +4 -11
- package/dist/docx/vmlImageParser.js +2 -2
- package/dist/docx/watermarkParser.js +2 -2
- package/dist/docx/xmlParser.d.ts +22 -32
- package/dist/docx/xmlParser.js +36 -21
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
- package/dist/internal/paragraphFormattingSerialization.d.ts +2 -3
- package/dist/internal/paragraphFormattingSerialization.js +26 -6
- package/dist/layout-bridge/convert/footnoteLayout.js +2 -7
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +2 -2
- package/dist/layout-engine/measure/measureBlocks.js +1 -6
- package/dist/layout-engine/types.d.ts +8 -2
- package/dist/layout-engine/types.js +35 -2
- package/dist/markdown/index.js +1 -1
- package/dist/markdown/internals.d.ts +6 -1
- package/dist/markdown/internals.js +14 -1
- package/dist/markdown/renderBlock.js +35 -21
- package/dist/markdown/renderParagraph.js +14 -5
- package/dist/markdown/renderRuns.js +4 -3
- package/dist/markdown/renderTable.js +4 -3
- package/dist/markdown/trailers.js +41 -7
- package/dist/markdown/types.d.ts +3 -7
- package/dist/prosemirror/attrs/index.js +2 -5
- package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +11 -1
- package/dist/prosemirror/bookmarkBoundaryAttrs.js +18 -3
- package/dist/prosemirror/commands/index.d.ts +3 -3
- package/dist/prosemirror/commands/index.js +2 -2
- package/dist/prosemirror/commands/paragraph.d.ts +3 -3
- package/dist/prosemirror/commands/paragraph.js +2 -2
- package/dist/prosemirror/commentIdAllocator.js +2 -7
- package/dist/prosemirror/conversion/fromProseDoc.js +129 -40
- package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -14
- package/dist/prosemirror/conversion/toProseDoc.js +375 -316
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +14 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +11 -6
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -3
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +4 -1
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +6 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +7 -0
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +74 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +11 -3
- package/dist/prosemirror/extensions/marks/markUtils.js +98 -19
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +7 -3
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +1 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +15 -1
- package/dist/prosemirror/extensions/types.d.ts +2 -2
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/index.js +3 -3
- package/dist/prosemirror/insertOperations.d.ts +9 -2
- package/dist/prosemirror/insertOperations.js +9 -4
- package/dist/prosemirror/paragraphFormattingProvenance.d.ts +159 -0
- package/dist/prosemirror/paragraphFormattingProvenance.js +106 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +9 -1
- package/dist/prosemirror/plugins/documentStyles.js +11 -1
- package/dist/prosemirror/plugins/index.d.ts +2 -2
- package/dist/prosemirror/plugins/index.js +2 -2
- package/dist/prosemirror/plugins/revisionIds.d.ts +11 -2
- package/dist/prosemirror/plugins/revisionIds.js +21 -6
- package/dist/prosemirror/runFormattingReconciliation.js +3 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +1 -1
- package/dist/prosemirror/schema/nodes.d.ts +31 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +2 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +9 -0
- package/dist/prosemirror/styles/styleResolver.js +12 -0
- package/dist/style-engine/styleEngine.d.ts +3 -0
- package/dist/style-engine/styleEngine.js +3 -0
- package/dist/style-sets/extract.js +1 -23
- package/dist/style-sets/stellaStyle.js +46 -39
- package/dist/style-sets/styleSetNormalization.d.ts +19 -0
- package/dist/style-sets/styleSetNormalization.js +99 -0
- package/dist/types/content.d.ts +2 -2
- package/dist/utils/createDocument.js +145 -20
- package/dist/utils/headingCollector.d.ts +8 -5
- package/dist/utils/headingCollector.js +23 -25
- package/dist/utils/tableOfContentsStyle.js +9 -2
- package/package.json +2 -2
- package/dist/docx/textWhitespace.d.ts +0 -4
- package/dist/docx/textWhitespace.js +0 -4
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +0 -6
- package/dist/layout-bridge/engine/tableWidthUtils.js +0 -25
- package/dist/markdown/headings.d.ts +0 -13
- package/dist/markdown/headings.js +0 -20
|
@@ -1,34 +1,32 @@
|
|
|
1
|
+
import { resolveHeadingLevel } from "../docx/builtInStyles.js";
|
|
1
2
|
//#region src/utils/headingCollector.ts
|
|
2
3
|
/**
|
|
3
|
-
* Collect all headings from a ProseMirror document.
|
|
4
|
+
* Collect all headings from a ProseMirror document, in document order.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Classification is {@link resolveHeadingLevel}'s: the paragraph's effective
|
|
7
|
+
* outline level, else the style's built-in `w:name`. Pass the open document's
|
|
8
|
+
* index (`styleResolver.builtInStyles`) so a localized style id such as
|
|
9
|
+
* `Nadpis1` or `berschrift1` resolves through its name rather than falling out
|
|
10
|
+
* of the outline.
|
|
8
11
|
*/
|
|
9
|
-
function collectHeadings(doc) {
|
|
12
|
+
function collectHeadings(doc, styles) {
|
|
10
13
|
const headings = [];
|
|
11
14
|
doc.descendants((node, pos) => {
|
|
12
|
-
if (node.type.name
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
level: effectiveLevel,
|
|
28
|
-
pmPos: pos
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
15
|
+
if (node.type.name !== "paragraph") return;
|
|
16
|
+
const level = resolveHeadingLevel({
|
|
17
|
+
outlineLevel: node.attrs["outlineLevel"],
|
|
18
|
+
styleId: node.attrs["styleId"]
|
|
19
|
+
}, styles);
|
|
20
|
+
if (level === void 0) return;
|
|
21
|
+
let text = "";
|
|
22
|
+
node.forEach((child) => {
|
|
23
|
+
if (child.isText) text += child.text || "";
|
|
24
|
+
});
|
|
25
|
+
if (text.trim()) headings.push({
|
|
26
|
+
text: text.trim(),
|
|
27
|
+
level,
|
|
28
|
+
pmPos: pos
|
|
29
|
+
});
|
|
32
30
|
});
|
|
33
31
|
return headings;
|
|
34
32
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { normalizeStyleName } from "../docx/builtInStyles.js";
|
|
1
2
|
//#region src/utils/tableOfContentsStyle.ts
|
|
2
3
|
const TABLE_OF_CONTENTS_STYLE_ID = /^TOC(?<level>\d*)$/iu;
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Against an already-normalised name, so the same tolerance applies here as in
|
|
6
|
+
* `builtInStyles.ts`: the corpus carries `toc 1`, `TOC 1` and even `TOC 1`
|
|
7
|
+
* with a double space, and a producer that drops the space entirely would
|
|
8
|
+
* otherwise fall out.
|
|
9
|
+
*/
|
|
10
|
+
const TABLE_OF_CONTENTS_STYLE_NAME = /^toc(?<level>\d+)$/u;
|
|
4
11
|
const parsedLevel = (match) => {
|
|
5
12
|
if (!match) return;
|
|
6
13
|
const rawLevel = match.groups?.["level"];
|
|
@@ -9,6 +16,6 @@ const parsedLevel = (match) => {
|
|
|
9
16
|
return Number.isSafeInteger(level) && level > 0 ? level : void 0;
|
|
10
17
|
};
|
|
11
18
|
/** Resolve a built-in TOC entry style without relying on its localized style id. */
|
|
12
|
-
const tableOfContentsStyleLevel = ({ styleId, styleName }) => parsedLevel(TABLE_OF_CONTENTS_STYLE_ID.exec(styleId ?? "")) ?? parsedLevel(TABLE_OF_CONTENTS_STYLE_NAME.exec(styleName ?? ""));
|
|
19
|
+
const tableOfContentsStyleLevel = ({ styleId, styleName }) => parsedLevel(TABLE_OF_CONTENTS_STYLE_ID.exec(styleId ?? "")) ?? parsedLevel(TABLE_OF_CONTENTS_STYLE_NAME.exec(normalizeStyleName(styleName ?? "")));
|
|
13
20
|
//#endregion
|
|
14
21
|
export { tableOfContentsStyleLevel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/folio-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "Headless, framework-neutral core of folio: the OOXML (.docx) parser, document model, ProseMirror integration, and page-layout engine. No React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"document-model",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"perf": "bun scripts/profile-editor.ts"
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@stll/docx-core": "^0.
|
|
124
|
+
"@stll/docx-core": "^0.22.0",
|
|
125
125
|
"@stll/docx-utils": "^0.1.0",
|
|
126
126
|
"@stll/template-conditions": ">=0.4.0 <1.0.0",
|
|
127
127
|
"better-result": "3.0.1",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { document_d_exports } from "../../types/document.js";
|
|
2
|
-
//#region src/layout-bridge/engine/tableWidthUtils.d.ts
|
|
3
|
-
declare function resolveTableWidthPx(width: number | undefined, widthType: document_d_exports.TableWidthType | undefined, containerWidth: number): number | undefined;
|
|
4
|
-
declare function normalizeTableColumnWidths(widths: number[], columnCount: number, targetWidth: number): number[];
|
|
5
|
-
//#endregion
|
|
6
|
-
export { normalizeTableColumnWidths, resolveTableWidthPx };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
//#region src/layout-bridge/engine/tableWidthUtils.ts
|
|
2
|
-
const TWIPS_PER_INCH = 1440;
|
|
3
|
-
const PX_PER_INCH = 96;
|
|
4
|
-
const PCT_DENOMINATOR = 5e3;
|
|
5
|
-
const twipsToPixels = (twips) => twips / TWIPS_PER_INCH * PX_PER_INCH;
|
|
6
|
-
function resolveTableWidthPx(width, widthType, containerWidth) {
|
|
7
|
-
if (width === void 0 || width <= 0) return;
|
|
8
|
-
if (widthType === "dxa") return twipsToPixels(width);
|
|
9
|
-
if (widthType === "pct") return width / PCT_DENOMINATOR * containerWidth;
|
|
10
|
-
}
|
|
11
|
-
function normalizeTableColumnWidths(widths, columnCount, targetWidth) {
|
|
12
|
-
if (columnCount <= 0) return [];
|
|
13
|
-
if (widths.length === 0) return Array.from({ length: columnCount }, () => targetWidth / columnCount);
|
|
14
|
-
const normalized = widths.slice(0, columnCount);
|
|
15
|
-
const positives = normalized.filter((width) => width > 0);
|
|
16
|
-
const fallback = positives.length > 0 ? positives.reduce((sum, width) => sum + width, 0) / positives.length : targetWidth / columnCount;
|
|
17
|
-
while (normalized.length < columnCount) normalized.push(fallback);
|
|
18
|
-
let fixedTotal = 0;
|
|
19
|
-
for (const width of normalized) if (width > 0) fixedTotal += width;
|
|
20
|
-
const missingCount = normalized.filter((width) => width <= 0).length;
|
|
21
|
-
const missingWidth = missingCount > 0 ? Math.max(0, targetWidth - fixedTotal) / missingCount : 0;
|
|
22
|
-
return normalized.map((width) => width > 0 ? width : missingWidth);
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { normalizeTableColumnWidths, resolveTableWidthPx };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/markdown/headings.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Heading-style detection from a paragraph style id. Ported from eigenpal
|
|
4
|
-
* `agent/text-utils` (PR #595) so the markdown exporter stays self-contained
|
|
5
|
-
* (folio has no `agent/text-utils` module). Word's built-in heading styles are
|
|
6
|
-
* `Heading1`…`Heading9` (and localised aliases that still contain "heading").
|
|
7
|
-
*/
|
|
8
|
-
/** True when the style id denotes a Word heading style. */
|
|
9
|
-
declare function isHeadingStyle(styleId?: string): boolean;
|
|
10
|
-
/** Extract the 1-based heading level from a style id, or undefined. */
|
|
11
|
-
declare function parseHeadingLevel(styleId?: string): number | undefined;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { isHeadingStyle, parseHeadingLevel };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/markdown/headings.ts
|
|
2
|
-
/**
|
|
3
|
-
* Heading-style detection from a paragraph style id. Ported from eigenpal
|
|
4
|
-
* `agent/text-utils` (PR #595) so the markdown exporter stays self-contained
|
|
5
|
-
* (folio has no `agent/text-utils` module). Word's built-in heading styles are
|
|
6
|
-
* `Heading1`…`Heading9` (and localised aliases that still contain "heading").
|
|
7
|
-
*/
|
|
8
|
-
/** True when the style id denotes a Word heading style. */
|
|
9
|
-
function isHeadingStyle(styleId) {
|
|
10
|
-
if (!styleId) return false;
|
|
11
|
-
return styleId.toLowerCase().includes("heading");
|
|
12
|
-
}
|
|
13
|
-
/** Extract the 1-based heading level from a style id, or undefined. */
|
|
14
|
-
function parseHeadingLevel(styleId) {
|
|
15
|
-
if (!styleId) return;
|
|
16
|
-
const digit = /heading\s*(?<level>\d)/iu.exec(styleId)?.groups?.["level"];
|
|
17
|
-
if (digit) return Number.parseInt(digit, 10);
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { isHeadingStyle, parseHeadingLevel };
|