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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/chunks/behaviours/kinds.js +273 -0
  4. package/dist/chunks/behaviours/kinds.js.map +1 -0
  5. package/dist/chunks/behaviours/layers.js +607 -0
  6. package/dist/chunks/behaviours/layers.js.map +1 -0
  7. package/dist/chunks/behaviours/spec.js +181 -0
  8. package/dist/chunks/behaviours/spec.js.map +1 -0
  9. package/dist/chunks/buffered-events.js +57 -0
  10. package/dist/chunks/buffered-events.js.map +1 -0
  11. package/dist/chunks/color/contrast.js +57 -0
  12. package/dist/chunks/color/contrast.js.map +1 -0
  13. package/dist/chunks/{components/properties.js → color/index.js} +577 -522
  14. package/dist/chunks/color/index.js.map +1 -0
  15. package/dist/chunks/comments/document.js +32 -0
  16. package/dist/chunks/comments/document.js.map +1 -0
  17. package/dist/chunks/comments/list.js +182 -0
  18. package/dist/chunks/comments/list.js.map +1 -0
  19. package/dist/chunks/comments/merge.js +58 -0
  20. package/dist/chunks/comments/merge.js.map +1 -0
  21. package/dist/chunks/components/exposure.js +2291 -0
  22. package/dist/chunks/components/exposure.js.map +1 -0
  23. package/dist/chunks/components/variants.js +32 -0
  24. package/dist/chunks/components/variants.js.map +1 -0
  25. package/dist/chunks/coordinate.js +93 -55
  26. package/dist/chunks/coordinate.js.map +1 -1
  27. package/dist/chunks/css/grid.js +94 -0
  28. package/dist/chunks/css/grid.js.map +1 -0
  29. package/dist/chunks/css/index.js +160 -0
  30. package/dist/chunks/css/index.js.map +1 -0
  31. package/dist/chunks/fields/geometry.js +14 -0
  32. package/dist/chunks/fields/geometry.js.map +1 -0
  33. package/dist/chunks/group-bounds.js +104 -0
  34. package/dist/chunks/group-bounds.js.map +1 -0
  35. package/dist/chunks/icons/glyph.js +147 -0
  36. package/dist/chunks/icons/glyph.js.map +1 -0
  37. package/dist/chunks/index.js +1724 -663
  38. package/dist/chunks/index.js.map +1 -1
  39. package/dist/color.d.ts +72 -0
  40. package/dist/color.d.ts.map +1 -0
  41. package/dist/color.js +3 -0
  42. package/dist/constants.d.ts +2 -2
  43. package/dist/constants.js +2 -2
  44. package/dist/constants2.d.ts +3 -1
  45. package/dist/constants2.d.ts.map +1 -1
  46. package/dist/coordinate.d.ts +2 -448
  47. package/dist/coordinate.js +2 -2
  48. package/dist/copy.d.ts +1 -1
  49. package/dist/copy.js +1 -1
  50. package/dist/css.d.ts +39 -0
  51. package/dist/css.d.ts.map +1 -0
  52. package/dist/css.js +3 -0
  53. package/dist/geometry.d.ts +1 -1
  54. package/dist/geometry.js +1 -1
  55. package/dist/gradient.d.ts +51 -0
  56. package/dist/gradient.d.ts.map +1 -0
  57. package/dist/gradient.js +132 -0
  58. package/dist/gradient.js.map +1 -0
  59. package/dist/guides.d.ts +2 -2
  60. package/dist/guides.js +39 -0
  61. package/dist/guides.js.map +1 -0
  62. package/dist/hit-test.d.ts +2 -9
  63. package/dist/hit-test.js +176 -34
  64. package/dist/hit-test.js.map +1 -1
  65. package/dist/index.d.ts +4 -8
  66. package/dist/index.js +19 -5
  67. package/dist/instances.d.ts +2 -2
  68. package/dist/instances.js +2 -2
  69. package/dist/layout.d.ts +2 -0
  70. package/dist/layout.js +4 -0
  71. package/dist/node-defaults.d.ts +2 -8
  72. package/dist/node-defaults.js +2 -2
  73. package/dist/order-keys.d.ts +39 -0
  74. package/dist/order-keys.d.ts.map +1 -0
  75. package/dist/order-keys.js +136 -0
  76. package/dist/order-keys.js.map +1 -0
  77. package/dist/parse-path.d.ts +7 -1
  78. package/dist/parse-path.d.ts.map +1 -1
  79. package/dist/parse-path.js +6 -2
  80. package/dist/parse-path.js.map +1 -1
  81. package/dist/polygon.d.ts +53 -0
  82. package/dist/polygon.d.ts.map +1 -0
  83. package/dist/polygon.js +205 -0
  84. package/dist/polygon.js.map +1 -0
  85. package/dist/preview.d.ts +1 -1
  86. package/dist/random.d.ts +7 -0
  87. package/dist/random.d.ts.map +1 -0
  88. package/dist/random.js +2 -0
  89. package/dist/resize.d.ts +11 -2
  90. package/dist/resize.d.ts.map +1 -1
  91. package/dist/resize.js +2 -184
  92. package/dist/snap.d.ts +1 -1
  93. package/dist/text-direction.d.ts +13 -0
  94. package/dist/text-direction.d.ts.map +1 -0
  95. package/dist/text-direction.js +31 -0
  96. package/dist/text-direction.js.map +1 -0
  97. package/dist/text-picture.d.ts +1 -1
  98. package/dist/text-picture.d.ts.map +1 -1
  99. package/dist/text.d.ts +2 -0
  100. package/dist/text.js +3 -0
  101. package/dist/types.d.ts +2121 -15
  102. package/dist/types.d.ts.map +1 -1
  103. package/dist/types.js +2 -1
  104. package/dist/types2.d.ts +2 -2
  105. package/dist/undo.d.ts +2 -2
  106. package/dist/undo.js +2 -2
  107. package/dist/undo2.d.ts +29 -1
  108. package/dist/undo2.d.ts.map +1 -1
  109. package/dist/variables.d.ts +2 -29
  110. package/dist/variables.js +2 -2
  111. package/dist/variant-properties.d.ts +9 -1
  112. package/dist/variant-properties.d.ts.map +1 -1
  113. package/dist/variant-properties.js +36 -1
  114. package/dist/variant-properties.js.map +1 -1
  115. package/dist/vector-network.d.ts +1 -1
  116. package/dist/vector-network.js +1 -1
  117. package/package.json +60 -9
  118. package/src/behaviours/kinds.ts +185 -0
  119. package/src/behaviours/layers.ts +51 -0
  120. package/src/behaviours/model.ts +192 -0
  121. package/src/behaviours/schema.ts +58 -0
  122. package/src/behaviours/spec.ts +223 -0
  123. package/src/buffered-events.ts +64 -0
  124. package/src/color/contrast.ts +31 -0
  125. package/src/color/index.ts +88 -0
  126. package/src/color/management.ts +210 -0
  127. package/src/color/normalize.ts +7 -0
  128. package/src/color/okhcl.ts +201 -0
  129. package/src/comments/document.ts +51 -0
  130. package/src/comments/list.ts +52 -0
  131. package/src/comments/merge.ts +63 -0
  132. package/src/comments/threads.ts +156 -0
  133. package/src/components/exposure.ts +61 -0
  134. package/src/components/properties.ts +18 -15
  135. package/src/components/variants.ts +53 -0
  136. package/src/constants.ts +2 -0
  137. package/src/coordinate.ts +100 -43
  138. package/src/copy.ts +17 -6
  139. package/src/css/grid.ts +70 -0
  140. package/src/css/index.ts +9 -0
  141. package/src/css/layout.ts +53 -0
  142. package/src/css/shadows.ts +68 -0
  143. package/src/css/values.ts +42 -0
  144. package/src/export-format.ts +12 -0
  145. package/src/fields/geometry.ts +11 -0
  146. package/src/fields/text.ts +35 -0
  147. package/src/gradient.ts +166 -0
  148. package/src/group-bounds.ts +131 -0
  149. package/src/guides.ts +39 -0
  150. package/src/hit-test.ts +262 -46
  151. package/src/icons/glyph.ts +128 -0
  152. package/src/icons/model.ts +54 -0
  153. package/src/icons/schema.ts +18 -0
  154. package/src/index.ts +347 -57
  155. package/src/instance-overrides.ts +27 -0
  156. package/src/instances/content-size.ts +58 -0
  157. package/src/instances/copies.ts +239 -0
  158. package/src/instances/cycles.ts +73 -0
  159. package/src/instances/fields.ts +143 -0
  160. package/src/instances/main-component.ts +19 -0
  161. package/src/instances/placement.ts +29 -0
  162. package/src/instances/source-walk.ts +41 -0
  163. package/src/instances/sync.ts +600 -0
  164. package/src/instances/vector-geometry.ts +81 -0
  165. package/src/instances.ts +125 -330
  166. package/src/layout/aspect-ratio.ts +51 -0
  167. package/src/{layout-guides.ts → layout/guides.ts} +41 -12
  168. package/src/layout/index.ts +4 -0
  169. package/src/layout/keywords.ts +73 -0
  170. package/src/layout/sizing.ts +196 -0
  171. package/src/mutation-impact.ts +25 -10
  172. package/src/node-defaults.ts +50 -2
  173. package/src/order-keys.ts +162 -0
  174. package/src/parse-path.ts +10 -2
  175. package/src/plugin-data/field.ts +131 -0
  176. package/src/plugin-data/fields.ts +246 -0
  177. package/src/polygon.ts +211 -0
  178. package/src/preview.ts +1 -1
  179. package/src/random.ts +28 -0
  180. package/src/resize.ts +99 -12
  181. package/src/scaling/index.ts +2 -0
  182. package/src/scaling/node.ts +164 -0
  183. package/src/scaling/tree.ts +50 -0
  184. package/src/shaders/model.ts +98 -0
  185. package/src/shaders/schema.ts +48 -0
  186. package/src/shared-styles.ts +5 -2
  187. package/src/slots/authoring.ts +101 -0
  188. package/src/slots/content.ts +124 -0
  189. package/src/slots/frames.ts +160 -0
  190. package/src/slots/limits.ts +49 -0
  191. package/src/text/direction.ts +55 -0
  192. package/src/text/index.ts +3 -0
  193. package/src/text/lists.ts +138 -0
  194. package/src/text/paragraphs.ts +241 -0
  195. package/src/{text-picture.ts → text/picture.ts} +21 -29
  196. package/src/text/references.ts +50 -0
  197. package/src/transfer/apply.ts +84 -0
  198. package/src/transfer/history.ts +49 -0
  199. package/src/transfer/identity.ts +16 -0
  200. package/src/transfer/index.ts +6 -0
  201. package/src/transfer/nodes.ts +120 -0
  202. package/src/transfer/plan.ts +130 -0
  203. package/src/transfer/references.ts +9 -0
  204. package/src/transfer/remove.ts +39 -0
  205. package/src/transfer/validation.ts +59 -0
  206. package/src/transfer/variables.ts +82 -0
  207. package/src/types.ts +257 -13
  208. package/src/undo.ts +54 -2
  209. package/src/variables/bindings.ts +224 -0
  210. package/src/variables/fields.ts +43 -0
  211. package/src/variables/token.ts +14 -0
  212. package/src/variables/units.ts +15 -0
  213. package/src/variables.ts +118 -69
  214. package/src/variant-properties.ts +50 -0
  215. package/dist/chunks/components/properties.js.map +0 -1
  216. package/dist/chunks/export-scale.js +0 -19
  217. package/dist/chunks/export-scale.js.map +0 -1
  218. package/dist/coordinate.d.ts.map +0 -1
  219. package/dist/coordinate2.d.ts +0 -2
  220. package/dist/guides2.d.ts +0 -11
  221. package/dist/guides2.d.ts.map +0 -1
  222. package/dist/hit-test.d.ts.map +0 -1
  223. package/dist/layout-guides.d.ts +0 -2
  224. package/dist/layout-guides.js +0 -2
  225. package/dist/layout-guides2.d.ts +0 -16
  226. package/dist/layout-guides2.d.ts.map +0 -1
  227. package/dist/node-defaults.d.ts.map +0 -1
  228. package/dist/preview2.d.ts +0 -12
  229. package/dist/preview2.d.ts.map +0 -1
  230. package/dist/resize.js.map +0 -1
  231. package/dist/variables.d.ts.map +0 -1
  232. package/dist/vector-network2.d.ts +0 -32
  233. package/dist/vector-network2.d.ts.map +0 -1
  234. package/src/instance-overrides.test.ts +0 -67
