@office-open/pptx 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1373,7 +1373,7 @@ var DefaultSlideMaster = class DefaultSlideMaster extends ImportedXmlComponent {
1373
1373
  };
1374
1374
  //#endregion
1375
1375
  //#region src/file/animation/timing.ts
1376
- const PRESET_IDS = {
1376
+ const ENTR_PRESET_IDS = {
1377
1377
  appear: 1,
1378
1378
  fade: 10,
1379
1379
  fly: 2,
@@ -1389,6 +1389,42 @@ const PRESET_IDS = {
1389
1389
  push: 19,
1390
1390
  strips: 23
1391
1391
  };
1392
+ const EXIT_PRESET_IDS = {
1393
+ appear: 53,
1394
+ fade: 59,
1395
+ fly: 51,
1396
+ wipe: 72,
1397
+ dissolve: 84,
1398
+ split: 71,
1399
+ blinds: 75,
1400
+ checker: 76,
1401
+ randomBars: 74,
1402
+ wheel: 77,
1403
+ zoom: 60,
1404
+ cover: 78,
1405
+ push: 69,
1406
+ strips: 73
1407
+ };
1408
+ const EMPH_PRESET_IDS = {
1409
+ growShrink: 53,
1410
+ spin: 54,
1411
+ growWithTurn: 56,
1412
+ colorChange: 29,
1413
+ transparency: 57,
1414
+ boldFlash: 50,
1415
+ wave: 55,
1416
+ pulse: 58
1417
+ };
1418
+ const PATH_PRESET_IDS = {
1419
+ customPath: 200,
1420
+ arc: 201,
1421
+ bounce: 202,
1422
+ circle: 203,
1423
+ curve: 204,
1424
+ figureEight: 205,
1425
+ line: 206,
1426
+ loop: 207
1427
+ };
1392
1428
  const DIRECTION_SUBTYPES = {
1393
1429
  left: 4,
1394
1430
  right: 8,
@@ -1461,169 +1497,522 @@ const DIRECTION_FILTER = {
1461
1497
  },
1462
1498
  wheel: {}
1463
1499
  };
1464
- /**
1465
- * p:timing — Slide timing for shape animations.
1466
- */
1467
- var SlideTiming = class extends XmlComponent {
1468
- constructor(entries) {
1469
- super("p:timing");
1470
- if (entries.length === 0) return;
1471
- let id = 1;
1472
- const rootCtnId = id++;
1473
- const seqCtnId = id++;
1474
- const animationNodes = [];
1475
- let clickGroupDelay = 0;
1476
- for (let i = 0; i < entries.length; i++) {
1477
- const { spid, options } = entries[i];
1478
- const nodeType = options.trigger === "withPrevious" ? "withEffect" : options.trigger === "afterPrevious" ? "afterEffect" : "clickEffect";
1479
- if (options.trigger === "afterPrevious" && i > 0) clickGroupDelay += (options.duration ?? 500) + (options.delay ?? 0);
1480
- if (options.trigger === "onClick" || options.trigger === void 0) clickGroupDelay = 0;
1481
- const groupCtnId = id++;
1482
- const effectCtnId = id++;
1483
- const setCtnId = id++;
1484
- const effectCtnId2 = id++;
1485
- const presetId = PRESET_IDS[options.type];
1486
- const presetSubtype = options.direction ? DIRECTION_SUBTYPES[options.direction] ?? 0 : 0;
1487
- const effectChildren = [];
1488
- effectChildren.push(new BuilderElement({
1489
- name: "p:set",
1500
+ const PATH_STRINGS = {
1501
+ customPath: "",
1502
+ arc: "M 0 0 C 50 -100 100 -100 150 0",
1503
+ bounce: "M 0 0 L 50 0 C 50 -30 30 -50 0 -50 C -30 -50 -50 -30 -50 0 L 50 0",
1504
+ circle: "M 0 0 C 50 -50 100 0 50 50 C 0 100 -50 50 0 0",
1505
+ curve: "M 0 0 C 50 -80 100 -80 150 0 C 200 80 250 80 300 0",
1506
+ figureEight: "M 0 0 C 50 -50 100 0 50 50 C 0 100 -50 50 0 0 C -50 -50 -100 0 -50 50 C 0 100 50 50 0 0",
1507
+ line: "M 0 0 L 200 0",
1508
+ loop: "M 0 0 C 50 -80 100 0 50 80 C 0 160 -50 80 0 0"
1509
+ };
1510
+ function resolvePresetId(options) {
1511
+ const cls = options.class ?? "entr";
1512
+ if (cls === "emph" && options.emphasisType) return EMPH_PRESET_IDS[options.emphasisType] ?? 0;
1513
+ if (options.pathType) return PATH_PRESET_IDS[options.pathType] ?? 200;
1514
+ const type = options.type ?? "appear";
1515
+ return (cls === "exit" ? EXIT_PRESET_IDS : ENTR_PRESET_IDS)[type] ?? 0;
1516
+ }
1517
+ function resolvePresetClass(options) {
1518
+ if (options.pathType) return "emph";
1519
+ return options.class ?? "entr";
1520
+ }
1521
+ function resolvePresetSubtype(options) {
1522
+ if (options.direction) return DIRECTION_SUBTYPES[options.direction] ?? 0;
1523
+ return 0;
1524
+ }
1525
+ function buildEntrOrExitEffects(options, spid, ids) {
1526
+ const children = [];
1527
+ const cls = options.class ?? "entr";
1528
+ const visibility = cls === "exit" ? "hidden" : "visible";
1529
+ children.push(new BuilderElement({
1530
+ name: "p:set",
1531
+ children: [new BuilderElement({
1532
+ name: "p:cBhvr",
1533
+ children: [
1534
+ new BuilderElement({
1535
+ name: "p:cTn",
1536
+ attributes: {
1537
+ id: {
1538
+ key: "id",
1539
+ value: ids.set
1540
+ },
1541
+ dur: {
1542
+ key: "dur",
1543
+ value: "1"
1544
+ },
1545
+ fill: {
1546
+ key: "fill",
1547
+ value: "hold"
1548
+ }
1549
+ },
1550
+ children: [new BuilderElement({
1551
+ name: "p:stCondLst",
1552
+ children: [new BuilderElement({
1553
+ name: "p:cond",
1554
+ attributes: { delay: {
1555
+ key: "delay",
1556
+ value: "0"
1557
+ } }
1558
+ })]
1559
+ })]
1560
+ }),
1561
+ new BuilderElement({
1562
+ name: "p:tgtEl",
1563
+ children: [new BuilderElement({
1564
+ name: "p:spTgt",
1565
+ attributes: { spid: {
1566
+ key: "spid",
1567
+ value: spid
1568
+ } }
1569
+ })]
1570
+ }),
1571
+ new BuilderElement({
1572
+ name: "p:attrNameLst",
1573
+ children: [new StringContainer("p:attrName", "style.visibility")]
1574
+ })
1575
+ ]
1576
+ }), new BuilderElement({
1577
+ name: "p:to",
1578
+ children: [new BuilderElement({
1579
+ name: "p:strVal",
1580
+ attributes: { val: {
1581
+ key: "val",
1582
+ value: visibility
1583
+ } }
1584
+ })]
1585
+ })]
1586
+ }));
1587
+ if (options.type !== "appear") {
1588
+ const filterBase = FILTER_MAP[options.type ?? "fade"];
1589
+ const dirMap = DIRECTION_FILTER[options.type ?? "fade"];
1590
+ const dirFilter = options.direction && dirMap ? dirMap[options.direction] : void 0;
1591
+ let filter = filterBase;
1592
+ if (options.type === "wheel") filter = "wheel(4)";
1593
+ else if (options.type === "split") filter = `split(${options.direction ?? "horizontal"})`;
1594
+ else if (dirFilter) filter = `${filterBase}(${dirFilter})`;
1595
+ const transition = cls === "exit" ? "out" : "in";
1596
+ children.push(new BuilderElement({
1597
+ name: "p:animEffect",
1598
+ attributes: {
1599
+ transition: {
1600
+ key: "transition",
1601
+ value: transition
1602
+ },
1603
+ filter: {
1604
+ key: "filter",
1605
+ value: filter
1606
+ }
1607
+ },
1608
+ children: [new BuilderElement({
1609
+ name: "p:cBhvr",
1610
+ children: [new BuilderElement({
1611
+ name: "p:cTn",
1612
+ attributes: {
1613
+ id: {
1614
+ key: "id",
1615
+ value: ids.effect
1616
+ },
1617
+ dur: {
1618
+ key: "dur",
1619
+ value: String(options.duration ?? 500)
1620
+ },
1621
+ fill: {
1622
+ key: "fill",
1623
+ value: "hold"
1624
+ }
1625
+ }
1626
+ }), new BuilderElement({
1627
+ name: "p:tgtEl",
1628
+ children: [new BuilderElement({
1629
+ name: "p:spTgt",
1630
+ attributes: { spid: {
1631
+ key: "spid",
1632
+ value: spid
1633
+ } }
1634
+ })]
1635
+ })]
1636
+ })]
1637
+ }));
1638
+ }
1639
+ return children;
1640
+ }
1641
+ function buildEmphasisEffects(options, spid, ids) {
1642
+ const emphType = options.emphasisType ?? "growShrink";
1643
+ const children = [];
1644
+ const dur = String(options.duration ?? 500);
1645
+ const tgtEl = new BuilderElement({
1646
+ name: "p:tgtEl",
1647
+ children: [new BuilderElement({
1648
+ name: "p:spTgt",
1649
+ attributes: { spid: {
1650
+ key: "spid",
1651
+ value: spid
1652
+ } }
1653
+ })]
1654
+ });
1655
+ switch (emphType) {
1656
+ case "growShrink":
1657
+ children.push(new BuilderElement({
1658
+ name: "p:animScale",
1490
1659
  children: [new BuilderElement({
1491
1660
  name: "p:cBhvr",
1492
- children: [
1493
- new BuilderElement({
1494
- name: "p:cTn",
1495
- attributes: {
1496
- id: {
1497
- key: "id",
1498
- value: setCtnId
1499
- },
1500
- dur: {
1501
- key: "dur",
1502
- value: "1"
1503
- },
1504
- fill: {
1505
- key: "fill",
1506
- value: "hold"
1507
- }
1661
+ children: [new BuilderElement({
1662
+ name: "p:cTn",
1663
+ attributes: {
1664
+ id: {
1665
+ key: "id",
1666
+ value: ids.effect
1667
+ },
1668
+ dur: {
1669
+ key: "dur",
1670
+ value: dur
1671
+ },
1672
+ fill: {
1673
+ key: "fill",
1674
+ value: "hold"
1508
1675
  },
1676
+ ...options.autoReverse ? { autoRev: {
1677
+ key: "autoRev",
1678
+ value: 1
1679
+ } } : {}
1680
+ },
1681
+ children: [new BuilderElement({
1682
+ name: "p:stCondLst",
1509
1683
  children: [new BuilderElement({
1510
- name: "p:stCondLst",
1511
- children: [new BuilderElement({
1512
- name: "p:cond",
1513
- attributes: { delay: {
1514
- key: "delay",
1515
- value: "0"
1516
- } }
1517
- })]
1684
+ name: "p:cond",
1685
+ attributes: { delay: {
1686
+ key: "delay",
1687
+ value: "0"
1688
+ } }
1518
1689
  })]
1519
- }),
1520
- new BuilderElement({
1521
- name: "p:tgtEl",
1690
+ })]
1691
+ }), tgtEl]
1692
+ }), new BuilderElement({
1693
+ name: "p:by",
1694
+ attributes: {
1695
+ x: {
1696
+ key: "x",
1697
+ value: "150000"
1698
+ },
1699
+ y: {
1700
+ key: "y",
1701
+ value: "150000"
1702
+ }
1703
+ }
1704
+ })]
1705
+ }));
1706
+ break;
1707
+ case "spin":
1708
+ children.push(new BuilderElement({
1709
+ name: "p:animRot",
1710
+ attributes: { by: {
1711
+ key: "by",
1712
+ value: "3600000"
1713
+ } },
1714
+ children: [new BuilderElement({
1715
+ name: "p:cBhvr",
1716
+ children: [new BuilderElement({
1717
+ name: "p:cTn",
1718
+ attributes: {
1719
+ id: {
1720
+ key: "id",
1721
+ value: ids.effect
1722
+ },
1723
+ dur: {
1724
+ key: "dur",
1725
+ value: dur
1726
+ },
1727
+ fill: {
1728
+ key: "fill",
1729
+ value: "hold"
1730
+ }
1731
+ },
1732
+ children: [new BuilderElement({
1733
+ name: "p:stCondLst",
1522
1734
  children: [new BuilderElement({
1523
- name: "p:spTgt",
1524
- attributes: { spid: {
1525
- key: "spid",
1526
- value: spid
1735
+ name: "p:cond",
1736
+ attributes: { delay: {
1737
+ key: "delay",
1738
+ value: "0"
1527
1739
  } }
1528
1740
  })]
1529
- }),
1530
- new BuilderElement({
1531
- name: "p:attrNameLst",
1532
- children: [new StringContainer("p:attrName", "style.visibility")]
1533
- })
1534
- ]
1741
+ })]
1742
+ }), tgtEl]
1743
+ })]
1744
+ }));
1745
+ break;
1746
+ case "colorChange": {
1747
+ const color = options.color ?? "FF0000";
1748
+ children.push(new BuilderElement({
1749
+ name: "p:animClr",
1750
+ children: [new BuilderElement({
1751
+ name: "p:cBhvr",
1752
+ children: [new BuilderElement({
1753
+ name: "p:cTn",
1754
+ attributes: {
1755
+ id: {
1756
+ key: "id",
1757
+ value: ids.effect
1758
+ },
1759
+ dur: {
1760
+ key: "dur",
1761
+ value: dur
1762
+ },
1763
+ fill: {
1764
+ key: "fill",
1765
+ value: "hold"
1766
+ }
1767
+ },
1768
+ children: [new BuilderElement({
1769
+ name: "p:stCondLst",
1770
+ children: [new BuilderElement({
1771
+ name: "p:cond",
1772
+ attributes: { delay: {
1773
+ key: "delay",
1774
+ value: "0"
1775
+ } }
1776
+ })]
1777
+ })]
1778
+ }), tgtEl]
1535
1779
  }), new BuilderElement({
1536
1780
  name: "p:to",
1537
1781
  children: [new BuilderElement({
1538
- name: "p:strVal",
1782
+ name: "a:srgbClr",
1539
1783
  attributes: { val: {
1540
1784
  key: "val",
1541
- value: "visible"
1785
+ value: color
1542
1786
  } }
1543
1787
  })]
1544
1788
  })]
1545
1789
  }));
1546
- if (options.type !== "appear") {
1547
- const filterBase = FILTER_MAP[options.type];
1548
- const dirMap = DIRECTION_FILTER[options.type];
1549
- const dirFilter = options.direction && dirMap ? dirMap[options.direction] : void 0;
1550
- let filter = filterBase;
1551
- if (options.type === "wheel") filter = "wheel(4)";
1552
- else if (options.type === "split") filter = `split(${options.direction ?? "horizontal"})`;
1553
- else if (dirFilter) filter = `${filterBase}(${dirFilter})`;
1554
- effectChildren.push(new BuilderElement({
1555
- name: "p:animEffect",
1556
- attributes: {
1557
- transition: {
1558
- key: "transition",
1559
- value: "in"
1560
- },
1561
- filter: {
1562
- key: "filter",
1563
- value: filter
1564
- }
1790
+ break;
1791
+ }
1792
+ case "transparency":
1793
+ children.push(new BuilderElement({
1794
+ name: "p:anim",
1795
+ attributes: {
1796
+ calcmode: {
1797
+ key: "calcmode",
1798
+ value: "lin"
1565
1799
  },
1566
- children: [new BuilderElement({
1567
- name: "p:cBhvr",
1568
- children: [new BuilderElement({
1800
+ valueType: {
1801
+ key: "valueType",
1802
+ value: "num"
1803
+ },
1804
+ from: {
1805
+ key: "from",
1806
+ value: "0"
1807
+ },
1808
+ to: {
1809
+ key: "to",
1810
+ value: "1"
1811
+ }
1812
+ },
1813
+ children: [new BuilderElement({
1814
+ name: "p:cBhvr",
1815
+ children: [
1816
+ new BuilderElement({
1569
1817
  name: "p:cTn",
1570
1818
  attributes: {
1571
1819
  id: {
1572
1820
  key: "id",
1573
- value: effectCtnId2
1821
+ value: ids.effect
1574
1822
  },
1575
1823
  dur: {
1576
1824
  key: "dur",
1577
- value: String(options.duration ?? 500)
1825
+ value: dur
1578
1826
  },
1579
1827
  fill: {
1580
1828
  key: "fill",
1581
1829
  value: "hold"
1582
1830
  }
1583
1831
  }
1584
- }), new BuilderElement({
1585
- name: "p:tgtEl",
1586
- children: [new BuilderElement({
1587
- name: "p:spTgt",
1588
- attributes: { spid: {
1589
- key: "spid",
1590
- value: spid
1591
- } }
1592
- })]
1593
- })]
1594
- })]
1595
- }));
1832
+ }),
1833
+ tgtEl,
1834
+ new BuilderElement({
1835
+ name: "p:attrNameLst",
1836
+ children: [new StringContainer("p:attrName", "style.opacity")]
1837
+ })
1838
+ ]
1839
+ })]
1840
+ }));
1841
+ break;
1842
+ default:
1843
+ children.push(new BuilderElement({
1844
+ name: "p:animEffect",
1845
+ attributes: {
1846
+ transition: {
1847
+ key: "transition",
1848
+ value: "in"
1849
+ },
1850
+ filter: {
1851
+ key: "filter",
1852
+ value: emphType
1853
+ }
1854
+ },
1855
+ children: [new BuilderElement({
1856
+ name: "p:cBhvr",
1857
+ children: [new BuilderElement({
1858
+ name: "p:cTn",
1859
+ attributes: {
1860
+ id: {
1861
+ key: "id",
1862
+ value: ids.effect
1863
+ },
1864
+ dur: {
1865
+ key: "dur",
1866
+ value: dur
1867
+ },
1868
+ fill: {
1869
+ key: "fill",
1870
+ value: "hold"
1871
+ }
1872
+ }
1873
+ }), tgtEl]
1874
+ })]
1875
+ }));
1876
+ break;
1877
+ }
1878
+ return children;
1879
+ }
1880
+ function buildPathEffects(options, spid, ids) {
1881
+ const pathStr = options.path ?? PATH_STRINGS[options.pathType ?? "customPath"] ?? "";
1882
+ const dur = String(options.duration ?? 1e3);
1883
+ return [new BuilderElement({
1884
+ name: "p:animMotion",
1885
+ attributes: {
1886
+ origin: {
1887
+ key: "origin",
1888
+ value: "layout"
1889
+ },
1890
+ path: {
1891
+ key: "path",
1892
+ value: pathStr
1596
1893
  }
1894
+ },
1895
+ children: [new BuilderElement({
1896
+ name: "p:cBhvr",
1897
+ children: [new BuilderElement({
1898
+ name: "p:cTn",
1899
+ attributes: {
1900
+ id: {
1901
+ key: "id",
1902
+ value: ids.effect
1903
+ },
1904
+ dur: {
1905
+ key: "dur",
1906
+ value: dur
1907
+ },
1908
+ fill: {
1909
+ key: "fill",
1910
+ value: "hold"
1911
+ }
1912
+ },
1913
+ children: [new BuilderElement({
1914
+ name: "p:stCondLst",
1915
+ children: [new BuilderElement({
1916
+ name: "p:cond",
1917
+ attributes: { delay: {
1918
+ key: "delay",
1919
+ value: "0"
1920
+ } }
1921
+ })]
1922
+ })]
1923
+ }), new BuilderElement({
1924
+ name: "p:tgtEl",
1925
+ children: [new BuilderElement({
1926
+ name: "p:spTgt",
1927
+ attributes: { spid: {
1928
+ key: "spid",
1929
+ value: spid
1930
+ } }
1931
+ })]
1932
+ })]
1933
+ })]
1934
+ })];
1935
+ }
1936
+ /**
1937
+ * p:timing — Slide timing for shape animations.
1938
+ */
1939
+ var SlideTiming = class extends XmlComponent {
1940
+ constructor(entries) {
1941
+ super("p:timing");
1942
+ if (entries.length === 0) return;
1943
+ let id = 1;
1944
+ const rootCtnId = id++;
1945
+ const seqCtnId = id++;
1946
+ const animationNodes = [];
1947
+ let clickGroupDelay = 0;
1948
+ for (let i = 0; i < entries.length; i++) {
1949
+ const { spid, options } = entries[i];
1950
+ const nodeType = options.trigger === "withPrevious" ? "withEffect" : options.trigger === "afterPrevious" ? "afterEffect" : "clickEffect";
1951
+ if (options.trigger === "afterPrevious" && i > 0) clickGroupDelay += (options.duration ?? 500) + (options.delay ?? 0);
1952
+ if (options.trigger === "onClick" || options.trigger === void 0) clickGroupDelay = 0;
1953
+ const groupCtnId = id++;
1954
+ const effectCtnId = id++;
1955
+ const setCtnId = id++;
1956
+ const effectCtnId2 = id++;
1957
+ const presetId = resolvePresetId(options);
1958
+ const presetClass = resolvePresetClass(options);
1959
+ const presetSubtype = resolvePresetSubtype(options);
1960
+ let effectChildren;
1961
+ if (options.pathType) effectChildren = buildPathEffects(options, spid, {
1962
+ set: setCtnId,
1963
+ effect: effectCtnId2
1964
+ });
1965
+ else if (presetClass === "emph") effectChildren = buildEmphasisEffects(options, spid, {
1966
+ set: setCtnId,
1967
+ effect: effectCtnId2
1968
+ });
1969
+ else effectChildren = buildEntrOrExitEffects(options, spid, {
1970
+ set: setCtnId,
1971
+ effect: effectCtnId2
1972
+ });
1973
+ const cTnAttrs = {
1974
+ id: {
1975
+ key: "id",
1976
+ value: effectCtnId
1977
+ },
1978
+ presetID: {
1979
+ key: "presetID",
1980
+ value: presetId
1981
+ },
1982
+ presetClass: {
1983
+ key: "presetClass",
1984
+ value: presetClass
1985
+ },
1986
+ presetSubtype: {
1987
+ key: "presetSubtype",
1988
+ value: presetSubtype
1989
+ },
1990
+ fill: {
1991
+ key: "fill",
1992
+ value: "hold"
1993
+ },
1994
+ nodeType: {
1995
+ key: "nodeType",
1996
+ value: nodeType
1997
+ }
1998
+ };
1999
+ if (options.speed !== void 0) cTnAttrs.spd = {
2000
+ key: "spd",
2001
+ value: String(options.speed)
2002
+ };
2003
+ if (options.repeatCount !== void 0) cTnAttrs.repeatCount = {
2004
+ key: "repeatCount",
2005
+ value: String(options.repeatCount)
2006
+ };
2007
+ if (options.autoReverse) cTnAttrs.autoRev = {
2008
+ key: "autoRev",
2009
+ value: 1
2010
+ };
1597
2011
  const innerPar = new BuilderElement({
1598
2012
  name: "p:par",
1599
2013
  children: [new BuilderElement({
1600
2014
  name: "p:cTn",
1601
- attributes: {
1602
- id: {
1603
- key: "id",
1604
- value: effectCtnId
1605
- },
1606
- presetID: {
1607
- key: "presetID",
1608
- value: presetId
1609
- },
1610
- presetClass: {
1611
- key: "presetClass",
1612
- value: "entr"
1613
- },
1614
- presetSubtype: {
1615
- key: "presetSubtype",
1616
- value: presetSubtype
1617
- },
1618
- fill: {
1619
- key: "fill",
1620
- value: "hold"
1621
- },
1622
- nodeType: {
1623
- key: "nodeType",
1624
- value: nodeType
1625
- }
1626
- },
2015
+ attributes: cTnAttrs,
1627
2016
  children: [new BuilderElement({
1628
2017
  name: "p:stCondLst",
1629
2018
  children: [new BuilderElement({