Skip to main content
Glama
slide.js•7.9 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Slide = void 0; const file_helper_1 = require("../helper/file-helper"); const general_helper_1 = require("../helper/general-helper"); const xml_relationship_helper_1 = require("../helper/xml-relationship-helper"); const has_shapes_1 = __importDefault(require("./has-shapes")); const master_1 = require("./master"); class Slide extends has_shapes_1.default { constructor(params) { super(params); this.targetType = 'slide'; this.sourceNumber = this.getSlideNumber(params.template, params.slideIdentifier); this.sourcePath = `ppt/slides/slide${this.sourceNumber}.xml`; this.relsPath = `ppt/slides/_rels/slide${this.sourceNumber}.xml.rels`; } /** * Appends slide * @internal * @param targetTemplate * @returns append */ append(targetTemplate) { return __awaiter(this, void 0, void 0, function* () { this.targetTemplate = targetTemplate; this.targetArchive = yield targetTemplate.archive; this.targetNumber = targetTemplate.incrementCounter('slides'); this.targetPath = `ppt/slides/slide${this.targetNumber}.xml`; this.targetRelsPath = `ppt/slides/_rels/slide${this.targetNumber}.xml.rels`; this.sourceArchive = yield this.sourceTemplate.archive; this.status.info = 'Appending slide ' + this.targetNumber; yield this.copySlideFiles(); yield this.copyRelatedContent(); yield this.addToPresentation(); const sourceNotesNumber = yield this.getSlideNoteSourceNumber(); if (sourceNotesNumber) { yield this.copySlideNoteFiles(sourceNotesNumber); yield this.updateSlideNoteFile(sourceNotesNumber); yield this.appendNotesToContentType(this.targetArchive, this.targetNumber); } if (this.importElements.length) { yield this.importedSelectedElements(); } yield this.applyModifications(); yield this.applyRelModifications(); const info = this.targetTemplate.automizer.params.showIntegrityInfo; const assert = this.targetTemplate.automizer.params.showIntegrityInfo; yield this.checkIntegrity(info, assert); yield this.cleanSlide(this.targetPath); this.status.increment(); }); } /** * Use another slide layout. * @param targetLayoutId */ useSlideLayout(layoutId) { this.modifyRelations((slideRelXml) => __awaiter(this, void 0, void 0, function* () { let targetLayoutId; if (typeof layoutId === 'string') { targetLayoutId = yield this.useNamedSlideLayout(layoutId); if (!targetLayoutId) { layoutId = null; } } if (!layoutId || typeof layoutId === 'number') { targetLayoutId = yield this.useIndexedSlideLayout(layoutId); } const slideLayouts = new xml_relationship_helper_1.XmlRelationshipHelper(slideRelXml) .readTargets() .getTargetsByPrefix('../slideLayouts/slideLayout'); if (slideLayouts.length) { slideLayouts[0].updateTargetIndex(targetLayoutId); } })); return this; } /** * Find another slide layout by name. * @param targetLayoutId */ useNamedSlideLayout(targetLayoutName) { return __awaiter(this, void 0, void 0, function* () { const templateName = this.sourceTemplate.name; const sourceLayoutId = yield xml_relationship_helper_1.XmlRelationshipHelper.getSlideLayoutNumber(this.sourceArchive, this.sourceNumber); yield this.autoImportSourceSlideMaster(templateName, sourceLayoutId); const alreadyImported = this.targetTemplate.getNamedMappedContent('slideLayout', targetLayoutName); if (!alreadyImported) { console.error('Could not find "' + targetLayoutName + '"@' + templateName + '@' + 'sourceLayoutId:' + sourceLayoutId); } return alreadyImported === null || alreadyImported === void 0 ? void 0 : alreadyImported.targetId; }); } /** * Use another slide layout by index or detect original index. * @param targetLayoutId */ useIndexedSlideLayout(targetLayoutIndex) { return __awaiter(this, void 0, void 0, function* () { if (!targetLayoutIndex) { const sourceLayoutId = yield xml_relationship_helper_1.XmlRelationshipHelper.getSlideLayoutNumber(this.sourceArchive, this.sourceNumber); const templateName = this.sourceTemplate.name; const alreadyImported = this.targetTemplate.getMappedContent('slideLayout', templateName, sourceLayoutId); if (alreadyImported) { return alreadyImported.targetId; } else { return yield this.autoImportSourceSlideMaster(templateName, sourceLayoutId); } } return targetLayoutIndex; }); } autoImportSourceSlideMaster(templateName, sourceLayoutId) { return __awaiter(this, void 0, void 0, function* () { const sourceMasterId = yield xml_relationship_helper_1.XmlRelationshipHelper.getSlideMasterNumber(this.sourceArchive, sourceLayoutId); const key = master_1.Master.getKey(sourceMasterId, templateName); if (!this.targetTemplate.masters.find((master) => master.key === key)) { yield this.targetTemplate.automizer.addMaster(templateName, sourceMasterId); const previouslyAddedMaster = (0, general_helper_1.last)(this.targetTemplate.masters); yield this.targetTemplate .appendMasterSlide(previouslyAddedMaster) .catch((e) => { throw e; }); } const alreadyImported = this.targetTemplate.getMappedContent('slideLayout', templateName, sourceLayoutId); return alreadyImported === null || alreadyImported === void 0 ? void 0 : alreadyImported.targetId; }); } /** * Copys slide files * @internal */ copySlideFiles() { return __awaiter(this, void 0, void 0, function* () { yield file_helper_1.FileHelper.zipCopy(this.sourceArchive, `ppt/slides/slide${this.sourceNumber}.xml`, this.targetArchive, `ppt/slides/slide${this.targetNumber}.xml`); yield file_helper_1.FileHelper.zipCopy(this.sourceArchive, `ppt/slides/_rels/slide${this.sourceNumber}.xml.rels`, this.targetArchive, `ppt/slides/_rels/slide${this.targetNumber}.xml.rels`); }); } } exports.Slide = Slide; //# sourceMappingURL=slide.js.map

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/guangxiangdebizi/PPT-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server