@@ -0,0 +1,51 @@
1
+ import { Color, Vector } from "./primitives2.js";
2
+ import { Fill, GradientStop, GradientTransform } from "./types.js";
3
+ //#region src/gradient.d.ts
4
+ /**
5
+ * Gradient paints in Figma's convention. A paint's `gradientTransform` maps the layer's unit
6
+ * square to gradient space, as Figma's plugin API, `.fig` files, and the clipboard store it. In
7
+ * gradient space a linear gradient runs from (0, 0.5) to (1, 0.5); radial, angular, and diamond
8
+ * gradients are centred on (0.5, 0.5) with radius 0.5, and an angular one starts at +x and turns
9
+ * clockwise. Every reader and writer of gradients goes through this module.
10
+ */
11
+ type GradientFillType = Extract<Fill['type'], 'GRADIENT_LINEAR' | 'GRADIENT_RADIAL' | 'GRADIENT_ANGULAR' | 'GRADIENT_DIAMOND'>;
12
+ declare function isGradientFill(type: Fill['type']): type is GradientFillType;
13
+ /** Left to right for a linear gradient; centred and filling the layer for the others. */
14
+ declare const IDENTITY_GRADIENT_TRANSFORM: GradientTransform;
15
+ /**
16
+ * Figma's transform when a fill becomes a gradient: top to bottom, and centred when switched to
17
+ * another kind (Figma desktop 126).
18
+ */
19
+ declare const DEFAULT_GRADIENT_TRANSFORM: GradientTransform;
20
+ /** Figma's stops for a new gradient: the fill colour, then a 60% shade of it. */
21
+ declare function defaultGradientStops(color: Color): GradientStop[];
22
+ declare function isIdentityGradientTransform(t: GradientTransform): boolean;
23
+ /**
24
+ * The inverse affine map; a singular one falls back to the identity. Inverting a
25
+ * `gradientTransform` gives the map from gradient space to the layer's unit square.
26
+ */
27
+ declare function invertGradientTransform(t: GradientTransform): GradientTransform;
28
+ /** A point through an affine map. */
29
+ declare function applyGradientTransform(t: GradientTransform, point: Vector): Vector;
30
+ /** Where a point of gradient space falls in the layer's unit square. */
31
+ declare function gradientPoint(t: GradientTransform, point: Vector): Vector;
32
+ /**
33
+ * The transform of a linear gradient from `start` to `end` whose bands run along `across`, all in
34
+ * the layer's unit square, such as an SVG gradient mapped through its own transform.
35
+ */
36
+ declare function linearGradientTransformFromAxes(start: Vector, end: Vector, across: Vector): GradientTransform;
37
+ /**
38
+ * The transform of a linear gradient from `start` to `end`, both in the layer's unit square, in a
39
+ * `width` × `height` layer. Its second axis is square to the line on screen and `ratio` times as
40
+ * long; Figma keeps that ratio when a handle is dragged (measured on desktop 126), and it starts
41
+ * as the layer's height over its width.
42
+ */
43
+ declare function linearGradientTransform(start: Vector, end: Vector, width?: number, height?: number, ratio?: number): GradientTransform;
44
+ /**
45
+ * The transform of a radial, angular, or diamond gradient from its centre and the ends of its two
46
+ * radii, all in the layer's unit square.
47
+ */
48
+ declare function ellipticalGradientTransform(center: Vector, radiusX: Vector, radiusY: Vector): GradientTransform;
49
+ //#endregion
50
+ export { DEFAULT_GRADIENT_TRANSFORM, GradientFillType, IDENTITY_GRADIENT_TRANSFORM, applyGradientTransform, defaultGradientStops, ellipticalGradientTransform, gradientPoint, invertGradientTransform, isGradientFill, isIdentityGradientTransform, linearGradientTransform, linearGradientTransformFromAxes };
51
+ //# sourceMappingURL=gradient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gradient.d.ts","names":[],"sources":["../src/gradient.ts"],"mappings":";;;;;;;;;;KAWY,mBAAmB,QAC7B;iBAIc,eAAe,MAAM,eAAe,QAAQ;;cAU/C,6BAA6B;;;;;cAa7B,4BAA4B;;iBAazB,qBAAqB,OAAO,QAAQ;iBAepC,4BAA4B,GAAG;;;;;iBAU/B,wBAAwB,GAAG,oBAAoB;;iBAkB/C,uBAAuB,GAAG,mBAAmB,OAAO,SAAS;;iBAQ7D,cAAc,GAAG,mBAAmB,OAAO,SAAS;;;;;iBAQpD,gCACd,OAAO,QACP,KAAK,QACL,QAAQ,SACP;;;;;;;iBAiBa,wBACd,OAAO,QACP,KAAK,QACL,gBACA,iBACA,iBACC;;;;;iBAYa,4BACd,QAAQ,QACR,SAAS,QACT,SAAS,SACR"}
@@ -0,0 +1,132 @@
1
+ //#region src/gradient.ts
2
+ function isGradientFill(type) {
3
+ return type === "GRADIENT_LINEAR" || type === "GRADIENT_RADIAL" || type === "GRADIENT_ANGULAR" || type === "GRADIENT_DIAMOND";
4
+ }
5
+ /** Left to right for a linear gradient; centred and filling the layer for the others. */
6
+ const IDENTITY_GRADIENT_TRANSFORM = {
7
+ m00: 1,
8
+ m01: 0,
9
+ m02: 0,
10
+ m10: 0,
11
+ m11: 1,
12
+ m12: 0
13
+ };
14
+ /**
15
+ * Figma's transform when a fill becomes a gradient: top to bottom, and centred when switched to
16
+ * another kind (Figma desktop 126).
17
+ */
18
+ const DEFAULT_GRADIENT_TRANSFORM = {
19
+ m00: 0,
20
+ m01: 1,
21
+ m02: 0,
22
+ m10: -1,
23
+ m11: 0,
24
+ m12: 1
25
+ };
26
+ /** How dark a new gradient's second stop is next to the fill colour, as in Figma. */
27
+ const DEFAULT_GRADIENT_SHADE = .6;
28
+ /** Figma's stops for a new gradient: the fill colour, then a 60% shade of it. */
29
+ function defaultGradientStops(color) {
30
+ return [{
31
+ color: { ...color },
32
+ position: 0
33
+ }, {
34
+ color: {
35
+ r: color.r * DEFAULT_GRADIENT_SHADE,
36
+ g: color.g * DEFAULT_GRADIENT_SHADE,
37
+ b: color.b * DEFAULT_GRADIENT_SHADE,
38
+ a: color.a
39
+ },
40
+ position: 1
41
+ }];
42
+ }
43
+ function isIdentityGradientTransform(t) {
44
+ return Object.keys(IDENTITY_GRADIENT_TRANSFORM).every((key) => t[key] === IDENTITY_GRADIENT_TRANSFORM[key]);
45
+ }
46
+ /**
47
+ * The inverse affine map; a singular one falls back to the identity. Inverting a
48
+ * `gradientTransform` gives the map from gradient space to the layer's unit square.
49
+ */
50
+ function invertGradientTransform(t) {
51
+ const det = t.m00 * t.m11 - t.m01 * t.m10;
52
+ if (Math.abs(det) < 1e-12) return IDENTITY_GRADIENT_TRANSFORM;
53
+ const m00 = t.m11 / det;
54
+ const m01 = -t.m01 / det;
55
+ const m10 = -t.m10 / det;
56
+ const m11 = t.m00 / det;
57
+ return {
58
+ m00,
59
+ m01,
60
+ m02: -(m00 * t.m02 + m01 * t.m12),
61
+ m10,
62
+ m11,
63
+ m12: -(m10 * t.m02 + m11 * t.m12)
64
+ };
65
+ }
66
+ /** A point through an affine map. */
67
+ function applyGradientTransform(t, point) {
68
+ return {
69
+ x: t.m00 * point.x + t.m01 * point.y + t.m02,
70
+ y: t.m10 * point.x + t.m11 * point.y + t.m12
71
+ };
72
+ }
73
+ /** Where a point of gradient space falls in the layer's unit square. */
74
+ function gradientPoint(t, point) {
75
+ return applyGradientTransform(invertGradientTransform(t), point);
76
+ }
77
+ /**
78
+ * The transform of a linear gradient from `start` to `end` whose bands run along `across`, all in
79
+ * the layer's unit square, such as an SVG gradient mapped through its own transform.
80
+ */
81
+ function linearGradientTransformFromAxes(start, end, across) {
82
+ return invertGradientTransform({
83
+ m00: end.x - start.x,
84
+ m01: across.x,
85
+ m02: start.x - across.x / 2,
86
+ m10: end.y - start.y,
87
+ m11: across.y,
88
+ m12: start.y - across.y / 2
89
+ });
90
+ }
91
+ /**
92
+ * The transform of a linear gradient from `start` to `end`, both in the layer's unit square, in a
93
+ * `width` × `height` layer. Its second axis is square to the line on screen and `ratio` times as
94
+ * long; Figma keeps that ratio when a handle is dragged (measured on desktop 126), and it starts
95
+ * as the layer's height over its width.
96
+ */
97
+ function linearGradientTransform(start, end, width = 1, height = 1, ratio = height / width) {
98
+ const axis = {
99
+ x: end.x - start.x,
100
+ y: end.y - start.y
101
+ };
102
+ return linearGradientTransformFromAxes(start, end, {
103
+ x: -axis.y * height * ratio / width,
104
+ y: axis.x * width * ratio / height
105
+ });
106
+ }
107
+ /**
108
+ * The transform of a radial, angular, or diamond gradient from its centre and the ends of its two
109
+ * radii, all in the layer's unit square.
110
+ */
111
+ function ellipticalGradientTransform(center, radiusX, radiusY) {
112
+ const xAxis = {
113
+ x: 2 * (radiusX.x - center.x),
114
+ y: 2 * (radiusX.y - center.y)
115
+ };
116
+ const yAxis = {
117
+ x: 2 * (radiusY.x - center.x),
118
+ y: 2 * (radiusY.y - center.y)
119
+ };
120
+ return invertGradientTransform({
121
+ m00: xAxis.x,
122
+ m01: yAxis.x,
123
+ m02: center.x - (xAxis.x + yAxis.x) / 2,
124
+ m10: xAxis.y,
125
+ m11: yAxis.y,
126
+ m12: center.y - (xAxis.y + yAxis.y) / 2
127
+ });
128
+ }
129
+ //#endregion
130
+ export { DEFAULT_GRADIENT_TRANSFORM, IDENTITY_GRADIENT_TRANSFORM, applyGradientTransform, defaultGradientStops, ellipticalGradientTransform, gradientPoint, invertGradientTransform, isGradientFill, isIdentityGradientTransform, linearGradientTransform, linearGradientTransformFromAxes };
131
+
132
+ //# sourceMappingURL=gradient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gradient.js","names":[],"sources":["../src/gradient.ts"],"sourcesContent":["import type { Color, Vector } from './primitives'\nimport type { Fill, GradientStop, GradientTransform } from './types'\n\n/**\n * Gradient paints in Figma's convention. A paint's `gradientTransform` maps the layer's unit\n * square to gradient space, as Figma's plugin API, `.fig` files, and the clipboard store it. In\n * gradient space a linear gradient runs from (0, 0.5) to (1, 0.5); radial, angular, and diamond\n * gradients are centred on (0.5, 0.5) with radius 0.5, and an angular one starts at +x and turns\n * clockwise. Every reader and writer of gradients goes through this module.\n */\n\nexport type GradientFillType = Extract<\n Fill['type'],\n 'GRADIENT_LINEAR' | 'GRADIENT_RADIAL' | 'GRADIENT_ANGULAR' | 'GRADIENT_DIAMOND'\n>\n\nexport function isGradientFill(type: Fill['type']): type is GradientFillType {\n return (\n type === 'GRADIENT_LINEAR' ||\n type === 'GRADIENT_RADIAL' ||\n type === 'GRADIENT_ANGULAR' ||\n type === 'GRADIENT_DIAMOND'\n )\n}\n\n/** Left to right for a linear gradient; centred and filling the layer for the others. */\nexport const IDENTITY_GRADIENT_TRANSFORM: GradientTransform = {\n m00: 1,\n m01: 0,\n m02: 0,\n m10: 0,\n m11: 1,\n m12: 0\n}\n\n/**\n * Figma's transform when a fill becomes a gradient: top to bottom, and centred when switched to\n * another kind (Figma desktop 126).\n */\nexport const DEFAULT_GRADIENT_TRANSFORM: GradientTransform = {\n m00: 0,\n m01: 1,\n m02: 0,\n m10: -1,\n m11: 0,\n m12: 1\n}\n\n/** How dark a new gradient's second stop is next to the fill colour, as in Figma. */\nconst DEFAULT_GRADIENT_SHADE = 0.6\n\n/** Figma's stops for a new gradient: the fill colour, then a 60% shade of it. */\nexport function defaultGradientStops(color: Color): GradientStop[] {\n return [\n { color: { ...color }, position: 0 },\n {\n color: {\n r: color.r * DEFAULT_GRADIENT_SHADE,\n g: color.g * DEFAULT_GRADIENT_SHADE,\n b: color.b * DEFAULT_GRADIENT_SHADE,\n a: color.a\n },\n position: 1\n }\n ]\n}\n\nexport function isIdentityGradientTransform(t: GradientTransform): boolean {\n return (Object.keys(IDENTITY_GRADIENT_TRANSFORM) as (keyof GradientTransform)[]).every(\n (key) => t[key] === IDENTITY_GRADIENT_TRANSFORM[key]\n )\n}\n\n/**\n * The inverse affine map; a singular one falls back to the identity. Inverting a\n * `gradientTransform` gives the map from gradient space to the layer's unit square.\n */\nexport function invertGradientTransform(t: GradientTransform): GradientTransform {\n const det = t.m00 * t.m11 - t.m01 * t.m10\n if (Math.abs(det) < 1e-12) return IDENTITY_GRADIENT_TRANSFORM\n const m00 = t.m11 / det\n const m01 = -t.m01 / det\n const m10 = -t.m10 / det\n const m11 = t.m00 / det\n return {\n m00,\n m01,\n m02: -(m00 * t.m02 + m01 * t.m12),\n m10,\n m11,\n m12: -(m10 * t.m02 + m11 * t.m12)\n }\n}\n\n/** A point through an affine map. */\nexport function applyGradientTransform(t: GradientTransform, point: Vector): Vector {\n return {\n x: t.m00 * point.x + t.m01 * point.y + t.m02,\n y: t.m10 * point.x + t.m11 * point.y + t.m12\n }\n}\n\n/** Where a point of gradient space falls in the layer's unit square. */\nexport function gradientPoint(t: GradientTransform, point: Vector): Vector {\n return applyGradientTransform(invertGradientTransform(t), point)\n}\n\n/**\n * The transform of a linear gradient from `start` to `end` whose bands run along `across`, all in\n * the layer's unit square, such as an SVG gradient mapped through its own transform.\n */\nexport function linearGradientTransformFromAxes(\n start: Vector,\n end: Vector,\n across: Vector\n): GradientTransform {\n return invertGradientTransform({\n m00: end.x - start.x,\n m01: across.x,\n m02: start.x - across.x / 2,\n m10: end.y - start.y,\n m11: across.y,\n m12: start.y - across.y / 2\n })\n}\n\n/**\n * The transform of a linear gradient from `start` to `end`, both in the layer's unit square, in a\n * `width` × `height` layer. Its second axis is square to the line on screen and `ratio` times as\n * long; Figma keeps that ratio when a handle is dragged (measured on desktop 126), and it starts\n * as the layer's height over its width.\n */\nexport function linearGradientTransform(\n start: Vector,\n end: Vector,\n width = 1,\n height = 1,\n ratio = height / width\n): GradientTransform {\n const axis = { x: end.x - start.x, y: end.y - start.y }\n return linearGradientTransformFromAxes(start, end, {\n x: (-axis.y * height * ratio) / width,\n y: (axis.x * width * ratio) / height\n })\n}\n\n/**\n * The transform of a radial, angular, or diamond gradient from its centre and the ends of its two\n * radii, all in the layer's unit square.\n */\nexport function ellipticalGradientTransform(\n center: Vector,\n radiusX: Vector,\n radiusY: Vector\n): GradientTransform {\n const xAxis = { x: 2 * (radiusX.x - center.x), y: 2 * (radiusX.y - center.y) }\n const yAxis = { x: 2 * (radiusY.x - center.x), y: 2 * (radiusY.y - center.y) }\n return invertGradientTransform({\n m00: xAxis.x,\n m01: yAxis.x,\n m02: center.x - (xAxis.x + yAxis.x) / 2,\n m10: xAxis.y,\n m11: yAxis.y,\n m12: center.y - (xAxis.y + yAxis.y) / 2\n })\n}\n"],"mappings":";AAgBA,SAAgB,eAAe,MAA8C;CAC3E,OACE,SAAS,qBACT,SAAS,qBACT,SAAS,sBACT,SAAS;AAEb;;AAGA,MAAa,8BAAiD;CAC5D,KAAK;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MA,SAAgB,gCACd,OACA,KACA,QACmB;CACnB,OAAO,wBAAwB;EAC7B,KAAK,IAAI,IAAI,MAAM;EACnB,KAAK,OAAO;EACZ,KAAK,MAAM,IAAI,OAAO,IAAI;EAC1B,KAAK,IAAI,IAAI,MAAM;EACnB,KAAK,OAAO;EACZ,KAAK,MAAM,IAAI,OAAO,IAAI;CAC5B,CAAC;AACH;;;;;;;AAQA,SAAgB,wBACd,OACA,KACA,QAAQ,GACR,SAAS,GACT,QAAQ,SAAS,OACE;CACnB,MAAM,OAAO;EAAE,GAAG,IAAI,IAAI,MAAM;EAAG,GAAG,IAAI,IAAI,MAAM;CAAE;CACtD,OAAO,gCAAgC,OAAO,KAAK;EACjD,GAAI,CAAC,KAAK,IAAI,SAAS,QAAS;EAChC,GAAI,KAAK,IAAI,QAAQ,QAAS;CAChC,CAAC;AACH;;;;;AAMA,SAAgB,4BACd,QACA,SACA,SACmB;CACnB,MAAM,QAAQ;EAAE,GAAG,KAAK,QAAQ,IAAI,OAAO;EAAI,GAAG,KAAK,QAAQ,IAAI,OAAO;CAAG;CAC7E,MAAM,QAAQ;EAAE,GAAG,KAAK,QAAQ,IAAI,OAAO;EAAI,GAAG,KAAK,QAAQ,IAAI,OAAO;CAAG;CAC7E,OAAO,wBAAwB;EAC7B,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,OAAO,KAAK,MAAM,IAAI,MAAM,KAAK;EACtC,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,OAAO,KAAK,MAAM,IAAI,MAAM,KAAK;CACxC,CAAC;AACH"}
package/dist/guides.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { CanvasGuide } from "./guides2.js";
2
- export { CanvasGuide };
1
+ import { CanvasGuide, guideOwnersOnPage } from "./types.js";
2
+ export { CanvasGuide, guideOwnersOnPage };
package/dist/guides.js CHANGED
@@ -0,0 +1,39 @@
1
+ //#region src/guides.ts
2
+ const ownersByGraph = /* @__PURE__ */ new WeakMap();
3
+ function ownerSet(graph) {
4
+ const existing = ownersByGraph.get(graph);
5
+ if (existing) return existing;
6
+ const owners = /* @__PURE__ */ new Set();
7
+ for (const node of graph.getAllNodes()) if (node.guides.length > 0) owners.add(node.id);
8
+ const track = (node, id) => {
9
+ if (node && node.guides.length > 0) owners.add(id);
10
+ else owners.delete(id);
11
+ };
12
+ graph.onNodeEvents({
13
+ created: (node) => track(node, node.id),
14
+ updated: (id, changes) => {
15
+ if ("guides" in changes) track(graph.getNode(id), id);
16
+ },
17
+ deleted: (id) => owners.delete(id)
18
+ });
19
+ ownersByGraph.set(graph, owners);
20
+ return owners;
21
+ }
22
+ /**
23
+ * The layers on a page that carry guides, which a frame anywhere in the tree can, as in Figma.
24
+ * The graph keeps the set current from its node events, so drawing and hit-testing guides do not
25
+ * walk the page's whole tree on every frame.
26
+ */
27
+ function guideOwnersOnPage(graph, pageId) {
28
+ const owners = [];
29
+ for (const id of ownerSet(graph)) {
30
+ const node = graph.getNode(id);
31
+ if (!node || node.guides.length === 0) continue;
32
+ if (graph.pageOf(id) === pageId) owners.push(node);
33
+ }
34
+ return owners;
35
+ }
36
+ //#endregion
37
+ export { guideOwnersOnPage };
38
+
39
+ //# sourceMappingURL=guides.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guides.js","names":[],"sources":["../src/guides.ts"],"sourcesContent":["import type { SceneGraph } from './index'\nimport type { GUID } from './primitives'\nimport type { SceneNode } from './types'\n\nexport interface CanvasGuide {\n id: string\n axis: 'x' | 'y'\n position: number\n figGuid?: GUID\n}\n\nconst ownersByGraph = new WeakMap<SceneGraph, Set<string>>()\n\nfunction ownerSet(graph: SceneGraph): Set<string> {\n const existing = ownersByGraph.get(graph)\n if (existing) return existing\n const owners = new Set<string>()\n for (const node of graph.getAllNodes()) if (node.guides.length > 0) owners.add(node.id)\n const track = (node: SceneNode | undefined, id: string) => {\n if (node && node.guides.length > 0) owners.add(id)\n else owners.delete(id)\n }\n graph.onNodeEvents({\n created: (node) => track(node, node.id),\n updated: (id, changes) => {\n if ('guides' in changes) track(graph.getNode(id), id)\n },\n deleted: (id) => owners.delete(id)\n })\n ownersByGraph.set(graph, owners)\n return owners\n}\n\n/**\n * The layers on a page that carry guides, which a frame anywhere in the tree can, as in Figma.\n * The graph keeps the set current from its node events, so drawing and hit-testing guides do not\n * walk the page's whole tree on every frame.\n */\nexport function guideOwnersOnPage(graph: SceneGraph, pageId: string): SceneNode[] {\n const owners: SceneNode[] = []\n for (const id of ownerSet(graph)) {\n const node = graph.getNode(id)\n if (!node || node.guides.length === 0) continue\n if (graph.pageOf(id) === pageId) owners.push(node)\n }\n return owners\n}\n"],"mappings":";AAWA,MAAM,gCAAgB,IAAI,QAAiC;AAE3D,SAAS,SAAS,OAAgC;CAChD,MAAM,WAAW,cAAc,IAAI,KAAK;CACxC,IAAI,UAAU,OAAO;CACrB,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,MAAM,YAAY,GAAG,IAAI,KAAK,OAAO,SAAS,GAAG,OAAO,IAAI,KAAK,EAAE;CACtF,MAAM,SAAS,MAA6B,OAAe;EACzD,IAAI,QAAQ,KAAK,OAAO,SAAS,GAAG,OAAO,IAAI,EAAE;OAC5C,OAAO,OAAO,EAAE;CACvB;CACA,MAAM,aAAa;EACjB,UAAU,SAAS,MAAM,MAAM,KAAK,EAAE;EACtC,UAAU,IAAI,YAAY;GACxB,IAAI,YAAY,SAAS,MAAM,MAAM,QAAQ,EAAE,GAAG,EAAE;EACtD;EACA,UAAU,OAAO,OAAO,OAAO,EAAE;CACnC,CAAC;CACD,cAAc,IAAI,OAAO,MAAM;CAC/B,OAAO;AACT;;;;;;AAOA,SAAgB,kBAAkB,OAAmB,QAA6B;CAChF,MAAM,SAAsB,CAAC;CAC7B,KAAK,MAAM,MAAM,SAAS,KAAK,GAAG;EAChC,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,QAAQ,KAAK,OAAO,WAAW,GAAG;EACvC,IAAI,MAAM,OAAO,EAAE,MAAM,QAAQ,OAAO,KAAK,IAAI;CACnD;CACA,OAAO;AACT"}
@@ -1,9 +1,2 @@
1
- import { SceneNode } from "./types.js";
2
- import { SceneGraph } from "./coordinate.js";
3
- //#region src/hit-test.d.ts
4
- declare function hitTest(graph: SceneGraph, px: number, py: number, scopeId?: string): SceneNode | null;
5
- declare function hitTestDeep(graph: SceneGraph, px: number, py: number, scopeId?: string): SceneNode | null;
6
- declare function hitTestFrame(graph: SceneGraph, px: number, py: number, excludeIds: Set<string>, scopeId?: string): SceneNode | null;
7
- //#endregion
8
- export { hitTest, hitTestDeep, hitTestFrame };
9
- //# sourceMappingURL=hit-test.d.ts.map
1
+ import { DropTargetOptions, hitTest, hitTestDeep, hitTestDropTarget, hitTestOpenContainer, hitTestSelectable, isOpenContainer, isPointInNode } from "./types.js";
2
+ export { DropTargetOptions, hitTest, hitTestDeep, hitTestDropTarget, hitTestOpenContainer, hitTestSelectable, isOpenContainer, isPointInNode };
package/dist/hit-test.js CHANGED
@@ -13,6 +13,19 @@ const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]
13
13
  function hasVisibleFillOrStroke(node) {
14
14
  return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible);
