@open-pencil/scene-graph 0.16.0-beta.1 → 0.16.0-beta.2

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,9 +1,8 @@
1
1
  import { CONTAINER_TYPES, cloneNodeProps, copyFills, copyStrokes, createDefaultNode, getInstanceOverride, normalizeVectorNetwork, remapInstanceOverrideState, rotatedBBox, setInstanceOverride } from "./color/index.js";
2
2
  import { BLACK, TRANSPARENT } from "./color/contrast.js";
3
- import { BOOLEAN_BINDING_FIELDS, NUMERIC_FIELDS, STRING_BINDING_FIELDS, cloneChildrenWithMapping, createInstance, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, isNumericVariableBindingField, ownsSlotContent, paragraphStyleAt, populateInstanceChildren, scaleNodeChanges, scaleVariableBindingUnits, slotPropertyId, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, textParagraphRanges } from "./components/exposure.js";
3
+ import { BOOLEAN_BINDING_FIELDS, NUMERIC_FIELDS, STRING_BINDING_FIELDS, TEXT_LAYOUT_FIELDS, TEXT_SHAPING_FIELDS, cloneChildrenWithMapping, createInstance, detachInstance, findInstanceAncestor, getInstances, getMainComponent, hasInstanceOverride, isNumericVariableBindingField, ownsSlotContent, paragraphStyleAt, populateInstanceChildren, scaleNodeChanges, scaleVariableBindingUnits, slotPropertyId, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether, textParagraphRanges } from "./components/exposure.js";
4
4
  import { OPEN_PENCIL_PLUGIN_DATA, readAllPluginData, withAllPluginData } from "./behaviours/layers.js";
5
5
  import { SIZE_FIELDS, TRANSFORM_FIELDS } from "./fields/geometry.js";
6
- import { TEXT_LAYOUT_FIELDS, TEXT_SHAPING_FIELDS } from "./fields/text.js";
7
6
  import { computeImageHash } from "../images.js";
8
7
  import { randomHex, randomIndex } from "./comments/list.js";
9
8
  import { Matrix, getAbsolutePosition, getNodeLocalMatrix, getParentWorldMatrix, isTranslationOnly, localTransformFromWorld } from "./coordinate.js";
@@ -13,7 +12,7 @@ import { bindNodeEvents } from "./events.js";
13
12
  import { hitTest, hitTestDeep, hitTestDropTarget, hitTestOpenContainer, hitTestSelectable, isOpenContainer, isPointInNode } from "../hit-test.js";
14
13
  import { partition, uniq } from "es-toolkit/array";
15
14
  import { isEqual } from "es-toolkit/predicate";
16
- import { omit, omitBy } from "es-toolkit/object";
15
+ import { mapValues, omit, omitBy } from "es-toolkit/object";
17
16
  //#region src/mutation-impact.ts
