@office-kit/pptx-dev 0.2.1 → 0.2.3

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
@@ -16,7 +16,7 @@ npm install
16
16
  npm run dev
17
17
  ```
18
18
 
19
- Open the local URL printed by the server. Save `deck.tsx` to rebuild. The viewer
19
+ Open the local URL printed by the server. Save a slide file, `theme.ts` or `deck.tsx` to rebuild. The viewer
20
20
  has a vertical thumbnail strip and a large slide canvas. Click a thumbnail or use
21
21
  arrow keys, Page Up/Down, Home/End to navigate. Fit/zoom and Present (Escape to
22
22
  exit) are viewing controls; the canvas has no editing, dragging or resize handles.
@@ -45,6 +45,27 @@ presentation** task, then use **Simple Browser: Show** with the printed URL and
45
45
  move it to a side editor group. No custom editor extension is needed for this
46
46
  workflow. Preview-to-source selection is not implemented.
47
47
 
48
+ ## Edit only what changed
49
+
50
+ New projects separate slide order, content and shared styling:
51
+
52
+ ```text
53
+ deck.tsx # Slide imports and order
54
+ slides/cover.tsx # One slide per descriptively named file
55
+ theme.ts # Shared design values
56
+ ```
57
+
58
+ For example, a headline revision changes only the text in the corresponding
59
+ slide file. A deck-wide palette change belongs in `theme.ts`; a one-slide color
60
+ exception belongs in that slide's props. Imported files are watched, so keep the
61
+ preview running while editing. Existing single-file decks remain supported and
62
+ do not need migration for a small revision.
63
+
64
+ Use focused code patches for revisions. Review affected slides while iterating;
65
+ check types, export and review the whole deck before delivery. The build still
66
+ evaluates the whole presentation; file splitting reduces authoring scope, not
67
+ the amount of PPTX evaluation.
68
+
48
69
  ## Commands
49
70
 
50
71
  - `office-pptx init <new-directory>` creates a TSX project without overwriting an existing directory.
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as createDeckBuilder, i as initProject, n as exportDeck, r as inspectTemplate } from "./src-U5ZNAbtV.mjs";
2
+ import { a as createDeckBuilder, i as initProject, n as exportDeck, r as inspectTemplate } from "./src-31HzWTvZ.mjs";
3
3
  import { dirname, resolve, sep } from "node:path";
4
4
  import { watch } from "node:fs";
5
5
  import { createServer } from "node:http";
package/dist/index.d.mts CHANGED
@@ -16,25 +16,8 @@ declare function initProject(directory: string): Promise<string>;
16
16
  //#region src/inspect.d.ts
17
17
  /** Source references usable directly in Slide, Fill and Remove props. */
18
18
  declare function inspectTemplate(file: string): Promise<{
19
- slides: {
20
- index: number;
21
- part: string;
22
- title: string | null;
23
- shapes: {
24
- id: number;
25
- name: string;
26
- kind: "shape" | "picture" | "group" | "graphicFrame" | "connector";
27
- placeholder: {
28
- type: string | null;
29
- idx: number | null;
30
- };
31
- }[];
32
- }[];
33
- layouts: {
34
- part: string;
35
- name: string;
36
- type: string | null;
37
- }[];
19
+ slides: any;
20
+ layouts: any;
38
21
  }>;
39
22
  //#endregion
40
23
  //#region src/index.d.ts
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { i as initProject, n as exportDeck, r as inspectTemplate, t as buildDeck } from "./src-U5ZNAbtV.mjs";
1
+ import { i as initProject, n as exportDeck, r as inspectTemplate, t as buildDeck } from "./src-31HzWTvZ.mjs";
2
2
  export { buildDeck, exportDeck, initProject, inspectTemplate };
@@ -71,25 +71,43 @@ function createDeckBuilder(entry, keepWarm = true) {
71
71
  }
72
72
  //#endregion
73
73
  //#region src/init.ts
74
- const starter = `import { Presentation, Slide, Text, Shape } from '@office-kit/pptx-dsl';
74
+ const starter = `import { Presentation } from '@office-kit/pptx-dsl';
75
+ import { Cover } from './slides/cover.tsx';
75
76
 
76
77
  export default (
77
78
  <Presentation>
78
- <Slide background="#15171C">
79
- <Shape preset="rect" x={0.9} y={2.55} width={0.14} height={1.75} fill="#E5481F" stroke={false} />
80
- <Text x={1.25} y={2.4} width={10} height={1.1} size={48} bold color="#FFFFFF">
79
+ <Cover />
80
+ </Presentation>
81
+ );
82
+ `;
83
+ const theme = `export const theme = {
84
+ background: '#15171C',
85
+ accent: '#E5481F',
86
+ text: '#FFFFFF',
87
+ muted: '#B4B9C4',
88
+ } as const;
89
+ `;
90
+ const cover = `import { Slide, Text, Shape } from '@office-kit/pptx-dsl';
91
+ import { theme } from '../theme.ts';
92
+
93
+ export function Cover() {
94
+ return (
95
+ <Slide background={theme.background}>
96
+ <Shape preset="rect" x={0.9} y={2.55} width={0.14} height={1.75} fill={theme.accent} stroke={false} />
97
+ <Text x={1.25} y={2.4} width={10} height={1.1} size={48} bold color={theme.text}>
81
98
  Your next presentation
82
99
  </Text>
83
- <Text x={1.25} y={3.55} width={10} height={0.6} size={22} color="#B4B9C4">
100
+ <Text x={1.25} y={3.55} width={10} height={0.6} size={22} color={theme.muted}>
84
101
  Edit this TSX and save to update the preview.
85
102
  </Text>
86
103
  </Slide>
87
- </Presentation>
88
- );
104
+ );
105
+ }
89
106
  `;
