@pairdraw/pen 0.20.0 → 0.21.1

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.
@@ -1,16 +1,20 @@
1
- import { ANNOTATION_TYPES, UNRESOLVED_REF, applyAnnotation, applyCornerRadius, applyPadding, applyPenPluginData, bindIfVar, buildVarContext, createAnnotation, isAnnotation, isVarRef, mapAlignItems, mapJustifyContent, mapLayoutMode, parseSize, resolveBoolean, resolveNumber, resolveString, unresolvedRef } from "./annotations.js";
1
+ import { ANNOTATION_TYPES, UNRESOLVED_REF, applyAnnotation, applyCornerRadius, applyPadding, applyPenPluginData, bindIfVar, buildVarContext, createAnnotation, isAnnotation, isVarRef, mapAlignItems, mapJustifyContent, mapLayoutMode, parseSize, readIconOrigin, resolveBoolean, resolveNumber, resolveString, unresolvedRef } from "./annotations.js";
2
2
  import { withImports } from "./imports.js";
3
+ import { readPenImports, readSourceLibraryPublication, writeLibraryLinks } from "./document-libraries.js";
3
4
  import { ellipseArc, lineNetwork, networkToSVGPath, pathNetwork } from "./geometry.js";
4
5
  import { drawIcon, insideComponent, removeUnusedIconComponents, useIconComponent } from "./icons.js";
5
- import { applyStroke, convertEffects, convertPaints, createImageStore, penFileSchema, strokeFields } from "./effects.js";
6
+ import { applyStroke, convertEffects, convertPaints, createImageStore, penCropTransform, penFileSchema, strokeFields } from "./effects.js";
6
7
  import { SceneGraph, generateId } from "@pairdraw/scene-graph";
7
8
  import { colorToHex, colorToHex8 } from "@pairdraw/scene-graph/color";
8
9
  import { pick } from "es-toolkit/object";
9
10
  import { isEqual } from "es-toolkit/predicate";
10
11
  import { createComponentPropertyId, libraryDefinitionsPage } from "@pairdraw/scene-graph/components";
11
12
  import * as v from "valibot";
13
+ import { readDesignMemory, writeDesignMemory } from "@pairdraw/scene-graph/design-memory";
14
+ import { readStoredStatusWorkflow, writeStatusWorkflow } from "@pairdraw/scene-graph/statuses";
12
15
  import { readTokenSources, rekeyTokenSources, tokenSourcesPluginData } from "@pairdraw/scene-graph/token-sources";
13
16
  import { INSTANCE_OVERRIDE_FIELDS, detachInstance, populateInstanceChildren, recordInstanceOverride, swapInstanceComponent } from "@pairdraw/scene-graph/instances";
17
+ import { imageMimeType } from "@pairdraw/scene-graph/images";
14
18
  import { normalizeEffects } from "@pairdraw/scene-graph/effects";
15
19
  import { CORNER_FIELDS } from "@pairdraw/scene-graph/fields";
16
20
  import { fillSizingFields, layoutSizing } from "@pairdraw/scene-graph/layout";
@@ -20,9 +24,10 @@ import { getNodeLocalMatrix, localTransformFromWorld } from "@pairdraw/scene-gra
20
24
  import { fitEnclosingGroups } from "@pairdraw/scene-graph/group-bounds";
21
25
  import Matrix from "@pairdraw/scene-graph/matrix";
22
26
  import { canCreateSlot, claimSlotContent, createSlotProperty, slotOwner, slotScope, updateSlotProperty } from "@pairdraw/scene-graph/slots";
23
- import { omit } from "es-toolkit";
27
+ import { isEqual as isEqual$1, omit } from "es-toolkit";
24
28
  import { parseFontStyle } from "@pairdraw/scene-graph/font-style";
25
29
  import { percentLength, pixelLength } from "@pairdraw/scene-graph/text";
