@office-kit/pptx-dev 0.4.1 → 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/dist/worker.mjs CHANGED
@@ -1,58 +1,48 @@
1
- import { readFile } from "node:fs/promises";
2
1
  import { parentPort, workerData } from "node:worker_threads";
3
- import { join, resolve } from "node:path";
4
- import { getSlideSize, getSlideText, getSlides, loadPresentation, savePresentation, validatePresentation } from "@office-kit/pptx";
2
+ import { join } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { getSlidePartName, getSlideSize, getSlideText, getSlides, loadPresentation, savePresentation, validatePresentation } from "@office-kit/pptx";
5
+ import { createHash } from "node:crypto";
5
6
  import { once } from "node:events";
6
- import { build, transform } from "esbuild";
7
- import { fileURLToPath, pathToFileURL } from "node:url";
8
7
  import { compile } from "@office-kit/pptx-dsl";
8
+ import { unzipSync } from "fflate";
9
9
  import { renderSlideToSvg } from "@office-kit/pptx-preview";
10
+ //#region src/preview-cache.ts
11
+ /** Reuse SVG only when both slide XML and every shared rendering resource match. */
12
+ function renderPreview(presentation, bytes, previous) {
13
+ const slides = getSlides(presentation);
14
+ const names = slides.map((slide) => getSlidePartName(slide).replace(/^\//, ""));
15
+ const slideParts = new Set(names);
16
+ const parts = unzipSync(bytes);
17
+ const hashes = new Map(Object.keys(parts).sort().map((name) => [name, createHash("sha256").update(parts[name]).digest("hex")]));
18
+ const shared = createHash("sha256").update(JSON.stringify([...hashes].filter(([name]) => !slideParts.has(name) && !name.startsWith("docProps/")))).digest("hex");
19
+ const cache = {
20
+ shared,
21
+ slides: {}
22
+ };
23
+ const rendered = slides.map((slide, index) => {
24
+ const name = names[index];
25
+ const hash = hashes.get(name);
26
+ const cached = previous?.shared === shared ? previous.slides[name] : void 0;
27
+ const result = cached?.hash === hash ? cached : {
28
+ hash,
29
+ svg: renderSlideToSvg(presentation, slide),
30
+ text: getSlideText(slide)
31
+ };
32
+ cache.slides[name] = result;
33
+ return result;
34
+ });
35
+ return {
36
+ slides: rendered.map((slide) => slide.svg),
37
+ slideTexts: rendered.map((slide) => slide.text),
38
+ cache
39
+ };
40
+ }
41
+ //#endregion
10
42
  //#region src/build.ts
11
- const resolvePackage = (name) => fileURLToPath(import.meta.resolve(name));
12
43
  /** Evaluates trusted local TSX. This is code execution, not a sandbox. */
13
- async function buildDeck(entry, directory) {
14
- const output = join(directory, "deck.mjs");
15
- const result = await build({
16
- entryPoints: [resolve(entry)],
17
- outfile: output,
18
- bundle: true,
19
- platform: "node",
20
- format: "esm",
21
- target: "node22",
22
- jsx: "automatic",
23
- jsxImportSource: "@office-kit/pptx-dsl",
24
- sourcemap: "inline",
25
- metafile: true,
26
- logLevel: "silent",
27
- plugins: [{
28
- name: "source-location",
29
- setup(builder) {
30
- builder.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, async ({ path }) => {
31
- return {
32
- contents: (await transform(await readFile(path, "utf8"), {
33
- loader: path.endsWith(".tsx") ? "tsx" : path.endsWith(".ts") || path.endsWith(".mts") || path.endsWith(".cts") ? "ts" : path.endsWith(".jsx") ? "jsx" : "js",
34
- sourcefile: path,
35
- sourcemap: "inline",
36
- jsx: "automatic",
37
- jsxDev: true,
38
- jsxImportSource: "@office-kit/pptx-dsl",
39
- define: { "import.meta.url": JSON.stringify(pathToFileURL(path).href) }
40
- })).code,
41
- loader: "js"
42
- };
43
- });
44
- }
45
- }, {
46
- name: "shared-office-kit",
47
- setup(builder) {
48
- builder.onResolve({ filter: /^@office-kit\/pptx(?:-dsl)?(?:\/.*)?$/ }, ({ path }) => ({
49
- path: resolvePackage(path),
50
- external: true
51
- }));
52
- }
53
- }]
54
- });
55
- const module = await import(pathToFileURL(output).href);
44
+ async function buildDeck(directory, dependencies, previous) {
45
+ const module = await import(pathToFileURL(join(directory, "deck.mjs")).href);
56
46
  if (!module.default) throw new Error("The TSX file must default-export a Presentation.");
57
47
  const presentation = await compile(module.default);
58
48
  const diagnostics = validatePresentation(presentation);
@@ -61,21 +51,25 @@ async function buildDeck(entry, directory) {
61
51
  const bytes = await savePresentation(presentation);
62
52
  const saved = await loadPresentation(bytes);
63
53
  const size = getSlideSize(saved);
54
+ const { slides, slideTexts, cache } = renderPreview(saved, bytes, previous);
64
55
  return {
65
- bytes,
66
- aspectRatio: size ? size.width / size.height : 16 / 9,
67
- slides: getSlides(saved).map((slide) => renderSlideToSvg(saved, slide)),
68
- dependencies: Object.keys(result.metafile.inputs).map((path) => resolve(path)),
69
- slideTexts: getSlides(saved).map((slide) => getSlideText(slide)),
70
- diagnostics
56
+ cache,
57
+ result: {
58
+ bytes,
59
+ aspectRatio: size ? size.width / size.height : 16 / 9,
60
+ slides,
61
+ dependencies,
62
+ slideTexts,
63
+ diagnostics
64
+ }
71
65
  };
72
66
  }
73
67
  //#endregion
74
68
  //#region src/worker.ts
75
69
  if (!parentPort) throw new Error("The build worker must run in a worker thread.");
76
- const { entry, directory } = workerData;
77
- await once(parentPort, "message");
78
- parentPort.postMessage(await buildDeck(entry, directory));
70
+ const { directory } = workerData;
71
+ const [request] = await once(parentPort, "message");
72
+ parentPort.postMessage(await buildDeck(directory, request.dependencies, request.cache));
79
73
  //#endregion
80
74
  export {};
81
75
 
@@ -1 +1 @@
1
- {"version":3,"file":"worker.mjs","names":[],"sources":["../src/build.ts","../src/worker.ts"],"sourcesContent":["import { build, transform } from 'esbuild';\nimport { readFile } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { compile, type Node } from '@office-kit/pptx-dsl';\nimport {\n getSlideSize,\n getSlides,\n getSlideText,\n loadPresentation,\n savePresentation,\n validatePresentation,\n} from '@office-kit/pptx';\nimport { renderSlideToSvg } from '@office-kit/pptx-preview';\n\nconst resolvePackage = (name: string) => fileURLToPath(import.meta.resolve(name));\nexport interface BuildResult {\n bytes: Uint8Array;\n slides: string[];\n slideTexts: string[];\n aspectRatio: number;\n dependencies: string[];\n diagnostics: ReturnType<typeof validatePresentation>;\n}\n/** Evaluates trusted local TSX. This is code execution, not a sandbox. */\nexport async function buildDeck(entry: string, directory: string): Promise<BuildResult> {\n const output = join(directory, 'deck.mjs');\n const result = await build({\n entryPoints: [resolve(entry)],\n outfile: output,\n bundle: true,\n platform: 'node',\n format: 'esm',\n target: 'node22',\n jsx: 'automatic',\n jsxImportSource: '@office-kit/pptx-dsl',\n sourcemap: 'inline',\n metafile: true,\n logLevel: 'silent',\n plugins: [\n {\n name: 'source-location',\n setup(builder) {\n // A bundled module lives in a temporary directory. Keep source-relative\n // asset URLs pointing at each original module, including imported files.\n builder.onLoad({ filter: /\\.[cm]?[jt]sx?$/ }, async ({ path }) => {\n const source = await readFile(path, 'utf8');\n const loader = path.endsWith('.tsx')\n ? 'tsx'\n : path.endsWith('.ts') || path.endsWith('.mts') || path.endsWith('.cts')\n ? 'ts'\n : path.endsWith('.jsx')\n ? 'jsx'\n : 'js';\n const transformed = await transform(source, {\n loader,\n sourcefile: path,\n sourcemap: 'inline',\n jsx: 'automatic',\n jsxDev: true,\n jsxImportSource: '@office-kit/pptx-dsl',\n define: { 'import.meta.url': JSON.stringify(pathToFileURL(path).href) },\n });\n return { contents: transformed.code, loader: 'js' };\n });\n },\n },\n {\n name: 'shared-office-kit',\n setup(builder) {\n // Core uses symbol-backed handles; all consumers must share its instance.\n builder.onResolve({ filter: /^@office-kit\\/pptx(?:-dsl)?(?:\\/.*)?$/ }, ({ path }) => ({\n path: resolvePackage(path),\n external: true,\n }));\n },\n },\n ],\n });\n const module: { default?: Node } = await import(pathToFileURL(output).href);\n if (!module.default) throw new Error('The TSX file must default-export a Presentation.');\n const presentation = await compile(module.default);\n const diagnostics = validatePresentation(presentation);\n const errors = diagnostics.filter((issue) => issue.severity === 'error');\n if (errors.length) throw new Error(`Invalid presentation: ${JSON.stringify(errors)}`);\n const bytes = await savePresentation(presentation);\n // Preview serialized output too, so persistence defects are visible during authoring.\n const saved = await loadPresentation(bytes);\n const size = getSlideSize(saved);\n return {\n bytes,\n aspectRatio: size ? size.width / size.height : 16 / 9,\n slides: getSlides(saved).map((slide) => renderSlideToSvg(saved, slide)),\n dependencies: Object.keys(result.metafile.inputs).map((path) => resolve(path)),\n slideTexts: getSlides(saved).map((slide) => getSlideText(slide)),\n diagnostics,\n };\n}\n","import { once } from 'node:events';\nimport { parentPort, workerData } from 'node:worker_threads';\nimport { buildDeck } from './build.ts';\n\nif (!parentPort) throw new Error('The build worker must run in a worker thread.');\nconst { entry, directory } = workerData as { entry: string; directory: string };\nawait once(parentPort, 'message');\nparentPort.postMessage(await buildDeck(entry, directory));\n"],"mappings":";;;;;;;;;;AAeA,MAAM,kBAAkB,SAAiB,cAAc,OAAO,KAAK,QAAQ,IAAI,CAAC;;AAUhF,eAAsB,UAAU,OAAe,WAAyC;CACtF,MAAM,SAAS,KAAK,WAAW,UAAU;CACzC,MAAM,SAAS,MAAM,MAAM;EACzB,aAAa,CAAC,QAAQ,KAAK,CAAC;EAC5B,SAAS;EACT,QAAQ;EACR,UAAU;EACV,QAAQ;EACR,QAAQ;EACR,KAAK;EACL,iBAAiB;EACjB,WAAW;EACX,UAAU;EACV,UAAU;EACV,SAAS,CACP;GACE,MAAM;GACN,MAAM,SAAS;IAGb,QAAQ,OAAO,EAAE,QAAQ,kBAAkB,GAAG,OAAO,EAAE,WAAW;KAkBhE,OAAO;MAAE,WAAU,MATO,UAAU,MARf,SAAS,MAAM,MAAM,GAQE;OAC1C,QARa,KAAK,SAAS,MAAM,IAC/B,QACA,KAAK,SAAS,KAAK,KAAK,KAAK,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM,IACnE,OACA,KAAK,SAAS,MAAM,IAClB,QACA;OAGN,YAAY;OACZ,WAAW;OACX,KAAK;OACL,QAAQ;OACR,iBAAiB;OACjB,QAAQ,EAAE,mBAAmB,KAAK,UAAU,cAAc,IAAI,CAAC,CAAC,IAAI,EAAE;MACxE,CAAC,EAAA,CAC8B;MAAM,QAAQ;KAAK;IACpD,CAAC;GACH;EACF,GACA;GACE,MAAM;GACN,MAAM,SAAS;IAEb,QAAQ,UAAU,EAAE,QAAQ,wCAAwC,IAAI,EAAE,YAAY;KACpF,MAAM,eAAe,IAAI;KACzB,UAAU;IACZ,EAAE;GACJ;EACF,CACF;CACF,CAAC;CACD,MAAM,SAA6B,MAAM,OAAO,cAAc,MAAM,CAAC,CAAC;CACtE,IAAI,CAAC,OAAO,SAAS,MAAM,IAAI,MAAM,kDAAkD;CACvF,MAAM,eAAe,MAAM,QAAQ,OAAO,OAAO;CACjD,MAAM,cAAc,qBAAqB,YAAY;CACrD,MAAM,SAAS,YAAY,QAAQ,UAAU,MAAM,aAAa,OAAO;CACvE,IAAI,OAAO,QAAQ,MAAM,IAAI,MAAM,yBAAyB,KAAK,UAAU,MAAM,GAAG;CACpF,MAAM,QAAQ,MAAM,iBAAiB,YAAY;CAEjD,MAAM,QAAQ,MAAM,iBAAiB,KAAK;CAC1C,MAAM,OAAO,aAAa,KAAK;CAC/B,OAAO;EACL;EACA,aAAa,OAAO,KAAK,QAAQ,KAAK,SAAS,KAAK;EACpD,QAAQ,UAAU,KAAK,CAAC,CAAC,KAAK,UAAU,iBAAiB,OAAO,KAAK,CAAC;EACtE,cAAc,OAAO,KAAK,OAAO,SAAS,MAAM,CAAC,CAAC,KAAK,SAAS,QAAQ,IAAI,CAAC;EAC7E,YAAY,UAAU,KAAK,CAAC,CAAC,KAAK,UAAU,aAAa,KAAK,CAAC;EAC/D;CACF;AACF;;;AC7FA,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,+CAA+C;AAChF,MAAM,EAAE,OAAO,cAAc;AAC7B,MAAM,KAAK,YAAY,SAAS;AAChC,WAAW,YAAY,MAAM,UAAU,OAAO,SAAS,CAAC"}
1
+ {"version":3,"file":"worker.mjs","names":[],"sources":["../src/preview-cache.ts","../src/build.ts","../src/worker.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { unzipSync } from 'fflate';\nimport { getSlidePartName, getSlides, getSlideText, type PresentationData } from '@office-kit/pptx';\nimport { renderSlideToSvg } from '@office-kit/pptx-preview';\n\nexport interface PreviewCache {\n shared: string;\n slides: Record<string, { hash: string; svg: string; text: string }>;\n}\n\n/** Reuse SVG only when both slide XML and every shared rendering resource match. */\nexport function renderPreview(\n presentation: PresentationData,\n bytes: Uint8Array,\n previous?: PreviewCache,\n) {\n const slides = getSlides(presentation);\n const names = slides.map((slide) => getSlidePartName(slide).replace(/^\\//, ''));\n const slideParts = new Set(names);\n const parts = unzipSync(bytes);\n const hashes = new Map(\n Object.keys(parts)\n .sort()\n .map((name) => [name, createHash('sha256').update(parts[name]!).digest('hex')]),\n );\n // Relationships, themes, layouts, charts and media all invalidate the cache.\n // Document metadata changes on each save but cannot affect slide rendering.\n const shared = createHash('sha256')\n .update(\n JSON.stringify(\n [...hashes].filter(([name]) => !slideParts.has(name) && !name.startsWith('docProps/')),\n ),\n )\n .digest('hex');\n const cache: PreviewCache = { shared, slides: {} };\n const rendered = slides.map((slide, index) => {\n const name = names[index]!;\n const hash = hashes.get(name)!;\n const cached = previous?.shared === shared ? previous.slides[name] : undefined;\n const result =\n cached?.hash === hash\n ? cached\n : { hash, svg: renderSlideToSvg(presentation, slide), text: getSlideText(slide) };\n cache.slides[name] = result;\n return result;\n });\n return {\n slides: rendered.map((slide) => slide.svg),\n slideTexts: rendered.map((slide) => slide.text),\n cache,\n };\n}\n","import { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { compile, type Node } from '@office-kit/pptx-dsl';\nimport {\n getSlideSize,\n loadPresentation,\n savePresentation,\n validatePresentation,\n} from '@office-kit/pptx';\nimport { renderPreview, type PreviewCache } from './preview-cache.ts';\n\nexport interface BuildResult {\n bytes: Uint8Array;\n slides: string[];\n slideTexts: string[];\n aspectRatio: number;\n dependencies: string[];\n diagnostics: ReturnType<typeof validatePresentation>;\n}\n/** Evaluates trusted local TSX. This is code execution, not a sandbox. */\nexport async function buildDeck(\n directory: string,\n dependencies: string[],\n previous?: PreviewCache,\n): Promise<{ result: BuildResult; cache: PreviewCache }> {\n const output = join(directory, 'deck.mjs');\n const module: { default?: Node } = await import(pathToFileURL(output).href);\n if (!module.default) throw new Error('The TSX file must default-export a Presentation.');\n const presentation = await compile(module.default);\n const diagnostics = validatePresentation(presentation);\n const errors = diagnostics.filter((issue) => issue.severity === 'error');\n if (errors.length) throw new Error(`Invalid presentation: ${JSON.stringify(errors)}`);\n const bytes = await savePresentation(presentation);\n // Preview serialized output too, so persistence defects are visible during authoring.\n const saved = await loadPresentation(bytes);\n const size = getSlideSize(saved);\n const { slides, slideTexts, cache } = renderPreview(saved, bytes, previous);\n return {\n cache,\n result: {\n bytes,\n aspectRatio: size ? size.width / size.height : 16 / 9,\n slides,\n dependencies,\n slideTexts,\n diagnostics,\n },\n };\n}\n","import { once } from 'node:events';\nimport { parentPort, workerData } from 'node:worker_threads';\nimport type { PreviewCache } from './preview-cache.ts';\nimport { buildDeck } from './build.ts';\n\nif (!parentPort) throw new Error('The build worker must run in a worker thread.');\nconst { directory } = workerData as { directory: string };\nconst [request] = (await once(parentPort, 'message')) as [\n { dependencies: string[]; cache?: PreviewCache },\n];\nparentPort.postMessage(await buildDeck(directory, request.dependencies, request.cache));\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,cACd,cACA,OACA,UACA;CACA,MAAM,SAAS,UAAU,YAAY;CACrC,MAAM,QAAQ,OAAO,KAAK,UAAU,iBAAiB,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC;CAC9E,MAAM,aAAa,IAAI,IAAI,KAAK;CAChC,MAAM,QAAQ,UAAU,KAAK;CAC7B,MAAM,SAAS,IAAI,IACjB,OAAO,KAAK,KAAK,CAAC,CACf,KAAK,CAAC,CACN,KAAK,SAAS,CAAC,MAAM,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,KAAM,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,CAClF;CAGA,MAAM,SAAS,WAAW,QAAQ,CAAC,CAChC,OACC,KAAK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a,OAAO,KAAK,QAAQ,KAAK,SAAS,KAAK;GACpD;GACA;GACA;GACA;EACF;CACF;AACF;;;AC3CA,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,+CAA+C;AAChF,MAAM,EAAE,cAAc;AACtB,MAAM,CAAC,WAAY,MAAM,KAAK,YAAY,SAAS;AAGnD,WAAW,YAAY,MAAM,UAAU,WAAW,QAAQ,cAAc,QAAQ,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-kit/pptx-dev",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Build and preview PowerPoint TSX presentations locally",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,6 +33,7 @@
33
33
  "@xterm/addon-fit": "^0.11.0",
34
34
  "@xterm/xterm": "^6.0.0",
35
35
  "esbuild": "^0.28.1",
36
+ "fflate": "^0.8.3",
36
37
  "markdown-it": "^15.0.2",
37
38
  "node-pty": "^1.1.0"
38
39
  },
@@ -1 +0,0 @@
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;GACJ,IAAI;IACF,QAAQ,OAAO,YAAY,OAAO;IAClC,OAAO,MAAM,QAAQ,KAAK,CACxB,QAAQ,QACR,IAAI,SAAgB,GAAG,WAAW;KAChC,QAAQ,iBAEJ,uBACE,IAAI,MACF,6EACF,CACF,GACF,gBACF;IACF,CAAC,CACH,CAAC;GAC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