90
107
  const guide = `# Writing this presentation
91
108
 
92
- Edit deck.tsx and local TypeScript components. The JSX runtime is
109
+ Use deck.tsx for slide order, slides/*.tsx for individual slides, and theme.ts
110
+ for shared design values. The JSX runtime is
93
111
  @office-kit/pptx-dsl, with no React or Vue dependency.
94
112
 
95
113
  - Run npm run dev, then open its local URL to preview. Saving source files
@@ -97,8 +115,16 @@ Edit deck.tsx and local TypeScript components. The JSX runtime is
97
115
  - The preview is view-only: use the vertical thumbnails to select slides, zoom
98
116
  to inspect details, and Present to view full-screen (Escape exits). Make all
99
117
  content and layout changes in TSX; there are no canvas editing controls.
100
- - Run npm run check for TypeScript diagnostics; run npm run build to export
101
- deck.pptx. Inspect every slide in the preview after changes.
118
+ - For a local revision, locate the slide through deck.tsx or a text search and
119
+ read only the relevant source and dependencies. Patch the requested text, data
120
+ or props; do not regenerate the deck or reformat unrelated code. Keep descriptive
121
+ filenames stable when reordering slides. Preserve existing project structures.
122
+ - Change shared theme values/components only for changes intended for all their
123
+ consumers; use a local prop override for a one-slide exception.
124
+ - Keep the preview running during revisions and inspect affected slides after
125
+ saving. Review all affected consumers for shared changes. Do not run a separate
126
+ export for every intermediate edit. Before delivery, run npm run check and
127
+ npm run build to export deck.pptx, then review the whole deck.
102
128
  - Coordinates and dimensions are inches; font sizes and stroke widths are points.
103
129
  The default 16:9 canvas is 13.333 × 7.5 inches.
104
130
  - Use native Text, Shape, Image, Table and Chart elements. Use JS functions,
@@ -171,6 +197,8 @@ async function initProject(directory) {
171
197
  exclude: ["node_modules"]
172
198
  }, null, 2) + "\n",
173
199
  "deck.tsx": starter,
200
+ "theme.ts": theme,
201
+ "slides/cover.tsx": cover,
174
202
  "CLAUDE.md": guide,
175
203
  ".gitignore": "node_modules/\ndeck.pptx\n",
176
204
  ".vscode/tasks.json": JSON.stringify({
@@ -209,7 +237,7 @@ async function initProject(directory) {
209
237
  ]
210
238
  }, null, 2) + "\n"
211
239
  };
212
- await mkdir(join(root, ".vscode"));
240
+ await Promise.all([".vscode", "slides"].map((directory) => mkdir(join(root, directory))));
213
241
  await Promise.all(Object.entries(files).map(([name, content]) => writeFile(join(root, name), content, { flag: "wx" })));
214
242
  return root;
215
243
  }
@@ -259,4 +287,4 @@ async function exportDeck(entry, output) {
259
287
  //#endregion
260
288
  export { createDeckBuilder as a, initProject as i, exportDeck as n, inspectTemplate as r, buildDeck as t };
261
289
 
262
- //# sourceMappingURL=src-U5ZNAbtV.mjs.map
290
+ //# sourceMappingURL=src-31HzWTvZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-31HzWTvZ.mjs","names":[],"sources":["../src/build-runner.ts","../src/init.ts","../src/inspect.ts","../src/index.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport { resolve, join } from 'node:path';\nimport { mkdtempSync } from 'node:fs';\nimport { rm } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport type { BuildResult } from './build.ts';\n\nconst BUILD_TIMEOUT_MS = 60_000;\n\nfunction prepareWorker(entry: string) {\n const directory = mkdtempSync(join(tmpdir(), 'office-pptx-'));\n const worker = new Worker(new URL('./worker.mjs', import.meta.url), {\n workerData: { entry: resolve(entry), directory },\n execArgv: ['--enable-source-maps'],\n });\n const result = new Promise<BuildResult>((resolveBuild, reject) => {\n worker.once('message', resolveBuild);\n worker.once('error', reject);\n worker.once('exit', (code) =>\n reject(new Error(`Build worker exited without a result (code ${code}).`)),\n );\n });\n // Startup may fail before the next edit asks to use this worker.\n void result.catch(() => {});\n return { worker, result, directory };\n}\n\n/** Internal watch session. Preload libraries, but never reuse a user module cache. */\nexport function createDeckBuilder(entry: string, keepWarm = true) {\n let prepared: ReturnType<typeof prepareWorker> | undefined = prepareWorker(entry);\n let closed = false;\n let active = false;\n return {\n async build(): Promise<BuildResult> {\n if (closed || active) throw new Error('Deck builder is closed or already building.');\n active = true;\n const current = prepared ?? prepareWorker(entry);\n prepared = current;\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n current.worker.postMessage('build');\n return await Promise.race([\n current.result,\n new Promise<never>((_, reject) => {\n timer = setTimeout(\n () =>\n reject(\n new Error(\n 'Build exceeded 60 seconds. Check the deck for loops or unresolved promises.',\n ),\n ),\n BUILD_TIMEOUT_MS,\n );\n }),\n ]);\n } finally {\n clearTimeout(timer);\n await current.worker.terminate();\n await rm(current.directory, { recursive: true, force: true });\n active = false;\n prepared = !closed && keepWarm ? prepareWorker(entry) : undefined;\n }\n },\n async cancel() {\n if (active) await prepared?.worker.terminate();\n },\n async close() {\n closed = true;\n const current = prepared;\n await current?.worker.terminate();\n if (current) await rm(current.directory, { recursive: true, force: true });\n },\n };\n}\n","import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\n\nconst starter = `import { Presentation } from '@office-kit/pptx-dsl';\nimport { Cover } from './slides/cover.tsx';\n\nexport default (\n <Presentation>\n <Cover />\n </Presentation>\n);\n`;\n\nconst theme = `export const theme = {\n background: '#15171C',\n accent: '#E5481F',\n text: '#FFFFFF',\n muted: '#B4B9C4',\n} as const;\n`;\n\nconst cover = `import { Slide, Text, Shape } from '@office-kit/pptx-dsl';\nimport { theme } from '../theme.ts';\n\nexport function Cover() {\n return (\n <Slide background={theme.background}>\n <Shape preset=\"rect\" x={0.9} y={2.55} width={0.14} height={1.75} fill={theme.accent} stroke={false} />\n <Text x={1.25} y={2.4} width={10} height={1.1} size={48} bold color={theme.text}>\n Your next presentation\n </Text>\n <Text x={1.25} y={3.55} width={10} height={0.6} size={22} color={theme.muted}>\n Edit this TSX and save to update the preview.\n </Text>\n </Slide>\n );\n}\n`;\n\nconst guide = `# Writing this presentation\n\nUse deck.tsx for slide order, slides/*.tsx for individual slides, and theme.ts\nfor shared design values. The JSX runtime is\n@office-kit/pptx-dsl, with no React or Vue dependency.\n\n- Run npm run dev, then open its local URL to preview. Saving source files\n updates the preview. A failed build retains the last successful output.\n- The preview is view-only: use the vertical thumbnails to select slides, zoom\n to inspect details, and Present to view full-screen (Escape exits). Make all\n content and layout changes in TSX; there are no canvas editing controls.\n- For a local revision, locate the slide through deck.tsx or a text search and\n read only the relevant source and dependencies. Patch the requested text, data\n or props; do not regenerate the deck or reformat unrelated code. Keep descriptive\n filenames stable when reordering slides. Preserve existing project structures.\n- Change shared theme values/components only for changes intended for all their\n consumers; use a local prop override for a one-slide exception.\n- Keep the preview running during revisions and inspect affected slides after\n saving. Review all affected consumers for shared changes. Do not run a separate\n export for every intermediate edit. Before delivery, run npm run check and\n npm run build to export deck.pptx, then review the whole deck.\n- Coordinates and dimensions are inches; font sizes and stroke widths are points.\n The default 16:9 canvas is 13.333 × 7.5 inches.\n- Use native Text, Shape, Image, Table and Chart elements. Use JS functions,\n arrays and map to compose elements; do not import React.\n- Chart takes the core ChartSpec in its spec prop. Text accepts rich ParagraphSpec\n arrays through paragraphs. Raw is an escape hatch for public core APIs.\n- For templates: readFile(new URL('./template.pptx', import.meta.url)), then use\n Presentation source={bytes} mode=\"edit\" and Slide target={{index: 0}}.\n Fill target={{name: 'Title 1'}} changes an existing shape. Indices are zero-based.\n Use office-pptx inspect template.pptx to discover names, layouts and placeholders.\n- Use mode=\"compose\" and Slide from={{index: 0}} to build a new sequence from a\n source deck. This intentionally removes the original slide sequence.\n- Keep assets inside this project so the dev server sees changes. Use source-relative\n new URL('./image.png', import.meta.url) when loading local assets.\n- Preserve existing slides and formatting unless the request calls for changes.\n Never rasterize a chart/table as a shortcut. Raw-only features are not DSL coverage.\n- Preview is a rendering aid, not a guarantee of identical PowerPoint rendering.\n Check the exported file in the target application for final delivery.\n\nVSCode uses tsconfig.json for completion and diagnostics. Start the\n\"Preview presentation\" task, then run \"Simple Browser: Show\" with the printed URL\nand move that editor to a side group. Type errors appear in the Problems panel.\n`;\n\n/** Creates a new directory; existing projects are never overwritten. */\nexport async function initProject(directory: string): Promise<string> {\n const root = resolve(directory);\n const packageLocations = [\n import.meta.resolve('@office-kit/pptx/package.json'),\n import.meta.resolve('@office-kit/pptx-dsl/package.json'),\n new URL('../package.json', import.meta.url),\n ];\n const versions = await Promise.all(\n packageLocations.map(async (location) => {\n const manifest: { version: string } = JSON.parse(await readFile(new URL(location), 'utf8'));\n return `^${manifest.version}`;\n }),\n );\n await mkdir(root);\n const files: Record<string, string> = {\n 'package.json':\n JSON.stringify(\n {\n name: 'my-presentation',\n private: true,\n type: 'module',\n scripts: {\n dev: 'office-pptx dev deck.tsx',\n build: 'office-pptx build deck.tsx --out deck.pptx',\n check: 'tsc --noEmit',\n },\n dependencies: { '@office-kit/pptx': versions[0]!, '@office-kit/pptx-dsl': versions[1]! },\n devDependencies: {\n '@office-kit/pptx-dev': versions[2]!,\n '@types/node': '^24.13.2',\n typescript: '^6.0.3',\n },\n },\n null,\n 2,\n ) + '\\n',\n 'tsconfig.json':\n JSON.stringify(\n {\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'Bundler',\n jsx: 'react-jsx',\n jsxImportSource: '@office-kit/pptx-dsl',\n strict: true,\n exactOptionalPropertyTypes: true,\n noEmit: true,\n allowImportingTsExtensions: true,\n types: ['node'],\n },\n include: ['**/*.ts', '**/*.tsx'],\n exclude: ['node_modules'],\n },\n null,\n 2,\n ) + '\\n',\n 'deck.tsx': starter,\n 'theme.ts': theme,\n 'slides/cover.tsx': cover,\n 'CLAUDE.md': guide,\n '.gitignore': 'node_modules/\\ndeck.pptx\\n',\n '.vscode/tasks.json':\n JSON.stringify(\n {\n version: '2.0.0',\n tasks: [\n {\n label: 'Preview presentation',\n type: 'shell',\n command: 'npm run dev',\n isBackground: true,\n problemMatcher: {\n pattern: { regexp: '^NEVER_MATCH$', file: 1, message: 2 },\n background: {\n activeOnStart: true,\n beginsPattern: '^.*office-pptx dev',\n endsPattern: '^Preview: ',\n },\n },\n },\n {\n label: 'Check presentation',\n type: 'shell',\n command: 'npm run check',\n problemMatcher: '$tsc',\n },\n {\n label: 'Export presentation',\n type: 'shell',\n command: 'npm run build',\n problemMatcher: [],\n },\n ],\n },\n null,\n 2,\n ) + '\\n',\n };\n await Promise.all(['.vscode', 'slides'].map((directory) => mkdir(join(root, directory))));\n await Promise.all(\n Object.entries(files).map(([name, content]) =>\n writeFile(join(root, name), content, { flag: 'wx' }),\n ),\n );\n return root;\n}\n","import { readFile } from 'node:fs/promises';\nimport {\n loadPresentation,\n getSlides,\n getSlidePartName,\n getSlideTitle,\n getSlideShapes,\n getShapeName,\n getShapeId,\n getShapeKind,\n getShapePlaceholderType,\n getShapePlaceholderIdx,\n getSlideLayouts,\n getSlideLayoutName,\n getSlideLayoutPartName,\n getSlideLayoutType,\n} from '@office-kit/pptx';\n\n/** Source references usable directly in Slide, Fill and Remove props. */\nexport async function inspectTemplate(file: string) {\n const presentation = await loadPresentation(await readFile(file));\n return {\n slides: getSlides(presentation).map((slide, index) => ({\n index,\n part: getSlidePartName(slide),\n title: getSlideTitle(slide),\n shapes: getSlideShapes(slide).map((shape) => ({\n id: getShapeId(shape),\n name: getShapeName(shape),\n kind: getShapeKind(shape),\n placeholder: { type: getShapePlaceholderType(shape), idx: getShapePlaceholderIdx(shape) },\n })),\n })),\n layouts: getSlideLayouts(presentation).map((layout) => ({\n part: getSlideLayoutPartName(layout),\n name: getSlideLayoutName(layout),\n type: getSlideLayoutType(layout),\n })),\n };\n}\n","import { writeFile } from 'node:fs/promises';\nimport { createDeckBuilder } from './build-runner.ts';\nimport type { BuildResult } from './build.ts';\nexport type { BuildResult } from './build.ts';\nexport { initProject } from './init.ts';\nexport { inspectTemplate } from './inspect.ts';\n\n/** Each evaluation gets a fresh module cache and releases it when finished. */\nexport async function buildDeck(entry: string): Promise<BuildResult> {\n const builder = createDeckBuilder(entry, false);\n try {\n return await builder.build();\n } finally {\n await builder.close();\n }\n}\nexport async function exportDeck(entry: string, output: string): Promise<BuildResult> {\n const result = await buildDeck(entry);\n await writeFile(output, result.bytes);\n return result;\n}\n"],"mappings":";;;;;;;AAOA,MAAM,mBAAmB;AAEzB,SAAS,cAAc,OAAe;CACpC,MAAM,YAAY,YAAY,KAAK,OAAO,GAAG,cAAc,CAAC;CAC5D,MAAM,SAAS,IAAI,OAAO,IAAI,IAAI,gBAAgB,OAAO,KAAK,GAAG,GAAG;EAClE,YAAY;GAAE,OAAO,QAAQ,KAAK;GAAG;EAAU;EAC/C,UAAU,CAAC,sBAAsB;CACnC,CAAC;CACD,MAAM,SAAS,IAAI,SAAsB,cAAc,WAAW;EAChE,OAAO,KAAK,WAAW,YAAY;EACnC,OAAO,KAAK,SAAS,MAAM;EAC3B,OAAO,KAAK,SAAS,SACnB,uBAAO,IAAI,MAAM,8CAA8C,KAAK,GAAG,CAAC,CAC1E;CACF,CAAC;CAED,OAAY,YAAY,CAAC,CAAC;CAC1B,OAAO;EAAE;EAAQ;EAAQ;CAAU;AACrC;;AAGA,SAAgB,kBAAkB,OAAe,WAAW,MAAM;CAChE,IAAI,WAAyD,cAAc,KAAK;CAChF,IAAI,SAAS;CACb,IAAI,SAAS;CACb,OAAO;EACL,MAAM,QAA8B;GAClC,IAAI,UAAU,QAAQ,MAAM,IAAI,MAAM,6CAA6C;GACnF,SAAS;GACT,MAAM,UAAU,YAAY,cAAc,KAAK;GAC/C,WAAW;GACX,IAAI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A,eAAsB,gBAAgB,MAAc;CAClD,MAAM,eAAe,MAAM,iBAAiB,MAAM,SAAS,IAAI,CAAC;CAChE,OAAO;EACL,QAAQ,UAAU,YAAY,CAAC,CAAC,KAAK,OAAO,WAAW;GACrD;GACA,MAAM,iBAAiB,KAAK;GAC5B,OAAO,cAAc,KAAK;GAC1B,QAAQ,eAAe,KAAK,CAAC,CAAC,KAAK,WAAW;IAC5C,IAAI,WAAW,KAAK;IACpB,MAAM,aAAa,KAAK;IACxB,MAAM,aAAa,KAAK;IACxB,aAAa;KAAE,MAAM,wBAAwB,KAAK;KAAG,KAAK,uBAAuB,KAAK;IAAE;GAC1F,EAAE;EACJ,EAAE;EACF,SAAS,gBAAgB,YAAY,CAAC,CAAC,KAAK,YAAY;GACtD,MAAM,uBAAuB,MAAM;GACnC,MAAM,mBAAmB,MAAM;GAC/B,MAAM,mBAAmB,MAAM;EACjC,EAAE;CACJ;AACF;;;;AC/BA,eAAsB,UAAU,OAAqC;CACnE,MAAM,UAAU,kBAAkB,OAAO,KAAK;CAC9C,IAAI;EACF,OAAO,MAAM,QAAQ,MAAM;CAC7B,UAAU;EACR,MAAM,QAAQ,MAAM;CACtB;AACF;AACA,eAAsB,WAAW,OAAe,QAAsC;CACpF,MAAM,SAAS,MAAM,UAAU,KAAK;CACpC,MAAM,UAAU,QAAQ,OAAO,KAAK;CACpC,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-kit/pptx-dev",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Build and preview PowerPoint TSX presentations locally",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "esbuild": "^0.28.1",
31
- "@office-kit/pptx": "^0.17.0",
32
- "@office-kit/pptx-dsl": "^0.3.0",
31
+ "@office-kit/pptx": "^0.18.0",
32
+ "@office-kit/pptx-dsl": "^0.5.0",
33
33
  "@office-kit/pptx-preview": "^0.9.6"
34
34
  },
