@shbernal/pptxgenjs 5.0.1 → 5.0.2

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.
@@ -1,4 +1,5 @@
1
- import { A as EMU, B as PLACEHOLDER_TYPES, C as DEF_PRES_LAYOUT_NAME, D as DEF_SLIDE_MARGIN_IN, F as LINEH_MODIFIER, H as SCHEME_COLOR_NAMES, K as SchemeColor, L as ONEPT, N as LAYOUT_IDX_SERIES_BASE, O as DEF_TEXT_GLOW, P as LETTERS, R as OutputType, S as DEF_PRES_LAYOUT, T as DEF_SHAPE_SHADOW, U as SHAPE_TYPE, V as REGEX_HEX_COLOR, W as SLDNUMFLDID, _ as DEF_CHART_BORDER, a as AXIS_ID_VALUE_SECONDARY, c as BARCHART_COLORS, f as ChartType, h as DEF_CELL_MARGIN_IN, i as AXIS_ID_VALUE_PRIMARY, j as IMG_BROKEN, k as DEF_TEXT_SHADOW, m as DEF_CELL_BORDER, n as AXIS_ID_CATEGORY_SECONDARY, o as AlignH, q as ShapeType, r as AXIS_ID_SERIES_PRIMARY, s as AlignV, t as AXIS_ID_CATEGORY_PRIMARY, u as CHART_TYPE, v as DEF_CHART_GRIDLINE, y as DEF_FONT_COLOR, z as PIECHART_COLORS } from "./core-enums-BkfumA6H.js";
1
+ import { c as inchesToEmu, i as STANDARD_LAYOUTS } from "./units-Bmst2HBb.js";
2
+ import { A as EMU, B as PLACEHOLDER_TYPES, C as DEF_PRES_LAYOUT_NAME, D as DEF_SLIDE_MARGIN_IN, F as LINEH_MODIFIER, H as SCHEME_COLOR_NAMES, K as SchemeColor, L as ONEPT, N as LAYOUT_IDX_SERIES_BASE, O as DEF_TEXT_GLOW, P as LETTERS, R as OutputType, S as DEF_PRES_LAYOUT, T as DEF_SHAPE_SHADOW, U as SHAPE_TYPE, V as REGEX_HEX_COLOR, W as SLDNUMFLDID, _ as DEF_CHART_BORDER, a as AXIS_ID_VALUE_SECONDARY, c as BARCHART_COLORS, f as ChartType, h as DEF_CELL_MARGIN_IN, i as AXIS_ID_VALUE_PRIMARY, j as IMG_BROKEN, k as DEF_TEXT_SHADOW, m as DEF_CELL_BORDER, n as AXIS_ID_CATEGORY_SECONDARY, o as AlignH, q as ShapeType, r as AXIS_ID_SERIES_PRIMARY, s as AlignV, t as AXIS_ID_CATEGORY_PRIMARY, u as CHART_TYPE, v as DEF_CHART_GRIDLINE, y as DEF_FONT_COLOR, z as PIECHART_COLORS } from "./core-enums-CZn5br4v.js";
2
3
  import JSZip from "jszip";
3
4
  //#region src/gen-utils.ts
