document-model.js 1.9.0 → 1.10.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 +36 -0
- package/dist/color-AELCDH_b.d.cts +13 -0
- package/dist/color-AELCDH_b.d.ts +13 -0
- package/dist/color.cjs +40 -0
- package/dist/color.d.cts +2 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +36 -0
- package/dist/content.cjs +341 -0
- package/dist/content.d.cts +1188 -0
- package/dist/content.d.ts +1188 -0
- package/dist/content.js +309 -0
- package/dist/geometry-CokwQGtJ.d.cts +27 -0
- package/dist/geometry-CokwQGtJ.d.ts +27 -0
- package/dist/geometry.cjs +43 -0
- package/dist/geometry.d.cts +2 -0
- package/dist/geometry.d.ts +2 -0
- package/dist/geometry.js +36 -0
- package/dist/index.cjs +79 -684
- package/dist/index.d.cts +8 -2448
- package/dist/index.d.ts +8 -2448
- package/dist/index.js +8 -613
- package/dist/layout.cjs +147 -0
- package/dist/layout.d.cts +636 -0
- package/dist/layout.d.ts +636 -0
- package/dist/layout.js +133 -0
- package/dist/metadata.cjs +15 -0
- package/dist/metadata.d.cts +15 -0
- package/dist/metadata.d.ts +15 -0
- package/dist/metadata.js +14 -0
- package/dist/package.cjs +14 -0
- package/dist/package.d.cts +528 -0
- package/dist/package.d.ts +528 -0
- package/dist/package.js +12 -0
- package/dist/schema-io.cjs +87 -0
- package/dist/schema-io.d.cts +37 -0
- package/dist/schema-io.d.ts +37 -0
- package/dist/schema-io.js +79 -0
- package/dist/style.cjs +23 -0
- package/dist/style.d.cts +24 -0
- package/dist/style.d.ts +24 -0
- package/dist/style.js +20 -0
- package/package.json +10 -4
- package/schemas/content-document.schema.json +3 -3
- package/schemas/document-package.schema.json +3 -3
- package/schemas/layout-document.schema.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ContentDocument } from "./content.js";
|
|
2
|
+
import { LayoutDocument } from "./layout.js";
|
|
3
|
+
import { DocumentPackage } from "./package.js";
|
|
4
|
+
//#region src/schema-io.d.ts
|
|
5
|
+
type DocumentSchemaKind = 'DocumentPackage' | 'ContentDocument' | 'LayoutDocument';
|
|
6
|
+
declare const SCHEMA_FILE_NAMES: Record<DocumentSchemaKind, string>;
|
|
7
|
+
declare function schemaUriFor(kind: DocumentSchemaKind): string;
|
|
8
|
+
declare function documentSchemaKindOf(value: unknown): DocumentSchemaKind | undefined;
|
|
9
|
+
type DocumentPackageJson = DocumentPackage & {
|
|
10
|
+
readonly $schema: string;
|
|
11
|
+
};
|
|
12
|
+
type ContentDocumentJson = ContentDocument & {
|
|
13
|
+
readonly $schema: string;
|
|
14
|
+
};
|
|
15
|
+
type LayoutDocumentJson = LayoutDocument & {
|
|
16
|
+
readonly $schema: string;
|
|
17
|
+
};
|
|
18
|
+
declare function documentPackageWithSchema(value: DocumentPackage): DocumentPackageJson;
|
|
19
|
+
declare function contentDocumentWithSchema(value: ContentDocument): ContentDocumentJson;
|
|
20
|
+
declare function layoutDocumentWithSchema(value: LayoutDocument): LayoutDocumentJson;
|
|
21
|
+
declare class UnrecognizedDocumentSchemaError extends Error {
|
|
22
|
+
readonly schema: unknown;
|
|
23
|
+
constructor(schema: unknown);
|
|
24
|
+
}
|
|
25
|
+
type DocumentJsonResult = {
|
|
26
|
+
kind: 'DocumentPackage';
|
|
27
|
+
value: DocumentPackage;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'ContentDocument';
|
|
30
|
+
value: ContentDocument;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'LayoutDocument';
|
|
33
|
+
value: LayoutDocument;
|
|
34
|
+
};
|
|
35
|
+
declare function documentFromJson(value: unknown): DocumentJsonResult;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ContentDocumentJson, DocumentJsonResult, DocumentPackageJson, DocumentSchemaKind, LayoutDocumentJson, SCHEMA_FILE_NAMES, UnrecognizedDocumentSchemaError, contentDocumentWithSchema, documentFromJson, documentPackageWithSchema, documentSchemaKindOf, layoutDocumentWithSchema, schemaUriFor };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ContentDocumentSchema } from "./content.js";
|
|
2
|
+
import { LayoutDocumentSchema } from "./layout.js";
|
|
3
|
+
import { DocumentPackageSchema } from "./package.js";
|
|
4
|
+
//#region src/schema-io.ts
|
|
5
|
+
const SCHEMA_FILE_NAMES = {
|
|
6
|
+
DocumentPackage: "document-package.schema.json",
|
|
7
|
+
ContentDocument: "content-document.schema.json",
|
|
8
|
+
LayoutDocument: "layout-document.schema.json"
|
|
9
|
+
};
|
|
10
|
+
function schemaUriFor(kind) {
|
|
11
|
+
return `https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/${SCHEMA_FILE_NAMES[kind]}`;
|
|
12
|
+
}
|
|
13
|
+
const SCHEMA_URI_PATTERN = /^https:\/\/cdn\.jsdelivr\.net\/npm\/document-schema\.js@[^/]+\/schemas\/(document-package|content-document|layout-document)\.schema\.json$/;
|
|
14
|
+
function kindForFileStem(stem) {
|
|
15
|
+
switch (stem) {
|
|
16
|
+
case "document-package": return "DocumentPackage";
|
|
17
|
+
case "content-document": return "ContentDocument";
|
|
18
|
+
case "layout-document": return "LayoutDocument";
|
|
19
|
+
default: return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function documentSchemaKindOf(value) {
|
|
26
|
+
if (!isRecord(value)) return void 0;
|
|
27
|
+
if (!("$schema" in value) || typeof value.$schema !== "string") return void 0;
|
|
28
|
+
const match = SCHEMA_URI_PATTERN.exec(value.$schema);
|
|
29
|
+
if (match === null) return void 0;
|
|
30
|
+
const stem = match[1];
|
|
31
|
+
if (stem === void 0) return void 0;
|
|
32
|
+
return kindForFileStem(stem);
|
|
33
|
+
}
|
|
34
|
+
function documentPackageWithSchema(value) {
|
|
35
|
+
return {
|
|
36
|
+
$schema: schemaUriFor("DocumentPackage"),
|
|
37
|
+
...value
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function contentDocumentWithSchema(value) {
|
|
41
|
+
return {
|
|
42
|
+
$schema: schemaUriFor("ContentDocument"),
|
|
43
|
+
...value
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function layoutDocumentWithSchema(value) {
|
|
47
|
+
return {
|
|
48
|
+
$schema: schemaUriFor("LayoutDocument"),
|
|
49
|
+
...value
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var UnrecognizedDocumentSchemaError = class extends Error {
|
|
53
|
+
schema;
|
|
54
|
+
constructor(schema) {
|
|
55
|
+
super(`documentFromJson: value has no recognized "$schema" property (expected one of the three document-schema.js .schema.json URIs; found: ${JSON.stringify(schema)}).`);
|
|
56
|
+
this.name = "UnrecognizedDocumentSchemaError";
|
|
57
|
+
this.schema = schema;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
function documentFromJson(value) {
|
|
61
|
+
const kind = documentSchemaKindOf(value);
|
|
62
|
+
if (kind === void 0) throw new UnrecognizedDocumentSchemaError(isRecord(value) ? value.$schema : void 0);
|
|
63
|
+
switch (kind) {
|
|
64
|
+
case "DocumentPackage": return {
|
|
65
|
+
kind,
|
|
66
|
+
value: DocumentPackageSchema.parse(value)
|
|
67
|
+
};
|
|
68
|
+
case "ContentDocument": return {
|
|
69
|
+
kind,
|
|
70
|
+
value: ContentDocumentSchema.parse(value)
|
|
71
|
+
};
|
|
72
|
+
case "LayoutDocument": return {
|
|
73
|
+
kind,
|
|
74
|
+
value: LayoutDocumentSchema.parse(value)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { SCHEMA_FILE_NAMES, UnrecognizedDocumentSchemaError, contentDocumentWithSchema, documentFromJson, documentPackageWithSchema, documentSchemaKindOf, layoutDocumentWithSchema, schemaUriFor };
|
package/dist/style.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
//#region src/style.ts
|
|
4
|
+
const AlignmentSchema = zod.z.enum([
|
|
5
|
+
"left",
|
|
6
|
+
"center",
|
|
7
|
+
"right",
|
|
8
|
+
"justify"
|
|
9
|
+
]);
|
|
10
|
+
const LayoutFontSchema = zod.z.object({
|
|
11
|
+
family: zod.z.string(),
|
|
12
|
+
weight: zod.z.enum(["normal", "bold"]),
|
|
13
|
+
style: zod.z.enum(["normal", "italic"])
|
|
14
|
+
});
|
|
15
|
+
const DEFAULT_LAYOUT_FONT = {
|
|
16
|
+
family: "Helvetica",
|
|
17
|
+
weight: "normal",
|
|
18
|
+
style: "normal"
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.AlignmentSchema = AlignmentSchema;
|
|
22
|
+
exports.DEFAULT_LAYOUT_FONT = DEFAULT_LAYOUT_FONT;
|
|
23
|
+
exports.LayoutFontSchema = LayoutFontSchema;
|
package/dist/style.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/style.d.ts
|
|
3
|
+
declare const AlignmentSchema: z.ZodEnum<{
|
|
4
|
+
left: "left";
|
|
5
|
+
center: "center";
|
|
6
|
+
right: "right";
|
|
7
|
+
justify: "justify";
|
|
8
|
+
}>;
|
|
9
|
+
type Alignment = z.infer<typeof AlignmentSchema>;
|
|
10
|
+
declare const LayoutFontSchema: z.ZodObject<{
|
|
11
|
+
family: z.ZodString;
|
|
12
|
+
weight: z.ZodEnum<{
|
|
13
|
+
normal: "normal";
|
|
14
|
+
bold: "bold";
|
|
15
|
+
}>;
|
|
16
|
+
style: z.ZodEnum<{
|
|
17
|
+
normal: "normal";
|
|
18
|
+
italic: "italic";
|
|
19
|
+
}>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
type LayoutFont = z.infer<typeof LayoutFontSchema>;
|
|
22
|
+
declare const DEFAULT_LAYOUT_FONT: LayoutFont;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Alignment, AlignmentSchema, DEFAULT_LAYOUT_FONT, LayoutFont, LayoutFontSchema };
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/style.d.ts
|
|
3
|
+
declare const AlignmentSchema: z.ZodEnum<{
|
|
4
|
+
left: "left";
|
|
5
|
+
center: "center";
|
|
6
|
+
right: "right";
|
|
7
|
+
justify: "justify";
|
|
8
|
+
}>;
|
|
9
|
+
type Alignment = z.infer<typeof AlignmentSchema>;
|
|
10
|
+
declare const LayoutFontSchema: z.ZodObject<{
|
|
11
|
+
family: z.ZodString;
|
|
12
|
+
weight: z.ZodEnum<{
|
|
13
|
+
normal: "normal";
|
|
14
|
+
bold: "bold";
|
|
15
|
+
}>;
|
|
16
|
+
style: z.ZodEnum<{
|
|
17
|
+
normal: "normal";
|
|
18
|
+
italic: "italic";
|
|
19
|
+
}>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
type LayoutFont = z.infer<typeof LayoutFontSchema>;
|
|
22
|
+
declare const DEFAULT_LAYOUT_FONT: LayoutFont;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Alignment, AlignmentSchema, DEFAULT_LAYOUT_FONT, LayoutFont, LayoutFontSchema };
|
package/dist/style.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/style.ts
|
|
3
|
+
const AlignmentSchema = z.enum([
|
|
4
|
+
"left",
|
|
5
|
+
"center",
|
|
6
|
+
"right",
|
|
7
|
+
"justify"
|
|
8
|
+
]);
|
|
9
|
+
const LayoutFontSchema = z.object({
|
|
10
|
+
family: z.string(),
|
|
11
|
+
weight: z.enum(["normal", "bold"]),
|
|
12
|
+
style: z.enum(["normal", "italic"])
|
|
13
|
+
});
|
|
14
|
+
const DEFAULT_LAYOUT_FONT = {
|
|
15
|
+
family: "Helvetica",
|
|
16
|
+
weight: "normal",
|
|
17
|
+
style: "normal"
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { AlignmentSchema, DEFAULT_LAYOUT_FONT, LayoutFontSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-model.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "The canonical, format-agnostic content and layout schemas shared by ooxml.js, odf.js, and documents.js -- pure Zod schemas, no behaviour.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -20,9 +20,15 @@
|
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
21
|
"require": "./dist/index.cjs"
|
|
22
22
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"./*": {
|
|
24
|
+
"types": {
|
|
25
|
+
"import": "./dist/*.d.ts",
|
|
26
|
+
"require": "./dist/*.d.cts"
|
|
27
|
+
},
|
|
28
|
+
"import": "./dist/*.js",
|
|
29
|
+
"require": "./dist/*.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./schemas/*.schema.json": "./schemas/*.schema.json"
|
|
26
32
|
},
|
|
27
33
|
"main": "./dist/index.cjs",
|
|
28
34
|
"module": "./dist/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
3
|
+
"$id": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/content-document.schema.json",
|
|
4
4
|
"oneOf": [
|
|
5
5
|
{
|
|
6
6
|
"type": "object",
|
|
@@ -930,7 +930,7 @@
|
|
|
930
930
|
]
|
|
931
931
|
},
|
|
932
932
|
"document": {
|
|
933
|
-
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
933
|
+
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/content-document.schema.json"
|
|
934
934
|
},
|
|
935
935
|
"frame": {
|
|
936
936
|
"$ref": "#/$defs/Box"
|
|
@@ -2021,7 +2021,7 @@
|
|
|
2021
2021
|
]
|
|
2022
2022
|
},
|
|
2023
2023
|
"document": {
|
|
2024
|
-
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
2024
|
+
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/content-document.schema.json"
|
|
2025
2025
|
},
|
|
2026
2026
|
"frame": {
|
|
2027
2027
|
"$ref": "#/$defs/Box"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
3
|
+
"$id": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/document-package.schema.json",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
6
|
"formatVersion": {
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"const": 1
|
|
9
9
|
},
|
|
10
10
|
"content": {
|
|
11
|
-
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
11
|
+
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/content-document.schema.json"
|
|
12
12
|
},
|
|
13
13
|
"layout": {
|
|
14
|
-
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
14
|
+
"$ref": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/layout-document.schema.json"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"required": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://cdn.jsdelivr.net/npm/document-schema.js@1.
|
|
3
|
+
"$id": "https://cdn.jsdelivr.net/npm/document-schema.js@1.10.0/schemas/layout-document.schema.json",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
6
|
"formatVersion": {
|