@mce/bigesj 0.15.6 → 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/cropping.d.ts +15 -0
- package/dist/convert/element.d.ts +1 -1
- package/dist/convert/index.d.ts +2 -0
- package/dist/convert/style.d.ts +1 -1
- package/dist/convert/transform.d.ts +15 -0
- package/dist/index.js +136 -70
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface BigeCropping {
|
|
2
|
+
imageWidth: number;
|
|
3
|
+
imageHeight: number;
|
|
4
|
+
maskWidth?: number;
|
|
5
|
+
maskHeight?: number;
|
|
6
|
+
translateX: number;
|
|
7
|
+
translateY: number;
|
|
8
|
+
zoom?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function croppingToCropRect(cropping: BigeCropping, width: number, height: number): {
|
|
11
|
+
left: number;
|
|
12
|
+
top: number;
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
};
|
|
@@ -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/convert/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './animation';
|
|
2
2
|
export * from './background';
|
|
3
|
+
export * from './cropping';
|
|
3
4
|
export * from './doc';
|
|
4
5
|
export * from './element';
|
|
5
6
|
export * from './image';
|
|
@@ -7,4 +8,5 @@ export * from './layout';
|
|
|
7
8
|
export * from './style';
|
|
8
9
|
export * from './svg';
|
|
9
10
|
export * from './text';
|
|
11
|
+
export * from './transform';
|
|
10
12
|
export * from './types';
|
package/dist/convert/style.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getStyle(el: Record<string, any
|
|
1
|
+
export declare function getStyle(el: Record<string, any>, clone?: boolean): any;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface BigeTransform {
|
|
2
|
+
imageWidth: number;
|
|
3
|
+
imageHeight: number;
|
|
4
|
+
originWidth?: number;
|
|
5
|
+
originHeight?: number;
|
|
6
|
+
translateX: number;
|
|
7
|
+
translateY: number;
|
|
8
|
+
zoom?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function transformToCropRect(transform: BigeTransform, width: number, height: number): {
|
|
11
|
+
left: number;
|
|
12
|
+
top: number;
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -585,28 +585,115 @@ 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
|
+
}
|
|
606
|
+
function transformToCropRect(transform, width, height) {
|
|
607
|
+
const {
|
|
608
|
+
imageWidth,
|
|
609
|
+
imageHeight,
|
|
610
|
+
originWidth: _originWidth = width,
|
|
611
|
+
originHeight: _originHeight = height,
|
|
612
|
+
translateX,
|
|
613
|
+
translateY,
|
|
614
|
+
zoom = 1
|
|
615
|
+
} = transform;
|
|
616
|
+
const left = -(imageWidth * (zoom - 1) / 2) + translateX * zoom;
|
|
617
|
+
const top = -(imageHeight * (zoom - 1) / 2) + translateY * zoom;
|
|
618
|
+
const right = left + imageWidth * zoom;
|
|
619
|
+
const bottom = top + imageHeight * zoom;
|
|
620
|
+
return {
|
|
621
|
+
left: -left / width,
|
|
622
|
+
top: -top / height,
|
|
623
|
+
right: -(width - right) / width,
|
|
624
|
+
bottom: -(height - bottom) / height
|
|
625
|
+
};
|
|
626
|
+
}
|
|
588
627
|
function convertBackground(el) {
|
|
628
|
+
const style = getStyle(el);
|
|
589
629
|
let background;
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (isGradient(backgroundColor ?? "")) {
|
|
630
|
+
const color = el.backgroundColor ?? el.background?.color;
|
|
631
|
+
if (color) {
|
|
632
|
+
if (isGradient(color ?? "")) {
|
|
594
633
|
background = {
|
|
595
|
-
image:
|
|
634
|
+
image: color
|
|
596
635
|
};
|
|
597
636
|
} else {
|
|
598
637
|
background = {
|
|
599
|
-
color
|
|
638
|
+
color
|
|
600
639
|
};
|
|
601
640
|
}
|
|
602
641
|
}
|
|
603
|
-
|
|
642
|
+
const image = el.backgroundImage ?? el.background?.image;
|
|
643
|
+
if (image) {
|
|
604
644
|
background = {
|
|
605
|
-
image:
|
|
645
|
+
image: image.match(/url\((.+)\)/)?.[1] ?? image
|
|
646
|
+
};
|
|
647
|
+
}
|
|
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
|
|
606
659
|
};
|
|
607
660
|
}
|
|
661
|
+
if (background && transform) {
|
|
662
|
+
background.cropRect = transformToCropRect(
|
|
663
|
+
transform,
|
|
664
|
+
style.width,
|
|
665
|
+
style.height
|
|
666
|
+
);
|
|
667
|
+
}
|
|
608
668
|
return background;
|
|
609
669
|
}
|
|
670
|
+
function croppingToCropRect(cropping, width, height) {
|
|
671
|
+
const {
|
|
672
|
+
imageWidth,
|
|
673
|
+
imageHeight,
|
|
674
|
+
maskWidth = width,
|
|
675
|
+
maskHeight = height,
|
|
676
|
+
translateX,
|
|
677
|
+
translateY,
|
|
678
|
+
zoom = 1
|
|
679
|
+
} = cropping;
|
|
680
|
+
const cvsWidth = imageWidth * zoom;
|
|
681
|
+
const cvsHeight = imageHeight * zoom;
|
|
682
|
+
const distX = (cvsWidth - maskWidth) / 2 - translateX;
|
|
683
|
+
const distY = (cvsHeight - maskHeight) / 2 - translateY;
|
|
684
|
+
const originX = distX + maskWidth / 2;
|
|
685
|
+
const originY = distY + maskHeight / 2;
|
|
686
|
+
const left = -(width / 2 - originX);
|
|
687
|
+
const top = -(height / 2 - originY);
|
|
688
|
+
const right = cvsWidth - (left + width);
|
|
689
|
+
const bottom = cvsHeight - (top + height);
|
|
690
|
+
return {
|
|
691
|
+
left: left / cvsWidth,
|
|
692
|
+
top: top / cvsHeight,
|
|
693
|
+
right: right / cvsWidth,
|
|
694
|
+
bottom: bottom / cvsHeight
|
|
695
|
+
};
|
|
696
|
+
}
|
|
610
697
|
async function convertImageElementToUrl(el) {
|
|
611
698
|
const {
|
|
612
699
|
transform = {},
|
|
@@ -1168,9 +1255,6 @@ function convertSvgLinearGradient(value) {
|
|
|
1168
1255
|
return `linear-gradient(${args.join(", ")})`;
|
|
1169
1256
|
}
|
|
1170
1257
|
}
|
|
1171
|
-
function getStyle(el) {
|
|
1172
|
-
return el.style ?? el;
|
|
1173
|
-
}
|
|
1174
1258
|
async function convertSvgElementToUrl(el) {
|
|
1175
1259
|
const {
|
|
1176
1260
|
id,
|
|
@@ -1388,10 +1472,9 @@ async function convertTextContent(el, isByWord = false) {
|
|
|
1388
1472
|
}
|
|
1389
1473
|
const percentageToPx = (per) => (Number.parseFloat(per) || 0) / 100;
|
|
1390
1474
|
async function convertElement(el, parent, context) {
|
|
1391
|
-
const style = { ...getStyle(el) };
|
|
1392
|
-
delete style.bottom;
|
|
1393
|
-
delete style.right;
|
|
1394
1475
|
const { children: _children, ...raw } = el;
|
|
1476
|
+
const oldStyle = getStyle(el);
|
|
1477
|
+
const style = getStyle(el, true);
|
|
1395
1478
|
const meta = {
|
|
1396
1479
|
raw,
|
|
1397
1480
|
inPptIs: "Shape",
|
|
@@ -1399,19 +1482,25 @@ async function convertElement(el, parent, context) {
|
|
|
1399
1482
|
};
|
|
1400
1483
|
const element = {
|
|
1401
1484
|
id: idGenerator(),
|
|
1402
|
-
name: el.name ?? el.title
|
|
1485
|
+
name: el.name ?? el.title,
|
|
1403
1486
|
style,
|
|
1404
1487
|
meta,
|
|
1405
|
-
children: []
|
|
1488
|
+
children: [],
|
|
1489
|
+
background: convertBackground(el)
|
|
1406
1490
|
};
|
|
1407
|
-
if (
|
|
1408
|
-
style.borderRadius =
|
|
1491
|
+
if (oldStyle.borderRadius) {
|
|
1492
|
+
style.borderRadius = oldStyle.borderRadius * 0.01 * Math.max(oldStyle.height, oldStyle.width);
|
|
1409
1493
|
}
|
|
1410
|
-
if (parent
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1494
|
+
if (parent) {
|
|
1495
|
+
if (el.groupStyle) {
|
|
1496
|
+
style.width = parent.style.width * percentageToPx(el.groupStyle.width);
|
|
1497
|
+
style.height = parent.style.height * percentageToPx(el.groupStyle.height);
|
|
1498
|
+
style.left = parent.style.width * percentageToPx(el.groupStyle.left);
|
|
1499
|
+
style.top = parent.style.height * percentageToPx(el.groupStyle.top);
|
|
1500
|
+
} else {
|
|
1501
|
+
style.left = oldStyle.left - parent.left;
|
|
1502
|
+
style.top = oldStyle.top - parent.top;
|
|
1503
|
+
}
|
|
1415
1504
|
}
|
|
1416
1505
|
if (el.editable === false) {
|
|
1417
1506
|
style.visibility = "hidden";
|
|
@@ -1447,33 +1536,17 @@ async function convertElement(el, parent, context) {
|
|
|
1447
1536
|
meta.rawForegroundImage = el.url;
|
|
1448
1537
|
}
|
|
1449
1538
|
if (el.cropping) {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
const cvsWidth = imageWidth * zoom;
|
|
1462
|
-
const cvsHeight = imageHeight * zoom;
|
|
1463
|
-
const distX = (cvsWidth - maskWidth) / 2 - translateX;
|
|
1464
|
-
const distY = (cvsHeight - maskHeight) / 2 - translateY;
|
|
1465
|
-
const originX = distX + maskWidth / 2;
|
|
1466
|
-
const originY = distY + maskHeight / 2;
|
|
1467
|
-
const left = -(width / 2 - originX);
|
|
1468
|
-
const top = -(height / 2 - originY);
|
|
1469
|
-
const right = cvsWidth - (left + width);
|
|
1470
|
-
const bottom = cvsHeight - (top + height);
|
|
1471
|
-
element.foreground.cropRect = {
|
|
1472
|
-
left: left / cvsWidth,
|
|
1473
|
-
top: top / cvsHeight,
|
|
1474
|
-
right: right / cvsWidth,
|
|
1475
|
-
bottom: bottom / cvsHeight
|
|
1476
|
-
};
|
|
1539
|
+
element.foreground.cropRect = croppingToCropRect(
|
|
1540
|
+
el.cropping,
|
|
1541
|
+
el.style.width,
|
|
1542
|
+
el.style.height
|
|
1543
|
+
);
|
|
1544
|
+
} else if (el.transform) {
|
|
1545
|
+
element.foreground.cropRect = transformToCropRect(
|
|
1546
|
+
el.transform,
|
|
1547
|
+
el.style.width,
|
|
1548
|
+
el.style.height
|
|
1549
|
+
);
|
|
1477
1550
|
}
|
|
1478
1551
|
break;
|
|
1479
1552
|
case "svg": {
|
|
@@ -1561,24 +1634,18 @@ async function convertElement(el, parent, context) {
|
|
|
1561
1634
|
return element;
|
|
1562
1635
|
}
|
|
1563
1636
|
async function convertLayout(layout, isFrame = true, context) {
|
|
1637
|
+
const { elements, ...raw } = layout;
|
|
1564
1638
|
const id = idGenerator();
|
|
1565
|
-
const style =
|
|
1566
|
-
delete style.right;
|
|
1567
|
-
delete style.bottom;
|
|
1639
|
+
const style = getStyle(layout, true);
|
|
1568
1640
|
if (isFrame) {
|
|
1569
1641
|
style.overflow = "hidden";
|
|
1570
1642
|
}
|
|
1571
1643
|
const meta = {
|
|
1644
|
+
raw,
|
|
1572
1645
|
inPptIs: isFrame ? "Slide" : "GroupShape",
|
|
1573
1646
|
inEditorIs: isFrame ? "Frame" : "Element",
|
|
1574
1647
|
inCanvasIs: "Element2D"
|
|
1575
1648
|
};
|
|
1576
|
-
if (layout.id) {
|
|
1577
|
-
meta.rawId = layout.id;
|
|
1578
|
-
}
|
|
1579
|
-
if (layout.name) {
|
|
1580
|
-
meta.rawName = layout.name;
|
|
1581
|
-
}
|
|
1582
1649
|
return {
|
|
1583
1650
|
id,
|
|
1584
1651
|
name: isFrame ? `Frame ${id}` : layout.name,
|
|
@@ -1586,7 +1653,7 @@ async function convertLayout(layout, isFrame = true, context) {
|
|
|
1586
1653
|
// TODO 过滤掉部分属性
|
|
1587
1654
|
background: convertBackground(layout),
|
|
1588
1655
|
children: (await Promise.all(
|
|
1589
|
-
|
|
1656
|
+
elements.map(async (element) => {
|
|
1590
1657
|
try {
|
|
1591
1658
|
return await convertElement(element, void 0, context);
|
|
1592
1659
|
} catch (e) {
|
|
@@ -1601,7 +1668,7 @@ async function convertLayout(layout, isFrame = true, context) {
|
|
|
1601
1668
|
async function convertDoc(doc, gap = 0) {
|
|
1602
1669
|
const {
|
|
1603
1670
|
layouts,
|
|
1604
|
-
|
|
1671
|
+
raw = {}
|
|
1605
1672
|
} = doc;
|
|
1606
1673
|
const context = {
|
|
1607
1674
|
endTime: 0
|
|
@@ -1638,14 +1705,14 @@ async function convertDoc(doc, gap = 0) {
|
|
|
1638
1705
|
}, { minX: 0, minY: 0, maxX: 0, maxY: 0 });
|
|
1639
1706
|
return {
|
|
1640
1707
|
id: idGenerator(),
|
|
1641
|
-
name:
|
|
1708
|
+
name: raw.name || "doc",
|
|
1642
1709
|
style: {
|
|
1643
|
-
width:
|
|
1644
|
-
height:
|
|
1710
|
+
width: raw?.width ?? minmax.maxX - minmax.minX,
|
|
1711
|
+
height: raw?.height ?? minmax.maxY - minmax.minY
|
|
1645
1712
|
},
|
|
1646
1713
|
children,
|
|
1647
1714
|
meta: {
|
|
1648
|
-
|
|
1715
|
+
raw,
|
|
1649
1716
|
endTime: context.endTime,
|
|
1650
1717
|
inEditorIs: "Doc"
|
|
1651
1718
|
}
|
|
@@ -1683,8 +1750,7 @@ function bidTidLoader(editor, api) {
|
|
|
1683
1750
|
if (included !== void 0) {
|
|
1684
1751
|
content.layouts = content.layouts.filter((_, index) => included.includes(index));
|
|
1685
1752
|
}
|
|
1686
|
-
doc2 = await convertDoc(content);
|
|
1687
|
-
doc2.meta.raw = raw;
|
|
1753
|
+
doc2 = await convertDoc({ ...content, raw });
|
|
1688
1754
|
}
|
|
1689
1755
|
maxTime = Math.max(maxTime, doc2.meta?.maxTime ?? 0);
|
|
1690
1756
|
return doc2;
|
|
@@ -1724,9 +1790,7 @@ function bigeLoader() {
|
|
|
1724
1790
|
)
|
|
1725
1791
|
);
|
|
1726
1792
|
const { content, ...raw } = bigeDoc;
|
|
1727
|
-
|
|
1728
|
-
doc.meta.raw = raw;
|
|
1729
|
-
return doc;
|
|
1793
|
+
return await convertDoc({ ...content, raw });
|
|
1730
1794
|
}
|
|
1731
1795
|
};
|
|
1732
1796
|
}
|
|
@@ -1813,11 +1877,13 @@ export {
|
|
|
1813
1877
|
convertTextContent,
|
|
1814
1878
|
convertTextEffects,
|
|
1815
1879
|
convertTextStyle,
|
|
1880
|
+
croppingToCropRect,
|
|
1816
1881
|
plugin as default,
|
|
1817
1882
|
getStyle,
|
|
1818
1883
|
getTextContents,
|
|
1819
1884
|
parseAnimations,
|
|
1820
1885
|
plugin,
|
|
1886
|
+
transformToCropRect,
|
|
1821
1887
|
useFonts,
|
|
1822
1888
|
useSharedTextAssets
|
|
1823
1889
|
};
|
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"
|