@makhmudov.kay/az-editor 0.1.0-beta.2 → 0.1.0-beta.4
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/CHANGELOG.md +27 -0
- package/README.md +73 -70
- package/dist/az-editor.js +1029 -500
- package/dist/library/AzDocumentEditor.d.ts +13 -1
- package/dist/library/AzHtmlEditor.d.ts +7 -1
- package/dist/library/document-diagnostics.d.ts +3 -0
- package/dist/library/font-diagnostics.d.ts +16 -0
- package/dist/library/hujjat/contract.d.ts +15 -9
- package/dist/library/hujjat/docx-to-html.d.ts +3 -1
- package/dist/library/hujjat/docx.d.ts +6 -3
- package/dist/library/hujjat/html-to-docx.d.ts +2 -1
- package/dist/library/hujjat/page-layout.d.ts +5 -0
- package/dist/library/hujjat/paragraph-format.d.ts +10 -0
- package/dist/library/hujjat/table-grid.d.ts +8 -0
- package/dist/library/index.d.ts +6 -1
- package/dist/library/layout-profile.d.ts +37 -0
- package/docs/integration.ru.md +911 -875
- package/docs/layout-metadata-v1.ru.md +135 -0
- package/examples/integration/DocxEditorExample.tsx +7 -2
- package/examples/integration/HtmlDraft.tsx +1 -0
- package/examples/integration/LayoutDraftExample.tsx +39 -0
- package/examples/integration/README.md +1 -0
- package/package.json +4 -1
|
@@ -2,11 +2,19 @@ import { type CSSProperties } from 'react';
|
|
|
2
2
|
import { type DocxEditorProps } from '@docx-editor.dev/react';
|
|
3
3
|
import '@docx-editor.dev/core/styles/editor.css';
|
|
4
4
|
import './editor.css';
|
|
5
|
-
import { type HujjatExportOptions, type HujjatExportResult } from './hujjat/contract';
|
|
5
|
+
import { type HujjatExportOptions, type HujjatExportResult, type HujjatWarning } from './hujjat/contract';
|
|
6
|
+
import { type AzFontStatus } from './font-diagnostics';
|
|
6
7
|
export interface EditorStatus {
|
|
7
8
|
pages: number;
|
|
8
9
|
loading: boolean;
|
|
9
10
|
error: string | null;
|
|
11
|
+
fonts?: AzFontStatus;
|
|
12
|
+
}
|
|
13
|
+
export interface AzParagraphPagination {
|
|
14
|
+
keepNext?: boolean;
|
|
15
|
+
keepLines?: boolean;
|
|
16
|
+
widowControl?: boolean;
|
|
17
|
+
pageBreakBefore?: boolean;
|
|
10
18
|
}
|
|
11
19
|
export interface AzDocumentEditorHandle {
|
|
12
20
|
save(): Promise<ArrayBuffer>;
|
|
@@ -14,6 +22,8 @@ export interface AzDocumentEditorHandle {
|
|
|
14
22
|
exportHujjat(options: HujjatExportOptions): Promise<HujjatExportResult>;
|
|
15
23
|
/** Insert a validated literal placeholder at the current selection. Not a protected chip. */
|
|
16
24
|
insertVariable(key: string): void;
|
|
25
|
+
/** Applies to the current selection as one undoable editor command. */
|
|
26
|
+
setParagraphPagination(options: AzParagraphPagination): void;
|
|
17
27
|
focus(): void;
|
|
18
28
|
print(): Promise<void>;
|
|
19
29
|
}
|
|
@@ -64,6 +74,8 @@ export interface AzDocumentEditorProps {
|
|
|
64
74
|
onExportPdf?: () => void;
|
|
65
75
|
onStatusChange?: (status: EditorStatus) => void;
|
|
66
76
|
onFontError?: (message: string) => void;
|
|
77
|
+
/** Read-only diagnostics for the opened/saved snapshot; cleared when edits invalidate it. */
|
|
78
|
+
onDiagnostics?: (warnings: HujjatWarning[]) => void;
|
|
67
79
|
}
|
|
68
80
|
/** Local DOCX editing adapter. Font and OOXML support determine visual fidelity. */
|
|
69
81
|
export declare const AzDocumentEditor: import("react").ForwardRefExoticComponent<AzDocumentEditorProps & import("react").RefAttributes<AzDocumentEditorHandle>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { type AzDocumentEditorProps } from './AzDocumentEditor';
|
|
2
|
+
import { type AzDocumentEditorProps, type AzParagraphPagination } from './AzDocumentEditor';
|
|
3
3
|
import { type HujjatHtmlResult, type HujjatWarning } from './hujjat/contract';
|
|
4
|
+
import type { AzHtmlLayoutOptions } from './layout-profile';
|
|
5
|
+
import type { AzFontStatus } from './font-diagnostics';
|
|
4
6
|
export interface AzHtmlEditorStatus {
|
|
5
7
|
phase: 'loading' | 'blocked' | 'ready' | 'exporting' | 'error';
|
|
6
8
|
/** True after the first user edit; exporting does not mark a server version saved. */
|
|
@@ -8,6 +10,7 @@ export interface AzHtmlEditorStatus {
|
|
|
8
10
|
pages: number;
|
|
9
11
|
error: string | null;
|
|
10
12
|
warnings: HujjatWarning[];
|
|
13
|
+
fonts?: AzFontStatus;
|
|
11
14
|
}
|
|
12
15
|
export interface AzHtmlExportResult extends HujjatHtmlResult {
|
|
13
16
|
changed: boolean;
|
|
@@ -20,11 +23,14 @@ export interface AzHtmlEditorHandle {
|
|
|
20
23
|
/** Retry a blocked import only after the host has obtained the user's decision. */
|
|
21
24
|
acceptImportLoss(): Promise<void>;
|
|
22
25
|
insertVariable(key: string): void;
|
|
26
|
+
setParagraphPagination(options: AzParagraphPagination): void;
|
|
23
27
|
focus(): void;
|
|
24
28
|
}
|
|
25
29
|
export interface AzHtmlEditorProps extends Omit<AzDocumentEditorProps, 'document' | 'onChange' | 'onStatusChange'> {
|
|
26
30
|
/** Read once per mount. Change React key after resolving unsaved edits to load another version. */
|
|
27
31
|
initialHtml: string;
|
|
32
|
+
/** Fixed for this draft, like initialHtml. Remount with a new key to change it. */
|
|
33
|
+
layout?: AzHtmlLayoutOptions;
|
|
28
34
|
onStatusChange?: (status: AzHtmlEditorStatus) => void;
|
|
29
35
|
/** Dirty notification, not serialized HTML. Call exportHtml before applying the draft. */
|
|
30
36
|
onChange?: () => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type FontConfigurationFragment } from '@docx-editor.dev/core/editor';
|
|
2
|
+
import type { DocxEditorProps } from '@docx-editor.dev/react';
|
|
3
|
+
import { type HujjatWarning } from './hujjat/contract';
|
|
4
|
+
export interface AzFontStatus {
|
|
5
|
+
/** Resource readiness, never a guarantee of matching Word's fonts or pagination. */
|
|
6
|
+
state: 'loading' | 'ready' | 'degraded' | 'unknown';
|
|
7
|
+
warnings: HujjatWarning[];
|
|
8
|
+
}
|
|
9
|
+
/** Stable per font configuration; reset each document without replacing the resolver. */
|
|
10
|
+
export declare function observeFonts(input: NonNullable<DocxEditorProps['fonts']>): {
|
|
11
|
+
fonts: FontConfigurationFragment | import("@docx-editor.dev/core").MarkedFontResolver<(request: import("@docx-editor.dev/core").FontResolutionRequest) => Promise<import("@docx-editor.dev/core").FontConfiguration | FontConfigurationFragment | undefined>>;
|
|
12
|
+
snapshot: () => AzFontStatus;
|
|
13
|
+
subscribe: (listener: () => void) => () => void;
|
|
14
|
+
fail: (code: string) => void;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** Hujjat template-format-spec.ru.md, 2026-10-09. Server validation remains authoritative. */
|
|
2
|
+
import type { AzHtmlLayoutOptions, AzLayoutMetadataV1 } from '../layout-profile';
|
|
3
|
+
export { HUJJAT_PAGE } from '../layout-profile';
|
|
2
4
|
export declare const HUJJAT_LOCALES: readonly ['uz', 'ru', 'uz_cyrl', 'en'];
|
|
3
5
|
export type HujjatLocale = typeof HUJJAT_LOCALES[number];
|
|
4
6
|
export interface HujjatBlock {
|
|
@@ -13,11 +15,22 @@ export interface HujjatWarning {
|
|
|
13
15
|
code: string;
|
|
14
16
|
message: string;
|
|
15
17
|
severity: 'warning' | 'loss';
|
|
18
|
+
stage?: 'import' | 'edit' | 'export' | 'fonts';
|
|
19
|
+
location?: {
|
|
20
|
+
part?: string;
|
|
21
|
+
paragraphIndex?: number;
|
|
22
|
+
sectionIndex?: number;
|
|
23
|
+
htmlPath?: string;
|
|
24
|
+
runIndex?: number;
|
|
25
|
+
};
|
|
26
|
+
before?: string | number | boolean | null;
|
|
27
|
+
after?: string | number | boolean | null;
|
|
16
28
|
}
|
|
17
29
|
export interface HujjatHtmlResult {
|
|
18
30
|
html: string;
|
|
19
31
|
variables: string[];
|
|
20
32
|
warnings: HujjatWarning[];
|
|
33
|
+
layout?: AzLayoutMetadataV1;
|
|
21
34
|
}
|
|
22
35
|
export interface HujjatExportResult extends HujjatHtmlResult {
|
|
23
36
|
locales: HujjatLocales;
|
|
@@ -26,21 +39,14 @@ export interface HujjatExportOptions {
|
|
|
26
39
|
locale: HujjatLocale;
|
|
27
40
|
locales?: HujjatLocales;
|
|
28
41
|
allowLossy?: boolean;
|
|
42
|
+
layout?: AzHtmlLayoutOptions;
|
|
29
43
|
}
|
|
30
44
|
export declare const HUJJAT_MAX_HTML_BYTES = 1048576;
|
|
31
|
-
export declare const HUJJAT_PAGE: {
|
|
32
|
-
readonly widthMm: 210;
|
|
33
|
-
readonly heightMm: 297;
|
|
34
|
-
readonly topMm: 15;
|
|
35
|
-
readonly rightMm: 20;
|
|
36
|
-
readonly bottomMm: 35;
|
|
37
|
-
readonly leftMm: 20;
|
|
38
|
-
};
|
|
39
45
|
export declare class HujjatCompatibilityError extends Error {
|
|
40
46
|
readonly warnings: HujjatWarning[];
|
|
41
47
|
constructor(message: string, warnings?: HujjatWarning[]);
|
|
42
48
|
}
|
|
43
|
-
export declare function warn(warnings: HujjatWarning[], code: string, message: string, severity?: HujjatWarning['severity']): void;
|
|
49
|
+
export declare function warn(warnings: HujjatWarning[], code: string, message: string, severity?: HujjatWarning['severity'], details?: Pick<HujjatWarning, 'stage' | 'location' | 'before' | 'after'>): void;
|
|
44
50
|
export declare function assertNoLoss(warnings: HujjatWarning[], allowLossy?: boolean): void;
|
|
45
51
|
export declare function validateHujjatVariable(key: string): boolean;
|
|
46
52
|
export declare function hujjatFont(font: string): string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { AzHtmlLayoutOptions, AzLayoutMetadataV1 } from '../layout-profile';
|
|
1
2
|
import { type HujjatWarning } from './contract';
|
|
2
|
-
export declare function docxToHtml(bytes: Uint8Array | ArrayBuffer): Promise<{
|
|
3
|
+
export declare function docxToHtml(bytes: Uint8Array | ArrayBuffer, options?: AzHtmlLayoutOptions): Promise<{
|
|
3
4
|
html: string;
|
|
4
5
|
warnings: HujjatWarning[];
|
|
6
|
+
layout?: AzLayoutMetadataV1;
|
|
5
7
|
}>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { type HujjatExportOptions, type HujjatExportResult, type HujjatLocales, type HujjatLocale, type HujjatHtmlResult } from './contract';
|
|
2
|
+
import { type AzHtmlLayoutOptions } from '../layout-profile';
|
|
2
3
|
/** Export a saved live DOCX snapshot; never scrape the paginated editor DOM. */
|
|
3
4
|
export declare function exportHujjatDocx(bytes: ArrayBuffer | Uint8Array, options: HujjatExportOptions): Promise<HujjatExportResult>;
|
|
4
5
|
export interface HujjatImportResult extends HujjatHtmlResult {
|
|
5
6
|
document: Uint8Array<ArrayBuffer>;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
export declare function importHujjatTemplate(locales: HujjatLocales, locale: HujjatLocale, options?: {
|
|
8
|
+
export interface HujjatImportOptions {
|
|
9
9
|
allowLossy?: boolean;
|
|
10
|
-
|
|
10
|
+
layout?: AzHtmlLayoutOptions;
|
|
11
|
+
}
|
|
12
|
+
/** Open only HTML-only locales. Missing locales never silently fall back when editing. */
|
|
13
|
+
export declare function importHujjatTemplate(locales: HujjatLocales, locale: HujjatLocale, options?: HujjatImportOptions): Promise<HujjatImportResult>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type HujjatWarning } from './contract';
|
|
2
|
+
import { type AzLayoutMetadataV1 } from '../layout-profile';
|
|
2
3
|
/** Deliberately bounded HTML projection, not a general browser-to-Word converter. */
|
|
3
|
-
export declare function htmlToDocx(html: string, warnings: HujjatWarning[]): Promise<Uint8Array<ArrayBuffer>>;
|
|
4
|
+
export declare function htmlToDocx(html: string, warnings: HujjatWarning[], layout?: AzLayoutMetadataV1): Promise<Uint8Array<ArrayBuffer>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AzHtmlLayoutOptions, type AzLayoutMetadataV1, type AzPageLayout } from '../layout-profile';
|
|
2
|
+
import { type HujjatWarning } from './contract';
|
|
3
|
+
export declare function pageLayoutFromSection(section: Element): AzPageLayout;
|
|
4
|
+
/** Metadata is separate from HTML/locale JSON and cannot carry section boundaries. */
|
|
5
|
+
export declare function readHtmlLayout(body: Element, options: AzHtmlLayoutOptions, warnings: HujjatWarning[]): AzLayoutMetadataV1 | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Css } from './xml';
|
|
2
|
+
export interface LineSpacing {
|
|
3
|
+
rule: 'auto' | 'exact' | 'atLeast';
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
/** Resolve partial OOXML properties before reducing them to CSS. Values stay in native units. */
|
|
7
|
+
export declare function resolveLineSpacing(properties: (Element | null)[]): LineSpacing | undefined;
|
|
8
|
+
export declare function lineSpacingCss(spacing: LineSpacing): string;
|
|
9
|
+
/** Conservative size check, not a measurement of the installed font's ascent/descent. */
|
|
10
|
+
export declare function runHeightEstimate(css: Css): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type HujjatWarning } from './contract';
|
|
2
|
+
export interface ColumnWidth {
|
|
3
|
+
column: number;
|
|
4
|
+
span: number;
|
|
5
|
+
width: number;
|
|
6
|
+
}
|
|
7
|
+
/** Prefer individual columns, then merged-cell constraints; share only the unspecified remainder. */
|
|
8
|
+
export declare function tableColumnWidths(count: number, total: number, constraints: ColumnWidth[], warnings: HujjatWarning[]): number[];
|
package/dist/library/index.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export { pdfRenderProfile } from './pdf-profile';
|
|
|
10
10
|
export { sanitizeHujjatHtml, withHujjatLocale, readHujjatHtml, validateHujjatVariable, HujjatCompatibilityError, HUJJAT_LOCALES, HUJJAT_MAX_HTML_BYTES, HUJJAT_PAGE } from './hujjat/contract';
|
|
11
11
|
export type { HujjatLocale, HujjatLocales, HujjatBlock, HujjatWarning, HujjatHtmlResult, HujjatExportOptions, HujjatExportResult } from './hujjat/contract';
|
|
12
12
|
export { exportHujjatDocx, importHujjatTemplate } from './hujjat/docx';
|
|
13
|
-
export type { HujjatImportResult } from './hujjat/docx';
|
|
13
|
+
export type { HujjatImportResult, HujjatImportOptions } from './hujjat/docx';
|
|
14
|
+
export { resolveHtmlLayout } from './layout-profile';
|
|
15
|
+
export type { AzParagraphPagination } from './AzDocumentEditor';
|
|
16
|
+
export { analyzeDocxFormatting } from './document-diagnostics';
|
|
17
|
+
export type { AzFontStatus } from './font-diagnostics';
|
|
18
|
+
export type { AzPageLayout, AzHtmlLayoutOptions, AzLayoutMetadataV1 } from './layout-profile';
|
|
14
19
|
export { requestHujjatPreview, createHujjatTemplatePayload } from './hujjat/api';
|
|
15
20
|
export type { HujjatPreviewOptions, HujjatTemplateMetadata } from './hujjat/api';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Physical values use OOXML twips (1/1440 inch), avoiding repeated mm rounding. */
|
|
2
|
+
export interface AzPageLayout {
|
|
3
|
+
widthTwips: number;
|
|
4
|
+
heightTwips: number;
|
|
5
|
+
orientation: 'portrait' | 'landscape';
|
|
6
|
+
margins: {
|
|
7
|
+
top: number;
|
|
8
|
+
right: number;
|
|
9
|
+
bottom: number;
|
|
10
|
+
left: number;
|
|
11
|
+
header: number;
|
|
12
|
+
footer: number;
|
|
13
|
+
gutter: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface AzHtmlLayoutOptions {
|
|
17
|
+
page?: AzPageLayout;
|
|
18
|
+
lineSpacingPolicy?: 'normalize' | 'preserve';
|
|
19
|
+
}
|
|
20
|
+
export interface AzLayoutMetadataV1 {
|
|
21
|
+
schema: 'az-editor.layout';
|
|
22
|
+
version: 1;
|
|
23
|
+
page: AzPageLayout;
|
|
24
|
+
lineSpacingPolicy: 'normalize' | 'preserve';
|
|
25
|
+
}
|
|
26
|
+
export declare const HUJJAT_PAGE: Readonly<{
|
|
27
|
+
widthMm: 210;
|
|
28
|
+
heightMm: 297;
|
|
29
|
+
topMm: 15;
|
|
30
|
+
rightMm: 20;
|
|
31
|
+
bottomMm: 35;
|
|
32
|
+
leftMm: 20;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function contentWidthTwips(page: AzPageLayout): number;
|
|
35
|
+
/** A new, validated snapshot; callers may reuse or mutate their own input objects safely. */
|
|
36
|
+
export declare function resolveHtmlLayout(options?: AzHtmlLayoutOptions): AzLayoutMetadataV1;
|
|
37
|
+
export declare function samePageLayout(a: AzPageLayout, b: AzPageLayout): boolean;
|