30
+ import { fromUint8Array } from "js-base64";
26
31
  //#region src/library.ts
27
32
  /** The component IDs a layer and its overrides name: its `ref`s and the slots' suggestions. */
28
33
  function namedComponents(node, found) {
@@ -149,6 +154,24 @@ function markLibraryRoots(graph, roots) {
149
154
  root.locked = true;
150
155
  }
151
156
  }
157
+ /**
158
+ * The components whose `ref`s a file can resolve: the library definitions its own imports give it,
159
+ * matched to the alias and path each import names. Writing their ids as refs keeps the instances
160
+ * linked on a reopen; the definitions themselves stay out of the file.
161
+ */
162
+ function importedComponentIds(graph, imports) {
163
+ const ids = /* @__PURE__ */ new Set();
164
+ const aliases = Object.entries(imports);
165
+ if (aliases.length === 0) return ids;
166
+ const paths = new Map(aliases.map(([alias, path]) => [penLibraryId(alias), path]));
167
+ const visit = (node) => {
168
+ const identity = node.librarySource?.identity;
169
+ if (identity && paths.get(identity.libraryId) === identity.revisionId) ids.add(node.id);
170
+ for (const child of graph.getChildren(node.id)) visit(child);
171
+ };
172
+ for (const page of graph.getPages(true)) for (const node of graph.getChildren(page.id)) visit(node);
173
+ return ids;
174
+ }
152
175
  //#endregion
153
176
  //#region src/placeholders.ts
154
177
  /**
@@ -550,6 +573,7 @@ const PROPERTY_FIELDS = {
550
573
  justifyContent: ["primaryAxisAlign"],
551
574
  alignItems: ["counterAxisAlign"],
552
575
  clip: ["clipsContent"],
576
+ status: ["status"],
553
577
  placeholder: ["pluginData"],
554
578
  slot: ["pluginData"],
555
579
  innerRadius: ["arcData"],
@@ -640,6 +664,7 @@ function applyPenProperties(node, pen, build) {
640
664
  visible: resolveBoolean(pen.enabled, ctx),
641
665
  opacity: resolveNumber(pen.opacity, ctx, 1),
642
666
  clipsContent: resolveBoolean(pen.clip, ctx, false),
667
+ status: pen.status ?? null,
643
668
  layoutPositioning: absolute ? "ABSOLUTE" : "AUTO",
644
669
  layoutGrow: 0,
645
670
  layoutAlignSelf: "AUTO",
@@ -1029,6 +1054,9 @@ function buildPenGraph(doc, options = {}) {
1029
1054
  markLibraryRoots(graph, libraryRoots);
1030
1055
  if (graph.getPages(true).length === 0) graph.addPage("Page 1");
1031
1056
  if (doc.tokenSources && doc.tokenSources.length > 0) graph.updateNode(graph.rootId, { pluginData: tokenSourcesPluginData(graph, rekeyTokenSources(graph, doc.tokenSources)) });
1057
+ if (doc.designMemory) writeDesignMemory(graph, doc.designMemory);
1058
+ if (doc.statuses) writeStatusWorkflow(graph, doc.statuses);
1059
+ writeLibraryLinks(graph, doc);
1032
1060
  return graph;
1033
1061
  }
1034
1062
  function parsePenFile(json, options = {}) {
@@ -1074,6 +1102,25 @@ const PEN_PLUGIN_FIELDS = {
1074
1102
  "pen/scrollX": "scrollX",
1075
1103
  "pen/scrollY": "scrollY"
1076
1104
  };
1105
+ /** The English sentence a write warning has always been reported as. */
1106
+ function penWriteWarningText(warning) {
1107
+ switch (warning.kind) {
1108
+ case "merged-pages": return `Pencil.dev files hold one page; ${warning.pages} pages were merged into “${warning.name}”.`;
1109
+ 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.";
1110
+ 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.`;
1111
+ 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.`;
1112
+ case "dropped-effects": return `Noise and texture effects were left out (${warning.count}); Pencil.dev files have no form for them.`;
1113
+ case "dropped-filters": return `Image adjustment filters were left out (${warning.count}); Pencil.dev files have no form for them.`;
1114
+ case "dropped-scroll": return `Scroll overflow was left out (${warning.count}); Pencil.dev files have no form for it.`;
1115
+ case "dropped-font-features": return `OpenType font features were left out (${warning.count}); Pencil.dev files have no form for them.`;
1116
+ default: throw new Error(`Unhandled pen write warning: ${String(warning)}`);
1117
+ }
1118
+ }
1119
+ /** Records a warning as its sentence and its kind, in the order it was found. */
1120
+ function emit(state, warning) {
1121
+ state.details.push(warning);
1122
+ state.warnings.push(penWriteWarningText(warning));
1123
+ }
1077
1124
  /** Snaps matrix values that are within floating-point noise of an integer. */
