@mce/bigesj 0.15.7 → 0.15.8
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/convert/element.d.ts +1 -1
- package/dist/index.js +55 -49
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NormalizedElement } from 'modern-idoc';
|
|
2
2
|
import type { BigeElement } from './types';
|
|
3
|
-
export declare function convertElement(el: BigeElement, parent
|
|
3
|
+
export declare function convertElement(el: BigeElement, parent?: Record<string, any>, context?: {
|
|
4
4
|
endTime: number;
|
|
5
5
|
}): Promise<NormalizedElement>;
|
package/dist/index.js
CHANGED
|
@@ -585,6 +585,24 @@ function parseAnimations(el) {
|
|
|
585
585
|
animations: animations2.filter((v) => !!v?.keyframes)
|
|
586
586
|
};
|
|
587
587
|
}
|
|
588
|
+
function getStyle(el, clone = false) {
|
|
589
|
+
let style = el.style ?? el;
|
|
590
|
+
if (clone) {
|
|
591
|
+
style = { ...style };
|
|
592
|
+
delete style.right;
|
|
593
|
+
delete style.bottom;
|
|
594
|
+
delete style.backgroundColor;
|
|
595
|
+
delete style.backgroundImage;
|
|
596
|
+
delete style.backgroundImageOpacity;
|
|
597
|
+
delete style.backgroundPosition;
|
|
598
|
+
delete style.backgroundSize;
|
|
599
|
+
delete style.backgroundTransform;
|
|
600
|
+
delete style.backgroundUrl;
|
|
601
|
+
delete style.elements;
|
|
602
|
+
delete style.imageTransform;
|
|
603
|
+
}
|
|
604
|
+
return style;
|
|
605
|
+
}
|
|
588
606
|
function transformToCropRect(transform, width, height) {
|
|
589
607
|
const {
|
|
590
608
|
imageWidth,
|
|
@@ -607,31 +625,44 @@ function transformToCropRect(transform, width, height) {
|
|
|
607
625
|
};
|
|
608
626
|
}
|
|
609
627
|
function convertBackground(el) {
|
|
628
|
+
const style = getStyle(el);
|
|
610
629
|
let background;
|
|
611
|
-
const
|
|
612
|
-
if (
|
|
613
|
-
if (isGradient(
|
|
630
|
+
const color = el.backgroundColor ?? el.background?.color;
|
|
631
|
+
if (color) {
|
|
632
|
+
if (isGradient(color ?? "")) {
|
|
614
633
|
background = {
|
|
615
|
-
image:
|
|
634
|
+
image: color
|
|
616
635
|
};
|
|
617
636
|
} else {
|
|
618
637
|
background = {
|
|
619
|
-
color
|
|
638
|
+
color
|
|
620
639
|
};
|
|
621
640
|
}
|
|
622
641
|
}
|
|
623
|
-
const
|
|
624
|
-
if (
|
|
642
|
+
const image = el.backgroundImage ?? el.background?.image;
|
|
643
|
+
if (image) {
|
|
625
644
|
background = {
|
|
626
|
-
image:
|
|
645
|
+
image: image.match(/url\((.+)\)/)?.[1] ?? image
|
|
627
646
|
};
|
|
628
647
|
}
|
|
629
|
-
|
|
630
|
-
if (
|
|
648
|
+
let transform = el.backgroundTransform ?? el.background?.transform;
|
|
649
|
+
if (!transform && el.imageTransform) {
|
|
650
|
+
const imageTransform = el.imageTransform;
|
|
651
|
+
transform = {
|
|
652
|
+
zoom: imageTransform?.scale || 1,
|
|
653
|
+
translateX: imageTransform?.translateX || 0,
|
|
654
|
+
translateY: imageTransform?.translateY || 0,
|
|
655
|
+
originWidth: imageTransform?.imageWidth,
|
|
656
|
+
originHeight: imageTransform?.imageHeight,
|
|
657
|
+
imageWidth: imageTransform?.imageWidth || style.width,
|
|
658
|
+
imageHeight: imageTransform?.imageHeight || style.height
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
if (background && transform) {
|
|
631
662
|
background.cropRect = transformToCropRect(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
663
|
+
transform,
|
|
664
|
+
style.width,
|
|
665
|
+
style.height
|
|
635
666
|
);
|
|
636
667
|
}
|
|
637
668
|
return background;
|
|
@@ -1224,24 +1255,6 @@ function convertSvgLinearGradient(value) {
|
|
|
1224
1255
|
return `linear-gradient(${args.join(", ")})`;
|
|
1225
1256
|
}
|
|
1226
1257
|
}
|
|
1227
|
-
function getStyle(el, clone = false) {
|
|
1228
|
-
let style = el.style ?? el;
|
|
1229
|
-
if (clone) {
|
|
1230
|
-
style = { ...style };
|
|
1231
|
-
delete style.right;
|
|
1232
|
-
delete style.bottom;
|
|
1233
|
-
delete style.backgroundColor;
|
|
1234
|
-
delete style.backgroundImage;
|
|
1235
|
-
delete style.backgroundImageOpacity;
|
|
1236
|
-
delete style.backgroundPosition;
|
|
1237
|
-
delete style.backgroundSize;
|
|
1238
|
-
delete style.backgroundTransform;
|
|
1239
|
-
delete style.backgroundUrl;
|
|
1240
|
-
delete style.elements;
|
|
1241
|
-
delete style.imageTransform;
|
|
1242
|
-
}
|
|
1243
|
-
return style;
|
|
1244
|
-
}
|
|
1245
1258
|
async function convertSvgElementToUrl(el) {
|
|
1246
1259
|
const {
|
|
1247
1260
|
id,
|
|
@@ -1459,9 +1472,9 @@ async function convertTextContent(el, isByWord = false) {
|
|
|
1459
1472
|
}
|
|
1460
1473
|
const percentageToPx = (per) => (Number.parseFloat(per) || 0) / 100;
|
|
1461
1474
|
async function convertElement(el, parent, context) {
|
|
1475
|
+
const { children: _children, ...raw } = el;
|
|
1462
1476
|
const oldStyle = getStyle(el);
|
|
1463
1477
|
const style = getStyle(el, true);
|
|
1464
|
-
const { children: _children, ...raw } = el;
|
|
1465
1478
|
const meta = {
|
|
1466
1479
|
raw,
|
|
1467
1480
|
inPptIs: "Shape",
|
|
@@ -1621,22 +1634,18 @@ async function convertElement(el, parent, context) {
|
|
|
1621
1634
|
return element;
|
|
1622
1635
|
}
|
|
1623
1636
|
async function convertLayout(layout, isFrame = true, context) {
|
|
1637
|
+
const { elements, ...raw } = layout;
|
|
1624
1638
|
const id = idGenerator();
|
|
1625
1639
|
const style = getStyle(layout, true);
|
|
1626
1640
|
if (isFrame) {
|
|
1627
1641
|
style.overflow = "hidden";
|
|
1628
1642
|
}
|
|
1629
1643
|
const meta = {
|
|
1644
|
+
raw,
|
|
1630
1645
|
inPptIs: isFrame ? "Slide" : "GroupShape",
|
|
1631
1646
|
inEditorIs: isFrame ? "Frame" : "Element",
|
|
1632
1647
|
inCanvasIs: "Element2D"
|
|
1633
1648
|
};
|
|
1634
|
-
if (layout.id) {
|
|
1635
|
-
meta.rawId = layout.id;
|
|
1636
|
-
}
|
|
1637
|
-
if (layout.name) {
|
|
1638
|
-
meta.rawName = layout.name;
|
|
1639
|
-
}
|
|
1640
1649
|
return {
|
|
1641
1650
|
id,
|
|
1642
1651
|
name: isFrame ? `Frame ${id}` : layout.name,
|
|
@@ -1644,7 +1653,7 @@ async function convertLayout(layout, isFrame = true, context) {
|
|
|
1644
1653
|
// TODO 过滤掉部分属性
|
|
1645
1654
|
background: convertBackground(layout),
|
|
1646
1655
|
children: (await Promise.all(
|
|
1647
|
-
|
|
1656
|
+
elements.map(async (element) => {
|
|
1648
1657
|
try {
|
|
1649
1658
|
return await convertElement(element, void 0, context);
|
|
1650
1659
|
} catch (e) {
|
|
@@ -1659,7 +1668,7 @@ async function convertLayout(layout, isFrame = true, context) {
|
|
|
1659
1668
|
async function convertDoc(doc, gap = 0) {
|
|
1660
1669
|
const {
|
|
1661
1670
|
layouts,
|
|
1662
|
-
|
|
1671
|
+
raw = {}
|
|
1663
1672
|
} = doc;
|
|
1664
1673
|
const context = {
|
|
1665
1674
|
endTime: 0
|
|
@@ -1696,14 +1705,14 @@ async function convertDoc(doc, gap = 0) {
|
|
|
1696
1705
|
}, { minX: 0, minY: 0, maxX: 0, maxY: 0 });
|
|
1697
1706
|
return {
|
|
1698
1707
|
id: idGenerator(),
|
|
1699
|
-
name:
|
|
1708
|
+
name: raw.name || "doc",
|
|
1700
1709
|
style: {
|
|
1701
|
-
width:
|
|
1702
|
-
height:
|
|
1710
|
+
width: raw?.width ?? minmax.maxX - minmax.minX,
|
|
1711
|
+
height: raw?.height ?? minmax.maxY - minmax.minY
|
|
1703
1712
|
},
|
|
1704
1713
|
children,
|
|
1705
1714
|
meta: {
|
|
1706
|
-
|
|
1715
|
+
raw,
|
|
1707
1716
|
endTime: context.endTime,
|
|
1708
1717
|
inEditorIs: "Doc"
|
|
1709
1718
|
}
|
|
@@ -1741,8 +1750,7 @@ function bidTidLoader(editor, api) {
|
|
|
1741
1750
|
if (included !== void 0) {
|
|
1742
1751
|
content.layouts = content.layouts.filter((_, index) => included.includes(index));
|
|
1743
1752
|
}
|
|
1744
|
-
doc2 = await convertDoc(content);
|
|
1745
|
-
doc2.meta.raw = raw;
|
|
1753
|
+
doc2 = await convertDoc({ ...content, raw });
|
|
1746
1754
|
}
|
|
1747
1755
|
maxTime = Math.max(maxTime, doc2.meta?.maxTime ?? 0);
|
|
1748
1756
|
return doc2;
|
|
@@ -1782,9 +1790,7 @@ function bigeLoader() {
|
|
|
1782
1790
|
)
|
|
1783
1791
|
);
|
|
1784
1792
|
const { content, ...raw } = bigeDoc;
|
|
1785
|
-
|
|
1786
|
-
doc.meta.raw = raw;
|
|
1787
|
-
return doc;
|
|
1793
|
+
return await convertDoc({ ...content, raw });
|
|
1788
1794
|
}
|
|
1789
1795
|
};
|
|
1790
1796
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/bigesj",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.8",
|
|
5
5
|
"description": "Plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"modern-openxml": "^1.10.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"mce": "0.15.
|
|
52
|
+
"mce": "0.15.8"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|