@sobree/core 0.1.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/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/__vite-browser-external-DYxpcVy9.js +5 -0
- package/dist/__vite-browser-external-DYxpcVy9.js.map +1 -0
- package/dist/blob/cache.d.ts +69 -0
- package/dist/blob/fetch.d.ts +18 -0
- package/dist/blob/hash.d.ts +13 -0
- package/dist/blob/index.d.ts +33 -0
- package/dist/blob/memory.d.ts +2 -0
- package/dist/blob/types.d.ts +80 -0
- package/dist/createSobree.d.ts +132 -0
- package/dist/doc/api.d.ts +132 -0
- package/dist/doc/builders.d.ts +42 -0
- package/dist/doc/pageSetupBridge.d.ts +26 -0
- package/dist/doc/parts.d.ts +18 -0
- package/dist/doc/runs.d.ts +47 -0
- package/dist/doc/styles.d.ts +19 -0
- package/dist/doc/types.d.ts +800 -0
- package/dist/doc/walk.d.ts +30 -0
- package/dist/docx/export/contentTypes.d.ts +35 -0
- package/dist/docx/export/context.d.ts +59 -0
- package/dist/docx/export/document.d.ts +19 -0
- package/dist/docx/export/drawings.d.ts +10 -0
- package/dist/docx/export/headers.d.ts +19 -0
- package/dist/docx/export/index.d.ts +14 -0
- package/dist/docx/export/runs.d.ts +8 -0
- package/dist/docx/export/styles.d.ts +8 -0
- package/dist/docx/export/zip.d.ts +13 -0
- package/dist/docx/import/anchoredFrames.d.ts +34 -0
- package/dist/docx/import/comments.d.ts +3 -0
- package/dist/docx/import/document.d.ts +57 -0
- package/dist/docx/import/flowFrames.d.ts +11 -0
- package/dist/docx/import/footnotes.d.ts +3 -0
- package/dist/docx/import/headers.d.ts +50 -0
- package/dist/docx/import/index.d.ts +12 -0
- package/dist/docx/import/inlineFrames.d.ts +62 -0
- package/dist/docx/import/numbering.d.ts +2 -0
- package/dist/docx/import/paragraph.d.ts +24 -0
- package/dist/docx/import/paragraphs.d.ts +27 -0
- package/dist/docx/import/rels.d.ts +5 -0
- package/dist/docx/import/runs.d.ts +64 -0
- package/dist/docx/import/settings.d.ts +48 -0
- package/dist/docx/import/styles.d.ts +3 -0
- package/dist/docx/import/tables.d.ts +12 -0
- package/dist/docx/import/unzip.d.ts +13 -0
- package/dist/docx/shared/namespaces.d.ts +31 -0
- package/dist/docx/shared/pageSize.d.ts +27 -0
- package/dist/docx/shared/shading.d.ts +2 -0
- package/dist/docx/shared/units.d.ts +35 -0
- package/dist/docx/shared/xml.d.ts +29 -0
- package/dist/docx/types.d.ts +98 -0
- package/dist/editor/index.d.ts +1078 -0
- package/dist/editor/internal/blockRegistry.d.ts +91 -0
- package/dist/editor/internal/mutations.d.ts +63 -0
- package/dist/editor/internal/positionMap.d.ts +35 -0
- package/dist/editor/table.d.ts +96 -0
- package/dist/editor/view/docRenderer/anchorLayer.d.ts +26 -0
- package/dist/editor/view/docRenderer/block.d.ts +13 -0
- package/dist/editor/view/docRenderer/fontFallback.d.ts +28 -0
- package/dist/editor/view/docRenderer/index.d.ts +18 -0
- package/dist/editor/view/docRenderer/inline.d.ts +15 -0
- package/dist/editor/view/docRenderer/inlineFrame.d.ts +4 -0
- package/dist/editor/view/docRenderer/lists.d.ts +28 -0
- package/dist/editor/view/docRenderer/paragraph.d.ts +2 -0
- package/dist/editor/view/docRenderer/properties.d.ts +2 -0
- package/dist/editor/view/docRenderer/table.d.ts +15 -0
- package/dist/editor/view/docRenderer/units.d.ts +48 -0
- package/dist/editor/view/docSerialize/block.d.ts +14 -0
- package/dist/editor/view/docSerialize/index.d.ts +8 -0
- package/dist/editor/view/docSerialize/inline.d.ts +11 -0
- package/dist/editor/view/docSerialize/table.d.ts +12 -0
- package/dist/editor/view/imageResize.d.ts +16 -0
- package/dist/embed/floatingCorner.d.ts +44 -0
- package/dist/embed/viewport.d.ts +133 -0
- package/dist/fonts/embedAPI.d.ts +33 -0
- package/dist/fonts/emit.d.ts +24 -0
- package/dist/fonts/fontFaceRegistry.d.ts +20 -0
- package/dist/fonts/fsType.d.ts +36 -0
- package/dist/fonts/index.d.ts +19 -0
- package/dist/fonts/liveness.d.ts +2 -0
- package/dist/fonts/odttf.d.ts +33 -0
- package/dist/fonts/parse.d.ts +29 -0
- package/dist/fonts/types.d.ts +52 -0
- package/dist/headless.d.ts +168 -0
- package/dist/history/history.d.ts +100 -0
- package/dist/history/index.d.ts +4 -0
- package/dist/history/types.d.ts +54 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +10561 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown/parse.d.ts +6 -0
- package/dist/pagination/cost.d.ts +32 -0
- package/dist/pagination/index.d.ts +2 -0
- package/dist/pagination/paginate.d.ts +10 -0
- package/dist/pagination/postConditions.d.ts +10 -0
- package/dist/pagination/types.d.ts +94 -0
- package/dist/paperStack/pageSetup.d.ts +42 -0
- package/dist/paperStack/paginationAdapter/buildItems.d.ts +19 -0
- package/dist/paperStack/paginationAdapter/distribute.d.ts +23 -0
- package/dist/paperStack/paginationAdapter/index.d.ts +18 -0
- package/dist/paperStack/paginationAdapter/paragraphLines.d.ts +23 -0
- package/dist/paperStack/paginationAdapter/splitList.d.ts +19 -0
- package/dist/paperStack/paginationAdapter/splitParagraph.d.ts +21 -0
- package/dist/paperStack/paginationAdapter/types.d.ts +30 -0
- package/dist/paperStack/paper.d.ts +107 -0
- package/dist/paperStack/paperStack.d.ts +245 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/plugins/marks.d.ts +49 -0
- package/dist/plugins/sections.d.ts +15 -0
- package/dist/presence/attach.d.ts +48 -0
- package/dist/presence/awareness.d.ts +28 -0
- package/dist/presence/index.d.ts +19 -0
- package/dist/presence/overlay.d.ts +28 -0
- package/dist/presence/state.d.ts +36 -0
- package/dist/sobree.d.ts +211 -0
- package/dist/tokens.css +144 -0
- package/dist/util/selection.d.ts +13 -0
- package/dist/ydoc/apply.d.ts +68 -0
- package/dist/ydoc/index.d.ts +18 -0
- package/dist/ydoc/project.d.ts +41 -0
- package/dist/ydoc/runs.d.ts +51 -0
- package/dist/ydoc/schema.d.ts +123 -0
- package/dist/ydoc/seed.d.ts +45 -0
- package/dist/ydoc/textDiff.d.ts +59 -0
- package/dist/zoneEdit/index.d.ts +22 -0
- package/package.json +61 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConvertContext } from './paragraph';
|
|
2
|
+
import { Table } from '../../doc/types';
|
|
3
|
+
/**
|
|
4
|
+
* Convert a `<w:tbl>` element into a native Table block. Handles:
|
|
5
|
+
* - Column widths from `<w:tblGrid>` (twips).
|
|
6
|
+
* - Horizontal merges via `<w:gridSpan>`.
|
|
7
|
+
* - Vertical merges via `<w:vMerge>` (restart / continue).
|
|
8
|
+
* - Header rows flagged with `<w:tblHeader/>` in `<w:trPr>`.
|
|
9
|
+
* - Cell vertical alignment via `<w:vAlign>`.
|
|
10
|
+
* - Cell content as a sequence of Blocks (paragraphs, nested tables).
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertTable(tbl: Element, ctx: ConvertContext): Table;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a .docx file into a map of part-path → UTF-8 text for the parts we
|
|
3
|
+
* need as strings (all the `*.xml` parts), and bytes for the parts we need
|
|
4
|
+
* as binary (images, fonts). Kept synchronous: fflate is fast enough that a
|
|
5
|
+
* 100-page document unpacks in milliseconds on the main thread.
|
|
6
|
+
*/
|
|
7
|
+
export interface UnzippedDocx {
|
|
8
|
+
/** `word/document.xml` → text, `word/styles.xml` → text, etc. */
|
|
9
|
+
readonly text: Record<string, string>;
|
|
10
|
+
/** `word/media/image1.png` → bytes. */
|
|
11
|
+
readonly binary: Record<string, Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
export declare function unzipDocx(src: File | Blob | ArrayBuffer | Uint8Array): Promise<UnzippedDocx>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OOXML namespace URIs. The spec uses a rich set of prefixes
|
|
3
|
+
* (`w:`, `r:`, `wp:` …); we keep them as constants so both the
|
|
4
|
+
* importer and exporter reference the same strings. Typos here
|
|
5
|
+
* are silent parse failures, so: one source of truth.
|
|
6
|
+
*/
|
|
7
|
+
export declare const NS: {
|
|
8
|
+
/** WordprocessingML — the main body namespace. */
|
|
9
|
+
readonly w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
10
|
+
/** Relationships (images, headers, hyperlinks). */
|
|
11
|
+
readonly r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
12
|
+
/** DrawingML — image anchors and inline drawings. */
|
|
13
|
+
readonly wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
|
|
14
|
+
/** DrawingML core. */
|
|
15
|
+
readonly a: "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
16
|
+
/** Picture (DrawingML). */
|
|
17
|
+
readonly pic: "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
18
|
+
/** Word-processing shapes (textboxes, geometric primitives). */
|
|
19
|
+
readonly wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
20
|
+
/** Word-processing groups (containers for shapes / pictures). */
|
|
21
|
+
readonly wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
|
|
22
|
+
/** VML — the legacy `<v:shape>` / `<w:pict>` path Word still emits
|
|
23
|
+
* for OLE-embedded images and some compatibility shapes. */
|
|
24
|
+
readonly v: "urn:schemas-microsoft-com:vml";
|
|
25
|
+
/** Relationships package part. */
|
|
26
|
+
readonly rel: "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
27
|
+
/** Content types. */
|
|
28
|
+
readonly ct: "http://schemas.openxmlformats.org/package/2006/content-types";
|
|
29
|
+
};
|
|
30
|
+
/** Minimal attr mapping we emit on `<w:document>` (only the namespaces we use). */
|
|
31
|
+
export declare const ROOT_DOCUMENT_ATTRS: Record<string, string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Orientation, PageSizeKey } from '../../paperStack/pageSetup';
|
|
2
|
+
export interface PageGeometry {
|
|
3
|
+
size: PageSizeKey;
|
|
4
|
+
orientation: Orientation;
|
|
5
|
+
margins: {
|
|
6
|
+
top: number;
|
|
7
|
+
right: number;
|
|
8
|
+
bottom: number;
|
|
9
|
+
left: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve twips W×H back to a named page size at a given orientation. If it
|
|
14
|
+
* doesn't match a known size within a small tolerance, return the nearest
|
|
15
|
+
* one — users editing a custom-sized doc in Sobree still get a sensible
|
|
16
|
+
* landing spot, and the exact dimensions come back on export because we
|
|
17
|
+
* write our own sectPr anyway.
|
|
18
|
+
*/
|
|
19
|
+
export declare function matchPageSize(widthTwips: number, heightTwips: number): {
|
|
20
|
+
size: PageSizeKey;
|
|
21
|
+
orientation: Orientation;
|
|
22
|
+
};
|
|
23
|
+
/** Convert a PageSetup's logical size+orientation to the twip W/H pair. */
|
|
24
|
+
export declare function geometryToTwips(geom: PageGeometry): {
|
|
25
|
+
w: number;
|
|
26
|
+
h: number;
|
|
27
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OOXML unit conversions. Word mixes several units throughout the spec:
|
|
3
|
+
* - **Half-points** (`w:sz`, `w:szCs`) — divide by 2 to get pt.
|
|
4
|
+
* - **Twentieths of a point** aka "twips" (`w:spacing`, page margins in
|
|
5
|
+
* `w:pgMar`) — divide by 20 to get pt, by 567 to get mm.
|
|
6
|
+
* - **EMU** (English Metric Units, `wp:extent`) — 914400 per inch,
|
|
7
|
+
* 360000 per cm.
|
|
8
|
+
* - **Half-points via `w:line` for line spacing** — when `w:lineRule="auto"`,
|
|
9
|
+
* the value is twentieths-of-a-point multiplied by a factor: 240 twips
|
|
10
|
+
* = single-spacing.
|
|
11
|
+
*
|
|
12
|
+
* One file, one place to get them wrong or right.
|
|
13
|
+
*/
|
|
14
|
+
/** Half-point integer → floating-point pt. */
|
|
15
|
+
export declare const halfPtToPt: (n: number) => number;
|
|
16
|
+
/** Floating-point pt → rounded half-point integer. */
|
|
17
|
+
export declare const ptToHalfPt: (pt: number) => number;
|
|
18
|
+
/** EMU → CSS px (assuming 96 DPI). */
|
|
19
|
+
export declare const emuToPx: (emu: number) => number;
|
|
20
|
+
/** CSS px → EMU. */
|
|
21
|
+
export declare const pxToEmu: (px: number) => number;
|
|
22
|
+
/** Twips → mm. */
|
|
23
|
+
export declare const twipsToMm: (t: number) => number;
|
|
24
|
+
/** mm → twips. */
|
|
25
|
+
export declare const mmToTwips: (mm: number) => number;
|
|
26
|
+
/** Twips → pt. */
|
|
27
|
+
export declare const twipsToPt: (t: number) => number;
|
|
28
|
+
/** pt → twips. */
|
|
29
|
+
export declare const ptToTwips: (pt: number) => number;
|
|
30
|
+
/**
|
|
31
|
+
* `w:line` for line spacing in "auto" mode: 240 twips = single-spacing.
|
|
32
|
+
* So `line-height: 1.5` → `240 * 1.5 = 360`.
|
|
33
|
+
*/
|
|
34
|
+
export declare const lineHeightToOoxml: (lineHeight: number) => number;
|
|
35
|
+
export declare const ooxmlLineHeightToCss: (line: number) => number;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin wrappers around the browser's `DOMParser` and `XMLSerializer`.
|
|
3
|
+
* Pure functions; keep anything stateful (caches, registries) out of this
|
|
4
|
+
* file. One helper per concern so call sites stay readable.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseXml(src: string): Document;
|
|
7
|
+
export declare function serializeXml(node: Node): string;
|
|
8
|
+
/** Get the first descendant element in the WordprocessingML namespace. */
|
|
9
|
+
export declare function wFirst(root: Document | Element, localName: string): Element | null;
|
|
10
|
+
/** Get all descendants in the WordprocessingML namespace. */
|
|
11
|
+
export declare function wAll(root: Document | Element, localName: string): Element[];
|
|
12
|
+
/** Get direct-child elements in the WordprocessingML namespace. */
|
|
13
|
+
export declare function wChildren(parent: Element, localName: string): Element[];
|
|
14
|
+
/**
|
|
15
|
+
* Read a `w:val` attribute, Word's standard way of carrying a single value.
|
|
16
|
+
* Accepts either namespaced or non-namespaced attribute lookup since
|
|
17
|
+
* serialised documents differ.
|
|
18
|
+
*/
|
|
19
|
+
export declare function wVal(el: Element | null): string | null;
|
|
20
|
+
/** Build an XML declaration header + root element. Used by the exporter. */
|
|
21
|
+
export declare function xmlDocument(rootXml: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Emit a single element as a string. Attributes are rendered in insertion
|
|
24
|
+
* order; children are pre-serialized strings. Prefers a tiny, composable
|
|
25
|
+
* string builder over a virtual DOM — the OOXML shapes we emit are flat
|
|
26
|
+
* enough that this is clearer than juggling `document.createElementNS`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function el(tag: string, attrs?: Record<string, string | number | undefined> | null, children?: string[] | string | null): string;
|
|
29
|
+
export declare function escapeXmlText(s: string): string;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight OOXML-flavoured types used by the DOCX importer/exporter.
|
|
3
|
+
*
|
|
4
|
+
* These are NOT a general OOXML model — they carry only the fields we
|
|
5
|
+
* actually care about. Anything unknown is dropped (and logged to the
|
|
6
|
+
* warnings channel by the caller).
|
|
7
|
+
*/
|
|
8
|
+
/** Result of an `importDocx()` call — the SobreeDocument plus any warnings. */
|
|
9
|
+
export interface DocxImportResult {
|
|
10
|
+
document: import('../doc/types').SobreeDocument;
|
|
11
|
+
warnings: string[];
|
|
12
|
+
}
|
|
13
|
+
/** Result of an `exportDocx()` call. */
|
|
14
|
+
export interface DocxExportResult {
|
|
15
|
+
blob: Blob;
|
|
16
|
+
bytes: Uint8Array;
|
|
17
|
+
warnings: string[];
|
|
18
|
+
}
|
|
19
|
+
/** A single inline run's formatting flags — what `<w:rPr>` tells us. */
|
|
20
|
+
export interface RunFormat {
|
|
21
|
+
bold?: boolean;
|
|
22
|
+
italic?: boolean;
|
|
23
|
+
underline?: boolean;
|
|
24
|
+
strike?: boolean;
|
|
25
|
+
/** `<w:caps/>` — render the run with `text-transform: uppercase`. */
|
|
26
|
+
caps?: boolean;
|
|
27
|
+
/** CSS-ready `#rrggbb`. */
|
|
28
|
+
color?: string;
|
|
29
|
+
/** Highlight colour name or CSS-ready `#rrggbb`. */
|
|
30
|
+
highlight?: string;
|
|
31
|
+
/** CSS-ready `font-family` value. */
|
|
32
|
+
fontFamily?: string;
|
|
33
|
+
/** Size in pt. */
|
|
34
|
+
fontSizePt?: number;
|
|
35
|
+
verticalAlign?: "subscript" | "superscript";
|
|
36
|
+
/**
|
|
37
|
+
* `<w:rPrChange>` — a snapshot of the run's properties before the
|
|
38
|
+
* most recent tracked format edit. The inner `<w:rPr>` is parsed
|
|
39
|
+
* into the same `RunFormat` shape (recursion-free: the snapshot
|
|
40
|
+
* itself doesn't carry an `revisionFormat`).
|
|
41
|
+
*/
|
|
42
|
+
revisionFormat?: {
|
|
43
|
+
before: RunFormat;
|
|
44
|
+
author?: string;
|
|
45
|
+
date?: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Paragraph-level formatting — from `<w:pPr>`. */
|
|
49
|
+
export interface ParagraphFormat {
|
|
50
|
+
/** 1..6 if the paragraph carries a `Heading{N}` style; 0 otherwise. */
|
|
51
|
+
headingLevel?: number;
|
|
52
|
+
/** Verbatim `w:pStyle` value (`ListParagraph`, `BodyText`, …). Carries
|
|
53
|
+
* the cascade anchor for non-heading paragraphs — without it, the
|
|
54
|
+
* renderer falls back to Normal and any style-defined spacing /
|
|
55
|
+
* indent / font is lost. */
|
|
56
|
+
styleId?: string;
|
|
57
|
+
alignment?: "left" | "center" | "right" | "justify";
|
|
58
|
+
/** Parsed `w:line` / `w:lineRule` into a CSS `line-height` multiplier. */
|
|
59
|
+
lineHeight?: number;
|
|
60
|
+
/** Explicit `<w:spacing w:after>` in twips. Stored as-is (including
|
|
61
|
+
* 0) so the value overrides cascaded defaults. */
|
|
62
|
+
spacingAfterTwips?: number;
|
|
63
|
+
/** Explicit `<w:spacing w:before>` in twips. */
|
|
64
|
+
spacingBeforeTwips?: number;
|
|
65
|
+
/** Raw numbering reference (`numId`, `ilvl`) if this para is part of a list. */
|
|
66
|
+
numId?: number;
|
|
67
|
+
numLevel?: number;
|
|
68
|
+
/** Paragraph indentation (`<w:ind w:left/right/firstLine/hanging>`). */
|
|
69
|
+
indent?: import('../doc/types').ParagraphIndent;
|
|
70
|
+
/** Custom tab stops from `<w:pPr><w:tabs>` — positions in twips,
|
|
71
|
+
* alignment ("left" / "center" / "right" / "decimal"), and optional
|
|
72
|
+
* leader (dots / dashes / etc.). Translated to CSS by the renderer. */
|
|
73
|
+
tabStops?: {
|
|
74
|
+
positionTwips: number;
|
|
75
|
+
alignment: string;
|
|
76
|
+
leader?: string;
|
|
77
|
+
}[];
|
|
78
|
+
/** Font properties of the paragraph mark itself, from
|
|
79
|
+
* `<w:pPr><w:rPr>`. Used by the renderer to size the paragraph's
|
|
80
|
+
* line height when there are no inline runs to provide a font. */
|
|
81
|
+
markFormat?: {
|
|
82
|
+
fontFamily?: string;
|
|
83
|
+
fontSizePt?: number;
|
|
84
|
+
};
|
|
85
|
+
/** Paragraph background colour (`<w:shd w:fill="…">`). */
|
|
86
|
+
shading?: import('../doc/types').Shading;
|
|
87
|
+
/** Paragraph borders (`<w:pBdr>` — top / bottom / left / right /
|
|
88
|
+
* between). Used for inline rules like the dotted divider Word
|
|
89
|
+
* draws beneath the page-header text on complex-multipage.docx. */
|
|
90
|
+
borders?: import('../doc/types').ParagraphProperties["borders"];
|
|
91
|
+
/**
|
|
92
|
+
* Paragraph-mark revision (`<w:pPr><w:rPr><w:ins/></w:rPr></w:pPr>`).
|
|
93
|
+
* Semantically: the paragraph break that *precedes* this paragraph
|
|
94
|
+
* is a tracked change. See `ParagraphProperties.revision` for the
|
|
95
|
+
* accept/reject contract.
|
|
96
|
+
*/
|
|
97
|
+
revision?: import('../doc/types').RevisionMark;
|
|
98
|
+
}
|