4
5
  /**
@@ -143,6 +144,51 @@ function createGlowElement(options, defaults) {
143
144
  strXml += "</a:glow>";
144
145
  return strXml;
145
146
  }
147
+ function boolToXml(value) {
148
+ return value ? "1" : "0";
149
+ }
150
+ function normalizeGradientAngle(angle) {
151
+ const degrees = angle ?? 0;
152
+ if (typeof degrees !== "number" || !Number.isFinite(degrees)) throw new Error("Gradient angle must be a finite number.");
153
+ return convertRotationDegrees((degrees % 360 + 360) % 360);
154
+ }
155
+ function gradientStopColorAdjustments(stop) {
156
+ let internalElements = "";
157
+ if (stop.alpha) internalElements += `<a:alpha val="${Math.round((100 - stop.alpha) * 1e3)}"/>`;
158
+ if (stop.transparency) internalElements += `<a:alpha val="${Math.round((100 - stop.transparency) * 1e3)}"/>`;
159
+ return internalElements;
160
+ }
161
+ function normalizeGradientStops(stops) {
162
+ if (!Array.isArray(stops) || stops.length < 2) throw new Error("Gradient fill requires at least two stops.");
163
+ return stops.map((stop) => {
164
+ if (!stop || typeof stop.position !== "number" || !Number.isFinite(stop.position)) throw new Error("Gradient stop position must be a finite number from 0 to 100.");
165
+ if (stop.position < 0 || stop.position > 100) throw new Error("Gradient stop position must be from 0 to 100.");
166
+ return stop;
167
+ }).sort((a, b) => a.position - b.position);
168
+ }
169
+ /**
170
+ * Create a native DrawingML gradient fill.
171
+ * @param {GradientFillProps} gradient gradient fill options
172
+ * @returns XML string
173
+ */
174
+ function genXmlGradientFill(gradient) {
175
+ if (!gradient || gradient.kind !== "linear") throw new Error("Gradient fill currently supports only linear gradients.");
176
+ if (typeof gradient.rotateWithShape !== "undefined" && typeof gradient.rotateWithShape !== "boolean") throw new Error("Gradient rotateWithShape must be a boolean.");
177
+ if (typeof gradient.scaled !== "undefined" && typeof gradient.scaled !== "boolean") throw new Error("Gradient scaled must be a boolean.");
178
+ const stops = normalizeGradientStops(gradient.stops);
179
+ const rotWithShape = gradient.rotateWithShape ?? true;
180
+ const scaledAttr = typeof gradient.scaled === "boolean" ? ` scaled="${boolToXml(gradient.scaled)}"` : "";
181
+ let strXml = `<a:gradFill rotWithShape="${boolToXml(rotWithShape)}">`;
182
+ strXml += "<a:gsLst>";
183
+ stops.forEach((stop) => {
184
+ const position = Math.round(stop.position * 1e3);
185
+ strXml += `<a:gs pos="${position}">${createColorElement(stop.color, gradientStopColorAdjustments(stop))}</a:gs>`;
186
+ });
187
+ strXml += "</a:gsLst>";
188
+ strXml += `<a:lin ang="${normalizeGradientAngle(gradient.angle)}"${scaledAttr}/>`;
189
+ strXml += "</a:gradFill>";
190
+ return strXml;
191
+ }
146
192
  /**
147
193
  * Create color selection
148
194
  * @param {Color | ShapeFillProps | ShapeLineProps} props fill props
@@ -165,6 +211,9 @@ function genXmlColorSelection(props) {
165
211
  case "solid":
166
212
  outText += `<a:solidFill>${createColorElement(colorVal, internalElements)}</a:solidFill>`;
167
213
  break;
214
+ case "gradient":
215
+ outText += genXmlGradientFill(typeof props === "string" ? void 0 : props.gradient);
216
+ break;
168
217
  default:
169
218
  outText += "";
170
219
  break;
@@ -372,7 +421,7 @@ function getSlidesForTableRows(tableRows = [], tableProps = {}, presLayout, mast
372
421
  if (typeof tableProps.autoPageSlideStartY === "number") emuSlideTabH = (tablePropH || presLayout.height) - inch2Emu(tableProps.autoPageSlideStartY + arrInchMargins[2]);
373
422
  else if (typeof tableProps.newSlideStartY === "number") emuSlideTabH = (tablePropH || presLayout.height) - inch2Emu(tableProps.newSlideStartY + arrInchMargins[2]);
374
423
  else if (tablePropY) {
375
- emuSlideTabH = (tablePropH || presLayout.height) - inch2Emu((tablePropY / 914400 < arrInchMargins[0] ? tablePropY / EMU : arrInchMargins[0]) + arrInchMargins[2]);
424
+ emuSlideTabH = (tablePropH || presLayout.height) - inch2Emu((tablePropY / EMU < arrInchMargins[0] ? tablePropY / EMU : arrInchMargins[0]) + arrInchMargins[2]);
376
425
  if (emuSlideTabH < tablePropH) emuSlideTabH = tablePropH;
377
426
  }
378
427
  }
@@ -427,7 +476,7 @@ function getSlidesForTableRows(tableRows = [], tableProps = {}, presLayout, mast
427
476
  tableCalcW = Array.isArray(tableProps.colW) ? tableProps.colW.reduce((p, n) => p + n) * EMU : tableProps.colW * numCols || 0;
428
477
  if (tableProps.verbose) console.log(`| tableCalcW ...................................... = ${tableCalcW / EMU}`);
429
478
  }
430
- emuSlideTabW = tableCalcW || inch2Emu((tablePropX ? tablePropX / 914400 : arrInchMargins[1]) + arrInchMargins[3]);
479
+ emuSlideTabW = tableCalcW || inch2Emu((tablePropX ? tablePropX / EMU : arrInchMargins[1]) + arrInchMargins[3]);
431
480
  if (tableProps.verbose) console.log(`| emuSlideTabW .................................... = ${(emuSlideTabW / EMU).toFixed(1)}`);
432
481
  if (!tableProps.colW || !Array.isArray(tableProps.colW)) if (tableProps.colW && !isNaN(Number(tableProps.colW))) {
433
482
  const arrColW = [];
@@ -1454,8 +1503,8 @@ function addTableDefinition(target, tableRows, options, slideLayout, presLayout,
1454
1503
  }
1455
1504
  arrRows.push(newRow);
1456
1505
  });
1457
- opt.x = getSmartParseNumber(opt.x || (opt.x === 0 ? 0 : 914400 / 2), "X", presLayout);
1458
- opt.y = getSmartParseNumber(opt.y || (opt.y === 0 ? 0 : 914400 / 2), "Y", presLayout);
1506
+ opt.x = getSmartParseNumber(opt.x || (opt.x === 0 ? 0 : EMU / 2), "X", presLayout);
1507
+ opt.y = getSmartParseNumber(opt.y || (opt.y === 0 ? 0 : EMU / 2), "Y", presLayout);
1459
1508
  if (opt.h) opt.h = getSmartParseNumber(opt.h, "Y", presLayout);
1460
1509
  opt.fontSize = opt.fontSize || 12;
1461
1510
  opt.margin = opt.margin === 0 || opt.margin ? opt.margin : DEF_CELL_MARGIN_IN;
@@ -2947,7 +2996,9 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId) {
2947
2996
  */