15
15
  }
16
+ function isTopLevel(graph, node) {
17
+ const parent = node.parentId ? graph.nodes.get(node.parentId) : void 0;
18
+ return parent?.type === "CANVAS" || parent?.type === "SECTION";
19
+ }
20
+ /**
21
+ * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto
22
+ * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one
23
+ * click away, with or without a fill. A plain top-level frame's empty area is background, and a
24
+ * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).
25
+ */
26
+ function ownsItsEmptyArea(graph, node) {
27
+ return node.type === "FRAME" && node.layoutMode !== "NONE" && isTopLevel(graph, node);
28
+ }
16
29
  function hasTransformedAncestor(node, graph, cache) {
17
30
  const cached = cache.get(node.id);
18
31
  if (cached !== void 0) return cached;
@@ -21,38 +34,44 @@ function hasTransformedAncestor(node, graph, cache) {
21
34
  cache.set(node.id, transformed);
22
35
  return transformed;
23
36
  }
24
- function containsPoint(px, py, node, graph, transformCache) {
37
+ /** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */
38
+ function containsPoint(px, py, node, graph, transformCache, pad = 0) {
25
39
  if (!hasTransformedAncestor(node, graph, transformCache)) {
26
40
  const absolute = graph.getAbsolutePosition(node.id);
27
- return px >= absolute.x && px <= absolute.x + node.width && py >= absolute.y && py <= absolute.y + node.height;
41
+ return px >= absolute.x - pad && px <= absolute.x + node.width + pad && py >= absolute.y - pad && py <= absolute.y + node.height + pad;
28
42
  }
29
43
  const m = getWorldMatrix(node, graph);
30
44
  const inv = Matrix.invert(m);
31
45
  if (!inv) return false;
32
46
  const [localX, localY] = Matrix.mapPoints(inv, [px, py]);
33
- return localX >= 0 && localX <= node.width && localY >= 0 && localY <= node.height;
47
+ return localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad;
34
48
  }
35
- function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache) {
49
+ function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad) {
36
50
  if (!containsPoint(px, py, child, graph, transformCache)) return null;
37
- if (hitTestChildren(graph, px, py, childId, deep, transformCache)) return child;
51
+ if (hitTestChildren(graph, px, py, childId, deep, transformCache, pad)) return child;
38
52
  if (hasVisibleFillOrStroke(child)) return child;
39
53
  return null;
40
54
  }
41
- function hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache) {
55
+ function hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad) {
42
56
  if (child.type === "GROUP") {
43
- if (!containsPoint(px, py, child, graph, transformCache)) return null;
44
- if (deep) return hitTestChildren(graph, px, py, childId, deep, transformCache) ?? child;
45
- return child;
57
+ if (!containsPoint(px, py, child, graph, transformCache, pad)) return null;
58
+ const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad);
59
+ if (childHit) return deep ? childHit : child;
60
+ return containsPoint(px, py, child, graph, transformCache) ? child : null;
46
61
  }
