diff --git a/src/core/OXML.ts b/src/core/OXML.ts index 4e10e01..e54af1d 100644 --- a/src/core/OXML.ts +++ b/src/core/OXML.ts @@ -24,19 +24,15 @@ export interface OXMLChildDefinition { export interface OXMLDefinition { tag?: string namespace?: string - attributes?: Record - properties?: Record - children?: OXMLChildDefinition[] + attributes: Record + properties: Record + children: OXMLChildDefinition[] } export function defineElement(tag: string) { return (constructor: any) => { const proto = constructor.prototype - let definition = OXML.protoToDefinition.get(proto) - if (!definition) { - definition = {} as OXMLDefinition - OXML.protoToDefinition.set(proto, definition) - } + const definition = OXML.makeDefinition(proto) const tagArr = tag.split(':') definition.tag = tag definition.namespace = tagArr.length > 1 ? tagArr[0] : undefined @@ -55,12 +51,7 @@ export function defineAttribute( defaultValue?: any, ) { return function (proto: any, name: any) { - let definition = OXML.protoToDefinition.get(proto) - if (!definition) { - definition = {} as OXMLDefinition - OXML.protoToDefinition.set(proto, definition) - } - definition.attributes ??= {} + const definition = OXML.makeDefinition(proto) definition.attributes[attrName] = { name, alias: attrName, type, defaultValue } Object.defineProperty(proto, name, { get() { @@ -72,31 +63,26 @@ export function defineAttribute( } } -export function defineProperty(propName: string) { +export function defineProperty(aliasName?: string) { return function (proto: any, name: any) { - let definition = OXML.protoToDefinition.get(proto) - if (!definition) { - definition = {} as OXMLDefinition - OXML.protoToDefinition.set(proto, definition) + const alias = aliasName ?? name + const definition = OXML.makeDefinition(proto) + definition.properties[alias] = { name, alias } + if (name !== alias) { + Object.defineProperty(proto, name, { + get() { + return (this as OXML).offsetGet(alias) + }, + configurable: true, + enumerable: true, + }) } - definition.properties ??= {} - definition.properties[propName] = { name, alias: propName } - Object.defineProperty(proto, name, { - get() { - return (this as OXML).offsetGet(propName) - }, - }) } } export function defineChild(tag: string, defaultValue?: any, isArray = false) { return function (proto: any, name: any) { - let definition = OXML.protoToDefinition.get(proto) - if (!definition) { - definition = {} as OXMLDefinition - OXML.protoToDefinition.set(proto, definition) - } - definition.children ??= [] + const definition = OXML.makeDefinition(proto) definition.children.push({ tag, defaultValue, isArray }) Object.defineProperty(proto, name, { get() { @@ -126,13 +112,28 @@ export class OXML { return this.tagToConstructor.get(tag) } + static makeDefinition(proto: any): OXMLDefinition { + let definition = OXML.protoToDefinition.get(proto) + if (!definition) { + definition = { + attributes: {}, + properties: { + tag: { name: 'tag', alias: 'tag' }, + }, + children: [], + } as unknown as OXMLDefinition + OXML.protoToDefinition.set(proto, definition) + } + return definition + } + 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) + definition = deepMerge(definition ?? {}, _definition) as any } cur = Object.getPrototypeOf(cur) } @@ -196,19 +197,28 @@ export class OXML { case 'boolean': return !!value case 'degree': + case 'ST_Angle': return Number(value) / 60000 case 'fontSize': return Number(value) / 100 case 'number': + case 'SByteValue': return Number(value) case 'string': + case 'HexBinaryValue': + case 'StringValue': return String(value) case 'emu': + case 'ST_Coordinate32': + case 'ST_AdjCoordinate': return (Number(value) / 914400) * OXML.DPI case 'dxa': return (Number(value) / 1440) * OXML.DPI case 'percentage': + case 'ST_TextSpacingPercentOrPercentString': return Number(value) / 1000 + case 'ST_TextSpacingPoint': + return Number(value) / 100 case 'rate': return Number(value) / 100000 case 'lineHeight': @@ -335,19 +345,6 @@ export class OXML { } }) } - definition?.children?.forEach((child) => { - child.tag - }) - return { - ...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()] - // })), - // } + return properties } } diff --git a/src/openxml/drawing/BlipFill.ts b/src/openxml/drawing/BlipFill.ts index 019f73f..680dde4 100644 --- a/src/openxml/drawing/BlipFill.ts +++ b/src/openxml/drawing/BlipFill.ts @@ -12,8 +12,8 @@ export class BlipFill extends OXML { @defineAttribute('rotWithShape', 'boolean') declare rotWithShape?: boolean @defineAttribute('dpi', 'number') declare dpi?: number - @defineChild('a:blip') declare blip: Blip - @defineChild('a:srcRect') declare srcRect: SourceRectangle - @defineChild('a:stretch') declare stretch: Stretch - @defineChild('a:tile') declare tile: Tile + @defineChild('a:blip') declare blip?: Blip + @defineChild('a:srcRect') declare srcRect?: SourceRectangle + @defineChild('a:stretch') declare stretch?: Stretch + @defineChild('a:tile') declare tile?: Tile } diff --git a/src/openxml/drawing/BodyProperties.ts b/src/openxml/drawing/BodyProperties.ts index faf3638..a3f7504 100644 --- a/src/openxml/drawing/BodyProperties.ts +++ b/src/openxml/drawing/BodyProperties.ts @@ -1,20 +1,34 @@ -import type { TextWrappingValues } from './TextWrappingValues' +import type { + TextAnchoringTypeValues, + TextHorizontalOverflowValues, + TextVerticalOverflowValues, + TextVerticalValues, + TextWrappingValues, +} from './_types' import { defineAttribute, defineElement, OXML } from '../../core' -import { TextAnchoringTypeValues } from './TextAnchoringTypeValues' /** * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.bodyproperties */ @defineElement('a:bodyPr') export class BodyProperties extends OXML { - @defineAttribute('anchor', TextAnchoringTypeValues) declare anchor?: TextAnchoringTypeValues + @defineAttribute('anchor') declare anchor?: TextAnchoringTypeValues @defineAttribute('anchorCtr', 'boolean') declare anchorCtr?: boolean + @defineAttribute('bIns', 'ST_Coordinate32') declare bIns?: number + @defineAttribute('numCol', 'ST_TextColumnCount') declare numCol?: number + @defineAttribute('spcCol', 'ST_PositiveCoordinate32') declare spcCol?: number + @defineAttribute('compatLnSpc', 'boolean') declare compatLnSpc?: boolean + @defineAttribute('forceAA', 'boolean') declare forceAA?: boolean + @defineAttribute('fromWordArt', 'boolean') declare fromWordArt?: boolean + @defineAttribute('horzOverflow') declare horzOverflow?: TextHorizontalOverflowValues + @defineAttribute('lIns', 'ST_Coordinate32') declare lIns?: number + @defineAttribute('rIns', 'ST_Coordinate32') declare rIns?: number + @defineAttribute('rtlCol', 'boolean') declare rtlCol?: boolean + @defineAttribute('rot', 'ST_Angle') declare rot?: number + @defineAttribute('tIns', 'ST_Coordinate32') declare tIns?: number + @defineAttribute('upright', 'boolean') declare upright?: 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('vert') declare vert?: TextVerticalValues + @defineAttribute('vertOverflow') declare vertOverflow?: TextVerticalOverflowValues @defineAttribute('wrap') declare wrap?: TextWrappingValues - @defineAttribute('upright', 'boolean') declare upright?: boolean } diff --git a/src/openxml/drawing/Break.ts b/src/openxml/drawing/Break.ts new file mode 100644 index 0000000..a56f45f --- /dev/null +++ b/src/openxml/drawing/Break.ts @@ -0,0 +1,9 @@ +import { defineElement, OXML } from '../../core' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.break + */ +@defineElement('a:br') +export class Break extends OXML { + // +} diff --git a/src/openxml/drawing/ComplexScriptFont.ts b/src/openxml/drawing/ComplexScriptFont.ts new file mode 100644 index 0000000..e3f94bc --- /dev/null +++ b/src/openxml/drawing/ComplexScriptFont.ts @@ -0,0 +1,10 @@ +import { defineElement } from '../../core' +import { _Font } from './_Font' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.complexscriptfont + */ +@defineElement('a:cs') +export class ComplexScriptFont extends _Font { + // +} diff --git a/src/openxml/drawing/EastAsianFont.ts b/src/openxml/drawing/EastAsianFont.ts new file mode 100644 index 0000000..0ef5a6c --- /dev/null +++ b/src/openxml/drawing/EastAsianFont.ts @@ -0,0 +1,10 @@ +import { defineElement } from '../../core' +import { _Font } from './_Font' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.eastasianfont + */ +@defineElement('a:ea') +export class EastAsianFont extends _Font { + // +} diff --git a/src/openxml/drawing/EndParagraphRunProperties.ts b/src/openxml/drawing/EndParagraphRunProperties.ts new file mode 100644 index 0000000..dda36f9 --- /dev/null +++ b/src/openxml/drawing/EndParagraphRunProperties.ts @@ -0,0 +1,9 @@ +import { defineElement, OXML } from '../../core' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.endparagraphrunproperties + */ +@defineElement('a:endParaRPr') +export class EndParagraphRunProperties extends OXML { + // TODO +} diff --git a/src/openxml/drawing/Field.ts b/src/openxml/drawing/Field.ts new file mode 100644 index 0000000..c7c1ae0 --- /dev/null +++ b/src/openxml/drawing/Field.ts @@ -0,0 +1,10 @@ +import { defineAttribute, defineElement, OXML } from '../../core' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.field + */ +@defineElement('a:fld') +export class Field extends OXML { + @defineAttribute('id') declare id?: string + @defineAttribute('type') declare type?: string +} diff --git a/src/openxml/drawing/LatinFont.ts b/src/openxml/drawing/LatinFont.ts new file mode 100644 index 0000000..53b38d8 --- /dev/null +++ b/src/openxml/drawing/LatinFont.ts @@ -0,0 +1,10 @@ +import { defineElement } from '../../core' +import { _Font } from './_Font' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.latinfont + */ +@defineElement('a:latin') +export class LatinFont extends _Font { + // +} diff --git a/src/openxml/drawing/LineSpacing.ts b/src/openxml/drawing/LineSpacing.ts new file mode 100644 index 0000000..f1ab399 --- /dev/null +++ b/src/openxml/drawing/LineSpacing.ts @@ -0,0 +1,12 @@ +import type { SpacingPercent } from './SpacingPercent' +import type { SpacingPoints } from './SpacingPoints' +import { defineChild, defineElement, OXML } from '../../core' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.linespacing + */ +@defineElement('a:lnSpc') +export class LineSpacing extends OXML { + @defineChild('a:spcPct') declare spcPct?: SpacingPercent + @defineChild('a:spcPts') declare spcPts?: SpacingPoints +} diff --git a/src/openxml/drawing/Paragraph.ts b/src/openxml/drawing/Paragraph.ts index 637e618..dfd6888 100644 --- a/src/openxml/drawing/Paragraph.ts +++ b/src/openxml/drawing/Paragraph.ts @@ -1,22 +1,51 @@ -import type { TextAlignmentTypeValues } from './TextAlignmentTypeValues' +import type { Break } from './Break' +import type { EndParagraphRunProperties } from './EndParagraphRunProperties' +import type { Field } from './Field' +import type { ParagraphProperties } from './ParagraphProperties' +import type { Run } from './Run' import { defineChild, defineElement, defineProperty, OXML } from '../../core' -import { ParagraphProperties } from './ParagraphProperties' -import { Run } from './Run' /** * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.paragraph */ @defineElement('a:p') export class Paragraph extends OXML { - @defineChild('p:pPr', ParagraphProperties) declare pPr: ParagraphProperties - @defineChild('p:r', Run) declare rList: Run[] + @defineChild('a:fld') declare fld?: Field + @defineChild('a:pPr') declare pPr: ParagraphProperties - @defineProperty('pPr.marL', 0) declare marginLeft: number - @defineProperty('pPr.marR', 0) declare marginRight: number - @defineProperty('pPr.indent', 0) declare textIndent: number + @defineProperty() style = new _ParagraphStyle(this) @defineProperty('pPr.lvl') declare level?: number @defineProperty('pPr.fontAlgn') declare fontAlign?: string + @defineProperty('_children') declare children?: (Break | Run | EndParagraphRunProperties)[] - get textAlign(): TextAlignmentTypeValues | undefined { return this.pPr.algn } - get rightToLeft(): string | undefined { return this.pPr.rtl } + get _children(): (Break | Run | EndParagraphRunProperties)[] { + return Array.from(this.element.children).map((element) => { + switch (element.tagName) { + case 'a:fld': + case 'a:pPr': + return undefined + case 'a:br': + case 'a:r': + case 'a:endParaRPr': + default: + return OXML.make(element) + } + }).filter(Boolean) as any + } +} + +export class _ParagraphStyle extends OXML { + @defineProperty('_parent.pPr.marL') declare marginLeft?: number + @defineProperty('_parent.pPr.marR') declare marginRight?: number + @defineProperty('_parent.pPr.indent') declare textIndent: number + @defineProperty('_parent.pPr.lnSpc.spcPct.val') declare lineHeight?: number + + get textAlign() { return this._parent.pPr.algn } + get rightToLeft(): string | undefined { return this._parent.pPr.rtl } + + constructor( + protected _parent: Paragraph, + ) { + super() + } } diff --git a/src/openxml/drawing/ParagraphProperties.ts b/src/openxml/drawing/ParagraphProperties.ts index bccd7ef..a046ccf 100644 --- a/src/openxml/drawing/ParagraphProperties.ts +++ b/src/openxml/drawing/ParagraphProperties.ts @@ -1,16 +1,39 @@ -import { defineAttribute, defineElement, OXML } from '../../core' -import { TextAlignmentTypeValues } from './TextAlignmentTypeValues' +import type { TextAlignmentTypeValues, TextFontAlignmentValues } from './_types' +import type { LineSpacing } from './LineSpacing' +import { defineAttribute, defineChild, defineElement, OXML } from '../../core' /** * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.paragraphproperties */ @defineElement('a:pPr') export class ParagraphProperties extends OXML { - @defineAttribute('lvl', 'number') declare lvl?: number + @defineAttribute('algn') declare algn?: TextAlignmentTypeValues + @defineAttribute('defTabSz', 'emu') declare defTabSz?: number + @defineAttribute('eaLnBrk', 'boolean') declare eaLnBrk?: boolean + @defineAttribute('fontAlgn') declare fontAlgn?: TextFontAlignmentValues + @defineAttribute('hangingPunct', 'boolean') declare hangingPunct?: boolean + @defineAttribute('indent', 'emu') declare indent?: number + @defineAttribute('latinLnBrk', 'boolean') declare latinLnBrk?: boolean @defineAttribute('marL', 'emu') declare marL?: number + @defineAttribute('lvl', 'number') declare lvl?: 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 + @defineAttribute('rtl', 'boolean') declare rtl?: boolean + + @defineChild('a:buAutoNum') declare buAutoNum?: OXML + @defineChild('a:buBlip') declare buBlip?: OXML + @defineChild('a:buChar') declare buChar?: OXML + @defineChild('a:buClr') declare buClr?: OXML + @defineChild('a:buClrTx') declare buClrTx?: OXML + @defineChild('a:buFont') declare buFont?: OXML + @defineChild('a:buFontTx') declare buFontTx?: OXML + @defineChild('a:buNone') declare buNone?: OXML + @defineChild('a:buSzPct') declare buSzPct?: OXML + @defineChild('a:buSzPts') declare buSzPts?: OXML + @defineChild('a:buSzTx') declare buSzTx?: OXML + @defineChild('a:defRPr') declare defRPr?: OXML + @defineChild('a:extLst') declare extLst?: OXML + @defineChild('a:lnSpc') declare lnSpc?: LineSpacing + @defineChild('a:spcAft') declare spcAft?: OXML + @defineChild('a:spcBef') declare spcBef?: OXML + @defineChild('a:tabLst') declare tabLst?: OXML } diff --git a/src/openxml/drawing/Run.ts b/src/openxml/drawing/Run.ts index da83da6..1d9b5e9 100644 --- a/src/openxml/drawing/Run.ts +++ b/src/openxml/drawing/Run.ts @@ -10,17 +10,73 @@ export class Run extends OXML { @defineChild('a:rPr') declare rPr: RunProperties @defineChild('a:t') declare t: Text - @defineProperty('rPr.b', false) declare bold: boolean - @defineProperty('rPr.i', false) declare italic: boolean - @defineProperty('rPr.u', false) declare underline: boolean - @defineProperty('rPr.sz', 0) declare fontSize: number - @defineProperty('rPr.spc', 0) declare letterSpacing: number + @defineProperty() style = new _RunStyle(this) + @defineProperty('_content') declare content: string get color(): string | undefined { return this.rPr.solidFill?.srgbClr.val } get textIndent(): string | undefined { return this.rPr.kern } - get fontComplexScript(): string | undefined { return this.rPr.cs?.typeface } - get fontEastasian(): string | undefined { return this.rPr.ea?.typeface } - get fontLatin(): string | undefined { return this.rPr.latin?.typeface } - get fontSymbol(): string | undefined { return this.rPr.sym?.typeface } - get textContent(): string { return this.t.element.textContent ?? '' } + protected get _content(): string { return this.t.element.textContent ?? '' } +} + +export class _RunStyle extends OXML { + @defineProperty('_fontWeight') declare fontWeight?: 700 + @defineProperty('_fontStyle') declare fontStyle?: 'italic' + @defineProperty('_fontFamily') declare fontFamily?: string + @defineProperty('_textTransform') declare textTransform?: 'uppercase' | 'lowercase' + @defineProperty('_textDecoration') declare textDecoration?: 'underline' + @defineProperty('_parent.rPr.sz') declare fontSize?: number + @defineProperty('_parent.rPr.spc') declare letterSpacing?: number + + protected get _fontFamily(): string | undefined { + const rPr = this._parent.rPr + return rPr.cs?.typeface + ?? rPr.ea?.typeface + ?? rPr.latin?.typeface + ?? rPr.sym?.typeface + } + + protected get _fontWeight(): 700 | undefined { + switch (this._parent.rPr.b) { + case true: + return 700 + default: + return undefined + } + } + + protected get _fontStyle(): 'italic' | undefined { + switch (this._parent.rPr.i) { + case true: + return 'italic' + default: + return undefined + } + } + + protected get _textTransform(): 'uppercase' | 'lowercase' | undefined { + switch (this._parent.rPr.cap) { + case 'all': + return 'uppercase' + case 'small': + return 'lowercase' + case 'none': + default: + return undefined + } + } + + protected get _textDecoration(): 'underline' | undefined { + if (this._parent.rPr.u && this._parent.rPr.u !== 'none') { + return 'underline' + } + else { + return undefined + } + } + + constructor( + protected _parent: Run, + ) { + super() + } } diff --git a/src/openxml/drawing/RunProperties.ts b/src/openxml/drawing/RunProperties.ts index 9771b2a..4a0ef5d 100644 --- a/src/openxml/drawing/RunProperties.ts +++ b/src/openxml/drawing/RunProperties.ts @@ -1,35 +1,56 @@ -import type { SolidFill } from './SolidFill' -import { defineAttribute, defineChild, defineElement, OXML } from '../../core' +import type { OXML } from '../../core' +import type { TextCapsValues, TextStrikeValues, TextUnderlineValues } from './_types' +import type { ComplexScriptFont } from './ComplexScriptFont' +import type { EastAsianFont } from './EastAsianFont' +import type { EffectDag } from './EffectDag' +import type { EffectList } from './EffectList' +import type { ExtensionList } from './ExtensionList' +import type { LatinFont } from './LatinFont' +import type { Outline } from './Outline' +import type { SymbolFont } from './SymbolFont' +import { defineAttribute, defineChild, defineElement } from '../../core' +import { _Fill } from './_Fill' /** * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.runproperties */ @defineElement('a:rPr') -export class RunProperties extends OXML { +export class RunProperties extends _Fill { @defineAttribute('altLang') declare altLang?: string - @defineAttribute('baseline') declare baseline?: string + @defineAttribute('baseline', 'number') declare baseline?: number @defineAttribute('b', 'boolean') declare b?: boolean @defineAttribute('bmk') declare bmk?: string - @defineAttribute('cap') declare cap?: string - @defineAttribute('dirty') declare dirty?: string + @defineAttribute('cap') declare cap?: TextCapsValues + @defineAttribute('dirty', 'boolean') declare dirty?: boolean @defineAttribute('sz', 'fontSize') declare sz?: number @defineAttribute('i', 'boolean') declare i?: boolean @defineAttribute('kern', 'emu') declare kern?: string - @defineAttribute('kumimoji') declare kumimoji?: string + @defineAttribute('kumimoji', 'boolean') declare kumimoji?: boolean @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('noProof', 'boolean') declare noProof?: boolean + @defineAttribute('normalizeH', 'boolean') declare normalizeH?: boolean + @defineAttribute('smtClean', 'boolean') declare smtClean?: boolean + @defineAttribute('smtId', 'number') declare smtId?: number @defineAttribute('spc', 'fontSize') declare spc?: number - @defineAttribute('err') declare err?: string - @defineAttribute('strike') declare strike?: string - @defineAttribute('u') declare u?: string + @defineAttribute('err', 'boolean') declare err?: boolean + @defineAttribute('strike') declare strike?: TextStrikeValues + @defineAttribute('u') declare u?: TextUnderlineValues - @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 + @defineChild('a:cs') declare cs?: ComplexScriptFont + @defineChild('a:ea') declare ea?: EastAsianFont + @defineChild('a:effectDag') declare effectDag?: EffectDag + @defineChild('a:effectLst') declare effectLst?: EffectList + @defineChild('a:extLst') declare extLst?: ExtensionList + @defineChild('a:highlight') declare highlight?: OXML + @defineChild('a:hlinkClick') declare hlinkClick?: OXML + @defineChild('a:hlinkMouseOver') declare hlinkMouseOver?: OXML + @defineChild('a:latin') declare latin?: LatinFont + @defineChild('a:ln') declare ln?: Outline + @defineChild('a:rtl') declare rtl?: OXML + @defineChild('a:sym') declare sym?: SymbolFont + @defineChild('a:uFill') declare uFill?: OXML + @defineChild('a:uFillTx') declare uFillTx?: OXML + @defineChild('a:uLn') declare uLn?: OXML + @defineChild('a:uLnTx') declare uLnTx?: OXML + @defineChild('a:lnSpc') declare lnSpc?: OXML } diff --git a/src/openxml/drawing/SpacingPercent.ts b/src/openxml/drawing/SpacingPercent.ts new file mode 100644 index 0000000..91595c7 --- /dev/null +++ b/src/openxml/drawing/SpacingPercent.ts @@ -0,0 +1,9 @@ +import { defineAttribute, defineElement, OXML } from '../../core' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.spacingpercent + */ +@defineElement('a:spcPct') +export class SpacingPercent extends OXML { + @defineAttribute('val', 'ST_TextSpacingPercentOrPercentString') declare val: number +} diff --git a/src/openxml/drawing/SpacingPoints.ts b/src/openxml/drawing/SpacingPoints.ts new file mode 100644 index 0000000..28afee9 --- /dev/null +++ b/src/openxml/drawing/SpacingPoints.ts @@ -0,0 +1,9 @@ +import { defineAttribute, defineElement, OXML } from '../../core' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.spacingpoints + */ +@defineElement('a:spcPts') +export class SpacingPoints extends OXML { + @defineAttribute('val', 'ST_TextSpacingPoint') declare val: number +} diff --git a/src/openxml/drawing/SymbolFont.ts b/src/openxml/drawing/SymbolFont.ts new file mode 100644 index 0000000..f95f574 --- /dev/null +++ b/src/openxml/drawing/SymbolFont.ts @@ -0,0 +1,10 @@ +import { defineElement } from '../../core' +import { _Font } from './_Font' + +/** + * https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.symbolfont + */ +@defineElement('a:sym') +export class SymbolFont extends _Font { + // +} diff --git a/src/openxml/drawing/TextAlignmentTypeValues.ts b/src/openxml/drawing/TextAlignmentTypeValues.ts deleted file mode 100644 index 05be6a4..0000000 --- a/src/openxml/drawing/TextAlignmentTypeValues.ts +++ /dev/null @@ -1,9 +0,0 @@ -export enum TextAlignmentTypeValues { - ctr = 'center', - dist = 'distributed', - just = 'justified', - justLow = 'justified-low', - l = 'left', - r = 'right', - thaiDist = 'thai-distributed', -} diff --git a/src/openxml/drawing/TextAnchoringTypeValues.ts b/src/openxml/drawing/TextAnchoringTypeValues.ts deleted file mode 100644 index a094d9e..0000000 --- a/src/openxml/drawing/TextAnchoringTypeValues.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum TextAnchoringTypeValues { - ctr = 'middle', - b = 'bottom', - t = 'top', -} diff --git a/src/openxml/drawing/TextWrappingValues.ts b/src/openxml/drawing/TextWrappingValues.ts deleted file mode 100644 index ef792cc..0000000 --- a/src/openxml/drawing/TextWrappingValues.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum TextWrappingValues { - none = 'none', - square = 'square', -} diff --git a/src/openxml/drawing/Transform2D.ts b/src/openxml/drawing/Transform2D.ts index 0770364..624f180 100644 --- a/src/openxml/drawing/Transform2D.ts +++ b/src/openxml/drawing/Transform2D.ts @@ -9,7 +9,7 @@ import { defineAttribute, defineChild, defineElement, OXML } from '../../core' */ @defineElement('a:xfrm') export class Transform2D extends OXML { - @defineAttribute('rot', 'degree') declare rot: number + @defineAttribute('rot', 'ST_Angle') declare rot: number @defineAttribute('flipV', 'boolean') declare flipV: boolean @defineAttribute('flipH', 'boolean') declare flipH: boolean diff --git a/src/openxml/drawing/_Fill.ts b/src/openxml/drawing/_Fill.ts new file mode 100644 index 0000000..6f30f87 --- /dev/null +++ b/src/openxml/drawing/_Fill.ts @@ -0,0 +1,16 @@ +import type { BlipFill } from './BlipFill' +import type { GradientFill } from './GradientFill' +import type { GroupFill } from './GroupFill' +import type { NoFill } from './NoFill' +import type { PatternFill } from './PatternFill' +import type { SolidFill } from './SolidFill' +import { defineChild, OXML } from '../../core' + +export class _Fill extends OXML { + @defineChild('a:noFill') declare noFill?: NoFill + @defineChild('a:blipFill') declare blipFill?: BlipFill + @defineChild('a:gradFill') declare gradFill?: GradientFill + @defineChild('a:grpFill') declare grpFill?: GroupFill + @defineChild('a:pattFill') declare pattFill?: PatternFill + @defineChild('a:solidFill') declare solidFill?: SolidFill +} diff --git a/src/openxml/drawing/_Font.ts b/src/openxml/drawing/_Font.ts new file mode 100644 index 0000000..624c77e --- /dev/null +++ b/src/openxml/drawing/_Font.ts @@ -0,0 +1,8 @@ +import { defineAttribute, OXML } from '../../core' + +export class _Font extends OXML { + @defineAttribute('charset', 'SByteValue') declare charset?: number + @defineAttribute('panose', 'HexBinaryValue') declare panose?: string + @defineAttribute('pitchFamily', 'SByteValue') declare pitchFamily?: number + @defineAttribute('typeface', 'StringValue') declare typeface?: string +} diff --git a/src/openxml/drawing/_types.ts b/src/openxml/drawing/_types.ts new file mode 100644 index 0000000..49cd0e8 --- /dev/null +++ b/src/openxml/drawing/_types.ts @@ -0,0 +1,102 @@ +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textwrappingvalues + */ +export type TextWrappingValues = + | 'none' + | 'square' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.texthorizontaloverflowvalues + */ +export type TextHorizontalOverflowValues = + | 'clip' + | 'overflow' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textverticalvalues + */ +export type TextVerticalValues = + | 'eaVert' + | 'horz' + | 'mongolianVert' + | 'vert' + | 'vert270' + | 'wordArtVertRtl' + | 'wordArtVert' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textverticaloverflowvalues + */ +export type TextVerticalOverflowValues = + | 'clip' + | 'ellipsis' + | 'overflow' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textanchoringtypevalues + */ +export type TextAnchoringTypeValues = + | 'ctr' + | 'b' + | 't' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textalignmenttypevalues + */ +export type TextAlignmentTypeValues = + | 'ctr' + | 'dist' + | 'just' + | 'justLow' + | 'l' + | 'r' + | 'thaiDist' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textfontalignmentvalues + */ +export type TextFontAlignmentValues = + | 'auto' + | 'base' + | 'b' + | 'ctr' + | 't' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textcapsvalues + */ +export type TextCapsValues = + | 'all' + | 'none' + | 'small' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textstrikevalues + */ +export type TextStrikeValues = + | 'dblStrike' + | 'noStrike' + | 'sngStrike' + +/** + * @link https://learn.microsoft.com/dotnet/api/documentformat.openxml.drawing.textunderlinevalues + */ +export type TextUnderlineValues = + | 'dash' + | 'dashHeavy' + | 'dashLong' + | 'dashLongHeavy' + | 'dotDash' + | 'dotDashHeavy' + | 'dotDotDash' + | 'dotDotDashHeavy' + | 'dotted' + | 'dbl' + | 'heavy' + | 'dottedHeavy' + | 'none' + | 'sng' + | 'wavy' + | 'wavyDbl' + | 'wavyHeavy' + | 'words' diff --git a/src/openxml/drawing/index.ts b/src/openxml/drawing/index.ts index fbbded9..4433eba 100644 --- a/src/openxml/drawing/index.ts +++ b/src/openxml/drawing/index.ts @@ -1,6 +1,9 @@ export * from './_Color' +export * from './_Fill' +export * from './_Font' export * from './_ParagraphProperties' export * from './_Style' +export * from './_types' export * from './AdjustHandleList' export * from './AdjustValueList' export * from './ArcTo' @@ -9,18 +12,24 @@ export * from './BackgroundColor' export * from './Blip' export * from './BlipFill' export * from './BodyProperties' +export * from './Break' export * from './ChildExtents' export * from './ChildOffset' export * from './CloseShapePath' +export * from './ComplexScriptFont' export * from './ConnectionSiteList' export * from './CubicBezierCurveTo' export * from './CustomGeometry' +export * from './EastAsianFont' export * from './EffectDag' export * from './EffectList' export * from './EffectReference' +export * from './EndParagraphRunProperties' export * from './Extension' export * from './ExtensionList' export * from './Extents' +export * from './Field' +export * from './Field' export * from './FillReference' export * from './FontReference' export * from './ForegroundColor' @@ -29,8 +38,10 @@ export * from './GradientStop' export * from './GradientStopList' export * from './GroupFill' export * from './HslColor' +export * from './LatinFont' export * from './LinearGradientFill' export * from './LineReference' +export * from './LineSpacing' export * from './LineTo' export * from './ListStyle' export * from './MasterColorMapping' @@ -53,12 +64,12 @@ export * from './ShapeGuide' export * from './ShapeGuideList' export * from './SolidFill' export * from './SourceRectangle' +export * from './SpacingPercent' +export * from './SpacingPoints' export * from './Stretch' +export * from './SymbolFont' export * from './SystemColor' export * from './Text' -export * from './TextAlignmentTypeValues' -export * from './TextAnchoringTypeValues' -export * from './TextWrappingValues' export * from './Theme' export * from './Tile' export * from './TileRectangle' diff --git a/src/openxml/presentation/GroupShape.ts b/src/openxml/presentation/GroupShape.ts index c5d8176..60a009c 100644 --- a/src/openxml/presentation/GroupShape.ts +++ b/src/openxml/presentation/GroupShape.ts @@ -1,7 +1,6 @@ import type { GroupShapeProperties } from './GroupShapeProperties' import type { NonVisualGroupShapeProperties } from './NonVisualGroupShapeProperties' import { defineChild, defineElement, defineProperty, OXML } from '../../core' -import { getElements } from './_utils' /** * https://learn.microsoft.com/dotnet/api/documentformat.openxml.presentation.groupshape @@ -11,19 +10,33 @@ export class GroupShape extends OXML { @defineChild('p:nvGrpSpPr') declare nvGrpSpPr: NonVisualGroupShapeProperties @defineChild('p:grpSpPr') declare grpSpPr: GroupShapeProperties - @defineProperty('_type') declare type: string + @defineProperty() type = 'groupShape' @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() style = new _GroupShapeStyle(this) @defineProperty('_elements') declare elements: OXML[] - protected get _type(): string { return 'groupShape' } - protected get _elements(): OXML[] { return getElements(this.element.children) } + protected get _elements(): OXML[] { + return Array.from(this.element.children).map(element => OXML.make(element)) + } +} + +export class _GroupShapeStyle extends OXML { + @defineProperty('_parent.grpSpPr.xfrm.off.x') declare left: number + @defineProperty('_parent.grpSpPr.xfrm.off.y') declare top: number + @defineProperty('_parent.grpSpPr.xfrm.ext.cx') declare width: number + @defineProperty('_parent.grpSpPr.xfrm.ext.cy') declare height: number + @defineProperty('_parent.grpSpPr.xfrm.rot') declare rotate: number + @defineProperty('_parent.grpSpPr.xfrm.flipH') declare flipH: boolean + @defineProperty('_parent.grpSpPr.xfrm.flipV') declare flipV: boolean + @defineProperty('_parent.grpSpPr.xfrm.chOff.x') declare childLeft: number + @defineProperty('_parent.grpSpPr.xfrm.chOff.y') declare childTop: number + @defineProperty('_parent.grpSpPr.xfrm.chExt.cx') declare childWidth: number + @defineProperty('_parent.grpSpPr.xfrm.chExt.cy') declare childHeight: number + + constructor( + protected _parent: GroupShape, + ) { + super() + } } diff --git a/src/openxml/presentation/Picture.ts b/src/openxml/presentation/Picture.ts index 008ee38..745e938 100644 --- a/src/openxml/presentation/Picture.ts +++ b/src/openxml/presentation/Picture.ts @@ -12,16 +12,24 @@ export class Picture extends OXML { @defineChild('p:blipFill') declare blipFill: BlipFill @defineChild('p:nvPicPr') declare nvPicPr: NonVisualPictureProperties @defineChild('p:spPr') declare spPr: ShapeProperties - @defineChild('p:style') declare style: ShapeStyle + @defineChild('p:style') declare pStyle: ShapeStyle - @defineProperty('_type') declare type: string + @defineProperty() type = 'picture' @defineProperty('nvPicPr.cNvPr.id') declare id: string @defineProperty('nvPicPr.cNvPr.name') declare name: string - @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() style = new _PictureStyle(this) @defineProperty('blipFill.blip.rEmbed') declare rEmbed: string +} + +export class _PictureStyle extends OXML { + @defineProperty('_parent.spPr.xfrm.off.x') declare left: number + @defineProperty('_parent.spPr.xfrm.off.y') declare top: number + @defineProperty('_parent.spPr.xfrm.ext.cx') declare width: number + @defineProperty('_parent.spPr.xfrm.ext.cy') declare height: number - protected get _type(): string { return 'picture' } + constructor( + protected _parent: Picture, + ) { + super() + } } diff --git a/src/openxml/presentation/Shape.ts b/src/openxml/presentation/Shape.ts index 48d9ebb..49e9339 100644 --- a/src/openxml/presentation/Shape.ts +++ b/src/openxml/presentation/Shape.ts @@ -1,11 +1,10 @@ -import type { Paragraph, TextWrappingValues } from '../drawing' +import type { Paragraph } from '../drawing' import type { NonVisualShapeProperties } from './NonVisualShapeProperties' import type { PlaceholderShape } from './PlaceholderShape' import type { ShapeProperties } from './ShapeProperties' import type { ShapeStyle } from './ShapeStyle' import type { TextBody } from './TextBody' import { defineChild, defineElement, defineProperty, OXML } from '../../core' -import { TextAnchoringTypeValues } from '../drawing' /** * https://learn.microsoft.com/dotnet/api/documentformat.openxml.presentation.shape @@ -15,37 +14,101 @@ 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') declare style?: ShapeStyle + @defineChild('p:style') declare pStyle?: ShapeStyle - @defineProperty('_type') declare type: string + @defineProperty() type = 'shape' @defineProperty('nvSpPr.cNvPr.id') declare id?: string @defineProperty('nvSpPr.cNvPr.name') declare name?: string + @defineProperty() style = new _ShapeStyle(this) @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('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' } + @defineProperty('spPr.ln') declare outline: Record + @defineProperty('_paragraphs') declare paragraphs: Paragraph[] 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 } - get verticalAlign(): TextAnchoringTypeValues { return this.txBody.bodyPr.anchor ?? TextAnchoringTypeValues.ctr } - get textAlign(): string | undefined { return this.txBody.bodyPr.anchorCtr ? 'center' : undefined } get useParagraphSpacing(): boolean { return !!this.txBody.bodyPr.spcFirstLastPara } - get writingMode(): 'vertical-lr' | 'horizontal-tb' { return this.txBody.bodyPr.upright ? 'vertical-lr' : 'horizontal-tb' } - get geometry() { return this.spPr.prstGeom } + + get _paragraphs(): Paragraph[] | undefined { + if (this.nvSpPr.cNvSpPr.txBox) { + return this.txBody.pList + } + return undefined + } +} + +export class _ShapeStyle extends OXML { + @defineProperty('_parent.spPr.xfrm.off.x') declare left: number + @defineProperty('_parent.spPr.xfrm.off.y') declare top: number + @defineProperty('_parent.spPr.xfrm.ext.cx') declare width: number + @defineProperty('_parent.spPr.xfrm.ext.cy') declare height: number + @defineProperty('_parent.spPr.xfrm.rot') declare rotate: number + @defineProperty('_parent.spPr.xfrm.flipH') declare flipH: boolean + @defineProperty('_parent.spPr.xfrm.flipV') declare flipV: boolean + + @defineProperty('_parent.txBody.bodyPr.lIns') declare paddingLeft: number + @defineProperty('_parent.txBody.bodyPr.tIns') declare paddingTop: number + @defineProperty('_parent.txBody.bodyPr.rIns') declare paddingRight: number + @defineProperty('_parent.txBody.bodyPr.bIns') declare paddingBottom: number + @defineProperty('_parent.txBody.bodyPr.rot') declare textRotate: number + @defineProperty('_writingMode') declare writingMode?: 'horizontal-tb' | 'vertical-lr' | 'vertical-rl' + @defineProperty('_textWrap') declare textWrap?: 'wrap' | 'nowrap' + @defineProperty('_textAlign') declare textAlign?: 'center' | 'start' + @defineProperty('_verticalAlign') declare verticalAlign?: 'top' | 'middle' | 'bottom' + + protected get _writingMode(): 'horizontal-tb' | 'vertical-lr' | 'vertical-rl' | undefined { + switch (this._parent.txBody.bodyPr.upright) { + case true: + return 'vertical-rl' + case false: + return 'horizontal-tb' + default: + return undefined + } + } + + protected get _textWrap(): 'wrap' | 'nowrap' | undefined { + switch (this._parent.txBody.bodyPr.wrap) { + case 'none': + return 'nowrap' + case 'square': + return 'wrap' + default: + return undefined + } + } + + protected get _verticalAlign(): 'top' | 'middle' | 'bottom' | undefined { + switch (this._parent.txBody.bodyPr.anchor) { + case 't': + return 'top' + case 'b': + return 'bottom' + case 'ctr': + return 'middle' + default: + return undefined + } + } + + protected get _textAlign(): 'center' | 'start' | undefined { + switch (this._parent.txBody.bodyPr.anchorCtr) { + case true: + return 'center' + case false: + return 'start' + default: + return undefined + } + } + + constructor( + protected _parent: Shape, + ) { + super() + } } diff --git a/src/openxml/presentation/Slide.ts b/src/openxml/presentation/Slide.ts index e2a6df4..382ca0b 100644 --- a/src/openxml/presentation/Slide.ts +++ b/src/openxml/presentation/Slide.ts @@ -16,7 +16,5 @@ export class Slide extends _Slide { @defineChild('p:clrMapOvr') declare clrMapOvr: ColorMapOverride - @defineProperty('_type') declare type: string - - protected get _type(): string { return 'slide' } + @defineProperty() type = 'slide' } diff --git a/src/openxml/presentation/_Properties.ts b/src/openxml/presentation/_Properties.ts index 8099dde..639374e 100644 --- a/src/openxml/presentation/_Properties.ts +++ b/src/openxml/presentation/_Properties.ts @@ -1,15 +1,13 @@ -import type { BlipFill, EffectDag, EffectList, GradientFill, GroupFill, NoFill, PatternFill, SolidFill } from '../drawing' +import type { + EffectDag, + EffectList, +} from '../drawing' import type { ExtensionList } from './ExtensionList' -import { defineChild, OXML } from '../../core' +import { defineChild } from '../../core' +import { _Fill } from '../drawing' -export class _Properties extends OXML { - @defineChild('p:extLst') extLst?: ExtensionList - @defineChild('a:effectDag') effectDag?: EffectDag - @defineChild('a:effectLst') effectLst?: EffectList - @defineChild('a:noFill') noFill?: NoFill - @defineChild('a:blipFill') blipFill?: BlipFill - @defineChild('a:gradFill') gradFill?: GradientFill - @defineChild('a:grpFill') grpFill?: GroupFill - @defineChild('a:pattFill') pattFill?: PatternFill - @defineChild('a:solidFill') solidFill?: SolidFill +export class _Properties extends _Fill { + @defineChild('p:extLst') declare extLst?: ExtensionList + @defineChild('a:effectDag') declare effectDag?: EffectDag + @defineChild('a:effectLst') declare effectLst?: EffectList } diff --git a/src/openxml/presentation/_Slide.ts b/src/openxml/presentation/_Slide.ts index 69758d1..c97d9f5 100644 --- a/src/openxml/presentation/_Slide.ts +++ b/src/openxml/presentation/_Slide.ts @@ -2,7 +2,6 @@ import type { CommonSlideData } from './CommonSlideData' import type { ExtensionList } from './ExtensionList' import type { Timing } from './Timing' import { defineChild, defineProperty, OXML } from '../../core' -import { getElements } from './_utils' export class _Slide extends OXML { @defineChild('p:cSld') declare cSld: CommonSlideData @@ -15,5 +14,7 @@ export class _Slide extends OXML { @defineProperty('cSld.spTree.nvGrpSpPr.cNvPr.name') declare name: string @defineProperty('_elements') declare elements: OXML[] - get _elements(): OXML[] { return getElements(this.cSld.spTree.element.children) } + get _elements(): OXML[] { + return Array.from(this.cSld.spTree.element.children).map(element => OXML.make(element)) + } } diff --git a/src/openxml/presentation/_utils.ts b/src/openxml/presentation/_utils.ts deleted file mode 100644 index df2965b..0000000 --- a/src/openxml/presentation/_utils.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { OXML } from '../../core' -import { ConnectionShape } from './ConnectionShape' -import { GraphicFrame } from './GraphicFrame' -import { GroupShape } from './GroupShape' -import { Picture } from './Picture' -import { Shape } from './Shape' - -export function getElements(children: HTMLCollection): OXML[] { - const elements: OXML[] = [] - Array.from(children).forEach((element) => { - switch (element.tagName) { - case 'p:nvGrpSpPr': - case 'p:grpSpPr': - // skip - break - case 'p:sp': - case 'dsp:sp': - elements.push(new Shape().fromElement(element)) - break - case 'p:pic': - elements.push(new Picture().fromElement(element)) - break - case 'p:grpSp': - elements.push(new GroupShape().fromElement(element)) - break - case 'p:cxnSp': - elements.push(new ConnectionShape().fromElement(element)) - break - case 'p:graphicFrame': - elements.push(new GraphicFrame().fromElement(element)) - break - default: - console.warn(element) - break - } - }) - return elements -}