pptx-ts 0.0.1
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/LICENSE +22 -0
- package/README.md +319 -0
- package/dist/autopage-DkjYZUFD.js +423 -0
- package/dist/autopage-DkjYZUFD.js.map +1 -0
- package/dist/browser.d.ts +31 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +110 -0
- package/dist/browser.js.map +1 -0
- package/dist/diagnostics-Du_s75MT.d.ts +829 -0
- package/dist/diagnostics-Du_s75MT.d.ts.map +1 -0
- package/dist/enums-CvRYniUA.d.ts +463 -0
- package/dist/enums-CvRYniUA.d.ts.map +1 -0
- package/dist/errors-Bvln0H-7.js +112 -0
- package/dist/errors-Bvln0H-7.js.map +1 -0
- package/dist/errors-PflMPWBn.d.ts +182 -0
- package/dist/errors-PflMPWBn.d.ts.map +1 -0
- package/dist/fit-BKs0zxMI.js +1356 -0
- package/dist/fit-BKs0zxMI.js.map +1 -0
- package/dist/html-dom-B0I0QSbU.js +679 -0
- package/dist/html-dom-B0I0QSbU.js.map +1 -0
- package/dist/html.d.ts +26 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +63 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect.d.ts +197 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/inspect.js +317 -0
- package/dist/inspect.js.map +1 -0
- package/dist/math.d.ts +37 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +203 -0
- package/dist/math.js.map +1 -0
- package/dist/measure.d.ts +313 -0
- package/dist/measure.d.ts.map +1 -0
- package/dist/measure.js +3 -0
- package/dist/namespaces-BVnNu7sg.js +666 -0
- package/dist/namespaces-BVnNu7sg.js.map +1 -0
- package/dist/node.d.ts +20 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +55 -0
- package/dist/node.js.map +1 -0
- package/dist/notes-RLCwdlTE.js +1703 -0
- package/dist/notes-RLCwdlTE.js.map +1 -0
- package/dist/package-CaOLXSNi.d.ts +193 -0
- package/dist/package-CaOLXSNi.d.ts.map +1 -0
- package/dist/pres-C5__xkDh.d.ts +202 -0
- package/dist/pres-C5__xkDh.d.ts.map +1 -0
- package/dist/presentation-Cp7vzlAw.js +5427 -0
- package/dist/presentation-Cp7vzlAw.js.map +1 -0
- package/dist/presentation-types-DP_8jog7.d.ts +4872 -0
- package/dist/presentation-types-DP_8jog7.d.ts.map +1 -0
- package/dist/read.d.ts +55 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +4 -0
- package/dist/script.d.ts +581 -0
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +3741 -0
- package/dist/script.js.map +1 -0
- package/dist/shapes-BemroU-z.js +6951 -0
- package/dist/shapes-BemroU-z.js.map +1 -0
- package/dist/slide-js0QpRV-.d.ts +3873 -0
- package/dist/slide-js0QpRV-.d.ts.map +1 -0
- package/dist/text-CyetbF6p.js +11278 -0
- package/dist/text-CyetbF6p.js.map +1 -0
- package/dist/units-1kRzYShk.js +231 -0
- package/dist/units-1kRzYShk.js.map +1 -0
- package/dist/units-internal-Dg95w_YD.js +753 -0
- package/dist/units-internal-Dg95w_YD.js.map +1 -0
- package/dist/zip.d.ts +68 -0
- package/dist/zip.d.ts.map +1 -0
- package/dist/zip.js +163 -0
- package/dist/zip.js.map +1 -0
- package/package.json +152 -0
- package/skills/ts-pptx-upstream/SKILL.md +340 -0
package/dist/browser.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { _ as pointsToEmu, a as FIXED_PCT_PER_PERCENT, b as setDiagnosticHandler, c as POINTS_PER_INCH, d as emuToInches, f as emuToPixels, g as pixelsToEmu, h as percentToEmu, i as EMU_PER_POINT, l as STANDARD_LAYOUTS, m as inchesToEmu, n as DEFAULT_PX_PER_INCH, o as HUNDREDTHS_PER_POINT, p as emuToPoints, r as EMU_PER_INCH, s as PERCENT_SCALE, t as ANGLE_UNITS_PER_DEGREE, u as coordToEmu, v as ptToHundredths, y as resetDiagnosticState } from "./units-1kRzYShk.js";
|
|
2
|
+
import { a as TsPptxError, i as PackageReadError, n as InvalidOptionError, o as UnsupportedFeatureError, r as MediaError, t as InternalError } from "./errors-Bvln0H-7.js";
|
|
3
|
+
import { c as PresentationCore, i as fetchFontBytes, l as IMG_SVG_PLACEHOLDER, n as textRuns, r as clipPath, t as textRun } from "./text-CyetbF6p.js";
|
|
4
|
+
import { $ as isChartExType, B as BulletType, G as SchemeColor, H as ChartType, J as TableStyle, K as ShapeType, Q as connectorPresetFor, R as AlignH, U as OutputType, V as CONNECTOR_PRESETS, W as PlaceholderType, X as VALID_SHAPE_PRESETS, Y as TextAnchor, Z as asChartType, et as isChartType, q as SlideObjectType, z as AlignV } from "./units-internal-Dg95w_YD.js";
|
|
5
|
+
import { t as genTableToSlides } from "./html-dom-B0I0QSbU.js";
|
|
6
|
+
//#region src/runtime/browser.ts
|
|
7
|
+
function createBrowserRuntime() {
|
|
8
|
+
return {
|
|
9
|
+
writeFileOutputType: null,
|
|
10
|
+
loadMedia,
|
|
11
|
+
createSvgPngPreview,
|
|
12
|
+
writeFile,
|
|
13
|
+
loadFontData: fetchFontBytes
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a `data:` URI, not raw base64 — see {@link RuntimeAdapter.loadMedia}. The `FileReader`
|
|
18
|
+
* is what makes this adapter's own implementation worth keeping: it decodes the blob off the main
|
|
19
|
+
* thread, where the shared `fetchMediaBase64` would encode the whole payload synchronously.
|
|
20
|
+
*/
|
|
21
|
+
async function loadMedia(rel) {
|
|
22
|
+
const response = await fetch(rel.path);
|
|
23
|
+
if (!response.ok) throw new MediaError("media/fetch-failed", `Unable to load image (fetch): ${rel.path}`);
|
|
24
|
+
const blob = await response.blob();
|
|
25
|
+
return await new Promise((resolve, reject) => {
|
|
26
|
+
const reader = new FileReader();
|
|
27
|
+
reader.onloadend = () => resolve(reader.result);
|
|
28
|
+
reader.onerror = () => reject(new MediaError("media/decode-failed", `Unable to load image (FileReader): ${rel.path}`));
|
|
29
|
+
reader.readAsDataURL(blob);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function createSvgPngPreview(rel) {
|
|
33
|
+
return await new Promise((resolve, reject) => {
|
|
34
|
+
const image = new Image();
|
|
35
|
+
const fail = (reason) => {
|
|
36
|
+
rel.data = IMG_SVG_PLACEHOLDER;
|
|
37
|
+
reject(new MediaError("media/svg-preview-failed", `Unable to load image (image.onerror): ${rel.path}${reason ? ` - ${String(reason)}` : ""}`));
|
|
38
|
+
};
|
|
39
|
+
image.onload = () => {
|
|
40
|
+
if (image.width + image.height === 0) {
|
|
41
|
+
fail("h/w=0");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const canvas = document.createElement("CANVAS");
|
|
45
|
+
const ctx = canvas.getContext("2d");
|
|
46
|
+
if (!ctx) {
|
|
47
|
+
fail("canvas 2d context unavailable");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
canvas.width = image.width;
|
|
51
|
+
canvas.height = image.height;
|
|
52
|
+
ctx.drawImage(image, 0, 0);
|
|
53
|
+
try {
|
|
54
|
+
rel.data = canvas.toDataURL(rel.type);
|
|
55
|
+
resolve("done");
|
|
56
|
+
} catch (ex) {
|
|
57
|
+
fail(ex);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
image.onerror = () => fail();
|
|
61
|
+
image.src = typeof rel.data === "string" ? rel.data : IMG_SVG_PLACEHOLDER;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async function writeFile(fileName, data) {
|
|
65
|
+
const eleLink = document.createElement("a");
|
|
66
|
+
eleLink.setAttribute("style", "display:none;");
|
|
67
|
+
eleLink.dataset["interception"] = "off";
|
|
68
|
+
document.body.appendChild(eleLink);
|
|
69
|
+
const url = window.URL.createObjectURL(new Blob([data], { type: "application/vnd.openxmlformats-officedocument.presentationml.presentation" }));
|
|
70
|
+
eleLink.href = url;
|
|
71
|
+
eleLink.download = fileName;
|
|
72
|
+
eleLink.click();
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
window.URL.revokeObjectURL(url);
|
|
75
|
+
document.body.removeChild(eleLink);
|
|
76
|
+
}, 100);
|
|
77
|
+
return fileName;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/browser.ts
|
|
81
|
+
/**
|
|
82
|
+
* The browser entry, reached through the `browser` export condition — a bundler resolving the
|
|
83
|
+
* bare `@shbernal/ts-pptx` specifier for the web lands here without naming this subpath.
|
|
84
|
+
*
|
|
85
|
+
* Same authoring API as every other entry (see `entry-surface.ts`), plus one method that only
|
|
86
|
+
* makes sense with a live DOM: {@link TsPptx.tableToSlides}. `writeFile` triggers a download
|
|
87
|
+
* rather than touching a filesystem.
|
|
88
|
+
*/
|
|
89
|
+
var TsPptx = class extends PresentationCore {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(createBrowserRuntime());
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reproduces a rendered HTML `<table>` as a PowerPoint table — including column widths,
|
|
95
|
+
* style, etc. — creating one or more slides as needed. Resolves `eleId` against the global
|
|
96
|
+
* `document`, so it exists only on the browser/standalone build; the same conversion is
|
|
97
|
+
* available anywhere there is a DOM as the free `tableToSlides` on `ts-pptx/html`, which
|
|
98
|
+
* also takes the element directly. The in-memory `slide.addTable(rows, opts)` path remains
|
|
99
|
+
* the platform-agnostic way to build a table from data you already hold.
|
|
100
|
+
* @param {string} eleId - table HTML element ID
|
|
101
|
+
* @param {TableToSlidesProps} options - generation options
|
|
102
|
+
*/
|
|
103
|
+
tableToSlides(eleId, options = {}) {
|
|
104
|
+
genTableToSlides(this, eleId, options);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
export { ANGLE_UNITS_PER_DEGREE, AlignH, AlignV, BulletType, CONNECTOR_PRESETS, ChartType, DEFAULT_PX_PER_INCH, EMU_PER_INCH, EMU_PER_POINT, FIXED_PCT_PER_PERCENT, HUNDREDTHS_PER_POINT, InternalError, InvalidOptionError, MediaError, OutputType, PERCENT_SCALE, POINTS_PER_INCH, PackageReadError, PlaceholderType, STANDARD_LAYOUTS, SchemeColor, ShapeType, SlideObjectType, TableStyle, TextAnchor, TsPptx, TsPptx as default, TsPptxError, UnsupportedFeatureError, VALID_SHAPE_PRESETS, asChartType, clipPath, connectorPresetFor, coordToEmu, emuToInches, emuToPixels, emuToPoints, inchesToEmu, isChartExType, isChartType, percentToEmu, pixelsToEmu, pointsToEmu, ptToHundredths, resetDiagnosticState, setDiagnosticHandler, textRun, textRuns };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","names":[],"sources":["../src/runtime/browser.ts","../src/browser.ts"],"sourcesContent":["import { IMG_SVG_PLACEHOLDER } from '../media/placeholders.js'\nimport { MediaError } from '../errors.js'\nimport type { SlideRelMedia } from '../types/internal.js'\nimport type { RuntimeAdapter } from './types.js'\nimport { fetchFontBytes } from './fetch-media.js'\n\nexport function createBrowserRuntime(): RuntimeAdapter {\n\treturn {\n\t\twriteFileOutputType: null,\n\t\tloadMedia,\n\t\tcreateSvgPngPreview,\n\t\twriteFile,\n\t\tloadFontData: fetchFontBytes,\n\t}\n}\n\n/**\n * Returns a `data:` URI, not raw base64 — see {@link RuntimeAdapter.loadMedia}. The `FileReader`\n * is what makes this adapter's own implementation worth keeping: it decodes the blob off the main\n * thread, where the shared `fetchMediaBase64` would encode the whole payload synchronously.\n */\nasync function loadMedia(rel: SlideRelMedia & { path: string }): Promise<string> {\n\tconst response = await fetch(rel.path)\n\tif (!response.ok) throw new MediaError('media/fetch-failed', `Unable to load image (fetch): ${rel.path}`)\n\tconst blob = await response.blob()\n\n\treturn await new Promise<string>((resolve, reject) => {\n\t\tconst reader = new FileReader()\n\t\treader.onloadend = () => resolve(reader.result as string)\n\t\treader.onerror = () =>\n\t\t\treject(new MediaError('media/decode-failed', `Unable to load image (FileReader): ${rel.path}`))\n\t\treader.readAsDataURL(blob)\n\t})\n}\n\nasync function createSvgPngPreview(rel: SlideRelMedia): Promise<string> {\n\treturn await new Promise((resolve, reject) => {\n\t\tconst image = new Image()\n\t\tconst fail = (reason?: unknown) => {\n\t\t\trel.data = IMG_SVG_PLACEHOLDER\n\t\t\treject(\n\t\t\t\tnew MediaError(\n\t\t\t\t\t'media/svg-preview-failed',\n\t\t\t\t\t`Unable to load image (image.onerror): ${rel.path}${reason ? ` - ${String(reason)}` : ''}`\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\n\t\timage.onload = () => {\n\t\t\tif (image.width + image.height === 0) {\n\t\t\t\tfail('h/w=0')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst canvas = document.createElement('CANVAS') as HTMLCanvasElement\n\t\t\tconst ctx = canvas.getContext('2d')\n\t\t\tif (!ctx) {\n\t\t\t\tfail('canvas 2d context unavailable')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcanvas.width = image.width\n\t\t\tcanvas.height = image.height\n\t\t\tctx.drawImage(image, 0, 0)\n\t\t\ttry {\n\t\t\t\t// `rel.type` is `image/png`, not the SVG's type, so this is a valid canvas output\n\t\t\t\t// type and not an `image/svg+xml` that silently falls back to PNG.\n\t\t\t\t// `createSvgPngPreview` is only called on a rel flagged `isSvgPng` — all three\n\t\t\t\t// call sites in `gen/media.ts` filter on it — and the only two places that\n\t\t\t\t// create such a rel (`gen/define/image.ts`, `gen/define/text.ts`) set the\n\t\t\t\t// *fallback's* type, since that is the part this writes. The SVG keeps its own\n\t\t\t\t// rel beside it.\n\t\t\t\trel.data = canvas.toDataURL(rel.type)\n\t\t\t\tresolve('done')\n\t\t\t} catch (ex) {\n\t\t\t\tfail(ex)\n\t\t\t}\n\t\t}\n\t\timage.onerror = () => fail()\n\t\timage.src = typeof rel.data === 'string' ? rel.data : IMG_SVG_PLACEHOLDER\n\t})\n}\n\nasync function writeFile(fileName: string, data: string | ArrayBuffer | Blob | Uint8Array): Promise<string> {\n\tconst eleLink = document.createElement('a')\n\teleLink.setAttribute('style', 'display:none;')\n\teleLink.dataset['interception'] = 'off'\n\tdocument.body.appendChild(eleLink)\n\n\tconst url = window.URL.createObjectURL(\n\t\tnew Blob([data as Blob], { type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' })\n\t)\n\teleLink.href = url\n\teleLink.download = fileName\n\teleLink.click()\n\n\tsetTimeout(() => {\n\t\twindow.URL.revokeObjectURL(url)\n\t\tdocument.body.removeChild(eleLink)\n\t}, 100)\n\n\treturn fileName\n}\n","import PresentationCore from './presentation.js'\nimport { createBrowserRuntime } from './runtime/browser.js'\nimport { genTableToSlides } from './gen/table/html-dom.js'\nimport type { TableToSlidesProps } from './types/index.js'\n\n/**\n * The browser entry, reached through the `browser` export condition — a bundler resolving the\n * bare `@shbernal/ts-pptx` specifier for the web lands here without naming this subpath.\n *\n * Same authoring API as every other entry (see `entry-surface.ts`), plus one method that only\n * makes sense with a live DOM: {@link TsPptx.tableToSlides}. `writeFile` triggers a download\n * rather than touching a filesystem.\n */\nexport class TsPptx extends PresentationCore {\n\tconstructor() {\n\t\tsuper(createBrowserRuntime())\n\t}\n\n\t/**\n\t * Reproduces a rendered HTML `<table>` as a PowerPoint table — including column widths,\n\t * style, etc. — creating one or more slides as needed. Resolves `eleId` against the global\n\t * `document`, so it exists only on the browser/standalone build; the same conversion is\n\t * available anywhere there is a DOM as the free `tableToSlides` on `ts-pptx/html`, which\n\t * also takes the element directly. The in-memory `slide.addTable(rows, opts)` path remains\n\t * the platform-agnostic way to build a table from data you already hold.\n\t * @param {string} eleId - table HTML element ID\n\t * @param {TableToSlidesProps} options - generation options\n\t */\n\ttableToSlides(eleId: string, options: TableToSlidesProps = {}): void {\n\t\t// @note `options.verbose` (a documented dev-only flag on TableToSlidesProps) is read\n\t\t// inside genTableToSlides to trace the auto-paging layout process.\n\t\tgenTableToSlides(this, eleId, options)\n\t}\n}\n\nexport { TsPptx as default }\nexport * from './entry-surface.js'\n"],"mappings":";;;;;;AAMA,SAAgB,uBAAuC;CACtD,OAAO;EACN,qBAAqB;EACrB;EACA;EACA;EACA,cAAc;CACf;AACD;;;;;;AAOA,eAAe,UAAU,KAAwD;CAChF,MAAM,WAAW,MAAM,MAAM,IAAI,IAAI;CACrC,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,WAAW,sBAAsB,iCAAiC,IAAI,MAAM;CACxG,MAAM,OAAO,MAAM,SAAS,KAAK;CAEjC,OAAO,MAAM,IAAI,SAAiB,SAAS,WAAW;EACrD,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,kBAAkB,QAAQ,OAAO,MAAgB;EACxD,OAAO,gBACN,OAAO,IAAI,WAAW,uBAAuB,sCAAsC,IAAI,MAAM,CAAC;EAC/F,OAAO,cAAc,IAAI;CAC1B,CAAC;AACF;AAEA,eAAe,oBAAoB,KAAqC;CACvE,OAAO,MAAM,IAAI,SAAS,SAAS,WAAW;EAC7C,MAAM,QAAQ,IAAI,MAAM;EACxB,MAAM,QAAQ,WAAqB;GAClC,IAAI,OAAO;GACX,OACC,IAAI,WACH,4BACA,yCAAyC,IAAI,OAAO,SAAS,MAAM,OAAO,MAAM,MAAM,IACvF,CACD;EACD;EAEA,MAAM,eAAe;GACpB,IAAI,MAAM,QAAQ,MAAM,WAAW,GAAG;IACrC,KAAK,OAAO;IACZ;GACD;GACA,MAAM,SAAS,SAAS,cAAc,QAAQ;GAC9C,MAAM,MAAM,OAAO,WAAW,IAAI;GAClC,IAAI,CAAC,KAAK;IACT,KAAK,+BAA+B;IACpC;GACD;GACA,OAAO,QAAQ,MAAM;GACrB,OAAO,SAAS,MAAM;GACtB,IAAI,UAAU,OAAO,GAAG,CAAC;GACzB,IAAI;IAQH,IAAI,OAAO,OAAO,UAAU,IAAI,IAAI;IACpC,QAAQ,MAAM;GACf,SAAS,IAAI;IACZ,KAAK,EAAE;GACR;EACD;EACA,MAAM,gBAAgB,KAAK;EAC3B,MAAM,MAAM,OAAO,IAAI,SAAS,WAAW,IAAI,OAAO;CACvD,CAAC;AACF;AAEA,eAAe,UAAU,UAAkB,MAAiE;CAC3G,MAAM,UAAU,SAAS,cAAc,GAAG;CAC1C,QAAQ,aAAa,SAAS,eAAe;CAC7C,QAAQ,QAAQ,kBAAkB;CAClC,SAAS,KAAK,YAAY,OAAO;CAEjC,MAAM,MAAM,OAAO,IAAI,gBACtB,IAAI,KAAK,CAAC,IAAY,GAAG,EAAE,MAAM,4EAA4E,CAAC,CAC/G;CACA,QAAQ,OAAO;CACf,QAAQ,WAAW;CACnB,QAAQ,MAAM;CAEd,iBAAiB;EAChB,OAAO,IAAI,gBAAgB,GAAG;EAC9B,SAAS,KAAK,YAAY,OAAO;CAClC,GAAG,GAAG;CAEN,OAAO;AACR;;;;;;;;;;;ACvFA,IAAa,SAAb,cAA4B,iBAAiB;CAC5C,cAAc;EACb,MAAM,qBAAqB,CAAC;CAC7B;;;;;;;;;;;CAYA,cAAc,OAAe,UAA8B,CAAC,GAAS;EAGpE,iBAAiB,MAAM,OAAO,OAAO;CACtC;AACD"}
|