47
- const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache);
62
+ const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad);
48
63
  if (childHit) {
49
64
  if (child.locked) return child;
50
65
  return childHit;
51
66
  }
52
- if (containsPoint(px, py, child, graph, transformCache) && hasVisibleFillOrStroke(child)) return child;
67
+ if (containsPoint(px, py, child, graph, transformCache) && (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))) return child;
53
68
  return null;
54
69
  }
55
- function hitTestChildren(graph, px, py, parentId, deep = false, transformCache = /* @__PURE__ */ new Map()) {
70
+ /**
71
+ * The topmost layer under the point among a container's children. `pad`, in canvas units, grows
72
+ * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.
73
+ */
74
+ function hitTestChildren(graph, px, py, parentId, deep = false, transformCache = /* @__PURE__ */ new Map(), pad = 0) {
56
75
  const parent = graph.nodes.get(parentId);
57
76
  if (!parent) return null;
58
77
  if (parent.clipsContent) {
@@ -64,46 +83,169 @@ function hitTestChildren(graph, px, py, parentId, deep = false, transformCache =
64
83
  if (!child || child.internalOnly || !child.visible) continue;
65
84
  if (CONTAINER_TYPES.has(child.type)) {
66
85
  if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
67
- const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache);
86
+ const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad);
68
87
  if (hit) return hit;
69
88
  continue;
70
89
  }
71
- const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache);
90
+ const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad);
72
91
  if (hit) return hit;
