document-model.js 4.1.0 → 4.3.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 +64 -9
- package/dist/canonicalise.cjs +20 -0
- package/dist/canonicalise.d.cts +5 -0
- package/dist/canonicalise.d.ts +5 -0
- package/dist/canonicalise.js +18 -0
- package/dist/codec.d.cts +1 -1
- package/dist/codec.d.ts +1 -1
- package/dist/{content-BN0PWqpt.d.cts → content-BmqzegMG.d.cts} +90 -2
- package/dist/{content-CiZf6Fqn.d.ts → content-CIwPb_yh.d.ts} +90 -2
- package/dist/content-json-schema-defs.cjs +36 -6
- package/dist/content-json-schema-defs.js +36 -6
- package/dist/content.cjs +32 -0
- package/dist/content.d.cts +2 -2
- package/dist/content.d.ts +2 -2
- package/dist/content.js +28 -1
- package/dist/decompose.cjs +186 -0
- package/dist/decompose.d.cts +18 -0
- package/dist/decompose.d.ts +18 -0
- package/dist/decompose.js +177 -0
- package/dist/definitions.d.cts +1 -1
- package/dist/definitions.d.ts +1 -1
- package/dist/factor-styles.cjs +435 -0
- package/dist/factor-styles.d.cts +9 -0
- package/dist/factor-styles.d.ts +9 -0
- package/dist/factor-styles.js +432 -0
- package/dist/flatten.cjs +154 -0
- package/dist/flatten.d.cts +6 -0
- package/dist/flatten.d.ts +6 -0
- package/dist/flatten.js +153 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/{package-node-DLUobcDQ.d.ts → package-node-C7RiYhyk.d.ts} +9 -6
- package/dist/{package-node-BiUEzIzl.d.cts → package-node-a9CyRaD3.d.cts} +9 -6
- package/dist/package-node.cjs +11 -4
- package/dist/package-node.d.cts +2 -2
- package/dist/package-node.d.ts +2 -2
- package/dist/package-node.js +11 -6
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/dist/schema-io.cjs +2 -2
- package/dist/schema-io.d.cts +1 -1
- package/dist/schema-io.d.ts +1 -1
- package/dist/schema-io.js +2 -2
- package/package.json +2 -2
- package/schemas/content-document.schema.json +64 -9
- package/schemas/document-package.schema.json +64 -9
|
@@ -389,7 +389,37 @@ const CONTENT_DEFS = {
|
|
|
389
389
|
],
|
|
390
390
|
additionalProperties: false
|
|
391
391
|
},
|
|
392
|
+
ContentConstructStart: {
|
|
393
|
+
type: "object",
|
|
394
|
+
properties: {
|
|
395
|
+
kind: {
|
|
396
|
+
type: "string",
|
|
397
|
+
const: "constructStart"
|
|
398
|
+
},
|
|
399
|
+
descriptor: { $ref: "#/$defs/ConstructDescriptor" }
|
|
400
|
+
},
|
|
401
|
+
required: ["kind", "descriptor"],
|
|
402
|
+
additionalProperties: false
|
|
403
|
+
},
|
|
404
|
+
ContentConstructEnd: {
|
|
405
|
+
type: "object",
|
|
406
|
+
properties: { kind: {
|
|
407
|
+
type: "string",
|
|
408
|
+
const: "constructEnd"
|
|
409
|
+
} },
|
|
410
|
+
required: ["kind"],
|
|
411
|
+
additionalProperties: false
|
|
412
|
+
},
|
|
392
413
|
ContentBlock: { oneOf: [
|
|
414
|
+
{ $ref: "#/$defs/ContentParagraph" },
|
|
415
|
+
{ $ref: "#/$defs/ContentTable" },
|
|
416
|
+
{ $ref: "#/$defs/ContentImageBlock" },
|
|
417
|
+
{ $ref: "#/$defs/ContentPageBreak" },
|
|
418
|
+
{ $ref: "#/$defs/ContentEmbeddedObjectBlock" },
|
|
419
|
+
{ $ref: "#/$defs/ContentConstructStart" },
|
|
420
|
+
{ $ref: "#/$defs/ContentConstructEnd" }
|
|
421
|
+
] },
|
|
422
|
+
PackageBlockLeaf: { oneOf: [
|
|
393
423
|
{ $ref: "#/$defs/ContentParagraph" },
|
|
394
424
|
{ $ref: "#/$defs/ContentTable" },
|
|
395
425
|
{ $ref: "#/$defs/ContentImageBlock" },
|
|
@@ -1267,7 +1297,7 @@ const CONTENT_DEFS = {
|
|
|
1267
1297
|
{ $ref: "#/$defs/HeadingGroup" },
|
|
1268
1298
|
{ $ref: "#/$defs/ListGroup" },
|
|
1269
1299
|
{ $ref: "#/$defs/SectionConstructGroup" },
|
|
1270
|
-
{ $ref: "#/$defs/
|
|
1300
|
+
{ $ref: "#/$defs/PackageBlockLeaf" }
|
|
1271
1301
|
] }
|
|
1272
1302
|
}
|
|
1273
1303
|
},
|
|
@@ -1285,7 +1315,7 @@ const CONTENT_DEFS = {
|
|
|
1285
1315
|
{ $ref: "#/$defs/HeadingGroup" },
|
|
1286
1316
|
{ $ref: "#/$defs/ListGroup" },
|
|
1287
1317
|
{ $ref: "#/$defs/SectionConstructGroup" },
|
|
1288
|
-
{ $ref: "#/$defs/
|
|
1318
|
+
{ $ref: "#/$defs/PackageBlockLeaf" }
|
|
1289
1319
|
] }
|
|
1290
1320
|
}
|
|
1291
1321
|
},
|
|
@@ -1302,7 +1332,7 @@ const CONTENT_DEFS = {
|
|
|
1302
1332
|
items: { oneOf: [
|
|
1303
1333
|
{ $ref: "#/$defs/ListGroup" },
|
|
1304
1334
|
{ $ref: "#/$defs/ShapeConstructGroup" },
|
|
1305
|
-
{ $ref: "#/$defs/
|
|
1335
|
+
{ $ref: "#/$defs/PackageBlockLeaf" }
|
|
1306
1336
|
] }
|
|
1307
1337
|
}
|
|
1308
1338
|
},
|
|
@@ -1332,7 +1362,7 @@ const CONTENT_DEFS = {
|
|
|
1332
1362
|
items: { oneOf: [
|
|
1333
1363
|
{ $ref: "#/$defs/ListGroup" },
|
|
1334
1364
|
{ $ref: "#/$defs/ShapeConstructGroup" },
|
|
1335
|
-
{ $ref: "#/$defs/
|
|
1365
|
+
{ $ref: "#/$defs/PackageBlockLeaf" }
|
|
1336
1366
|
] }
|
|
1337
1367
|
}
|
|
1338
1368
|
},
|
|
@@ -1376,7 +1406,7 @@ const CONTENT_DEFS = {
|
|
|
1376
1406
|
{ $ref: "#/$defs/HeadingGroup" },
|
|
1377
1407
|
{ $ref: "#/$defs/ListGroup" },
|
|
1378
1408
|
{ $ref: "#/$defs/SectionConstructGroup" },
|
|
1379
|
-
{ $ref: "#/$defs/
|
|
1409
|
+
{ $ref: "#/$defs/PackageBlockLeaf" }
|
|
1380
1410
|
] }
|
|
1381
1411
|
}
|
|
1382
1412
|
},
|
|
@@ -1393,7 +1423,7 @@ const CONTENT_DEFS = {
|
|
|
1393
1423
|
items: { oneOf: [
|
|
1394
1424
|
{ $ref: "#/$defs/ListGroup" },
|
|
1395
1425
|
{ $ref: "#/$defs/ShapeConstructGroup" },
|
|
1396
|
-
{ $ref: "#/$defs/
|
|
1426
|
+
{ $ref: "#/$defs/PackageBlockLeaf" }
|
|
1397
1427
|
] }
|
|
1398
1428
|
}
|
|
1399
1429
|
},
|
package/dist/content.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_color = require("./color.cjs");
|
|
3
|
+
const require_construct = require("./construct.cjs");
|
|
3
4
|
const require_math = require("./math.cjs");
|
|
4
5
|
const require_geometry = require("./geometry.cjs");
|
|
5
6
|
const require_mathml = require("./mathml.cjs");
|
|
@@ -57,6 +58,11 @@ const ContentPageBreakSchema = zod.z.object({
|
|
|
57
58
|
sourcePath: zod.z.string().optional(),
|
|
58
59
|
frames: zod.z.array(require_geometry.LayoutFrameSchema).optional()
|
|
59
60
|
});
|
|
61
|
+
const ContentConstructStartSchema = zod.z.object({
|
|
62
|
+
kind: zod.z.literal("constructStart"),
|
|
63
|
+
descriptor: require_construct.ConstructDescriptorSchema
|
|
64
|
+
});
|
|
65
|
+
const ContentConstructEndSchema = zod.z.object({ kind: zod.z.literal("constructEnd") });
|
|
60
66
|
function isRecord(value) {
|
|
61
67
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
68
|
}
|
|
@@ -78,6 +84,12 @@ function isContentEmbeddedObject(value) {
|
|
|
78
84
|
function isContentEmbeddedObjectBlock(value) {
|
|
79
85
|
return isRecord(value) && value.kind === "embeddedObject" && isContentEmbeddedObject(value);
|
|
80
86
|
}
|
|
87
|
+
function isContentConstructStart(value) {
|
|
88
|
+
return isRecord(value) && value.kind === "constructStart" && require_construct.ConstructDescriptorSchema.safeParse(value.descriptor).success;
|
|
89
|
+
}
|
|
90
|
+
function isContentConstructEnd(value) {
|
|
91
|
+
return isRecord(value) && value.kind === "constructEnd";
|
|
92
|
+
}
|
|
81
93
|
function isContentBlock(value) {
|
|
82
94
|
if (!isRecord(value)) return false;
|
|
83
95
|
const kind = value.kind;
|
|
@@ -86,11 +98,26 @@ function isContentBlock(value) {
|
|
|
86
98
|
if (kind === "pageBreak") return true;
|
|
87
99
|
if (kind === "table") return Array.isArray(value.rows) && value.rows.every(isContentTableRow) && Array.isArray(value.columnWidthsPt) && value.columnWidthsPt.every((w) => typeof w === "number");
|
|
88
100
|
if (kind === "embeddedObject") return isContentEmbeddedObject(value);
|
|
101
|
+
if (kind === "constructStart") return isContentConstructStart(value);
|
|
102
|
+
if (kind === "constructEnd") return true;
|
|
89
103
|
return false;
|
|
90
104
|
}
|
|
91
105
|
const ContentBlockSchema = zod.z.custom(isContentBlock);
|
|
92
106
|
const ContentEmbeddedObjectSchema = zod.z.custom(isContentEmbeddedObject);
|
|
93
107
|
const ContentEmbeddedObjectBlockSchema = zod.z.custom(isContentEmbeddedObjectBlock);
|
|
108
|
+
function findConstructMarkerImbalance(blocks) {
|
|
109
|
+
const openStartIndices = [];
|
|
110
|
+
for (const [index, block] of blocks.entries()) if (isContentConstructStart(block)) openStartIndices.push(index);
|
|
111
|
+
else if (isContentConstructEnd(block) && openStartIndices.pop() === void 0) return {
|
|
112
|
+
kind: "unmatchedEnd",
|
|
113
|
+
index
|
|
114
|
+
};
|
|
115
|
+
const outermostUnclosed = openStartIndices[0];
|
|
116
|
+
if (outermostUnclosed !== void 0) return {
|
|
117
|
+
kind: "unclosedStart",
|
|
118
|
+
index: outermostUnclosed
|
|
119
|
+
};
|
|
120
|
+
}
|
|
94
121
|
const ContentStrokeStyleSchema = zod.z.enum([
|
|
95
122
|
"solid",
|
|
96
123
|
"dashed",
|
|
@@ -397,6 +424,8 @@ exports.ContentBlockSchema = ContentBlockSchema;
|
|
|
397
424
|
exports.ContentBorderSchema = ContentBorderSchema;
|
|
398
425
|
exports.ContentCellBordersSchema = ContentCellBordersSchema;
|
|
399
426
|
exports.ContentCellValueSchema = ContentCellValueSchema;
|
|
427
|
+
exports.ContentConstructEndSchema = ContentConstructEndSchema;
|
|
428
|
+
exports.ContentConstructStartSchema = ContentConstructStartSchema;
|
|
400
429
|
exports.ContentDocumentSchema = ContentDocumentSchema;
|
|
401
430
|
exports.ContentDrawPageSchema = ContentDrawPageSchema;
|
|
402
431
|
exports.ContentEmbeddedObjectBlockSchema = ContentEmbeddedObjectBlockSchema;
|
|
@@ -431,4 +460,7 @@ exports.ContentVectorSchema = ContentVectorSchema;
|
|
|
431
460
|
exports.DecimalStringSchema = DecimalStringSchema;
|
|
432
461
|
exports.clampHeadingLevel = clampHeadingLevel;
|
|
433
462
|
exports.contentDocumentSharedFields = contentDocumentSharedFields;
|
|
463
|
+
exports.findConstructMarkerImbalance = findConstructMarkerImbalance;
|
|
434
464
|
exports.isContentBlock = isContentBlock;
|
|
465
|
+
exports.isContentConstructEnd = isContentConstructEnd;
|
|
466
|
+
exports.isContentConstructStart = isContentConstructStart;
|
package/dist/content.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { ContentBlock, ContentBlockSchema, ContentBorder, ContentBorderSchema, ContentCellBorders, ContentCellBordersSchema, ContentCellValue, ContentCellValueSchema, ContentDocument, ContentDocumentSchema, ContentDrawPage, ContentDrawPageSchema, ContentEmbeddedObject, ContentEmbeddedObjectBlock, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectKind, ContentEmbeddedObjectSchema, ContentFormula, ContentFormulaSchema, ContentImageBlock, ContentImageBlockSchema, ContentListMembership, ContentListMembershipSchema, ContentPageBreak, ContentPageBreakSchema, ContentParagraph, ContentParagraphSchema, ContentPathPoint, ContentPathPointSchema, ContentPathSegment, ContentPathSegmentSchema, ContentRun, ContentRunSchema, ContentSection, ContentSectionSchema, ContentShape, ContentShapeSchema, ContentSheet, ContentSheetCell, ContentSheetCellComment, ContentSheetCellCommentSchema, ContentSheetCellSchema, ContentSheetColumn, ContentSheetColumnSchema, ContentSheetImage, ContentSheetImageSchema, ContentSheetPrintRange, ContentSheetPrintRangeSchema, ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, ContentSlide, ContentSlideSchema, ContentStroke, ContentStrokeSchema, ContentStrokeStyle, ContentStrokeStyleSchema, ContentSubpath, ContentSubpathSchema, ContentTable, ContentTableCell, ContentTableCellSchema, ContentTableRow, ContentTableRowSchema, ContentTableSchema, ContentVector, ContentVectorSchema, DecimalString, DecimalStringSchema, FusedNode, clampHeadingLevel, contentDocumentSharedFields, isContentBlock };
|
|
1
|
+
import { $ as ContentSheetPrintRangeSchema, A as ContentPageBreakSchema, At as isContentConstructEnd, B as ContentSectionSchema, C as ContentFormula, Ct as DecimalString, D as ContentListMembership, Dt as contentDocumentSharedFields, E as ContentImageBlockSchema, Et as clampHeadingLevel, F as ContentPathSegment, G as ContentSheetCellComment, H as ContentShapeSchema, I as ContentPathSegmentSchema, J as ContentSheetColumn, K as ContentSheetCellCommentSchema, L as ContentRun, M as ContentParagraphSchema, N as ContentPathPoint, O as ContentListMembershipSchema, Ot as findConstructMarkerImbalance, P as ContentPathPointSchema, Q as ContentSheetPrintRange, R as ContentRunSchema, S as ContentEmbeddedObjectSchema, St as ContentVectorSchema, T as ContentImageBlock, Tt as FusedNode, U as ContentSheet, V as ContentShape, W as ContentSheetCell, X as ContentSheetImage, Y as ContentSheetColumnSchema, Z as ContentSheetImageSchema, _ as ContentDrawPageSchema, _t as ContentTableCellSchema, a as ContentBorderSchema, at as ContentSheetRowSchema, b as ContentEmbeddedObjectBlockSchema, bt as ContentTableSchema, c as ContentCellValue, ct as ContentSlideSchema, d as ContentConstructEndSchema, dt as ContentStrokeStyle, et as ContentSheetPrintSettings, f as ContentConstructStart, ft as ContentStrokeStyleSchema, g as ContentDrawPage, gt as ContentTableCell, h as ContentDocumentSchema, ht as ContentTable, i as ContentBorder, it as ContentSheetRow, j as ContentParagraph, jt as isContentConstructStart, k as ContentPageBreak, kt as isContentBlock, l as ContentCellValueSchema, lt as ContentStroke, m as ContentDocument, mt as ContentSubpathSchema, n as ContentBlock, nt as ContentSheetRepeatRange, o as ContentCellBorders, ot as ContentSheetSchema, p as ContentConstructStartSchema, pt as ContentSubpath, q as ContentSheetCellSchema, r as ContentBlockSchema, rt as ContentSheetRepeatRangeSchema, s as ContentCellBordersSchema, st as ContentSlide, t as ConstructMarkerImbalance, tt as ContentSheetPrintSettingsSchema, u as ContentConstructEnd, ut as ContentStrokeSchema, v as ContentEmbeddedObject, vt as ContentTableRow, w as ContentFormulaSchema, wt as DecimalStringSchema, x as ContentEmbeddedObjectKind, xt as ContentVector, y as ContentEmbeddedObjectBlock, yt as ContentTableRowSchema, z as ContentSection } from "./content-BmqzegMG.cjs";
|
|
2
|
+
export { ConstructMarkerImbalance, ContentBlock, ContentBlockSchema, ContentBorder, ContentBorderSchema, ContentCellBorders, ContentCellBordersSchema, ContentCellValue, ContentCellValueSchema, ContentConstructEnd, ContentConstructEndSchema, ContentConstructStart, ContentConstructStartSchema, ContentDocument, ContentDocumentSchema, ContentDrawPage, ContentDrawPageSchema, ContentEmbeddedObject, ContentEmbeddedObjectBlock, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectKind, ContentEmbeddedObjectSchema, ContentFormula, ContentFormulaSchema, ContentImageBlock, ContentImageBlockSchema, ContentListMembership, ContentListMembershipSchema, ContentPageBreak, ContentPageBreakSchema, ContentParagraph, ContentParagraphSchema, ContentPathPoint, ContentPathPointSchema, ContentPathSegment, ContentPathSegmentSchema, ContentRun, ContentRunSchema, ContentSection, ContentSectionSchema, ContentShape, ContentShapeSchema, ContentSheet, ContentSheetCell, ContentSheetCellComment, ContentSheetCellCommentSchema, ContentSheetCellSchema, ContentSheetColumn, ContentSheetColumnSchema, ContentSheetImage, ContentSheetImageSchema, ContentSheetPrintRange, ContentSheetPrintRangeSchema, ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, ContentSlide, ContentSlideSchema, ContentStroke, ContentStrokeSchema, ContentStrokeStyle, ContentStrokeStyleSchema, ContentSubpath, ContentSubpathSchema, ContentTable, ContentTableCell, ContentTableCellSchema, ContentTableRow, ContentTableRowSchema, ContentTableSchema, ContentVector, ContentVectorSchema, DecimalString, DecimalStringSchema, FusedNode, clampHeadingLevel, contentDocumentSharedFields, findConstructMarkerImbalance, isContentBlock, isContentConstructEnd, isContentConstructStart };
|
package/dist/content.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { ContentBlock, ContentBlockSchema, ContentBorder, ContentBorderSchema, ContentCellBorders, ContentCellBordersSchema, ContentCellValue, ContentCellValueSchema, ContentDocument, ContentDocumentSchema, ContentDrawPage, ContentDrawPageSchema, ContentEmbeddedObject, ContentEmbeddedObjectBlock, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectKind, ContentEmbeddedObjectSchema, ContentFormula, ContentFormulaSchema, ContentImageBlock, ContentImageBlockSchema, ContentListMembership, ContentListMembershipSchema, ContentPageBreak, ContentPageBreakSchema, ContentParagraph, ContentParagraphSchema, ContentPathPoint, ContentPathPointSchema, ContentPathSegment, ContentPathSegmentSchema, ContentRun, ContentRunSchema, ContentSection, ContentSectionSchema, ContentShape, ContentShapeSchema, ContentSheet, ContentSheetCell, ContentSheetCellComment, ContentSheetCellCommentSchema, ContentSheetCellSchema, ContentSheetColumn, ContentSheetColumnSchema, ContentSheetImage, ContentSheetImageSchema, ContentSheetPrintRange, ContentSheetPrintRangeSchema, ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, ContentSlide, ContentSlideSchema, ContentStroke, ContentStrokeSchema, ContentStrokeStyle, ContentStrokeStyleSchema, ContentSubpath, ContentSubpathSchema, ContentTable, ContentTableCell, ContentTableCellSchema, ContentTableRow, ContentTableRowSchema, ContentTableSchema, ContentVector, ContentVectorSchema, DecimalString, DecimalStringSchema, FusedNode, clampHeadingLevel, contentDocumentSharedFields, isContentBlock };
|
|
1
|
+
import { $ as ContentSheetPrintRangeSchema, A as ContentPageBreakSchema, At as isContentConstructEnd, B as ContentSectionSchema, C as ContentFormula, Ct as DecimalString, D as ContentListMembership, Dt as contentDocumentSharedFields, E as ContentImageBlockSchema, Et as clampHeadingLevel, F as ContentPathSegment, G as ContentSheetCellComment, H as ContentShapeSchema, I as ContentPathSegmentSchema, J as ContentSheetColumn, K as ContentSheetCellCommentSchema, L as ContentRun, M as ContentParagraphSchema, N as ContentPathPoint, O as ContentListMembershipSchema, Ot as findConstructMarkerImbalance, P as ContentPathPointSchema, Q as ContentSheetPrintRange, R as ContentRunSchema, S as ContentEmbeddedObjectSchema, St as ContentVectorSchema, T as ContentImageBlock, Tt as FusedNode, U as ContentSheet, V as ContentShape, W as ContentSheetCell, X as ContentSheetImage, Y as ContentSheetColumnSchema, Z as ContentSheetImageSchema, _ as ContentDrawPageSchema, _t as ContentTableCellSchema, a as ContentBorderSchema, at as ContentSheetRowSchema, b as ContentEmbeddedObjectBlockSchema, bt as ContentTableSchema, c as ContentCellValue, ct as ContentSlideSchema, d as ContentConstructEndSchema, dt as ContentStrokeStyle, et as ContentSheetPrintSettings, f as ContentConstructStart, ft as ContentStrokeStyleSchema, g as ContentDrawPage, gt as ContentTableCell, h as ContentDocumentSchema, ht as ContentTable, i as ContentBorder, it as ContentSheetRow, j as ContentParagraph, jt as isContentConstructStart, k as ContentPageBreak, kt as isContentBlock, l as ContentCellValueSchema, lt as ContentStroke, m as ContentDocument, mt as ContentSubpathSchema, n as ContentBlock, nt as ContentSheetRepeatRange, o as ContentCellBorders, ot as ContentSheetSchema, p as ContentConstructStartSchema, pt as ContentSubpath, q as ContentSheetCellSchema, r as ContentBlockSchema, rt as ContentSheetRepeatRangeSchema, s as ContentCellBordersSchema, st as ContentSlide, t as ConstructMarkerImbalance, tt as ContentSheetPrintSettingsSchema, u as ContentConstructEnd, ut as ContentStrokeSchema, v as ContentEmbeddedObject, vt as ContentTableRow, w as ContentFormulaSchema, wt as DecimalStringSchema, x as ContentEmbeddedObjectKind, xt as ContentVector, y as ContentEmbeddedObjectBlock, yt as ContentTableRowSchema, z as ContentSection } from "./content-CIwPb_yh.js";
|
|
2
|
+
export { ConstructMarkerImbalance, ContentBlock, ContentBlockSchema, ContentBorder, ContentBorderSchema, ContentCellBorders, ContentCellBordersSchema, ContentCellValue, ContentCellValueSchema, ContentConstructEnd, ContentConstructEndSchema, ContentConstructStart, ContentConstructStartSchema, ContentDocument, ContentDocumentSchema, ContentDrawPage, ContentDrawPageSchema, ContentEmbeddedObject, ContentEmbeddedObjectBlock, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectKind, ContentEmbeddedObjectSchema, ContentFormula, ContentFormulaSchema, ContentImageBlock, ContentImageBlockSchema, ContentListMembership, ContentListMembershipSchema, ContentPageBreak, ContentPageBreakSchema, ContentParagraph, ContentParagraphSchema, ContentPathPoint, ContentPathPointSchema, ContentPathSegment, ContentPathSegmentSchema, ContentRun, ContentRunSchema, ContentSection, ContentSectionSchema, ContentShape, ContentShapeSchema, ContentSheet, ContentSheetCell, ContentSheetCellComment, ContentSheetCellCommentSchema, ContentSheetCellSchema, ContentSheetColumn, ContentSheetColumnSchema, ContentSheetImage, ContentSheetImageSchema, ContentSheetPrintRange, ContentSheetPrintRangeSchema, ContentSheetPrintSettings, ContentSheetPrintSettingsSchema, ContentSheetRepeatRange, ContentSheetRepeatRangeSchema, ContentSheetRow, ContentSheetRowSchema, ContentSheetSchema, ContentSlide, ContentSlideSchema, ContentStroke, ContentStrokeSchema, ContentStrokeStyle, ContentStrokeStyleSchema, ContentSubpath, ContentSubpathSchema, ContentTable, ContentTableCell, ContentTableCellSchema, ContentTableRow, ContentTableRowSchema, ContentTableSchema, ContentVector, ContentVectorSchema, DecimalString, DecimalStringSchema, FusedNode, clampHeadingLevel, contentDocumentSharedFields, findConstructMarkerImbalance, isContentBlock, isContentConstructEnd, isContentConstructStart };
|
package/dist/content.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ColorSchema } from "./color.js";
|
|
2
|
+
import { ConstructDescriptorSchema } from "./construct.js";
|
|
2
3
|
import { MathExpressionSchema, MathPresentationSchema, MathProvenanceSchema, SymbolTableSchema } from "./math.js";
|
|
3
4
|
import { BoxSchema, LayoutFrameSchema, MarginsSchema, PageSizeSchema } from "./geometry.js";
|
|
4
5
|
import { MathMlNodeSchema } from "./mathml.js";
|
|
@@ -56,6 +57,11 @@ const ContentPageBreakSchema = z.object({
|
|
|
56
57
|
sourcePath: z.string().optional(),
|
|
57
58
|
frames: z.array(LayoutFrameSchema).optional()
|
|
58
59
|
});
|
|
60
|
+
const ContentConstructStartSchema = z.object({
|
|
61
|
+
kind: z.literal("constructStart"),
|
|
62
|
+
descriptor: ConstructDescriptorSchema
|
|
63
|
+
});
|
|
64
|
+
const ContentConstructEndSchema = z.object({ kind: z.literal("constructEnd") });
|
|
59
65
|
function isRecord(value) {
|
|
60
66
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
61
67
|
}
|
|
@@ -77,6 +83,12 @@ function isContentEmbeddedObject(value) {
|
|
|
77
83
|
function isContentEmbeddedObjectBlock(value) {
|
|
78
84
|
return isRecord(value) && value.kind === "embeddedObject" && isContentEmbeddedObject(value);
|
|
79
85
|
}
|
|
86
|
+
function isContentConstructStart(value) {
|
|
87
|
+
return isRecord(value) && value.kind === "constructStart" && ConstructDescriptorSchema.safeParse(value.descriptor).success;
|
|
88
|
+
}
|
|
89
|
+
function isContentConstructEnd(value) {
|
|
90
|
+
return isRecord(value) && value.kind === "constructEnd";
|
|
91
|
+
}
|
|
80
92
|
function isContentBlock(value) {
|
|
81
93
|
if (!isRecord(value)) return false;
|
|
82
94
|
const kind = value.kind;
|
|
@@ -85,11 +97,26 @@ function isContentBlock(value) {
|
|
|
85
97
|
if (kind === "pageBreak") return true;
|
|
86
98
|
if (kind === "table") return Array.isArray(value.rows) && value.rows.every(isContentTableRow) && Array.isArray(value.columnWidthsPt) && value.columnWidthsPt.every((w) => typeof w === "number");
|
|
87
99
|
if (kind === "embeddedObject") return isContentEmbeddedObject(value);
|
|
100
|
+
if (kind === "constructStart") return isContentConstructStart(value);
|
|
101
|
+
if (kind === "constructEnd") return true;
|
|
88
102
|
return false;
|
|
89
103
|
}
|
|
90
104
|
const ContentBlockSchema = z.custom(isContentBlock);
|
|
91
105
|
const ContentEmbeddedObjectSchema = z.custom(isContentEmbeddedObject);
|
|
92
106
|
const ContentEmbeddedObjectBlockSchema = z.custom(isContentEmbeddedObjectBlock);
|
|
107
|
+
function findConstructMarkerImbalance(blocks) {
|
|
108
|
+
const openStartIndices = [];
|
|
109
|
+
for (const [index, block] of blocks.entries()) if (isContentConstructStart(block)) openStartIndices.push(index);
|
|
110
|
+
else if (isContentConstructEnd(block) && openStartIndices.pop() === void 0) return {
|
|
111
|
+
kind: "unmatchedEnd",
|
|
112
|
+
index
|
|
113
|
+
};
|
|
114
|
+
const outermostUnclosed = openStartIndices[0];
|
|
115
|
+
if (outermostUnclosed !== void 0) return {
|
|
116
|
+
kind: "unclosedStart",
|
|
117
|
+
index: outermostUnclosed
|
|
118
|
+
};
|
|
119
|
+
}
|
|
93
120
|
const ContentStrokeStyleSchema = z.enum([
|
|
94
121
|
"solid",
|
|
95
122
|
"dashed",
|
|
@@ -392,4 +419,4 @@ const ContentDocumentSchema = z.discriminatedUnion("kind", [
|
|
|
392
419
|
})
|
|
393
420
|
]);
|
|
394
421
|
//#endregion
|
|
395
|
-
export { ContentBlockSchema, ContentBorderSchema, ContentCellBordersSchema, ContentCellValueSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectSchema, ContentFormulaSchema, ContentImageBlockSchema, ContentListMembershipSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellCommentSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetImageSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentStrokeStyleSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DecimalStringSchema, clampHeadingLevel, contentDocumentSharedFields, isContentBlock };
|
|
422
|
+
export { ContentBlockSchema, ContentBorderSchema, ContentCellBordersSchema, ContentCellValueSchema, ContentConstructEndSchema, ContentConstructStartSchema, ContentDocumentSchema, ContentDrawPageSchema, ContentEmbeddedObjectBlockSchema, ContentEmbeddedObjectSchema, ContentFormulaSchema, ContentImageBlockSchema, ContentListMembershipSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentPathPointSchema, ContentPathSegmentSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSheetCellCommentSchema, ContentSheetCellSchema, ContentSheetColumnSchema, ContentSheetImageSchema, ContentSheetPrintRangeSchema, ContentSheetPrintSettingsSchema, ContentSheetRepeatRangeSchema, ContentSheetRowSchema, ContentSheetSchema, ContentSlideSchema, ContentStrokeSchema, ContentStrokeStyleSchema, ContentSubpathSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, ContentVectorSchema, DecimalStringSchema, clampHeadingLevel, contentDocumentSharedFields, findConstructMarkerImbalance, isContentBlock, isContentConstructEnd, isContentConstructStart };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_content = require("./content.cjs");
|
|
3
|
+
//#region src/decompose.ts
|
|
4
|
+
function isHeadingParagraph(paragraph) {
|
|
5
|
+
return paragraph.headingLevel !== void 0;
|
|
6
|
+
}
|
|
7
|
+
function isListParagraph(paragraph) {
|
|
8
|
+
return paragraph.list !== void 0;
|
|
9
|
+
}
|
|
10
|
+
var ConstructMarkerImbalanceError = class extends Error {
|
|
11
|
+
imbalance;
|
|
12
|
+
constructor(imbalance) {
|
|
13
|
+
super(imbalance.kind === "unmatchedEnd" ? `decompose: the constructEnd marker at index ${imbalance.index} of this container's block flow closes no open construct` : `decompose: the constructStart marker at index ${imbalance.index} of this container's block flow is never closed`);
|
|
14
|
+
this.name = "ConstructMarkerImbalanceError";
|
|
15
|
+
this.imbalance = imbalance;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function decompose(content) {
|
|
19
|
+
switch (content.kind) {
|
|
20
|
+
case "wordprocessing": return content.sections.map(decomposeSection);
|
|
21
|
+
case "presentation": return content.slides.map(decomposeSlide);
|
|
22
|
+
case "spreadsheet": return content.sheets.map(decomposeSheet);
|
|
23
|
+
case "drawing": return content.pages.map(decomposeDrawPage);
|
|
24
|
+
case "formula": return [content.formula];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function decomposeSection(section) {
|
|
28
|
+
const { blocks, ...rest } = section;
|
|
29
|
+
return {
|
|
30
|
+
node: {
|
|
31
|
+
kind: "section",
|
|
32
|
+
...rest
|
|
33
|
+
},
|
|
34
|
+
children: decomposeSectionBlocks(blocks)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function assertBalancedConstructMarkers(blocks) {
|
|
38
|
+
const imbalance = require_content.findConstructMarkerImbalance(blocks);
|
|
39
|
+
if (imbalance !== void 0) throw new ConstructMarkerImbalanceError(imbalance);
|
|
40
|
+
}
|
|
41
|
+
function decomposeSectionBlocks(blocks) {
|
|
42
|
+
assertBalancedConstructMarkers(blocks);
|
|
43
|
+
return walkSectionBlocks(blocks.values());
|
|
44
|
+
}
|
|
45
|
+
function walkSectionBlocks(cursor) {
|
|
46
|
+
const root = [];
|
|
47
|
+
const headingStack = [];
|
|
48
|
+
const listStack = [];
|
|
49
|
+
const headingScope = () => headingStack.at(-1)?.children ?? root;
|
|
50
|
+
for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
|
|
51
|
+
const block = step.value;
|
|
52
|
+
if (block.kind === "constructEnd") return root;
|
|
53
|
+
if (block.kind === "constructStart") {
|
|
54
|
+
openConstructGroup(block.descriptor, cursor, listStack, headingScope());
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (block.kind !== "paragraph") {
|
|
58
|
+
const parent = listStack.at(-1);
|
|
59
|
+
(parent !== void 0 ? parent.children : headingScope()).push(block);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (isHeadingParagraph(block)) {
|
|
63
|
+
listStack.length = 0;
|
|
64
|
+
const level = block.headingLevel;
|
|
65
|
+
for (let top = headingStack.at(-1); top !== void 0 && top.node.headingLevel >= level; top = headingStack.at(-1)) headingStack.pop();
|
|
66
|
+
const group = {
|
|
67
|
+
node: block,
|
|
68
|
+
children: []
|
|
69
|
+
};
|
|
70
|
+
const parent = headingStack.at(-1);
|
|
71
|
+
(parent !== void 0 ? parent.children : root).push(group);
|
|
72
|
+
headingStack.push(group);
|
|
73
|
+
} else if (isListParagraph(block)) openListGroup(listStack, headingScope(), block);
|
|
74
|
+
else {
|
|
75
|
+
listStack.length = 0;
|
|
76
|
+
headingScope().push(block);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return root;
|
|
80
|
+
}
|
|
81
|
+
function decomposeSlide(slide) {
|
|
82
|
+
const { shapes, ...rest } = slide;
|
|
83
|
+
return {
|
|
84
|
+
node: {
|
|
85
|
+
kind: "slide",
|
|
86
|
+
...rest
|
|
87
|
+
},
|
|
88
|
+
children: shapes.map(decomposeShape)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function decomposeSheet(sheet) {
|
|
92
|
+
const { images, embeddedObjects, ...rest } = sheet;
|
|
93
|
+
const children = [...images, ...embeddedObjects ?? []];
|
|
94
|
+
return {
|
|
95
|
+
node: {
|
|
96
|
+
kind: "sheet",
|
|
97
|
+
...rest
|
|
98
|
+
},
|
|
99
|
+
children
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function decomposeDrawPage(page) {
|
|
103
|
+
const { shapes, vectors, ...rest } = page;
|
|
104
|
+
const children = [...shapes.map(decomposeShape), ...vectors];
|
|
105
|
+
return {
|
|
106
|
+
node: {
|
|
107
|
+
kind: "drawPage",
|
|
108
|
+
...rest
|
|
109
|
+
},
|
|
110
|
+
children
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function decomposeShape(shape) {
|
|
114
|
+
const { blocks, ...rest } = shape;
|
|
115
|
+
return {
|
|
116
|
+
node: rest,
|
|
117
|
+
children: decomposeShapeBlocks(blocks)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function decomposeShapeBlocks(blocks) {
|
|
121
|
+
assertBalancedConstructMarkers(blocks);
|
|
122
|
+
return walkShapeBlocks(blocks.values());
|
|
123
|
+
}
|
|
124
|
+
function walkShapeBlocks(cursor) {
|
|
125
|
+
const root = [];
|
|
126
|
+
const listStack = [];
|
|
127
|
+
for (let step = cursor.next(); step.done !== true; step = cursor.next()) {
|
|
128
|
+
const block = step.value;
|
|
129
|
+
if (block.kind === "constructEnd") return root;
|
|
130
|
+
if (block.kind === "constructStart") {
|
|
131
|
+
const parent = listStack.at(-1);
|
|
132
|
+
(parent !== void 0 ? parent.children : root).push({
|
|
133
|
+
node: block.descriptor,
|
|
134
|
+
children: walkShapeBlocks(cursor)
|
|
135
|
+
});
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (block.kind !== "paragraph") {
|
|
139
|
+
const parent = listStack.at(-1);
|
|
140
|
+
(parent !== void 0 ? parent.children : root).push(block);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (isListParagraph(block)) {
|
|
144
|
+
openListGroup(listStack, root, block);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
listStack.length = 0;
|
|
148
|
+
root.push(block);
|
|
149
|
+
}
|
|
150
|
+
return root;
|
|
151
|
+
}
|
|
152
|
+
function openConstructGroup(descriptor, cursor, listStack, headingScope) {
|
|
153
|
+
const parent = listStack.at(-1);
|
|
154
|
+
if (parent === void 0) {
|
|
155
|
+
headingScope.push({
|
|
156
|
+
node: descriptor,
|
|
157
|
+
children: walkSectionBlocks(cursor)
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
parent.children.push({
|
|
162
|
+
node: descriptor,
|
|
163
|
+
children: walkShapeBlocks(cursor)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function openListGroup(listStack, scopeChildren, paragraph) {
|
|
167
|
+
const level = paragraph.list.level;
|
|
168
|
+
for (let top = listStack.at(-1); top !== void 0 && top.node.list.level >= level; top = listStack.at(-1)) listStack.pop();
|
|
169
|
+
const group = {
|
|
170
|
+
node: paragraph,
|
|
171
|
+
children: []
|
|
172
|
+
};
|
|
173
|
+
const parent = listStack.at(-1);
|
|
174
|
+
(parent !== void 0 ? parent.children : scopeChildren).push(group);
|
|
175
|
+
listStack.push(group);
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
exports.ConstructMarkerImbalanceError = ConstructMarkerImbalanceError;
|
|
179
|
+
exports.decompose = decompose;
|
|
180
|
+
exports.decomposeDrawPage = decomposeDrawPage;
|
|
181
|
+
exports.decomposeSection = decomposeSection;
|
|
182
|
+
exports.decomposeShape = decomposeShape;
|
|
183
|
+
exports.decomposeSheet = decomposeSheet;
|
|
184
|
+
exports.decomposeSlide = decomposeSlide;
|
|
185
|
+
exports.isHeadingParagraph = isHeadingParagraph;
|
|
186
|
+
exports.isListParagraph = isListParagraph;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { C as ContentFormula, U as ContentSheet, V as ContentShape, g as ContentDrawPage, j as ContentParagraph, m as ContentDocument, st as ContentSlide, t as ConstructMarkerImbalance, z as ContentSection } from "./content-BmqzegMG.cjs";
|
|
2
|
+
import { B as SheetGroupNode, F as ShapeGroupNode, O as SectionGroupNode, W as SlideGroupNode, c as HeadingParagraph, i as DrawPageGroupNode, p as ListParagraph } from "./package-node-a9CyRaD3.cjs";
|
|
3
|
+
//#region src/decompose.d.ts
|
|
4
|
+
declare function isHeadingParagraph(paragraph: ContentParagraph): paragraph is HeadingParagraph;
|
|
5
|
+
declare function isListParagraph(paragraph: ContentParagraph): paragraph is ListParagraph;
|
|
6
|
+
declare class ConstructMarkerImbalanceError extends Error {
|
|
7
|
+
readonly imbalance: ConstructMarkerImbalance;
|
|
8
|
+
constructor(imbalance: ConstructMarkerImbalance);
|
|
9
|
+
}
|
|
10
|
+
type PackageChildren = SectionGroupNode[] | SlideGroupNode[] | SheetGroupNode[] | DrawPageGroupNode[] | ContentFormula[];
|
|
11
|
+
declare function decompose(content: ContentDocument): PackageChildren;
|
|
12
|
+
declare function decomposeSection(section: ContentSection): SectionGroupNode;
|
|
13
|
+
declare function decomposeSlide(slide: ContentSlide): SlideGroupNode;
|
|
14
|
+
declare function decomposeSheet(sheet: ContentSheet): SheetGroupNode;
|
|
15
|
+
declare function decomposeDrawPage(page: ContentDrawPage): DrawPageGroupNode;
|
|
16
|
+
declare function decomposeShape(shape: ContentShape): ShapeGroupNode;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConstructMarkerImbalanceError, PackageChildren, decompose, decomposeDrawPage, decomposeSection, decomposeShape, decomposeSheet, decomposeSlide, isHeadingParagraph, isListParagraph };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { C as ContentFormula, U as ContentSheet, V as ContentShape, g as ContentDrawPage, j as ContentParagraph, m as ContentDocument, st as ContentSlide, t as ConstructMarkerImbalance, z as ContentSection } from "./content-CIwPb_yh.js";
|
|
2
|
+
import { B as SheetGroupNode, F as ShapeGroupNode, O as SectionGroupNode, W as SlideGroupNode, c as HeadingParagraph, i as DrawPageGroupNode, p as ListParagraph } from "./package-node-C7RiYhyk.js";
|
|
3
|
+
//#region src/decompose.d.ts
|
|
4
|
+
declare function isHeadingParagraph(paragraph: ContentParagraph): paragraph is HeadingParagraph;
|
|
5
|
+
declare function isListParagraph(paragraph: ContentParagraph): paragraph is ListParagraph;
|
|
6
|
+
declare class ConstructMarkerImbalanceError extends Error {
|
|
7
|
+
readonly imbalance: ConstructMarkerImbalance;
|
|
8
|
+
constructor(imbalance: ConstructMarkerImbalance);
|
|
9
|
+
}
|
|
10
|
+
type PackageChildren = SectionGroupNode[] | SlideGroupNode[] | SheetGroupNode[] | DrawPageGroupNode[] | ContentFormula[];
|
|
11
|
+
declare function decompose(content: ContentDocument): PackageChildren;
|
|
12
|
+
declare function decomposeSection(section: ContentSection): SectionGroupNode;
|
|
13
|
+
declare function decomposeSlide(slide: ContentSlide): SlideGroupNode;
|
|
14
|
+
declare function decomposeSheet(sheet: ContentSheet): SheetGroupNode;
|
|
15
|
+
declare function decomposeDrawPage(page: ContentDrawPage): DrawPageGroupNode;
|
|
16
|
+
declare function decomposeShape(shape: ContentShape): ShapeGroupNode;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConstructMarkerImbalanceError, PackageChildren, decompose, decomposeDrawPage, decomposeSection, decomposeShape, decomposeSheet, decomposeSlide, isHeadingParagraph, isListParagraph };
|