@shbernal/pptxgenjs 5.2.0 → 5.4.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/{browser-DraPrTLD.js → browser-DGH8T04O.js} +3 -3
- package/dist/{browser-DraPrTLD.js.map → browser-DGH8T04O.js.map} +1 -1
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +4 -4
- package/dist/{core-interfaces-vUc0ElZs.js → core-interfaces-C091uvh_.js} +41 -9
- package/dist/core-interfaces-C091uvh_.js.map +1 -0
- package/dist/core.d.ts +2 -2
- package/dist/core.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/inspect.js +1 -1
- package/dist/node.d.ts +3 -3
- package/dist/node.js +4 -4
- package/dist/{pptxgen--5RWzhb4.js → pptxgen-S8dEuBnC.js} +922 -244
- package/dist/pptxgen-S8dEuBnC.js.map +1 -0
- package/dist/{pptxgen-DzBNFPxG.d.ts → pptxgen-ZuXXUvB-.d.ts} +2 -2
- package/dist/{pptxgen-DzBNFPxG.d.ts.map → pptxgen-ZuXXUvB-.d.ts.map} +1 -1
- package/dist/standalone.d.ts +443 -34
- package/dist/standalone.d.ts.map +1 -1
- package/dist/standalone.js +1002 -248
- package/dist/standalone.js.map +1 -1
- package/dist/units-BMrBTU0-.js +106 -0
- package/dist/units-BMrBTU0-.js.map +1 -0
- package/dist/{units-y594YyBo.d.ts → units-DlsWUw1U.d.ts} +444 -35
- package/dist/units-DlsWUw1U.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/core-interfaces-vUc0ElZs.js.map +0 -1
- package/dist/pptxgen--5RWzhb4.js.map +0 -1
- package/dist/units-DmzbVUNp.js +0 -62
- package/dist/units-DmzbVUNp.js.map +0 -1
- package/dist/units-y594YyBo.d.ts.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/units.ts
|
|
2
|
+
/**
|
|
3
|
+
* Public unit conversion helpers and standard PowerPoint slide-layout constants.
|
|
4
|
+
*/
|
|
5
|
+
const EMU_PER_INCH = 914400;
|
|
6
|
+
const EMU_PER_POINT = 12700;
|
|
7
|
+
const POINTS_PER_INCH = 72;
|
|
8
|
+
/** A bare number larger than this (in inches) is almost certainly a mistake — likely a raw EMU
|
|
9
|
+
* value passed where inches are expected. We interpret it as inches (the documented contract) but
|
|
10
|
+
* warn, pointing at the explicit `"<n>emu"` form. ~1000in is far beyond any real slide. */
|
|
11
|
+
const IMPLAUSIBLE_INCHES = 1e3;
|
|
12
|
+
function inchesToEmu(inches) {
|
|
13
|
+
assertFiniteNumber(inches, "inches");
|
|
14
|
+
return Math.round(inches * EMU_PER_INCH);
|
|
15
|
+
}
|
|
16
|
+
function pointsToEmu(points) {
|
|
17
|
+
assertFiniteNumber(points, "points");
|
|
18
|
+
return Math.round(points * EMU_PER_POINT);
|
|
19
|
+
}
|
|
20
|
+
function pixelsToEmu(pixels, dpi) {
|
|
21
|
+
assertFiniteNumber(pixels, "pixels");
|
|
22
|
+
assertPositiveFiniteNumber(dpi, "dpi");
|
|
23
|
+
return inchesToEmu(pixels / dpi);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a percentage of an axis length to EMU.
|
|
27
|
+
* @param percent - percentage value (e.g. `50` for 50%)
|
|
28
|
+
* @param axisEmu - the axis length in EMU (slide width for x/w, height for y/h)
|
|
29
|
+
*/
|
|
30
|
+
function percentToEmu(percent, axisEmu) {
|
|
31
|
+
assertFiniteNumber(percent, "percent");
|
|
32
|
+
assertFiniteNumber(axisEmu, "axisEmu");
|
|
33
|
+
return Math.round(percent / 100 * axisEmu);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The single user-coordinate → EMU boundary. Convert each user-supplied coordinate exactly once.
|
|
37
|
+
*
|
|
38
|
+
* Accepts (see {@link Coord}):
|
|
39
|
+
* - a bare `number` → **always inches** (the documented unit); no magnitude guessing
|
|
40
|
+
* - `"<n>%"` → percentage of `axisEmu`
|
|
41
|
+
* - `"<n>in"` / `"<n>pt"` / `"<n>emu"` → explicit units (the escape hatch for non-inch values)
|
|
42
|
+
*
|
|
43
|
+
* Throws on non-finite or unparseable input rather than silently emitting a degenerate 0-size.
|
|
44
|
+
* @param value - user coordinate
|
|
45
|
+
* @param axisEmu - axis length in EMU, used only to resolve percentages
|
|
46
|
+
*/
|
|
47
|
+
function coordToEmu(value, axisEmu) {
|
|
48
|
+
if (typeof value === "number") {
|
|
49
|
+
assertFiniteNumber(value, "coordinate");
|
|
50
|
+
if (Math.abs(value) > IMPLAUSIBLE_INCHES) console.warn(`PptxGenJS: coordinate ${value} interpreted as ${value} inches. A bare number is always inches; if you meant EMU, pass it as a string like "${Math.round(value)}emu".`);
|
|
51
|
+
return inchesToEmu(value);
|
|
52
|
+
}
|
|
53
|
+
const match = /^\s*(-?\d*\.?\d+)\s*(%|in|pt|emu)\s*$/.exec(value);
|
|
54
|
+
if (!match) throw new Error(`PptxGenJS: invalid coordinate "${value}". Expected a number (inches) or a string like "50%", "5in", "72pt", or "914400emu".`);
|
|
55
|
+
const n = Number(match[1]);
|
|
56
|
+
switch (match[2]) {
|
|
57
|
+
case "%": return percentToEmu(n, axisEmu);
|
|
58
|
+
case "in": return inchesToEmu(n);
|
|
59
|
+
case "pt": return pointsToEmu(n);
|
|
60
|
+
default:
|
|
61
|
+
assertFiniteNumber(n, "coordinate");
|
|
62
|
+
return Math.round(n);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function emuToInches(emu) {
|
|
66
|
+
assertFiniteNumber(emu, "emu");
|
|
67
|
+
return emu / EMU_PER_INCH;
|
|
68
|
+
}
|
|
69
|
+
function emuToPoints(emu) {
|
|
70
|
+
assertFiniteNumber(emu, "emu");
|
|
71
|
+
return emu / EMU_PER_POINT;
|
|
72
|
+
}
|
|
73
|
+
function emuToPixels(emu, dpi) {
|
|
74
|
+
assertFiniteNumber(emu, "emu");
|
|
75
|
+
assertPositiveFiniteNumber(dpi, "dpi");
|
|
76
|
+
return Math.round(emuToInches(emu) * dpi);
|
|
77
|
+
}
|
|
78
|
+
function standardLayout(layout, name, widthIn, heightIn) {
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
layout,
|
|
81
|
+
name,
|
|
82
|
+
width: widthIn,
|
|
83
|
+
height: heightIn,
|
|
84
|
+
widthIn,
|
|
85
|
+
heightIn,
|
|
86
|
+
widthEmu: inchesToEmu(widthIn),
|
|
87
|
+
heightEmu: inchesToEmu(heightIn)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const STANDARD_LAYOUTS = Object.freeze({
|
|
91
|
+
LAYOUT_4x3: standardLayout("LAYOUT_4x3", "screen4x3", 10, 7.5),
|
|
92
|
+
LAYOUT_16x9: standardLayout("LAYOUT_16x9", "screen16x9", 10, 5.625),
|
|
93
|
+
LAYOUT_16x10: standardLayout("LAYOUT_16x10", "screen16x10", 10, 6.25),
|
|
94
|
+
LAYOUT_WIDE: standardLayout("LAYOUT_WIDE", "custom", 40 / 3, 7.5)
|
|
95
|
+
});
|
|
96
|
+
function assertFiniteNumber(value, name) {
|
|
97
|
+
if (!Number.isFinite(value)) throw new Error(`${name} must be a finite number`);
|
|
98
|
+
}
|
|
99
|
+
function assertPositiveFiniteNumber(value, name) {
|
|
100
|
+
assertFiniteNumber(value, name);
|
|
101
|
+
if (value <= 0) throw new Error(`${name} must be greater than 0`);
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { coordToEmu as a, emuToPoints as c, pixelsToEmu as d, pointsToEmu as f, STANDARD_LAYOUTS as i, inchesToEmu as l, EMU_PER_POINT as n, emuToInches as o, POINTS_PER_INCH as r, emuToPixels as s, EMU_PER_INCH as t, percentToEmu as u };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=units-BMrBTU0-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units-BMrBTU0-.js","names":[],"sources":["../src/units.ts"],"sourcesContent":["/**\n * Public unit conversion helpers and standard PowerPoint slide-layout constants.\n */\n\nexport const EMU_PER_INCH = 914400\nexport const EMU_PER_POINT = 12700\nexport const POINTS_PER_INCH = 72\n\n/**\n * English Metric Units — the integer unit OOXML serializes geometry in (914400 per inch).\n *\n * Branded so a value that has already been resolved to EMU cannot be silently fed back into a\n * unit converter: {@link coordToEmu} only accepts a user `Coord`, so passing an `Emu` into it is\n * a compile-time error. This replaces the old runtime \"a number ≥ 100 must already be EMU\"\n * magnitude guess, which silently mis-rendered values near the threshold.\n */\nexport type Emu = number & { readonly __unit: 'emu' }\n\n/** A bare number larger than this (in inches) is almost certainly a mistake — likely a raw EMU\n * value passed where inches are expected. We interpret it as inches (the documented contract) but\n * warn, pointing at the explicit `\"<n>emu\"` form. ~1000in is far beyond any real slide. */\nconst IMPLAUSIBLE_INCHES = 1000\n\nexport type StandardLayoutName = 'LAYOUT_4x3' | 'LAYOUT_16x9' | 'LAYOUT_16x10' | 'LAYOUT_WIDE'\n\nexport interface StandardLayout {\n\t/** PptxGenJS layout key used with `pptx.layout`. */\n\treadonly layout: StandardLayoutName\n\t/** PresentationML slide-size preset name, or `custom` for PowerPoint widescreen. */\n\treadonly name: string\n\t/** Slide width in inches. Alias of {@link StandardLayout.widthIn} — inches is PptxGenJS's default coordinate unit, so this is the value to use for `addText`/`addShape` math. */\n\treadonly width: number\n\t/** Slide height in inches. Alias of {@link StandardLayout.heightIn}. */\n\treadonly height: number\n\t/** Slide width in inches. */\n\treadonly widthIn: number\n\t/** Slide height in inches. */\n\treadonly heightIn: number\n\t/** Slide width in English Metric Units. */\n\treadonly widthEmu: number\n\t/** Slide height in English Metric Units. */\n\treadonly heightEmu: number\n}\n\nexport function inchesToEmu(inches: number): Emu {\n\tassertFiniteNumber(inches, 'inches')\n\treturn Math.round(inches * EMU_PER_INCH) as Emu\n}\n\nexport function pointsToEmu(points: number): Emu {\n\tassertFiniteNumber(points, 'points')\n\treturn Math.round(points * EMU_PER_POINT) as Emu\n}\n\nexport function pixelsToEmu(pixels: number, dpi: number): Emu {\n\tassertFiniteNumber(pixels, 'pixels')\n\tassertPositiveFiniteNumber(dpi, 'dpi')\n\treturn inchesToEmu(pixels / dpi)\n}\n\n/**\n * Resolve a percentage of an axis length to EMU.\n * @param percent - percentage value (e.g. `50` for 50%)\n * @param axisEmu - the axis length in EMU (slide width for x/w, height for y/h)\n */\nexport function percentToEmu(percent: number, axisEmu: number): Emu {\n\tassertFiniteNumber(percent, 'percent')\n\tassertFiniteNumber(axisEmu, 'axisEmu')\n\treturn Math.round((percent / 100) * axisEmu) as Emu\n}\n\n/**\n * The single user-coordinate → EMU boundary. Convert each user-supplied coordinate exactly once.\n *\n * Accepts (see {@link Coord}):\n * - a bare `number` → **always inches** (the documented unit); no magnitude guessing\n * - `\"<n>%\"` → percentage of `axisEmu`\n * - `\"<n>in\"` / `\"<n>pt\"` / `\"<n>emu\"` → explicit units (the escape hatch for non-inch values)\n *\n * Throws on non-finite or unparseable input rather than silently emitting a degenerate 0-size.\n * @param value - user coordinate\n * @param axisEmu - axis length in EMU, used only to resolve percentages\n */\nexport function coordToEmu(value: number | string, axisEmu: number): Emu {\n\tif (typeof value === 'number') {\n\t\tassertFiniteNumber(value, 'coordinate')\n\t\tif (Math.abs(value) > IMPLAUSIBLE_INCHES) {\n\t\t\tconsole.warn(\n\t\t\t\t`PptxGenJS: coordinate ${value} interpreted as ${value} inches. A bare number is always inches; ` +\n\t\t\t\t\t`if you meant EMU, pass it as a string like \"${Math.round(value)}emu\".`\n\t\t\t)\n\t\t}\n\t\treturn inchesToEmu(value)\n\t}\n\n\tconst match = /^\\s*(-?\\d*\\.?\\d+)\\s*(%|in|pt|emu)\\s*$/.exec(value)\n\tif (!match) {\n\t\tthrow new Error(\n\t\t\t`PptxGenJS: invalid coordinate \"${value}\". Expected a number (inches) or a string like \"50%\", \"5in\", \"72pt\", or \"914400emu\".`\n\t\t)\n\t}\n\tconst n = Number(match[1])\n\tswitch (match[2]) {\n\t\tcase '%':\n\t\t\treturn percentToEmu(n, axisEmu)\n\t\tcase 'in':\n\t\t\treturn inchesToEmu(n)\n\t\tcase 'pt':\n\t\t\treturn pointsToEmu(n)\n\t\tdefault: // 'emu'\n\t\t\tassertFiniteNumber(n, 'coordinate')\n\t\t\treturn Math.round(n) as Emu\n\t}\n}\n\nexport function emuToInches(emu: number): number {\n\tassertFiniteNumber(emu, 'emu')\n\treturn emu / EMU_PER_INCH\n}\n\nexport function emuToPoints(emu: number): number {\n\tassertFiniteNumber(emu, 'emu')\n\treturn emu / EMU_PER_POINT\n}\n\nexport function emuToPixels(emu: number, dpi: number): number {\n\tassertFiniteNumber(emu, 'emu')\n\tassertPositiveFiniteNumber(dpi, 'dpi')\n\treturn Math.round(emuToInches(emu) * dpi)\n}\n\nfunction standardLayout(layout: StandardLayoutName, name: string, widthIn: number, heightIn: number): StandardLayout {\n\treturn Object.freeze({\n\t\tlayout,\n\t\tname,\n\t\twidth: widthIn,\n\t\theight: heightIn,\n\t\twidthIn,\n\t\theightIn,\n\t\twidthEmu: inchesToEmu(widthIn),\n\t\theightEmu: inchesToEmu(heightIn),\n\t})\n}\n\nexport const STANDARD_LAYOUTS: Readonly<Record<StandardLayoutName, StandardLayout>> = Object.freeze({\n\tLAYOUT_4x3: standardLayout('LAYOUT_4x3', 'screen4x3', 10, 7.5),\n\tLAYOUT_16x9: standardLayout('LAYOUT_16x9', 'screen16x9', 10, 5.625),\n\tLAYOUT_16x10: standardLayout('LAYOUT_16x10', 'screen16x10', 10, 6.25),\n\tLAYOUT_WIDE: standardLayout('LAYOUT_WIDE', 'custom', 40 / 3, 7.5),\n})\n\nfunction assertFiniteNumber(value: number, name: string): void {\n\tif (!Number.isFinite(value)) throw new Error(`${name} must be a finite number`)\n}\n\nfunction assertPositiveFiniteNumber(value: number, name: string): void {\n\tassertFiniteNumber(value, name)\n\tif (value <= 0) throw new Error(`${name} must be greater than 0`)\n}\n"],"mappings":";;;;AAIA,MAAa,eAAe;AAC5B,MAAa,gBAAgB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