From 497725524a2bd3fa9bf9ca0484b087d24b4ae61b Mon Sep 17 00:00:00 2001 From: wxm <157215725@qq.com> Date: Thu, 5 Dec 2024 15:29:13 +0800 Subject: [PATCH] feat: updatae --- src/core/OXML.ts | 111 ++++++++++++++---- src/core/utils.ts | 70 +++++++++++ src/openxml/drawing/BlipFill.ts | 4 +- src/openxml/drawing/BodyProperties.ts | 20 ++-- src/openxml/drawing/CustomGeometry.ts | 12 +- src/openxml/drawing/EffectList.ts | 16 +-- src/openxml/drawing/HslColor.ts | 2 +- src/openxml/drawing/Outline.ts | 23 +++- src/openxml/drawing/Paragraph.ts | 4 +- src/openxml/drawing/ParagraphProperties.ts | 14 +-- src/openxml/drawing/PatternFill.ts | 6 +- src/openxml/drawing/PresetColor.ts | 2 +- src/openxml/drawing/PresetGeometry.ts | 2 +- src/openxml/drawing/RgbColorModelHex.ts | 2 +- .../drawing/RgbColorModelPercentage.ts | 2 +- src/openxml/drawing/RunProperties.ts | 50 ++++---- src/openxml/drawing/SchemeColor.ts | 2 +- src/openxml/drawing/Stretch.ts | 2 +- src/openxml/drawing/SystemColor.ts | 2 +- src/openxml/drawing/Transform2D.ts | 4 +- src/openxml/drawing/_Color.ts | 12 +- src/openxml/drawing/_Style.ts | 22 ++-- .../ApplicationNonVisualDrawingProperties.ts | 16 +-- src/openxml/presentation/ColorMap.ts | 24 ++-- src/openxml/presentation/CommonSlideData.ts | 2 +- src/openxml/presentation/ConnectionShape.ts | 4 +- src/openxml/presentation/EmbeddedFont.ts | 8 +- src/openxml/presentation/Font.ts | 8 +- src/openxml/presentation/GraphicFrame.ts | 4 +- src/openxml/presentation/GroupShape.ts | 18 ++- .../presentation/GroupShapeProperties.ts | 4 +- .../NonVisualDrawingProperties.ts | 16 +-- .../NonVisualShapeDrawingProperties.ts | 2 +- src/openxml/presentation/Picture.ts | 3 + src/openxml/presentation/PlaceholderShape.ts | 4 +- src/openxml/presentation/Presentation.ts | 22 ++-- src/openxml/presentation/Shape.ts | 24 ++-- src/openxml/presentation/ShapeProperties.ts | 10 +- src/openxml/presentation/ShapeStyle.ts | 8 +- src/openxml/presentation/Slide.ts | 6 +- src/openxml/presentation/SlideLayout.ts | 14 +-- src/openxml/presentation/SlideMaster.ts | 4 +- src/openxml/presentation/TextBody.ts | 2 +- src/openxml/presentation/_Slide.ts | 6 +- 44 files changed, 384 insertions(+), 209 deletions(-) create mode 100644 src/core/utils.ts diff --git a/src/core/OXML.ts b/src/core/OXML.ts index adf0822..4e10e01 100644 --- a/src/core/OXML.ts +++ b/src/core/OXML.ts @@ -1,12 +1,17 @@ +import { deepMerge, getObjectValueByPath, setObjectValueByPath } from './utils' + export type OXMLProto = new (...args: any[]) => OXML export interface OXMLAttributeDefinition { - type: string + name: string + alias: string + type: string | Record defaultValue?: any } export interface OXMLPropertyDefinition { - type: string + name: string + alias: string defaultValue?: any } @@ -19,8 +24,8 @@ export interface OXMLChildDefinition { export interface OXMLDefinition { tag?: string namespace?: string - attributes?: Map - properties?: Map + attributes?: Record + properties?: Record children?: OXMLChildDefinition[] } @@ -55,8 +60,8 @@ export function defineAttribute( definition = {} as OXMLDefinition OXML.protoToDefinition.set(proto, definition) } - definition.attributes ??= new Map() - definition.attributes.set(attrName, { type, defaultValue }) + definition.attributes ??= {} + definition.attributes[attrName] = { name, alias: attrName, type, defaultValue } Object.defineProperty(proto, name, { get() { return (this as OXML).getAttribute(attrName) @@ -74,11 +79,11 @@ export function defineProperty(propName: string) { definition = {} as OXMLDefinition OXML.protoToDefinition.set(proto, definition) } - definition.properties ??= new Map() - definition.properties.set(propName, {}) + definition.properties ??= {} + definition.properties[propName] = { name, alias: propName } Object.defineProperty(proto, name, { get() { - return (this as OXML).getAttribute(propName) + return (this as OXML).offsetGet(propName) }, }) } @@ -121,16 +126,41 @@ export class OXML { return this.tagToConstructor.get(tag) } - static getDefinition(tag: string): OXMLDefinition | undefined { - const proto = this.getConstructor(tag)?.prototype - return proto ? this.protoToDefinition.get(proto) : undefined + static getDefinition(proto: any): OXMLDefinition | undefined { + let definition: OXMLDefinition | undefined + let cur = proto + while (cur) { + const _definition = this.protoToDefinition.get(cur) + if (_definition) { + definition = deepMerge(definition ?? {}, _definition) + } + cur = Object.getPrototypeOf(cur) + } + return definition + } + + static make(source: string | Element): T { + let tag: string + let element: Element | undefined + if (typeof source === 'string') { + tag = source + } + else { + tag = source.tagName + element = source + } + const oxml = new (this.getConstructor(tag) ?? OXML)() + if (element) { + oxml.fromElement(element) + } + return oxml as T } declare tag?: string declare element: Element definition(): OXMLDefinition | undefined { - return OXML.protoToDefinition.get(this.constructor.prototype as any) + return OXML.getDefinition(this) } getSetterValue(type: string, value: any): any { @@ -192,7 +222,7 @@ export class OXML { } setAttribute(name: string, value: any): void { - const definition = this.definition()?.attributes?.get(name) + const definition = this.definition()?.attributes?.[name] let newValue = value if (definition) { try { @@ -207,7 +237,7 @@ export class OXML { getAttribute(name: string): any | undefined { const value = this.element.getAttribute(name) - const definition = this.definition()?.attributes?.get(name) + const definition = this.definition()?.attributes?.[name] if (value === undefined) { return value ?? definition?.defaultValue } @@ -230,12 +260,20 @@ export class OXML { ) } + offsetSet(path: string, value: any): void { + return setObjectValueByPath(this, path, value) + } + + offsetGet(path: string): any | undefined { + return getObjectValueByPath(this, path) + } + getChild(tag: string): OXML | undefined { const element = Array.from(this.element.children).find((element) => { return element.tagName === tag || element.localName === tag }) if (element) { - return new (OXML.getConstructor(element.tagName) ?? OXML)().fromElement(element) + return OXML.make(element) } return undefined } @@ -244,7 +282,7 @@ export class OXML { return Array.from(this.element.children) .map((element) => { if (!tag || (element.tagName === tag || element.localName === tag)) { - return new (OXML.getConstructor(element.tagName) ?? OXML)().fromElement(element) + return OXML.make(element) } return undefined }) @@ -276,13 +314,40 @@ export class OXML { } toJSON(): Record { + const definition = this.definition() + const properties: Record = {} + if (definition?.properties) { + Object.values(definition.properties).forEach((property) => { + let value = this.offsetGet(property.alias) + if (value instanceof OXML) { + value = value.toJSON() + } + else if (Array.isArray(value)) { + value = value.map((v) => { + if (v instanceof OXML) { + return v.toJSON() + } + return v + }) + } + if (value !== undefined) { + properties[property.name] = value + } + }) + } + definition?.children?.forEach((child) => { + child.tag + }) return { - ...this.getAttributes(), - ...Object.fromEntries(this.getChildren().map((child) => { - const tag = child.tag ?? child.element.tagName - const tagArr = tag.split(':') - return [tagArr[tagArr.length - 1], child.toJSON()] - })), + ...properties, } + // return { + // ...this.getAttributes(), + // ...Object.fromEntries(this.getChildren().map((child) => { + // const tag = child.tag ?? child.element.tagName + // const tagArr = tag.split(':') + // return [tagArr[tagArr.length - 1], child.toJSON()] + // })), + // } } } diff --git a/src/core/utils.ts b/src/core/utils.ts new file mode 100644 index 0000000..4f89098 --- /dev/null +++ b/src/core/utils.ts @@ -0,0 +1,70 @@ +export function getNestedValue(obj: any, path: (string | number)[], fallback?: any): any { + const last = path.length - 1 + if (last < 0) + return obj === undefined ? fallback : obj + for (let i = 0; i < last; i++) { + if (obj == null) { + return fallback + } + obj = obj[path[i]] + } + if (obj == null) + return fallback + return obj[path[last]] === undefined ? fallback : obj[path[last]] +} + +export function getObjectValueByPath(obj: any, path: string, fallback?: any): any { + // credit: http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key#comment55278413_6491621 + if (obj == null || !path || typeof path !== 'string') + return fallback + if (obj[path] !== undefined) + return obj[path] + path = path.replace(/\[(\w+)\]/g, '.$1') // convert indexes to properties + path = path.replace(/^\./, '') // strip a leading dot + return getNestedValue(obj, path.split('.'), fallback) +} + +export function setNestedValue(obj: any, path: (string | number)[], value: any): void { + const last = path.length - 1 + for (let i = 0; i < last; i++) { + if (typeof obj[path[i]] !== 'object') + obj[path[i]] = {} + obj = obj[path[i]] + } + obj[path[last]] = value +} + +export function setObjectValueByPath(obj: any, path: string, value: any): void { + if (typeof obj !== 'object' || !path) + return + path = path.replace(/\[(\w+)\]/g, '.$1') + path = path.replace(/^\./, '') + return setNestedValue(obj, path.split('.'), value) +} + +export function isObject(objectable: any): objectable is object { + return objectable !== null && typeof objectable === 'object' && !Array.isArray(objectable) +} + +export function deepMerge( + source: Record = {}, + target: Record = {}, + out: Record = {}, +): Record { + for (const key in source) { + out[key] = source[key] + } + for (const key in target) { + const sourceProperty = source[key] + const targetProperty = target[key] + if ( + isObject(sourceProperty) + && isObject(targetProperty) + ) { + out[key] = deepMerge(sourceProperty, targetProperty) + continue + } + out[key] = targetProperty + } + return out +} diff --git a/src/openxml/drawing/BlipFill.ts b/src/openxml/drawing/BlipFill.ts index fa0fe1f..019f73f 100644 --- a/src/openxml/drawing/BlipFill.ts +++ b/src/openxml/drawing/BlipFill.ts @@ -9,8 +9,8 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' */ @defineElement('a:blipFill') export class BlipFill extends OXML { - @defineAttribute('rotWithShape', 'boolean') rotWithShape?: boolean - @defineAttribute('dpi', 'number') dpi?: number + @defineAttribute('rotWithShape', 'boolean') declare rotWithShape?: boolean + @defineAttribute('dpi', 'number') declare dpi?: number @defineChild('a:blip') declare blip: Blip @defineChild('a:srcRect') declare srcRect: SourceRectangle diff --git a/src/openxml/drawing/BodyProperties.ts b/src/openxml/drawing/BodyProperties.ts index f262a4e..faf3638 100644 --- a/src/openxml/drawing/BodyProperties.ts +++ b/src/openxml/drawing/BodyProperties.ts @@ -7,14 +7,14 @@ import { TextAnchoringTypeValues } from './TextAnchoringTypeValues' */ @defineElement('a:bodyPr') export class BodyProperties extends OXML { - @defineAttribute('anchor', TextAnchoringTypeValues) anchor?: TextAnchoringTypeValues - @defineAttribute('anchorCtr', 'boolean') anchorCtr?: boolean - @defineAttribute('spcFirstLastPara', 'boolean') spcFirstLastPara?: boolean - @defineAttribute('lIns', 'emu') lIns?: number - @defineAttribute('tIns', 'emu') tIns?: number - @defineAttribute('rIns', 'emu') rIns?: number - @defineAttribute('bIns', 'emu') bIns?: number - @defineAttribute('rot', 'degree') rot?: number - @defineAttribute('wrap') wrap?: TextWrappingValues - @defineAttribute('upright', 'boolean') upright?: boolean + @defineAttribute('anchor', TextAnchoringTypeValues) declare anchor?: TextAnchoringTypeValues + @defineAttribute('anchorCtr', 'boolean') declare anchorCtr?: boolean + @defineAttribute('spcFirstLastPara', 'boolean') declare spcFirstLastPara?: boolean + @defineAttribute('lIns', 'emu') declare lIns?: number + @defineAttribute('tIns', 'emu') declare tIns?: number + @defineAttribute('rIns', 'emu') declare rIns?: number + @defineAttribute('bIns', 'emu') declare bIns?: number + @defineAttribute('rot', 'degree') declare rot?: number + @defineAttribute('wrap') declare wrap?: TextWrappingValues + @defineAttribute('upright', 'boolean') declare upright?: boolean } diff --git a/src/openxml/drawing/CustomGeometry.ts b/src/openxml/drawing/CustomGeometry.ts index 66c6d8e..fa56113 100644 --- a/src/openxml/drawing/CustomGeometry.ts +++ b/src/openxml/drawing/CustomGeometry.ts @@ -11,10 +11,10 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('a:custGeom') export class CustomGeometry extends OXML { - @defineChild('a:ahLst') ahLst?: AdjustHandleList - @defineChild('a:avLst') avLst?: AdjustValueList - @defineChild('a:cxnLst') cxnLst?: ConnectionSiteList - @defineChild('a:gdLst') gdLst?: ShapeGuideList - @defineChild('a:pathLst') pathLst?: PathList - @defineChild('a:rect') rect?: Rectangle + @defineChild('a:ahLst') declare ahLst?: AdjustHandleList + @defineChild('a:avLst') declare avLst?: AdjustValueList + @defineChild('a:cxnLst') declare cxnLst?: ConnectionSiteList + @defineChild('a:gdLst') declare gdLst?: ShapeGuideList + @defineChild('a:pathLst') declare pathLst?: PathList + @defineChild('a:rect') declare rect?: Rectangle } diff --git a/src/openxml/drawing/EffectList.ts b/src/openxml/drawing/EffectList.ts index 6a947d9..ea4a233 100644 --- a/src/openxml/drawing/EffectList.ts +++ b/src/openxml/drawing/EffectList.ts @@ -6,12 +6,12 @@ import { defineChild, defineElement, OXML } from '../../core' @defineElement('a:effectLst') export class EffectList extends OXML { // TODO - @defineChild('blur') blur?: OXML - @defineChild('fillOverlay') fillOverlay?: OXML - @defineChild('glow') glow?: OXML - @defineChild('innerShdw') innerShdw?: OXML - @defineChild('outerShdw') outerShdw?: OXML - @defineChild('prstShdw') prstShdw?: OXML - @defineChild('reflection') reflection?: OXML - @defineChild('softEdge') softEdge?: OXML + @defineChild('blur') declare blur?: OXML + @defineChild('fillOverlay') declare fillOverlay?: OXML + @defineChild('glow') declare glow?: OXML + @defineChild('innerShdw') declare innerShdw?: OXML + @defineChild('outerShdw') declare outerShdw?: OXML + @defineChild('prstShdw') declare prstShdw?: OXML + @defineChild('reflection') declare reflection?: OXML + @defineChild('softEdge') declare softEdge?: OXML } diff --git a/src/openxml/drawing/HslColor.ts b/src/openxml/drawing/HslColor.ts index 6380306..1bc93ad 100644 --- a/src/openxml/drawing/HslColor.ts +++ b/src/openxml/drawing/HslColor.ts @@ -10,5 +10,5 @@ export class HslColor extends OXML { @defineAttribute('sat', 'percentage') declare sat: number @defineAttribute('lum', 'percentage') declare lum: number - @defineChild('a:alpha') alpha?: Alpha + @defineChild('a:alpha') declare alpha?: Alpha } diff --git a/src/openxml/drawing/Outline.ts b/src/openxml/drawing/Outline.ts index 07dee7d..26302cf 100644 --- a/src/openxml/drawing/Outline.ts +++ b/src/openxml/drawing/Outline.ts @@ -1,9 +1,30 @@ -import { defineElement, OXML } from '../../core' +import { defineChild, defineElement, OXML } from '../../core' /** * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.outline */ @defineElement('a:ln') export class Outline extends OXML { + @defineChild('a:bevel') declare bevel: OXML + @defineChild('a:custDash') declare custDash: OXML + @defineChild('a:extLst') declare extLst: OXML + @defineChild('a:gradFill') declare gradFill: OXML + @defineChild('a:headEnd') declare headEnd: OXML + @defineChild('a:miter') declare miter: OXML + @defineChild('a:noFill') declare noFill: OXML + @defineChild('a:pattFill') declare pattFill: OXML + @defineChild('a:prstDash') declare prstDash: OXML + @defineChild('a:round') declare round: OXML + @defineChild('a:solidFill') declare solidFill: OXML + @defineChild('a:tailEnd') declare tailEnd: OXML + + // + // + // + // + // + // + // + // // } diff --git a/src/openxml/drawing/Paragraph.ts b/src/openxml/drawing/Paragraph.ts index fe1775e..637e618 100644 --- a/src/openxml/drawing/Paragraph.ts +++ b/src/openxml/drawing/Paragraph.ts @@ -14,8 +14,8 @@ export class Paragraph extends OXML { @defineProperty('pPr.marL', 0) declare marginLeft: number @defineProperty('pPr.marR', 0) declare marginRight: number @defineProperty('pPr.indent', 0) declare textIndent: number - @defineProperty('pPr.lvl') level?: number - @defineProperty('pPr.fontAlgn') fontAlign?: string + @defineProperty('pPr.lvl') declare level?: number + @defineProperty('pPr.fontAlgn') declare fontAlign?: string get textAlign(): TextAlignmentTypeValues | undefined { return this.pPr.algn } get rightToLeft(): string | undefined { return this.pPr.rtl } diff --git a/src/openxml/drawing/ParagraphProperties.ts b/src/openxml/drawing/ParagraphProperties.ts index 484efba..bccd7ef 100644 --- a/src/openxml/drawing/ParagraphProperties.ts +++ b/src/openxml/drawing/ParagraphProperties.ts @@ -6,11 +6,11 @@ import { TextAlignmentTypeValues } from './TextAlignmentTypeValues' */ @defineElement('a:pPr') export class ParagraphProperties extends OXML { - @defineAttribute('lvl', 'number') lvl?: number - @defineAttribute('marL', 'emu') marL?: number - @defineAttribute('marR', 'emu') marR?: number - @defineAttribute('indent', 'emu') indent?: number - @defineAttribute('algn', TextAlignmentTypeValues) algn?: TextAlignmentTypeValues - @defineAttribute('fontAlgn') fontAlgn?: string - @defineAttribute('rtl') rtl?: string + @defineAttribute('lvl', 'number') declare lvl?: number + @defineAttribute('marL', 'emu') declare marL?: number + @defineAttribute('marR', 'emu') declare marR?: number + @defineAttribute('indent', 'emu') declare indent?: number + @defineAttribute('algn', TextAlignmentTypeValues) declare algn?: TextAlignmentTypeValues + @defineAttribute('fontAlgn') declare fontAlgn?: string + @defineAttribute('rtl') declare rtl?: string } diff --git a/src/openxml/drawing/PatternFill.ts b/src/openxml/drawing/PatternFill.ts index 9da38c7..767ddca 100644 --- a/src/openxml/drawing/PatternFill.ts +++ b/src/openxml/drawing/PatternFill.ts @@ -7,8 +7,8 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' */ @defineElement('a:pattFill') export class PatternFill extends OXML { - @defineAttribute('prst', 'presetPatternVal') prst?: string + @defineAttribute('prst', 'presetPatternVal') declare prst?: string - @defineChild('a:bgClr') bgClr?: BackgroundColor - @defineChild('a:fgClr') fgClr?: ForegroundColor + @defineChild('a:bgClr') declare bgClr?: BackgroundColor + @defineChild('a:fgClr') declare fgClr?: ForegroundColor } diff --git a/src/openxml/drawing/PresetColor.ts b/src/openxml/drawing/PresetColor.ts index 7d3cc63..1b27e2b 100644 --- a/src/openxml/drawing/PresetColor.ts +++ b/src/openxml/drawing/PresetColor.ts @@ -8,5 +8,5 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' export class PresetColor extends OXML { @defineAttribute('val') declare val: string - @defineChild('a:alpha') alpha?: Alpha + @defineChild('a:alpha') declare alpha?: Alpha } diff --git a/src/openxml/drawing/PresetGeometry.ts b/src/openxml/drawing/PresetGeometry.ts index 06c0071..77cb67c 100644 --- a/src/openxml/drawing/PresetGeometry.ts +++ b/src/openxml/drawing/PresetGeometry.ts @@ -7,5 +7,5 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' export class PresetGeometry extends OXML { @defineAttribute('prst') declare prst: string - @defineChild('a:avLst') avLst?: OXML + @defineChild('a:avLst') declare avLst?: OXML } diff --git a/src/openxml/drawing/RgbColorModelHex.ts b/src/openxml/drawing/RgbColorModelHex.ts index e948b6d..9228b73 100644 --- a/src/openxml/drawing/RgbColorModelHex.ts +++ b/src/openxml/drawing/RgbColorModelHex.ts @@ -8,5 +8,5 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' export class RgbColorModelHex extends OXML { @defineAttribute('val') declare val: string - @defineChild('a:alpha') alpha?: Alpha + @defineChild('a:alpha') declare alpha?: Alpha } diff --git a/src/openxml/drawing/RgbColorModelPercentage.ts b/src/openxml/drawing/RgbColorModelPercentage.ts index 3abe991..2276977 100644 --- a/src/openxml/drawing/RgbColorModelPercentage.ts +++ b/src/openxml/drawing/RgbColorModelPercentage.ts @@ -10,5 +10,5 @@ export class RgbColorModelPercentage extends OXML { @defineAttribute('g', 'percentage') declare g: number @defineAttribute('b', 'percentage') declare b: number - @defineChild('a:alpha') alpha?: Alpha + @defineChild('a:alpha') declare alpha?: Alpha } diff --git a/src/openxml/drawing/RunProperties.ts b/src/openxml/drawing/RunProperties.ts index a5ea0dc..9771b2a 100644 --- a/src/openxml/drawing/RunProperties.ts +++ b/src/openxml/drawing/RunProperties.ts @@ -6,30 +6,30 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' */ @defineElement('a:rPr') export class RunProperties extends OXML { - @defineAttribute('altLang') altLang?: string - @defineAttribute('baseline') baseline?: string - @defineAttribute('b', 'boolean') b?: boolean - @defineAttribute('bmk') bmk?: string - @defineAttribute('cap') cap?: string - @defineAttribute('dirty') dirty?: string - @defineAttribute('sz', 'fontSize') sz?: number - @defineAttribute('i', 'boolean') i?: boolean - @defineAttribute('kern', 'emu') kern?: string - @defineAttribute('kumimoji') kumimoji?: string - @defineAttribute('lang') lang?: string - @defineAttribute('noProof') noProof?: string - @defineAttribute('normalizeH') normalizeH?: string - @defineAttribute('Outline') Outline?: string - @defineAttribute('smtClean') smtClean?: string - @defineAttribute('smtId') smtId?: string - @defineAttribute('spc', 'fontSize') spc?: number - @defineAttribute('err') err?: string - @defineAttribute('strike') strike?: string - @defineAttribute('u') u?: string + @defineAttribute('altLang') declare altLang?: string + @defineAttribute('baseline') declare baseline?: string + @defineAttribute('b', 'boolean') declare b?: boolean + @defineAttribute('bmk') declare bmk?: string + @defineAttribute('cap') declare cap?: string + @defineAttribute('dirty') declare dirty?: string + @defineAttribute('sz', 'fontSize') declare sz?: number + @defineAttribute('i', 'boolean') declare i?: boolean + @defineAttribute('kern', 'emu') declare kern?: string + @defineAttribute('kumimoji') declare kumimoji?: string + @defineAttribute('lang') declare lang?: string + @defineAttribute('noProof') declare noProof?: string + @defineAttribute('normalizeH') declare normalizeH?: string + @defineAttribute('Outline') declare Outline?: string + @defineAttribute('smtClean') declare smtClean?: string + @defineAttribute('smtId') declare smtId?: string + @defineAttribute('spc', 'fontSize') declare spc?: number + @defineAttribute('err') declare err?: string + @defineAttribute('strike') declare strike?: string + @defineAttribute('u') declare u?: string - @defineChild('a:cs') cs?: OXML - @defineChild('a:ea') ea?: OXML - @defineChild('a:latin') latin?: OXML - @defineChild('a:sym') sym?: OXML - @defineChild('a:solidFill') solidFill?: SolidFill + @defineChild('a:cs') declare cs?: OXML + @defineChild('a:ea') declare ea?: OXML + @defineChild('a:latin') declare latin?: OXML + @defineChild('a:sym') declare sym?: OXML + @defineChild('a:solidFill') declare solidFill?: SolidFill } diff --git a/src/openxml/drawing/SchemeColor.ts b/src/openxml/drawing/SchemeColor.ts index 9daff13..1401bce 100644 --- a/src/openxml/drawing/SchemeColor.ts +++ b/src/openxml/drawing/SchemeColor.ts @@ -8,5 +8,5 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' export class SchemeColor extends OXML { @defineAttribute('val') declare val: string - @defineChild('a:alpha') alpha?: Alpha + @defineChild('a:alpha') declare alpha?: Alpha } diff --git a/src/openxml/drawing/Stretch.ts b/src/openxml/drawing/Stretch.ts index 5c4fac5..c70d06f 100644 --- a/src/openxml/drawing/Stretch.ts +++ b/src/openxml/drawing/Stretch.ts @@ -6,5 +6,5 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('a:stretch') export class Stretch extends OXML { - @defineChild('a:fillRect') fillRect?: FillRectangle + @defineChild('a:fillRect') declare fillRect?: FillRectangle } diff --git a/src/openxml/drawing/SystemColor.ts b/src/openxml/drawing/SystemColor.ts index 61226d5..2ec3710 100644 --- a/src/openxml/drawing/SystemColor.ts +++ b/src/openxml/drawing/SystemColor.ts @@ -8,5 +8,5 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' export class SystemColor extends OXML { @defineAttribute('val') declare val: string - @defineChild('a:alpha') alpha?: Alpha + @defineChild('a:alpha') declare alpha?: Alpha } diff --git a/src/openxml/drawing/Transform2D.ts b/src/openxml/drawing/Transform2D.ts index 0cf80fe..0770364 100644 --- a/src/openxml/drawing/Transform2D.ts +++ b/src/openxml/drawing/Transform2D.ts @@ -15,6 +15,6 @@ export class Transform2D extends OXML { @defineChild('a:off') declare off: Offset @defineChild('a:ext') declare ext: Extents - @defineChild('a:chOff') chOff?: ChildOffset - @defineChild('a:chExt') chExt?: ChildExtents + @defineChild('a:chOff') declare chOff?: ChildOffset + @defineChild('a:chExt') declare chExt?: ChildExtents } diff --git a/src/openxml/drawing/_Color.ts b/src/openxml/drawing/_Color.ts index b04ac70..4102616 100644 --- a/src/openxml/drawing/_Color.ts +++ b/src/openxml/drawing/_Color.ts @@ -7,10 +7,10 @@ import type { SystemColor } from './SystemColor' import { defineChild, OXML } from '../../core' export class _Color extends OXML { - @defineChild('a:hslClr') hslClr?: HslColor - @defineChild('a:prstClr') prstClr?: PresetColor - @defineChild('a:schemeClr') schemeClr?: SchemeColor - @defineChild('a:scrgbClr') scrgbClr?: RgbColorModelPercentage - @defineChild('a:srgbClr') srgbClr?: RgbColorModelHex - @defineChild('a:sysClr') sysClr?: SystemColor + @defineChild('a:hslClr') declare hslClr?: HslColor + @defineChild('a:prstClr') declare prstClr?: PresetColor + @defineChild('a:schemeClr') declare schemeClr?: SchemeColor + @defineChild('a:scrgbClr') declare scrgbClr?: RgbColorModelPercentage + @defineChild('a:srgbClr') declare srgbClr?: RgbColorModelHex + @defineChild('a:sysClr') declare sysClr?: SystemColor } diff --git a/src/openxml/drawing/_Style.ts b/src/openxml/drawing/_Style.ts index b37c82a..59c8d04 100644 --- a/src/openxml/drawing/_Style.ts +++ b/src/openxml/drawing/_Style.ts @@ -3,15 +3,15 @@ import type { ExtensionList } from './ExtensionList' import { defineChild, OXML } from '../../core' export class _Style extends OXML { - @defineChild('a:defPPr') defPPr?: DefaultParagraphProperties - @defineChild('a:extLst') extLst?: ExtensionList - @defineChild('a:lvl1pPr') lvl1pPr?: OXML - @defineChild('a:lvl2pPr') lvl2pPr?: OXML - @defineChild('a:lvl3pPr') lvl3pPr?: OXML - @defineChild('a:lvl4pPr') lvl4pPr?: OXML - @defineChild('a:lvl5pPr') lvl5pPr?: OXML - @defineChild('a:lvl6pPr') lvl6pPr?: OXML - @defineChild('a:lvl7pPr') lvl7pPr?: OXML - @defineChild('a:lvl8pPr') lvl8pPr?: OXML - @defineChild('a:lvl9pPr') lvl9pPr?: OXML + @defineChild('a:defPPr') declare defPPr?: DefaultParagraphProperties + @defineChild('a:extLst') declare extLst?: ExtensionList + @defineChild('a:lvl1pPr') declare lvl1pPr?: OXML + @defineChild('a:lvl2pPr') declare lvl2pPr?: OXML + @defineChild('a:lvl3pPr') declare lvl3pPr?: OXML + @defineChild('a:lvl4pPr') declare lvl4pPr?: OXML + @defineChild('a:lvl5pPr') declare lvl5pPr?: OXML + @defineChild('a:lvl6pPr') declare lvl6pPr?: OXML + @defineChild('a:lvl7pPr') declare lvl7pPr?: OXML + @defineChild('a:lvl8pPr') declare lvl8pPr?: OXML + @defineChild('a:lvl9pPr') declare lvl9pPr?: OXML } diff --git a/src/openxml/presentation/ApplicationNonVisualDrawingProperties.ts b/src/openxml/presentation/ApplicationNonVisualDrawingProperties.ts index 195689a..acfebd2 100644 --- a/src/openxml/presentation/ApplicationNonVisualDrawingProperties.ts +++ b/src/openxml/presentation/ApplicationNonVisualDrawingProperties.ts @@ -7,12 +7,12 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:nvPr') export class ApplicationNonVisualDrawingProperties extends OXML { - @defineChild('a:audioCd') audioCd?: OXML - @defineChild('a:audioFile') audioFile?: AudioFromFile - @defineChild('a:custDataLst') custDataLst?: OXML - @defineChild('a:extLst') extLst?: ExtensionList - @defineChild('p:ph') ph?: PlaceholderShape - @defineChild('quickTimeFile') quickTimeFile?: OXML - @defineChild('a:videoFile') videoFile?: VideoFromFile - @defineChild('a:wavAudioFile') wavAudioFile?: OXML + @defineChild('a:audioCd') declare audioCd?: OXML + @defineChild('a:audioFile') declare audioFile?: AudioFromFile + @defineChild('a:custDataLst') declare custDataLst?: OXML + @defineChild('a:extLst') declare extLst?: ExtensionList + @defineChild('p:ph') declare ph?: PlaceholderShape + @defineChild('quickTimeFile') declare quickTimeFile?: OXML + @defineChild('a:videoFile') declare videoFile?: VideoFromFile + @defineChild('a:wavAudioFile') declare wavAudioFile?: OXML } diff --git a/src/openxml/presentation/ColorMap.ts b/src/openxml/presentation/ColorMap.ts index 3ac8907..a829c91 100644 --- a/src/openxml/presentation/ColorMap.ts +++ b/src/openxml/presentation/ColorMap.ts @@ -5,16 +5,16 @@ import { defineAttribute, defineElement, OXML } from '../../core' */ @defineElement('p:clrMap') export class ColorMap extends OXML { - @defineAttribute('accent1') accent1?: string - @defineAttribute('accent2') accent2?: string - @defineAttribute('accent3') accent3?: string - @defineAttribute('accent4') accent4?: string - @defineAttribute('accent5') accent5?: string - @defineAttribute('accent6') accent6?: string - @defineAttribute('bg1') bg1?: string - @defineAttribute('bg2') bg2?: string - @defineAttribute('folHlink') folHlink?: string - @defineAttribute('hlink') hlink?: string - @defineAttribute('tx1') tx1?: string - @defineAttribute('tx2') tx2?: string + @defineAttribute('accent1') declare accent1?: string + @defineAttribute('accent2') declare accent2?: string + @defineAttribute('accent3') declare accent3?: string + @defineAttribute('accent4') declare accent4?: string + @defineAttribute('accent5') declare accent5?: string + @defineAttribute('accent6') declare accent6?: string + @defineAttribute('bg1') declare bg1?: string + @defineAttribute('bg2') declare bg2?: string + @defineAttribute('folHlink') declare folHlink?: string + @defineAttribute('hlink') declare hlink?: string + @defineAttribute('tx1') declare tx1?: string + @defineAttribute('tx2') declare tx2?: string } diff --git a/src/openxml/presentation/CommonSlideData.ts b/src/openxml/presentation/CommonSlideData.ts index 85b8e1e..e125529 100644 --- a/src/openxml/presentation/CommonSlideData.ts +++ b/src/openxml/presentation/CommonSlideData.ts @@ -7,6 +7,6 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:cSld') export class CommonSlideData extends OXML { - @defineChild('p:bg') bg?: Background + @defineChild('p:bg') declare bg?: Background @defineChild('p:spTree') declare spTree: ShapeTree } diff --git a/src/openxml/presentation/ConnectionShape.ts b/src/openxml/presentation/ConnectionShape.ts index a1ef4b5..6553487 100644 --- a/src/openxml/presentation/ConnectionShape.ts +++ b/src/openxml/presentation/ConnectionShape.ts @@ -9,8 +9,8 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:cxnSp') export class ConnectionShape extends OXML { - @defineChild('p:extLst') extLst?: ExtensionList + @defineChild('p:extLst') declare extLst?: ExtensionList @defineChild('p:nvCxnSpPr') declare nvCxnSpPr: NonVisualConnectionShapeProperties @defineChild('p:spPr') declare spPr: ShapeProperties - @defineChild('p:style') style?: ShapeStyle + @defineChild('p:style') declare style?: ShapeStyle } diff --git a/src/openxml/presentation/EmbeddedFont.ts b/src/openxml/presentation/EmbeddedFont.ts index 858f9ef..5771a2c 100644 --- a/src/openxml/presentation/EmbeddedFont.ts +++ b/src/openxml/presentation/EmbeddedFont.ts @@ -6,9 +6,9 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:embeddedFont') export class EmbeddedFont extends OXML { - @defineChild('p:bold') bold?: OXML - @defineChild('p:boldItalic') boldItalic?: OXML + @defineChild('p:bold') declare bold?: OXML + @defineChild('p:boldItalic') declare boldItalic?: OXML @defineChild('p:font') declare font: Font - @defineChild('p:italic') italic?: OXML - @defineChild('p:regular') regular?: OXML + @defineChild('p:italic') declare italic?: OXML + @defineChild('p:regular') declare regular?: OXML } diff --git a/src/openxml/presentation/Font.ts b/src/openxml/presentation/Font.ts index 24e8613..3732d91 100644 --- a/src/openxml/presentation/Font.ts +++ b/src/openxml/presentation/Font.ts @@ -5,8 +5,8 @@ import { defineAttribute, defineElement, OXML } from '../../core' */ @defineElement('p:font') export class Font extends OXML { - @defineAttribute('charset') charset?: string - @defineAttribute('panose') panose?: string - @defineAttribute('pitchFamily') pitchFamily?: string - @defineAttribute('typeface') typeface?: string + @defineAttribute('charset') declare charset?: string + @defineAttribute('panose') declare panose?: string + @defineAttribute('pitchFamily') declare pitchFamily?: string + @defineAttribute('typeface') declare typeface?: string } diff --git a/src/openxml/presentation/GraphicFrame.ts b/src/openxml/presentation/GraphicFrame.ts index a3fb249..acf82bf 100644 --- a/src/openxml/presentation/GraphicFrame.ts +++ b/src/openxml/presentation/GraphicFrame.ts @@ -7,8 +7,8 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:graphicFrame') export class GraphicFrame extends OXML { - @defineChild('p:extLst') extLst?: ExtensionList - @defineChild('a:graphic') graphic?: OXML + @defineChild('p:extLst') declare extLst?: ExtensionList + @defineChild('a:graphic') declare graphic?: OXML @defineChild('p:nvGraphicFramePr') declare nvGraphicFramePr: OXML @defineChild('p:xfrm') declare xfrm: Transform2D } diff --git a/src/openxml/presentation/GroupShape.ts b/src/openxml/presentation/GroupShape.ts index 2fa90eb..c5d8176 100644 --- a/src/openxml/presentation/GroupShape.ts +++ b/src/openxml/presentation/GroupShape.ts @@ -11,9 +11,19 @@ export class GroupShape extends OXML { @defineChild('p:nvGrpSpPr') declare nvGrpSpPr: NonVisualGroupShapeProperties @defineChild('p:grpSpPr') declare grpSpPr: GroupShapeProperties - @defineProperty(['getElements']) declare elements: OXML[] + @defineProperty('_type') declare type: string + @defineProperty('nvSpPr.cNvPr.id') declare id?: string + @defineProperty('nvSpPr.cNvPr.name') declare name?: string + @defineProperty('grpSpPr.xfrm.off.x') declare left: number + @defineProperty('grpSpPr.xfrm.off.y') declare top: number + @defineProperty('grpSpPr.xfrm.ext.cx') declare width: number + @defineProperty('grpSpPr.xfrm.ext.cy') declare height: number + @defineProperty('grpSpPr.xfrm.chOff.x') declare childLeft: number + @defineProperty('grpSpPr.xfrm.chOff.y') declare childTop: number + @defineProperty('grpSpPr.xfrm.chExt.cx') declare childWidth: number + @defineProperty('grpSpPr.xfrm.chExt.cy') declare childHeight: number + @defineProperty('_elements') declare elements: OXML[] - getElements(): OXML[] { - return getElements(this.element.children) - } + protected get _type(): string { return 'groupShape' } + protected get _elements(): OXML[] { return getElements(this.element.children) } } diff --git a/src/openxml/presentation/GroupShapeProperties.ts b/src/openxml/presentation/GroupShapeProperties.ts index 3e93bd2..5d792c4 100644 --- a/src/openxml/presentation/GroupShapeProperties.ts +++ b/src/openxml/presentation/GroupShapeProperties.ts @@ -8,6 +8,6 @@ import { _Properties } from './_Properties' */ @defineElement('p:grpSpPr') export class GroupShapeProperties extends _Properties { - @defineChild('a:scene3d') scene3d?: OXML - @defineChild('a:xfrm') xfrm?: Transform2D + @defineChild('a:scene3d') declare scene3d?: OXML + @defineChild('a:xfrm') declare xfrm?: Transform2D } diff --git a/src/openxml/presentation/NonVisualDrawingProperties.ts b/src/openxml/presentation/NonVisualDrawingProperties.ts index 7fe7eb1..05e6ca8 100644 --- a/src/openxml/presentation/NonVisualDrawingProperties.ts +++ b/src/openxml/presentation/NonVisualDrawingProperties.ts @@ -6,13 +6,13 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:cNvPr') export class NonVisualDrawingProperties extends OXML { - @defineAttribute('id') id?: string - @defineAttribute('title') title?: string - @defineAttribute('name') name?: string - @defineAttribute('descr') descr?: string - @defineAttribute('hidden') hidden?: string + @defineAttribute('id') declare id?: string + @defineAttribute('title') declare title?: string + @defineAttribute('name') declare name?: string + @defineAttribute('descr') declare descr?: string + @defineAttribute('hidden') declare hidden?: string - @defineChild('a:extLst') extLst?: ExtensionList - @defineChild('a:hlinkClick') hlinkClick?: OXML - @defineChild('a:hlinkHover') hlinkHover?: OXML + @defineChild('a:extLst') declare extLst?: ExtensionList + @defineChild('a:hlinkClick') declare hlinkClick?: OXML + @defineChild('a:hlinkHover') declare hlinkHover?: OXML } diff --git a/src/openxml/presentation/NonVisualShapeDrawingProperties.ts b/src/openxml/presentation/NonVisualShapeDrawingProperties.ts index bd90ba4..3a06721 100644 --- a/src/openxml/presentation/NonVisualShapeDrawingProperties.ts +++ b/src/openxml/presentation/NonVisualShapeDrawingProperties.ts @@ -5,5 +5,5 @@ import { defineAttribute, defineElement, OXML } from '../../core' */ @defineElement('p:cNvSpPr') export class NonVisualShapeDrawingProperties extends OXML { - @defineAttribute('txBox', 'boolean') txBox?: boolean + @defineAttribute('txBox', 'boolean') declare txBox?: boolean } diff --git a/src/openxml/presentation/Picture.ts b/src/openxml/presentation/Picture.ts index 388f6f2..008ee38 100644 --- a/src/openxml/presentation/Picture.ts +++ b/src/openxml/presentation/Picture.ts @@ -14,6 +14,7 @@ export class Picture extends OXML { @defineChild('p:spPr') declare spPr: ShapeProperties @defineChild('p:style') declare style: ShapeStyle + @defineProperty('_type') declare type: string @defineProperty('nvPicPr.cNvPr.id') declare id: string @defineProperty('nvPicPr.cNvPr.name') declare name: string @defineProperty('spPr.xfrm.off.x') declare left: number @@ -21,4 +22,6 @@ export class Picture extends OXML { @defineProperty('spPr.xfrm.ext.cx') declare width: number @defineProperty('spPr.xfrm.ext.cy') declare height: number @defineProperty('blipFill.blip.rEmbed') declare rEmbed: string + + protected get _type(): string { return 'picture' } } diff --git a/src/openxml/presentation/PlaceholderShape.ts b/src/openxml/presentation/PlaceholderShape.ts index 1478f9f..0647e37 100644 --- a/src/openxml/presentation/PlaceholderShape.ts +++ b/src/openxml/presentation/PlaceholderShape.ts @@ -5,6 +5,6 @@ import { defineAttribute, defineElement, OXML } from '../../core' */ @defineElement('p:ph') export class PlaceholderShape extends OXML { - @defineAttribute('type') type?: string - @defineAttribute('idx') idx?: string + @defineAttribute('type') declare type?: string + @defineAttribute('idx') declare idx?: string } diff --git a/src/openxml/presentation/Presentation.ts b/src/openxml/presentation/Presentation.ts index 4e21f00..b747095 100644 --- a/src/openxml/presentation/Presentation.ts +++ b/src/openxml/presentation/Presentation.ts @@ -21,19 +21,19 @@ export class Presentation extends OXML { 'conformance': 'transitional', } - @defineChild('p:custDataLst') custDataLst?: OXML - @defineChild('p:custShowLst') custShowLst?: OXML + @defineChild('p:custDataLst') declare custDataLst?: OXML + @defineChild('p:custShowLst') declare custShowLst?: OXML @defineChild('p:defaultTextStyle') declare defaultTextStyle: DefaultTextStyle - @defineChild('p:embeddedFontLst') embeddedFontLst?: EmbeddedFontList - @defineChild('p:extLst') extLst?: OXML - @defineChild('p:handoutMasterIdLst') handoutMasterIdLst?: OXML - @defineChild('p:kinsoku') kinsoku?: OXML - @defineChild('p:modifyVerifier') modifyVerifier?: OXML - @defineChild('p:notesMasterIdLst') notesMasterIdLst?: OXML - @defineChild('p:notesSz') notesSz?: NotesSize - @defineChild('p:photoAlbum') photoAlbum?: OXML + @defineChild('p:embeddedFontLst') declare embeddedFontLst?: EmbeddedFontList + @defineChild('p:extLst') declare extLst?: OXML + @defineChild('p:handoutMasterIdLst') declare handoutMasterIdLst?: OXML + @defineChild('p:kinsoku') declare kinsoku?: OXML + @defineChild('p:modifyVerifier') declare modifyVerifier?: OXML + @defineChild('p:notesMasterIdLst') declare notesMasterIdLst?: OXML + @defineChild('p:notesSz') declare notesSz?: NotesSize + @defineChild('p:photoAlbum') declare photoAlbum?: OXML @defineChild('p:sldIdLst') declare sldIdLst: SlideIdList @defineChild('p:sldMasterIdLst') declare sldMasterIdLst: SlideMasterIdList @defineChild('p:sldSz') declare sldSz: SlideSize - @defineChild('p:smartTags') smartTags?: OXML + @defineChild('p:smartTags') declare smartTags?: OXML } diff --git a/src/openxml/presentation/Shape.ts b/src/openxml/presentation/Shape.ts index 9efc6ce..48d9ebb 100644 --- a/src/openxml/presentation/Shape.ts +++ b/src/openxml/presentation/Shape.ts @@ -15,24 +15,28 @@ export class Shape extends OXML { @defineChild('p:nvSpPr') declare nvSpPr: NonVisualShapeProperties @defineChild('p:spPr') declare spPr: ShapeProperties @defineChild('p:txBody') declare txBody: TextBody - @defineChild('p:style') style?: ShapeStyle + @defineChild('p:style') declare style?: ShapeStyle - @defineProperty('nvSpPr.cNvPr.id') id?: string - @defineProperty('nvSpPr.cNvPr.name') name?: string - @defineProperty('nvSpPr.nvPr.ph') placeholder?: PlaceholderShape + @defineProperty('_type') declare type: string + @defineProperty('nvSpPr.cNvPr.id') declare id?: string + @defineProperty('nvSpPr.cNvPr.name') declare name?: string + @defineProperty('nvSpPr.nvPr.ph') declare placeholder?: PlaceholderShape @defineProperty('nvSpPr.cNvSpPr.txBox') declare isTextBox: boolean @defineProperty('spPr.xfrm.off.x') declare left: number @defineProperty('spPr.xfrm.off.y') declare top: number @defineProperty('spPr.xfrm.ext.cx') declare width: number @defineProperty('spPr.xfrm.ext.cy') declare height: number - @defineProperty('txBody.bodyPr.lIns', 0) declare paddingLeft: number - @defineProperty('txBody.bodyPr.tIns', 0) declare paddingTop: number - @defineProperty('txBody.bodyPr.rIns', 0) declare paddingRight: number - @defineProperty('txBody.bodyPr.bIns', 0) declare paddingBottom: number - @defineProperty('txBody.bodyPr.rot', 0) declare textRotate: number - @defineProperty('txBody.bodyPr.wrap', 0) declare textWrap: TextWrappingValues + @defineProperty('spPr.ln') declare outline: Record + @defineProperty('txBody.bodyPr.lIns') declare paddingLeft: number + @defineProperty('txBody.bodyPr.tIns') declare paddingTop: number + @defineProperty('txBody.bodyPr.rIns') declare paddingRight: number + @defineProperty('txBody.bodyPr.bIns') declare paddingBottom: number + @defineProperty('txBody.bodyPr.rot') declare textRotate: number + @defineProperty('txBody.bodyPr.wrap') declare textWrap: TextWrappingValues @defineProperty('txBody.pList') declare paragraphs: Paragraph[] + protected get _type(): string { return 'shape' } + get schemeColor(): string | undefined { return this.spPr.solidFill?.schemeClr?.val } get color(): string | undefined { return this.spPr.solidFill?.srgbClr?.val } get alpha(): string | undefined { return this.spPr.solidFill?.srgbClr?.alpha?.val } diff --git a/src/openxml/presentation/ShapeProperties.ts b/src/openxml/presentation/ShapeProperties.ts index 87670d9..6d72b0a 100644 --- a/src/openxml/presentation/ShapeProperties.ts +++ b/src/openxml/presentation/ShapeProperties.ts @@ -13,10 +13,10 @@ import { _Properties } from './_Properties' */ @defineElement('p:spPr') export class ShapeProperties extends _Properties { - @defineChild('a:scene3d') scene3d?: OXML + @defineChild('a:scene3d') declare scene3d?: OXML @defineChild('a:xfrm') declare xfrm: Transform2D - @defineChild('a:prstGeom') prstGeom?: PresetGeometry - @defineChild('a:custGeom') custGeom?: CustomGeometry - @defineChild('a:ln') ln?: Outline - @defineChild('a:sp3d') sp3d?: OXML + @defineChild('a:prstGeom') declare prstGeom?: PresetGeometry + @defineChild('a:custGeom') declare custGeom?: CustomGeometry + @defineChild('a:ln') declare ln?: Outline + @defineChild('a:sp3d') declare sp3d?: OXML } diff --git a/src/openxml/presentation/ShapeStyle.ts b/src/openxml/presentation/ShapeStyle.ts index b1f53d4..37ab3ab 100644 --- a/src/openxml/presentation/ShapeStyle.ts +++ b/src/openxml/presentation/ShapeStyle.ts @@ -6,8 +6,8 @@ import { defineChild, defineElement, OXML } from '../../core' */ @defineElement('p:style') export class ShapeStyle extends OXML { - @defineChild('a:lnRef') lnRef?: LineReference - @defineChild('a:fillRef') fillRef?: FillReference - @defineChild('a:effectRef') effectRef?: EffectReference - @defineChild('a:fontRef') fontRef?: FontReference + @defineChild('a:lnRef') declare lnRef?: LineReference + @defineChild('a:fillRef') declare fillRef?: FillReference + @defineChild('a:effectRef') declare effectRef?: EffectReference + @defineChild('a:fontRef') declare fontRef?: FontReference } diff --git a/src/openxml/presentation/Slide.ts b/src/openxml/presentation/Slide.ts index 1a2b727..e2a6df4 100644 --- a/src/openxml/presentation/Slide.ts +++ b/src/openxml/presentation/Slide.ts @@ -1,5 +1,5 @@ import type { ColorMapOverride } from './ColorMapOverride' -import { defineChild, defineElement } from '../../core' +import { defineChild, defineElement, defineProperty } from '../../core' import { _Slide } from './_Slide' /** @@ -15,4 +15,8 @@ export class Slide extends _Slide { } @defineChild('p:clrMapOvr') declare clrMapOvr: ColorMapOverride + + @defineProperty('_type') declare type: string + + protected get _type(): string { return 'slide' } } diff --git a/src/openxml/presentation/SlideLayout.ts b/src/openxml/presentation/SlideLayout.ts index ea1e9d2..fcc774f 100644 --- a/src/openxml/presentation/SlideLayout.ts +++ b/src/openxml/presentation/SlideLayout.ts @@ -14,13 +14,13 @@ export class SlideLayout extends _Slide { 'xmlns:p': 'http://schemas.openxmlformats.org/presentationml/2006/main', } - @defineAttribute('matchingName') matchingName?: string - @defineAttribute('preserve', 'boolean') preserve?: boolean - @defineAttribute('showMasterPhAnim', 'boolean') showMasterPhAnim?: boolean - @defineAttribute('showMasterSp', 'boolean') showMasterSp?: boolean - @defineAttribute('type', 'ST_SlideLayoutType') type?: string - @defineAttribute('userDrawn', 'boolean') userDrawn?: boolean + @defineAttribute('matchingName') declare matchingName?: string + @defineAttribute('preserve', 'boolean') declare preserve?: boolean + @defineAttribute('showMasterPhAnim', 'boolean') declare showMasterPhAnim?: boolean + @defineAttribute('showMasterSp', 'boolean') declare showMasterSp?: boolean + @defineAttribute('type', 'ST_SlideLayoutType') declare type?: string + @defineAttribute('userDrawn', 'boolean') declare userDrawn?: boolean @defineChild('p:clrMapOvr') declare clrMapOvr: ColorMapOverride - @defineChild('p:hf') hf?: OXML + @defineChild('p:hf') declare hf?: OXML } diff --git a/src/openxml/presentation/SlideMaster.ts b/src/openxml/presentation/SlideMaster.ts index 5af90be..f0d11ed 100644 --- a/src/openxml/presentation/SlideMaster.ts +++ b/src/openxml/presentation/SlideMaster.ts @@ -14,10 +14,10 @@ export class SlideMaster extends _Slide { 'xmlns:p': 'http://schemas.openxmlformats.org/presentationml/2006/main', } - @defineAttribute('preserve', 'boolean') preserve?: boolean + @defineAttribute('preserve', 'boolean') declare preserve?: boolean @defineChild('p:clrMap') declare clrMap: ColorMap - @defineChild('p:hf') hf?: OXML + @defineChild('p:hf') declare hf?: OXML @defineChild('p:sldLayoutIdLst') declare sldLayoutIdLst: OXML @defineChild('p:txStyles') declare txStyles: OXML } diff --git a/src/openxml/presentation/TextBody.ts b/src/openxml/presentation/TextBody.ts index 3310c04..a994feb 100644 --- a/src/openxml/presentation/TextBody.ts +++ b/src/openxml/presentation/TextBody.ts @@ -7,6 +7,6 @@ import { defineChild, defineChildren, defineElement, OXML } from '../../core' @defineElement('p:txBody') export class TextBody extends OXML { @defineChild('a:bodyPr') declare bodyPr: BodyProperties - @defineChild('a:lstStyle') lstStyle?: ListStyle + @defineChild('a:lstStyle') declare lstStyle?: ListStyle @defineChildren('a:p') declare pList: Paragraph[] } diff --git a/src/openxml/presentation/_Slide.ts b/src/openxml/presentation/_Slide.ts index 75cc61b..69758d1 100644 --- a/src/openxml/presentation/_Slide.ts +++ b/src/openxml/presentation/_Slide.ts @@ -13,9 +13,7 @@ export class _Slide extends OXML { @defineProperty('cSld.spTree.nvGrpSpPr.cNvPr.id') declare id: string @defineProperty('cSld.spTree.nvGrpSpPr.cNvPr.name') declare name: string - @defineProperty(['getElements']) declare elements: OXML[] + @defineProperty('_elements') declare elements: OXML[] - getElements(): OXML[] { - return getElements(this.cSld.spTree.element.children) - } + get _elements(): OXML[] { return getElements(this.cSld.spTree.element.children) } }