35
35
  "devDependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"src-U5ZNAbtV.mjs","names":[],"sources":["../src/build-runner.ts","../src/init.ts","../src/inspect.ts","../src/index.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport { resolve, join } from 'node:path';\nimport { mkdtempSync } from 'node:fs';\nimport { rm } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport type { BuildResult } from './build.ts';\n\nconst BUILD_TIMEOUT_MS = 60_000;\n\nfunction prepareWorker(entry: string) {\n const directory = mkdtempSync(join(tmpdir(), 'office-pptx-'));\n const worker = new Worker(new URL('./worker.mjs', import.meta.url), {\n workerData: { entry: resolve(entry), directory },\n execArgv: ['--enable-source-maps'],\n });\n const result = new Promise<BuildResult>((resolveBuild, reject) => {\n worker.once('message', resolveBuild);\n worker.once('error', reject);\n worker.once('exit', (code) =>\n reject(new Error(`Build worker exited without a result (code ${code}).`)),\n );\n });\n // Startup may fail before the next edit asks to use this worker.\n void result.catch(() => {});\n return { worker, result, directory };\n}\n\n/** Internal watch session. Preload libraries, but never reuse a user module cache. */\nexport function createDeckBuilder(entry: string, keepWarm = true) {\n let prepared: ReturnType<typeof prepareWorker> | undefined = prepareWorker(entry);\n let closed = false;\n let active = false;\n return {\n async build(): Promise<BuildResult> {\n if (closed || active) throw new Error('Deck builder is closed or already building.');\n active = true;\n const current = prepared ?? prepareWorker(entry);\n prepared = current;\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n current.worker.postMessage('build');\n return await Promise.race([\n current.result,\n new Promise<never>((_, reject) => {\n timer = setTimeout(\n () =>\n reject(\n new Error(\n 'Build exceeded 60 seconds. Check the deck for loops or unresolved promises.',\n ),\n ),\n BUILD_TIMEOUT_MS,\n );\n }),\n ]);\n } finally {\n clearTimeout(timer);\n await current.worker.terminate();\n await rm(current.directory, { recursive: true, force: true });\n active = false;\n prepared = !closed && keepWarm ? prepareWorker(entry) : undefined;\n }\n },\n async cancel() {\n if (active) await prepared?.worker.terminate();\n },\n async close() {\n closed = true;\n const current = prepared;\n await current?.worker.terminate();\n if (current) await rm(current.directory, { recursive: true, force: true });\n },\n };\n}\n","import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\n\nconst starter = `import { Presentation, Slide, Text, Shape } from '@office-kit/pptx-dsl';\n\nexport default (\n <Presentation>\n <Slide background=\"#15171C\">\n <Shape preset=\"rect\" x={0.9} y={2.55} width={0.14} height={1.75} fill=\"#E5481F\" stroke={false} />\n <Text x={1.25} y={2.4} width={10} height={1.1} size={48} bold color=\"#FFFFFF\">\n Your next presentation\n </Text>\n <Text x={1.25} y={3.55} width={10} height={0.6} size={22} color=\"#B4B9C4\">\n Edit this TSX and save to update the preview.\n </Text>\n </Slide>\n </Presentation>\n);\n`;\n\nconst guide = `# Writing this presentation\n\nEdit deck.tsx and local TypeScript components. The JSX runtime is\n@office-kit/pptx-dsl, with no React or Vue dependency.\n\n- Run npm run dev, then open its local URL to preview. Saving source files\n updates the preview. A failed build retains the last successful output.\n- The preview is view-only: use the vertical thumbnails to select slides, zoom\n to inspect details, and Present to view full-screen (Escape exits). Make all\n content and layout changes in TSX; there are no canvas editing controls.\n- Run npm run check for TypeScript diagnostics; run npm run build to export\n deck.pptx. Inspect every slide in the preview after changes.\n- Coordinates and dimensions are inches; font sizes and stroke widths are points.\n The default 16:9 canvas is 13.333 × 7.5 inches.\n- Use native Text, Shape, Image, Table and Chart elements. Use JS functions,\n arrays and map to compose elements; do not import React.\n- Chart takes the core ChartSpec in its spec prop. Text accepts rich ParagraphSpec\n arrays through paragraphs. Raw is an escape hatch for public core APIs.\n- For templates: readFile(new URL('./template.pptx', import.meta.url)), then use\n Presentation source={bytes} mode=\"edit\" and Slide target={{index: 0}}.\n Fill target={{name: 'Title 1'}} changes an existing shape. Indices are zero-based.\n Use office-pptx inspect template.pptx to discover names, layouts and placeholders.\n- Use mode=\"compose\" and Slide from={{index: 0}} to build a new sequence from a\n source deck. This intentionally removes the original slide sequence.\n- Keep assets inside this project so the dev server sees changes. Use source-relative\n new URL('./image.png', import.meta.url) when loading local assets.\n- Preserve existing slides and formatting unless the request calls for changes.\n Never rasterize a chart/table as a shortcut. Raw-only features are not DSL coverage.\n- Preview is a rendering aid, not a guarantee of identical PowerPoint rendering.\n Check the exported file in the target application for final delivery.\n\nVSCode uses tsconfig.json for completion and diagnostics. Start the\n\"Preview presentation\" task, then run \"Simple Browser: Show\" with the printed URL\nand move that editor to a side group. Type errors appear in the Problems panel.\n`;\n\n/** Creates a new directory; existing projects are never overwritten. */\nexport async function initProject(directory: string): Promise<string> {\n const root = resolve(directory);\n const packageLocations = [\n import.meta.resolve('@office-kit/pptx/package.json'),\n import.meta.resolve('@office-kit/pptx-dsl/package.json'),\n new URL('../package.json', import.meta.url),\n ];\n const versions = await Promise.all(\n packageLocations.map(async (location) => {\n const manifest: { version: string } = JSON.parse(await readFile(new URL(location), 'utf8'));\n return `^${manifest.version}`;\n }),\n );\n await mkdir(root);\n const files: Record<string, string> = {\n 'package.json':\n JSON.stringify(\n {\n name: 'my-presentation',\n private: true,\n type: 'module',\n scripts: {\n dev: 'office-pptx dev deck.tsx',\n build: 'office-pptx build deck.tsx --out deck.pptx',\n check: 'tsc --noEmit',\n },\n dependencies: { '@office-kit/pptx': versions[0]!, '@office-kit/pptx-dsl': versions[1]! },\n devDependencies: {\n '@office-kit/pptx-dev': versions[2]!,\n '@types/node': '^24.13.2',\n typescript: '^6.0.3',\n },\n },\n null,\n 2,\n ) + '\\n',\n 'tsconfig.json':\n JSON.stringify(\n {\n compilerOptions: {\n target: 'ES2022',\n module: 'ESNext',\n moduleResolution: 'Bundler',\n jsx: 'react-jsx',\n jsxImportSource: '@office-kit/pptx-dsl',\n strict: true,\n exactOptionalPropertyTypes: true,\n noEmit: true,\n allowImportingTsExtensions: true,\n types: ['node'],\n },\n include: ['**/*.ts', '**/*.tsx'],\n exclude: ['node_modules'],\n },\n null,\n 2,\n ) + '\\n',\n 'deck.tsx': starter,\n 'CLAUDE.md': guide,\n '.gitignore': 'node_modules/\\ndeck.pptx\\n',\n '.vscode/tasks.json':\n JSON.stringify(\n {\n version: '2.0.0',\n tasks: [\n {\n label: 'Preview presentation',\n type: 'shell',\n command: 'npm run dev',\n isBackground: true,\n problemMatcher: {\n pattern: { regexp: '^NEVER_MATCH$', file: 1, message: 2 },\n background: {\n activeOnStart: true,\n beginsPattern: '^.*office-pptx dev',\n endsPattern: '^Preview: ',\n },\n },\n },\n {\n label: 'Check presentation',\n type: 'shell',\n command: 'npm run check',\n problemMatcher: '$tsc',\n },\n {\n label: 'Export presentation',\n type: 'shell',\n command: 'npm run build',\n problemMatcher: [],\n },\n ],\n },\n null,\n 2,\n ) + '\\n',\n };\n await mkdir(join(root, '.vscode'));\n await Promise.all(\n Object.entries(files).map(([name, content]) =>\n writeFile(join(root, name), content, { flag: 'wx' }),\n ),\n );\n return root;\n}\n","import { readFile } from 'node:fs/promises';\nimport {\n loadPresentation,\n getSlides,\n getSlidePartName,\n getSlideTitle,\n getSlideShapes,\n getShapeName,\n getShapeId,\n getShapeKind,\n getShapePlaceholderType,\n getShapePlaceholderIdx,\n getSlideLayouts,\n getSlideLayoutName,\n getSlideLayoutPartName,\n getSlideLayoutType,\n} from '@office-kit/pptx';\n\n/** Source references usable directly in Slide, Fill and Remove props. */\nexport async function inspectTemplate(file: string) {\n const presentation = await loadPresentation(await readFile(file));\n return {\n slides: getSlides(presentation).map((slide, index) => ({\n index,\n part: getSlidePartName(slide),\n title: getSlideTitle(slide),\n shapes: getSlideShapes(slide).map((shape) => ({\n id: getShapeId(shape),\n name: getShapeName(shape),\n kind: getShapeKind(shape),\n placeholder: { type: getShapePlaceholderType(shape), idx: getShapePlaceholderIdx(shape) },\n })),\n })),\n layouts: getSlideLayouts(presentation).map((layout) => ({\n part: getSlideLayoutPartName(layout),\n name: getSlideLayoutName(layout),\n type: getSlideLayoutType(layout),\n })),\n };\n}\n","import { writeFile } from 'node:fs/promises';\nimport { createDeckBuilder } from './build-runner.ts';\nimport type { BuildResult } from './build.ts';\nexport type { BuildResult } from './build.ts';\nexport { initProject } from './init.ts';\nexport { inspectTemplate } from './inspect.ts';\n\n/** Each evaluation gets a fresh module cache and releases it when finished. */\nexport async function buildDeck(entry: string): Promise<BuildResult> {\n const builder = createDeckBuilder(entry, false);\n try {\n return await builder.build();\n } finally {\n await builder.close();\n }\n}\nexport async function exportDeck(entry: string, output: string): Promise<BuildResult> {\n const result = await buildDeck(entry);\n await writeFile(output, result.bytes);\n return result;\n}\n"],"mappings":";;;;;;;AAOA,MAAM,mBAAmB;AAEzB,SAAS,cAAc,OAAe;CACpC,MAAM,YAAY,YAAY,KAAK,OAAO,GAAG,cAAc,CAAC;CAC5D,MAAM,SAAS,IAAI,OAAO,IAAI,IAAI,gBAAgB,OAAO,KAAK,GAAG,GAAG;EAClE,YAAY;GAAE,OAAO,QAAQ,KAAK;GAAG;EAAU;EAC/C,UAAU,CAAC,sBAAsB;CACnC,CAAC;CACD,MAAM,SAAS,IAAI,SAAsB,cAAc,WAAW;EAChE,OAAO,KAAK,WAAW,YAAY;EACnC,OAAO,KAAK,SAAS,MAAM;EAC3B,OAAO,KAAK,SAAS,SACnB,uBAAO,IAAI,MAAM,8CAA8C,KAAK,GAAG,CAAC,CAC1E;CACF,CAAC;CAED,OAAY,YAAY,CAAC,CAAC;CAC1B,OAAO;EAAE;EAAQ;EAAQ;CAAU;AACrC;;AAGA,SAAgB,kBAAkB,OAAe,WAAW,MAAM;CAChE,IAAI,WAAyD,cAAc,KAAK;CAChF,IAAI,SAAS;CACb,IAAI,SAAS;CACb,OAAO;EACL,MAAM,QAA8B;GAClC,IAAI,UAAU,QAAQ,MAAM,IAAI,MAAM,6CAA6C;GACnF,SAAS;GACT,MAAM,UAAU,YAAY,cAAc,KAAK;GAC/C,WAAW;GACX,IAAI;GACJ,IAAI;IACF,QAAQ,OAAO,YAAY,OAAO;IAClC,OAAO,MAA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