@pairdraw/scene-graph 0.18.0 → 0.19.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/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +14 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +1 -0
- package/dist/copy.js.map +1 -1
- package/dist/css/gradient.d.ts +23 -0
- package/dist/css/gradient.d.ts.map +1 -0
- package/dist/css/gradient.js +404 -0
- package/dist/css/gradient.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +2 -13
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.js +24 -1
- package/dist/css/values.js.map +1 -1
- package/dist/font-style.d.ts +2 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +31 -6
- package/dist/font-style.js.map +1 -1
- package/dist/geometry.d.ts +10 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +21 -6
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -3
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +179 -17
- package/dist/graph.js.map +1 -1
- package/dist/hit-test.d.ts +3 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +38 -23
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/index.d.ts +2 -2
- package/dist/icons/index.js +2 -2
- package/dist/icons/model.d.ts +8 -2
- package/dist/icons/model.d.ts.map +1 -1
- package/dist/icons/model.js +10 -1
- package/dist/icons/model.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +40 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +18 -1
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +38 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +134 -15
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +10 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +28 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +1 -1
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap-overrides.js +94 -0
- package/dist/instances/swap-overrides.js.map +1 -0
- package/dist/instances/sync.js +90 -12
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/draw-order.d.ts +11 -0
- package/dist/layout/draw-order.d.ts.map +1 -0
- package/dist/layout/draw-order.js +14 -0
- package/dist/layout/draw-order.js.map +1 -0
- package/dist/layout/index.d.ts +2 -1
- package/dist/layout/index.js +2 -1
- package/dist/node-defaults.d.ts +11 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +16 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/resize.d.ts +29 -9
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +95 -62
- package/dist/resize.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +1 -8
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/source-metadata.d.ts +4 -2
- package/dist/source-metadata.d.ts.map +1 -1
- package/dist/source-metadata.js +10 -3
- package/dist/source-metadata.js.map +1 -1
- package/dist/strokes.d.ts +39 -0
- package/dist/strokes.d.ts.map +1 -0
- package/dist/strokes.js +104 -0
- package/dist/strokes.js.map +1 -0
- package/dist/text/direction.d.ts +6 -2
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +2 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +3 -3
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +22 -6
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +24 -6
- package/dist/text/overflow.js.map +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +18 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +36 -1
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +52 -2
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +14 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +42 -67
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +10 -4
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +58 -15
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +101 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +313 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +44 -4
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/package.json +6 -1
- package/src/components/properties.ts +17 -2
- package/src/copy.ts +1 -0
- package/src/css/gradient.ts +438 -0
- package/src/css/index.ts +1 -0
- package/src/css/shadows.ts +2 -18
- package/src/css/values.ts +27 -1
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +25 -6
- package/src/graph.ts +207 -17
- package/src/hit-test.ts +67 -24
- package/src/icons/model.ts +11 -1
- package/src/instances/assignments.ts +65 -7
- package/src/instances/fields.ts +21 -0
- package/src/instances/index.ts +237 -14
- package/src/instances/overrides.ts +36 -1
- package/src/instances/placement.ts +5 -1
- package/src/instances/swap-overrides.ts +123 -0
- package/src/instances/sync.ts +139 -12
- package/src/layout/draw-order.ts +13 -0
- package/src/layout/index.ts +1 -0
- package/src/node-defaults.ts +21 -0
- package/src/order-keys.ts +6 -0
- package/src/resize.ts +133 -69
- package/src/shared-styles.ts +1 -3
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/source-metadata.ts +18 -3
- package/src/strokes.ts +121 -0
- package/src/text/direction.ts +7 -5
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +30 -7
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +17 -0
- package/src/undo.ts +79 -2
- package/src/variables/bindings.ts +52 -74
- package/src/variables/index.ts +80 -14
- package/src/variables/paints.ts +413 -0
- package/src/variables/resolution.ts +56 -5
- package/src/variables/subtree.ts +15 -0
package/dist/hit-test.js
CHANGED
|
@@ -2,6 +2,7 @@ import Matrix from "./matrix.js";
|
|
|
2
2
|
import { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from "./coordinate.js";
|
|
3
3
|
import { geometryBlobPolylines } from "./geometry.js";
|
|
4
4
|
import { hitsConnectorLine } from "./connectors/hit.js";
|
|
5
|
+
import { drawnChildIds } from "./layout/draw-order.js";
|
|
5
6
|
//#region src/hit-test.ts
|
|
6
7
|
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
7
8
|
"CANVAS",
|
|
@@ -133,24 +134,28 @@ function clippingMasks(graph, childIds) {
|
|
|
133
134
|
}
|
|
134
135
|
return result;
|
|
135
136
|
}
|
|
136
|
-
function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad) {
|
|
137
|
+
function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad, locked = false) {
|
|
137
138
|
if (!containsPoint(px, py, child, graph, transformCache)) return null;
|
|
138
|
-
if (hitTestChildren(graph, px, py, childId, deep, transformCache, pad)) return child;
|
|
139
|
+
if (hitTestChildren(graph, px, py, childId, deep, transformCache, pad, locked)) return child;
|
|
139
140
|
if (hasVisibleFillOrStroke(child)) return child;
|
|
140
141
|
return null;
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
+
/**
|
|
144
|
+
* What a hit inside a container reports: the container itself when it is locked (a locked layer,
|
|
145
|
+
* where one is hit at all, stands in for everything inside it) or the walk stops at containers.
|
|
146
|
+
*/
|
|
147
|
+
function standIn(container, hit, deep) {
|
|
148
|
+
return container.locked || !deep ? container : hit;
|
|
149
|
+
}
|
|
150
|
+
function hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad, locked = false) {
|
|
143
151
|
if (child.type === "GROUP") {
|
|
144
152
|
if (!containsPoint(px, py, child, graph, transformCache, pad)) return null;
|
|
145
|
-
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad);
|
|
146
|
-
if (childHit) return
|
|
153
|
+
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad, locked);
|
|
154
|
+
if (childHit) return standIn(child, childHit, deep);
|
|
147
155
|
return containsPoint(px, py, child, graph, transformCache) ? child : null;
|
|
148
156
|
}
|
|
149
|
-
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad);
|
|
150
|
-
if (childHit)
|
|
151
|
-
if (child.locked) return child;
|
|
152
|
-
return childHit;
|
|
153
|
-
}
|
|
157
|
+
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad, locked);
|
|
158
|
+
if (childHit) return standIn(child, childHit, true);
|
|
154
159
|
if (containsPoint(px, py, child, graph, transformCache) && (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))) return child;
|
|
155
160
|
return null;
|
|
156
161
|
}
|
|
@@ -163,25 +168,34 @@ function isMaskedOut(px, py, masks, graph, transformCache) {
|
|
|
163
168
|
* The topmost layer under the point among a container's children. `pad`, in canvas units, grows
|
|
164
169
|
* each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.
|
|
165
170
|
*/
|
|
166
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Whether a layer under the point can take the click. A locked layer and everything in it are
|
|
173
|
+
* invisible to a press and to hover, as in Figma: a click falls through to what lies under it, and
|
|
174
|
+
* a drag from it draws a marquee.
|
|
175
|
+
*/
|
|
176
|
+
function takesClick(graph, px, py, child, mask, locked, transformCache) {
|
|
177
|
+
if (!child || child.internalOnly || !child.visible || child.locked && !locked) return false;
|
|
178
|
+
return !isMaskedOut(px, py, mask, graph, transformCache);
|
|
179
|
+
}
|
|
180
|
+
function hitTestChildren(graph, px, py, parentId, deep = false, transformCache = /* @__PURE__ */ new Map(), pad = 0, locked = false) {
|
|
167
181
|
const parent = graph.nodes.get(parentId);
|
|
168
182
|
if (!parent) return null;
|
|
169
183
|
if (parent.clipsContent) {
|
|
170
184
|
if (!containsPoint(px, py, parent, graph, transformCache)) return null;
|
|
171
185
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
const drawn = drawnChildIds(parent);
|
|
187
|
+
const masks = clippingMasks(graph, drawn);
|
|
188
|
+
for (let i = drawn.length - 1; i >= 0; i--) {
|
|
189
|
+
const childId = drawn[i];
|
|
175
190
|
const child = graph.nodes.get(childId);
|
|
176
|
-
if (!
|
|
177
|
-
if (isMaskedOut(px, py, masks[i], graph, transformCache)) continue;
|
|
191
|
+
if (!takesClick(graph, px, py, child, masks[i], locked, transformCache)) continue;
|
|
178
192
|
if (CONTAINER_TYPES.has(child.type)) {
|
|
179
193
|
if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
|
|
180
|
-
const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad);
|
|
194
|
+
const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad, locked);
|
|
181
195
|
if (hit) return hit;
|
|
182
196
|
continue;
|
|
183
197
|
}
|
|
184
|
-
const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad);
|
|
198
|
+
const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad, locked);
|
|
185
199
|
if (hit) return hit;
|
|
186
200
|
continue;
|
|
187
201
|
}
|
|
@@ -214,11 +228,12 @@ function opensByItself(graph, node) {
|
|
|
214
228
|
* Figma a click on the empty area of a frame inside an open container, or of an empty frame on the
|
|
215
229
|
* page or in a section, selects that frame, while a deep (⌘) click looks through it.
|
|
216
230
|
*/
|
|
217
|
-
function frameChildAt(graph, container, px, py) {
|
|
231
|
+
function frameChildAt(graph, container, px, py, locked = false) {
|
|
218
232
|
const transformCache = /* @__PURE__ */ new Map();
|
|
219
233
|
for (let i = container.childIds.length - 1; i >= 0; i--) {
|
|
220
234
|
const child = graph.nodes.get(container.childIds[i]);
|
|
221
235
|
if (!child || child.internalOnly || !child.visible || child.type !== "FRAME") continue;
|
|
236
|
+
if (child.locked && !locked) continue;
|
|
222
237
|
if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue;
|
|
223
238
|
if (containsPoint(px, py, child, graph, transformCache)) return child;
|
|
224
239
|
}
|
|
@@ -250,11 +265,11 @@ function openedBySelection(graph, selectedIds, scopeId) {
|
|
|
250
265
|
* by the selection is selected, so is a top-level frame with auto layout, and a plain top-level
|
|
251
266
|
* frame or a section is not.
|
|
252
267
|
*/
|
|
253
|
-
function hitTestSelectable(graph, px, py, scopeId, selectedIds, pad = 0) {
|
|
254
|
-
const deepest = hitTestChildren(graph, px, py, scopeId, true, /* @__PURE__ */ new Map(), pad);
|
|
268
|
+
function hitTestSelectable(graph, px, py, scopeId, selectedIds, pad = 0, locked = false) {
|
|
269
|
+
const deepest = hitTestChildren(graph, px, py, scopeId, true, /* @__PURE__ */ new Map(), pad, locked);
|
|
255
270
|
if (!deepest) {
|
|
256
271
|
const scope = graph.nodes.get(scopeId);
|
|
257
|
-
return scope ? frameChildAt(graph, scope, px, py) : null;
|
|
272
|
+
return scope ? frameChildAt(graph, scope, px, py, locked) : null;
|
|
258
273
|
}
|
|
259
274
|
const chain = [];
|
|
260
275
|
for (let node = deepest; node && node.id !== scopeId;) {
|
|
@@ -268,7 +283,7 @@ function hitTestSelectable(graph, px, py, scopeId, selectedIds, pad = 0) {
|
|
|
268
283
|
}
|
|
269
284
|
const last = chain.at(-1);
|
|
270
285
|
if (!last) return null;
|
|
271
|
-
const frame = frameChildAt(graph, last, px, py);
|
|
286
|
+
const frame = frameChildAt(graph, last, px, py, locked);
|
|
272
287
|
if (frame) return frame;
|
|
273
288
|
if (ownsItsEmptyArea(graph, last)) return last;
|
|
274
289
|
return opened.has(last.id) && !opensByItself(graph, last) ? last : null;
|
package/dist/hit-test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport { geometryBlobPolylines } from './geometry'\nimport type { SceneGraph } from './graph'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n/**\n * How far from a zero-width or zero-height layer, in canvas units, a point still lands on it, so\n * a flat line or an empty box stays clickable; matches a connector line's slop (`connectors/hit.ts`).\n */\nconst DEGENERATE_AXIS_SLOP = 4\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/**\n * Where the point lies in the node's own coordinates: its offset from the position when nothing\n * above it is turned, else through the inverse world matrix. Null when that cannot be inverted.\n */\nfunction localPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): Vector | null {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return { x: px - absolute.x, y: py - absolute.y }\n }\n const inv = Matrix.invert(getWorldMatrix(node, graph))\n if (!inv) return null\n const [x, y] = Matrix.mapPoints(inv, [px, py])\n return { x, y }\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n const local = localPoint(px, py, node, graph, transformCache)\n if (!local) return false\n const padX = node.width > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n const padY = node.height > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n return (\n local.x >= -padX &&\n local.x <= node.width + padX &&\n local.y >= -padY &&\n local.y <= node.height + padY\n )\n}\n\n/** Whether a rounded rectangle of `width` × `height` holds the point. */\nfunction roundedRectContains(\n point: Vector,\n width: number,\n height: number,\n radius: number\n): boolean {\n if (point.x < 0 || point.y < 0 || point.x > width || point.y > height) return false\n const r = Math.max(0, Math.min(radius, width / 2, height / 2))\n const cx = Math.min(Math.max(point.x, r), width - r)\n const cy = Math.min(Math.max(point.y, r), height - r)\n return Math.hypot(point.x - cx, point.y - cy) <= r\n}\n\n/** Whether the point is inside a closed polyline, by the even-odd rule. */\nfunction insidePolyline(polyline: readonly Vector[], x: number, y: number): boolean {\n let inside = false\n for (let i = 0, j = polyline.length - 1; i < polyline.length; j = i++) {\n const a = polyline[i]\n const b = polyline[j]\n if (a.y > y === b.y > y) continue\n if (x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x) inside = !inside\n }\n return inside\n}\n\n/**\n * Whether a mask lets the point through, by the outline it draws: an ellipse's curve, a rounded\n * rectangle's corners, or a vector's filled path. Other shapes clip by their box.\n */\nfunction maskContainsPoint(\n px: number,\n py: number,\n mask: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n const outlined =\n (mask.type === 'ELLIPSE' && mask.width > 0 && mask.height > 0) ||\n (mask.type === 'RECTANGLE' && mask.cornerRadius > 0) ||\n (mask.type === 'VECTOR' && mask.fillGeometry.length > 0)\n if (!outlined) return containsPoint(px, py, mask, graph, transformCache)\n const local = localPoint(px, py, mask, graph, transformCache)\n if (!local) return false\n if (mask.type === 'ELLIPSE') {\n const rx = mask.width / 2\n const ry = mask.height / 2\n const dx = (local.x - rx) / rx\n const dy = (local.y - ry) / ry\n return dx * dx + dy * dy <= 1\n }\n if (mask.type === 'RECTANGLE') {\n return roundedRectContains(local, mask.width, mask.height, mask.cornerRadius)\n }\n return geometryBlobPolylines(mask.fillGeometry).some((points) =>\n insidePolyline(points, local.x, local.y)\n )\n}\n\nfunction isVisibleMask(node: SceneNode | undefined): node is SceneNode {\n return node !== undefined && node.visible && node.isMask\n}\n\n/**\n * The masks that clip each child, by index, as the renderer groups them (`core/canvas/masks.ts`):\n * a run of visible masks clips the layers after it up to the next visible mask. Empty when the\n * container has no visible mask.\n */\nfunction clippingMasks(graph: SceneGraph, childIds: readonly string[]): SceneNode[][] {\n const children = childIds.map((childId) => graph.nodes.get(childId))\n if (!children.some(isVisibleMask)) return []\n const result: SceneNode[][] = []\n let run: SceneNode[] = []\n let previousWasMask = false\n for (const child of children) {\n if (isVisibleMask(child)) {\n run = previousWasMask ? [...run, child] : [child]\n previousWasMask = true\n result.push([])\n continue\n }\n previousWasMask = false\n result.push(run)\n }\n return result\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return deep ? childHit : child\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))\n )\n return child\n return null\n}\n\n/** Whether the masks that clip a layer leave the point outside every one of their outlines. */\nfunction isMaskedOut(\n px: number,\n py: number,\n masks: readonly SceneNode[] | undefined,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n if (!masks) return false\n return (\n masks.length > 0 &&\n !masks.some((mask) => maskContainsPoint(px, py, mask, graph, transformCache))\n )\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n const masks = clippingMasks(graph, parent.childIds)\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n if (isMaskedOut(px, py, masks[i], graph, transformCache)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return hasVisibleFillOrStroke(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (\n parent.type !== 'CANVAS' &&\n parent.clipsContent &&\n !containsPoint(px, py, parent, graph, transformCache)\n )\n return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;;AAQA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;;;;;AAK1E,MAAM,uBAAuB;AAE7B,SAAS,uBAAuB,MAA0B;CACxD,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,OAAO,KAAK,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO;AAChF;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/D,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAChE,OAAO,QAAQ,SAAS,YA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nF,IAAI,QAAQ,OAAO;EACnB,IAAI,UAAU,cAAc,IAAI,IAAI,OAAO,OAAO,cAAc,GAAG,OAAO;CAC5E;CAEA,OAAO;AACT;;;;;;;AAgBA,SAAgB,kBACd,OACA,IACA,IACA,YACA,SACA,UAA6B,CAAC,GACZ;CAClB,MAAM,QAAQ,MAAM,MAAM,IAAI,WAAW,MAAM,MAAM;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport { geometryBlobPolylines } from './geometry'\nimport type { SceneGraph } from './graph'\nimport { drawnChildIds } from './layout/draw-order'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n/**\n * How far from a zero-width or zero-height layer, in canvas units, a point still lands on it, so\n * a flat line or an empty box stays clickable; matches a connector line's slop (`connectors/hit.ts`).\n */\nconst DEGENERATE_AXIS_SLOP = 4\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/**\n * Where the point lies in the node's own coordinates: its offset from the position when nothing\n * above it is turned, else through the inverse world matrix. Null when that cannot be inverted.\n */\nfunction localPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): Vector | null {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return { x: px - absolute.x, y: py - absolute.y }\n }\n const inv = Matrix.invert(getWorldMatrix(node, graph))\n if (!inv) return null\n const [x, y] = Matrix.mapPoints(inv, [px, py])\n return { x, y }\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n const local = localPoint(px, py, node, graph, transformCache)\n if (!local) return false\n const padX = node.width > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n const padY = node.height > 0 ? pad : Math.max(pad, DEGENERATE_AXIS_SLOP)\n return (\n local.x >= -padX &&\n local.x <= node.width + padX &&\n local.y >= -padY &&\n local.y <= node.height + padY\n )\n}\n\n/** Whether a rounded rectangle of `width` × `height` holds the point. */\nfunction roundedRectContains(\n point: Vector,\n width: number,\n height: number,\n radius: number\n): boolean {\n if (point.x < 0 || point.y < 0 || point.x > width || point.y > height) return false\n const r = Math.max(0, Math.min(radius, width / 2, height / 2))\n const cx = Math.min(Math.max(point.x, r), width - r)\n const cy = Math.min(Math.max(point.y, r), height - r)\n return Math.hypot(point.x - cx, point.y - cy) <= r\n}\n\n/** Whether the point is inside a closed polyline, by the even-odd rule. */\nfunction insidePolyline(polyline: readonly Vector[], x: number, y: number): boolean {\n let inside = false\n for (let i = 0, j = polyline.length - 1; i < polyline.length; j = i++) {\n const a = polyline[i]\n const b = polyline[j]\n if (a.y > y === b.y > y) continue\n if (x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x) inside = !inside\n }\n return inside\n}\n\n/**\n * Whether a mask lets the point through, by the outline it draws: an ellipse's curve, a rounded\n * rectangle's corners, or a vector's filled path. Other shapes clip by their box.\n */\nfunction maskContainsPoint(\n px: number,\n py: number,\n mask: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n const outlined =\n (mask.type === 'ELLIPSE' && mask.width > 0 && mask.height > 0) ||\n (mask.type === 'RECTANGLE' && mask.cornerRadius > 0) ||\n (mask.type === 'VECTOR' && mask.fillGeometry.length > 0)\n if (!outlined) return containsPoint(px, py, mask, graph, transformCache)\n const local = localPoint(px, py, mask, graph, transformCache)\n if (!local) return false\n if (mask.type === 'ELLIPSE') {\n const rx = mask.width / 2\n const ry = mask.height / 2\n const dx = (local.x - rx) / rx\n const dy = (local.y - ry) / ry\n return dx * dx + dy * dy <= 1\n }\n if (mask.type === 'RECTANGLE') {\n return roundedRectContains(local, mask.width, mask.height, mask.cornerRadius)\n }\n return geometryBlobPolylines(mask.fillGeometry).some((points) =>\n insidePolyline(points, local.x, local.y)\n )\n}\n\nfunction isVisibleMask(node: SceneNode | undefined): node is SceneNode {\n return node !== undefined && node.visible && node.isMask\n}\n\n/**\n * The masks that clip each child, by index, as the renderer groups them (`core/canvas/masks.ts`):\n * a run of visible masks clips the layers after it up to the next visible mask. Empty when the\n * container has no visible mask.\n */\nfunction clippingMasks(graph: SceneGraph, childIds: readonly string[]): SceneNode[][] {\n const children = childIds.map((childId) => graph.nodes.get(childId))\n if (!children.some(isVisibleMask)) return []\n const result: SceneNode[][] = []\n let run: SceneNode[] = []\n let previousWasMask = false\n for (const child of children) {\n if (isVisibleMask(child)) {\n run = previousWasMask ? [...run, child] : [child]\n previousWasMask = true\n result.push([])\n continue\n }\n previousWasMask = false\n result.push(run)\n }\n return result\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number,\n locked = false\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad, locked)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\n/**\n * What a hit inside a container reports: the container itself when it is locked (a locked layer,\n * where one is hit at all, stands in for everything inside it) or the walk stops at containers.\n */\nfunction standIn(container: SceneNode, hit: SceneNode, deep: boolean): SceneNode {\n return container.locked || !deep ? container : hit\n}\n\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number,\n locked = false\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad, locked)\n if (childHit) return standIn(child, childHit, deep)\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad, locked)\n if (childHit) return standIn(child, childHit, true)\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))\n )\n return child\n return null\n}\n\n/** Whether the masks that clip a layer leave the point outside every one of their outlines. */\nfunction isMaskedOut(\n px: number,\n py: number,\n masks: readonly SceneNode[] | undefined,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n if (!masks) return false\n return (\n masks.length > 0 &&\n !masks.some((mask) => maskContainsPoint(px, py, mask, graph, transformCache))\n )\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\n/**\n * Whether a layer under the point can take the click. A locked layer and everything in it are\n * invisible to a press and to hover, as in Figma: a click falls through to what lies under it, and\n * a drag from it draws a marquee.\n */\nfunction takesClick(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode | undefined,\n mask: readonly SceneNode[] | undefined,\n locked: boolean,\n transformCache: Map<string, boolean>\n): child is SceneNode {\n if (!child || child.internalOnly || !child.visible || (child.locked && !locked)) return false\n return !isMaskedOut(px, py, mask, graph, transformCache)\n}\n\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0,\n locked = false\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n // Front to back, as the layers are drawn: a reversed auto layout puts the first child on top.\n const drawn = drawnChildIds(parent)\n const masks = clippingMasks(graph, drawn)\n for (let i = drawn.length - 1; i >= 0; i--) {\n const childId = drawn[i]\n const child = graph.nodes.get(childId)\n if (!takesClick(graph, px, py, child, masks[i], locked, transformCache)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad,\n locked\n )\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad,\n locked\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number,\n locked = false\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n if (child.locked && !locked) continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0,\n /** Whether locked layers are hit, as a right-click hits them; see `hitTestAtPoint`. */\n locked = false\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad, locked)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py, locked) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer, hit only with `locked`, stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py, locked)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return hasVisibleFillOrStroke(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (\n parent.type !== 'CANVAS' &&\n parent.clipsContent &&\n !containsPoint(px, py, parent, graph, transformCache)\n )\n return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;;;AASA,MAAM,kCAAkB,IAAI,IAAc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./glyph.js";
|
|
2
2
|
import { ICON_NAME, ICON_PAINTS, Icon, IconOptions, IconPaint, iconOptionsSchema, iconSchema, iconTintSchema } from "./schema.js";
|
|
3
|
-
import { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint } from "./model.js";
|
|
4
|
-
export { ICON_NAME, ICON_PAINTS, Icon, IconOptions, IconPaint, iconGlyph, iconLayerName, iconNames, iconOptionsSchema, iconSchema, iconTintSchema, isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
3
|
+
import { acceptsContent, iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint } from "./model.js";
|
|
4
|
+
export { ICON_NAME, ICON_PAINTS, Icon, IconOptions, IconPaint, acceptsContent, iconGlyph, iconLayerName, iconNames, iconOptionsSchema, iconSchema, iconTintSchema, isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
package/dist/icons/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ICON_NAME, ICON_PAINTS, iconOptionsSchema, iconSchema, iconTintSchema } from "./schema.js";
|
|
2
|
-
import { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint } from "./model.js";
|
|
2
|
+
import { acceptsContent, iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint } from "./model.js";
|
|
3
3
|
import { iconGlyph, isIconModified } from "./glyph.js";
|
|
4
|
-
export { ICON_NAME, ICON_PAINTS, iconGlyph, iconLayerName, iconNames, iconOptionsSchema, iconSchema, iconTintSchema, isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
4
|
+
export { ICON_NAME, ICON_PAINTS, acceptsContent, iconGlyph, iconLayerName, iconNames, iconOptionsSchema, iconSchema, iconTintSchema, isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
package/dist/icons/model.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import { SceneNode } from "../types.js";
|
|
|
2
2
|
import { Icon, IconPaint } from "./schema.js";
|
|
3
3
|
//#region src/icons/model.d.ts
|
|
4
4
|
/** The icon a frame draws, or null when it is not an icon or its data is unreadable. */
|
|
5
|
-
declare function readIcon(node: SceneNode): Icon | null;
|
|
5
|
+
declare function readIcon(node: Pick<SceneNode, 'pluginData'>): Icon | null;
|
|
6
|
+
/**
|
|
7
|
+
* Whether a layer holds other layers. An icon frame does not: it draws one glyph at the
|
|
8
|
+
* proportions it was placed with, so a layer put inside would cover it, and a top-level icon
|
|
9
|
+
* would stand where a slide does.
|
|
10
|
+
*/
|
|
11
|
+
declare function acceptsContent(node: Pick<SceneNode, 'type' | 'pluginData'>): boolean;
|
|
6
12
|
/** The node's plugin data with the icon set, or removed when null. */
|
|
7
13
|
declare function withIcon(node: SceneNode, icon: Icon | null): SceneNode['pluginData'];
|
|
8
14
|
/**
|
|
@@ -25,5 +31,5 @@ declare function readIconTint(node: SceneNode): readonly IconPaint[];
|
|
|
25
31
|
/** The path's plugin data with its tinted paints, or removed when there are none. */
|
|
26
32
|
declare function withIconTint(node: SceneNode, paints: readonly IconPaint[]): SceneNode['pluginData'];
|
|
27
33
|
//#endregion
|
|
28
|
-
export { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
34
|
+
export { acceptsContent, iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
29
35
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/icons/model.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/icons/model.ts"],"mappings":";;;;iBAOgB,SAAS,MAAM,KAAK,2BAA2B;;;;;;iBAS/C,eAAe,MAAM,KAAK;;iBAK1B,SAAS,MAAM,WAAW,MAAM,cAAc;;;;;;iBAS9C,YAAY,MAAM;;iBAKlB,cAAc;;;;;iBAQd,iBAAiB,mBAAmB;;iBAKpC,UAAU,OAAO,SAAS;;iBAU1B,aAAa,MAAM,qBAAqB;;iBAKxC,aACd,MAAM,WACN,iBAAiB,cAChB"}
|
package/dist/icons/model.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONTAINER_TYPES } from "../node-defaults.js";
|
|
1
2
|
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
2
3
|
import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
3
4
|
//#region src/icons/model.ts
|
|
@@ -5,6 +6,14 @@ import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
|
5
6
|
function readIcon(node) {
|
|
6
7
|
return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon) ?? null;
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether a layer holds other layers. An icon frame does not: it draws one glyph at the
|
|
11
|
+
* proportions it was placed with, so a layer put inside would cover it, and a top-level icon
|
|
12
|
+
* would stand where a slide does.
|
|
13
|
+
*/
|
|
14
|
+
function acceptsContent(node) {
|
|
15
|
+
return node.type !== "CANVAS" && CONTAINER_TYPES.has(node.type) && readIcon(node) === null;
|
|
16
|
+
}
|
|
8
17
|
/** The node's plugin data with the icon set, or removed when null. */
|
|
9
18
|
function withIcon(node, icon) {
|
|
10
19
|
return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon, icon ?? void 0);
|
|
@@ -46,6 +55,6 @@ function withIconTint(node, paints) {
|
|
|
46
55
|
return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.iconTint, paints.length > 0 ? [...paints] : void 0);
|
|
47
56
|
}
|
|
48
57
|
//#endregion
|
|
49
|
-
export { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
58
|
+
export { acceptsContent, iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
50
59
|
|
|
51
60
|
//# sourceMappingURL=model.js.map
|
package/dist/icons/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/icons/model.ts"],"sourcesContent":["import { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\nimport type { Icon, IconPaint } from './schema'\n\n/** The icon a frame draws, or null when it is not an icon or its data is unreadable. */\nexport function readIcon(node: SceneNode): Icon | null {\n return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon) ?? null\n}\n\n/** The node's plugin data with the icon set, or removed when null. */\nexport function withIcon(node: SceneNode, icon: Icon | null): SceneNode['pluginData'] {\n return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon, icon ?? undefined)\n}\n\n/**\n * Whether code can draw the icon from its name alone, as Iconify's components do. An icon with\n * options was drawn from a set of our own, such as a font at its axes, so it exports as the paths\n * it draws.\n */\nexport function isNamedIcon(icon: Icon): boolean {\n return icon.options === undefined\n}\n\n/** The layer name an icon is placed with: its name in the set, such as `cat` for `mdi:cat`. */\nexport function iconLayerName(name: string): string {\n return name.slice(name.indexOf(':') + 1)\n}\n\n/**\n * Whether `layerName` is the name an icon `name` was placed with, rather than one someone gave\n * it: `cat`, or `Icon / mdi:cat` as icons were named before.\n */\nexport function isPlacedIconName(layerName: string, name: string): boolean {\n return layerName === iconLayerName(name) || layerName === `Icon / ${name}`\n}\n\n/** The names of the icons among `nodes`, each once, in the order they are first met. */\nexport function iconNames(nodes: Iterable<SceneNode>): string[] {\n const names = new Set<string>()\n for (const node of nodes) {\n const icon = readIcon(node)\n if (icon) names.add(icon.name)\n }\n return [...names]\n}\n\n/** The paints of an icon path that its icon's color sets; none when it keeps its own colors. */\nexport function readIconTint(node: SceneNode): readonly IconPaint[] {\n return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.iconTint) ?? []\n}\n\n/** The path's plugin data with its tinted paints, or removed when there are none. */\nexport function withIconTint(\n node: SceneNode,\n paints: readonly IconPaint[]\n): SceneNode['pluginData'] {\n return withPluginData(\n node.pluginData,\n PAIRDRAW_PLUGIN_DATA.iconTint,\n paints.length > 0 ? [...paints] : undefined\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/icons/model.ts"],"sourcesContent":["import { CONTAINER_TYPES } from '../node-defaults'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\nimport type { Icon, IconPaint } from './schema'\n\n/** The icon a frame draws, or null when it is not an icon or its data is unreadable. */\nexport function readIcon(node: Pick<SceneNode, 'pluginData'>): Icon | null {\n return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon) ?? null\n}\n\n/**\n * Whether a layer holds other layers. An icon frame does not: it draws one glyph at the\n * proportions it was placed with, so a layer put inside would cover it, and a top-level icon\n * would stand where a slide does.\n */\nexport function acceptsContent(node: Pick<SceneNode, 'type' | 'pluginData'>): boolean {\n return node.type !== 'CANVAS' && CONTAINER_TYPES.has(node.type) && readIcon(node) === null\n}\n\n/** The node's plugin data with the icon set, or removed when null. */\nexport function withIcon(node: SceneNode, icon: Icon | null): SceneNode['pluginData'] {\n return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon, icon ?? undefined)\n}\n\n/**\n * Whether code can draw the icon from its name alone, as Iconify's components do. An icon with\n * options was drawn from a set of our own, such as a font at its axes, so it exports as the paths\n * it draws.\n */\nexport function isNamedIcon(icon: Icon): boolean {\n return icon.options === undefined\n}\n\n/** The layer name an icon is placed with: its name in the set, such as `cat` for `mdi:cat`. */\nexport function iconLayerName(name: string): string {\n return name.slice(name.indexOf(':') + 1)\n}\n\n/**\n * Whether `layerName` is the name an icon `name` was placed with, rather than one someone gave\n * it: `cat`, or `Icon / mdi:cat` as icons were named before.\n */\nexport function isPlacedIconName(layerName: string, name: string): boolean {\n return layerName === iconLayerName(name) || layerName === `Icon / ${name}`\n}\n\n/** The names of the icons among `nodes`, each once, in the order they are first met. */\nexport function iconNames(nodes: Iterable<SceneNode>): string[] {\n const names = new Set<string>()\n for (const node of nodes) {\n const icon = readIcon(node)\n if (icon) names.add(icon.name)\n }\n return [...names]\n}\n\n/** The paints of an icon path that its icon's color sets; none when it keeps its own colors. */\nexport function readIconTint(node: SceneNode): readonly IconPaint[] {\n return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.iconTint) ?? []\n}\n\n/** The path's plugin data with its tinted paints, or removed when there are none. */\nexport function withIconTint(\n node: SceneNode,\n paints: readonly IconPaint[]\n): SceneNode['pluginData'] {\n return withPluginData(\n node.pluginData,\n PAIRDRAW_PLUGIN_DATA.iconTint,\n paints.length > 0 ? [...paints] : undefined\n )\n}\n"],"mappings":";;;;;AAOA,SAAgB,SAAS,MAAkD;CACzE,OAAO,eAAe,KAAK,YAAY,qBAAqB,IAAI,KAAK;AACvE;;;;;;AAOA,SAAgB,eAAe,MAAuD;CACpF,OAAO,KAAK,SAAS,YAAY,gBAAgB,IAAI,KAAK,IAAI,KAAK,SAAS,IAAI,MAAM;AACxF;;AAGA,SAAgB,SAAS,MAAiB,MAA4C;CACpF,OAAO,eAAe,KAAK,YAAY,qBAAqB,MAAM,QAAQ,KAAA,CAAS;AACrF;;;;;;AAOA,SAAgB,YAAY,MAAqB;CAC/C,OAAO,KAAK,YAAY,KAAA;AAC1B;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,CAAC;AACzC;;;;;AAMA,SAAgB,iBAAiB,WAAmB,MAAuB;CACzE,OAAO,cAAc,cAAc,IAAI,KAAK,cAAc,UAAU;AACtE;;AAGA,SAAgB,UAAU,OAAsC;CAC9D,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,SAAS,IAAI;EAC1B,IAAI,MAAM,MAAM,IAAI,KAAK,IAAI;CAC/B;CACA,OAAO,CAAC,GAAG,KAAK;AAClB;;AAGA,SAAgB,aAAa,MAAuC;CAClE,OAAO,eAAe,KAAK,YAAY,qBAAqB,QAAQ,KAAK,CAAC;AAC5E;;AAGA,SAAgB,aACd,MACA,QACyB;CACzB,OAAO,eACL,KAAK,YACL,qBAAqB,UACrB,OAAO,SAAS,IAAI,CAAC,GAAG,MAAM,IAAI,KAAA,CACpC;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
2
|
import { SceneGraph } from "./graph.js";
|
|
3
|
-
import { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
3
|
+
import { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
4
|
import { generateId, setIdSession } from "./ids.js";
|
|
5
|
-
export { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
5
|
+
export { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, DerivedTextGlyph, DocumentColorSpace, DocumentKind, Effect, EnabledLibraryBinding, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, MeshGradientPoint, NodeChangeObserver, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, PrototypeAction, PrototypeActionType, PrototypeBackAction, PrototypeCloseAction, PrototypeNavigationType, PrototypeNodeAction, PrototypeOverlayPositionType, PrototypeReaction, PrototypeTransition, PrototypeTransitionType, PrototypeTrigger, PrototypeTriggerType, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffect, ShadowEffect, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignmentOverrideField } from "./overrides.js";
|
|
1
2
|
//#region src/instances/assignments.ts
|
|
2
3
|
/** SLOT_CONTENT is absent because it drives children, which `ownsSlotContent` keeps instead. */
|
|
3
4
|
const PROPERTY_REFERENCE_FIELDS = {
|
|
@@ -25,16 +26,48 @@ function definesProperty(graph, instance, propertyId) {
|
|
|
25
26
|
* that defines it, so the walk stops at an instance of that component even when it assigns
|
|
26
27
|
* nothing; otherwise an outer instance's unrelated property of the same id wins.
|
|
27
28
|
*/
|
|
28
|
-
function
|
|
29
|
+
function findEnclosingAssignment(graph, node, propertyId) {
|
|
29
30
|
let current = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
30
31
|
while (current) {
|
|
31
32
|
if (current.type === "INSTANCE") {
|
|
32
|
-
if (Object.hasOwn(current.componentPropertyAssignments, propertyId)) return
|
|
33
|
+
if (Object.hasOwn(current.componentPropertyAssignments, propertyId)) return {
|
|
34
|
+
instance: current,
|
|
35
|
+
value: current.componentPropertyAssignments[propertyId]
|
|
36
|
+
};
|
|
33
37
|
if (definesProperty(graph, current, propertyId)) return void 0;
|
|
34
38
|
}
|
|
35
39
|
current = current.parentId ? graph.nodes.get(current.parentId) : void 0;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
42
|
+
function enclosingAssignment(graph, node, propertyId) {
|
|
43
|
+
return findEnclosingAssignment(graph, node, propertyId)?.value;
|
|
44
|
+
}
|
|
45
|
+
/** The instances around `node`, nearest first. */
|
|
46
|
+
function enclosingInstances(graph, node) {
|
|
47
|
+
const instances = [];
|
|
48
|
+
let parent = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
49
|
+
while (parent) {
|
|
50
|
+
if (parent.type === "INSTANCE") instances.push(parent);
|
|
51
|
+
parent = parent.parentId ? graph.nodes.get(parent.parentId) : void 0;
|
|
52
|
+
}
|
|
53
|
+
return instances;
|
|
54
|
+
}
|
|
55
|
+
/** The outermost of `instances` that records `field` as an edit of `node`, or -1. */
|
|
56
|
+
function outermostEdit(instances, node, field) {
|
|
57
|
+
return instances.findLastIndex((instance) => instance.instanceOverrides.descendants.get(node.id)?.has(field));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether a text edit of `layer` outranks the assignment that drives it. As in Figma, the edit
|
|
61
|
+
* made in the outer instance wins, and at the same level the assignment does. An assignment is
|
|
62
|
+
* made where an override of it is recorded, or else by the instance that holds it.
|
|
63
|
+
*/
|
|
64
|
+
function textEditOutranks(graph, layer, propertyId, assignment) {
|
|
65
|
+
const instances = enclosingInstances(graph, layer);
|
|
66
|
+
const textLevel = outermostEdit(instances, layer, "text");
|
|
67
|
+
if (textLevel < 0) return false;
|
|
68
|
+
const overridden = outermostEdit(instances, assignment.instance, assignmentOverrideField(propertyId));
|
|
69
|
+
return textLevel > (overridden < 0 ? instances.indexOf(assignment.instance) : overridden);
|
|
70
|
+
}
|
|
38
71
|
function hasEnclosingAssignment(graph, node, propertyId) {
|
|
39
72
|
return enclosingAssignment(graph, node, propertyId) !== void 0;
|
|
40
73
|
}
|
|
@@ -76,10 +109,11 @@ function propertyDrivenFields(graph, instChild, compChild) {
|
|
|
76
109
|
function assignedFieldValues(graph, instChild, compChild) {
|
|
77
110
|
const values = {};
|
|
78
111
|
for (const reference of compChild.componentPropertyReferences) {
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
if (reference.field === "TEXT" && instChild.type === "TEXT")
|
|
82
|
-
|
|
112
|
+
const assignment = findEnclosingAssignment(graph, instChild, reference.propertyId);
|
|
113
|
+
if (!assignment) continue;
|
|
114
|
+
if (reference.field === "TEXT" && instChild.type === "TEXT") {
|
|
115
|
+
if (!textEditOutranks(graph, instChild, reference.propertyId, assignment)) values.text = assignment.value;
|
|
116
|
+
} else if (reference.field === "VISIBLE") values.visible = assignment.value === "true";
|
|
83
117
|
}
|
|
84
118
|
return values;
|
|
85
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assignments.js","names":[],"sources":["../../src/instances/assignments.ts"],"sourcesContent":["// What enclosing instances assign the component properties that drive a copy's layers.\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyReferenceField, SceneNode } from '../types'\n\n/** SLOT_CONTENT is absent because it drives children, which `ownsSlotContent` keeps instead. */\nconst PROPERTY_REFERENCE_FIELDS: Partial<Record<ComponentPropertyReferenceField, string>> = {\n VISIBLE: 'visible',\n TEXT: 'text',\n INSTANCE_SWAP: 'componentId'\n}\n\n/** Instance links are expected to be shallow; the cap only stops a cycle from hanging sync. */\nconst INSTANCE_CHAIN_LIMIT = 16\n\n/**\n * Whether this instance's component, or the set it is a variant of, is where `propertyId` is\n * defined. Only a set counts: a component nested in an ordinary component defines its own\n * properties, not the outer one's.\n */\nfunction definesProperty(graph: SceneGraph, instance: SceneNode, propertyId: string): boolean {\n // An instance of an instance links through to the component, so follow the chain to it.\n let component = instance.componentId ? graph.nodes.get(instance.componentId) : undefined\n for (let hops = 0; component?.type === 'INSTANCE' && hops < INSTANCE_CHAIN_LIMIT; hops++) {\n component = component.componentId ? graph.nodes.get(component.componentId) : undefined\n }\n const parent = component?.parentId ? graph.nodes.get(component.parentId) : undefined\n const set = parent?.type === 'COMPONENT_SET' ? parent : undefined\n return [component, set]\n .flatMap((node) => node?.componentPropertyDefinitions ?? [])\n .some((definition) => definition.id === propertyId)\n}\n\n/**\n * What the nearest enclosing instance assigns `propertyId`, if any does. An instance assigns its\n * children, not itself, so the walk starts at the parent. A property id belongs to the component\n * that defines it, so the walk stops at an instance of that component even when it assigns\n * nothing; otherwise an outer instance's unrelated property of the same id wins.\n */\nfunction enclosingAssignment(\n graph: SceneGraph,\n node: SceneNode,\n propertyId: string\n): string | undefined {\n let current = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (current) {\n if (current.type === 'INSTANCE') {\n if (Object.hasOwn(current.componentPropertyAssignments, propertyId))\n return current.componentPropertyAssignments[propertyId]\n if (definesProperty(graph, current, propertyId)) return undefined\n }\n current = current.parentId ? graph.nodes.get(current.parentId) : undefined\n }\n return undefined\n}\n\nfunction hasEnclosingAssignment(graph: SceneGraph, node: SceneNode, propertyId: string): boolean {\n return enclosingAssignment(graph, node, propertyId) !== undefined\n}\n\n/**\n * A component can gain a property-driven layer after an instance of it exists. Pass 4 leaves a\n * driven field alone, so the fresh clone has to take the enclosing instance's assignment here or\n * it keeps the component's default while every other instance layer shows the assigned value.\n */\nexport function applyEnclosingAssignments(graph: SceneGraph, clone: SceneNode): void {\n for (const reference of clone.componentPropertyReferences) {\n const field = PROPERTY_REFERENCE_FIELDS[reference.field]\n if (!field) continue\n const value = enclosingAssignment(graph, clone, reference.propertyId)\n if (value === undefined) continue\n if (field === 'visible') graph.updateNode(clone.id, { visible: value === 'true' })\n else if (field === 'text') graph.updateNode(clone.id, { text: value })\n else if (field === 'componentId' && clone.type === 'INSTANCE' && graph.nodes.has(value)) {\n graph.swapInstanceComponent(clone.id, value)\n }\n }\n for (const child of graph.getChildren(clone.id)) applyEnclosingAssignments(graph, child)\n}\n\n/**\n * Fields a component property drives on this child. The component states the default, but\n * an enclosing instance's assignment decides the value, so synchronising must not copy the\n * default over it — a page loaded later would otherwise reset the instance to the default.\n */\nexport function propertyDrivenFields(\n graph: SceneGraph,\n instChild: SceneNode,\n compChild: SceneNode\n): Set<string> {\n const driven = new Set<string>()\n for (const reference of compChild.componentPropertyReferences) {\n const field = PROPERTY_REFERENCE_FIELDS[reference.field]\n if (field && hasEnclosingAssignment(graph, instChild, reference.propertyId)) driven.add(field)\n }\n return driven\n}\n\n/**\n * The text and visibility enclosing assignments give an existing child whose layer a property\n * drives. A layer linked to a property after the instance was made would otherwise keep what it\n * showed before, since synchronising leaves driven fields alone.\n */\nexport function assignedFieldValues(\n graph: SceneGraph,\n instChild: SceneNode,\n compChild: SceneNode\n): Partial<SceneNode> {\n const values: Partial<SceneNode> = {}\n for (const reference of compChild.componentPropertyReferences) {\n const value = enclosingAssignment(graph, instChild, reference.propertyId)\n if (value === undefined) continue\n if (reference.field === 'TEXT' && instChild.type === 'TEXT') values.text = value\n else if (reference.field === 'VISIBLE') values.visible = value === 'true'\n }\n return values\n}\n"],"mappings":";;AAKA,MAAM,4BAAsF;CAC1F,SAAS;CACT,MAAM;CACN,eAAe;AACjB;;AAGA,MAAM,uBAAuB;;;;;;AAO7B,SAAS,gBAAgB,OAAmB,UAAqB,YAA6B;CAE5F,IAAI,YAAY,SAAS,cAAc,MAAM,MAAM,IAAI,SAAS,WAAW,IAAI,KAAA;CAC/E,KAAK,IAAI,OAAO,GAAG,WAAW,SAAS,cAAc,OAAO,sBAAsB,QAChF,YAAY,UAAU,cAAc,MAAM,MAAM,IAAI,UAAU,WAAW,IAAI,KAAA;CAE/E,MAAM,SAAS,WAAW,WAAW,MAAM,MAAM,IAAI,UAAU,QAAQ,IAAI,KAAA;CAC3E,MAAM,MAAM,QAAQ,SAAS,kBAAkB,SAAS,KAAA;CACxD,OAAO,CAAC,WAAW,GAAG,CAAC,CACpB,SAAS,SAAS,MAAM,gCAAgC,CAAC,CAAC,CAAC,CAC3D,MAAM,eAAe,WAAW,OAAO,UAAU;AACtD;;;;;;;AAQA,SAAS,oBACP,OACA,MACA,YACoB;CACpB,IAAI,UAAU,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAC/D,OAAO,SAAS;EACd,IAAI,QAAQ,SAAS,YAAY;GAC/B,IAAI,OAAO,OAAO,QAAQ,8BAA8B,UAAU,GAChE,OAAO,QAAQ,6BAA6B;GAC9C,IAAI,gBAAgB,OAAO,SAAS,UAAU,GAAG,OAAO,KAAA;EAC1D;EACA,UAAU,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E,IAAI,UAAU,UAAU,WAAW,OAAO,UAAU,UAAU;CACrE;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"assignments.js","names":[],"sources":["../../src/instances/assignments.ts"],"sourcesContent":["// What enclosing instances assign the component properties that drive a copy's layers.\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyReferenceField, SceneNode } from '../types'\nimport { assignmentOverrideField } from './overrides'\n\n/** SLOT_CONTENT is absent because it drives children, which `ownsSlotContent` keeps instead. */\nconst PROPERTY_REFERENCE_FIELDS: Partial<Record<ComponentPropertyReferenceField, string>> = {\n VISIBLE: 'visible',\n TEXT: 'text',\n INSTANCE_SWAP: 'componentId'\n}\n\n/** Instance links are expected to be shallow; the cap only stops a cycle from hanging sync. */\nconst INSTANCE_CHAIN_LIMIT = 16\n\n/**\n * Whether this instance's component, or the set it is a variant of, is where `propertyId` is\n * defined. Only a set counts: a component nested in an ordinary component defines its own\n * properties, not the outer one's.\n */\nfunction definesProperty(graph: SceneGraph, instance: SceneNode, propertyId: string): boolean {\n // An instance of an instance links through to the component, so follow the chain to it.\n let component = instance.componentId ? graph.nodes.get(instance.componentId) : undefined\n for (let hops = 0; component?.type === 'INSTANCE' && hops < INSTANCE_CHAIN_LIMIT; hops++) {\n component = component.componentId ? graph.nodes.get(component.componentId) : undefined\n }\n const parent = component?.parentId ? graph.nodes.get(component.parentId) : undefined\n const set = parent?.type === 'COMPONENT_SET' ? parent : undefined\n return [component, set]\n .flatMap((node) => node?.componentPropertyDefinitions ?? [])\n .some((definition) => definition.id === propertyId)\n}\n\ninterface Assignment {\n /** The instance whose assignment it is. */\n instance: SceneNode\n value: string\n}\n\n/**\n * What the nearest enclosing instance assigns `propertyId`, if any does. An instance assigns its\n * children, not itself, so the walk starts at the parent. A property id belongs to the component\n * that defines it, so the walk stops at an instance of that component even when it assigns\n * nothing; otherwise an outer instance's unrelated property of the same id wins.\n */\nfunction findEnclosingAssignment(\n graph: SceneGraph,\n node: SceneNode,\n propertyId: string\n): Assignment | undefined {\n let current = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (current) {\n if (current.type === 'INSTANCE') {\n if (Object.hasOwn(current.componentPropertyAssignments, propertyId))\n return { instance: current, value: current.componentPropertyAssignments[propertyId] }\n if (definesProperty(graph, current, propertyId)) return undefined\n }\n current = current.parentId ? graph.nodes.get(current.parentId) : undefined\n }\n return undefined\n}\n\nfunction enclosingAssignment(\n graph: SceneGraph,\n node: SceneNode,\n propertyId: string\n): string | undefined {\n return findEnclosingAssignment(graph, node, propertyId)?.value\n}\n\n/** The instances around `node`, nearest first. */\nfunction enclosingInstances(graph: SceneGraph, node: SceneNode): SceneNode[] {\n const instances: SceneNode[] = []\n let parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (parent) {\n if (parent.type === 'INSTANCE') instances.push(parent)\n parent = parent.parentId ? graph.nodes.get(parent.parentId) : undefined\n }\n return instances\n}\n\n/** The outermost of `instances` that records `field` as an edit of `node`, or -1. */\nfunction outermostEdit(instances: SceneNode[], node: SceneNode, field: string): number {\n return instances.findLastIndex((instance) =>\n instance.instanceOverrides.descendants.get(node.id)?.has(field)\n )\n}\n\n/**\n * Whether a text edit of `layer` outranks the assignment that drives it. As in Figma, the edit\n * made in the outer instance wins, and at the same level the assignment does. An assignment is\n * made where an override of it is recorded, or else by the instance that holds it.\n */\nfunction textEditOutranks(\n graph: SceneGraph,\n layer: SceneNode,\n propertyId: string,\n assignment: Assignment\n): boolean {\n const instances = enclosingInstances(graph, layer)\n const textLevel = outermostEdit(instances, layer, 'text')\n if (textLevel < 0) return false\n const overridden = outermostEdit(\n instances,\n assignment.instance,\n assignmentOverrideField(propertyId)\n )\n const assignmentLevel = overridden < 0 ? instances.indexOf(assignment.instance) : overridden\n return textLevel > assignmentLevel\n}\n\nfunction hasEnclosingAssignment(graph: SceneGraph, node: SceneNode, propertyId: string): boolean {\n return enclosingAssignment(graph, node, propertyId) !== undefined\n}\n\n/**\n * A component can gain a property-driven layer after an instance of it exists. Pass 4 leaves a\n * driven field alone, so the fresh clone has to take the enclosing instance's assignment here or\n * it keeps the component's default while every other instance layer shows the assigned value.\n */\nexport function applyEnclosingAssignments(graph: SceneGraph, clone: SceneNode): void {\n for (const reference of clone.componentPropertyReferences) {\n const field = PROPERTY_REFERENCE_FIELDS[reference.field]\n if (!field) continue\n const value = enclosingAssignment(graph, clone, reference.propertyId)\n if (value === undefined) continue\n if (field === 'visible') graph.updateNode(clone.id, { visible: value === 'true' })\n else if (field === 'text') graph.updateNode(clone.id, { text: value })\n else if (field === 'componentId' && clone.type === 'INSTANCE' && graph.nodes.has(value)) {\n graph.swapInstanceComponent(clone.id, value)\n }\n }\n for (const child of graph.getChildren(clone.id)) applyEnclosingAssignments(graph, child)\n}\n\n/**\n * Fields a component property drives on this child. The component states the default, but\n * an enclosing instance's assignment decides the value, so synchronising must not copy the\n * default over it — a page loaded later would otherwise reset the instance to the default.\n */\nexport function propertyDrivenFields(\n graph: SceneGraph,\n instChild: SceneNode,\n compChild: SceneNode\n): Set<string> {\n const driven = new Set<string>()\n for (const reference of compChild.componentPropertyReferences) {\n const field = PROPERTY_REFERENCE_FIELDS[reference.field]\n if (field && hasEnclosingAssignment(graph, instChild, reference.propertyId)) driven.add(field)\n }\n return driven\n}\n\n/**\n * The text and visibility enclosing assignments give an existing child whose layer a property\n * drives. A layer linked to a property after the instance was made would otherwise keep what it\n * showed before, since synchronising leaves driven fields alone.\n */\nexport function assignedFieldValues(\n graph: SceneGraph,\n instChild: SceneNode,\n compChild: SceneNode\n): Partial<SceneNode> {\n const values: Partial<SceneNode> = {}\n for (const reference of compChild.componentPropertyReferences) {\n const assignment = findEnclosingAssignment(graph, instChild, reference.propertyId)\n if (!assignment) continue\n if (reference.field === 'TEXT' && instChild.type === 'TEXT') {\n if (!textEditOutranks(graph, instChild, reference.propertyId, assignment))\n values.text = assignment.value\n } else if (reference.field === 'VISIBLE') values.visible = assignment.value === 'true'\n }\n return values\n}\n"],"mappings":";;;AAMA,MAA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,KAAK;AACzF;;;;;;AAOA,SAAgB,qBACd,OACA,WACA,WACa;CACb,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,aAAa,UAAU,6BAA6B;EAC7D,MAAM,QAAQ,0BAA0B,UAAU;EAClD,IAAI,SAAS,uBAAuB,OAAO,WAAW,UAAU,UAAU,GAAG,OAAO,IAAI,KAAK;CAC/F;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,oBACd,OACA,WACA,WACoB;CACpB,MAAM,SAA6B,CAAC;CACpC,KAAK,MAAM,aAAa,UAAU,6BAA6B;EAC7D,MAAM,aAAa,wBAAwB,OAAO,WAAW,UAAU,UAAU;EACjF,IAAI,CAAC,YAAY;EACjB,IAAI,UAAU,UAAU,UAAU,UAAU,SAAS,QAC/C;OAAA,CAAC,iBAAiB,OAAO,WAAW,UAAU,YAAY,UAAU,GACtE,OAAO,OAAO,WAAW;EAAA,OACtB,IAAI,UAAU,UAAU,WAAW,OAAO,UAAU,WAAW,UAAU;CAClF;CACA,OAAO;AACT"}
|
|
@@ -6,13 +6,13 @@ declare const INSTANCE_SYNC_TEXT_PROPS: readonly ["name", "text", "fontFamily",
|
|
|
6
6
|
* instance ("This property cannot be overridden in an instance"), so its copies always follow.
|
|
7
7
|
* A layer in an auto layout flow takes its position from the layout instead.
|
|
8
8
|
*/
|
|
9
|
-
declare const INSTANCE_FOLLOWED_FIELDS: readonly ["x", "y", "rotation", "flipX", "flipY", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
9
|
+
declare const INSTANCE_FOLLOWED_FIELDS: readonly ["x", "y", "rotation", "flipX", "flipY", "minWidth", "maxWidth", "minHeight", "maxHeight", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
10
10
|
/** Fields a component's layer gives its copies unless an instance overrides them. */
|
|
11
11
|
declare const INSTANCE_SYNC_PROPS: (keyof SceneNode)[];
|
|
12
12
|
/** Fields an edit to a layer inside an instance records as that instance's override. */
|
|
13
13
|
declare const INSTANCE_OVERRIDE_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible"];
|
|
14
14
|
/** Fields a component's layer gives the copies of it in every instance. */
|
|
15
|
-
declare const INSTANCE_SYNC_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible", "x", "y", "rotation", "flipX", "flipY", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
15
|
+
declare const INSTANCE_SYNC_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible", "x", "y", "rotation", "flipX", "flipY", "minWidth", "maxWidth", "minHeight", "maxHeight", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
16
16
|
//#endregion
|
|
17
17
|
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS };
|
|
18
18
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;cA4BA;;
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;cA4BA;;cAsBA,4BAA4B;;cA2B5B,8CAAwB;;cAQxB,0CAAoB"}
|
package/dist/instances/fields.js
CHANGED
|
@@ -32,6 +32,10 @@ const INSTANCE_SYNC_FIELD_OWNERS = {
|
|
|
32
32
|
*/
|
|
33
33
|
const INSTANCE_FOLLOWED_FIELDS = [
|
|
34
34
|
...TRANSFORM_FIELDS,
|
|
35
|
+
"minWidth",
|
|
36
|
+
"maxWidth",
|
|
37
|
+
"minHeight",
|
|
38
|
+
"maxHeight",
|
|
35
39
|
"horizontalConstraint",
|
|
36
40
|
"verticalConstraint",
|
|
37
41
|
"layoutPositioning",
|
|
@@ -53,6 +57,7 @@ const INSTANCE_SYNC_PROPS = difference([
|
|
|
53
57
|
...STROKE_FIELDS,
|
|
54
58
|
...CORNER_FIELDS,
|
|
55
59
|
...AUTO_LAYOUT_FIELDS,
|
|
60
|
+
"layoutAlignSelf",
|
|
56
61
|
"itemReverseZIndex",
|
|
57
62
|
"gridPosition",
|
|
58
63
|
"clipsContent",
|
|
@@ -76,7 +81,19 @@ const INSTANCE_OVERRIDE_FIELDS = [
|
|
|
76
81
|
];
|
|
77
82
|
/** Fields a component's layer gives the copies of it in every instance. */
|
|
78
83
|
const INSTANCE_SYNC_FIELDS = [...INSTANCE_OVERRIDE_FIELDS, ...INSTANCE_FOLLOWED_FIELDS];
|
|
84
|
+
/**
|
|
85
|
+
* Fields an instance frame takes from its component frame, where the file keeps one value for
|
|
86
|
+
* both: a layer inside an instance has no field of its own for them.
|
|
87
|
+
*/
|
|
88
|
+
const INSTANCE_FRAME_FOLLOWED_FIELDS = [
|
|
89
|
+
"layoutPositioning",
|
|
90
|
+
"layoutGrow",
|
|
91
|
+
"minWidth",
|
|
92
|
+
"maxWidth",
|
|
93
|
+
"minHeight",
|
|
94
|
+
"maxHeight"
|
|
95
|
+
];
|
|
79
96
|
//#endregion
|
|
80
|
-
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS };
|
|
97
|
+
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_FRAME_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS };
|
|
81
98
|
|
|
82
99
|
//# sourceMappingURL=fields.js.map
|