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 +99 -98
- package/dist/index.d.cts +86 -126
- package/dist/index.d.mts +86 -126
- package/dist/index.d.ts +86 -126
- package/dist/index.js +2 -2
- package/dist/index.mjs +98 -93
- package/package.json +12 -12
package/dist/index.mjs
CHANGED
|
@@ -1386,7 +1386,7 @@ function isPresetFill(fill) {
|
|
|
1386
1386
|
return typeof fill === "string" ? false : isPresetFillObject(fill);
|
|
1387
1387
|
}
|
|
1388
1388
|
function normalizeFill(fill) {
|
|
1389
|
-
const enabled = fill && typeof fill === "object" ? fill.enabled :
|
|
1389
|
+
const enabled = fill && typeof fill === "object" ? fill.enabled ?? true : true;
|
|
1390
1390
|
const obj = { enabled };
|
|
1391
1391
|
if (isColorFill(fill)) {
|
|
1392
1392
|
Object.assign(obj, normalizeColorFill(fill));
|
|
@@ -1401,6 +1401,7 @@ function normalizeFill(fill) {
|
|
|
1401
1401
|
Object.assign(obj, normalizePresetFill(fill));
|
|
1402
1402
|
}
|
|
1403
1403
|
return pick(clearUndef(obj), Array.from(/* @__PURE__ */ new Set([
|
|
1404
|
+
"enabled",
|
|
1404
1405
|
...colorFillFields,
|
|
1405
1406
|
...imageFillFiedls,
|
|
1406
1407
|
...gradientFillFields,
|
|
@@ -1421,48 +1422,106 @@ function normalizeBackground(background) {
|
|
|
1421
1422
|
}
|
|
1422
1423
|
}
|
|
1423
1424
|
|
|
1424
|
-
function
|
|
1425
|
+
function getDefaultBackgroundStyle() {
|
|
1425
1426
|
return {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1427
|
+
backgroundImage: "none",
|
|
1428
|
+
backgroundSize: "auto, auto",
|
|
1429
|
+
backgroundColor: "none",
|
|
1430
|
+
backgroundColormap: "none"
|
|
1430
1431
|
};
|
|
1431
1432
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
...
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1433
|
+
|
|
1434
|
+
function normalizeOutline(outline) {
|
|
1435
|
+
if (typeof outline === "string") {
|
|
1436
|
+
return {
|
|
1437
|
+
...normalizeFill(outline)
|
|
1438
|
+
};
|
|
1439
|
+
} else {
|
|
1440
|
+
return {
|
|
1441
|
+
...normalizeFill(outline),
|
|
1442
|
+
...pick(outline, ["width", "style", "lineCap", "lineJoin", "headEnd", "tailEnd"])
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1440
1445
|
}
|
|
1441
1446
|
|
|
1442
|
-
function
|
|
1447
|
+
function getDefaultOutlineStyle() {
|
|
1443
1448
|
return {
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1449
|
+
outlineWidth: 0,
|
|
1450
|
+
outlineOffset: 0,
|
|
1451
|
+
outlineColor: "none",
|
|
1452
|
+
outlineStyle: "none"
|
|
1447
1453
|
};
|
|
1448
1454
|
}
|
|
1449
|
-
|
|
1455
|
+
|
|
1456
|
+
function normalizeShadow(shadow) {
|
|
1457
|
+
if (typeof shadow === "string") {
|
|
1458
|
+
return {
|
|
1459
|
+
enabled: true,
|
|
1460
|
+
color: normalizeColor(shadow)
|
|
1461
|
+
};
|
|
1462
|
+
} else {
|
|
1463
|
+
return {
|
|
1464
|
+
...shadow,
|
|
1465
|
+
enabled: shadow.enabled ?? true,
|
|
1466
|
+
color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function getDefaultShadowStyle() {
|
|
1450
1472
|
return {
|
|
1451
|
-
|
|
1452
|
-
...normalizeInnerShadow(shadow)
|
|
1473
|
+
boxShadow: "none"
|
|
1453
1474
|
};
|
|
1454
1475
|
}
|
|
1455
1476
|
|
|
1456
|
-
|
|
1457
|
-
|
|
1477
|
+
const effectFields = [
|
|
1478
|
+
"fill",
|
|
1479
|
+
"outline",
|
|
1480
|
+
"shadow",
|
|
1481
|
+
"transform",
|
|
1482
|
+
"transformOrigin"
|
|
1483
|
+
];
|
|
1484
|
+
function normalizeEffectV0(effect) {
|
|
1485
|
+
const _effect = pick(effect, effectFields);
|
|
1486
|
+
const { rotate, scaleX, scaleY, skewX, skewY, translateX, translateY } = effect;
|
|
1487
|
+
const transforms = [];
|
|
1488
|
+
(translateX || translateY) && transforms.push(`translate(${translateX || 0}, ${translateY || 0})`);
|
|
1489
|
+
rotate && transforms.push(`rotate(${rotate}deg)`);
|
|
1490
|
+
(scaleX || scaleY) && transforms.push(`scale(${scaleX ?? 1}, ${scaleY ?? 1})`);
|
|
1491
|
+
skewX && transforms.push(`skewX(${skewX}deg)`);
|
|
1492
|
+
skewY && transforms.push(`skewY(${skewY}deg)`);
|
|
1493
|
+
if (transforms.length > 0) {
|
|
1494
|
+
_effect.transform = transforms.join(" ");
|
|
1495
|
+
}
|
|
1496
|
+
if (effect.textStrokeWidth || effect.textStrokeColor) {
|
|
1497
|
+
_effect.outline = {
|
|
1498
|
+
color: effect.textStrokeColor,
|
|
1499
|
+
width: effect.textStrokeWidth
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
if (effect.color) {
|
|
1503
|
+
_effect.fill = {
|
|
1504
|
+
color: effect.color
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
if (effect.shadowOffsetX || effect.shadowOffsetY || effect.shadowBlur || effect.shadowColor) {
|
|
1508
|
+
_effect.shadow = {
|
|
1509
|
+
offsetX: effect.shadowOffsetX,
|
|
1510
|
+
offsetY: effect.shadowOffsetY,
|
|
1511
|
+
blur: effect.shadowBlur,
|
|
1512
|
+
color: effect.shadowColor
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
return _effect;
|
|
1458
1516
|
}
|
|
1459
|
-
|
|
1460
1517
|
function normalizeEffect(effect) {
|
|
1518
|
+
const _effect = normalizeEffectV0(effect);
|
|
1461
1519
|
return clearUndef({
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1520
|
+
fill: isNone(_effect.fill) ? void 0 : normalizeFill(_effect.fill),
|
|
1521
|
+
outline: isNone(_effect.outline) ? void 0 : normalizeOutline(_effect.outline),
|
|
1522
|
+
shadow: isNone(_effect.shadow) ? void 0 : normalizeShadow(_effect.shadow),
|
|
1523
|
+
transform: isNone(_effect.transform) ? void 0 : _effect.transform,
|
|
1524
|
+
transformOrigin: _effect.transformOrigin
|
|
1466
1525
|
});
|
|
1467
1526
|
}
|
|
1468
1527
|
|
|
@@ -1484,52 +1543,16 @@ const nanoid = () => {
|
|
|
1484
1543
|
};
|
|
1485
1544
|
const idGenerator = nanoid;
|
|
1486
1545
|
|
|
1487
|
-
function normalizeOutline(outline) {
|
|
1488
|
-
if (typeof outline === "string") {
|
|
1489
|
-
return {
|
|
1490
|
-
...normalizeFill(outline)
|
|
1491
|
-
};
|
|
1492
|
-
} else {
|
|
1493
|
-
return {
|
|
1494
|
-
...normalizeFill(outline),
|
|
1495
|
-
...pick(outline, [
|
|
1496
|
-
"width",
|
|
1497
|
-
"style",
|
|
1498
|
-
"lineCap",
|
|
1499
|
-
"lineJoin",
|
|
1500
|
-
"headEnd",
|
|
1501
|
-
"tailEnd"
|
|
1502
|
-
])
|
|
1503
|
-
};
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
function normalizeShadow(shadow) {
|
|
1508
|
-
if (typeof shadow === "string") {
|
|
1509
|
-
return {
|
|
1510
|
-
color: normalizeColor(shadow)
|
|
1511
|
-
};
|
|
1512
|
-
} else {
|
|
1513
|
-
return {
|
|
1514
|
-
...shadow,
|
|
1515
|
-
color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
function getDefaultShadowStyle() {
|
|
1520
|
-
return {
|
|
1521
|
-
boxShadow: "none"
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
1546
|
function normalizeShape(shape) {
|
|
1526
1547
|
if (typeof shape === "string") {
|
|
1527
1548
|
if (shape.startsWith("<svg")) {
|
|
1528
1549
|
return {
|
|
1550
|
+
enabled: true,
|
|
1529
1551
|
svg: shape
|
|
1530
1552
|
};
|
|
1531
1553
|
} else {
|
|
1532
1554
|
return {
|
|
1555
|
+
enabled: true,
|
|
1533
1556
|
paths: [
|
|
1534
1557
|
{ data: shape }
|
|
1535
1558
|
]
|
|
@@ -1537,6 +1560,7 @@ function normalizeShape(shape) {
|
|
|
1537
1560
|
}
|
|
1538
1561
|
} else if (Array.isArray(shape)) {
|
|
1539
1562
|
return {
|
|
1563
|
+
enabled: true,
|
|
1540
1564
|
paths: shape.map((data) => {
|
|
1541
1565
|
if (typeof data === "string") {
|
|
1542
1566
|
return {
|
|
@@ -1606,13 +1630,6 @@ function getDefaultLayoutStyle() {
|
|
|
1606
1630
|
|
|
1607
1631
|
function getDefaultTransformStyle() {
|
|
1608
1632
|
return {
|
|
1609
|
-
rotate: 0,
|
|
1610
|
-
scaleX: 1,
|
|
1611
|
-
scaleY: 1,
|
|
1612
|
-
skewX: 0,
|
|
1613
|
-
skewY: 0,
|
|
1614
|
-
translateX: 0,
|
|
1615
|
-
translateY: 0,
|
|
1616
1633
|
transform: "none",
|
|
1617
1634
|
transformOrigin: "center"
|
|
1618
1635
|
};
|
|
@@ -1623,20 +1640,12 @@ function getDefaultElementStyle() {
|
|
|
1623
1640
|
...getDefaultLayoutStyle(),
|
|
1624
1641
|
...getDefaultTransformStyle(),
|
|
1625
1642
|
...getDefaultShadowStyle(),
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
backgroundSize: "auto, auto",
|
|
1629
|
-
backgroundColor: "none",
|
|
1630
|
-
backgroundColormap: "none",
|
|
1643
|
+
...getDefaultBackgroundStyle(),
|
|
1644
|
+
...getDefaultOutlineStyle(),
|
|
1631
1645
|
// border
|
|
1632
1646
|
borderRadius: 0,
|
|
1633
1647
|
borderColor: "none",
|
|
1634
1648
|
borderStyle: "solid",
|
|
1635
|
-
// outline
|
|
1636
|
-
outlineWidth: 0,
|
|
1637
|
-
outlineOffset: 0,
|
|
1638
|
-
outlineColor: "none",
|
|
1639
|
-
outlineStyle: "none",
|
|
1640
1649
|
// other
|
|
1641
1650
|
visibility: "visible",
|
|
1642
1651
|
filter: "none",
|
|
@@ -1845,18 +1854,18 @@ function isFragmentObject(value) {
|
|
|
1845
1854
|
function normalizeText(value) {
|
|
1846
1855
|
if (typeof value === "string" || Array.isArray(value)) {
|
|
1847
1856
|
return {
|
|
1857
|
+
enabled: true,
|
|
1848
1858
|
content: normalizeTextContent(value)
|
|
1849
1859
|
};
|
|
1850
1860
|
} else {
|
|
1851
1861
|
return clearUndef({
|
|
1852
|
-
|
|
1862
|
+
enabled: value.enabled ?? true,
|
|
1853
1863
|
content: normalizeTextContent(value.content ?? ""),
|
|
1854
1864
|
style: value.style ? normalizeStyle(value.style) : void 0,
|
|
1855
|
-
effects: value.effects ? value.effects.map((v) => normalizeStyle(v)) : void 0,
|
|
1856
1865
|
measureDom: value.measureDom,
|
|
1857
1866
|
fonts: value.fonts,
|
|
1858
|
-
|
|
1859
|
-
|
|
1867
|
+
...normalizeEffect(value),
|
|
1868
|
+
effects: value.effects ? value.effects.map((v) => normalizeEffect(v)) : void 0
|
|
1860
1869
|
});
|
|
1861
1870
|
}
|
|
1862
1871
|
}
|
|
@@ -1882,19 +1891,15 @@ function normalizeVideo(video) {
|
|
|
1882
1891
|
|
|
1883
1892
|
function normalizeElement(element) {
|
|
1884
1893
|
return clearUndef({
|
|
1885
|
-
...element,
|
|
1886
1894
|
id: element.id ?? idGenerator(),
|
|
1887
1895
|
style: isNone(element.style) ? void 0 : normalizeStyle(element.style),
|
|
1888
1896
|
text: isNone(element.text) ? void 0 : normalizeText(element.text),
|
|
1889
1897
|
background: isNone(element.background) ? void 0 : normalizeBackground(element.background),
|
|
1890
1898
|
shape: isNone(element.shape) ? void 0 : normalizeShape(element.shape),
|
|
1891
|
-
fill: isNone(element.fill) ? void 0 : normalizeFill(element.fill),
|
|
1892
|
-
outline: isNone(element.outline) ? void 0 : normalizeOutline(element.outline),
|
|
1893
1899
|
foreground: isNone(element.foreground) ? void 0 : normalizeForeground(element.foreground),
|
|
1894
|
-
shadow: isNone(element.shadow) ? void 0 : normalizeShadow(element.shadow),
|
|
1895
1900
|
video: isNone(element.video) ? void 0 : normalizeVideo(element.video),
|
|
1896
1901
|
audio: isNone(element.audio) ? void 0 : normalizeAudio(element.audio),
|
|
1897
|
-
|
|
1902
|
+
...normalizeEffect(element),
|
|
1898
1903
|
children: element.children?.map((child) => normalizeElement(child))
|
|
1899
1904
|
});
|
|
1900
1905
|
}
|
|
@@ -1955,4 +1960,4 @@ function flatDocumentToDocument(flatDoc) {
|
|
|
1955
1960
|
return doc;
|
|
1956
1961
|
}
|
|
1957
1962
|
|
|
1958
|
-
export { EventEmitter, Observable, RawWeakMap, Reactivable, clearUndef, colorFillFields, defaultColor, defineProperty, flatDocumentToDocument, getDeclarations, getDefaultElementStyle, getDefaultHighlightStyle,
|
|
1963
|
+
export { EventEmitter, Observable, RawWeakMap, Reactivable, clearUndef, colorFillFields, defaultColor, defineProperty, flatDocumentToDocument, getDeclarations, getDefaultBackgroundStyle, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOutlineStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, getNestedValue, getObjectValueByPath, getPropertyDescriptor, gradientFillFields, hasCRLF, idGenerator, imageFillFiedls, isCRLF, isColor, isColorFill, isColorFillObject, isEqualObject, isFragmentObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isParagraphObject, isPresetFill, isPresetFillObject, nanoid, normalizeAudio, normalizeBackground, normalizeCRLF, normalizeColor, normalizeColorFill, normalizeDocument, normalizeElement, normalizeFill, normalizeFlatDocument, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, pick, presetFillFiedls, property, property2, propertyOffsetFallback, propertyOffsetGet, propertyOffsetSet, round, setNestedValue, setObjectValueByPath, stringifyGradient, textContentToString };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-idoc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"packageManager": "pnpm@10.18.1",
|
|
6
6
|
"description": "Intermediate document for modern codec libs",
|
|
7
7
|
"author": "wxm",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"build": "vite build && unbuild",
|
|
47
47
|
"build:schema": "npx ts-json-schema-generator --minify --expose 'export' --no-top-ref --path 'src/index.ts' --type 'NormalizedDocument' --tsconfig=./tsconfig.json > dist/schema.json",
|
|
48
48
|
"dev": "vite docs",
|
|
49
|
-
"lint": "eslint
|
|
49
|
+
"lint": "eslint src",
|
|
50
50
|
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
|
|
51
51
|
"release": "bumpp package.json --commit \"release: v%s\" --push --all --tag",
|
|
52
52
|
"start": "esno src/index.ts",
|
|
@@ -56,25 +56,25 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"colord": "^2.9.3",
|
|
59
|
-
"nanoid": "^5.1.
|
|
59
|
+
"nanoid": "^5.1.11"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@antfu/eslint-config": "^
|
|
63
|
-
"@types/node": "^25.
|
|
64
|
-
"bumpp": "^
|
|
62
|
+
"@antfu/eslint-config": "^8.2.0",
|
|
63
|
+
"@types/node": "^25.6.0",
|
|
64
|
+
"bumpp": "^11.0.1",
|
|
65
65
|
"conventional-changelog-cli": "^5.0.0",
|
|
66
|
-
"eslint": "^
|
|
67
|
-
"lint-staged": "^16.
|
|
66
|
+
"eslint": "^10.3.0",
|
|
67
|
+
"lint-staged": "^16.4.0",
|
|
68
68
|
"simple-git-hooks": "^2.13.1",
|
|
69
|
-
"typescript": "^
|
|
69
|
+
"typescript": "^6.0.3",
|
|
70
70
|
"unbuild": "^3.6.1",
|
|
71
|
-
"vite": "^
|
|
72
|
-
"vitest": "^4.
|
|
71
|
+
"vite": "^8.0.10",
|
|
72
|
+
"vitest": "^4.1.5"
|
|
73
73
|
},
|
|
74
74
|
"simple-git-hooks": {
|
|
75
75
|
"pre-commit": "pnpm lint-staged"
|
|
76
76
|
},
|
|
77
77
|
"lint-staged": {
|
|
78
|
-
"*": "eslint --fix"
|
|
78
|
+
"*": "eslint src --fix"
|
|
79
79
|
}
|
|
80
80
|
}
|