modern-idoc 0.10.21 → 0.11.0

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.cjs CHANGED
@@ -1388,7 +1388,7 @@ function isPresetFill(fill) {
1388
1388
  return typeof fill === "string" ? false : isPresetFillObject(fill);
1389
1389
  }
1390
1390
  function normalizeFill(fill) {
1391
- const enabled = fill && typeof fill === "object" ? fill.enabled : void 0;
1391
+ const enabled = fill && typeof fill === "object" ? fill.enabled ?? true : true;
1392
1392
  const obj = { enabled };
1393
1393
  if (isColorFill(fill)) {
1394
1394
  Object.assign(obj, normalizeColorFill(fill));
@@ -1403,6 +1403,7 @@ function normalizeFill(fill) {
1403
1403
  Object.assign(obj, normalizePresetFill(fill));
1404
1404
  }
1405
1405
  return pick(clearUndef(obj), Array.from(/* @__PURE__ */ new Set([
1406
+ "enabled",
1406
1407
  ...colorFillFields,
1407
1408
  ...imageFillFiedls,
1408
1409
  ...gradientFillFields,
@@ -1423,48 +1424,106 @@ function normalizeBackground(background) {
1423
1424
  }
1424
1425
  }
1425
1426
 
1426
- function getDefaultInnerShadow() {
1427
+ function getDefaultBackgroundStyle() {
1427
1428
  return {
1428
- color: defaultColor,
1429
- offsetX: 0,
1430
- offsetY: 0,
1431
- blurRadius: 1
1429
+ backgroundImage: "none",
1430
+ backgroundSize: "auto, auto",
1431
+ backgroundColor: "none",
1432
+ backgroundColormap: "none"
1432
1433
  };
1433
1434
  }
1434
- function normalizeInnerShadow(shadow) {
1435
- return {
1436
- ...getDefaultInnerShadow(),
1437
- ...clearUndef({
1438
- ...shadow,
1439
- color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
1440
- })
1441
- };
1435
+
1436
+ function normalizeOutline(outline) {
1437
+ if (typeof outline === "string") {
1438
+ return {
1439
+ ...normalizeFill(outline)
1440
+ };
1441
+ } else {
1442
+ return {
1443
+ ...normalizeFill(outline),
1444
+ ...pick(outline, ["width", "style", "lineCap", "lineJoin", "headEnd", "tailEnd"])
1445
+ };
1446
+ }
1442
1447
  }
1443
1448
 
1444
- function getDefaultOuterShadow() {
1449
+ function getDefaultOutlineStyle() {
1445
1450
  return {
1446
- ...getDefaultInnerShadow(),
1447
- scaleX: 1,
1448
- scaleY: 1
1451
+ outlineWidth: 0,
1452
+ outlineOffset: 0,
1453
+ outlineColor: "none",
1454
+ outlineStyle: "none"
1449
1455
  };
1450
1456
  }
1451
- function normalizeOuterShadow(shadow) {
1457
+
1458
+ function normalizeShadow(shadow) {
1459
+ if (typeof shadow === "string") {
1460
+ return {
1461
+ enabled: true,
1462
+ color: normalizeColor(shadow)
1463
+ };
1464
+ } else {
1465
+ return {
1466
+ ...shadow,
1467
+ enabled: shadow.enabled ?? true,
1468
+ color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
1469
+ };
1470
+ }
1471
+ }
1472
+
1473
+ function getDefaultShadowStyle() {
1452
1474
  return {
1453
- ...getDefaultOuterShadow(),
1454
- ...normalizeInnerShadow(shadow)
1475
+ boxShadow: "none"
1455
1476
  };
1456
1477
  }
1457
1478
 
1458
- function normalizeSoftEdge(softEdge) {
1459
- return softEdge;
1479
+ const effectFields = [
1480
+ "fill",
1481
+ "outline",
1482
+ "shadow",
1483
+ "transform",
1484
+ "transformOrigin"
1485
+ ];
1486
+ function normalizeEffectV0(effect) {
1487
+ const _effect = pick(effect, effectFields);
1488
+ const { rotate, scaleX, scaleY, skewX, skewY, translateX, translateY } = effect;
1489
+ const transforms = [];
1490
+ (translateX || translateY) && transforms.push(`translate(${translateX || 0}, ${translateY || 0})`);
1491
+ rotate && transforms.push(`rotate(${rotate}deg)`);
1492
+ (scaleX || scaleY) && transforms.push(`scale(${scaleX ?? 1}, ${scaleY ?? 1})`);
1493
+ skewX && transforms.push(`skewX(${skewX}deg)`);
1494
+ skewY && transforms.push(`skewY(${skewY}deg)`);
1495
+ if (transforms.length > 0) {
1496
+ _effect.transform = transforms.join(" ");
1497
+ }
1498
+ if (effect.textStrokeWidth || effect.textStrokeColor) {
1499
+ _effect.outline = {
1500
+ color: effect.textStrokeColor,
1501
+ width: effect.textStrokeWidth
1502
+ };
1503
+ }
1504
+ if (effect.color) {
1505
+ _effect.fill = {
1506
+ color: effect.color
1507
+ };
1508
+ }
1509
+ if (effect.shadowOffsetX || effect.shadowOffsetY || effect.shadowBlur || effect.shadowColor) {
1510
+ _effect.shadow = {
1511
+ offsetX: effect.shadowOffsetX,
1512
+ offsetY: effect.shadowOffsetY,
1513
+ blur: effect.shadowBlur,
1514
+ color: effect.shadowColor
1515
+ };
1516
+ }
1517
+ return _effect;
1460
1518
  }
1461
-
1462
1519
  function normalizeEffect(effect) {
1520
+ const _effect = normalizeEffectV0(effect);
1463
1521
  return clearUndef({
1464
- ...effect,
1465
- softEdge: isNone(effect.softEdge) ? void 0 : normalizeSoftEdge(effect.softEdge),
1466
- outerShadow: isNone(effect.outerShadow) ? void 0 : normalizeOuterShadow(effect.outerShadow),
1467
- innerShadow: isNone(effect.innerShadow) ? void 0 : normalizeInnerShadow(effect.innerShadow)
1522
+ fill: isNone(_effect.fill) ? void 0 : normalizeFill(_effect.fill),
1523
+ outline: isNone(_effect.outline) ? void 0 : normalizeOutline(_effect.outline),
1524
+ shadow: isNone(_effect.shadow) ? void 0 : normalizeShadow(_effect.shadow),
1525
+ transform: isNone(_effect.transform) ? void 0 : _effect.transform,
1526
+ transformOrigin: _effect.transformOrigin
1468
1527
  });
1469
1528
  }
1470
1529
 
@@ -1486,52 +1545,16 @@ const nanoid = () => {
1486
1545
  };
1487
1546
  const idGenerator = nanoid;
1488
1547
 
1489
- function normalizeOutline(outline) {
1490
- if (typeof outline === "string") {
1491
- return {
1492
- ...normalizeFill(outline)
1493
- };
1494
- } else {
1495
- return {
1496
- ...normalizeFill(outline),
1497
- ...pick(outline, [
1498
- "width",
1499
- "style",
1500
- "lineCap",
1501
- "lineJoin",
1502
- "headEnd",
1503
- "tailEnd"
1504
- ])
1505
- };
1506
- }
1507
- }
1508
-
1509
- function normalizeShadow(shadow) {
1510
- if (typeof shadow === "string") {
1511
- return {
1512
- color: normalizeColor(shadow)
1513
- };
1514
- } else {
1515
- return {
1516
- ...shadow,
1517
- color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
1518
- };
1519
- }
1520
- }
1521
- function getDefaultShadowStyle() {
1522
- return {
1523
- boxShadow: "none"
1524
- };
1525
- }
1526
-
1527
1548
  function normalizeShape(shape) {
1528
1549
  if (typeof shape === "string") {
1529
1550
  if (shape.startsWith("<svg")) {
1530
1551
  return {
1552
+ enabled: true,
1531
1553
  svg: shape
1532
1554
  };
1533
1555
  } else {
1534
1556
  return {
1557
+ enabled: true,
1535
1558
  paths: [
1536
1559
  { data: shape }
1537
1560
  ]
@@ -1539,6 +1562,7 @@ function normalizeShape(shape) {
1539
1562
  }
1540
1563
  } else if (Array.isArray(shape)) {
1541
1564
  return {
1565
+ enabled: true,
1542
1566
  paths: shape.map((data) => {
1543
1567
  if (typeof data === "string") {
1544
1568
  return {
@@ -1608,13 +1632,6 @@ function getDefaultLayoutStyle() {
1608
1632
 
1609
1633
  function getDefaultTransformStyle() {
1610
1634
  return {
1611
- rotate: 0,
1612
- scaleX: 1,
1613
- scaleY: 1,
1614
- skewX: 0,
1615
- skewY: 0,
1616
- translateX: 0,
1617
- translateY: 0,
1618
1635
  transform: "none",
1619
1636
  transformOrigin: "center"
1620
1637
  };
@@ -1625,20 +1642,12 @@ function getDefaultElementStyle() {
1625
1642
  ...getDefaultLayoutStyle(),
1626
1643
  ...getDefaultTransformStyle(),
1627
1644
  ...getDefaultShadowStyle(),
1628
- // background
1629
- backgroundImage: "none",
1630
- backgroundSize: "auto, auto",
1631
- backgroundColor: "none",
1632
- backgroundColormap: "none",
1645
+ ...getDefaultBackgroundStyle(),
1646
+ ...getDefaultOutlineStyle(),
1633
1647
  // border
1634
1648
  borderRadius: 0,
1635
1649
  borderColor: "none",
1636
1650
  borderStyle: "solid",
1637
- // outline
1638
- outlineWidth: 0,
1639
- outlineOffset: 0,
1640
- outlineColor: "none",
1641
- outlineStyle: "none",
1642
1651
  // other
1643
1652
  visibility: "visible",
1644
1653
  filter: "none",
@@ -1847,18 +1856,18 @@ function isFragmentObject(value) {
1847
1856
  function normalizeText(value) {
1848
1857
  if (typeof value === "string" || Array.isArray(value)) {
1849
1858
  return {
1859
+ enabled: true,
1850
1860
  content: normalizeTextContent(value)
1851
1861
  };
1852
1862
  } else {
1853
1863
  return clearUndef({
1854
- ...value,
1864
+ enabled: value.enabled ?? true,
1855
1865
  content: normalizeTextContent(value.content ?? ""),
1856
1866
  style: value.style ? normalizeStyle(value.style) : void 0,
1857
- effects: value.effects ? value.effects.map((v) => normalizeStyle(v)) : void 0,
1858
1867
  measureDom: value.measureDom,
1859
1868
  fonts: value.fonts,
1860
- fill: value.fill ? normalizeFill(value.fill) : void 0,
1861
- outline: value.outline ? normalizeOutline(value.outline) : void 0
1869
+ ...normalizeEffect(value),
1870
+ effects: value.effects ? value.effects.map((v) => normalizeEffect(v)) : void 0
1862
1871
  });
1863
1872
  }
1864
1873
  }
@@ -1884,19 +1893,15 @@ function normalizeVideo(video) {
1884
1893
 
1885
1894
  function normalizeElement(element) {
1886
1895
  return clearUndef({
1887
- ...element,
1888
1896
  id: element.id ?? idGenerator(),
1889
1897
  style: isNone(element.style) ? void 0 : normalizeStyle(element.style),
1890
1898
  text: isNone(element.text) ? void 0 : normalizeText(element.text),
1891
1899
  background: isNone(element.background) ? void 0 : normalizeBackground(element.background),
1892
1900
  shape: isNone(element.shape) ? void 0 : normalizeShape(element.shape),
1893
- fill: isNone(element.fill) ? void 0 : normalizeFill(element.fill),
1894
- outline: isNone(element.outline) ? void 0 : normalizeOutline(element.outline),
1895
1901
  foreground: isNone(element.foreground) ? void 0 : normalizeForeground(element.foreground),
1896
- shadow: isNone(element.shadow) ? void 0 : normalizeShadow(element.shadow),
1897
1902
  video: isNone(element.video) ? void 0 : normalizeVideo(element.video),
1898
1903
  audio: isNone(element.audio) ? void 0 : normalizeAudio(element.audio),
1899
- effect: isNone(element.effect) ? void 0 : normalizeEffect(element.effect),
1904
+ ...normalizeEffect(element),
1900
1905
  children: element.children?.map((child) => normalizeElement(child))
1901
1906
  });
1902
1907
  }
@@ -1967,12 +1972,12 @@ exports.defaultColor = defaultColor;
1967
1972
  exports.defineProperty = defineProperty;
1968
1973
  exports.flatDocumentToDocument = flatDocumentToDocument;
1969
1974
  exports.getDeclarations = getDeclarations;
1975
+ exports.getDefaultBackgroundStyle = getDefaultBackgroundStyle;
1970
1976
  exports.getDefaultElementStyle = getDefaultElementStyle;
1971
1977
  exports.getDefaultHighlightStyle = getDefaultHighlightStyle;
1972
- exports.getDefaultInnerShadow = getDefaultInnerShadow;
1973
1978
  exports.getDefaultLayoutStyle = getDefaultLayoutStyle;
1974
1979
  exports.getDefaultListStyleStyle = getDefaultListStyleStyle;
1975
- exports.getDefaultOuterShadow = getDefaultOuterShadow;
1980
+ exports.getDefaultOutlineStyle = getDefaultOutlineStyle;
1976
1981
  exports.getDefaultShadowStyle = getDefaultShadowStyle;
1977
1982
  exports.getDefaultStyle = getDefaultStyle;
1978
1983
  exports.getDefaultTextInlineStyle = getDefaultTextInlineStyle;
@@ -2008,7 +2013,6 @@ exports.normalizeCRLF = normalizeCRLF;
2008
2013
  exports.normalizeColor = normalizeColor;
2009
2014
  exports.normalizeColorFill = normalizeColorFill;
2010
2015
  exports.normalizeDocument = normalizeDocument;
2011
- exports.normalizeEffect = normalizeEffect;
2012
2016
  exports.normalizeElement = normalizeElement;
2013
2017
  exports.normalizeFill = normalizeFill;
2014
2018
  exports.normalizeFlatDocument = normalizeFlatDocument;
@@ -2016,13 +2020,10 @@ exports.normalizeForeground = normalizeForeground;
2016
2020
  exports.normalizeGradient = normalizeGradient;
2017
2021
  exports.normalizeGradientFill = normalizeGradientFill;
2018
2022
  exports.normalizeImageFill = normalizeImageFill;
2019
- exports.normalizeInnerShadow = normalizeInnerShadow;
2020
- exports.normalizeOuterShadow = normalizeOuterShadow;
2021
2023
  exports.normalizeOutline = normalizeOutline;
2022
2024
  exports.normalizePresetFill = normalizePresetFill;
2023
2025
  exports.normalizeShadow = normalizeShadow;
2024
2026
  exports.normalizeShape = normalizeShape;
2025
- exports.normalizeSoftEdge = normalizeSoftEdge;
2026
2027
  exports.normalizeStyle = normalizeStyle;
2027
2028
  exports.normalizeText = normalizeText;
2028
2029
  exports.normalizeTextContent = normalizeTextContent;