73
92
  continue;
74
93
  }
75
- if (containsPoint(px, py, child, graph, transformCache)) return child;
94
+ if (containsPoint(px, py, child, graph, transformCache, pad)) return child;
76
95
  }
77
96
  return null;
78
97
  }
79
98
  function hitTest(graph, px, py, scopeId) {
80
99
  return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, false);
81
100
  }
82
- function hitTestDeep(graph, px, py, scopeId) {
83
- return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, true);
101
+ function hitTestDeep(graph, px, py, scopeId, pad = 0) {
102
+ return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, true, /* @__PURE__ */ new Map(), pad);
84
103
  }
85
- function hitTestFrameChildren(graph, px, py, parentId, offsetX, offsetY, excludeIds) {
86
- const parent = graph.nodes.get(parentId);
87
- if (!parent) return null;
88
- let best = null;
89
- for (const childId of parent.childIds) {
104
+ /**
105
+ * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a
106
+ * section) or a section that holds layers, and a component set.
107
+ */
108
+ function opensByItself(graph, node) {
109
+ if (node.type === "COMPONENT_SET") return true;
110
+ if (node.childIds.length === 0) return false;
111
+ if (node.type === "SECTION") return true;
112
+ return node.type === "FRAME" && isTopLevel(graph, node);
113
+ }
114
+ /**
115
+ * The topmost frame among a container's children whose bounds hold the point, filled or not: in
116
+ * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the
117
+ * page or in a section, selects that frame, while a deep (⌘) click looks through it.
118
+ */
119
+ function frameChildAt(graph, container, px, py) {
120
+ const transformCache = /* @__PURE__ */ new Map();
121
+ for (let i = container.childIds.length - 1; i >= 0; i--) {
122
+ const child = graph.nodes.get(container.childIds[i]);
123
+ if (!child || child.internalOnly || !child.visible || child.type !== "FRAME") continue;
124
+ if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue;
125
+ if (containsPoint(px, py, child, graph, transformCache)) return child;
126
+ }
127
+ return null;
128
+ }
129
+ /**
130
+ * The containers the selection opens: every ancestor of a selected layer inside the scope, and a
131
+ * selected container itself, so a click inside it selects the layer under the point, as in Figma.
132
+ * A selected group or boolean stays closed: clicking inside it keeps it selected.
133
+ */
134
+ function openedBySelection(graph, selectedIds, scopeId) {
135
+ const ancestors = /* @__PURE__ */ new Set();
136
+ for (const id of selectedIds) {
137
+ const node = graph.nodes.get(id);
138
+ if (node && node.childIds.length > 0 && node.type !== "GROUP" && node.type !== "BOOLEAN_OPERATION") ancestors.add(id);
139
+ let parentId = node?.parentId;
140
+ while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {
141
+ ancestors.add(parentId);
142
+ parentId = graph.nodes.get(parentId)?.parentId;
143
+ }
144
+ }
145
+ return ancestors;
146
+ }
147
+ /**
148
+ * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under
149
+ * the point and stops at the first layer that is not open. Top-level frames and sections with
150
+ * layers and component sets are open, and so is every ancestor of the selection, so clicks reach
151
+ * the siblings of selected layers. Where every layer under the point is open, a container opened
152
+ * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level
153
+ * frame or a section is not.
154
+ */
155
+ function hitTestSelectable(graph, px, py, scopeId, selectedIds, pad = 0) {
156
+ const deepest = hitTestChildren(graph, px, py, scopeId, true, /* @__PURE__ */ new Map(), pad);
157
+ if (!deepest) {
158
+ const scope = graph.nodes.get(scopeId);
159
+ return scope ? frameChildAt(graph, scope, px, py) : null;
160
+ }
161
+ const chain = [];
162
+ for (let node = deepest; node && node.id !== scopeId;) {
163
+ chain.unshift(node);
164
+ node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
165
+ }
166
+ const opened = openedBySelection(graph, selectedIds, scopeId);
167
+ for (const node of chain) {
168
+ if (node.locked) return node;
169
+ if (!opened.has(node.id) && !opensByItself(graph, node)) return node;
170
+ }
171
+ const last = chain.at(-1);
172
+ if (!last) return null;
173
+ const frame = frameChildAt(graph, last, px, py);
174
+ if (frame) return frame;
175
+ if (ownsItsEmptyArea(graph, last)) return last;
176
+ return opened.has(last.id) && !opensByItself(graph, last) ? last : null;
177
+ }
178
+ /** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */
179
+ function isOpenContainer(graph, nodeId) {
180
+ const node = graph.nodes.get(nodeId);
181
+ return node !== void 0 && opensByItself(graph, node);
182
+ }
183
+ /**
184
+ * The innermost open container under the point when every layer there is open: a marquee starting
185
+ * here selects that container's layers, as in Figma.
186
+ */
187
+ function hitTestOpenContainer(graph, px, py, scopeId) {
188
+ const deepest = hitTestChildren(graph, px, py, scopeId, true);
189
+ for (let node = deepest ?? void 0; node && node.id !== scopeId;) {
190
+ if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null;
191
+ node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
192
+ }
193
+ return deepest;
194
+ }
195
+ /** Whether the point lies inside the node's rotated and flipped bounds. */
196
+ function isPointInNode(graph, nodeId, px, py) {
197
+ const node = graph.nodes.get(nodeId);
198
+ return node !== void 0 && containsPoint(px, py, node, graph, /* @__PURE__ */ new Map());
199
+ }
200
+ const LAYER_TARGETS = /* @__PURE__ */ new Set([
201
+ "FRAME",
202
+ "SECTION",
203
+ "COMPONENT",
204
+ "INSTANCE"
205
+ ]);
206
+ const COMPONENT_TARGETS = /* @__PURE__ */ new Set([
207
+ "FRAME",
208
+ "SECTION",
209
+ "INSTANCE"
210
+ ]);
211
+ function dropRules(options) {
212
+ const { componentSetIds } = options;
213
+ if (!componentSetIds) return {
214
+ takes: (node) => LAYER_TARGETS.has(node.type),
215
+ passThrough: /* @__PURE__ */ new Set(["GROUP", "COMPONENT_SET"])
216
+ };
217
+ return {
218
+ takes: (node) => COMPONENT_TARGETS.has(node.type) || node.type === "COMPONENT_SET" && componentSetIds.has(node.id),
219
+ passThrough: /* @__PURE__ */ new Set(["GROUP"])
220
+ };
221
+ }
222
+ function dropTargetIn(graph, px, py, parent, excludeIds, rules, transformCache) {
223
+ if (parent.type !== "CANVAS" && parent.clipsContent && !containsPoint(px, py, parent, graph, transformCache)) return null;
224
+ for (let i = parent.childIds.length - 1; i >= 0; i--) {
225
+ const childId = parent.childIds[i];
90
226
  if (excludeIds.has(childId)) continue;
91
227
  const child = graph.nodes.get(childId);
92
- if (!child || child.internalOnly || !child.visible) continue;
93
- const ax = offsetX + child.x;
94
- const ay = offsetY + child.y;
95
- if (!CONTAINER_TYPES.has(child.type)) continue;
96
- if (px < ax || px > ax + child.width || py < ay || py > ay + child.height) continue;
97
- best = child;
98
- const deeper = hitTestFrameChildren(graph, px, py, childId, ax, ay, excludeIds);
99
- if (deeper) best = deeper;
228
+ if (!child || child.internalOnly || !child.visible || child.locked) continue;
229
+ const target = rules.takes(child);
230
+ if (!target && !rules.passThrough.has(child.type)) continue;
231
+ const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache);
232
+ if (deeper) return deeper;
233
+ if (target && containsPoint(px, py, child, graph, transformCache)) return child;
100
234
  }
101
- return best;
235
+ return null;
102
236
  }
103
- function hitTestFrame(graph, px, py, excludeIds, scopeId) {
104
- return hitTestFrameChildren(graph, px, py, scopeId ?? graph.rootId, 0, 0, excludeIds);
237
+ /**
238
+ * The topmost unlocked frame, section, component, or instance under the point, in its rotated
239
+ * shape and inside its clipping ancestors. Groups and component sets are looked through but never
240
+ * returned, except that a set takes dropped components; locked layers and their contents are
241
+ * skipped.
242
+ */
243
+ function hitTestDropTarget(graph, px, py, excludeIds, scopeId, options = {}) {
244
+ const scope = graph.nodes.get(scopeId ?? graph.rootId);
245
+ if (!scope) return null;
246
+ return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), /* @__PURE__ */ new Map());
105
247
  }
