@office-open/pptx 0.4.5 → 0.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @office-open/pptx
2
2
 
3
- > Generate .pptx files with JS/TS with a declarative API.
3
+ > Generate and parse .pptx files with JS/TS with a declarative API.
4
4
 
5
5
  ## Features
6
6
 
@@ -20,6 +20,7 @@
20
20
  - **Notes** — Speaker notes for each slide
21
21
  - **Group Shapes** — Group multiple shapes together
22
22
  - **DrawingML** — Shapes with fills, outlines, shadows, glow, reflection, and 3D effects
23
+ - **Parsing** — Read existing .pptx files with `readPresentation` for round-trip workflows
23
24
 
24
25
  ## Installation
25
26
 
@@ -38,26 +39,42 @@ import { Presentation, Shape, Packer, Paragraph, Run } from "@office-open/pptx";
38
39
  import { writeFileSync } from "node:fs";
39
40
 
40
41
  const pres = new Presentation({
41
- slides: [
42
- {
43
- children: [
44
- new Shape({
45
- text: "Hello World",
46
- fill: "4472C4",
47
- x: 100,
48
- y: 100,
49
- width: 600,
50
- height: 400,
51
- }),
52
- ],
53
- },
54
- ],
42
+ slides: [
43
+ {
44
+ children: [
45
+ new Shape({
46
+ text: "Hello World",
47
+ fill: "4472C4",
48
+ x: 100,
49
+ y: 100,
50
+ width: 600,
51
+ height: 400,
52
+ }),
53
+ ],
54
+ },
55
+ ],
55
56
  });
56
57
 
57
58
  const buffer = await Packer.toBuffer(pres);
58
59
  writeFileSync("presentation.pptx", buffer);
59
60
  ```
60
61
 
62
+ ## Parsing
63
+
64
+ Read existing `.pptx` files and re-create them as `ISlideOptions[]`:
65
+
66
+ ```typescript
67
+ import { readPresentation, Presentation, Packer } from "@office-open/pptx";
68
+ import { readFileSync, writeFileSync } from "node:fs";
69
+
70
+ const slides = readPresentation(new Uint8Array(readFileSync("input.pptx")));
71
+
72
+ // Modify parsed data, then re-generate
73
+ const pres = new Presentation({ slides });
74
+ const buffer = await Packer.toBuffer(pres);
75
+ writeFileSync("output.pptx", buffer);
76
+ ```
77
+
61
78
  ## Performance
62
79
 
63
80
  Performance vs [PptxGenJS](https://github.com/gitbrent/PptxGenJS) (higher hz is better, Windows 11 / Node 22):
@@ -66,27 +83,27 @@ Performance vs [PptxGenJS](https://github.com/gitbrent/PptxGenJS) (higher hz is
66
83
 
67
84
  | Scenario | @office-open/pptx | PptxGenJS | Speedup |
68
85
  | ------------------------- | ----------------: | ----------: | --------: |
69
- | Simple (2 shapes) | 4.39M ops/s | 518K ops/s | **8.5x** |
70
- | Styled shapes (20 shapes) | 237K ops/s | 72.1K ops/s | **3.3x** |
71
- | Table (10x5) | 1.97M ops/s | 24.6K ops/s | **79.8x** |
72
- | Full featured | 181K ops/s | 16.1K ops/s | **11.3x** |
86
+ | Simple (2 shapes) | 5.06M ops/s | 659K ops/s | **7.7x** |
87
+ | Styled shapes (20 shapes) | 244K ops/s | 82.9K ops/s | **2.9x** |
88
+ | Table (10x5) | 2.32M ops/s | 28.9K ops/s | **80.2x** |
89
+ | Full featured | 199K ops/s | 18.1K ops/s | **11.0x** |
73
90
 
74
91
  **Create + toBuffer (end-to-end)**
75
92
 
76
93
  | Scenario | @office-open/pptx | PptxGenJS (DEFLATE) | Speedup |
77
94
  | ------------------------- | ----------------: | ------------------: | -------: |
78
- | Simple (2 shapes) | 1,606 ops/s | 1,216 ops/s | **1.3x** |
79
- | Styled shapes (20 shapes) | 1,408 ops/s | 1,038 ops/s | **1.4x** |
80
- | Table (10x5) | 1,614 ops/s | 850 ops/s | **1.9x** |
81
- | Full featured | 1,192 ops/s | 727 ops/s | **1.6x** |
95
+ | Simple (2 shapes) | 1,705 ops/s | 1,456 ops/s | **1.2x** |
96
+ | Styled shapes (20 shapes) | 1,377 ops/s | 1,243 ops/s | **1.1x** |
97
+ | Table (10x5) | 1,644 ops/s | 983 ops/s | **1.7x** |
98
+ | Full featured | 1,138 ops/s | 806 ops/s | **1.4x** |
82
99
 
83
100
  **Large Files — Create + toBuffer**
84
101
 
85
102
  | Scenario | @office-open/pptx | PptxGenJS (DEFLATE) | Speedup |
86
103
  | --------------------- | ----------------: | ------------------: | -------: |
87
- | 10 slides × 10 shapes | 502 ops/s | 410 ops/s | **1.2x** |
88
- | 50×10 table | 460 ops/s | 208 ops/s | **2.2x** |
89
- | 20 slides full | 444 ops/s | 281 ops/s | **1.6x** |
104
+ | 10 slides × 10 shapes | 493 ops/s | 475 ops/s | **1.0x** |
105
+ | 50×10 table | 450 ops/s | 243 ops/s | **1.9x** |
106
+ | 20 slides full | 450 ops/s | 343 ops/s | **1.3x** |
90
107
 
91
108
  ## Examples
92
109
 
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(e,t)=>()=>(e&&(t=e(e=0)),t),a=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},o=(i,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=n(a),l=0,u=c.length,d;l<u;l++)d=c[l],!r.call(i,d)&&d!==o&&e(i,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=t(a,d))||s.enumerable});return i},s=(e,t,n)=>(o(e,t,`default`),n&&o(n,t,`default`)),c=t=>r.call(t,`module.exports`)?t[`module.exports`]:o(e({},`__esModule`,{value:!0}),t);export{c as i,a as n,s as r,i as t};