pptx-viewer-core 1.1.36 → 1.1.38

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/cli/index.js CHANGED
Binary file
Binary file
package/dist/index.d.mts CHANGED
@@ -997,6 +997,14 @@ interface IPptxHandlerRuntime {
997
997
  * @returns Array of layout options belonging to the same slide master.
998
998
  */
999
999
  getAvailableLayoutsForSlide(slideIndex: number, slides: PptxSlide[]): Promise<PptxLayoutOption[]>;
1000
+ /**
1001
+ * Resolve the editable template (master + layout) elements a slide
1002
+ * inherits, each carrying a `master-` / `layout-` prefixed id. Excludes
1003
+ * placeholders; returns only decorative shapes/pictures/graphic frames.
1004
+ *
1005
+ * @param slideId - The slide's archive path (`PptxSlide.id`).
1006
+ */
1007
+ getTemplateElementsForSlide(slideId: string): Promise<PptxElement[]>;
1000
1008
  /**
1001
1009
  * Scan the loaded PPTX archive for all theme parts.
1002
1010
  */
@@ -6372,6 +6380,14 @@ declare class PptxHandlerRuntime$11 extends PptxHandlerRuntime$12 {
6372
6380
  declare class PptxHandlerRuntime$10 extends PptxHandlerRuntime$11 {
6373
6381
  protected textStylesEqual(left: TextStyle | undefined, right: TextStyle | undefined): boolean;
6374
6382
  protected hasMixedTextStyles(textSegments: TextSegment[]): boolean;
6383
+ /**
6384
+ * Whether a segment carries run-level content that the flat `el.text` string
6385
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
6386
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
6387
+ * to the plain-text path silently downgrades a field to static text (e.g. a
6388
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
6389
+ */
6390
+ protected isStructuralTextSegment(segment: TextSegment): boolean;
6375
6391
  protected areTextSegmentsUniform(textSegments: TextSegment[] | undefined): boolean;
6376
6392
  protected parseBooleanAttr(value: unknown): boolean;
6377
6393
  protected parseOptionalBooleanAttr(value: unknown): boolean | undefined;
@@ -8564,6 +8580,35 @@ declare class PptxHandlerRuntime$2 extends PptxHandlerRuntime$3 {
8564
8580
  * Find the master path for a slide by walking: slide -> layout -> master.
8565
8581
  */
8566
8582
  protected findMasterPathForSlide(slidePath: string): string | undefined;
8583
+ /**
8584
+ * Resolve the editable template (master + layout) elements a slide
8585
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
8586
+ *
8587
+ * This is the canonical entry point for an "edit template/master"
8588
+ * feature: it returns the same decorative master/layout shapes that the
8589
+ * loader already merges in front of slide-authored content (master shapes
8590
+ * behind, layout shapes on top), reusing the cached
8591
+ * {@link getLayoutElements} parse. Resolving a slide that has not been
8592
+ * loaded yet (no relationships cached) yields an empty array.
8593
+ *
8594
+ * Important scope notes for callers:
8595
+ * - Placeholder shapes (`<p:ph>`) are intentionally excluded; those are
8596
+ * resolved separately into each slide's own placeholders. Only
8597
+ * non-placeholder decorations (shapes, pictures, graphic frames) are
8598
+ * returned, which is exactly what the save writeback path supports.
8599
+ * - The returned elements are shared by every slide that inherits the
8600
+ * same layout/master. Editing one element and saving updates the shared
8601
+ * layout/master part, so the change is visible on all sibling slides.
8602
+ * - To persist an edit the binding must keep the mutated template element
8603
+ * inside the `slide.elements` array it passes to {@link save}; the save
8604
+ * writer reads template elements from `ctx.slide.elements` and writes
8605
+ * their shape XML back into the owning `p:spTree`.
8606
+ *
8607
+ * @param slideId - The slide's archive path (the `PptxSlide.id`, e.g.
8608
+ * `ppt/slides/slide1.xml`).
8609
+ * @returns Master + layout elements with prefixed ids (may be empty).
8610
+ */
8611
+ getTemplateElementsForSlide(slideId: string): Promise<PptxElement[]>;
8567
8612
  /**
8568
8613
  * Get layouts available for a specific slide, scoped to that slide's
8569
8614
  * master. If the slide's master cannot be determined, returns all
@@ -9032,6 +9077,37 @@ declare class PptxHandlerCore {
9032
9077
  * ```
9033
9078
  */
9034
9079
  getAvailableLayoutsForSlide(slideIndex: number, slides: PptxSlide[]): Promise<PptxLayoutOption[]>;
9080
+ /**
9081
+ * Resolve the editable template (master + layout) elements a slide
9082
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
9083
+ *
9084
+ * This is the foundation for an "edit template/master" feature. The
9085
+ * returned elements are the decorative master/layout shapes the loader
9086
+ * already merges behind slide-authored content (master shapes behind,
9087
+ * layout shapes on top); placeholders are excluded. The same elements are
9088
+ * shared by every slide inheriting the layout/master, so editing one and
9089
+ * saving updates the shared part.
9090
+ *
9091
+ * To persist an edit, keep the mutated template element inside the
9092
+ * `slide.elements` array passed to {@link save}; the save writer reads
9093
+ * template elements from there and writes their shape XML back into the
9094
+ * owning layout/master `p:spTree`.
9095
+ *
9096
+ * @param slideId - The slide's archive path (the `PptxSlide.id`).
9097
+ * @returns Master + layout elements with prefixed ids (may be empty).
9098
+ *
9099
+ * @example
9100
+ * ```ts
9101
+ * const templateEls = await handler.getTemplateElementsForSlide(slide.id);
9102
+ * const logo = templateEls.find((e) => e.id.startsWith("master-"));
9103
+ * if (logo) {
9104
+ * logo.x += 10;
9105
+ * slide.elements = [...slide.elements, logo];
9106
+ * await handler.save(data.slides);
9107
+ * }
9108
+ * ```
9109
+ */
9110
+ getTemplateElementsForSlide(slideId: string): Promise<PptxElement[]>;
9035
9111
  /**
9036
9112
  * Apply a different layout to an existing slide.
9037
9113
  *
package/dist/index.d.ts CHANGED
@@ -997,6 +997,14 @@ interface IPptxHandlerRuntime {
997
997
  * @returns Array of layout options belonging to the same slide master.
998
998
  */
999
999
  getAvailableLayoutsForSlide(slideIndex: number, slides: PptxSlide[]): Promise<PptxLayoutOption[]>;
1000
+ /**
1001
+ * Resolve the editable template (master + layout) elements a slide
1002
+ * inherits, each carrying a `master-` / `layout-` prefixed id. Excludes
1003
+ * placeholders; returns only decorative shapes/pictures/graphic frames.
1004
+ *
1005
+ * @param slideId - The slide's archive path (`PptxSlide.id`).
1006
+ */
1007
+ getTemplateElementsForSlide(slideId: string): Promise<PptxElement[]>;
1000
1008
  /**
1001
1009
  * Scan the loaded PPTX archive for all theme parts.
1002
1010
  */
@@ -6372,6 +6380,14 @@ declare class PptxHandlerRuntime$11 extends PptxHandlerRuntime$12 {
6372
6380
  declare class PptxHandlerRuntime$10 extends PptxHandlerRuntime$11 {
6373
6381
  protected textStylesEqual(left: TextStyle | undefined, right: TextStyle | undefined): boolean;
6374
6382
  protected hasMixedTextStyles(textSegments: TextSegment[]): boolean;
6383
+ /**
6384
+ * Whether a segment carries run-level content that the flat `el.text` string
6385
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
6386
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
6387
+ * to the plain-text path silently downgrades a field to static text (e.g. a
6388
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
6389
+ */
6390
+ protected isStructuralTextSegment(segment: TextSegment): boolean;
6375
6391
  protected areTextSegmentsUniform(textSegments: TextSegment[] | undefined): boolean;
6376
6392
  protected parseBooleanAttr(value: unknown): boolean;
6377
6393
  protected parseOptionalBooleanAttr(value: unknown): boolean | undefined;
@@ -8564,6 +8580,35 @@ declare class PptxHandlerRuntime$2 extends PptxHandlerRuntime$3 {
8564
8580
  * Find the master path for a slide by walking: slide -> layout -> master.
8565
8581
  */
8566
8582
  protected findMasterPathForSlide(slidePath: string): string | undefined;
8583
+ /**
8584
+ * Resolve the editable template (master + layout) elements a slide
8585
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
8586
+ *
8587
+ * This is the canonical entry point for an "edit template/master"
8588
+ * feature: it returns the same decorative master/layout shapes that the
8589
+ * loader already merges in front of slide-authored content (master shapes
8590
+ * behind, layout shapes on top), reusing the cached
8591
+ * {@link getLayoutElements} parse. Resolving a slide that has not been
8592
+ * loaded yet (no relationships cached) yields an empty array.
8593
+ *
8594
+ * Important scope notes for callers:
8595
+ * - Placeholder shapes (`<p:ph>`) are intentionally excluded; those are
8596
+ * resolved separately into each slide's own placeholders. Only
8597
+ * non-placeholder decorations (shapes, pictures, graphic frames) are
8598
+ * returned, which is exactly what the save writeback path supports.
8599
+ * - The returned elements are shared by every slide that inherits the
8600
+ * same layout/master. Editing one element and saving updates the shared
8601
+ * layout/master part, so the change is visible on all sibling slides.
8602
+ * - To persist an edit the binding must keep the mutated template element
8603
+ * inside the `slide.elements` array it passes to {@link save}; the save
8604
+ * writer reads template elements from `ctx.slide.elements` and writes
8605
+ * their shape XML back into the owning `p:spTree`.
8606
+ *
8607
+ * @param slideId - The slide's archive path (the `PptxSlide.id`, e.g.
8608
+ * `ppt/slides/slide1.xml`).
8609
+ * @returns Master + layout elements with prefixed ids (may be empty).
8610
+ */
8611
+ getTemplateElementsForSlide(slideId: string): Promise<PptxElement[]>;
8567
8612
  /**
8568
8613
  * Get layouts available for a specific slide, scoped to that slide's
8569
8614
  * master. If the slide's master cannot be determined, returns all
@@ -9032,6 +9077,37 @@ declare class PptxHandlerCore {
9032
9077
  * ```
9033
9078
  */
9034
9079
  getAvailableLayoutsForSlide(slideIndex: number, slides: PptxSlide[]): Promise<PptxLayoutOption[]>;
9080
+ /**
9081
+ * Resolve the editable template (master + layout) elements a slide
9082
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
9083
+ *
9084
+ * This is the foundation for an "edit template/master" feature. The
9085
+ * returned elements are the decorative master/layout shapes the loader
9086
+ * already merges behind slide-authored content (master shapes behind,
9087
+ * layout shapes on top); placeholders are excluded. The same elements are
9088
+ * shared by every slide inheriting the layout/master, so editing one and
9089
+ * saving updates the shared part.
9090
+ *
9091
+ * To persist an edit, keep the mutated template element inside the
9092
+ * `slide.elements` array passed to {@link save}; the save writer reads
9093
+ * template elements from there and writes their shape XML back into the
9094
+ * owning layout/master `p:spTree`.
9095
+ *
9096
+ * @param slideId - The slide's archive path (the `PptxSlide.id`).
9097
+ * @returns Master + layout elements with prefixed ids (may be empty).
9098
+ *
9099
+ * @example
9100
+ * ```ts
9101
+ * const templateEls = await handler.getTemplateElementsForSlide(slide.id);
9102
+ * const logo = templateEls.find((e) => e.id.startsWith("master-"));
9103
+ * if (logo) {
9104
+ * logo.x += 10;
9105
+ * slide.elements = [...slide.elements, logo];
9106
+ * await handler.save(data.slides);
9107
+ * }
9108
+ * ```
9109
+ */
9110
+ getTemplateElementsForSlide(slideId: string): Promise<PptxElement[]>;
9035
9111
  /**
9036
9112
  * Apply a different layout to an existing slide.
9037
9113
  *
package/dist/index.js CHANGED
@@ -30523,8 +30523,24 @@ var PptxHandlerRuntime17 = class extends PptxHandlerRuntime16 {
30523
30523
  (segment, index) => index > 0 && !this.textStylesEqual(segment.style, baseStyle)
30524
30524
  );
30525
30525
  }
30526
+ /**
30527
+ * Whether a segment carries run-level content that the flat `el.text` string
30528
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
30529
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
30530
+ * to the plain-text path silently downgrades a field to static text (e.g. a
30531
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
30532
+ */
30533
+ isStructuralTextSegment(segment) {
30534
+ return Boolean(segment.fieldType || segment.equationXml || segment.rubyText);
30535
+ }
30526
30536
  areTextSegmentsUniform(textSegments) {
30527
- if (!textSegments || textSegments.length <= 1) {
30537
+ if (!textSegments || textSegments.length === 0) {
30538
+ return true;
30539
+ }
30540
+ if (textSegments.some((segment) => this.isStructuralTextSegment(segment))) {
30541
+ return false;
30542
+ }
30543
+ if (textSegments.length === 1) {
30528
30544
  return true;
30529
30545
  }
30530
30546
  return !this.hasMixedTextStyles(textSegments);
@@ -46123,6 +46139,37 @@ var PptxHandlerRuntime79 = class extends PptxHandlerRuntime78 {
46123
46139
  }
46124
46140
  return this.findMasterPathForLayout(layoutPath);
46125
46141
  }
46142
+ /**
46143
+ * Resolve the editable template (master + layout) elements a slide
46144
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
46145
+ *
46146
+ * This is the canonical entry point for an "edit template/master"
46147
+ * feature: it returns the same decorative master/layout shapes that the
46148
+ * loader already merges in front of slide-authored content (master shapes
46149
+ * behind, layout shapes on top), reusing the cached
46150
+ * {@link getLayoutElements} parse. Resolving a slide that has not been
46151
+ * loaded yet (no relationships cached) yields an empty array.
46152
+ *
46153
+ * Important scope notes for callers:
46154
+ * - Placeholder shapes (`<p:ph>`) are intentionally excluded; those are
46155
+ * resolved separately into each slide's own placeholders. Only
46156
+ * non-placeholder decorations (shapes, pictures, graphic frames) are
46157
+ * returned, which is exactly what the save writeback path supports.
46158
+ * - The returned elements are shared by every slide that inherits the
46159
+ * same layout/master. Editing one element and saving updates the shared
46160
+ * layout/master part, so the change is visible on all sibling slides.
46161
+ * - To persist an edit the binding must keep the mutated template element
46162
+ * inside the `slide.elements` array it passes to {@link save}; the save
46163
+ * writer reads template elements from `ctx.slide.elements` and writes
46164
+ * their shape XML back into the owning `p:spTree`.
46165
+ *
46166
+ * @param slideId - The slide's archive path (the `PptxSlide.id`, e.g.
46167
+ * `ppt/slides/slide1.xml`).
46168
+ * @returns Master + layout elements with prefixed ids (may be empty).
46169
+ */
46170
+ async getTemplateElementsForSlide(slideId) {
46171
+ return this.getLayoutElements(slideId);
46172
+ }
46126
46173
  /**
46127
46174
  * Get layouts available for a specific slide, scoped to that slide's
46128
46175
  * master. If the slide's master cannot be determined, returns all
@@ -46795,6 +46842,39 @@ var PptxHandlerCore = class {
46795
46842
  async getAvailableLayoutsForSlide(slideIndex, slides) {
46796
46843
  return this.runtime.getAvailableLayoutsForSlide(slideIndex, slides);
46797
46844
  }
46845
+ /**
46846
+ * Resolve the editable template (master + layout) elements a slide
46847
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
46848
+ *
46849
+ * This is the foundation for an "edit template/master" feature. The
46850
+ * returned elements are the decorative master/layout shapes the loader
46851
+ * already merges behind slide-authored content (master shapes behind,
46852
+ * layout shapes on top); placeholders are excluded. The same elements are
46853
+ * shared by every slide inheriting the layout/master, so editing one and
46854
+ * saving updates the shared part.
46855
+ *
46856
+ * To persist an edit, keep the mutated template element inside the
46857
+ * `slide.elements` array passed to {@link save}; the save writer reads
46858
+ * template elements from there and writes their shape XML back into the
46859
+ * owning layout/master `p:spTree`.
46860
+ *
46861
+ * @param slideId - The slide's archive path (the `PptxSlide.id`).
46862
+ * @returns Master + layout elements with prefixed ids (may be empty).
46863
+ *
46864
+ * @example
46865
+ * ```ts
46866
+ * const templateEls = await handler.getTemplateElementsForSlide(slide.id);
46867
+ * const logo = templateEls.find((e) => e.id.startsWith("master-"));
46868
+ * if (logo) {
46869
+ * logo.x += 10;
46870
+ * slide.elements = [...slide.elements, logo];
46871
+ * await handler.save(data.slides);
46872
+ * }
46873
+ * ```
46874
+ */
46875
+ async getTemplateElementsForSlide(slideId) {
46876
+ return this.runtime.getTemplateElementsForSlide(slideId);
46877
+ }
46798
46878
  /**
46799
46879
  * Apply a different layout to an existing slide.
46800
46880
  *
package/dist/index.mjs CHANGED
@@ -30518,8 +30518,24 @@ var PptxHandlerRuntime17 = class extends PptxHandlerRuntime16 {
30518
30518
  (segment, index) => index > 0 && !this.textStylesEqual(segment.style, baseStyle)
30519
30519
  );
30520
30520
  }
30521
+ /**
30522
+ * Whether a segment carries run-level content that the flat `el.text` string
30523
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
30524
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
30525
+ * to the plain-text path silently downgrades a field to static text (e.g. a
30526
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
30527
+ */
30528
+ isStructuralTextSegment(segment) {
30529
+ return Boolean(segment.fieldType || segment.equationXml || segment.rubyText);
30530
+ }
30521
30531
  areTextSegmentsUniform(textSegments) {
30522
- if (!textSegments || textSegments.length <= 1) {
30532
+ if (!textSegments || textSegments.length === 0) {
30533
+ return true;
30534
+ }
30535
+ if (textSegments.some((segment) => this.isStructuralTextSegment(segment))) {
30536
+ return false;
30537
+ }
30538
+ if (textSegments.length === 1) {
30523
30539
  return true;
30524
30540
  }
30525
30541
  return !this.hasMixedTextStyles(textSegments);
@@ -46118,6 +46134,37 @@ var PptxHandlerRuntime79 = class extends PptxHandlerRuntime78 {
46118
46134
  }
46119
46135
  return this.findMasterPathForLayout(layoutPath);
46120
46136
  }
46137
+ /**
46138
+ * Resolve the editable template (master + layout) elements a slide
46139
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
46140
+ *
46141
+ * This is the canonical entry point for an "edit template/master"
46142
+ * feature: it returns the same decorative master/layout shapes that the
46143
+ * loader already merges in front of slide-authored content (master shapes
46144
+ * behind, layout shapes on top), reusing the cached
46145
+ * {@link getLayoutElements} parse. Resolving a slide that has not been
46146
+ * loaded yet (no relationships cached) yields an empty array.
46147
+ *
46148
+ * Important scope notes for callers:
46149
+ * - Placeholder shapes (`<p:ph>`) are intentionally excluded; those are
46150
+ * resolved separately into each slide's own placeholders. Only
46151
+ * non-placeholder decorations (shapes, pictures, graphic frames) are
46152
+ * returned, which is exactly what the save writeback path supports.
46153
+ * - The returned elements are shared by every slide that inherits the
46154
+ * same layout/master. Editing one element and saving updates the shared
46155
+ * layout/master part, so the change is visible on all sibling slides.
46156
+ * - To persist an edit the binding must keep the mutated template element
46157
+ * inside the `slide.elements` array it passes to {@link save}; the save
46158
+ * writer reads template elements from `ctx.slide.elements` and writes
46159
+ * their shape XML back into the owning `p:spTree`.
46160
+ *
46161
+ * @param slideId - The slide's archive path (the `PptxSlide.id`, e.g.
46162
+ * `ppt/slides/slide1.xml`).
46163
+ * @returns Master + layout elements with prefixed ids (may be empty).
46164
+ */
46165
+ async getTemplateElementsForSlide(slideId) {
46166
+ return this.getLayoutElements(slideId);
46167
+ }
46121
46168
  /**
46122
46169
  * Get layouts available for a specific slide, scoped to that slide's
46123
46170
  * master. If the slide's master cannot be determined, returns all
@@ -46790,6 +46837,39 @@ var PptxHandlerCore = class {
46790
46837
  async getAvailableLayoutsForSlide(slideIndex, slides) {
46791
46838
  return this.runtime.getAvailableLayoutsForSlide(slideIndex, slides);
46792
46839
  }
46840
+ /**
46841
+ * Resolve the editable template (master + layout) elements a slide
46842
+ * inherits, each carrying a `master-` / `layout-` prefixed id.
46843
+ *
46844
+ * This is the foundation for an "edit template/master" feature. The
46845
+ * returned elements are the decorative master/layout shapes the loader
46846
+ * already merges behind slide-authored content (master shapes behind,
46847
+ * layout shapes on top); placeholders are excluded. The same elements are
46848
+ * shared by every slide inheriting the layout/master, so editing one and
46849
+ * saving updates the shared part.
46850
+ *
46851
+ * To persist an edit, keep the mutated template element inside the
46852
+ * `slide.elements` array passed to {@link save}; the save writer reads
46853
+ * template elements from there and writes their shape XML back into the
46854
+ * owning layout/master `p:spTree`.
46855
+ *
46856
+ * @param slideId - The slide's archive path (the `PptxSlide.id`).
46857
+ * @returns Master + layout elements with prefixed ids (may be empty).
46858
+ *
46859
+ * @example
46860
+ * ```ts
46861
+ * const templateEls = await handler.getTemplateElementsForSlide(slide.id);
46862
+ * const logo = templateEls.find((e) => e.id.startsWith("master-"));
46863
+ * if (logo) {
46864
+ * logo.x += 10;
46865
+ * slide.elements = [...slide.elements, logo];
46866
+ * await handler.save(data.slides);
46867
+ * }
46868
+ * ```
46869
+ */
46870
+ async getTemplateElementsForSlide(slideId) {
46871
+ return this.runtime.getTemplateElementsForSlide(slideId);
46872
+ }
46793
46873
  /**
46794
46874
  * Apply a different layout to an existing slide.
46795
46875
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptx-viewer-core",
3
- "version": "1.1.36",
3
+ "version": "1.1.38",
4
4
  "description": "PowerPoint PPTX engine: parse, edit, serialize, and convert .pptx files. Framework-agnostic TypeScript SDK.",
5
5
  "keywords": [
6
6
  "converter",