pptx-glimpse 0.6.0 → 0.6.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.
Files changed (3) hide show
  1. package/dist/index.cjs +127 -32
  2. package/dist/index.js +127 -32
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -3017,7 +3017,7 @@ function navigateOrdered(ordered, path) {
3017
3017
  }
3018
3018
  return current;
3019
3019
  }
3020
- function parseSlide(slideXml, slidePath, slideNumber, archive, colorResolver, fontScheme, fmtScheme) {
3020
+ function parseSlide(slideXml, slidePath, slideNumber, archive, colorResolver, fontScheme, fmtScheme, placeholderStyles) {
3021
3021
  const parsed = parseXml(slideXml);
3022
3022
  const sld = parsed.sld;
3023
3023
  if (!sld) {
@@ -3041,7 +3041,8 @@ function parseSlide(slideXml, slidePath, slideNumber, archive, colorResolver, fo
3041
3041
  fillContext,
3042
3042
  fontScheme,
3043
3043
  orderedSpTree,
3044
- fmtScheme
3044
+ fmtScheme,
3045
+ placeholderStyles
3045
3046
  );
3046
3047
  const showMasterSpAttr = sld?.["@_showMasterSp"];
3047
3048
  const showMasterSp = showMasterSpAttr !== "0" && showMasterSpAttr !== "false";
@@ -3068,7 +3069,7 @@ function mergeChildElements(spTree, source) {
3068
3069
  }
3069
3070
  }
3070
3071
  }
3071
- function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, orderedChildren, fmtScheme) {
3072
+ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, orderedChildren, fmtScheme, placeholderStyles) {
3072
3073
  if (!spTree) return [];
3073
3074
  if (orderedChildren) {
3074
3075
  return parseShapeTreeOrdered(
@@ -3081,7 +3082,8 @@ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context
3081
3082
  context,
3082
3083
  fillContext,
3083
3084
  fontScheme,
3084
- fmtScheme
3085
+ fmtScheme,
3086
+ placeholderStyles
3085
3087
  );
3086
3088
  }
3087
3089
  const alternateContents = spTree.AlternateContent ?? [];
@@ -3102,7 +3104,8 @@ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context
3102
3104
  fillContext,
3103
3105
  fontScheme,
3104
3106
  void 0,
3105
- fmtScheme
3107
+ fmtScheme,
3108
+ placeholderStyles
3106
3109
  );
3107
3110
  if (shape) {
3108
3111
  elements.push(shape);
@@ -3158,7 +3161,7 @@ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context
3158
3161
  }
3159
3162
  return elements;
3160
3163
  }
3161
- function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, fmtScheme) {
3164
+ function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, fmtScheme, placeholderStyles) {
3162
3165
  const ctx = context ?? slidePath;
3163
3166
  const elements = [];
3164
3167
  const tagCounters = {};
@@ -3200,7 +3203,8 @@ function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive
3200
3203
  ctx,
3201
3204
  fillContext,
3202
3205
  fontScheme,
3203
- fmtScheme
3206
+ fmtScheme,
3207
+ placeholderStyles
3204
3208
  );
3205
3209
  }
3206
3210
  }
@@ -3224,12 +3228,13 @@ function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive
3224
3228
  ctx,
3225
3229
  fillContext,
3226
3230
  fontScheme,
3227
- fmtScheme
3231
+ fmtScheme,
3232
+ placeholderStyles
3228
3233
  );
3229
3234
  }
3230
3235
  return elements;
3231
3236
  }