106
248
  //#endregion
107
- export { hitTest, hitTestDeep, hitTestFrame };
249
+ export { hitTest, hitTestDeep, hitTestDropTarget, hitTestOpenContainer, hitTestSelectable, isOpenContainer, isPointInNode };
108
250
 
109
251
  //# sourceMappingURL=hit-test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, NodeType } from './'\nimport { getWorldMatrix } from './coordinate'\nimport Matrix from './matrix'\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\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\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\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x &&\n px <= absolute.x + node.width &&\n py >= absolute.y &&\n py <= absolute.y + node.height\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return localX >= 0 && localX <= node.width && localY >= 0 && localY <= node.height\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): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache)\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): SceneNode | null {\n if (child.type === 'GROUP') {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n\n if (deep) return hitTestChildren(graph, px, py, childId, deep, transformCache) ?? child\n\n return child\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (containsPoint(px, py, child, graph, transformCache) && hasVisibleFillOrStroke(child))\n return child\n return null\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): 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 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 (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)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache)\n if (hit) return hit\n continue\n }\n\n if (containsPoint(px, py, child, graph, transformCache)) 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): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true)\n}\n\nfunction hitTestFrameChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n offsetX: number,\n offsetY: number,\n excludeIds: Set<string>\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n let best: SceneNode | null = null\n\n for (const childId of parent.childIds) {\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n\n const ax = offsetX + child.x\n const ay = offsetY + child.y\n\n if (!CONTAINER_TYPES.has(child.type)) continue\n if (px < ax || px > ax + child.width || py < ay || py > ay + child.height) continue\n\n best = child\n\n const deeper = hitTestFrameChildren(graph, px, py, childId, ax, ay, excludeIds)\n if (deeper) best = deeper\n }\n\n return best\n}\n\nexport function hitTestFrame(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: Set<string>,\n scopeId?: string\n): SceneNode | null {\n return hitTestFrameChildren(graph, px, py, scopeId ?? graph.rootId, 0, 0, excludeIds)\n}\n"],"mappings":";;AAIA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;AAE1E,SAAS,uBAAuB,MAA0B;CACxD,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,OAAO,KAAK,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO;AAChF;AAEA,SAAS,uBACP,MACA,OACA,OACS;CACT,MAAM,SAAS,MAAM,IAAI,KAAK,EAAE;CAChC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC9D,MAAM,cACJ,KAAK,aAAa,KAClB,KAAK,SACL,KAAK,UACJ,SAAS,uBAAuB,QAAQ,OAAO,KAAK,IAAI;CAC3D,MAAM,IAAI,KAAK,IAAI,WAAW;CAC9B,OAAO;AACT;AAEA,SAAS,cACP,IACA,IACA,MACA,OACA,gBACS;CACT,IAAI,CAAC,uBAAuB,MAAM,OAAO,cAAc,GAAG;EACxD,MAAM,WAAW,MAAM,oBAAoB,KAAK,EAAE;EAClD,OACE,MAAM,SAAS,KACf,MAAM,SAAS,IAAI,KAAK,SACxB,MAAM,SAAS,KACf,MAAM,SAAS,IAAI,KAAK;CAE5B;CAEA,MAAM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AK,KAAK,MAAM,SAAS,KAAK,MAAM,KAAK,KAAK,MAAM,QAAQ;EAE3E,OAAO;EAEP,MAAM,SAAS,qBAAqB,OAAO,IAAI,IAAI,SAAS,IAAI,IAAI,UAAU;EAC9E,IAAI,QAAQ,OAAO;CACrB;CAEA,OAAO;AACT;AAEA,SAAgB,aACd,OACA,IACA,IACA,YACA,SACkB;CAClB,OAAO,qBAAqB,OAAO,IAAI,IAAI,WAAW,MAAM,QAAQ,GAAG,GAAG,UAAU;AACtF"}