18
17
  function createSceneMutationImpact() {
19
18
  return {
@@ -135,6 +134,43 @@ function resolvedValueBindings(graph, node, fallback = "active") {
135
134
  if (typeof visible === "boolean" && visible !== node.visible) updates.visible = visible;
136
135
  return updates;
137
136
  }
137
+ /** Fields of a range of characters a bound number gives its value; the rest need fonts loaded. */
138
+ const NUMERIC_RUN_FIELDS = [
139
+ "fontSize",
140
+ "fontWeight",
141
+ "letterSpacing",
142
+ "lineHeight"
143
+ ];
144
+ /**
145
+ * The runs a text's character bindings resolve to in its mode, when a bound number differs from
146
+ * what its characters hold. Bound font families and styles are left as stored, as the text's own.
147
+ */
148
+ function resolvedRunBindings(graph, node, fallback = "active") {
149
+ const styleRuns = node.styleRuns.map((run) => {
150
+ const bound = run.style.boundVariables;
151
+ if (!bound) return run;
152
+ let style = run.style;
153
+ for (const field of NUMERIC_RUN_FIELDS) {
154
+ const variableId = bound[field];
155
+ if (!variableId) continue;
156
+ const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback);
157
+ if (value === void 0 || !Number.isFinite(value) || style[field] === value) continue;
158
+ style = {
159
+ ...style,
160
+ [field]: value
161
+ };
162
+ }
163
+ return style === run.style ? run : {
164
+ ...run,
165
+ style
166
+ };
167
+ });
168
+ return styleRuns.some((run, index) => run !== node.styleRuns[index]) ? { styleRuns } : {};
169
+ }
170
+ /** The variables a node binds, its own and its characters'. */
171
+ function boundVariableIds(node) {
172
+ return [...Object.values(node.boundVariables), ...node.styleRuns.flatMap((run) => Object.values(run.style.boundVariables ?? {}))].filter((id) => typeof id === "string");
173
+ }
138
174
  /**
139
175
  * A bound paint takes its whole color from the variable, alpha included, the way Figma stores
140
176
  * it: the variable's RGB at full alpha, and its alpha as the paint's opacity.
@@ -199,7 +235,7 @@ function scopedNodes(graph, scope) {
199
235
  if (!scope) return graph.getAllNodes();
200
236
  if ("subtrees" in scope) return subtreeNodes(graph, scope.subtrees);
201
237
  const variables = variablesResolvingThrough(graph, scope.variables);
202
- return [...graph.getAllNodes()].filter((node) => Object.values(node.boundVariables).some((id) => variables.has(id)));
238
+ return [...graph.getAllNodes()].filter((node) => boundVariableIds(node).some((id) => variables.has(id)));
203
239
  }
204
240
  /**
205
241
  * Resolve live numeric, text, and visibility bindings, numbers in scene units, without authoring
@@ -211,7 +247,8 @@ function reconcileVariableBindings(graph, scope) {
211
247
  for (const node of scopedNodes(graph, scope)) {
212
248
  const updates = {
213
249
  ...resolvedNumericBindings(graph, node),
214
- ...resolvedValueBindings(graph, node)
250
+ ...resolvedValueBindings(graph, node),
251
+ ...resolvedRunBindings(graph, node)
215
252
  };
216
253
  if (Object.keys(updates).length === 0) continue;
217
254
  graph.updateNode(node.id, updates);
@@ -526,6 +563,45 @@ function rescaleNodeTree(graph, rootId, scale) {
526
563
  });
527
564
  }
528
565
  //#endregion
566
+ //#region src/text/references.ts
567
+ /** The variables and styles a text's runs refer to, which copies and transfers carry with it. */
568
+ function styleRunReferences(runs) {
569
+ const variables = /* @__PURE__ */ new Set();
570
+ const styles = /* @__PURE__ */ new Set();
571
+ for (const { style } of runs) {
572
+ for (const id of Object.values(style.boundVariables ?? {})) if (id) variables.add(id);
573
+ if (style.textStyleId) styles.add(style.textStyleId);
574
+ if (style.fillStyleId) styles.add(style.fillStyleId);
575
+ }
576
+ return {
577
+ variables: [...variables],
578
+ styles: [...styles]
579
+ };
580
+ }
581
+ /**
582
+ * Runs whose variables, styles, and linked layers are renamed, as a copy into another document
583
+ * renames them. Layers are renamed only when given, since a link may name a layer left behind.
584
+ */
585
+ function remapStyleRunReferences(runs, rename) {
586
+ return runs.map((run) => {
587
+ const { boundVariables, textStyleId, fillStyleId, hyperlink } = run.style;
588
+ const linksLayer = hyperlink?.type === "NODE" && rename.node !== void 0;
589
+ if (!boundVariables && !textStyleId && !fillStyleId && !linksLayer) return run;
590
+ const style = { ...run.style };
591
+ if (hyperlink?.type === "NODE" && rename.node) style.hyperlink = {
592
+ type: "NODE",
593
+ value: rename.node(hyperlink.value)
594
+ };
595
+ if (boundVariables) style.boundVariables = mapValues(boundVariables, (id) => id ? rename.variable(id) : id);
596
+ if (textStyleId) style.textStyleId = rename.style(textStyleId);
597
+ if (fillStyleId) style.fillStyleId = rename.style(fillStyleId);
598
+ return {
599
+ ...run,
600
+ style
601
+ };
602
+ });
603
+ }
604
+ //#endregion
529
605
  //#region src/transfer/references.ts
530
606
  function requireTransferReference(ids, id, kind) {
531
607
  const value = ids.get(id);
@@ -535,9 +611,12 @@ function requireTransferReference(ids, id, kind) {
535
611
  //#endregion
536
612
  //#region src/transfer/nodes.ts
537
613
  function semanticTransferReferences(node) {
614
+ const runs = styleRunReferences(node.styleRuns);
538
615
  return [
539
616
  ...node.componentId ? [node.componentId] : [],
540
617
  ...Object.values(node.boundVariables),
618
+ ...runs.variables,
619
+ ...runs.styles,
541
620
  ...[
542
621
  node.fillStyleId,
543
622
  node.strokeStyleId,
@@ -581,6 +660,11 @@ function prepareNodeTransfer(source, refs) {
581
660
  "effectStyleId",
582
661
  "gridStyleId"
583
662
  ]) result[field] = source[field] ? style(source[field]) : null;
663
+ if (result.styleRuns) result.styleRuns = remapStyleRunReferences(result.styleRuns, {
664
+ variable,
665
+ style,
666
+ node: (id) => refs.nodes.get(id) ?? id
667
+ });
584
668
  for (const paths of [result.fillGeometry, result.strokeGeometry]) for (const path of paths ?? []) if (path.fillStyleId) path.fillStyleId = style(path.fillStyleId);
585
669
  result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({
586
670
  ...structuredClone(definition),
@@ -679,7 +763,7 @@ function validateTransferReferences(target, plan) {
679
763
  const collections = new Map(plan.collections.map((collection) => [collection.id, collection]));
680
764
  const references = {
681
765
  nodes: identities,
682
- styles: identities,
766
+ styles: new Map([...nodes.values()].flatMap((node) => node.sharedStyleType !== null && node.source.id ? [[node.source.id, node.source.id]] : [])),
683
767
  properties,
684
768
  propertyTypes,
685
769
  ...variableIdentityReferences(plan.variables, plan.collections)
@@ -805,6 +889,18 @@ function applyGraphTransfer(target, input) {
805
889
  }
806
890
  //#endregion
807
891
  //#region src/transfer/plan.ts
892
+ /** A transferred style's props under the ID the transfer gives it. */
893
+ function withStyleId(node, props, styles) {
894
+ const id = node.sharedStyleType !== null && node.source.id ? styles.get(node.source.id) : void 0;
895
+ if (!id || id === node.source.id) return props;
896
+ return {
897
+ ...props,
898
+ source: {
899
+ ...props.source ?? node.source,
900
+ id
901
+ }
902
+ };
903
+ }
808
904
  /** Preflight a self-contained fragment; allocation does not insert anything into the target. */
809
905
  function prepareGraphTransfer(input) {
810
906
  const { source, target, parentId } = input;
@@ -846,6 +942,14 @@ function prepareGraphTransfer(input) {
846
942
  propertyTypes.set(definition.id, definition.type);
847
943
  if (!properties.has(definition.id)) properties.set(definition.id, allocate());
848
944
  }
945
+ const targetStyleIds = /* @__PURE__ */ new Set();
946
+ for (const node of target.getAllNodes()) if (node.sharedStyleType !== null && node.source.id) targetStyleIds.add(node.source.id);
947
+ const styles = /* @__PURE__ */ new Map();
948
+ for (const node of ordered) {
949
+ const id = node.source.id;
950
+ if (node.sharedStyleType === null || !id) continue;
951
+ styles.set(id, targetStyleIds.has(id) ? allocate() : id);
952
+ }
849
953
  const references = {
850
954
  nodes,
851
955
  variables,
@@ -853,7 +957,7 @@ function prepareGraphTransfer(input) {
853
957
  modes,
854
958
  properties,
855
959
  propertyTypes,
856
- styles: nodes
960
+ styles
857
961
  };
858
962
  const resources = prepareVariableTransfer([...source.variables.values()], [...source.variableCollections.values()], references);
859
963
  const mapped = (id) => {
@@ -876,7 +980,7 @@ function prepareGraphTransfer(input) {
876
980
  id: mapped(node.id),
877
981
  type: node.type,
878
982
  parentId: destinationParent(node),
879
- props: prepareNodeTransfer(node, references)
983
+ props: withStyleId(node, prepareNodeTransfer(node, references), styles)
880
984
  })),
881
985
  ...resources,
882
986
  activeModes: new Map([...source.activeMode].map(([collection, mode]) => [requireTransferReference(collections, collection, "collection"), requireTransferReference(modes, mode, "mode")])),
@@ -1248,10 +1352,19 @@ function computeSelectionBounds(nodes) {
1248
1352
  //#endregion
1249
1353
  //#region src/layout/guides.ts
1250
1354
  const MAX_LAYOUT_GUIDE_LINES = 1e4;
1251
- function normalizedCount(grid) {
1252
- const value = grid.count ?? grid.numSections ?? 1;
1253
- if (!Number.isFinite(value)) return 0;
1254
- return Math.min(MAX_LAYOUT_GUIDE_LINES, Math.max(0, Math.floor(value)));
1355
+ /** Figma's Auto count, as its archive stores it: as many sections as fit. */
1356
+ const AUTO_LAYOUT_GRID_COUNT = 2147483647;
1357
+ /** Whether a guide's count is Auto: the archive's value, or the plugin API's `Infinity` or `null`. */
1358
+ function isAutoGridCount(count) {
1359
+ return count === null || count === Infinity || (count ?? 0) >= 2147483647;
1360
+ }
1361
+ /**
1362
+ * A guide's count, set in Figma's plugin shape (`count`) or read from a file (`numSections`); an
1363
+ * edit's `count` wins over the count the file had. Auto is {@link AUTO_LAYOUT_GRID_COUNT}.
1364
+ */
1365
+ function layoutGridCount(grid) {
1366
+ const count = grid.count === void 0 ? grid.numSections : grid.count;
1367
+ return isAutoGridCount(count) ? AUTO_LAYOUT_GRID_COUNT : count ?? 1;
1255
1368
  }
1256
1369
  function pattern(grid) {
1257
1370
  if (grid.pattern === "GRID" || grid.pattern === "ROWS") return grid.pattern;
@@ -1263,15 +1376,29 @@ function alignment(grid) {
1263
1376
  if (value === "CENTER" || value === "MAX" || value === "STRETCH") return value;
1264
1377
  return "MIN";
1265
1378
  }
1266
- function sectionSize(nodeSize, grid) {
1379
+ /**
1380
+ * How many sections a guide draws. Auto fits as many fixed sections as the frame holds, counting
1381
+ * the offset once from the aligned edge, as Figma desktop 126 draws them.
1382
+ */
1383
+ function sectionCount(nodeSize, grid) {
1384
+ const value = layoutGridCount(grid);
1385
+ if (value === 2147483647) {
1386
+ const size = grid.sectionSize ?? 0;
1387
+ if (alignment(grid) === "STRETCH" || size <= 0) return 0;
1388
+ const gutter = grid.gutterSize ?? 0;
1389
+ const offset = alignment(grid) === "CENTER" ? 0 : grid.offset ?? 0;
1390
+ return Math.min(MAX_LAYOUT_GUIDE_LINES, Math.max(0, Math.floor((nodeSize - offset + gutter) / (size + gutter))));
1391
+ }
1392
+ if (!Number.isFinite(value)) return 0;
1393
+ return Math.min(MAX_LAYOUT_GUIDE_LINES, Math.max(0, Math.floor(value)));
1394
+ }
1395
+ function sectionSize(nodeSize, grid, count) {
1267
1396
  const fixed = grid.sectionSize ?? 0;
1268
1397
  if (alignment(grid) !== "STRETCH") return fixed;
1269
- const count = normalizedCount(grid);
1270
1398
  const gutter = grid.gutterSize ?? 0;
1271
1399
  return (nodeSize - (grid.offset ?? 0) * 2 - Math.max(0, count - 1) * gutter) / count;
1272
1400
  }
1273
- function start(nodeSize, grid, size) {
1274
- const count = normalizedCount(grid);
1401
+ function start(nodeSize, grid, size, count) {
1275
1402
  const gutter = grid.gutterSize ?? 0;
1276
1403
  const offset = grid.offset ?? 0;
1277
1404
  const span = count * size + Math.max(0, count - 1) * gutter;
@@ -1283,10 +1410,10 @@ function layoutGuideSections(node, grid) {
1283
1410
  if (grid.visible === false || pattern(grid) === "GRID") return [];
1284
1411
  const axis = pattern(grid) === "ROWS" ? "y" : "x";
1285
1412
  const nodeSize = axis === "x" ? node.width : node.height;
1286
- const size = sectionSize(nodeSize, grid);
1287
- const count = normalizedCount(grid);
1413
+ const count = sectionCount(nodeSize, grid);
1414
+ const size = sectionSize(nodeSize, grid, count);
1288
1415
  if (count <= 0 || size <= 0) return [];
1289
- const first = start(nodeSize, grid, size);
1416
+ const first = start(nodeSize, grid, size, count);
1290
1417
  const step = size + (grid.gutterSize ?? 0);
1291
1418
  return Array.from({ length: count }, (_, index) => {
1292
1419
  const sectionStart = first + index * step;
@@ -1325,125 +1452,6 @@ function layoutGuideLines(node, grid) {
1325
1452
  return lines;
1326
1453
  }
1327
1454
  //#endregion
1328
- //#region src/layout/sizing.ts
1329
- function primaryAxis(mode) {
1330
- return mode === "VERTICAL" ? "VERTICAL" : "HORIZONTAL";
1331
- }
1332
- /** The auto-layout parent that sizes a node's fill, or `undefined` when nothing does. */
1333
- function fillingParent(parent, node) {
1334
- if (!parent || parent.layoutMode === "NONE" || node.layoutPositioning === "ABSOLUTE") return void 0;
1335
- return parent;
1336
- }
1337
- function graphParent(graph, node) {
1338
- return node.parentId ? graph.getNode(node.parentId) : void 0;
1339
- }
1340
- function fills(parent, node, axis) {
1341
- if (parent.layoutMode === "NONE") return false;
1342
- if (axis === primaryAxis(parent.layoutMode)) return node.layoutGrow > 0;
1343
- if (node.layoutAlignSelf === "STRETCH") return true;
1344
- return node.layoutAlignSelf === "AUTO" && parent.layoutMode !== "GRID" && parent.counterAxisAlign === "STRETCH";
1345
- }
1346
- function ownSizingField(node, axis) {
1347
- if (node.layoutMode === "NONE") return void 0;
1348
- return axis === primaryAxis(node.layoutMode) ? "primaryAxisSizing" : "counterAxisSizing";
1349
- }
1350
- function textHugs(autoResize, axis) {
1351
- if (autoResize === "WIDTH_AND_HEIGHT") return true;
1352
- return axis === "VERTICAL" && autoResize === "HEIGHT";
1353
- }
1354
- function hugs(node, axis) {
1355
- if (node.type === "TEXT") return textHugs(node.textAutoResize, axis);
1356
- const field = ownSizingField(node, axis);
1357
- return field !== void 0 && node[field] === "HUG";
1358
- }
1359
- /** The node's sizing along `axis`: fill from its parent, else its own hug, else fixed. */
1360
- function layoutSizing(graph, node, axis) {
1361
- return layoutSizingInParent(graphParent(graph, node), node, axis);
1362
- }
1363
- /** `layoutSizing` for code that holds the parent rather than the graph. */
1364
- function layoutSizingInParent(parentNode, node, axis) {
1365
- const parent = fillingParent(parentNode, node);
1366
- if (parent && fills(parent, node, axis)) return "FILL";
1367
- if (hugs(node, axis) && (parent || node.layoutMode !== "NONE")) return "HUG";
1368
- return "FIXED";
1369
- }
1370
- /** The sizings this node accepts on either axis, in Figma's order. */
1371
- function layoutSizingOptions(graph, node) {
1372
- return [
1373
- "FIXED",
1374
- "HUG",
1375
- "FILL"
1376
- ].filter((value) => layoutSizingError(graph, node, value) === void 0);
1377
- }
1378
- /** Figma's reason for refusing `value` on this node, or `undefined` when it applies. */
1379
- function layoutSizingError(graph, node, value) {
1380
- const parent = graphParent(graph, node);
1381
- const inAutoLayout = parent !== void 0 && parent.layoutMode !== "NONE";
1382
- if (!inAutoLayout && node.layoutMode === "NONE") return "node must be an auto-layout frame or a child of an auto-layout frame";
1383
- if (value === "FILL") {
1384
- if (!inAutoLayout) return "FILL can only be set on children of auto-layout frames";
1385
- if (node.layoutPositioning === "ABSOLUTE") return "FILL cannot be set on absolute positioned auto-layout children";
1386
- }
1387
- if (value === "HUG" && node.layoutMode === "NONE" && node.type !== "TEXT") return "HUG can only be set on auto-layout frames or text children of auto-layout frames";
1388
- }
1389
- /** The text auto-resize that hugs the content along the axes given. */
1390
- function textAutoResizeFor(hugsWidth, hugsHeight) {
1391
- if (hugsWidth && hugsHeight) return "WIDTH_AND_HEIGHT";
1392
- return hugsHeight ? "HEIGHT" : "NONE";
1393
- }
1394
- function textSizingUpdates(graph, node, axis, value) {
1395
- const other = axis === "HORIZONTAL" ? "VERTICAL" : "HORIZONTAL";
1396
- const hugsAxis = value === "HUG";
1397
- const hugsOther = layoutSizing(graph, node, other) === "HUG";
1398
- const autoResize = axis === "HORIZONTAL" ? textAutoResizeFor(hugsAxis, hugsOther) : textAutoResizeFor(hugsOther, hugsAxis);
1399
- if (autoResize === "NONE" && node.textAutoResize === "TRUNCATE") return {};
1400
- return autoResize === node.textAutoResize ? {} : { textAutoResize: autoResize };
1401
- }
1402
- /**
1403
- * The fields that set the node's sizing along `axis` to `value`, as Figma's setter writes
1404
- * them. A value Figma refuses yields no updates; `layoutSizingError` says why.
1405
- */
1406
- function layoutSizingUpdates(graph, node, axis, value) {
1407
- if (layoutSizingError(graph, node, value) !== void 0) return {};
1408
- const updates = {};
1409
- const parent = fillingParent(graphParent(graph, node), node);
1410
- if (parent && parent.layoutMode !== "NONE") {
1411
- const fill = value === "FILL";
1412
- if (axis === primaryAxis(parent.layoutMode)) {
1413
- if (fill !== node.layoutGrow > 0) updates.layoutGrow = fill ? 1 : 0;
1414
- } else if (fill && node.layoutAlignSelf !== "STRETCH") updates.layoutAlignSelf = "STRETCH";
1415
- else if (!fill && fills(parent, node, axis)) updates.layoutAlignSelf = parent.layoutMode !== "GRID" && parent.counterAxisAlign === "STRETCH" ? "MIN" : "AUTO";
1416
- }
1417
- const field = ownSizingField(node, axis);
1418
- if (field) {
1419
- const own = value === "HUG" ? "HUG" : "FIXED";
1420
- if (node[field] !== own) updates[field] = own;
1421
- }
1422
- if (node.type === "TEXT") Object.assign(updates, textSizingUpdates(graph, node, axis, value));
1423
- return updates;
1424
- }
1425
- /**
1426
- * The fields that make a child fill `axis` of a parent laid out as `parentLayout`, for a node
1427
- * an importer builds before it joins the graph. Under a parent without auto layout, such as a
1428
- * staging parent the node leaves when placed, both are set, so it fills whichever axis its
1429
- * eventual parent stacks along.
1430
- */
1431
- function fillSizingFields(parentLayout, axis) {
1432
- if (parentLayout === "NONE") return {
1433
- layoutGrow: 1,
1434
- layoutAlignSelf: "STRETCH"
1435
- };
1436
- return axis === primaryAxis(parentLayout) ? { layoutGrow: 1 } : { layoutAlignSelf: "STRETCH" };
1437
- }
1438
- /** An auto-layout frame's own sizing when it hugs or fixes its width and height. */
1439
- function autoLayoutSizingFields(direction, width, height) {
1440
- const horizontal = primaryAxis(direction) === "HORIZONTAL";
1441
- return {
1442
- primaryAxisSizing: horizontal ? width : height,
1443
- counterAxisSizing: horizontal ? height : width
1444
- };
1445
- }
1446
- //#endregion
1447
1455
  //#region src/text/lists.ts
1448
1456
  /** The marker of an unordered item, at every level. */
1449
1457
  const LIST_BULLET = "•";
@@ -1555,7 +1563,8 @@ const STYLE_TYPES = {
1555
1563
  effect: "EFFECT",
1556
1564
  grid: "GRID"
1557
1565
  };
1558
- const TEXT_STYLE_KEYS = /* @__PURE__ */ new Set([
1566
+ /** The fields a text style gives what uses it; changing one leaves the style. */
1567
+ const SHARED_TEXT_STYLE_FIELDS = [
1559
1568
  "fontFamily",
1560
1569
  "fontWeight",
1561
1570
  "italic",
@@ -1565,7 +1574,8 @@ const TEXT_STYLE_KEYS = /* @__PURE__ */ new Set([
1565
1574
  "textDecoration",
1566
1575
  "textCase",
1567
1576
  "fontFeatures"
1568
- ]);
1577
+ ];
1578
+ const TEXT_STYLE_KEYS = new Set(SHARED_TEXT_STYLE_FIELDS);
1569
1579
  function sharedStyleRefKey(kind) {
1570
1580
  return STYLE_REF_KEYS[kind];
1571
1581
  }
@@ -2249,11 +2259,12 @@ var SceneGraph = class SceneGraph {
2249
2259
  hitTest(px, py, scopeId) {
2250
2260
  return hitTest(this, px, py, scopeId);
2251
2261
  }
2252
- hitTestDeep(px, py, scopeId) {
2253
- return hitTestDeep(this, px, py, scopeId);
2262
+ /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */
2263
+ hitTestDeep(px, py, scopeId, pad = 0) {
2264
+ return hitTestDeep(this, px, py, scopeId, pad);
2254
2265
  }
2255
- hitTestSelectable(px, py, scopeId, selectedIds) {
2256
- return hitTestSelectable(this, px, py, scopeId, selectedIds);
2266
+ hitTestSelectable(px, py, scopeId, selectedIds, pad = 0) {
2267
+ return hitTestSelectable(this, px, py, scopeId, selectedIds, pad);
2257
2268
  }
2258
2269
  hitTestOpenContainer(px, py, scopeId) {
2259
2270
  return hitTestOpenContainer(this, px, py, scopeId);
@@ -2328,6 +2339,6 @@ var SceneGraph = class SceneGraph {
2328
2339
  }
2329
2340
  };
2330
2341
  //#endregion
2331
- export { DEFAULT_SLOT_SETTINGS, GLYPH_AFFECTING_KEYS, LIST_BULLET, ROOT_FONT_SIZE_PX, SceneGraph, TEXT_PICTURE_KEYS, addCollection, addMode, addVariable, applyGraphTransfer, assignVariableBindingUnits, autoLayoutSizingFields, bindVariable, canCreateSlot, captureTransferredState, claimSlotContent, clearSlotContent, collectSceneMutation, computeSelectionBounds, computeSnap, createCollection, createMode, createSceneMutationImpact, createShaderPaint, createSlotProperty, createVariable, fillSizingFields, formatListNumber, generateId, getActiveModeId, getNodeVariableModeId, getSharedStyles, getVariablesByType, getVariablesForCollection, hasShaderPaint, invalidateTextCaches, isPreferredComponent, isShaderFrameCurrent, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, listNumberFormat, markSourceFieldsEdited, modesDefaultFirst, mutationLayoutScopeIds, nonPreferredLayers, prepareGraphTransfer, prepareNodeTransfer, prepareVariableTransfer, readShaderPaints, reconcileVariableBindings, recordSceneMutations, removeCollection, removeGraphTransfer, removeMode, removeVariable, renameMode, rescaleNodeTree, resetSlotContent, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolvedNumericBindings, resolvedPaintBindings, resolvedValueBindings, setActiveMode, setDefaultMode, setIdSession, shaderOfPaint, shaderPresetKey, sharedStyleRefKey, sharedStyleTypeForKind, slotLimitViolations, slotOwner, slotScope, styleDetachmentChanges, textAutoResizeFor, textCacheInvalidationChanges, textListItems, tokenNumberFromUnit, tokenNumberInUnit, topLevelNumberDigits, unbindVariable, updateNodePreview, updateSlotProperty, variableBindingOwner, variablesResolvingThrough, withShaderPaints };
2342
+ export { AUTO_LAYOUT_GRID_COUNT, DEFAULT_SLOT_SETTINGS, GLYPH_AFFECTING_KEYS, LIST_BULLET, ROOT_FONT_SIZE_PX, SHARED_TEXT_STYLE_FIELDS, SceneGraph, TEXT_PICTURE_KEYS, addCollection, addMode, addVariable, applyGraphTransfer, assignVariableBindingUnits, bindVariable, canCreateSlot, captureTransferredState, claimSlotContent, clearSlotContent, collectSceneMutation, computeSelectionBounds, computeSnap, createCollection, createMode, createSceneMutationImpact, createShaderPaint, createSlotProperty, createVariable, formatListNumber, generateId, getActiveModeId, getNodeVariableModeId, getSharedStyles, getVariablesByType, getVariablesForCollection, hasShaderPaint, invalidateTextCaches, isAutoGridCount, isPreferredComponent, isShaderFrameCurrent, layoutGridCount, layoutGuideLines, layoutGuideSections, listNumberFormat, markSourceFieldsEdited, modesDefaultFirst, mutationLayoutScopeIds, nonPreferredLayers, prepareGraphTransfer, prepareNodeTransfer, prepareVariableTransfer, readShaderPaints, reconcileVariableBindings, recordSceneMutations, remapStyleRunReferences, removeCollection, removeGraphTransfer, removeMode, removeVariable, renameMode, rescaleNodeTree, resetSlotContent, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolvedNumericBindings, resolvedPaintBindings, resolvedRunBindings, resolvedValueBindings, setActiveMode, setDefaultMode, setIdSession, shaderOfPaint, shaderPresetKey, sharedStyleRefKey, sharedStyleTypeForKind, slotLimitViolations, slotOwner, slotScope, styleDetachmentChanges, styleRunReferences, textCacheInvalidationChanges, textListItems, tokenNumberFromUnit, tokenNumberInUnit, topLevelNumberDigits, unbindVariable, updateNodePreview, updateSlotProperty, variableBindingOwner, variablesResolvingThrough, withShaderPaints };
2332
2343
 
2333
2344
  //# sourceMappingURL=index.js.map