ppt-codec 1.5.0 → 1.6.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.
Files changed (58) hide show
  1. package/README.md +70 -58
  2. package/dist/base64.cjs +48 -0
  3. package/dist/base64.d.cts +5 -0
  4. package/dist/base64.d.ts +5 -0
  5. package/dist/base64.js +46 -0
  6. package/dist/diagnostics-CqxAnubw.d.cts +16 -0
  7. package/dist/diagnostics-CqxAnubw.d.ts +16 -0
  8. package/dist/diagnostics.cjs +11 -0
  9. package/dist/diagnostics.d.cts +2 -0
  10. package/dist/diagnostics.d.ts +2 -0
  11. package/dist/diagnostics.js +9 -0
  12. package/dist/document/color-scheme.cjs +4 -0
  13. package/dist/document/color-scheme.d.cts +2 -1
  14. package/dist/document/color-scheme.d.ts +2 -1
  15. package/dist/document/color-scheme.js +4 -1
  16. package/dist/document/master-write.cjs +20 -15
  17. package/dist/document/master-write.d.cts +2 -1
  18. package/dist/document/master-write.d.ts +2 -1
  19. package/dist/document/master-write.js +21 -16
  20. package/dist/document/notes-write.cjs +14 -6
  21. package/dist/document/notes-write.d.cts +2 -1
  22. package/dist/document/notes-write.d.ts +2 -1
  23. package/dist/document/notes-write.js +14 -6
  24. package/dist/document/notes.cjs +4 -3
  25. package/dist/document/notes.js +4 -3
  26. package/dist/drawing/blips.cjs +81 -0
  27. package/dist/drawing/blips.d.cts +16 -0
  28. package/dist/drawing/blips.d.ts +16 -0
  29. package/dist/drawing/blips.js +77 -0
  30. package/dist/drawing/properties.cjs +94 -0
  31. package/dist/drawing/properties.d.cts +25 -0
  32. package/dist/drawing/properties.d.ts +25 -0
  33. package/dist/drawing/properties.js +83 -0
  34. package/dist/drawing/shapes-write.cjs +204 -17
  35. package/dist/drawing/shapes-write.d.cts +15 -4
  36. package/dist/drawing/shapes-write.d.ts +15 -4
  37. package/dist/drawing/shapes-write.js +206 -18
  38. package/dist/drawing/shapes.cjs +34 -4
  39. package/dist/drawing/shapes.d.cts +11 -2
  40. package/dist/drawing/shapes.d.ts +11 -2
  41. package/dist/drawing/shapes.js +35 -5
  42. package/dist/index.cjs +38 -1
  43. package/dist/index.d.cts +10 -6
  44. package/dist/index.d.ts +10 -6
  45. package/dist/index.js +8 -4
  46. package/dist/read.cjs +101 -19
  47. package/dist/read.d.cts +3 -2
  48. package/dist/read.d.ts +3 -2
  49. package/dist/read.js +103 -22
  50. package/dist/record/types.cjs +28 -0
  51. package/dist/record/types.d.cts +15 -1
  52. package/dist/record/types.d.ts +15 -1
  53. package/dist/record/types.js +15 -1
  54. package/dist/write.cjs +100 -37
  55. package/dist/write.d.cts +9 -4
  56. package/dist/write.d.ts +9 -4
  57. package/dist/write.js +100 -37
  58. package/package.json +2 -1