3232
- function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePath, archive, colorResolver, ctx, fillContext, fontScheme, fmtScheme) {
3237
+ function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePath, archive, colorResolver, ctx, fillContext, fontScheme, fmtScheme, placeholderStyles) {
3233
3238
  switch (tag) {
3234
3239
  case "sp": {
3235
3240
  const shape = parseShape(
@@ -3239,7 +3244,8 @@ function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePat
3239
3244
  fillContext,
3240
3245
  fontScheme,
3241
3246
  orderedNode,
3242
- fmtScheme
3247
+ fmtScheme,
3248
+ placeholderStyles
3243
3249
  );
3244
3250
  if (shape) {
3245
3251
  elements.push(shape);
@@ -3304,22 +3310,42 @@ function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePat
3304
3310
  }
3305
3311
  }
3306
3312
  }
3307
- function parseShape(sp, colorResolver, rels, fillContext, fontScheme, orderedNode, fmtScheme) {
3313
+ function parseShape(sp, colorResolver, rels, fillContext, fontScheme, orderedNode, fmtScheme, placeholderStyles) {
3308
3314
  const spPr = sp.spPr;
3309
- if (!spPr) return null;
3310
- const transform = parseTransform(spPr.xfrm);
3315
+ const spPrIsObject = spPr != null && typeof spPr === "object";
3316
+ const nvSpPr = sp.nvSpPr;
3317
+ const nvPr = nvSpPr?.nvPr;
3318
+ const ph = nvPr?.ph;
3319
+ const placeholderType = ph ? ph["@_type"] ?? "body" : void 0;
3320
+ const placeholderIdx = ph?.["@_idx"] !== void 0 ? Number(ph["@_idx"]) : void 0;
3321
+ let transform = null;
3322
+ let geometry;
3323
+ if (spPrIsObject) {
3324
+ transform = parseTransform(spPr.xfrm);
3325
+ geometry = parseGeometry(spPr);
3326
+ } else {
3327
+ geometry = { type: "preset", preset: "rect", adjustValues: {} };
3328
+ }
3329
+ if (!transform && placeholderType && placeholderStyles) {
3330
+ const inherited = findMatchingPlaceholder(placeholderType, placeholderIdx, placeholderStyles);
3331
+ if (inherited?.transform) {
3332
+ transform = inherited.transform;
3333
+ }
3334
+ if (!spPrIsObject && inherited?.geometry) {
3335
+ geometry = inherited.geometry;
3336
+ }
3337
+ }
3311
3338
  if (!transform) return null;
3312
- if (spPr.scene3d) {
3339
+ if (spPrIsObject && spPr.scene3d) {
3313
3340
  warn("spPr.scene3d", "3D scene/camera not implemented");
3314
3341
  }
3315
- if (spPr.sp3d) {
3342
+ if (spPrIsObject && spPr.sp3d) {
3316
3343
  warn("spPr.sp3d", "3D extrusion/bevel not implemented");
3317
3344
  }
3318
- const geometry = parseGeometry(spPr);
3319
3345
  const styleRef = resolveShapeStyle(sp.style, fmtScheme, colorResolver);
3320
- const directFill = parseFillFromNode(spPr, colorResolver, fillContext);
3346
+ const directFill = spPrIsObject ? parseFillFromNode(spPr, colorResolver, fillContext) : null;
3321
3347
  const fill = directFill ?? styleRef?.fill ?? null;
3322
- const directOutline = parseOutline(spPr.ln, colorResolver);
3348
+ const directOutline = spPrIsObject ? parseOutline(spPr.ln, colorResolver) : null;
3323
3349
  const outline = directOutline ?? styleRef?.outline ?? null;
3324
3350
  let orderedTxBody;
3325
3351
  if (orderedNode) {
@@ -3337,16 +3363,11 @@ function parseShape(sp, colorResolver, rels, fillContext, fontScheme, orderedNod
3337
3363
  void 0,
3338
3364
  orderedTxBody
3339
3365
  );
3340
- const directEffects = parseEffectList(spPr.effectLst, colorResolver);
3366
+ const directEffects = spPrIsObject ? parseEffectList(spPr.effectLst, colorResolver) : null;
3341
3367
  const effects = directEffects ?? styleRef?.effects ?? null;
3342
- const nvSpPr = sp.nvSpPr;
3343
3368
  const cNvPr = nvSpPr?.cNvPr;
3344
3369
  const altText = cNvPr?.["@_descr"];
3345
3370
  const hyperlink = parseHyperlink(cNvPr?.hlinkClick, rels);
3346
- const nvPr = nvSpPr?.nvPr;
3347
- const ph = nvPr?.ph;
3348
- const placeholderType = ph ? ph["@_type"] ?? "body" : void 0;
3349
- const placeholderIdx = ph?.["@_idx"] !== void 0 ? Number(ph["@_idx"]) : void 0;
3350
3371
  return {
3351
3372
  type: "shape",
3352
3373
  transform,
@@ -3700,6 +3721,31 @@ function parseGeometry(spPr) {
3700
3721
  }
3701
3722
  return { type: "preset", preset: "rect", adjustValues: {} };
3702
3723
  }
3724
+ function findMatchingPlaceholder(placeholderType, placeholderIdx, styles) {
3725
+ if (placeholderIdx !== void 0) {
3726
+ const byIdx = styles.find((s) => s.placeholderIdx === placeholderIdx && s.transform);
3727
+ if (byIdx) return byIdx;
3728
+ const byIdxAny = styles.find((s) => s.placeholderIdx === placeholderIdx);
3729
+ if (byIdxAny) return byIdxAny;
3730
+ }
3731
+ const byTypeWithTransform = styles.find(
3732
+ (s) => s.placeholderType === placeholderType && s.transform
3733
+ );
3734
+ if (byTypeWithTransform) return byTypeWithTransform;
3735
+ const fallbackType = placeholderType === "ctrTitle" ? "title" : placeholderType === "subTitle" ? "body" : void 0;
3736
+ if (fallbackType) {
3737
+ const byFallbackWithTransform = styles.find(
3738
+ (s) => s.placeholderType === fallbackType && s.transform
3739
+ );
3740
+ if (byFallbackWithTransform) return byFallbackWithTransform;
3741
+ }
3742
+ const byType = styles.find((s) => s.placeholderType === placeholderType);
3743
+ if (byType) return byType;
3744
+ if (fallbackType) {
3745
+ return styles.find((s) => s.placeholderType === fallbackType);
3746
+ }
3747
+ return void 0;
3748
+ }
3703
3749
  function parseTextBody(txBody, colorResolver, rels, fontScheme, lstStyleOverride, orderedTxBody) {
3704
3750
  if (!txBody) return null;
3705
3751
  const bodyPr = txBody.bodyPr;
@@ -4129,10 +4175,15 @@ function parseSlideLayoutPlaceholderStyles(xml, colorResolver) {
4129
4175
  const txBody = sp.txBody;
4130
4176
  const lstStyleNode = txBody?.lstStyle;
4131
4177
  const lstStyle = lstStyleNode ? parseListStyle(lstStyleNode, colorResolver) : void 0;
4178
+ const spPr = sp.spPr;
4179
+ const transform = spPr && typeof spPr === "object" ? parseTransform(spPr.xfrm) : null;
4180
+ const geometry = spPr && typeof spPr === "object" ? parseGeometry(spPr) : void 0;
4132
4181
  results.push({
4133
4182
  placeholderType,
4134
4183
  ...placeholderIdx !== void 0 && { placeholderIdx },
4135
- ...lstStyle && { lstStyle }
4184
+ ...lstStyle && { lstStyle },
4185
+ ...transform && { transform },
4186
+ ...geometry && { geometry }
4136
4187
  });
4137
4188
  }
4138
4189
  return results;
@@ -4249,10 +4300,15 @@ function parseSlideMasterPlaceholderStyles(xml, colorResolver) {
4249
4300
  const txBody = sp.txBody;
4250
4301
  const lstStyleNode = txBody?.lstStyle;
4251
4302
  const lstStyle = lstStyleNode ? parseListStyle(lstStyleNode, colorResolver) : void 0;
4303
+ const spPr = sp.spPr;
4304
+ const transform = spPr && typeof spPr === "object" ? parseTransform(spPr.xfrm) : null;
4305
+ const geometry = spPr && typeof spPr === "object" ? parseGeometry(spPr) : void 0;
4252
4306
  results.push({
4253
4307
  placeholderType,
4254
4308
  ...placeholderIdx !== void 0 && { placeholderIdx },
4255
- ...lstStyle && { lstStyle }
4309
+ ...lstStyle && { lstStyle },
4310
+ ...transform && { transform },
4311
+ ...geometry && { geometry }
4256
4312
  });
4257
4313
  }
4258
4314
  return results;
@@ -4703,6 +4759,17 @@ function parseSlideWithLayout(slideNumber, path, data) {
4703
4759
  slideMasterData,
4704
4760
  data.theme
4705
4761
  );
4762
+ let layoutPlaceholderStyles = [];
4763
+ let layoutShowMasterSp = true;
4764
+ if (layoutXml) {
4765
+ layoutPlaceholderStyles = parseSlideLayoutPlaceholderStyles(layoutXml, slideColorResolver);
4766
+ layoutShowMasterSp = parseSlideLayoutShowMasterSp(layoutXml);
4767
+ }
4768
+ const masterPlaceholderStyles = slideMasterData?.placeholderStyles ?? data.masterPlaceholderStyles;
4769
+ const mergedPlaceholderStyles = mergePlaceholderGeometry(
4770
+ layoutPlaceholderStyles,
4771
+ masterPlaceholderStyles
4772
+ );
4706
4773
  const slide = parseSlide(
4707
4774
  slideXml,
4708
4775
  path,
@@ -4710,11 +4777,10 @@ function parseSlideWithLayout(slideNumber, path, data) {
4710
4777
  data.archive,
4711
4778
  slideColorResolver,
4712
4779
  data.theme.fontScheme,
4713
- data.theme.fmtScheme
4780
+ data.theme.fmtScheme,
4781
+ mergedPlaceholderStyles
4714
4782
  );
4715
4783
  let layoutElements = [];
4716
- let layoutPlaceholderStyles = [];
4717
- let layoutShowMasterSp = true;
4718
4784
  if (layoutXml && layoutPath) {
4719
4785
  if (!slide.background) {
4720
4786
  const layoutFillContext = {
@@ -4736,13 +4802,10 @@ function parseSlideWithLayout(slideNumber, path, data) {
4736
4802
  data.theme.fontScheme,
4737
4803
  data.theme.fmtScheme
4738
4804
  );
4739
- layoutPlaceholderStyles = parseSlideLayoutPlaceholderStyles(layoutXml, slideColorResolver);
4740
- layoutShowMasterSp = parseSlideLayoutShowMasterSp(layoutXml);
4741
4805
  }
4742
4806
  if (!slide.background) {
4743
4807
  slide.background = slideMasterData?.background ?? data.masterBackground;
4744
4808
  }
4745
- const masterPlaceholderStyles = slideMasterData?.placeholderStyles ?? data.masterPlaceholderStyles;
4746
4809
  const masterTxStyles = slideMasterData?.txStyles ?? data.masterTxStyles;
4747
4810
  applyTextStyleInheritance(slide.elements, {
4748
4811
  layoutPlaceholderStyles,
@@ -4754,6 +4817,38 @@ function parseSlideWithLayout(slideNumber, path, data) {
4754
4817
  const masterElements = slideMasterData?.elements ?? data.masterElements;
4755
4818
  return { slide, layoutElements, layoutShowMasterSp, masterElements };
4756
4819
  }
4820
+ function mergePlaceholderGeometry(layoutStyles, masterStyles) {
4821
+ const merged = layoutStyles.map((ls) => {
4822
+ if (ls.transform) return ls;
4823
+ const masterMatch = findPlaceholderByTypeAndIdx(
4824
+ ls.placeholderType,
4825
+ ls.placeholderIdx,
4826
+ masterStyles
4827
+ );
4828
+ if (!masterMatch) return ls;
4829
+ return {
4830
+ ...ls,
4831
+ ...!ls.transform && masterMatch.transform && { transform: masterMatch.transform },
4832
+ ...!ls.geometry && masterMatch.geometry && { geometry: masterMatch.geometry }
4833
+ };
4834
+ });
4835
+ for (const ms of masterStyles) {
4836
+ const exists = merged.some(
4837
+ (m) => m.placeholderType === ms.placeholderType && m.placeholderIdx === ms.placeholderIdx
4838
+ );
4839
+ if (!exists) {
4840
+ merged.push(ms);
4841
+ }
4842
+ }
4843
+ return merged;
4844
+ }
4845
+ function findPlaceholderByTypeAndIdx(type, idx, styles) {
4846
+ if (idx !== void 0) {
4847
+ const byIdx = styles.find((s) => s.placeholderIdx === idx);
4848
+ if (byIdx) return byIdx;
4849
+ }
4850
+ return styles.find((s) => s.placeholderType === type);
4851
+ }
4757
4852
  function defaultColorScheme2() {
4758
4853
  return {
4759
4854
  dk1: "#000000",
package/dist/index.js CHANGED
@@ -2982,7 +2982,7 @@ function navigateOrdered(ordered, path) {
2982
2982
  }
2983
2983
  return current;
2984
2984
  }
2985
- function parseSlide(slideXml, slidePath, slideNumber, archive, colorResolver, fontScheme, fmtScheme) {
2985
+ function parseSlide(slideXml, slidePath, slideNumber, archive, colorResolver, fontScheme, fmtScheme, placeholderStyles) {
2986
2986
  const parsed = parseXml(slideXml);
2987
2987
  const sld = parsed.sld;
2988
2988
  if (!sld) {
@@ -3006,7 +3006,8 @@ function parseSlide(slideXml, slidePath, slideNumber, archive, colorResolver, fo
3006
3006
  fillContext,
3007
3007
  fontScheme,
3008
3008
  orderedSpTree,
3009
- fmtScheme
3009
+ fmtScheme,
3010
+ placeholderStyles
3010
3011
  );
3011
3012
  const showMasterSpAttr = sld?.["@_showMasterSp"];
3012
3013
  const showMasterSp = showMasterSpAttr !== "0" && showMasterSpAttr !== "false";
@@ -3033,7 +3034,7 @@ function mergeChildElements(spTree, source) {
3033
3034
  }
3034
3035
  }
3035
3036
  }
3036
- function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, orderedChildren, fmtScheme) {
3037
+ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, orderedChildren, fmtScheme, placeholderStyles) {
3037
3038
  if (!spTree) return [];
3038
3039
  if (orderedChildren) {
3039
3040
  return parseShapeTreeOrdered(
@@ -3046,7 +3047,8 @@ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context
3046
3047
  context,
3047
3048
  fillContext,
3048
3049
  fontScheme,
3049
- fmtScheme
3050
+ fmtScheme,
3051
+ placeholderStyles
3050
3052
  );
3051
3053
  }
3052
3054
  const alternateContents = spTree.AlternateContent ?? [];
@@ -3067,7 +3069,8 @@ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context
3067
3069
  fillContext,
3068
3070
  fontScheme,
3069
3071
  void 0,
3070
- fmtScheme
3072
+ fmtScheme,
3073
+ placeholderStyles
3071
3074
  );
3072
3075
  if (shape) {
3073
3076
  elements.push(shape);
@@ -3123,7 +3126,7 @@ function parseShapeTree(spTree, rels, slidePath, archive, colorResolver, context
3123
3126
  }
3124
3127
  return elements;
3125
3128
  }
3126
- function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, fmtScheme) {
3129
+ function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive, colorResolver, context, fillContext, fontScheme, fmtScheme, placeholderStyles) {
3127
3130
  const ctx = context ?? slidePath;
3128
3131
  const elements = [];
3129
3132
  const tagCounters = {};
@@ -3165,7 +3168,8 @@ function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive
3165
3168
  ctx,
3166
3169
  fillContext,
3167
3170
  fontScheme,
3168
- fmtScheme
3171
+ fmtScheme,
3172
+ placeholderStyles
3169
3173
  );
3170
3174
  }
3171
3175
  }
@@ -3189,12 +3193,13 @@ function parseShapeTreeOrdered(spTree, orderedChildren, rels, slidePath, archive
3189
3193
  ctx,
3190
3194
  fillContext,
3191
3195
  fontScheme,
3192
- fmtScheme
3196
+ fmtScheme,
3197
+ placeholderStyles
3193
3198
  );
3194
3199
  }
3195
3200
  return elements;
3196
3201
  }
3197
- function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePath, archive, colorResolver, ctx, fillContext, fontScheme, fmtScheme) {
3202
+ function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePath, archive, colorResolver, ctx, fillContext, fontScheme, fmtScheme, placeholderStyles) {
3198
3203
  switch (tag) {
3199
3204
  case "sp": {
3200
3205
  const shape = parseShape(
@@ -3204,7 +3209,8 @@ function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePat
3204
3209
  fillContext,
3205
3210
  fontScheme,
3206
3211
  orderedNode,
3207
- fmtScheme
3212
+ fmtScheme,
3213
+ placeholderStyles
3208
3214
  );
3209
3215
  if (shape) {
3210
3216
  elements.push(shape);
@@ -3269,22 +3275,42 @@ function parseAndPushElement(tag, element, orderedNode, elements, rels, slidePat
3269
3275
  }
3270
3276
  }
3271
3277
  }
3272
- function parseShape(sp, colorResolver, rels, fillContext, fontScheme, orderedNode, fmtScheme) {
3278
+ function parseShape(sp, colorResolver, rels, fillContext, fontScheme, orderedNode, fmtScheme, placeholderStyles) {
3273
3279
  const spPr = sp.spPr;
3274
- if (!spPr) return null;
3275
- const transform = parseTransform(spPr.xfrm);
3280
+ const spPrIsObject = spPr != null && typeof spPr === "object";
3281
+ const nvSpPr = sp.nvSpPr;
3282
+ const nvPr = nvSpPr?.nvPr;
3283
+ const ph = nvPr?.ph;
3284
+ const placeholderType = ph ? ph["@_type"] ?? "body" : void 0;
3285
+ const placeholderIdx = ph?.["@_idx"] !== void 0 ? Number(ph["@_idx"]) : void 0;
3286
+ let transform = null;
3287
+ let geometry;
3288
+ if (spPrIsObject) {
3289
+ transform = parseTransform(spPr.xfrm);
3290
+ geometry = parseGeometry(spPr);
3291
+ } else {
3292
+ geometry = { type: "preset", preset: "rect", adjustValues: {} };
3293
+ }
3294
+ if (!transform && placeholderType && placeholderStyles) {
3295
+ const inherited = findMatchingPlaceholder(placeholderType, placeholderIdx, placeholderStyles);
3296
+ if (inherited?.transform) {
3297
+ transform = inherited.transform;
3298
+ }
3299
+ if (!spPrIsObject && inherited?.geometry) {
3300
+ geometry = inherited.geometry;
3301
+ }
3302
+ }
3276
3303
  if (!transform) return null;
3277
- if (spPr.scene3d) {
3304
+ if (spPrIsObject && spPr.scene3d) {
3278
3305
  warn("spPr.scene3d", "3D scene/camera not implemented");
3279
3306
  }
3280
- if (spPr.sp3d) {
3307
+ if (spPrIsObject && spPr.sp3d) {
3281
3308
  warn("spPr.sp3d", "3D extrusion/bevel not implemented");
3282
3309
  }
3283
- const geometry = parseGeometry(spPr);
3284
3310
  const styleRef = resolveShapeStyle(sp.style, fmtScheme, colorResolver);
3285
- const directFill = parseFillFromNode(spPr, colorResolver, fillContext);
3311
+ const directFill = spPrIsObject ? parseFillFromNode(spPr, colorResolver, fillContext) : null;
3286
3312
  const fill = directFill ?? styleRef?.fill ?? null;
3287
- const directOutline = parseOutline(spPr.ln, colorResolver);
3313
+ const directOutline = spPrIsObject ? parseOutline(spPr.ln, colorResolver) : null;
3288
3314
  const outline = directOutline ?? styleRef?.outline ?? null;
3289
3315
  let orderedTxBody;
3290
3316
  if (orderedNode) {
@@ -3302,16 +3328,11 @@ function parseShape(sp, colorResolver, rels, fillContext, fontScheme, orderedNod
3302
3328
  void 0,
3303
3329
  orderedTxBody
3304
3330
  );
3305
- const directEffects = parseEffectList(spPr.effectLst, colorResolver);
3331
+ const directEffects = spPrIsObject ? parseEffectList(spPr.effectLst, colorResolver) : null;
3306
3332
  const effects = directEffects ?? styleRef?.effects ?? null;
3307
- const nvSpPr = sp.nvSpPr;
3308
3333
  const cNvPr = nvSpPr?.cNvPr;
3309
3334
  const altText = cNvPr?.["@_descr"];
3310
3335
  const hyperlink = parseHyperlink(cNvPr?.hlinkClick, rels);
3311
- const nvPr = nvSpPr?.nvPr;
3312
- const ph = nvPr?.ph;
3313
- const placeholderType = ph ? ph["@_type"] ?? "body" : void 0;
3314
- const placeholderIdx = ph?.["@_idx"] !== void 0 ? Number(ph["@_idx"]) : void 0;
3315
3336
  return {
3316
3337
  type: "shape",
3317
3338
  transform,
@@ -3665,6 +3686,31 @@ function parseGeometry(spPr) {
3665
3686
  }
3666
3687
  return { type: "preset", preset: "rect", adjustValues: {} };
3667
3688
  }
3689
+ function findMatchingPlaceholder(placeholderType, placeholderIdx, styles) {
3690
+ if (placeholderIdx !== void 0) {
3691
+ const byIdx = styles.find((s) => s.placeholderIdx === placeholderIdx && s.transform);
3692
+ if (byIdx) return byIdx;
3693
+ const byIdxAny = styles.find((s) => s.placeholderIdx === placeholderIdx);
3694
+ if (byIdxAny) return byIdxAny;
3695
+ }
3696
+ const byTypeWithTransform = styles.find(
3697
+ (s) => s.placeholderType === placeholderType && s.transform
3698
+ );
3699
+ if (byTypeWithTransform) return byTypeWithTransform;
3700
+ const fallbackType = placeholderType === "ctrTitle" ? "title" : placeholderType === "subTitle" ? "body" : void 0;
3701
+ if (fallbackType) {
3702
+ const byFallbackWithTransform = styles.find(
3703
+ (s) => s.placeholderType === fallbackType && s.transform
3704
+ );
3705
+ if (byFallbackWithTransform) return byFallbackWithTransform;
3706
+ }
3707
+ const byType = styles.find((s) => s.placeholderType === placeholderType);
3708
+ if (byType) return byType;
3709
+ if (fallbackType) {
3710
+ return styles.find((s) => s.placeholderType === fallbackType);
3711
+ }
3712
+ return void 0;
3713
+ }
3668
3714
  function parseTextBody(txBody, colorResolver, rels, fontScheme, lstStyleOverride, orderedTxBody) {
3669
3715
  if (!txBody) return null;
3670
3716
  const bodyPr = txBody.bodyPr;
@@ -4094,10 +4140,15 @@ function parseSlideLayoutPlaceholderStyles(xml, colorResolver) {
4094
4140
  const txBody = sp.txBody;
4095
4141
  const lstStyleNode = txBody?.lstStyle;
4096
4142
  const lstStyle = lstStyleNode ? parseListStyle(lstStyleNode, colorResolver) : void 0;
4143
+ const spPr = sp.spPr;
4144
+ const transform = spPr && typeof spPr === "object" ? parseTransform(spPr.xfrm) : null;
4145
+ const geometry = spPr && typeof spPr === "object" ? parseGeometry(spPr) : void 0;
4097
4146
  results.push({
4098
4147
  placeholderType,
4099
4148
  ...placeholderIdx !== void 0 && { placeholderIdx },
4100
- ...lstStyle && { lstStyle }
4149
+ ...lstStyle && { lstStyle },
4150
+ ...transform && { transform },
4151
+ ...geometry && { geometry }
4101
4152
  });
4102
4153
  }
4103
4154
  return results;
@@ -4214,10 +4265,15 @@ function parseSlideMasterPlaceholderStyles(xml, colorResolver) {
4214
4265
  const txBody = sp.txBody;
4215
4266
  const lstStyleNode = txBody?.lstStyle;
4216
4267
  const lstStyle = lstStyleNode ? parseListStyle(lstStyleNode, colorResolver) : void 0;
4268
+ const spPr = sp.spPr;
4269
+ const transform = spPr && typeof spPr === "object" ? parseTransform(spPr.xfrm) : null;
4270
+ const geometry = spPr && typeof spPr === "object" ? parseGeometry(spPr) : void 0;
4217
4271
  results.push({
4218
4272
  placeholderType,
4219
4273
  ...placeholderIdx !== void 0 && { placeholderIdx },
4220
- ...lstStyle && { lstStyle }
4274
+ ...lstStyle && { lstStyle },
4275
+ ...transform && { transform },
4276
+ ...geometry && { geometry }
4221
4277
  });
4222
4278
  }
4223
4279
  return results;
@@ -4668,6 +4724,17 @@ function parseSlideWithLayout(slideNumber, path, data) {
4668
4724
  slideMasterData,
4669
4725
  data.theme
4670
4726
  );
4727
+ let layoutPlaceholderStyles = [];
4728
+ let layoutShowMasterSp = true;
4729
+ if (layoutXml) {
4730
+ layoutPlaceholderStyles = parseSlideLayoutPlaceholderStyles(layoutXml, slideColorResolver);
4731
+ layoutShowMasterSp = parseSlideLayoutShowMasterSp(layoutXml);
4732
+ }
4733
+ const masterPlaceholderStyles = slideMasterData?.placeholderStyles ?? data.masterPlaceholderStyles;
4734
+ const mergedPlaceholderStyles = mergePlaceholderGeometry(
4735
+ layoutPlaceholderStyles,
4736
+ masterPlaceholderStyles
4737
+ );
4671
4738
  const slide = parseSlide(
4672
4739
  slideXml,
4673
4740
  path,
@@ -4675,11 +4742,10 @@ function parseSlideWithLayout(slideNumber, path, data) {
4675
4742
  data.archive,
4676
4743
  slideColorResolver,
4677
4744
  data.theme.fontScheme,
4678
- data.theme.fmtScheme
4745
+ data.theme.fmtScheme,
4746
+ mergedPlaceholderStyles
4679
4747
  );
4680
4748
  let layoutElements = [];
4681
- let layoutPlaceholderStyles = [];
4682
- let layoutShowMasterSp = true;
4683
4749
  if (layoutXml && layoutPath) {
4684
4750
  if (!slide.background) {
4685
4751
  const layoutFillContext = {
@@ -4701,13 +4767,10 @@ function parseSlideWithLayout(slideNumber, path, data) {
4701
4767
  data.theme.fontScheme,
4702
4768
  data.theme.fmtScheme
4703
4769
  );
4704
- layoutPlaceholderStyles = parseSlideLayoutPlaceholderStyles(layoutXml, slideColorResolver);
4705
- layoutShowMasterSp = parseSlideLayoutShowMasterSp(layoutXml);
4706
4770
  }
4707
4771
  if (!slide.background) {
4708
4772
  slide.background = slideMasterData?.background ?? data.masterBackground;
4709
4773
  }
4710
- const masterPlaceholderStyles = slideMasterData?.placeholderStyles ?? data.masterPlaceholderStyles;
4711
4774
  const masterTxStyles = slideMasterData?.txStyles ?? data.masterTxStyles;
4712
4775
  applyTextStyleInheritance(slide.elements, {
4713
4776
  layoutPlaceholderStyles,
@@ -4719,6 +4782,38 @@ function parseSlideWithLayout(slideNumber, path, data) {
4719
4782
  const masterElements = slideMasterData?.elements ?? data.masterElements;
4720
4783
  return { slide, layoutElements, layoutShowMasterSp, masterElements };
4721
4784
  }
4785
+ function mergePlaceholderGeometry(layoutStyles, masterStyles) {
4786
+ const merged = layoutStyles.map((ls) => {
4787
+ if (ls.transform) return ls;
4788
+ const masterMatch = findPlaceholderByTypeAndIdx(
4789
+ ls.placeholderType,
4790
+ ls.placeholderIdx,
4791
+ masterStyles
4792
+ );
4793
+ if (!masterMatch) return ls;
4794
+ return {
4795
+ ...ls,
4796
+ ...!ls.transform && masterMatch.transform && { transform: masterMatch.transform },
4797
+ ...!ls.geometry && masterMatch.geometry && { geometry: masterMatch.geometry }
4798
+ };
4799
+ });
4800
+ for (const ms of masterStyles) {
4801
+ const exists = merged.some(
4802
+ (m) => m.placeholderType === ms.placeholderType && m.placeholderIdx === ms.placeholderIdx
4803
+ );
4804
+ if (!exists) {
4805
+ merged.push(ms);
4806
+ }
4807
+ }
4808
+ return merged;
4809
+ }
4810
+ function findPlaceholderByTypeAndIdx(type, idx, styles) {
4811
+ if (idx !== void 0) {
4812
+ const byIdx = styles.find((s) => s.placeholderIdx === idx);
4813
+ if (byIdx) return byIdx;
4814
+ }
4815
+ return styles.find((s) => s.placeholderType === type);
4816
+ }
4722
4817
  function defaultColorScheme2() {
4723
4818
  return {
4724
4819
  dk1: "#000000",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptx-glimpse",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "A lightweight JavaScript library for rendering PowerPoint (.pptx) files as SVG or PNG in Node.js. No LibreOffice required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",