1
+ {"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, NodeType } from './'\nimport { getWorldMatrix } from './coordinate'\nimport Matrix from './matrix'\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\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/** 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 if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x - pad &&\n px <= absolute.x + node.width + pad &&\n py >= absolute.y - pad &&\n py <= absolute.y + node.height + pad\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return (\n localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad\n )\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/**\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 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 (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 (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\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":";;AAIA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;AAE1E,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,YAAY,QAAQ,SAAS;AACvD;;;;;;;AAQA,SAAS,iBAAiB,OAAmB,MAA0B;CACrE,OAAO,KAAK,SAAS,WAAW,KAAK,eAAe,UAAU,WAAW,OAAO,IAAI;AACtF;AAEA,SAAS,uBACP,MACA,OACA,OACS;CACT,MAAM,SAAS,MAAM,IAAI,KAAK,EAAE;CAChC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC9D,MAAM,cACJ,KAAK,aAAa,KAClB,KAAK,SACL,KAAK,UACJ,SAAS,uBAAuB,QAAQ,OAAO,KAAK,IAAI;CAC3D,MAAM,IAAI,KAAK,IAAI,WAAW;CAC9B,OAAO;AACT;;AAGA,SAAS,cACP,IACA,IACA,MACA,OACA,gBACA,MAAM,GACG;CACT,IAAI,CAAC,uBAAuB,MAAM,OAAO,cAAc,GAAG;EACxD,MAAM,WAAW,MAAM,oBAAoB,KAAK,EAAE;EAClD,OACE,MAAM,SAAS,IAAI,OACnB,MAAM,SAAS,IAAI,KAAK,QAAQ,OAChC,MAAM,SAAS,IAAI,OACnB,MAAM,SAAS,IA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