1078
1125
  function snapCoordinate(value) {
1079
1126
  return Math.abs(value - Math.round(value)) < 1e-9 ? Math.round(value) : value;
@@ -1215,12 +1262,31 @@ function gradientPaint(fill) {
1215
1262
  }))
1216
1263
  };
1217
1264
  }
1218
- function imagePaint(fill) {
1219
- return {
1265
+ /**
1266
+ * An image fill as a pen.dev paint whose image travels with the file: Pencil.dev opens a data URL
1267
+ * and the scene graph keeps the bytes, so the fill is written whole instead of pointing at a hash
1268
+ * no reader can resolve. A paint whose bytes are gone is left out and reported, never written as a
1269
+ * dead URL.
1270
+ */
1271
+ function imagePaint(state, fill) {
1272
+ const bytes = fill.imageHash ? state.graph.images.get(fill.imageHash) : void 0;
1273
+ if (!bytes) {
1274
+ state.drops.images++;
1275
+ return null;
1276
+ }
1277
+ if (fill.filters) state.drops.filters++;
1278
+ const paint = {
1220
1279
  type: "image",
1221
1280
  ...paintBase(fill),
1222
- url: fill.imageHash
1281
+ url: `data:${imageMimeType(bytes)};base64,${fromUint8Array(bytes)}`
1223
1282
  };
1283
+ if (fill.imageScaleMode === "FIT") paint.mode = "contain";
1284
+ if (fill.imageScaleMode === "CROP") {
1285
+ paint.mode = "stretch";
1286
+ const transform = fill.imageTransform && penCropTransform(fill.imageTransform);
1287
+ if (transform) paint.transform = transform;
1288
+ }
1289
+ return paint;
1224
1290
  }
1225
1291
  function penPaint(state, node, field, fill, index) {
1226
1292
  if (fill.type === "SOLID") return {
@@ -1229,7 +1295,7 @@ function penPaint(state, node, field, fill, index) {
1229
1295
  ...paintBase(fill)
1230
1296
  };
1231
1297
  if (fill.type.startsWith("GRADIENT_")) return gradientPaint(fill);
1232
- if (fill.type === "IMAGE") return imagePaint(fill);
1298
+ if (fill.type === "IMAGE") return imagePaint(state, fill);
1233
1299
  return {
1234
1300
  type: fill.type.toLowerCase(),
1235
1301
  ...paintBase(fill)
@@ -1237,7 +1303,8 @@ function penPaint(state, node, field, fill, index) {
1237
1303
  }
1238
1304
  function paintsOf(state, node, field, paints) {
1239
1305
  if (paints.length === 0) return void 0;
1240
- const result = paints.map((paint, index) => penPaint(state, node, field, paint, index));
1306
+ const result = paints.map((paint, index) => penPaint(state, node, field, paint, index)).filter((paint) => paint !== null);
1307
+ if (result.length === 0) return void 0;
1241
1308
  return result.length === 1 ? result[0] : result;
1242
1309
  }
1243
1310
  function strokesOf(state, node) {
@@ -1449,16 +1516,16 @@ function penVariable(variable, collection, state) {
1449
1516
  };
1450
1517
  }
1451
1518
  function variablesOf(state) {
1452
- if (state.graph.variables.size === 0) return void 0;
1453
- return Object.fromEntries([...state.graph.variables.values()].sort((left, right) => left.name.localeCompare(right.name)).map((variable) => [variable.name, penVariable(variable, state.collections.get(variable.collectionId), state)]));
1519
+ if (state.variables.size === 0) return void 0;
1520
+ return Object.fromEntries([...state.variables.values()].sort((left, right) => left.name.localeCompare(right.name)).map((variable) => [variable.name, penVariable(variable, state.collections.get(variable.collectionId), state)]));
1454
1521
  }
1455
1522
  function themesOf(state) {
1456
- if (state.graph.variableCollections.size === 0) return void 0;
1457
- return Object.fromEntries([...state.graph.variableCollections.values()].sort((left, right) => left.name.localeCompare(right.name)).map((collection) => [collection.name, collection.modes.map((mode) => mode.name)]));
1523
+ if (state.collections.size === 0) return void 0;
1524
+ return Object.fromEntries([...state.collections.values()].sort((left, right) => left.name.localeCompare(right.name)).map((collection) => [collection.name, collection.modes.map((mode) => mode.name)]));
1458
1525
  }
1459
1526
  /** The selector each mode applies in, by collection and mode name; none when no mode names one. */
1460
1527
  function modeConditionsOf(state) {
1461
- const entries = [...state.graph.variableCollections.values()].flatMap((collection) => {
1528
+ const entries = [...state.collections.values()].flatMap((collection) => {
1462
1529
  const modes = collection.modes.flatMap((mode) => mode.condition ? [[mode.name, mode.condition]] : []);
1463
1530
  return modes.length > 0 ? [[collection.name, Object.fromEntries(modes)]] : [];
1464
1531
  });
@@ -1495,25 +1562,141 @@ function themeFields(state, node) {
1495
1562
  }
1496
1563
  return Object.keys(theme).length > 0 ? theme : void 0;
1497
1564
  }
1565
+ /**
1566
+ * The pen fields an instance override writes: what it changes on a layer, not the placement and
1567
+ * layout a reopen recalculates from the component and the boxes around it.
1568
+ */
1569
+ const OVERRIDABLE_FIELDS = /* @__PURE__ */ new Set([
1570
+ "content",
1571
+ "fill",
1572
+ "stroke",
1573
+ "strokeWidth",
1574
+ "cornerRadius",
1575
+ "effect",
1576
+ "opacity",
1577
+ "enabled",
1578
+ "fontFamily",
1579
+ "fontSize",
1580
+ "fontWeight",
1581
+ "fontStyle",
1582
+ "textAlign",
1583
+ "textAlignVertical",
1584
+ "lineHeight",
1585
+ "letterSpacing",
1586
+ "href"
1587
+ ]);
1588
+ /**
1589
+ * The path a copy sits at in its component, from the instance down: the ids of the layers it
1590
+ * copies, as pen names a `descendants` override. A copy that swapped its component copies `swapOf`
1591
+ * instead of the component it draws.
1592
+ */
1593
+ function overridePath(graph, instanceId, copyId, swapOf) {
1594
+ const parts = [];
1595
+ let current = graph.getNode(copyId);
1596
+ while (current && current.id !== instanceId) {
1597
+ const id = current.id === copyId && swapOf ? swapOf : current.componentId;
1598
+ if (!id) return null;
1599
+ parts.unshift(id);
1600
+ current = current.parentId ? graph.getNode(current.parentId) : void 0;
1601
+ }
1602
+ return current ? parts.join("/") : null;
1603
+ }
1604
+ /**
1605
+ * The fields a swap override names an icon by: pen carries the glyph, not the component drawn.
1606
+ */
1607
+ function iconOverride(graph, componentId) {
1608
+ const origin = readIconOrigin(componentId ? graph.getNode(componentId) : void 0);
1609
+ if (!origin) return void 0;
1610
+ const override = { icon: origin.icon };
1611
+ if (origin.library) override.library = origin.library;
1612
+ if (origin.weight !== void 0) override.weight = origin.weight;
1613
+ return override;
1614
+ }
1615
+ /**
1616
+ * The overrides an instance writes, and whether one of them is a swap the file cannot name. A
1617
+ * layer that swapped its component draws another component than the one it copies, which pen holds
1618
+ * as a glyph for an icon; any other swap is what the instance shows, not what it links to.
1619
+ */
1620
+ function instanceDescendants(state, node) {
1621
+ const overridden = [...node.instanceOverrides.descendants.keys()];
1622
+ if (overridden.length === 0) return { unrepresentable: false };
1623
+ const probe = {
1624
+ ...state,
1625
+ drops: {
1626
+ images: 0,
1627
+ effects: 0,
1628
+ filters: 0,
1629
+ scroll: 0,
1630
+ fontFeatures: 0
1631
+ }
1632
+ };
1633
+ const descendants = {};
1634
+ let unrepresentable = false;
1635
+ for (const copyId of overridden) {
1636
+ const overrides = node.instanceOverrides.descendants.get(copyId);
1637
+ const swapped = overrides?.has("componentId") === true;
1638
+ const swapOf = swapped ? overrides.get("sourceComponentId") : void 0;
1639
+ const path = overridePath(state.graph, node.id, copyId, typeof swapOf === "string" ? swapOf : void 0);
1640
+ const copy = state.graph.getNode(copyId);
1641
+ if (!path || !copy) {
1642
+ unrepresentable = true;
1643
+ continue;
1644
+ }
1645
+ if (swapped) {
1646
+ const icon = iconOverride(state.graph, copy.componentId);
1647
+ if (!icon) {
1648
+ unrepresentable = true;
1649
+ continue;
1650
+ }
1651
+ descendants[path] = icon;
1652
+ continue;
1653
+ }
1654
+ const master = copy.componentId ? state.graph.getNode(copy.componentId) : void 0;
1655
+ if (!master) {
1656
+ unrepresentable = true;
1657
+ continue;
1658
+ }
1659
+ const own = writeNode(probe, copy);
1660
+ const base = writeNode(probe, master);
1661
+ const override = {};
1662
+ for (const field of OVERRIDABLE_FIELDS) if (!isEqual$1(own[field], base[field])) override[field] = own[field];
1663
+ if (Object.keys(override).length > 0) descendants[path] = override;
1664
+ }
1665
+ return {
1666
+ descendants: Object.keys(descendants).length > 0 ? descendants : void 0,
1667
+ unrepresentable
1668
+ };
1669
+ }
1498
1670
  function semanticNodeFields(state, node, result) {
1499
1671
  if (node.type === "TEXT" && node.textAutoResize === "WIDTH_AND_HEIGHT" && layoutSizing(state.graph, node, "HORIZONTAL") === "HUG") result.width = "fit_content";
1500
1672
  if (node.type === "STICKY") result.content = stickySublayers(state.graph, node)?.body.text ?? "";
1501
1673
  penPluginFields(node, result);
1502
- const effects = node.effects.filter((effect) => effect.type !== "SHADER");
1674
+ const effects = node.effects.filter((effect) => {
1675
+ if (effect.type === "DROP_SHADOW" || effect.type === "INNER_SHADOW") return true;
1676
+ if (effect.type === "LAYER_BLUR" || effect.type === "BACKGROUND_BLUR") return true;
1677
+ if (effect.type === "NOISE" || effect.type === "TEXTURE") state.drops.effects++;
1678
+ return false;
1679
+ });
1503
1680
  if (effects.length > 0) result.effect = effects.length === 1 ? effectOf(effects[0]) : effects.map(effectOf);
1504
1681
  if (node.type === "COMPONENT" || node.type === "COMPONENT_SET") result.reusable = true;
1505
- if (node.type === "INSTANCE" && node.componentId && state.writtenIds.has(node.componentId)) {
1682
+ if (node.type === "INSTANCE" && node.componentId && (state.writtenIds.has(node.componentId) || state.importedIds.has(node.componentId))) {
1683
+ const overrides = instanceDescendants(state, node);
1684
+ if (overrides.unrepresentable && !state.writtenIds.has(node.componentId)) return false;
1506
1685
  result.type = "ref";
1507
1686
  result.ref = node.componentId;
1687
+ if (overrides.descendants) result.descendants = overrides.descendants;
1508
1688
  return true;
1509
1689
  }
1510
1690
  return false;
1511
1691
  }
1512
1692
  function writeNode(state, node) {
1693
+ if (node.overflowDirection !== "NONE") state.drops.scroll++;
1694
+ if (node.fontFeatures.length > 0) state.drops.fontFeatures++;
1513
1695
  const result = {
1514
1696
  id: node.id,
1515
1697
  type: nodeType(node)
1516
1698
  };
1699
+ if (node.status !== null) result.status = node.status;
1517
1700
  basicNodeFields(state, node, result);
1518
1701
  if (semanticNodeFields(state, node, result)) return result;
1519
1702
  if (node.type === "VECTOR" && node.vectorNetwork && node.vectorNetwork.segments.length > 0) {
@@ -1547,21 +1730,33 @@ function sortKeys(value) {
1547
1730
  }
1548
1731
  return value;
1549
1732
  }
1550
- function penDocumentFromGraph(graph) {
1733
+ function penDocumentFromGraph(graph, options = {}) {
1551
1734
  const variables = /* @__PURE__ */ new Map();
1552
- for (const variable of graph.variables.values()) variables.set(variable.id, variable);
1735
+ for (const variable of graph.getLiveVariables()) variables.set(variable.id, variable);
1553
1736
  const collections = /* @__PURE__ */ new Map();
1554
- for (const collection of graph.variableCollections.values()) collections.set(collection.id, collection);
1737
+ for (const collection of graph.getLiveCollections()) collections.set(collection.id, collection);
1738
+ const imports = readPenImports(graph);
1555
1739
  const state = {
1556
1740
  graph,
1557
1741
  variables,
1558
1742
  collections,
1559
- writtenIds: writtenNodeIds(graph)
1743
+ writtenIds: writtenNodeIds(graph),
1744
+ importedIds: importedComponentIds(graph, imports ?? {}),
1745
+ warnings: options.warnings ?? [],
1746
+ details: [],
1747
+ drops: {
1748
+ images: 0,
1749
+ effects: 0,
1750
+ filters: 0,
1751
+ scroll: 0,
1752
+ fontFeatures: 0
1753
+ }
1560
1754
  };
1561
- const children = graph.getPages().flatMap((page) => graph.getChildren(page.id).filter((node) => !node.internalOnly).map((node) => writeNode(state, node)));
1755
+ const pages = graph.getPages();
1756
+ const children = pages.flatMap((page) => graph.getChildren(page.id).filter((node) => !node.internalOnly).map((node) => writeNode(state, node)));
1562
1757
  const document = {
1563
1758
  version: PEN_VERSION,
1564
- name: graph.getPages()[0]?.name,
1759
+ name: pages[0]?.name,
1565
1760
  children
1566
1761
  };
1567
1762
  const variablesValue = variablesOf(state);
@@ -1586,15 +1781,74 @@ function penDocumentFromGraph(graph) {
1586
1781
  return refreshed;
1587
1782
  });
1588
1783
  if (tokenSources.length > 0) document.tokenSources = tokenSources;
1784
+ const designMemory = readDesignMemory(graph);
1785
+ if (designMemory) document.designMemory = designMemory;
1786
+ const statuses = readStoredStatusWorkflow(graph);
1787
+ if (statuses) document.statuses = statuses;
1788
+ if (imports) document.imports = imports;
1789
+ const enabledLibraries = enabledLibrariesOf(graph, state);
1790
+ if (enabledLibraries) document.enabledLibraries = enabledLibraries;
1791
+ const publication = readSourceLibraryPublication(graph);
1792
+ if (publication) document.sourceLibraryPublication = publication;
1793
+ if (pages.length > 1) {
1794
+ const name = document.name ?? "Page 1";
1795
+ emit(state, {
1796
+ kind: "merged-pages",
1797
+ pages: pages.length,
1798
+ name
1799
+ });
1800
+ }
1801
+ if (graph.documentColorSpace === "display-p3") emit(state, { kind: "display-p3-colors" });
1802
+ reportDrops(state);
1803
+ options.warningDetails?.push(...state.details);
1589
1804
  return document;
1590
1805
  }
1806
+ /**
1807
+ * The library bindings a `.pen` file records, or null when the document has none. The definitions
1808
+ * live on the hidden page, which a Pencil.dev file cannot hold, so the file records the bindings
1809
+ * and says that the components it was built from come back as placeholders.
1810
+ */
1811
+ function enabledLibrariesOf(graph, state) {
1812
+ const bindings = [...graph.enabledLibraries.values()];
1813
+ if (bindings.length === 0) return null;
1814
+ const enabled = bindings.filter((binding) => binding.enabled).length;
1815
+ if (enabled > 0) emit(state, {
1816
+ kind: "library-definitions",
1817
+ count: enabled
1818
+ });
1819
+ return bindings;
1820
+ }
1821
+ /** Adds one sentence for each kind of content the written file had to leave out. */
1822
+ function reportDrops(state) {
1823
+ const { images, effects, filters, scroll, fontFeatures } = state.drops;
1824
+ if (images > 0) emit(state, {
1825
+ kind: "missing-image-fills",
1826
+ count: images
1827
+ });
1828
+ if (effects > 0) emit(state, {
1829
+ kind: "dropped-effects",
1830
+ count: effects
1831
+ });
1832
+ if (filters > 0) emit(state, {
1833
+ kind: "dropped-filters",
1834
+ count: filters
1835
+ });
1836
+ if (scroll > 0) emit(state, {
1837
+ kind: "dropped-scroll",
1838
+ count: scroll
1839
+ });
1840
+ if (fontFeatures > 0) emit(state, {
1841
+ kind: "dropped-font-features",
1842
+ count: fontFeatures
1843
+ });
1844
+ }
1591
1845
  function stringifyPenDocument(document) {
1592
1846
  return `${JSON.stringify(sortKeys(document), null, 2)}\n`;
1593
1847
  }
1594
- function writePenDocument(source) {
1595
- return stringifyPenDocument(source instanceof SceneGraph ? penDocumentFromGraph(source) : source);
1848
+ function writePenDocument(source, options = {}) {
1849
+ return stringifyPenDocument(source instanceof SceneGraph ? penDocumentFromGraph(source, options) : source);
1596
1850
  }
1597
1851
  //#endregion
1598
- export { buildPenGraph, parsePenDocument, parsePenFile, penDocumentFromGraph, readPenFile, stringifyPenDocument, withUsedImports, writePenDocument };
1852
+ export { buildPenGraph, parsePenDocument, parsePenFile, penDocumentFromGraph, penWriteWarningText, readPenFile, stringifyPenDocument, withUsedImports, writePenDocument };
1599
1853
 
1600
1854
  //# sourceMappingURL=index.js.map