@@ -2,7 +2,7 @@ import { OfficeArtClientData, RT_MainMaster, RT_PlaceholderAtom, RT_SlideAtom, R
2
2
  import "../text/atoms.js";
3
3
  import { concatBytes, i32le, u16le, u32le, u8, writeAtom, writeContainer } from "../record/write.js";
4
4
  import { writeSlideSchemeColorSchemeAtom } from "./color-scheme-write.js";
5
- import { writeDrawingWithClientData } from "../drawing/shapes-write.js";
5
+ import { writeSlideDrawing } from "../drawing/shapes-write.js";
6
6
  import { DEFAULT_INSET_LEFT_RIGHT_PT, DEFAULT_INSET_TOP_BOTTOM_PT } from "../read.js";
7
7
  //#region src/document/master-write.ts
8
8
  const SL_TITLE_BODY = 1;
@@ -85,7 +85,7 @@ function writeSlideAtomForSlide(notesIdRef) {
85
85
  function writeTextMasterStyleAtom(textType) {
86
86
  return writeAtom(RT_TextMasterStyleAtom, u16le(0), { recInstance: textType });
87
87
  }
88
- function writeMainMaster(size, fontIndexOf) {
88
+ function writeMainMaster(size, context) {
89
89
  const placeholders = MASTER_PLACEHOLDER_TYPES.map((placementId, index) => {
90
90
  const frame = placeholderFrames(size)[index];
91
91
  if (frame === void 0) throw new Error("internal error: the main master states more placeholder types than it has rectangles for");
@@ -101,20 +101,25 @@ function writeMainMaster(size, fontIndexOf) {
101
101
  clientData: placeholderClientData(index, placementId)
102
102
  };
103
103
  });
104
- return writeContainer(RT_MainMaster, [
105
- writeSlideAtom({
106
- geom: SL_TITLE_BODY,
107
- placeholderTypes: MASTER_PLACEHOLDER_TYPES,
108
- masterIdRef: 0,
109
- notesIdRef: 0,
110
- slideFlags: 0
111
- }),
112
- writeTextMasterStyleAtom(0),
113
- writeTextMasterStyleAtom(1),
114
- writeTextMasterStyleAtom(2),
115
- writeDrawingWithClientData(placeholders, fontIndexOf),
116
- writeSlideSchemeColorSchemeAtom()
117
- ]);
104
+ const drawing = writeSlideDrawing(placeholders, context);
105
+ return {
106
+ bytes: writeContainer(RT_MainMaster, [
107
+ writeSlideAtom({
108
+ geom: SL_TITLE_BODY,
109
+ placeholderTypes: MASTER_PLACEHOLDER_TYPES,
110
+ masterIdRef: 0,
111
+ notesIdRef: 0,
112
+ slideFlags: 0
113
+ }),
114
+ writeTextMasterStyleAtom(0),
115
+ writeTextMasterStyleAtom(1),
116
+ writeTextMasterStyleAtom(2),
117
+ drawing.bytes,
118
+ writeSlideSchemeColorSchemeAtom()
119
+ ]),
120
+ shapeCount: drawing.shapeCount,
121
+ maxSpid: drawing.maxSpid
122
+ };
118
123
  }
119
124
  function writeMasterListWithText(persistIdRef) {
120
125
  return writeContainer(RT_SlideListWithText, [writeAtom(RT_SlidePersistAtom, concatBytes(u32le(persistIdRef), u32le(0), i32le(0), u32le(MASTER_SLIDE_ID), u32le(0)))], { recInstance: 1 });
@@ -31,12 +31,20 @@ function notesBodyShape(notes, notesPageSize) {
31
31
  function writeNotesAtom(slideIdRef) {
32
32
  return require_record_write.writeAtom(require_record_types.RT_NotesAtom, require_record_write.concatBytes(require_record_write.u32le(slideIdRef), require_record_write.u16le(0), require_record_write.u16le(0)), { recVer: 1 });
33
33
  }
34
- function writeNotesContainer(slideIdRef, notes, notesPageSize, fontIndexOf) {
35
- return require_record_write.writeContainer(require_record_types.RT_Notes, [
36
- writeNotesAtom(slideIdRef),
37
- require_drawing_shapes_write.writeSlideDrawing([notesBodyShape(notes, notesPageSize)], fontIndexOf),
38
- require_document_color_scheme_write.writeSlideSchemeColorSchemeAtom()
39
- ]);
34
+ function writeNotesContainer(slideIdRef, notes, notesPageSize, context) {
35
+ const drawing = require_drawing_shapes_write.writeSlideDrawing([{
36
+ shape: notesBodyShape(notes, notesPageSize),
37
+ clientData: void 0
38
+ }], context);
39
+ return {
40
+ bytes: require_record_write.writeContainer(require_record_types.RT_Notes, [
41
+ writeNotesAtom(slideIdRef),
42
+ drawing.bytes,
43
+ require_document_color_scheme_write.writeSlideSchemeColorSchemeAtom()
44
+ ]),
45
+ shapeCount: drawing.shapeCount,
46
+ maxSpid: drawing.maxSpid
47
+ };
40
48
  }
41
49
  //#endregion
42
50
  exports.writeNotesAtom = writeNotesAtom;
@@ -1,6 +1,7 @@
1
+ import { DrawingWriteContext, DrawingWritten } from "../drawing/shapes-write.cjs";
1
2
  import { PageSize } from "document-schema.js";
2
3
  //#region src/document/notes-write.d.ts
3
4
  declare function writeNotesAtom(slideIdRef: number): Uint8Array<ArrayBuffer>;
4
- declare function writeNotesContainer(slideIdRef: number, notes: string, notesPageSize: PageSize, fontIndexOf: (family: string) => number): Uint8Array<ArrayBuffer>;
5
+ declare function writeNotesContainer(slideIdRef: number, notes: string, notesPageSize: PageSize, context: DrawingWriteContext): DrawingWritten;
5
6
  //#endregion
6
7
  export { writeNotesAtom, writeNotesContainer };
@@ -1,6 +1,7 @@
1
+ import { DrawingWriteContext, DrawingWritten } from "../drawing/shapes-write.js";
1
2
  import { PageSize } from "document-schema.js";
2
3
  //#region src/document/notes-write.d.ts
3
4
  declare function writeNotesAtom(slideIdRef: number): Uint8Array<ArrayBuffer>;
4
- declare function writeNotesContainer(slideIdRef: number, notes: string, notesPageSize: PageSize, fontIndexOf: (family: string) => number): Uint8Array<ArrayBuffer>;
5
+ declare function writeNotesContainer(slideIdRef: number, notes: string, notesPageSize: PageSize, context: DrawingWriteContext): DrawingWritten;
5
6
  //#endregion
6
7
  export { writeNotesAtom, writeNotesContainer };
@@ -30,12 +30,20 @@ function notesBodyShape(notes, notesPageSize) {
30
30
  function writeNotesAtom(slideIdRef) {
31
31
  return writeAtom(RT_NotesAtom, concatBytes(u32le(slideIdRef), u16le(0), u16le(0)), { recVer: 1 });
32
32
  }
33
- function writeNotesContainer(slideIdRef, notes, notesPageSize, fontIndexOf) {
34
- return writeContainer(RT_Notes, [
35
- writeNotesAtom(slideIdRef),
36
- writeSlideDrawing([notesBodyShape(notes, notesPageSize)], fontIndexOf),
37
- writeSlideSchemeColorSchemeAtom()
38
- ]);
33
+ function writeNotesContainer(slideIdRef, notes, notesPageSize, context) {
34
+ const drawing = writeSlideDrawing([{
35
+ shape: notesBodyShape(notes, notesPageSize),
36
+ clientData: void 0
37
+ }], context);
38
+ return {
39
+ bytes: writeContainer(RT_Notes, [
40
+ writeNotesAtom(slideIdRef),
41
+ drawing.bytes,
42
+ writeSlideSchemeColorSchemeAtom()
43
+ ]),
44
+ shapeCount: drawing.shapeCount,
45
+ maxSpid: drawing.maxSpid
46
+ };
39
47
  }
40
48
  //#endregion
41
49
  export { writeNotesAtom, writeNotesContainer };
@@ -26,9 +26,10 @@ function readNotesText(notesContainer) {
26
26
  const drawing = require_record_tree.findChild(require_record_tree.childRecords(notesContainer), require_record_types.RT_Drawing);
27
27
  if (drawing === void 0) return "";
28
28
  const bodies = [];
29
- for (const shape of require_drawing_shapes.readDrawingShapes(drawing)) {
30
- if (shape.clientTextbox === void 0) continue;
31
- const text = require_text_atoms.readTextBody(require_record_tree.childRecords(shape.clientTextbox));
29
+ for (const entry of require_drawing_shapes.readDrawingShapes(drawing)) {
30
+ if (!("clientTextbox" in entry)) continue;
31
+ if (entry.clientTextbox === void 0) continue;
32
+ const text = require_text_atoms.readTextBody(require_record_tree.childRecords(entry.clientTextbox));
32
33
  if (text === void 0 || text.length === 0) continue;
33
34
  bodies.push(require_text_atoms.splitParagraphs(text).map((paragraph) => paragraph.text).join("\n"));
34
35
  }
@@ -25,9 +25,10 @@ function readNotesText(notesContainer) {
25
25
  const drawing = findChild(childRecords(notesContainer), RT_Drawing);
26
26
  if (drawing === void 0) return "";
27
27
  const bodies = [];
28
- for (const shape of readDrawingShapes(drawing)) {
29
- if (shape.clientTextbox === void 0) continue;
30
- const text = readTextBody(childRecords(shape.clientTextbox));
28
+ for (const entry of readDrawingShapes(drawing)) {
29
+ if (!("clientTextbox" in entry)) continue;
30
+ if (entry.clientTextbox === void 0) continue;
31
+ const text = readTextBody(childRecords(entry.clientTextbox));
31
32
  if (text === void 0 || text.length === 0) continue;
32
33
  bodies.push(splitParagraphs(text).map((paragraph) => paragraph.text).join("\n"));
33
34
  }
@@ -0,0 +1,81 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors.cjs");
3
+ const require_record_tree = require("../record/tree.cjs");
4
+ const require_record_types = require("../record/types.cjs");
5
+ const require_record_write = require("../record/write.cjs");
6
+ //#region src/drawing/blips.ts
7
+ const MSOBLIP_JPEG = 5;
8
+ const MSOBLIP_PNG = 6;
9
+ function isBlipFormat(format) {
10
+ return format === "png" || format === "jpeg";
11
+ }
12
+ function blipPayload(record) {
13
+ const format = record.header.recType === 61470 ? "png" : record.header.recType === 61469 ? "jpeg" : void 0;
14
+ if (format === void 0) return;
15
+ const uidCount = (record.header.recInstance & 1) + 1;
16
+ const dataStart = uidCount * 16 + 1;
17
+ if (record.data.length < dataStart) throw new require_errors.PptFormatError(`a blip record of type 0x${record.header.recType.toString(16)} declares ${record.header.recInstance.toString(16)} as its instance (so ${uidCount} digest(s)) but carries only ${record.data.length} bytes`);
18
+ return {
19
+ format,
20
+ bytes: record.data.subarray(dataStart)
21
+ };
22
+ }
23
+ const FBSE_FIXED_SIZE = 36;
24
+ const FO_DELAY_NONE = 4294967295;
25
+ function readStoreEntry(entry, picturesStream) {
26
+ if (entry.header.recType !== 61447) return blipPayload(entry);
27
+ const view = new DataView(entry.data.buffer, entry.data.byteOffset, entry.data.byteLength);
28
+ const cRef = view.getUint32(24, true);
29
+ const foDelay = view.getUint32(28, true);
30
+ const cbName = view.getUint8(35);
31
+ const embeddedAt = entry.dataOffset + FBSE_FIXED_SIZE + cbName;
32
+ if (embeddedAt < entry.dataOffset + entry.header.recLen) return blipPayload(require_record_tree.readRecordAt(entry.stream, embeddedAt));
33
+ if (cRef === 0 || foDelay === FO_DELAY_NONE) return;
34
+ if (picturesStream === void 0) return;
35
+ return blipPayload(require_record_tree.readRecordAt(picturesStream, foDelay));
36
+ }
37
+ function readBlipStore(documentContainer, picturesStream) {
38
+ const drawingGroup = require_record_tree.findChild(require_record_tree.childRecords(documentContainer), require_record_types.RT_DrawingGroup);
39
+ if (drawingGroup === void 0) return [];
40
+ const dgg = require_record_tree.findChild(require_record_tree.childRecords(drawingGroup), require_record_types.OfficeArtDggContainer);
41
+ if (dgg === void 0) return [];
42
+ const bStore = require_record_tree.findChild(require_record_tree.childRecords(dgg), require_record_types.OfficeArtBStoreContainer);
43
+ if (bStore === void 0) return [];
44
+ const blips = [];
45
+ for (const entry of require_record_tree.childRecords(bStore)) {
46
+ const blip = readStoreEntry(entry, picturesStream);
47
+ if (blip !== void 0) blips.push(blip);
48
+ }
49
+ return blips;
50
+ }
51
+ function blipForPib(blips, pib) {
52
+ if (pib <= 0) return;
53
+ return blips[pib - 1];
54
+ }
55
+ const ZERO_DIGEST = /* @__PURE__ */ new Uint8Array(16);
56
+ const TAG_EXTERNAL = 255;
57
+ function writeBlipRecord(blip) {
58
+ const recType = blip.format === "png" ? require_record_types.OfficeArtBlipPNG : require_record_types.OfficeArtBlipJPEG;
59
+ const recInstance = blip.format === "png" ? 1760 : 1130;
60
+ return require_record_write.writeAtom(recType, require_record_write.concatBytes(ZERO_DIGEST, require_record_write.u8(TAG_EXTERNAL), blip.bytes), { recInstance });
61
+ }
62
+ function writeFbse(blip) {
63
+ const embedded = writeBlipRecord(blip);
64
+ const blipType = blip.format === "png" ? MSOBLIP_PNG : MSOBLIP_JPEG;
65
+ return require_record_write.writeAtom(require_record_types.OfficeArtFBSE, require_record_write.concatBytes(require_record_write.u8(blipType), require_record_write.u8(blipType), ZERO_DIGEST, require_record_write.u16le(TAG_EXTERNAL), require_record_write.u32le(embedded.length), require_record_write.u32le(1), require_record_write.u32le(0), require_record_write.u8(0), require_record_write.u8(0), require_record_write.u8(0), require_record_write.u8(0), embedded), {
66
+ recVer: 2,
67
+ recInstance: blipType
68
+ });
69
+ }
70
+ function writeDrawingGroupContainer(blips, counts) {
71
+ const fdgg = require_record_write.concatBytes(require_record_write.u32le(counts.spidMax), require_record_write.u32le(2), require_record_write.u32le(counts.shapeCount), require_record_write.u32le(counts.drawingCount));
72
+ const idcl = require_record_write.concatBytes(require_record_write.u32le(1), require_record_write.u32le(counts.spidMax));
73
+ const dggChildren = [require_record_write.writeAtom(require_record_types.OfficeArtFDGGBlock, require_record_write.concatBytes(fdgg, idcl))];
74
+ if (blips.length > 0) dggChildren.push(require_record_write.writeContainer(require_record_types.OfficeArtBStoreContainer, blips.map(writeFbse), { recInstance: blips.length }));
75
+ return require_record_write.writeContainer(require_record_types.RT_DrawingGroup, [require_record_write.writeContainer(require_record_types.OfficeArtDggContainer, dggChildren)]);
76
+ }
77
+ //#endregion
78
+ exports.blipForPib = blipForPib;
79
+ exports.isBlipFormat = isBlipFormat;
80
+ exports.readBlipStore = readBlipStore;
81
+ exports.writeDrawingGroupContainer = writeDrawingGroupContainer;
@@ -0,0 +1,16 @@
1
+ import { t as PptRecord } from "../tree-Du_LXAF0.cjs";
2
+ //#region src/drawing/blips.d.ts
3
+ interface PptBlip {
4
+ readonly format: "png" | "jpeg";
5
+ readonly bytes: Uint8Array<ArrayBuffer>;
6
+ }
7
+ declare function isBlipFormat(format: string): format is "png" | "jpeg";
8
+ declare function readBlipStore(documentContainer: PptRecord, picturesStream: Uint8Array<ArrayBuffer> | undefined): readonly PptBlip[];
9
+ declare function blipForPib(blips: readonly PptBlip[], pib: number): PptBlip | undefined;
10
+ declare function writeDrawingGroupContainer(blips: readonly PptBlip[], counts: {
11
+ readonly spidMax: number;
12
+ readonly shapeCount: number;
13
+ readonly drawingCount: number;
14
+ }): Uint8Array<ArrayBuffer>;
15
+ //#endregion
16
+ export { PptBlip, blipForPib, isBlipFormat, readBlipStore, writeDrawingGroupContainer };
@@ -0,0 +1,16 @@
1
+ import { t as PptRecord } from "../tree-PMcPNgd-.js";
2
+ //#region src/drawing/blips.d.ts
3
+ interface PptBlip {
4
+ readonly format: "png" | "jpeg";
5
+ readonly bytes: Uint8Array<ArrayBuffer>;
6
+ }
7
+ declare function isBlipFormat(format: string): format is "png" | "jpeg";
8
+ declare function readBlipStore(documentContainer: PptRecord, picturesStream: Uint8Array<ArrayBuffer> | undefined): readonly PptBlip[];
9
+ declare function blipForPib(blips: readonly PptBlip[], pib: number): PptBlip | undefined;
10
+ declare function writeDrawingGroupContainer(blips: readonly PptBlip[], counts: {
11
+ readonly spidMax: number;
12
+ readonly shapeCount: number;
13
+ readonly drawingCount: number;
14
+ }): Uint8Array<ArrayBuffer>;
15
+ //#endregion
16
+ export { PptBlip, blipForPib, isBlipFormat, readBlipStore, writeDrawingGroupContainer };
@@ -0,0 +1,77 @@
1
+ import { PptFormatError } from "../errors.js";
2
+ import { childRecords, findChild, readRecordAt } from "../record/tree.js";
3
+ import { OfficeArtBStoreContainer, OfficeArtBlipJPEG, OfficeArtBlipPNG, OfficeArtDggContainer, OfficeArtFBSE, OfficeArtFDGGBlock, RT_DrawingGroup } from "../record/types.js";
4
+ import { concatBytes, u16le, u32le, u8, writeAtom, writeContainer } from "../record/write.js";
5
+ //#region src/drawing/blips.ts
6
+ const MSOBLIP_JPEG = 5;
7
+ const MSOBLIP_PNG = 6;
8
+ function isBlipFormat(format) {
9
+ return format === "png" || format === "jpeg";
10
+ }
11
+ function blipPayload(record) {
12
+ const format = record.header.recType === 61470 ? "png" : record.header.recType === 61469 ? "jpeg" : void 0;
13
+ if (format === void 0) return;
14
+ const uidCount = (record.header.recInstance & 1) + 1;
15
+ const dataStart = uidCount * 16 + 1;
16
+ if (record.data.length < dataStart) throw new PptFormatError(`a blip record of type 0x${record.header.recType.toString(16)} declares ${record.header.recInstance.toString(16)} as its instance (so ${uidCount} digest(s)) but carries only ${record.data.length} bytes`);
17
+ return {
18
+ format,
19
+ bytes: record.data.subarray(dataStart)
20
+ };
21
+ }
22
+ const FBSE_FIXED_SIZE = 36;
23
+ const FO_DELAY_NONE = 4294967295;
24
+ function readStoreEntry(entry, picturesStream) {
25
+ if (entry.header.recType !== 61447) return blipPayload(entry);
26
+ const view = new DataView(entry.data.buffer, entry.data.byteOffset, entry.data.byteLength);
27
+ const cRef = view.getUint32(24, true);
28
+ const foDelay = view.getUint32(28, true);
29
+ const cbName = view.getUint8(35);
30
+ const embeddedAt = entry.dataOffset + FBSE_FIXED_SIZE + cbName;
31
+ if (embeddedAt < entry.dataOffset + entry.header.recLen) return blipPayload(readRecordAt(entry.stream, embeddedAt));
32
+ if (cRef === 0 || foDelay === FO_DELAY_NONE) return;
33
+ if (picturesStream === void 0) return;
34
+ return blipPayload(readRecordAt(picturesStream, foDelay));
35
+ }
36
+ function readBlipStore(documentContainer, picturesStream) {
37
+ const drawingGroup = findChild(childRecords(documentContainer), RT_DrawingGroup);
38
+ if (drawingGroup === void 0) return [];
39
+ const dgg = findChild(childRecords(drawingGroup), OfficeArtDggContainer);
40
+ if (dgg === void 0) return [];
41
+ const bStore = findChild(childRecords(dgg), OfficeArtBStoreContainer);
42
+ if (bStore === void 0) return [];
43
+ const blips = [];
44
+ for (const entry of childRecords(bStore)) {
45
+ const blip = readStoreEntry(entry, picturesStream);
46
+ if (blip !== void 0) blips.push(blip);
47
+ }
48
+ return blips;
49
+ }
50
+ function blipForPib(blips, pib) {
51
+ if (pib <= 0) return;
52
+ return blips[pib - 1];
53
+ }
54
+ const ZERO_DIGEST = /* @__PURE__ */ new Uint8Array(16);
55
+ const TAG_EXTERNAL = 255;
56
+ function writeBlipRecord(blip) {
57
+ const recType = blip.format === "png" ? OfficeArtBlipPNG : OfficeArtBlipJPEG;
58
+ const recInstance = blip.format === "png" ? 1760 : 1130;
59
+ return writeAtom(recType, concatBytes(ZERO_DIGEST, u8(TAG_EXTERNAL), blip.bytes), { recInstance });
60
+ }
61
+ function writeFbse(blip) {
62
+ const embedded = writeBlipRecord(blip);
63
+ const blipType = blip.format === "png" ? MSOBLIP_PNG : MSOBLIP_JPEG;
64
+ return writeAtom(OfficeArtFBSE, concatBytes(u8(blipType), u8(blipType), ZERO_DIGEST, u16le(TAG_EXTERNAL), u32le(embedded.length), u32le(1), u32le(0), u8(0), u8(0), u8(0), u8(0), embedded), {
65
+ recVer: 2,
66
+ recInstance: blipType
67
+ });
68
+ }
69
+ function writeDrawingGroupContainer(blips, counts) {
70
+ const fdgg = concatBytes(u32le(counts.spidMax), u32le(2), u32le(counts.shapeCount), u32le(counts.drawingCount));
71
+ const idcl = concatBytes(u32le(1), u32le(counts.spidMax));
72
+ const dggChildren = [writeAtom(OfficeArtFDGGBlock, concatBytes(fdgg, idcl))];
73
+ if (blips.length > 0) dggChildren.push(writeContainer(OfficeArtBStoreContainer, blips.map(writeFbse), { recInstance: blips.length }));
74
+ return writeContainer(RT_DrawingGroup, [writeContainer(OfficeArtDggContainer, dggChildren)]);
75
+ }
76
+ //#endregion
77
+ export { blipForPib, isBlipFormat, readBlipStore, writeDrawingGroupContainer };
@@ -0,0 +1,94 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors.cjs");
3
+ const require_record_tree = require("../record/tree.cjs");
4
+ require("../record/types.cjs");
5
+ const require_record_write = require("../record/write.cjs");
6
+ //#region src/drawing/properties.ts
7
+ const OPID_MASK = 16383;
8
+ const OPID_FCOMPLEX = 16384;
9
+ const OPID_FBID = 32768;
10
+ const PROPERTY_ROTATION = 4;
11
+ const PROPERTY_PIB = 260;
12
+ const PROPERTY_TABLE_PROPERTIES = 927;
13
+ const PROPERTY_TABLE_ROW_PROPERTIES = 928;
14
+ const FIXED_POINT_ONE = 65536;
15
+ function degreesToFixedPoint(degrees) {
16
+ return Math.round(degrees * FIXED_POINT_ONE);
17
+ }
18
+ function fixedPointToDegrees(raw) {
19
+ return raw / FIXED_POINT_ONE;
20
+ }
21
+ const TABLE_FLAG_IS_TABLE = 1;
22
+ function readIMsoArray(complex) {
23
+ if (complex.length < 6) throw new require_errors.PptFormatError(`a complex property's IMsoArray carries ${complex.length} bytes, fewer than the 6 its three count fields need`);
24
+ const view = new DataView(complex.buffer, complex.byteOffset, complex.byteLength);
25
+ const elementCount = view.getUint16(0, true);
26
+ const elementSize = view.getUint16(4, true);
27
+ const data = complex.subarray(6);
28
+ if (data.length < elementCount * elementSize) throw new require_errors.PptFormatError(`a complex property's IMsoArray declares ${elementCount} elements of ${elementSize} bytes but only ${data.length} remain`);
29
+ const elements = [];
30
+ for (let index = 0; index < elementCount; index += 1) elements.push(view.getInt32(6 + index * elementSize, true));
31
+ return elements;
32
+ }
33
+ function writeIMsoArray(elements, elementSize) {
34
+ const data = new Uint8Array(elements.length * elementSize);
35
+ const view = new DataView(data.buffer);
36
+ elements.forEach((element, index) => {
37
+ view.setInt32(index * elementSize, element, true);
38
+ });
39
+ return require_record_write.concatBytes(require_record_write.u16le(elements.length), require_record_write.u16le(elements.length), require_record_write.u16le(elementSize), data);
40
+ }
41
+ function readShapeProperties(shape) {
42
+ const properties = /* @__PURE__ */ new Map();
43
+ for (const record of require_record_tree.childRecords(shape)) {
44
+ if (record.header.recType !== 61451 && record.header.recType !== 61729 && record.header.recType !== 61730) continue;
45
+ const count = record.header.recInstance;
46
+ const needed = count * 6;
47
+ if (record.data.length < needed) throw new require_errors.PptFormatError(`a shape property table declares ${count} properties but its ${record.data.length} bytes of data cannot hold the ${needed} its entries need`);
48
+ const view = new DataView(record.data.buffer, record.data.byteOffset, record.data.byteLength);
49
+ let complexAt = needed;
50
+ for (let index = 0; index < count; index += 1) {
51
+ const at = index * 6;
52
+ const opid = view.getUint16(at, true);
53
+ const value = view.getInt32(at + 2, true);
54
+ const isComplex = (opid & OPID_FCOMPLEX) !== 0;
55
+ let complex;
56
+ if (isComplex) {
57
+ complex = record.data.subarray(complexAt, complexAt + value);
58
+ complexAt += value;
59
+ if (complexAt > record.data.length) throw new require_errors.PptFormatError(`a shape property table's complex data declares ${complexAt} bytes in total but the table carries only ${record.data.length}`);
60
+ }
61
+ properties.set(opid & OPID_MASK, {
62
+ value,
63
+ complex
64
+ });
65
+ }
66
+ }
67
+ return properties;
68
+ }
69
+ function writeShapePropertyTable(recType, entries) {
70
+ const ordered = [...entries].sort((a, b) => a.opid - b.opid);
71
+ const complexParts = [];
72
+ const entryParts = ordered.map((entry) => {
73
+ const isComplex = entry.complex !== void 0;
74
+ const opidWord = entry.opid | (isComplex ? OPID_FCOMPLEX : 0) | (entry.fBid === true ? OPID_FBID : 0);
75
+ if (isComplex) complexParts.push(entry.complex);
76
+ return require_record_write.concatBytes(require_record_write.u16le(opidWord), require_record_write.u32le(entry.op));
77
+ });
78
+ return require_record_write.writeAtom(recType, require_record_write.concatBytes(...entryParts, ...complexParts), {
79
+ recVer: 3,
80
+ recInstance: ordered.length
81
+ });
82
+ }
83
+ //#endregion
84
+ exports.PROPERTY_PIB = PROPERTY_PIB;
85
+ exports.PROPERTY_ROTATION = PROPERTY_ROTATION;
86
+ exports.PROPERTY_TABLE_PROPERTIES = PROPERTY_TABLE_PROPERTIES;
87
+ exports.PROPERTY_TABLE_ROW_PROPERTIES = PROPERTY_TABLE_ROW_PROPERTIES;
88
+ exports.TABLE_FLAG_IS_TABLE = TABLE_FLAG_IS_TABLE;
89
+ exports.degreesToFixedPoint = degreesToFixedPoint;
90
+ exports.fixedPointToDegrees = fixedPointToDegrees;
91
+ exports.readIMsoArray = readIMsoArray;
92
+ exports.readShapeProperties = readShapeProperties;
93
+ exports.writeIMsoArray = writeIMsoArray;
94
+ exports.writeShapePropertyTable = writeShapePropertyTable;
@@ -0,0 +1,25 @@
1
+ import { t as PptRecord } from "../tree-Du_LXAF0.cjs";
2
+ //#region src/drawing/properties.d.ts
3
+ declare const PROPERTY_ROTATION = 4;
4
+ declare const PROPERTY_PIB = 260;
5
+ declare const PROPERTY_TABLE_PROPERTIES = 927;
6
+ declare const PROPERTY_TABLE_ROW_PROPERTIES = 928;
7
+ declare function degreesToFixedPoint(degrees: number): number;
8
+ declare function fixedPointToDegrees(raw: number): number;
9
+ declare const TABLE_FLAG_IS_TABLE: number;
10
+ declare function readIMsoArray(complex: Uint8Array<ArrayBuffer>): readonly number[];
11
+ declare function writeIMsoArray(elements: readonly number[], elementSize: number): Uint8Array<ArrayBuffer>;
12
+ interface ShapeProperty {
13
+ readonly value: number;
14
+ readonly complex: Uint8Array<ArrayBuffer> | undefined;
15
+ }
16
+ declare function readShapeProperties(shape: PptRecord): Map<number, ShapeProperty>;
17
+ interface WritableShapeProperty {
18
+ readonly opid: number;
19
+ readonly op: number;
20
+ readonly fBid?: boolean;
21
+ readonly complex?: Uint8Array<ArrayBuffer>;
22
+ }
23
+ declare function writeShapePropertyTable(recType: number, entries: readonly WritableShapeProperty[]): Uint8Array<ArrayBuffer>;
24
+ //#endregion
25
+ export { PROPERTY_PIB, PROPERTY_ROTATION, PROPERTY_TABLE_PROPERTIES, PROPERTY_TABLE_ROW_PROPERTIES, ShapeProperty, TABLE_FLAG_IS_TABLE, WritableShapeProperty, degreesToFixedPoint, fixedPointToDegrees, readIMsoArray, readShapeProperties, writeIMsoArray, writeShapePropertyTable };
@@ -0,0 +1,25 @@
1
+ import { t as PptRecord } from "../tree-PMcPNgd-.js";
2
+ //#region src/drawing/properties.d.ts
3
+ declare const PROPERTY_ROTATION = 4;
4
+ declare const PROPERTY_PIB = 260;
5
+ declare const PROPERTY_TABLE_PROPERTIES = 927;
6
+ declare const PROPERTY_TABLE_ROW_PROPERTIES = 928;
7
+ declare function degreesToFixedPoint(degrees: number): number;
8
+ declare function fixedPointToDegrees(raw: number): number;
9
+ declare const TABLE_FLAG_IS_TABLE: number;
10
+ declare function readIMsoArray(complex: Uint8Array<ArrayBuffer>): readonly number[];
11
+ declare function writeIMsoArray(elements: readonly number[], elementSize: number): Uint8Array<ArrayBuffer>;
12
+ interface ShapeProperty {
13
+ readonly value: number;
14
+ readonly complex: Uint8Array<ArrayBuffer> | undefined;
15
+ }
16
+ declare function readShapeProperties(shape: PptRecord): Map<number, ShapeProperty>;
17
+ interface WritableShapeProperty {
18
+ readonly opid: number;
19
+ readonly op: number;
20
+ readonly fBid?: boolean;
21
+ readonly complex?: Uint8Array<ArrayBuffer>;
22
+ }
23
+ declare function writeShapePropertyTable(recType: number, entries: readonly WritableShapeProperty[]): Uint8Array<ArrayBuffer>;
24
+ //#endregion
25
+ export { PROPERTY_PIB, PROPERTY_ROTATION, PROPERTY_TABLE_PROPERTIES, PROPERTY_TABLE_ROW_PROPERTIES, ShapeProperty, TABLE_FLAG_IS_TABLE, WritableShapeProperty, degreesToFixedPoint, fixedPointToDegrees, readIMsoArray, readShapeProperties, writeIMsoArray, writeShapePropertyTable };
@@ -0,0 +1,83 @@
1
+ import { PptFormatError } from "../errors.js";
2
+ import { childRecords } from "../record/tree.js";
3
+ import "../record/types.js";
4
+ import { concatBytes, u16le, u32le, writeAtom } from "../record/write.js";
5
+ //#region src/drawing/properties.ts
6
+ const OPID_MASK = 16383;
7
+ const OPID_FCOMPLEX = 16384;
8
+ const OPID_FBID = 32768;
9
+ const PROPERTY_ROTATION = 4;
10
+ const PROPERTY_PIB = 260;
11
+ const PROPERTY_TABLE_PROPERTIES = 927;
12
+ const PROPERTY_TABLE_ROW_PROPERTIES = 928;
13
+ const FIXED_POINT_ONE = 65536;
14
+ function degreesToFixedPoint(degrees) {
15
+ return Math.round(degrees * FIXED_POINT_ONE);
16
+ }
17
+ function fixedPointToDegrees(raw) {
18
+ return raw / FIXED_POINT_ONE;
19
+ }
20
+ const TABLE_FLAG_IS_TABLE = 1;
21
+ function readIMsoArray(complex) {
22
+ if (complex.length < 6) throw new PptFormatError(`a complex property's IMsoArray carries ${complex.length} bytes, fewer than the 6 its three count fields need`);
23
+ const view = new DataView(complex.buffer, complex.byteOffset, complex.byteLength);
24
+ const elementCount = view.getUint16(0, true);
25
+ const elementSize = view.getUint16(4, true);
26
+ const data = complex.subarray(6);
27
+ if (data.length < elementCount * elementSize) throw new PptFormatError(`a complex property's IMsoArray declares ${elementCount} elements of ${elementSize} bytes but only ${data.length} remain`);
28
+ const elements = [];
29
+ for (let index = 0; index < elementCount; index += 1) elements.push(view.getInt32(6 + index * elementSize, true));
30
+ return elements;
31
+ }
32
+ function writeIMsoArray(elements, elementSize) {
33
+ const data = new Uint8Array(elements.length * elementSize);
34
+ const view = new DataView(data.buffer);
35
+ elements.forEach((element, index) => {
36
+ view.setInt32(index * elementSize, element, true);
37
+ });
38
+ return concatBytes(u16le(elements.length), u16le(elements.length), u16le(elementSize), data);
39
+ }
40
+ function readShapeProperties(shape) {
41
+ const properties = /* @__PURE__ */ new Map();
42
+ for (const record of childRecords(shape)) {
43
+ if (record.header.recType !== 61451 && record.header.recType !== 61729 && record.header.recType !== 61730) continue;
44
+ const count = record.header.recInstance;
45
+ const needed = count * 6;
46
+ if (record.data.length < needed) throw new PptFormatError(`a shape property table declares ${count} properties but its ${record.data.length} bytes of data cannot hold the ${needed} its entries need`);
47
+ const view = new DataView(record.data.buffer, record.data.byteOffset, record.data.byteLength);
48
+ let complexAt = needed;
49
+ for (let index = 0; index < count; index += 1) {
50
+ const at = index * 6;
51
+ const opid = view.getUint16(at, true);
52
+ const value = view.getInt32(at + 2, true);
53
+ const isComplex = (opid & OPID_FCOMPLEX) !== 0;
54
+ let complex;
55
+ if (isComplex) {
56
+ complex = record.data.subarray(complexAt, complexAt + value);
57
+ complexAt += value;
58
+ if (complexAt > record.data.length) throw new PptFormatError(`a shape property table's complex data declares ${complexAt} bytes in total but the table carries only ${record.data.length}`);
59
+ }
60
+ properties.set(opid & OPID_MASK, {
61
+ value,
62
+ complex
63
+ });
64
+ }
65
+ }
66
+ return properties;
67
+ }
68
+ function writeShapePropertyTable(recType, entries) {
69
+ const ordered = [...entries].sort((a, b) => a.opid - b.opid);
70
+ const complexParts = [];
71
+ const entryParts = ordered.map((entry) => {
72
+ const isComplex = entry.complex !== void 0;
73
+ const opidWord = entry.opid | (isComplex ? OPID_FCOMPLEX : 0) | (entry.fBid === true ? OPID_FBID : 0);
74
+ if (isComplex) complexParts.push(entry.complex);
75
+ return concatBytes(u16le(opidWord), u32le(entry.op));
76
+ });
77
+ return writeAtom(recType, concatBytes(...entryParts, ...complexParts), {
78
+ recVer: 3,
79
+ recInstance: ordered.length
80
+ });
81
+ }
82
+ //#endregion
83
+ export { PROPERTY_PIB, PROPERTY_ROTATION, PROPERTY_TABLE_PROPERTIES, PROPERTY_TABLE_ROW_PROPERTIES, TABLE_FLAG_IS_TABLE, degreesToFixedPoint, fixedPointToDegrees, readIMsoArray, readShapeProperties, writeIMsoArray, writeShapePropertyTable };