@maxoyed/ode-core 0.0.1

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * 公文字号(中文“号”制)与磅值(pt)对照表。
3
+ *
4
+ * 中国大陆排版沿用“号”制字号,GB/T 9704-2012《党政机关公文格式》中
5
+ * 各要素的字号均以“号”表示(如正文为 3 号字)。此处给出号制到磅值的
6
+ * 标准换算,供排版引擎与 docx 导出(OOXML 以半磅为单位)复用。
7
+ */
8
+ type ChineseFontSizeName = "初号" | "小初" | "一号" | "小一" | "二号" | "小二" | "三号" | "小三" | "四号" | "小四" | "五号" | "小五" | "六号" | "小六" | "七号" | "八号";
9
+ /** 号制字号 → 磅值(pt) */
10
+ declare const FONT_SIZE_PT: Record<ChineseFontSizeName, number>;
11
+ /** 1 磅(pt)= 1/72 英寸 = 25.4/72 毫米 */
12
+ declare const PT_TO_MM: number;
13
+ /** 1 磅(pt)按 96dpi 屏幕 = 96/72 像素 */
14
+ declare const PT_TO_PX: number;
15
+ /** 号制字号转磅值;传入数字则原样返回(已是磅值)。 */
16
+ declare function toPt(size: ChineseFontSizeName | number): number;
17
+ /** 号制字号转毫米。 */
18
+ declare function ptToMm(pt: number): number;
19
+ /** 号制字号转 CSS px(96dpi)。 */
20
+ declare function ptToPx(pt: number): number;
21
+ /** OOXML(docx)中字号以半磅(half-point)为单位,<w:sz w:val="32"/> 表示 16pt。 */
22
+ declare function toHalfPoint(size: ChineseFontSizeName | number): number;
23
+
24
+ /**
25
+ * 公文字体角色(与 GB/T 9704-2012 各要素字体要求对应)。
26
+ *
27
+ * ⚠️ 字体版权说明:
28
+ * 仿宋_GB2312、楷体_GB2312、方正小标宋 等公文常用字体多为商业字体,
29
+ * 本库不内置其字体文件,仅在 CSS 中通过 `local()` 优先引用用户系统已安装的
30
+ * 公文字体,并以可商用开源字体(思源宋体 / 思源黑体等)兜底。
31
+ * 如需在离线环境精确还原,请通过 registerFont() 由使用方自行提供授权字体。
32
+ */
33
+ type FontRole = "xiaobiaosong" | "fangsong" | "heiti" | "kaiti" | "songti";
34
+ /** 各字体角色的 CSS font-family 兜底栈(优先本机公文字体 → 开源字体 → 通用族)。 */
35
+ declare const FONT_STACK: Record<FontRole, string>;
36
+ /** CSS 变量名,运行时可被 registerFont() 覆盖以接入授权字体。 */
37
+ declare const FONT_CSS_VAR: Record<FontRole, string>;
38
+
39
+ /**
40
+ * GB/T 9704-2012 各公文要素的排版规格。
41
+ *
42
+ * 每个要素给出字体角色、字号(号制)、对齐、缩进(以“字”为单位)、颜色等,
43
+ * 供 Tiptap 节点渲染与 docx 导出共享同一份“事实来源”。
44
+ */
45
+
46
+ interface ElementSpec {
47
+ /** 字体角色 */
48
+ font: FontRole;
49
+ /** 字号(号制) */
50
+ size: ChineseFontSizeName;
51
+ /** 是否加粗 */
52
+ bold?: boolean;
53
+ /** 水平对齐 */
54
+ align?: "left" | "center" | "right" | "justify";
55
+ /** 首行缩进(字) */
56
+ indent?: number;
57
+ /** 整体左空(字) */
58
+ marginLeft?: number;
59
+ /** 整体右空(字) */
60
+ marginRight?: number;
61
+ /** 颜色(默认黑色 #000,红头为红色) */
62
+ color?: string;
63
+ }
64
+ /** 公文标准红色(发文机关标志、分隔线)。GB/T 9704 未规定具体值,实务常用正红。 */
65
+ declare const OFFICIAL_RED = "#e60012";
66
+ type OfficialElement = "copyNumber" | "secrecy" | "urgency" | "issuer" | "docNumber" | "signer" | "title" | "mainRecipient" | "body" | "headingLevel1" | "headingLevel2" | "headingLevel3" | "headingLevel4" | "attachmentNote" | "signature" | "dateline" | "note" | "ccOrgan" | "printOrgan" | "pageNumber";
67
+ declare const ELEMENT_SPEC: Record<OfficialElement, ElementSpec>;
68
+
69
+ export { type ChineseFontSizeName as C, ELEMENT_SPEC as E, type FontRole as F, type OfficialElement as O, PT_TO_MM as P, type ElementSpec as a, FONT_CSS_VAR as b, FONT_SIZE_PT as c, FONT_STACK as d, OFFICIAL_RED as e, PT_TO_PX as f, ptToPx as g, toPt as h, ptToMm as p, toHalfPoint as t };
@@ -0,0 +1,176 @@
1
+ export { CHARS_PER_LINE, CHAR_BOX_MM, LINES_PER_PAGE, LINE_HEIGHT_MM, Layout, LayoutSpec, MARGIN_MM, PAGE_A4_MM, TYPE_AREA_MM } from './spec/index.js';
2
+ import { O as OfficialElement, F as FontRole } from './elements-Bvueu_TD.js';
3
+ export { C as ChineseFontSizeName, E as ELEMENT_SPEC, a as ElementSpec, b as FONT_CSS_VAR, c as FONT_SIZE_PT, d as FONT_STACK, e as OFFICIAL_RED, P as PT_TO_MM, f as PT_TO_PX, p as ptToMm, g as ptToPx, t as toHalfPoint, h as toPt } from './elements-Bvueu_TD.js';
4
+ export { BODY_LINE_HEIGHT_PT, BlockRect, DASH, PAGE_NUMBER_OFFSET_MM, Page, PageBreak, PageBreakOptions, PageBreakResult, PageFragment, PageNumberAlign, PageNumberStyle, PaginateOptions, PaginationBlock, TYPE_AREA_HEIGHT_PT, blocksFromDoc, charsPerLineFor, computePageBreaks, countPages, estimateLines, formatPageNumber, lineHeightPtFor, pageNumberAlign, pageNumberStyle, paginate } from './pagination/index.js';
5
+ import * as _tiptap_core from '@tiptap/core';
6
+ import { Extension, Extensions, JSONContent, EditorOptions, Editor } from '@tiptap/core';
7
+ export { Editor, JSONContent } from '@tiptap/core';
8
+ import * as _tiptap_extension_image from '@tiptap/extension-image';
9
+
10
+ /**
11
+ * OfficialRole 扩展:为块级节点附加“公文要素角色”属性。
12
+ *
13
+ * 不直接写死样式,而是输出 data-odoc-role 与 class,由公文样式表(按 ELEMENT_SPEC
14
+ * 生成)统一渲染字体/字号/对齐/缩进,保证渲染与 docx 导出共享同一份规范。
15
+ */
16
+
17
+ declare module "@tiptap/core" {
18
+ interface Commands<ReturnType> {
19
+ officialRole: {
20
+ /** 将当前段落设为指定公文要素(如 title、headingLevel1、dateline)。 */
21
+ setOfficialRole: (role: OfficialElement) => ReturnType;
22
+ /** 清除当前段落的公文要素角色(回退为普通正文)。 */
23
+ unsetOfficialRole: () => ReturnType;
24
+ };
25
+ }
26
+ }
27
+ interface OfficialRoleOptions {
28
+ /** 应用角色属性的节点类型,默认作用于 paragraph。 */
29
+ types: string[];
30
+ }
31
+ declare const OfficialRole: Extension<OfficialRoleOptions, any>;
32
+
33
+ declare const OfficialImage: _tiptap_core.Node<_tiptap_extension_image.ImageOptions, any>;
34
+
35
+ /**
36
+ * 为分隔线(horizontalRule)增加公文变体属性:
37
+ * - reverse:红头反线(发文字号下方红色分隔线,默认)
38
+ * - record:版记分隔线(版记区上下黑色全幅线)
39
+ *
40
+ * 仅附加 data 属性与 class,颜色由样式表渲染;docx 导出/导入据此区分边框颜色。
41
+ */
42
+
43
+ type HrVariant = "reverse" | "record";
44
+ declare module "@tiptap/core" {
45
+ interface Commands<ReturnType> {
46
+ hrVariant: {
47
+ /** 插入指定变体的分隔线 */
48
+ setHorizontalRuleVariant: (variant: HrVariant) => ReturnType;
49
+ };
50
+ }
51
+ }
52
+ interface HrVariantOptions {
53
+ types: string[];
54
+ }
55
+ declare const HorizontalRuleVariant: Extension<HrVariantOptions, any>;
56
+
57
+ /**
58
+ * 编辑器内联实时分页(Tiptap/ProseMirror 扩展)。
59
+ *
60
+ * 测量可编辑区内各顶层块的真实位置,借助 headless computePageBreaks 计算断点,
61
+ * 以 widget 装饰插入“分页间隔”,把单一 contenteditable 可视化为多张 A4 页面,
62
+ * 并在每页版心下方编排页码(单页居右、双页居左空一字)。
63
+ *
64
+ * 说明:本扩展依赖浏览器布局,需在真实浏览器中目视核对;为可选扩展,
65
+ * 不影响默认编辑器。断页几何(computePageBreaks)已单测覆盖。
66
+ * v1 以块为断页粒度,超长段落跨页断行留待后续。
67
+ */
68
+
69
+ interface PaginationOptions {
70
+ /** 每页版心内容高度(px),默认 225mm */
71
+ pageContentPx: number;
72
+ /** 页间视觉间隔(px) */
73
+ pageGapPx: number;
74
+ /** 天头(上白边)px,用于页间留白 */
75
+ topMarginPx: number;
76
+ /** 地脚(下白边)px,用于页间留白 */
77
+ bottomMarginPx: number;
78
+ /** 是否渲染页码 */
79
+ showPageNumbers: boolean;
80
+ }
81
+ declare const Pagination: Extension<PaginationOptions, any>;
82
+
83
+ interface OfficialExtensionsOptions {
84
+ /** 占位提示文字 */
85
+ placeholder?: string;
86
+ /** 是否启用编辑器内联实时分页(默认关闭,需浏览器环境) */
87
+ pagination?: boolean;
88
+ }
89
+ declare function getOfficialExtensions(options?: OfficialExtensionsOptions): Extensions;
90
+
91
+ /**
92
+ * 公文模板:返回 Tiptap/ProseMirror JSON 文档内容。
93
+ * 让编辑器“开箱即默认公文版式”,使用方可直接加载或在此基础上修改。
94
+ */
95
+
96
+ /** 标准红头文件(下行文)骨架模板。 */
97
+ declare function redHeadDocumentTemplate(): JSONContent;
98
+ /** 空白公文(仅一个正文段落)。 */
99
+ declare function blankDocumentTemplate(): JSONContent;
100
+
101
+ /**
102
+ * createOfficialDocumentEditor —— headless 公文编辑器工厂。
103
+ *
104
+ * 基于 Tiptap,与具体前端框架无关;Vue/React 适配层只需在其上做薄封装。
105
+ * 创建时自动注入公文要素样式,并默认加载公文版式模板。
106
+ */
107
+
108
+ interface OfficialEditorOptions extends Partial<Omit<EditorOptions, "extensions" | "content">> {
109
+ /** 挂载元素(headless 使用可不传,自行渲染) */
110
+ element?: EditorOptions["element"];
111
+ /** 初始内容;缺省加载标准红头文件模板 */
112
+ content?: JSONContent | string;
113
+ /** 占位提示 */
114
+ placeholder?: string;
115
+ /** 是否自动注入公文要素样式(默认 true) */
116
+ injectStyles?: boolean;
117
+ /** 是否启用编辑器内联实时分页(默认 false,需浏览器环境) */
118
+ pagination?: boolean;
119
+ }
120
+ declare function createOfficialDocumentEditor(options?: OfficialEditorOptions): Editor;
121
+
122
+ /**
123
+ * 字体插槽:允许使用方在运行时注入授权公文字体,覆盖默认开源兜底栈。
124
+ *
125
+ * 适用于内网 / 离线环境需要精确还原仿宋_GB2312、方正小标宋等商业字体的场景,
126
+ * 字体文件由使用方自行提供并保证授权合规,本库不分发任何商业字体。
127
+ */
128
+
129
+ interface RegisterFontOptions {
130
+ /** 对应的公文字体角色 */
131
+ role: FontRole;
132
+ /** font-family 名称(将注入 @font-face 并设为该角色的最高优先级) */
133
+ family: string;
134
+ /** 字体文件来源:URL 字符串、ArrayBuffer、或 Blob */
135
+ source?: string | ArrayBuffer | Blob;
136
+ /** @font-face 格式提示,如 'woff2'、'truetype' */
137
+ format?: string;
138
+ /** 字重 */
139
+ weight?: string | number;
140
+ /** 作用范围根节点,默认 document.documentElement */
141
+ target?: HTMLElement;
142
+ }
143
+ /**
144
+ * 注册一个公文字体到指定角色。注册后该角色立即使用此字体(最高优先级)。
145
+ *
146
+ * @example
147
+ * registerFont({ role: "fangsong", family: "FangSong_GB2312", source: "/fonts/fs.woff2", format: "woff2" });
148
+ */
149
+ declare function registerFont(options: RegisterFontOptions): void;
150
+
151
+ /** 生成全部公文要素样式的 CSS 文本。 */
152
+ declare function buildElementStyles(): string;
153
+ /** 将公文要素样式注入页面(幂等,仅注入一次)。SSR 环境下静默跳过。 */
154
+ declare function injectOfficialStyles(): void;
155
+
156
+ /**
157
+ * 分页预览渲染器(浏览器)。
158
+ *
159
+ * 以真实 DOM 测量为准,将公文内容按版心高度逐块流入 A4 页面,并按 GB/T 9704
160
+ * 规则编排页码(单页居右空一字、双页居左空一字)。用于打印/导出前的所见即所得预览。
161
+ *
162
+ * v1 以“整块”为流动粒度(不在段落中间断行);超长段落的跨页断行将随
163
+ * 编辑器内联分页一并在后续迭代提供。headless paginate() 已支持按行精确分页,
164
+ * 可用于页数与导出计算。
165
+ */
166
+
167
+ interface PaginatedPreviewOptions {
168
+ /** 是否渲染页码,默认 true */
169
+ showPageNumber?: boolean;
170
+ }
171
+ /**
172
+ * 将文档渲染为分页预览,挂载到 mount 容器。返回总页数。
173
+ */
174
+ declare function renderPaginatedPreview(doc: JSONContent, mount: HTMLElement, options?: PaginatedPreviewOptions): number;
175
+
176
+ export { FontRole, HorizontalRuleVariant, type HrVariant, type OfficialEditorOptions, OfficialElement, type OfficialExtensionsOptions, OfficialImage, OfficialRole, type PaginatedPreviewOptions, Pagination, type PaginationOptions, type RegisterFontOptions, blankDocumentTemplate, buildElementStyles, createOfficialDocumentEditor, getOfficialExtensions, injectOfficialStyles, redHeadDocumentTemplate, registerFont, renderPaginatedPreview };