@pairdraw/pen 0.21.0 → 0.22.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/chunks/index.js +285 -90
- package/dist/chunks/index.js.map +1 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/package.json +2 -2
- package/src/index.ts +3 -1
- package/src/nodes.ts +5 -2
- package/src/write.ts +351 -125
package/dist/chunks/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import { getNodeLocalMatrix, localTransformFromWorld } from "@pairdraw/scene-gra
|
|
|
24
24
|
import { fitEnclosingGroups } from "@pairdraw/scene-graph/group-bounds";
|
|
25
25
|
import Matrix from "@pairdraw/scene-graph/matrix";
|
|
26
26
|
import { canCreateSlot, claimSlotContent, createSlotProperty, slotOwner, slotScope, updateSlotProperty } from "@pairdraw/scene-graph/slots";
|
|
27
|
-
import {
|
|
27
|
+
import { omit } from "es-toolkit";
|
|
28
28
|
import { parseFontStyle } from "@pairdraw/scene-graph/font-style";
|
|
29
29
|
import { percentLength, pixelLength } from "@pairdraw/scene-graph/text";
|
|
30
30
|
import { fromUint8Array } from "js-base64";
|
|
@@ -555,10 +555,10 @@ const PROPERTY_FIELDS = {
|
|
|
555
555
|
rotation: PLACEMENT_FIELDS,
|
|
556
556
|
fill: ["fills"],
|
|
557
557
|
stroke: STROKE_WRITES,
|
|
558
|
-
strokeWidth: STROKE_WRITES,
|
|
558
|
+
strokeWidth: [...STROKE_WRITES, "strokeWeight"],
|
|
559
559
|
strokeLinecap: ["strokes", "strokeCap"],
|
|
560
560
|
strokeLinejoin: ["strokes", "strokeJoin"],
|
|
561
|
-
strokeAlignment: ["strokes"],
|
|
561
|
+
strokeAlignment: ["strokes", "strokeAlign"],
|
|
562
562
|
effect: ["effects"],
|
|
563
563
|
cornerRadius: CORNER_FIELDS,
|
|
564
564
|
layout: ["layoutMode"],
|
|
@@ -611,6 +611,8 @@ const PROPERTY_FIELDS = {
|
|
|
611
611
|
scrollX: ["pluginData"],
|
|
612
612
|
scrollY: ["pluginData"]
|
|
613
613
|
};
|
|
614
|
+
/** Every pen field an override can name, and the scene fields it writes (see PROPERTY_FIELDS). */
|
|
615
|
+
const PEN_PROPERTY_FIELDS = Object.keys(PROPERTY_FIELDS);
|
|
614
616
|
const isProperty = (key) => key in PROPERTY_FIELDS;
|
|
615
617
|
/**
|
|
616
618
|
* The fields the properties `pen` carries write, whatever their values: pen.dev keeps a property
|
|
@@ -1102,6 +1104,30 @@ const PEN_PLUGIN_FIELDS = {
|
|
|
1102
1104
|
"pen/scrollX": "scrollX",
|
|
1103
1105
|
"pen/scrollY": "scrollY"
|
|
1104
1106
|
};
|
|
1107
|
+
/** The English sentence a write warning has always been reported as. */
|
|
1108
|
+
function penWriteWarningText(warning) {
|
|
1109
|
+
switch (warning.kind) {
|
|
1110
|
+
case "merged-pages": return `Pencil.dev files hold one page; ${warning.pages} pages were merged into “${warning.name}”.`;
|
|
1111
|
+
case "display-p3-colors": return "Colors are written as sRGB hex, the only form a Pencil.dev file holds; a Display P3 color outside sRGB comes out as the nearest sRGB color.";
|
|
1112
|
+
case "library-definitions": return `Library components came from ${warning.count} enabled ${warning.count === 1 ? "library" : "libraries"}, whose definitions Pencil.dev files do not hold; re-enable those libraries after reopening to restore them.`;
|
|
1113
|
+
case "missing-image-fills": return `Image fills with missing image data were left out (${warning.count}); Pencil.dev files cannot hold a paint without its image.`;
|
|
1114
|
+
case "flattened-image-tiles": return `Tiled image fills were written as filled images (${warning.count}); Pencil.dev files cannot hold tiling.`;
|
|
1115
|
+
case "dropped-constraints": return `Resize constraints were left out of ${warning.count} ${warning.count === 1 ? "layer" : "layers"}; Pencil.dev files do not hold them.`;
|
|
1116
|
+
case "dropped-effects": return `Noise and texture effects were left out (${warning.count}); Pencil.dev files have no form for them.`;
|
|
1117
|
+
case "dropped-filters": return `Image adjustment filters were left out (${warning.count}); Pencil.dev files have no form for them.`;
|
|
1118
|
+
case "dropped-scroll": return `Scroll overflow was left out (${warning.count}); Pencil.dev files have no form for it.`;
|
|
1119
|
+
case "dropped-font-features": return `OpenType font features were left out (${warning.count}); Pencil.dev files have no form for them.`;
|
|
1120
|
+
case "dropped-layout-grids": return `Layout grids were left out (${warning.count} ${warning.count === 1 ? "frame" : "frames"}); Pencil.dev files have no form for them.`;
|
|
1121
|
+
case "dropped-overrides": return `Instance overrides a Pencil.dev file cannot name were left out (${warning.count}); the instance still links to its component.`;
|
|
1122
|
+
case "flattened-swaps": return `Instance swaps a Pencil.dev file cannot name were written as the layers they show (${warning.count}); they reopen detached from their components.`;
|
|
1123
|
+
default: throw new Error(`Unhandled pen write warning: ${String(warning)}`);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
/** Records a warning as its sentence and its kind, in the order it was found. */
|
|
1127
|
+
function emit(state, warning) {
|
|
1128
|
+
state.details.push(warning);
|
|
1129
|
+
state.warnings.push(penWriteWarningText(warning));
|
|
1130
|
+
}
|
|
1105
1131
|
/** Snaps matrix values that are within floating-point noise of an integer. */
|
|
1106
1132
|
function snapCoordinate(value) {
|
|
1107
1133
|
return Math.abs(value - Math.round(value)) < 1e-9 ? Math.round(value) : value;
|
|
@@ -1261,6 +1287,7 @@ function imagePaint(state, fill) {
|
|
|
1261
1287
|
...paintBase(fill),
|
|
1262
1288
|
url: `data:${imageMimeType(bytes)};base64,${fromUint8Array(bytes)}`
|
|
1263
1289
|
};
|
|
1290
|
+
if (fill.imageScaleMode === "TILE") state.drops.tileImages++;
|
|
1264
1291
|
if (fill.imageScaleMode === "FIT") paint.mode = "contain";
|
|
1265
1292
|
if (fill.imageScaleMode === "CROP") {
|
|
1266
1293
|
paint.mode = "stretch";
|
|
@@ -1376,7 +1403,6 @@ function layoutFields(state, node) {
|
|
|
1376
1403
|
variableOr(state, node, "paddingLeft", node.paddingLeft)
|
|
1377
1404
|
];
|
|
1378
1405
|
if (padding.some((value) => value !== 0)) fields.padding = padding;
|
|
1379
|
-
if (node.clipsContent) fields.clip = true;
|
|
1380
1406
|
if (node.strokesIncludedInLayout) fields.layoutIncludeStroke = true;
|
|
1381
1407
|
return fields;
|
|
1382
1408
|
}
|
|
@@ -1528,7 +1554,25 @@ function basicNodeFields(state, node, result) {
|
|
|
1528
1554
|
if (theme) result.theme = theme;
|
|
1529
1555
|
const fill = paintsOf(state, node, "fills", node.fills);
|
|
1530
1556
|
if (fill !== void 0) result.fill = fill;
|
|
1531
|
-
|
|
1557
|
+
if (node.clipsContent) result.clip = true;
|
|
1558
|
+
Object.assign(result, strokesOf(state, node), layoutFields(state, node), cornerFields(state, node), textFields(state, node), shapeFields(node));
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* The shape fields pen stores outside the paint and layout groups: an ellipse's arc, which the
|
|
1562
|
+
* reader rebuilds on reopen, and a polygon's point count, whose pen default (3) the reader uses
|
|
1563
|
+
* when the field is absent.
|
|
1564
|
+
*/
|
|
1565
|
+
function shapeFields(node) {
|
|
1566
|
+
if (node.type === "ELLIPSE" && node.arcData) {
|
|
1567
|
+
const { startingAngle, endingAngle, innerRadius } = node.arcData;
|
|
1568
|
+
return {
|
|
1569
|
+
innerRadius: rounded(innerRadius),
|
|
1570
|
+
startAngle: rounded(-startingAngle * 180 / Math.PI),
|
|
1571
|
+
sweepAngle: rounded(-((endingAngle - startingAngle) * 180) / Math.PI)
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
if ((node.type === "POLYGON" || node.type === "STAR") && node.pointCount !== 3) return { polygonCount: node.pointCount };
|
|
1575
|
+
return {};
|
|
1532
1576
|
}
|
|
1533
1577
|
/**
|
|
1534
1578
|
* A layer's variable mode assignments, by the names pen writes: the collection's name and the
|
|
@@ -1544,44 +1588,43 @@ function themeFields(state, node) {
|
|
|
1544
1588
|
return Object.keys(theme).length > 0 ? theme : void 0;
|
|
1545
1589
|
}
|
|
1546
1590
|
/**
|
|
1547
|
-
*
|
|
1548
|
-
*
|
|
1591
|
+
* Pen override fields the writer must never store, because a reopen recalculates them from the
|
|
1592
|
+
* component and the boxes around it (X), or they are shape facts of a component, not a layer (Y).
|
|
1593
|
+
* Every other field PEN_PROPERTY_FIELDS names is writable, so the allow list follows the property
|
|
1594
|
+
* map instead of drifting beside it; a field missing here fails a test rather than disappearing.
|
|
1595
|
+
* Some names are writable in principle but never written today because their property map names no
|
|
1596
|
+
* recordable scene field: the icon identity fields (library, icon, weight, iconFontName,
|
|
1597
|
+
* iconFontFamily), text decoration (underline, strikethrough), and the plugin-only names whose map
|
|
1598
|
+
* is just `pluginData`. If INSTANCE_OVERRIDE_FIELDS ever gains one of those targets, add the name
|
|
1599
|
+
* here first.
|
|
1549
1600
|
*/
|
|
1550
|
-
const
|
|
1551
|
-
"
|
|
1552
|
-
"
|
|
1553
|
-
"
|
|
1554
|
-
"
|
|
1555
|
-
"
|
|
1556
|
-
"
|
|
1557
|
-
"
|
|
1558
|
-
"
|
|
1559
|
-
"
|
|
1560
|
-
"
|
|
1561
|
-
"
|
|
1562
|
-
"
|
|
1563
|
-
"
|
|
1564
|
-
"
|
|
1565
|
-
"
|
|
1566
|
-
"
|
|
1567
|
-
"
|
|
1601
|
+
const PEN_DENIED_OVERRIDE_FIELDS = /* @__PURE__ */ new Set([
|
|
1602
|
+
"x",
|
|
1603
|
+
"y",
|
|
1604
|
+
"rotation",
|
|
1605
|
+
"flipX",
|
|
1606
|
+
"flipY",
|
|
1607
|
+
"layoutPosition",
|
|
1608
|
+
"layout",
|
|
1609
|
+
"gap",
|
|
1610
|
+
"padding",
|
|
1611
|
+
"justifyContent",
|
|
1612
|
+
"alignItems",
|
|
1613
|
+
"layoutIncludeStroke",
|
|
1614
|
+
"viewBox",
|
|
1615
|
+
"geometry",
|
|
1616
|
+
"fillRule",
|
|
1617
|
+
"reusable",
|
|
1618
|
+
"slot",
|
|
1619
|
+
"placeholder",
|
|
1620
|
+
"ref",
|
|
1621
|
+
"innerRadius",
|
|
1622
|
+
"startAngle",
|
|
1623
|
+
"sweepAngle",
|
|
1624
|
+
"polygonCount"
|
|
1568
1625
|
]);
|
|
1569
|
-
/**
|
|
1570
|
-
|
|
1571
|
-
* copies, as pen names a `descendants` override. A copy that swapped its component copies `swapOf`
|
|
1572
|
-
* instead of the component it draws.
|
|
1573
|
-
*/
|
|
1574
|
-
function overridePath(graph, instanceId, copyId, swapOf) {
|
|
1575
|
-
const parts = [];
|
|
1576
|
-
let current = graph.getNode(copyId);
|
|
1577
|
-
while (current && current.id !== instanceId) {
|
|
1578
|
-
const id = current.id === copyId && swapOf ? swapOf : current.componentId;
|
|
1579
|
-
if (!id) return null;
|
|
1580
|
-
parts.unshift(id);
|
|
1581
|
-
current = current.parentId ? graph.getNode(current.parentId) : void 0;
|
|
1582
|
-
}
|
|
1583
|
-
return current ? parts.join("/") : null;
|
|
1584
|
-
}
|
|
1626
|
+
/** The pen fields an instance override writes: everything the property map names but the denylist. */
|
|
1627
|
+
const PEN_OVERRIDE_FIELDS = PEN_PROPERTY_FIELDS.filter((field) => !PEN_DENIED_OVERRIDE_FIELDS.has(field));
|
|
1585
1628
|
/**
|
|
1586
1629
|
* The fields a swap override names an icon by: pen carries the glyph, not the component drawn.
|
|
1587
1630
|
*/
|
|
@@ -1594,58 +1637,156 @@ function iconOverride(graph, componentId) {
|
|
|
1594
1637
|
return override;
|
|
1595
1638
|
}
|
|
1596
1639
|
/**
|
|
1597
|
-
* The
|
|
1598
|
-
*
|
|
1599
|
-
*
|
|
1640
|
+
* The pen fields a copy's recorded overrides name, in pen's own names. A field is written when the
|
|
1641
|
+
* copy records at least one scene field it maps to, so a value set back to the component's own
|
|
1642
|
+
* still belongs to the instance.
|
|
1600
1643
|
*/
|
|
1601
|
-
function
|
|
1602
|
-
const
|
|
1603
|
-
if (overridden.length === 0) return { unrepresentable: false };
|
|
1604
|
-
const probe = {
|
|
1644
|
+
function overrideFieldsFor(state, copy, overrides) {
|
|
1645
|
+
const own = writeNode({
|
|
1605
1646
|
...state,
|
|
1606
1647
|
drops: {
|
|
1607
1648
|
images: 0,
|
|
1649
|
+
tileImages: 0,
|
|
1650
|
+
constraints: 0,
|
|
1608
1651
|
effects: 0,
|
|
1609
1652
|
filters: 0,
|
|
1610
1653
|
scroll: 0,
|
|
1611
|
-
fontFeatures: 0
|
|
1654
|
+
fontFeatures: 0,
|
|
1655
|
+
overrides: 0,
|
|
1656
|
+
swaps: 0,
|
|
1657
|
+
layoutGrids: 0
|
|
1658
|
+
}
|
|
1659
|
+
}, copy);
|
|
1660
|
+
const override = {};
|
|
1661
|
+
for (const field of PEN_OVERRIDE_FIELDS) {
|
|
1662
|
+
if (!(field in own)) continue;
|
|
1663
|
+
if (field === "width" || field === "height") {
|
|
1664
|
+
const axis = field === "width" ? "HORIZONTAL" : "VERTICAL";
|
|
1665
|
+
if (layoutSizing(state.graph, copy, axis) !== "FIXED") continue;
|
|
1612
1666
|
}
|
|
1667
|
+
const value = own[field];
|
|
1668
|
+
if (!fieldsSetBy({ [field]: value }).some((key) => overrides.has(key))) continue;
|
|
1669
|
+
override[field] = value;
|
|
1670
|
+
}
|
|
1671
|
+
return override;
|
|
1672
|
+
}
|
|
1673
|
+
/** Adds a field map at a path, merging with one already there instead of replacing it. */
|
|
1674
|
+
function mergeOverride(entries, path, fields) {
|
|
1675
|
+
entries[path] = {
|
|
1676
|
+
...entries[path],
|
|
1677
|
+
...fields
|
|
1613
1678
|
};
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* The overrides an instance writes, and whether one of them is a swap the file cannot name.
|
|
1682
|
+
*
|
|
1683
|
+
* Three cases:
|
|
1684
|
+
* (i) a direct override, and a plain layer deeper than one level, is written at the authored layer id
|
|
1685
|
+
* from the component definition (a copy only holds the component it draws, so the definition is
|
|
1686
|
+
* paired with the copy list at every plain level);
|
|
1687
|
+
* (ii) a same-file nested instance (b1) resolves through its materialized `INSTANCE` chain to the
|
|
1688
|
+
* authored component, and its own overrides merge as flat `parent/child` paths;
|
|
1689
|
+
* (iii) an imported nested component resolves outside the file (b2 stores an authored-id map when
|
|
1690
|
+
* that changes), so its override is left out and counted in `drops.overrides` while the instance
|
|
1691
|
+
* keeps its `ref`; a swap the file cannot name as a glyph flattens the instance and is counted in
|
|
1692
|
+
* `drops.swaps`.
|
|
1693
|
+
* `copyPaths` pairs definitions with copies positionally; it skips nested `INSTANCE` copies because
|
|
1694
|
+
* their paths are collected by the recursion below, not because they are unnameable.
|
|
1695
|
+
*/
|
|
1696
|
+
function instanceDescendants(state, node) {
|
|
1697
|
+
/** The authored path of every copy this instance shows, plain layers included. */
|
|
1698
|
+
const copyPaths = (componentId, instanceId, base) => {
|
|
1699
|
+
const component = state.graph.getNode(componentId);
|
|
1700
|
+
if (!component) return null;
|
|
1701
|
+
const definition = state.graph.getChildren(component.id);
|
|
1702
|
+
const copies = state.graph.getChildren(instanceId);
|
|
1703
|
+
if (definition.length !== copies.length) return null;
|
|
1704
|
+
const paths = /* @__PURE__ */ new Map();
|
|
1705
|
+
for (let index = 0; index < definition.length; index++) {
|
|
1706
|
+
const authored = definition[index];
|
|
1707
|
+
const copy = copies[index];
|
|
1708
|
+
const path = `${base}${authored.id}`;
|
|
1709
|
+
paths.set(copy.id, path);
|
|
1710
|
+
if (copy.type !== "INSTANCE") {
|
|
1711
|
+
const deeper = copyPaths(authored.id, copy.id, `${path}/`);
|
|
1712
|
+
if (!deeper) return null;
|
|
1713
|
+
for (const [id, value] of deeper) paths.set(id, value);
|
|
1714
|
+
}
|
|
1625
1715
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1716
|
+
return paths;
|
|
1717
|
+
};
|
|
1718
|
+
/**
|
|
1719
|
+
* The authored COMPONENT behind a copy's component id. A nested ref is materialized as an
|
|
1720
|
+
* INSTANCE that points at the authored component, so following that chain is what makes a
|
|
1721
|
+
* same-file nested layer nameable; an imported component's chain ends outside the file.
|
|
1722
|
+
*/
|
|
1723
|
+
const authoredComponentId = (componentId) => {
|
|
1724
|
+
let node = state.graph.getNode(componentId);
|
|
1725
|
+
for (let depth = 0; node && depth < 8; depth++) {
|
|
1726
|
+
if (node.type === "COMPONENT") return node.id;
|
|
1727
|
+
if (node.type !== "INSTANCE" || !node.componentId) return void 0;
|
|
1728
|
+
node = state.graph.getNode(node.componentId);
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
const collect = (instance, componentId) => {
|
|
1732
|
+
const authored = authoredComponentId(componentId);
|
|
1733
|
+
if (!authored) return { unrepresentable: true };
|
|
1734
|
+
const paths = copyPaths(authored, instance.id, "");
|
|
1735
|
+
if (!paths) return { unrepresentable: true };
|
|
1736
|
+
const entries = {};
|
|
1737
|
+
const swapped = /* @__PURE__ */ new Set();
|
|
1738
|
+
let unrepresentable = false;
|
|
1739
|
+
for (const [copyId, overrides] of instance.instanceOverrides.descendants) {
|
|
1740
|
+
const path = paths.get(copyId);
|
|
1741
|
+
const copy = state.graph.getNode(copyId);
|
|
1742
|
+
if (!path || !copy) {
|
|
1743
|
+
state.drops.overrides++;
|
|
1630
1744
|
continue;
|
|
1631
1745
|
}
|
|
1632
|
-
|
|
1633
|
-
|
|
1746
|
+
if (overrides.has("componentId")) {
|
|
1747
|
+
const icon = iconOverride(state.graph, copy.componentId);
|
|
1748
|
+
if (!icon) {
|
|
1749
|
+
unrepresentable = true;
|
|
1750
|
+
continue;
|
|
1751
|
+
}
|
|
1752
|
+
state.drops.overrides += copy.instanceOverrides.descendants.size;
|
|
1753
|
+
entries[path] = {
|
|
1754
|
+
...icon,
|
|
1755
|
+
...overrideFieldsFor(state, copy, overrides)
|
|
1756
|
+
};
|
|
1757
|
+
swapped.add(copyId);
|
|
1758
|
+
continue;
|
|
1759
|
+
}
|
|
1760
|
+
const fields = overrideFieldsFor(state, copy, overrides);
|
|
1761
|
+
if (Object.keys(fields).length > 0) mergeOverride(entries, path, fields);
|
|
1634
1762
|
}
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
continue;
|
|
1763
|
+
for (const [copyId, path] of paths) {
|
|
1764
|
+
if (swapped.has(copyId)) continue;
|
|
1765
|
+
const copy = state.graph.getNode(copyId);
|
|
1766
|
+
if (copy?.type !== "INSTANCE" || !copy.componentId) continue;
|
|
1767
|
+
const nestedAuthored = authoredComponentId(copy.componentId);
|
|
1768
|
+
if (!nestedAuthored || !state.writtenIds.has(nestedAuthored)) {
|
|
1769
|
+
state.drops.overrides += copy.instanceOverrides.descendants.size;
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
const deeper = collect(copy, copy.componentId);
|
|
1773
|
+
if (deeper.unrepresentable) {
|
|
1774
|
+
unrepresentable = true;
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
for (const [sub, value] of Object.entries(deeper.entries ?? {})) mergeOverride(entries, `${path}/${sub}`, value);
|
|
1639
1778
|
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1779
|
+
return unrepresentable ? { unrepresentable } : {
|
|
1780
|
+
entries,
|
|
1781
|
+
unrepresentable
|
|
1782
|
+
};
|
|
1783
|
+
};
|
|
1784
|
+
if (!node.componentId) return { unrepresentable: true };
|
|
1785
|
+
const collected = collect(node, node.componentId);
|
|
1786
|
+
if (collected.unrepresentable) return { unrepresentable: true };
|
|
1646
1787
|
return {
|
|
1647
|
-
descendants: Object.keys(
|
|
1648
|
-
unrepresentable
|
|
1788
|
+
descendants: Object.keys(collected.entries ?? {}).length > 0 ? collected.entries : void 0,
|
|
1789
|
+
unrepresentable: false
|
|
1649
1790
|
};
|
|
1650
1791
|
}
|
|
1651
1792
|
function semanticNodeFields(state, node, result) {
|
|
@@ -1662,7 +1803,10 @@ function semanticNodeFields(state, node, result) {
|
|
|
1662
1803
|
if (node.type === "COMPONENT" || node.type === "COMPONENT_SET") result.reusable = true;
|
|
1663
1804
|
if (node.type === "INSTANCE" && node.componentId && (state.writtenIds.has(node.componentId) || state.importedIds.has(node.componentId))) {
|
|
1664
1805
|
const overrides = instanceDescendants(state, node);
|
|
1665
|
-
if (overrides.unrepresentable
|
|
1806
|
+
if (overrides.unrepresentable) {
|
|
1807
|
+
state.drops.swaps++;
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1666
1810
|
result.type = "ref";
|
|
1667
1811
|
result.ref = node.componentId;
|
|
1668
1812
|
if (overrides.descendants) result.descendants = overrides.descendants;
|
|
@@ -1671,7 +1815,9 @@ function semanticNodeFields(state, node, result) {
|
|
|
1671
1815
|
return false;
|
|
1672
1816
|
}
|
|
1673
1817
|
function writeNode(state, node) {
|
|
1818
|
+
if (node.horizontalConstraint !== "MIN" || node.verticalConstraint !== "MIN") state.drops.constraints++;
|
|
1674
1819
|
if (node.overflowDirection !== "NONE") state.drops.scroll++;
|
|
1820
|
+
if (node.layoutGrids.length > 0) state.drops.layoutGrids++;
|
|
1675
1821
|
if (node.fontFeatures.length > 0) state.drops.fontFeatures++;
|
|
1676
1822
|
const result = {
|
|
1677
1823
|
id: node.id,
|
|
@@ -1724,12 +1870,18 @@ function penDocumentFromGraph(graph, options = {}) {
|
|
|
1724
1870
|
writtenIds: writtenNodeIds(graph),
|
|
1725
1871
|
importedIds: importedComponentIds(graph, imports ?? {}),
|
|
1726
1872
|
warnings: options.warnings ?? [],
|
|
1873
|
+
details: [],
|
|
1727
1874
|
drops: {
|
|
1728
1875
|
images: 0,
|
|
1876
|
+
tileImages: 0,
|
|
1877
|
+
constraints: 0,
|
|
1729
1878
|
effects: 0,
|
|
1730
1879
|
filters: 0,
|
|
1731
1880
|
scroll: 0,
|
|
1732
|
-
fontFeatures: 0
|
|
1881
|
+
fontFeatures: 0,
|
|
1882
|
+
overrides: 0,
|
|
1883
|
+
swaps: 0,
|
|
1884
|
+
layoutGrids: 0
|
|
1733
1885
|
}
|
|
1734
1886
|
};
|
|
1735
1887
|
const pages = graph.getPages();
|
|
@@ -1772,10 +1924,15 @@ function penDocumentFromGraph(graph, options = {}) {
|
|
|
1772
1924
|
if (publication) document.sourceLibraryPublication = publication;
|
|
1773
1925
|
if (pages.length > 1) {
|
|
1774
1926
|
const name = document.name ?? "Page 1";
|
|
1775
|
-
state
|
|
1927
|
+
emit(state, {
|
|
1928
|
+
kind: "merged-pages",
|
|
1929
|
+
pages: pages.length,
|
|
1930
|
+
name
|
|
1931
|
+
});
|
|
1776
1932
|
}
|
|
1777
|
-
if (graph.documentColorSpace === "display-p3") state
|
|
1933
|
+
if (graph.documentColorSpace === "display-p3") emit(state, { kind: "display-p3-colors" });
|
|
1778
1934
|
reportDrops(state);
|
|
1935
|
+
options.warningDetails?.push(...state.details);
|
|
1779
1936
|
return document;
|
|
1780
1937
|
}
|
|
1781
1938
|
/**
|
|
@@ -1787,17 +1944,55 @@ function enabledLibrariesOf(graph, state) {
|
|
|
1787
1944
|
const bindings = [...graph.enabledLibraries.values()];
|
|
1788
1945
|
if (bindings.length === 0) return null;
|
|
1789
1946
|
const enabled = bindings.filter((binding) => binding.enabled).length;
|
|
1790
|
-
if (enabled > 0) state
|
|
1947
|
+
if (enabled > 0) emit(state, {
|
|
1948
|
+
kind: "library-definitions",
|
|
1949
|
+
count: enabled
|
|
1950
|
+
});
|
|
1791
1951
|
return bindings;
|
|
1792
1952
|
}
|
|
1793
1953
|
/** Adds one sentence for each kind of content the written file had to leave out. */
|
|
1794
1954
|
function reportDrops(state) {
|
|
1795
|
-
const { images, effects, filters, scroll, fontFeatures } = state.drops;
|
|
1796
|
-
if (images > 0) state
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
if (
|
|
1955
|
+
const { images, tileImages, constraints, effects, filters, scroll, fontFeatures, layoutGrids } = state.drops;
|
|
1956
|
+
if (images > 0) emit(state, {
|
|
1957
|
+
kind: "missing-image-fills",
|
|
1958
|
+
count: images
|
|
1959
|
+
});
|
|
1960
|
+
if (tileImages > 0) emit(state, {
|
|
1961
|
+
kind: "flattened-image-tiles",
|
|
1962
|
+
count: tileImages
|
|
1963
|
+
});
|
|
1964
|
+
if (constraints > 0) emit(state, {
|
|
1965
|
+
kind: "dropped-constraints",
|
|
1966
|
+
count: constraints
|
|
1967
|
+
});
|
|
1968
|
+
if (effects > 0) emit(state, {
|
|
1969
|
+
kind: "dropped-effects",
|
|
1970
|
+
count: effects
|
|
1971
|
+
});
|
|
1972
|
+
if (filters > 0) emit(state, {
|
|
1973
|
+
kind: "dropped-filters",
|
|
1974
|
+
count: filters
|
|
1975
|
+
});
|
|
1976
|
+
if (scroll > 0) emit(state, {
|
|
1977
|
+
kind: "dropped-scroll",
|
|
1978
|
+
count: scroll
|
|
1979
|
+
});
|
|
1980
|
+
if (fontFeatures > 0) emit(state, {
|
|
1981
|
+
kind: "dropped-font-features",
|
|
1982
|
+
count: fontFeatures
|
|
1983
|
+
});
|
|
1984
|
+
if (layoutGrids > 0) emit(state, {
|
|
1985
|
+
kind: "dropped-layout-grids",
|
|
1986
|
+
count: layoutGrids
|
|
1987
|
+
});
|
|
1988
|
+
if (state.drops.overrides > 0) emit(state, {
|
|
1989
|
+
kind: "dropped-overrides",
|
|
1990
|
+
count: state.drops.overrides
|
|
1991
|
+
});
|
|
1992
|
+
if (state.drops.swaps > 0) emit(state, {
|
|
1993
|
+
kind: "flattened-swaps",
|
|
1994
|
+
count: state.drops.swaps
|
|
1995
|
+
});
|
|
1801
1996
|
}
|
|
1802
1997
|
function stringifyPenDocument(document) {
|
|
1803
1998
|
return `${JSON.stringify(sortKeys(document), null, 2)}\n`;
|
|
@@ -1806,6 +2001,6 @@ function writePenDocument(source, options = {}) {
|
|
|
1806
2001
|
return stringifyPenDocument(source instanceof SceneGraph ? penDocumentFromGraph(source, options) : source);
|
|
1807
2002
|
}
|
|
1808
2003
|
//#endregion
|
|
1809
|
-
export { buildPenGraph, parsePenDocument, parsePenFile, penDocumentFromGraph, readPenFile, stringifyPenDocument, withUsedImports, writePenDocument };
|
|
2004
|
+
export { buildPenGraph, parsePenDocument, parsePenFile, penDocumentFromGraph, penWriteWarningText, readPenFile, stringifyPenDocument, withUsedImports, writePenDocument };
|
|
1810
2005
|
|
|
1811
2006
|
//# sourceMappingURL=index.js.map
|