document-model.js 3.2.0 → 4.0.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/README.md +82 -31
- package/dist/codec.d.cts +2 -7
- package/dist/codec.d.ts +2 -7
- package/dist/content-BN0PWqpt.d.cts +2393 -0
- package/dist/content-CiZf6Fqn.d.ts +2393 -0
- package/dist/content-json-schema-defs.cjs +1006 -1
- package/dist/content-json-schema-defs.js +1006 -1
- package/dist/content.cjs +2 -8
- package/dist/content.d.cts +2 -2354
- package/dist/content.d.ts +2 -2354
- package/dist/content.js +2 -8
- package/dist/definitions.cjs +109 -0
- package/dist/definitions.d.cts +115 -0
- package/dist/definitions.d.ts +115 -0
- package/dist/definitions.js +99 -0
- package/dist/index.cjs +42 -18
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +6 -5
- package/dist/package-node-DDPSNOvy.d.cts +441 -0
- package/dist/package-node-QVFHQcm8.d.ts +441 -0
- package/dist/package-node.cjs +120 -0
- package/dist/package-node.d.cts +2 -0
- package/dist/package-node.d.ts +2 -0
- package/dist/package-node.js +93 -0
- package/dist/package.cjs +37 -7
- package/dist/package.d.cts +452 -755
- package/dist/package.d.ts +452 -755
- package/dist/package.js +39 -8
- package/dist/schema-io.cjs +55 -25
- package/dist/schema-io.d.cts +13 -11
- package/dist/schema-io.d.ts +13 -11
- package/dist/schema-io.js +54 -25
- package/dist/style.d.cts +2 -2
- package/dist/style.d.ts +2 -2
- package/package.json +2 -2
- package/schemas/content-document.schema.json +1476 -69
- package/schemas/document-package.schema.json +3056 -30
- package/dist/layout.cjs +0 -150
- package/dist/layout.d.cts +0 -684
- package/dist/layout.d.ts +0 -684
- package/dist/layout.js +0 -136
- package/schemas/layout-document.schema.json +0 -760
package/dist/package.js
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { PageSizeSchema } from "./geometry.js";
|
|
2
|
-
import {
|
|
2
|
+
import { LayoutMetadataSchema } from "./metadata.js";
|
|
3
|
+
import { ContentFormulaSchema, contentDocumentSharedFields } from "./content.js";
|
|
4
|
+
import { DefinitionsTableSchema, StylesTableSchema } from "./definitions.js";
|
|
5
|
+
import { DrawPageGroupSchema, SectionGroupSchema, SheetGroupSchema, SlideGroupSchema } from "./package-node.js";
|
|
3
6
|
import { z } from "zod";
|
|
4
7
|
//#region src/package.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const packageEnvelopeFields = {
|
|
9
|
+
metadata: LayoutMetadataSchema,
|
|
10
|
+
...contentDocumentSharedFields,
|
|
11
|
+
pages: z.array(PageSizeSchema).optional(),
|
|
12
|
+
styles: StylesTableSchema.optional(),
|
|
13
|
+
definitions: DefinitionsTableSchema.optional()
|
|
14
|
+
};
|
|
15
|
+
const DocumentPackageSchema = z.discriminatedUnion("kind", [
|
|
16
|
+
z.object({
|
|
17
|
+
kind: z.literal("wordprocessing"),
|
|
18
|
+
...packageEnvelopeFields,
|
|
19
|
+
children: z.array(SectionGroupSchema)
|
|
20
|
+
}),
|
|
21
|
+
z.object({
|
|
22
|
+
kind: z.literal("presentation"),
|
|
23
|
+
...packageEnvelopeFields,
|
|
24
|
+
children: z.array(SlideGroupSchema)
|
|
25
|
+
}),
|
|
26
|
+
z.object({
|
|
27
|
+
kind: z.literal("spreadsheet"),
|
|
28
|
+
...packageEnvelopeFields,
|
|
29
|
+
children: z.array(SheetGroupSchema)
|
|
30
|
+
}),
|
|
31
|
+
z.object({
|
|
32
|
+
kind: z.literal("drawing"),
|
|
33
|
+
...packageEnvelopeFields,
|
|
34
|
+
children: z.array(DrawPageGroupSchema)
|
|
35
|
+
}),
|
|
36
|
+
z.object({
|
|
37
|
+
kind: z.literal("formula"),
|
|
38
|
+
...packageEnvelopeFields,
|
|
39
|
+
children: z.array(ContentFormulaSchema).length(1)
|
|
40
|
+
})
|
|
41
|
+
]);
|
|
11
42
|
//#endregion
|
|
12
|
-
export {
|
|
43
|
+
export { DocumentPackageSchema };
|
package/dist/schema-io.cjs
CHANGED
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_content = require("./content.cjs");
|
|
3
|
-
const require_layout = require("./layout.cjs");
|
|
4
3
|
const require_package = require("./package.cjs");
|
|
5
4
|
//#region src/schema-io.ts
|
|
6
5
|
const SCHEMA_FILE_NAMES = {
|
|
7
6
|
DocumentPackage: "document-package.schema.json",
|
|
8
|
-
ContentDocument: "content-document.schema.json"
|
|
9
|
-
LayoutDocument: "layout-document.schema.json"
|
|
7
|
+
ContentDocument: "content-document.schema.json"
|
|
10
8
|
};
|
|
11
9
|
function schemaUriFor(kind) {
|
|
12
|
-
return `https://cdn.jsdelivr.net/npm/document-schema.js@
|
|
10
|
+
return `https://cdn.jsdelivr.net/npm/document-schema.js@4.0.0/schemas/${SCHEMA_FILE_NAMES[kind]}`;
|
|
11
|
+
}
|
|
12
|
+
const SCHEMA_URI_PATTERN = /^https:\/\/cdn\.jsdelivr\.net\/npm\/document-schema\.js@([^/]+)\/schemas\/(document-package|content-document|layout-document)\.schema\.json$/;
|
|
13
|
+
function parseSchemaUri(uri) {
|
|
14
|
+
const match = SCHEMA_URI_PATTERN.exec(uri);
|
|
15
|
+
if (match === null) return void 0;
|
|
16
|
+
const version = match[1];
|
|
17
|
+
const stem = match[2];
|
|
18
|
+
if (version === void 0 || stem === void 0) return void 0;
|
|
19
|
+
return {
|
|
20
|
+
version,
|
|
21
|
+
stem
|
|
22
|
+
};
|
|
13
23
|
}
|
|
14
|
-
const SCHEMA_URI_PATTERN = /^https:\/\/cdn\.jsdelivr\.net\/npm\/document-schema\.js@[^/]+\/schemas\/(document-package|content-document|layout-document)\.schema\.json$/;
|
|
15
24
|
function kindForFileStem(stem) {
|
|
16
25
|
switch (stem) {
|
|
17
26
|
case "document-package": return "DocumentPackage";
|
|
18
27
|
case "content-document": return "ContentDocument";
|
|
19
|
-
case "layout-document": return "LayoutDocument";
|
|
20
28
|
default: return;
|
|
21
29
|
}
|
|
22
30
|
}
|
|
31
|
+
function majorVersionOf(version) {
|
|
32
|
+
const match = /^(\d+)/.exec(version);
|
|
33
|
+
if (match?.[1] === void 0) return void 0;
|
|
34
|
+
return Number(match[1]);
|
|
35
|
+
}
|
|
23
36
|
function isRecord(value) {
|
|
24
37
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
38
|
}
|
|
26
39
|
function documentSchemaKindOf(value) {
|
|
27
40
|
if (!isRecord(value)) return void 0;
|
|
28
41
|
if (!("$schema" in value) || typeof value.$schema !== "string") return void 0;
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
if (stem === void 0) return void 0;
|
|
33
|
-
return kindForFileStem(stem);
|
|
42
|
+
const parts = parseSchemaUri(value.$schema);
|
|
43
|
+
if (parts === void 0) return void 0;
|
|
44
|
+
return kindForFileStem(parts.stem);
|
|
34
45
|
}
|
|
35
46
|
function documentPackageWithSchema(value) {
|
|
36
47
|
return {
|
|
@@ -44,23 +55,45 @@ function contentDocumentWithSchema(value) {
|
|
|
44
55
|
...value
|
|
45
56
|
};
|
|
46
57
|
}
|
|
47
|
-
function layoutDocumentWithSchema(value) {
|
|
48
|
-
return {
|
|
49
|
-
$schema: schemaUriFor("LayoutDocument"),
|
|
50
|
-
...value
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
58
|
var UnrecognizedDocumentSchemaError = class extends Error {
|
|
54
59
|
schema;
|
|
55
60
|
constructor(schema) {
|
|
56
|
-
super(`documentFromJson: value has no recognized "$schema" property (expected one of the
|
|
61
|
+
super(`documentFromJson: value has no recognized "$schema" property (expected one of the document-schema.js .schema.json URIs; found: ${JSON.stringify(schema)}).`);
|
|
57
62
|
this.name = "UnrecognizedDocumentSchemaError";
|
|
58
63
|
this.schema = schema;
|
|
59
64
|
}
|
|
60
65
|
};
|
|
66
|
+
var LayoutSchemaDemotedError = class extends Error {
|
|
67
|
+
schema;
|
|
68
|
+
constructor(schema) {
|
|
69
|
+
super(`documentFromJson: this value is a layout-document dump (${schema}), and LayoutDocument moved to pdf-codec in document-schema.js 4.0.0 (ExaDev/pdf-codec#65). Read it with pdf-codec's own layout model, or with a document-schema.js 3.x release.`);
|
|
70
|
+
this.name = "LayoutSchemaDemotedError";
|
|
71
|
+
this.schema = schema;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var SchemaVersionMismatchError = class extends Error {
|
|
75
|
+
schema;
|
|
76
|
+
dumpVersion;
|
|
77
|
+
installedVersion;
|
|
78
|
+
constructor(schema, dumpVersion, installedVersion) {
|
|
79
|
+
const dumpMajor = majorVersionOf(dumpVersion);
|
|
80
|
+
const installedMajor = majorVersionOf(installedVersion);
|
|
81
|
+
const isOlder = dumpMajor !== void 0 && installedMajor !== void 0 && dumpMajor < installedMajor;
|
|
82
|
+
super(`documentFromJson: this dump's $schema pins document-schema.js@${dumpVersion}, but the installed release is @${installedVersion}, and a dump only parses under the major that wrote it.` + (isOlder ? ` Dumps from before 4.0.0 carry the retired formatVersion field and (for packages) the flat { formatVersion, content, pages } shape, replaced in 4.0.0 by the tree-form DocumentPackage (ExaDev/document-schema.js#20). Re-dump the value with a 4.x release, or parse it with the release that produced it.` : ` Upgrade document-schema.js to read it.`));
|
|
83
|
+
this.name = "SchemaVersionMismatchError";
|
|
84
|
+
this.schema = schema;
|
|
85
|
+
this.dumpVersion = dumpVersion;
|
|
86
|
+
this.installedVersion = installedVersion;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
61
89
|
function documentFromJson(value) {
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
if (!isRecord(value) || typeof value.$schema !== "string") throw new UnrecognizedDocumentSchemaError(isRecord(value) ? value.$schema : void 0);
|
|
91
|
+
const parts = parseSchemaUri(value.$schema);
|
|
92
|
+
if (parts === void 0) throw new UnrecognizedDocumentSchemaError(value.$schema);
|
|
93
|
+
if (parts.stem === "layout-document") throw new LayoutSchemaDemotedError(value.$schema);
|
|
94
|
+
const kind = kindForFileStem(parts.stem);
|
|
95
|
+
if (kind === void 0) throw new UnrecognizedDocumentSchemaError(value.$schema);
|
|
96
|
+
if (majorVersionOf(parts.version) !== majorVersionOf("4.0.0")) throw new SchemaVersionMismatchError(value.$schema, parts.version, "4.0.0");
|
|
64
97
|
switch (kind) {
|
|
65
98
|
case "DocumentPackage": return {
|
|
66
99
|
kind,
|
|
@@ -70,18 +103,15 @@ function documentFromJson(value) {
|
|
|
70
103
|
kind,
|
|
71
104
|
value: require_content.ContentDocumentSchema.parse(value)
|
|
72
105
|
};
|
|
73
|
-
case "LayoutDocument": return {
|
|
74
|
-
kind,
|
|
75
|
-
value: require_layout.LayoutDocumentSchema.parse(value)
|
|
76
|
-
};
|
|
77
106
|
}
|
|
78
107
|
}
|
|
79
108
|
//#endregion
|
|
109
|
+
exports.LayoutSchemaDemotedError = LayoutSchemaDemotedError;
|
|
80
110
|
exports.SCHEMA_FILE_NAMES = SCHEMA_FILE_NAMES;
|
|
111
|
+
exports.SchemaVersionMismatchError = SchemaVersionMismatchError;
|
|
81
112
|
exports.UnrecognizedDocumentSchemaError = UnrecognizedDocumentSchemaError;
|
|
82
113
|
exports.contentDocumentWithSchema = contentDocumentWithSchema;
|
|
83
114
|
exports.documentFromJson = documentFromJson;
|
|
84
115
|
exports.documentPackageWithSchema = documentPackageWithSchema;
|
|
85
116
|
exports.documentSchemaKindOf = documentSchemaKindOf;
|
|
86
|
-
exports.layoutDocumentWithSchema = layoutDocumentWithSchema;
|
|
87
117
|
exports.schemaUriFor = schemaUriFor;
|
package/dist/schema-io.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ContentDocument } from "./content.cjs";
|
|
2
|
-
import { LayoutDocument } from "./layout.cjs";
|
|
1
|
+
import { l as ContentDocument } from "./content-BN0PWqpt.cjs";
|
|
3
2
|
import { DocumentPackage } from "./package.cjs";
|
|
4
3
|
//#region src/schema-io.d.ts
|
|
5
|
-
type DocumentSchemaKind = 'DocumentPackage' | 'ContentDocument'
|
|
4
|
+
type DocumentSchemaKind = 'DocumentPackage' | 'ContentDocument';
|
|
6
5
|
declare const SCHEMA_FILE_NAMES: Record<DocumentSchemaKind, string>;
|
|
7
6
|
declare function schemaUriFor(kind: DocumentSchemaKind): string;
|
|
8
7
|
declare function documentSchemaKindOf(value: unknown): DocumentSchemaKind | undefined;
|
|
@@ -12,26 +11,29 @@ type DocumentPackageJson = DocumentPackage & {
|
|
|
12
11
|
type ContentDocumentJson = ContentDocument & {
|
|
13
12
|
readonly $schema: string;
|
|
14
13
|
};
|
|
15
|
-
type LayoutDocumentJson = LayoutDocument & {
|
|
16
|
-
readonly $schema: string;
|
|
17
|
-
};
|
|
18
14
|
declare function documentPackageWithSchema(value: DocumentPackage): DocumentPackageJson;
|
|
19
15
|
declare function contentDocumentWithSchema(value: ContentDocument): ContentDocumentJson;
|
|
20
|
-
declare function layoutDocumentWithSchema(value: LayoutDocument): LayoutDocumentJson;
|
|
21
16
|
declare class UnrecognizedDocumentSchemaError extends Error {
|
|
22
17
|
readonly schema: unknown;
|
|
23
18
|
constructor(schema: unknown);
|
|
24
19
|
}
|
|
20
|
+
declare class LayoutSchemaDemotedError extends Error {
|
|
21
|
+
readonly schema: string;
|
|
22
|
+
constructor(schema: string);
|
|
23
|
+
}
|
|
24
|
+
declare class SchemaVersionMismatchError extends Error {
|
|
25
|
+
readonly schema: string;
|
|
26
|
+
readonly dumpVersion: string;
|
|
27
|
+
readonly installedVersion: string;
|
|
28
|
+
constructor(schema: string, dumpVersion: string, installedVersion: string);
|
|
29
|
+
}
|
|
25
30
|
type DocumentJsonResult = {
|
|
26
31
|
kind: 'DocumentPackage';
|
|
27
32
|
value: DocumentPackage;
|
|
28
33
|
} | {
|
|
29
34
|
kind: 'ContentDocument';
|
|
30
35
|
value: ContentDocument;
|
|
31
|
-
} | {
|
|
32
|
-
kind: 'LayoutDocument';
|
|
33
|
-
value: LayoutDocument;
|
|
34
36
|
};
|
|
35
37
|
declare function documentFromJson(value: unknown): DocumentJsonResult;
|
|
36
38
|
//#endregion
|
|
37
|
-
export { ContentDocumentJson, DocumentJsonResult, DocumentPackageJson, DocumentSchemaKind,
|
|
39
|
+
export { ContentDocumentJson, DocumentJsonResult, DocumentPackageJson, DocumentSchemaKind, LayoutSchemaDemotedError, SCHEMA_FILE_NAMES, SchemaVersionMismatchError, UnrecognizedDocumentSchemaError, contentDocumentWithSchema, documentFromJson, documentPackageWithSchema, documentSchemaKindOf, schemaUriFor };
|
package/dist/schema-io.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ContentDocument } from "./content.js";
|
|
2
|
-
import { LayoutDocument } from "./layout.js";
|
|
1
|
+
import { l as ContentDocument } from "./content-CiZf6Fqn.js";
|
|
3
2
|
import { DocumentPackage } from "./package.js";
|
|
4
3
|
//#region src/schema-io.d.ts
|
|
5
|
-
type DocumentSchemaKind = 'DocumentPackage' | 'ContentDocument'
|
|
4
|
+
type DocumentSchemaKind = 'DocumentPackage' | 'ContentDocument';
|
|
6
5
|
declare const SCHEMA_FILE_NAMES: Record<DocumentSchemaKind, string>;
|
|
7
6
|
declare function schemaUriFor(kind: DocumentSchemaKind): string;
|
|
8
7
|
declare function documentSchemaKindOf(value: unknown): DocumentSchemaKind | undefined;
|
|
@@ -12,26 +11,29 @@ type DocumentPackageJson = DocumentPackage & {
|
|
|
12
11
|
type ContentDocumentJson = ContentDocument & {
|
|
13
12
|
readonly $schema: string;
|
|
14
13
|
};
|
|
15
|
-
type LayoutDocumentJson = LayoutDocument & {
|
|
16
|
-
readonly $schema: string;
|
|
17
|
-
};
|
|
18
14
|
declare function documentPackageWithSchema(value: DocumentPackage): DocumentPackageJson;
|
|
19
15
|
declare function contentDocumentWithSchema(value: ContentDocument): ContentDocumentJson;
|
|
20
|
-
declare function layoutDocumentWithSchema(value: LayoutDocument): LayoutDocumentJson;
|
|
21
16
|
declare class UnrecognizedDocumentSchemaError extends Error {
|
|
22
17
|
readonly schema: unknown;
|
|
23
18
|
constructor(schema: unknown);
|
|
24
19
|
}
|
|
20
|
+
declare class LayoutSchemaDemotedError extends Error {
|
|
21
|
+
readonly schema: string;
|
|
22
|
+
constructor(schema: string);
|
|
23
|
+
}
|
|
24
|
+
declare class SchemaVersionMismatchError extends Error {
|
|
25
|
+
readonly schema: string;
|
|
26
|
+
readonly dumpVersion: string;
|
|
27
|
+
readonly installedVersion: string;
|
|
28
|
+
constructor(schema: string, dumpVersion: string, installedVersion: string);
|
|
29
|
+
}
|
|
25
30
|
type DocumentJsonResult = {
|
|
26
31
|
kind: 'DocumentPackage';
|
|
27
32
|
value: DocumentPackage;
|
|
28
33
|
} | {
|
|
29
34
|
kind: 'ContentDocument';
|
|
30
35
|
value: ContentDocument;
|
|
31
|
-
} | {
|
|
32
|
-
kind: 'LayoutDocument';
|
|
33
|
-
value: LayoutDocument;
|
|
34
36
|
};
|
|
35
37
|
declare function documentFromJson(value: unknown): DocumentJsonResult;
|
|
36
38
|
//#endregion
|
|
37
|
-
export { ContentDocumentJson, DocumentJsonResult, DocumentPackageJson, DocumentSchemaKind,
|
|
39
|
+
export { ContentDocumentJson, DocumentJsonResult, DocumentPackageJson, DocumentSchemaKind, LayoutSchemaDemotedError, SCHEMA_FILE_NAMES, SchemaVersionMismatchError, UnrecognizedDocumentSchemaError, contentDocumentWithSchema, documentFromJson, documentPackageWithSchema, documentSchemaKindOf, schemaUriFor };
|
package/dist/schema-io.js
CHANGED
|
@@ -1,35 +1,46 @@
|
|
|
1
1
|
import { ContentDocumentSchema } from "./content.js";
|
|
2
|
-
import { LayoutDocumentSchema } from "./layout.js";
|
|
3
2
|
import { DocumentPackageSchema } from "./package.js";
|
|
4
3
|
//#region src/schema-io.ts
|
|
5
4
|
const SCHEMA_FILE_NAMES = {
|
|
6
5
|
DocumentPackage: "document-package.schema.json",
|
|
7
|
-
ContentDocument: "content-document.schema.json"
|
|
8
|
-
LayoutDocument: "layout-document.schema.json"
|
|
6
|
+
ContentDocument: "content-document.schema.json"
|
|
9
7
|
};
|
|
10
8
|
function schemaUriFor(kind) {
|
|
11
|
-
return `https://cdn.jsdelivr.net/npm/document-schema.js@
|
|
9
|
+
return `https://cdn.jsdelivr.net/npm/document-schema.js@4.0.0/schemas/${SCHEMA_FILE_NAMES[kind]}`;
|
|
10
|
+
}
|
|
11
|
+
const SCHEMA_URI_PATTERN = /^https:\/\/cdn\.jsdelivr\.net\/npm\/document-schema\.js@([^/]+)\/schemas\/(document-package|content-document|layout-document)\.schema\.json$/;
|
|
12
|
+
function parseSchemaUri(uri) {
|
|
13
|
+
const match = SCHEMA_URI_PATTERN.exec(uri);
|
|
14
|
+
if (match === null) return void 0;
|
|
15
|
+
const version = match[1];
|
|
16
|
+
const stem = match[2];
|
|
17
|
+
if (version === void 0 || stem === void 0) return void 0;
|
|
18
|
+
return {
|
|
19
|
+
version,
|
|
20
|
+
stem
|
|
21
|
+
};
|
|
12
22
|
}
|
|
13
|
-
const SCHEMA_URI_PATTERN = /^https:\/\/cdn\.jsdelivr\.net\/npm\/document-schema\.js@[^/]+\/schemas\/(document-package|content-document|layout-document)\.schema\.json$/;
|
|
14
23
|
function kindForFileStem(stem) {
|
|
15
24
|
switch (stem) {
|
|
16
25
|
case "document-package": return "DocumentPackage";
|
|
17
26
|
case "content-document": return "ContentDocument";
|
|
18
|
-
case "layout-document": return "LayoutDocument";
|
|
19
27
|
default: return;
|
|
20
28
|
}
|
|
21
29
|
}
|
|
30
|
+
function majorVersionOf(version) {
|
|
31
|
+
const match = /^(\d+)/.exec(version);
|
|
32
|
+
if (match?.[1] === void 0) return void 0;
|
|
33
|
+
return Number(match[1]);
|
|
34
|
+
}
|
|
22
35
|
function isRecord(value) {
|
|
23
36
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
37
|
}
|
|
25
38
|
function documentSchemaKindOf(value) {
|
|
26
39
|
if (!isRecord(value)) return void 0;
|
|
27
40
|
if (!("$schema" in value) || typeof value.$schema !== "string") return void 0;
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
if (stem === void 0) return void 0;
|
|
32
|
-
return kindForFileStem(stem);
|
|
41
|
+
const parts = parseSchemaUri(value.$schema);
|
|
42
|
+
if (parts === void 0) return void 0;
|
|
43
|
+
return kindForFileStem(parts.stem);
|
|
33
44
|
}
|
|
34
45
|
function documentPackageWithSchema(value) {
|
|
35
46
|
return {
|
|
@@ -43,23 +54,45 @@ function contentDocumentWithSchema(value) {
|
|
|
43
54
|
...value
|
|
44
55
|
};
|
|
45
56
|
}
|
|
46
|
-
function layoutDocumentWithSchema(value) {
|
|
47
|
-
return {
|
|
48
|
-
$schema: schemaUriFor("LayoutDocument"),
|
|
49
|
-
...value
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
57
|
var UnrecognizedDocumentSchemaError = class extends Error {
|
|
53
58
|
schema;
|
|
54
59
|
constructor(schema) {
|
|
55
|
-
super(`documentFromJson: value has no recognized "$schema" property (expected one of the
|
|
60
|
+
super(`documentFromJson: value has no recognized "$schema" property (expected one of the document-schema.js .schema.json URIs; found: ${JSON.stringify(schema)}).`);
|
|
56
61
|
this.name = "UnrecognizedDocumentSchemaError";
|
|
57
62
|
this.schema = schema;
|
|
58
63
|
}
|
|
59
64
|
};
|
|
65
|
+
var LayoutSchemaDemotedError = class extends Error {
|
|
66
|
+
schema;
|
|
67
|
+
constructor(schema) {
|
|
68
|
+
super(`documentFromJson: this value is a layout-document dump (${schema}), and LayoutDocument moved to pdf-codec in document-schema.js 4.0.0 (ExaDev/pdf-codec#65). Read it with pdf-codec's own layout model, or with a document-schema.js 3.x release.`);
|
|
69
|
+
this.name = "LayoutSchemaDemotedError";
|
|
70
|
+
this.schema = schema;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var SchemaVersionMismatchError = class extends Error {
|
|
74
|
+
schema;
|
|
75
|
+
dumpVersion;
|
|
76
|
+
installedVersion;
|
|
77
|
+
constructor(schema, dumpVersion, installedVersion) {
|
|
78
|
+
const dumpMajor = majorVersionOf(dumpVersion);
|
|
79
|
+
const installedMajor = majorVersionOf(installedVersion);
|
|
80
|
+
const isOlder = dumpMajor !== void 0 && installedMajor !== void 0 && dumpMajor < installedMajor;
|
|
81
|
+
super(`documentFromJson: this dump's $schema pins document-schema.js@${dumpVersion}, but the installed release is @${installedVersion}, and a dump only parses under the major that wrote it.` + (isOlder ? ` Dumps from before 4.0.0 carry the retired formatVersion field and (for packages) the flat { formatVersion, content, pages } shape, replaced in 4.0.0 by the tree-form DocumentPackage (ExaDev/document-schema.js#20). Re-dump the value with a 4.x release, or parse it with the release that produced it.` : ` Upgrade document-schema.js to read it.`));
|
|
82
|
+
this.name = "SchemaVersionMismatchError";
|
|
83
|
+
this.schema = schema;
|
|
84
|
+
this.dumpVersion = dumpVersion;
|
|
85
|
+
this.installedVersion = installedVersion;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
60
88
|
function documentFromJson(value) {
|
|
61
|
-
|
|
62
|
-
|
|
89
|
+
if (!isRecord(value) || typeof value.$schema !== "string") throw new UnrecognizedDocumentSchemaError(isRecord(value) ? value.$schema : void 0);
|
|
90
|
+
const parts = parseSchemaUri(value.$schema);
|
|
91
|
+
if (parts === void 0) throw new UnrecognizedDocumentSchemaError(value.$schema);
|
|
92
|
+
if (parts.stem === "layout-document") throw new LayoutSchemaDemotedError(value.$schema);
|
|
93
|
+
const kind = kindForFileStem(parts.stem);
|
|
94
|
+
if (kind === void 0) throw new UnrecognizedDocumentSchemaError(value.$schema);
|
|
95
|
+
if (majorVersionOf(parts.version) !== majorVersionOf("4.0.0")) throw new SchemaVersionMismatchError(value.$schema, parts.version, "4.0.0");
|
|
63
96
|
switch (kind) {
|
|
64
97
|
case "DocumentPackage": return {
|
|
65
98
|
kind,
|
|
@@ -69,11 +102,7 @@ function documentFromJson(value) {
|
|
|
69
102
|
kind,
|
|
70
103
|
value: ContentDocumentSchema.parse(value)
|
|
71
104
|
};
|
|
72
|
-
case "LayoutDocument": return {
|
|
73
|
-
kind,
|
|
74
|
-
value: LayoutDocumentSchema.parse(value)
|
|
75
|
-
};
|
|
76
105
|
}
|
|
77
106
|
}
|
|
78
107
|
//#endregion
|
|
79
|
-
export { SCHEMA_FILE_NAMES, UnrecognizedDocumentSchemaError, contentDocumentWithSchema, documentFromJson, documentPackageWithSchema, documentSchemaKindOf,
|
|
108
|
+
export { LayoutSchemaDemotedError, SCHEMA_FILE_NAMES, SchemaVersionMismatchError, UnrecognizedDocumentSchemaError, contentDocumentWithSchema, documentFromJson, documentPackageWithSchema, documentSchemaKindOf, schemaUriFor };
|
package/dist/style.d.cts
CHANGED
|
@@ -10,12 +10,12 @@ type Alignment = z.infer<typeof AlignmentSchema>;
|
|
|
10
10
|
declare const LayoutFontSchema: z.ZodObject<{
|
|
11
11
|
family: z.ZodString;
|
|
12
12
|
weight: z.ZodEnum<{
|
|
13
|
-
normal: "normal";
|
|
14
13
|
bold: "bold";
|
|
14
|
+
normal: "normal";
|
|
15
15
|
}>;
|
|
16
16
|
style: z.ZodEnum<{
|
|
17
|
-
normal: "normal";
|
|
18
17
|
italic: "italic";
|
|
18
|
+
normal: "normal";
|
|
19
19
|
}>;
|
|
20
20
|
}, z.core.$strip>;
|
|
21
21
|
type LayoutFont = z.infer<typeof LayoutFontSchema>;
|
package/dist/style.d.ts
CHANGED
|
@@ -10,12 +10,12 @@ type Alignment = z.infer<typeof AlignmentSchema>;
|
|
|
10
10
|
declare const LayoutFontSchema: z.ZodObject<{
|
|
11
11
|
family: z.ZodString;
|
|
12
12
|
weight: z.ZodEnum<{
|
|
13
|
-
normal: "normal";
|
|
14
13
|
bold: "bold";
|
|
14
|
+
normal: "normal";
|
|
15
15
|
}>;
|
|
16
16
|
style: z.ZodEnum<{
|
|
17
|
-
normal: "normal";
|
|
18
17
|
italic: "italic";
|
|
18
|
+
normal: "normal";
|
|
19
19
|
}>;
|
|
20
20
|
}, z.core.$strip>;
|
|
21
21
|
type LayoutFont = z.infer<typeof LayoutFontSchema>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-model.js",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "The canonical, format-agnostic content and
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "The canonical, format-agnostic content and document-package schemas shared by ooxml.js, odf.js, documents.js, pdf-codec, and markdown-codec -- pure Zod schemas, no behaviour.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|