2948
2997
  function makeCatAxis(opts, axisId, valAxisId) {
2949
2998
  let strXml = "";
2950
- if (opts._type === "scatter" || opts._type === "bubble" || opts._type === "bubble3D") strXml += "<c:valAx>";
2999
+ const usesValueAxisForCategories = opts._type === "scatter" || opts._type === "bubble" || opts._type === "bubble3D";
3000
+ const usesCategoryAxis = !usesValueAxisForCategories && !opts.catLabelFormatCode;
3001
+ if (usesValueAxisForCategories) strXml += "<c:valAx>";
2951
3002
  else strXml += "<c:" + (opts.catLabelFormatCode ? "dateAx" : "catAx") + ">";
2952
3003
  strXml += " <c:axId val=\"" + axisId + "\"/>";
2953
3004
  strXml += " <c:scaling>";
@@ -2998,12 +3049,16 @@ function makeCatAxis(opts, axisId, valAxisId) {
2998
3049
  strXml += " </a:p>";
2999
3050
  strXml += " </c:txPr>";
3000
3051
  strXml += " <c:crossAx val=\"" + valAxisId + "\"/>";
3001
- strXml += ` <c:${typeof opts.valAxisCrossesAt === "number" ? "crossesAt" : "crosses"} val="${opts.valAxisCrossesAt || "autoZero"}"/>`;
3002
- strXml += " <c:auto val=\"1\"/>";
3003
- strXml += " <c:lblAlgn val=\"ctr\"/>";
3004
- strXml += ` <c:noMultiLvlLbl val="${opts.catAxisMultiLevelLabels ? 0 : 1}"/>`;
3005
- if (opts.catAxisLabelFrequency) strXml += " <c:tickLblSkip val=\"" + opts.catAxisLabelFrequency + "\"/>";
3006
- if (opts.catLabelFormatCode || opts._type === "scatter" || opts._type === "bubble" || opts._type === "bubble3D") {
3052
+ const valAxisCrossTag = typeof opts.valAxisCrossesAt === "number" ? "crossesAt" : "crosses";
3053
+ const valAxisCrossValue = typeof opts.valAxisCrossesAt === "number" ? opts.valAxisCrossesAt : opts.valAxisCrossesAt || "autoZero";
3054
+ strXml += ` <c:${valAxisCrossTag} val="${valAxisCrossValue}"/>`;
3055
+ if (!usesValueAxisForCategories) strXml += " <c:auto val=\"1\"/>";
3056
+ if (usesCategoryAxis) {
3057
+ strXml += " <c:lblAlgn val=\"ctr\"/>";
3058
+ if (opts.catAxisLabelFrequency) strXml += " <c:tickLblSkip val=\"" + opts.catAxisLabelFrequency + "\"/>";
3059
+ strXml += ` <c:noMultiLvlLbl val="${opts.catAxisMultiLevelLabels ? 0 : 1}"/>`;
3060
+ }
3061
+ if (opts.catLabelFormatCode || usesValueAxisForCategories) {
3007
3062
  if (opts.catLabelFormatCode) {
3008
3063
  [
3009
3064
  "catAxisBaseTimeUnit",
@@ -3023,7 +3078,7 @@ function makeCatAxis(opts, axisId, valAxisId) {
3023
3078
  if (opts.catAxisMajorUnit) strXml += `<c:majorUnit val="${opts.catAxisMajorUnit}"/>`;
3024
3079
  if (opts.catAxisMinorUnit) strXml += `<c:minorUnit val="${opts.catAxisMinorUnit}"/>`;
3025
3080
  }
3026
- if (opts._type === "scatter" || opts._type === "bubble" || opts._type === "bubble3D") strXml += "</c:valAx>";
3081
+ if (usesValueAxisForCategories) strXml += "</c:valAx>";
3027
3082
  else strXml += "</c:" + (opts.catLabelFormatCode ? "dateAx" : "catAx") + ">";
3028
3083
  return strXml;
3029
3084
  }
@@ -3367,7 +3422,7 @@ function slideObjectToXml(slide) {
3367
3422
  let strSlideXml = slide._name ? "<p:cSld name=\"" + slide._name + "\">" : "<p:cSld>";
3368
3423
  let intTableNum = 1;
3369
3424
  if (slide._bkgdImgRid) strSlideXml += `<p:bg><p:bgPr><a:blipFill dpi="0" rotWithShape="1"><a:blip r:embed="rId${slide._bkgdImgRid}"><a:lum/></a:blip><a:srcRect/><a:stretch><a:fillRect/></a:stretch></a:blipFill><a:effectLst/></p:bgPr></p:bg>`;
3370
- else if (slide.background?.color) strSlideXml += `<p:bg><p:bgPr>${genXmlColorSelection(slide.background)}<a:effectLst/></p:bgPr></p:bg>`;
3425
+ else if (slide.background?.color || slide.background?.type === "gradient") strSlideXml += `<p:bg><p:bgPr>${genXmlColorSelection(slide.background)}<a:effectLst/></p:bgPr></p:bg>`;
3371
3426
  else if (!slide.bkgd && slide._name && slide._name === "DEFAULT") strSlideXml += "<p:bg><p:bgRef idx=\"1001\"><a:schemeClr val=\"bg1\"/></p:bgRef></p:bg>";
3372
3427
  strSlideXml += "<p:spTree>";
3373
3428
  strSlideXml += "<p:nvGrpSpPr><p:cNvPr id=\"1\" name=\"\"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>";
@@ -3416,7 +3471,7 @@ function slideObjectToXml(slide) {
3416
3471
  });
3417
3472
  strXml = `<p:graphicFrame><p:nvGraphicFramePr><p:cNvPr id="${intTableNum * slide._slideNum + 1}" name="${slideItemObj.options.objectName}"/>`;
3418
3473
  strXml += "<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp=\"1\"/></p:cNvGraphicFramePr> <p:nvPr><p:extLst><p:ext uri=\"{D42A27DB-BD31-4B8C-83A1-F6EECF244321}\"><p14:modId xmlns:p14=\"http://schemas.microsoft.com/office/powerpoint/2010/main\" val=\"1579011935\"/></p:ext></p:extLst></p:nvPr></p:nvGraphicFramePr>";
3419
- strXml += `<p:xfrm><a:off x="${x || (x === 0 ? 0 : 914400)}" y="${y || (y === 0 ? 0 : 914400)}"/><a:ext cx="${cx || (cx === 0 ? 0 : 914400)}" cy="${cy || 914400}"/></p:xfrm>`;
3474
+ strXml += `<p:xfrm><a:off x="${x || (x === 0 ? 0 : EMU)}" y="${y || (y === 0 ? 0 : EMU)}"/><a:ext cx="${cx || (cx === 0 ? 0 : EMU)}" cy="${cy || EMU}"/></p:xfrm>`;
3420
3475
  strXml += "<a:graphic><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/table\"><a:tbl><a:tblPr/>";
3421
3476
  if (Array.isArray(objTabOpts.colW)) {
3422
3477
  strXml += "<a:tblGrid>";
@@ -3666,7 +3721,7 @@ function slideObjectToXml(slide) {
3666
3721
  strSlideXml += ` <a:${shadowType}Shdw ${shadowType === "outer" ? "sx=\"100000\" sy=\"100000\" kx=\"0\" ky=\"0\" algn=\"bl\" rotWithShape=\"0\"" : ""} blurRad="${shadowBlur}" dist="${shadowOffset}" dir="${shadowAngle}">`;
3667
3722
  strSlideXml += ` <a:srgbClr val="${shadowColor}">`;
3668
3723
  strSlideXml += ` <a:alpha val="${shadowOpacity}"/></a:srgbClr>`;
3669
- strSlideXml += " </a:outerShdw>";
3724
+ strSlideXml += ` </a:${shadowType}Shdw>`;
3670
3725
  strSlideXml += "</a:effectLst>";
3671
3726
  }
3672
3727
  strSlideXml += "</p:spPr>";
@@ -4309,7 +4364,7 @@ function makeXmlApp(slides, company) {
4309
4364
  ${slides.map((_slideObj, idx) => `<vt:lpstr>Slide ${idx + 1}</vt:lpstr>`).join("")}
4310
4365
  </vt:vector>
4311
4366
  </TitlesOfParts>
4312
- <Company>${company}</Company>
4367
+ <Company>${encodeXmlEntities(company)}</Company>
4313
4368
  <LinksUpToDate>false</LinksUpToDate>
4314
4369
  <SharedDoc>false</SharedDoc>
4315
4370
  <HyperlinksChanged>false</HyperlinksChanged>
@@ -4623,7 +4678,14 @@ function makeXmlViewProps() {
4623
4678
  * @see https://docs.microsoft.com/en-us/office/open-xml/structure-of-a-presentationml-document
4624
4679
  * @see https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/hh273476(v=office.14)
4625
4680
  */
4626
- const VERSION = "5.0.1";
4681
+ const VERSION = "5.0.2";
4682
+ function standardLayoutToPresLayout(layout) {
4683
+ return {
4684
+ name: layout.name,
4685
+ width: layout.widthEmu,
4686
+ height: layout.heightEmu
4687
+ };
4688
+ }
4627
4689
  var PptxGenJS = class {
4628
4690
  /**
4629
4691
  * Presentation layout name
@@ -4631,7 +4693,7 @@ var PptxGenJS = class {
4631
4693
  * - 'LAYOUT_4x3' (10" x 7.5")
4632
4694
  * - 'LAYOUT_16x9' (10" x 5.625")
4633
4695
  * - 'LAYOUT_16x10' (10" x 6.25")
4634
- * - 'LAYOUT_WIDE' (13.33" x 7.5")
4696
+ * - 'LAYOUT_WIDE' (13.333" x 7.5")
4635
4697
  * Custom layouts:
4636
4698
  * Use `pptx.defineLayout()` to create custom layouts (e.g.: 'A4')
4637
4699
  * @type {string}
@@ -4817,31 +4879,11 @@ var PptxGenJS = class {
4817
4879
  _runtime;
4818
4880
  constructor(runtime) {
4819
4881
  this._runtime = runtime;
4820
- const layout4x3 = {
4821
- name: "screen4x3",
4822
- width: 9144e3,
4823
- height: 6858e3
4824
- };
4825
- const layout16x9 = {
4826
- name: "screen16x9",
4827
- width: 9144e3,
4828
- height: 5143500
4829
- };
4830
- const layout16x10 = {
4831
- name: "screen16x10",
4832
- width: 9144e3,
4833
- height: 5715e3
4834
- };
4835
- const layoutWide = {
4836
- name: "custom",
4837
- width: 12192e3,
4838
- height: 6858e3
4839
- };
4840
4882
  this.LAYOUTS = {
4841
- LAYOUT_4x3: layout4x3,
4842
- LAYOUT_16x9: layout16x9,
4843
- LAYOUT_16x10: layout16x10,
4844
- LAYOUT_WIDE: layoutWide
4883
+ LAYOUT_4x3: standardLayoutToPresLayout(STANDARD_LAYOUTS.LAYOUT_4x3),
4884
+ LAYOUT_16x9: standardLayoutToPresLayout(STANDARD_LAYOUTS.LAYOUT_16x9),
4885
+ LAYOUT_16x10: standardLayoutToPresLayout(STANDARD_LAYOUTS.LAYOUT_16x10),
4886
+ LAYOUT_WIDE: standardLayoutToPresLayout(STANDARD_LAYOUTS.LAYOUT_WIDE)
4845
4887
  };
4846
4888
  this._author = "PptxGenJS";
4847
4889
  this._company = "PptxGenJS";
@@ -5132,10 +5174,10 @@ var PptxGenJS = class {
5132
5174
  else if (typeof layout.width !== "number") console.warn("defineLayout `width` should be a number (inches)");
5133
5175
  this.LAYOUTS[layout.name] = {
5134
5176
  name: layout.name,
5135
- _sizeW: Math.round(Number(layout.width) * EMU),
5136
- _sizeH: Math.round(Number(layout.height) * EMU),
5137
- width: Math.round(Number(layout.width) * EMU),
5138
- height: Math.round(Number(layout.height) * EMU)
5177
+ _sizeW: inchesToEmu(Number(layout.width)),
5178
+ _sizeH: inchesToEmu(Number(layout.height)),
5179
+ width: inchesToEmu(Number(layout.width)),
5180
+ height: inchesToEmu(Number(layout.height))
5139
5181
  };
5140
5182
  }
5141
5183
  /**
@@ -5176,4 +5218,4 @@ var PptxGenJS = class {
5176
5218
  //#endregion
5177
5219
  export { PptxGenJS as t };
5178
5220
 
5179
- //# sourceMappingURL=pptxgen-D4hSJlcN.js.map
5221
+ //# sourceMappingURL=pptxgen-1VITjpGE.js.map